1 /*
2  * NOTE: This is generated code. Look in numpy/linalg/lapack_lite for
3  *       information on remaking this file.
4  */
5 #include "f2c.h"
6 
7 #ifdef HAVE_CONFIG
8 #include "config.h"
9 #else
10 extern doublereal dlamch_(char *);
11 #define EPSILON dlamch_("Epsilon")
12 #define SAFEMINIMUM dlamch_("Safe minimum")
13 #define PRECISION dlamch_("Precision")
14 #define BASE dlamch_("Base")
15 #endif
16 
17 extern doublereal dlapy2_(doublereal *x, doublereal *y);
18 
19 /*
20 f2c knows the exact rules for precedence, and so omits parentheses where not
21 strictly necessary. Since this is generated code, we don't really care if
22 it's readable, and we know what is written is correct. So don't warn about
23 them.
24 */
25 #if defined(__GNUC__)
26 #pragma GCC diagnostic ignored "-Wparentheses"
27 #endif
28 
29 
30 /* Table of constant values */
31 
32 static integer c__9 = 9;
33 static integer c__0 = 0;
34 static doublereal c_b15 = 1.;
35 static integer c__1 = 1;
36 static doublereal c_b29 = 0.;
37 static doublereal c_b94 = -.125;
38 static doublereal c_b151 = -1.;
39 static integer c_n1 = -1;
40 static integer c__3 = 3;
41 static integer c__2 = 2;
42 static integer c__65 = 65;
43 static integer c__6 = 6;
44 static integer c__12 = 12;
45 static integer c__49 = 49;
46 static integer c__4 = 4;
47 static logical c_false = FALSE_;
48 static integer c__13 = 13;
49 static integer c__15 = 15;
50 static integer c__14 = 14;
51 static integer c__16 = 16;
52 static logical c_true = TRUE_;
53 static integer c__10 = 10;
54 static integer c__11 = 11;
55 static doublereal c_b3192 = 2.;
56 
dbdsdc_(char * uplo,char * compq,integer * n,doublereal * d__,doublereal * e,doublereal * u,integer * ldu,doublereal * vt,integer * ldvt,doublereal * q,integer * iq,doublereal * work,integer * iwork,integer * info)57 /* Subroutine */ int dbdsdc_(char *uplo, char *compq, integer *n, doublereal *
58 	d__, doublereal *e, doublereal *u, integer *ldu, doublereal *vt,
59 	integer *ldvt, doublereal *q, integer *iq, doublereal *work, integer *
60 	iwork, integer *info)
61 {
62     /* System generated locals */
63     integer u_dim1, u_offset, vt_dim1, vt_offset, i__1, i__2;
64     doublereal d__1;
65 
66     /* Local variables */
67     static integer i__, j, k;
68     static doublereal p, r__;
69     static integer z__, ic, ii, kk;
70     static doublereal cs;
71     static integer is, iu;
72     static doublereal sn;
73     static integer nm1;
74     static doublereal eps;
75     static integer ivt, difl, difr, ierr, perm, mlvl, sqre;
76     extern logical lsame_(char *, char *);
77     extern /* Subroutine */ int dlasr_(char *, char *, char *, integer *,
78 	    integer *, doublereal *, doublereal *, doublereal *, integer *), dcopy_(integer *, doublereal *, integer *
79 	    , doublereal *, integer *), dswap_(integer *, doublereal *,
80 	    integer *, doublereal *, integer *);
81     static integer poles, iuplo, nsize, start;
82     extern /* Subroutine */ int dlasd0_(integer *, integer *, doublereal *,
83 	    doublereal *, doublereal *, integer *, doublereal *, integer *,
84 	    integer *, integer *, doublereal *, integer *);
85 
86     extern /* Subroutine */ int dlasda_(integer *, integer *, integer *,
87 	    integer *, doublereal *, doublereal *, doublereal *, integer *,
88 	    doublereal *, integer *, doublereal *, doublereal *, doublereal *,
89 	     doublereal *, integer *, integer *, integer *, integer *,
90 	    doublereal *, doublereal *, doublereal *, doublereal *, integer *,
91 	     integer *), dlascl_(char *, integer *, integer *, doublereal *,
92 	    doublereal *, integer *, integer *, doublereal *, integer *,
93 	    integer *), dlasdq_(char *, integer *, integer *, integer
94 	    *, integer *, integer *, doublereal *, doublereal *, doublereal *,
95 	     integer *, doublereal *, integer *, doublereal *, integer *,
96 	    doublereal *, integer *), dlaset_(char *, integer *,
97 	    integer *, doublereal *, doublereal *, doublereal *, integer *), dlartg_(doublereal *, doublereal *, doublereal *,
98 	    doublereal *, doublereal *);
99     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
100 	    integer *, integer *, ftnlen, ftnlen);
101     extern /* Subroutine */ int xerbla_(char *, integer *);
102     static integer givcol;
103     extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
104     static integer icompq;
105     static doublereal orgnrm;
106     static integer givnum, givptr, qstart, smlsiz, wstart, smlszp;
107 
108 
109 /*
110     -- LAPACK routine (version 3.2.2) --
111     -- LAPACK is a software package provided by Univ. of Tennessee,    --
112     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
113        June 2010
114 
115 
116     Purpose
117     =======
118 
119     DBDSDC computes the singular value decomposition (SVD) of a real
120     N-by-N (upper or lower) bidiagonal matrix B:  B = U * S * VT,
121     using a divide and conquer method, where S is a diagonal matrix
122     with non-negative diagonal elements (the singular values of B), and
123     U and VT are orthogonal matrices of left and right singular vectors,
124     respectively. DBDSDC can be used to compute all singular values,
125     and optionally, singular vectors or singular vectors in compact form.
126 
127     This code makes very mild assumptions about floating point
128     arithmetic. It will work on machines with a guard digit in
129     add/subtract, or on those binary machines without guard digits
130     which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or Cray-2.
131     It could conceivably fail on hexadecimal or decimal machines
132     without guard digits, but we know of none.  See DLASD3 for details.
133 
134     The code currently calls DLASDQ if singular values only are desired.
135     However, it can be slightly modified to compute singular values
136     using the divide and conquer method.
137 
138     Arguments
139     =========
140 
141     UPLO    (input) CHARACTER*1
142             = 'U':  B is upper bidiagonal.
143             = 'L':  B is lower bidiagonal.
144 
145     COMPQ   (input) CHARACTER*1
146             Specifies whether singular vectors are to be computed
147             as follows:
148             = 'N':  Compute singular values only;
149             = 'P':  Compute singular values and compute singular
150                     vectors in compact form;
151             = 'I':  Compute singular values and singular vectors.
152 
153     N       (input) INTEGER
154             The order of the matrix B.  N >= 0.
155 
156     D       (input/output) DOUBLE PRECISION array, dimension (N)
157             On entry, the n diagonal elements of the bidiagonal matrix B.
158             On exit, if INFO=0, the singular values of B.
159 
160     E       (input/output) DOUBLE PRECISION array, dimension (N-1)
161             On entry, the elements of E contain the offdiagonal
162             elements of the bidiagonal matrix whose SVD is desired.
163             On exit, E has been destroyed.
164 
165     U       (output) DOUBLE PRECISION array, dimension (LDU,N)
166             If  COMPQ = 'I', then:
167                On exit, if INFO = 0, U contains the left singular vectors
168                of the bidiagonal matrix.
169             For other values of COMPQ, U is not referenced.
170 
171     LDU     (input) INTEGER
172             The leading dimension of the array U.  LDU >= 1.
173             If singular vectors are desired, then LDU >= max( 1, N ).
174 
175     VT      (output) DOUBLE PRECISION array, dimension (LDVT,N)
176             If  COMPQ = 'I', then:
177                On exit, if INFO = 0, VT' contains the right singular
178                vectors of the bidiagonal matrix.
179             For other values of COMPQ, VT is not referenced.
180 
181     LDVT    (input) INTEGER
182             The leading dimension of the array VT.  LDVT >= 1.
183             If singular vectors are desired, then LDVT >= max( 1, N ).
184 
185     Q       (output) DOUBLE PRECISION array, dimension (LDQ)
186             If  COMPQ = 'P', then:
187                On exit, if INFO = 0, Q and IQ contain the left
188                and right singular vectors in a compact form,
189                requiring O(N log N) space instead of 2*N**2.
190                In particular, Q contains all the DOUBLE PRECISION data in
191                LDQ >= N*(11 + 2*SMLSIZ + 8*INT(LOG_2(N/(SMLSIZ+1))))
192                words of memory, where SMLSIZ is returned by ILAENV and
193                is equal to the maximum size of the subproblems at the
194                bottom of the computation tree (usually about 25).
195             For other values of COMPQ, Q is not referenced.
196 
197     IQ      (output) INTEGER array, dimension (LDIQ)
198             If  COMPQ = 'P', then:
199                On exit, if INFO = 0, Q and IQ contain the left
200                and right singular vectors in a compact form,
201                requiring O(N log N) space instead of 2*N**2.
202                In particular, IQ contains all INTEGER data in
203                LDIQ >= N*(3 + 3*INT(LOG_2(N/(SMLSIZ+1))))
204                words of memory, where SMLSIZ is returned by ILAENV and
205                is equal to the maximum size of the subproblems at the
206                bottom of the computation tree (usually about 25).
207             For other values of COMPQ, IQ is not referenced.
208 
209     WORK    (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
210             If COMPQ = 'N' then LWORK >= (4 * N).
211             If COMPQ = 'P' then LWORK >= (6 * N).
212             If COMPQ = 'I' then LWORK >= (3 * N**2 + 4 * N).
213 
214     IWORK   (workspace) INTEGER array, dimension (8*N)
215 
216     INFO    (output) INTEGER
217             = 0:  successful exit.
218             < 0:  if INFO = -i, the i-th argument had an illegal value.
219             > 0:  The algorithm failed to compute a singular value.
220                   The update process of divide and conquer failed.
221 
222     Further Details
223     ===============
224 
225     Based on contributions by
226        Ming Gu and Huan Ren, Computer Science Division, University of
227        California at Berkeley, USA
228 
229     =====================================================================
230     Changed dimension statement in comment describing E from (N) to
231     (N-1).  Sven, 17 Feb 05.
232     =====================================================================
233 
234 
235        Test the input parameters.
236 */
237 
238     /* Parameter adjustments */
239     --d__;
240     --e;
241     u_dim1 = *ldu;
242     u_offset = 1 + u_dim1;
243     u -= u_offset;
244     vt_dim1 = *ldvt;
245     vt_offset = 1 + vt_dim1;
246     vt -= vt_offset;
247     --q;
248     --iq;
249     --work;
250     --iwork;
251 
252     /* Function Body */
253     *info = 0;
254 
255     iuplo = 0;
256     if (lsame_(uplo, "U")) {
257 	iuplo = 1;
258     }
259     if (lsame_(uplo, "L")) {
260 	iuplo = 2;
261     }
262     if (lsame_(compq, "N")) {
263 	icompq = 0;
264     } else if (lsame_(compq, "P")) {
265 	icompq = 1;
266     } else if (lsame_(compq, "I")) {
267 	icompq = 2;
268     } else {
269 	icompq = -1;
270     }
271     if (iuplo == 0) {
272 	*info = -1;
273     } else if (icompq < 0) {
274 	*info = -2;
275     } else if (*n < 0) {
276 	*info = -3;
277     } else if (*ldu < 1 || icompq == 2 && *ldu < *n) {
278 	*info = -7;
279     } else if (*ldvt < 1 || icompq == 2 && *ldvt < *n) {
280 	*info = -9;
281     }
282     if (*info != 0) {
283 	i__1 = -(*info);
284 	xerbla_("DBDSDC", &i__1);
285 	return 0;
286     }
287 
288 /*     Quick return if possible */
289 
290     if (*n == 0) {
291 	return 0;
292     }
293     smlsiz = ilaenv_(&c__9, "DBDSDC", " ", &c__0, &c__0, &c__0, &c__0, (
294 	    ftnlen)6, (ftnlen)1);
295     if (*n == 1) {
296 	if (icompq == 1) {
297 	    q[1] = d_sign(&c_b15, &d__[1]);
298 	    q[smlsiz * *n + 1] = 1.;
299 	} else if (icompq == 2) {
300 	    u[u_dim1 + 1] = d_sign(&c_b15, &d__[1]);
301 	    vt[vt_dim1 + 1] = 1.;
302 	}
303 	d__[1] = abs(d__[1]);
304 	return 0;
305     }
306     nm1 = *n - 1;
307 
308 /*
309        If matrix lower bidiagonal, rotate to be upper bidiagonal
310        by applying Givens rotations on the left
311 */
312 
313     wstart = 1;
314     qstart = 3;
315     if (icompq == 1) {
316 	dcopy_(n, &d__[1], &c__1, &q[1], &c__1);
317 	i__1 = *n - 1;
318 	dcopy_(&i__1, &e[1], &c__1, &q[*n + 1], &c__1);
319     }
320     if (iuplo == 2) {
321 	qstart = 5;
322 	wstart = (*n << 1) - 1;
323 	i__1 = *n - 1;
324 	for (i__ = 1; i__ <= i__1; ++i__) {
325 	    dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
326 	    d__[i__] = r__;
327 	    e[i__] = sn * d__[i__ + 1];
328 	    d__[i__ + 1] = cs * d__[i__ + 1];
329 	    if (icompq == 1) {
330 		q[i__ + (*n << 1)] = cs;
331 		q[i__ + *n * 3] = sn;
332 	    } else if (icompq == 2) {
333 		work[i__] = cs;
334 		work[nm1 + i__] = -sn;
335 	    }
336 /* L10: */
337 	}
338     }
339 
340 /*     If ICOMPQ = 0, use DLASDQ to compute the singular values. */
341 
342     if (icompq == 0) {
343 	dlasdq_("U", &c__0, n, &c__0, &c__0, &c__0, &d__[1], &e[1], &vt[
344 		vt_offset], ldvt, &u[u_offset], ldu, &u[u_offset], ldu, &work[
345 		wstart], info);
346 	goto L40;
347     }
348 
349 /*
350        If N is smaller than the minimum divide size SMLSIZ, then solve
351        the problem with another solver.
352 */
353 
354     if (*n <= smlsiz) {
355 	if (icompq == 2) {
356 	    dlaset_("A", n, n, &c_b29, &c_b15, &u[u_offset], ldu);
357 	    dlaset_("A", n, n, &c_b29, &c_b15, &vt[vt_offset], ldvt);
358 	    dlasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &vt[vt_offset]
359 		    , ldvt, &u[u_offset], ldu, &u[u_offset], ldu, &work[
360 		    wstart], info);
361 	} else if (icompq == 1) {
362 	    iu = 1;
363 	    ivt = iu + *n;
364 	    dlaset_("A", n, n, &c_b29, &c_b15, &q[iu + (qstart - 1) * *n], n);
365 	    dlaset_("A", n, n, &c_b29, &c_b15, &q[ivt + (qstart - 1) * *n], n);
366 	    dlasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &q[ivt + (
367 		    qstart - 1) * *n], n, &q[iu + (qstart - 1) * *n], n, &q[
368 		    iu + (qstart - 1) * *n], n, &work[wstart], info);
369 	}
370 	goto L40;
371     }
372 
373     if (icompq == 2) {
374 	dlaset_("A", n, n, &c_b29, &c_b15, &u[u_offset], ldu);
375 	dlaset_("A", n, n, &c_b29, &c_b15, &vt[vt_offset], ldvt);
376     }
377 
378 /*     Scale. */
379 
380     orgnrm = dlanst_("M", n, &d__[1], &e[1]);
381     if (orgnrm == 0.) {
382 	return 0;
383     }
384     dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, n, &c__1, &d__[1], n, &ierr);
385     dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, &nm1, &c__1, &e[1], &nm1, &
386 	    ierr);
387 
388     eps = EPSILON;
389 
390     mlvl = (integer) (log((doublereal) (*n) / (doublereal) (smlsiz + 1)) /
391 	    log(2.)) + 1;
392     smlszp = smlsiz + 1;
393 
394     if (icompq == 1) {
395 	iu = 1;
396 	ivt = smlsiz + 1;
397 	difl = ivt + smlszp;
398 	difr = difl + mlvl;
399 	z__ = difr + (mlvl << 1);
400 	ic = z__ + mlvl;
401 	is = ic + 1;
402 	poles = is + 1;
403 	givnum = poles + (mlvl << 1);
404 
405 	k = 1;
406 	givptr = 2;
407 	perm = 3;
408 	givcol = perm + mlvl;
409     }
410 
411     i__1 = *n;
412     for (i__ = 1; i__ <= i__1; ++i__) {
413 	if ((d__1 = d__[i__], abs(d__1)) < eps) {
414 	    d__[i__] = d_sign(&eps, &d__[i__]);
415 	}
416 /* L20: */
417     }
418 
419     start = 1;
420     sqre = 0;
421 
422     i__1 = nm1;
423     for (i__ = 1; i__ <= i__1; ++i__) {
424 	if ((d__1 = e[i__], abs(d__1)) < eps || i__ == nm1) {
425 
426 /*
427           Subproblem found. First determine its size and then
428           apply divide and conquer on it.
429 */
430 
431 	    if (i__ < nm1) {
432 
433 /*        A subproblem with E(I) small for I < NM1. */
434 
435 		nsize = i__ - start + 1;
436 	    } else if ((d__1 = e[i__], abs(d__1)) >= eps) {
437 
438 /*        A subproblem with E(NM1) not too small but I = NM1. */
439 
440 		nsize = *n - start + 1;
441 	    } else {
442 
443 /*
444           A subproblem with E(NM1) small. This implies an
445           1-by-1 subproblem at D(N). Solve this 1-by-1 problem
446           first.
447 */
448 
449 		nsize = i__ - start + 1;
450 		if (icompq == 2) {
451 		    u[*n + *n * u_dim1] = d_sign(&c_b15, &d__[*n]);
452 		    vt[*n + *n * vt_dim1] = 1.;
453 		} else if (icompq == 1) {
454 		    q[*n + (qstart - 1) * *n] = d_sign(&c_b15, &d__[*n]);
455 		    q[*n + (smlsiz + qstart - 1) * *n] = 1.;
456 		}
457 		d__[*n] = (d__1 = d__[*n], abs(d__1));
458 	    }
459 	    if (icompq == 2) {
460 		dlasd0_(&nsize, &sqre, &d__[start], &e[start], &u[start +
461 			start * u_dim1], ldu, &vt[start + start * vt_dim1],
462 			ldvt, &smlsiz, &iwork[1], &work[wstart], info);
463 	    } else {
464 		dlasda_(&icompq, &smlsiz, &nsize, &sqre, &d__[start], &e[
465 			start], &q[start + (iu + qstart - 2) * *n], n, &q[
466 			start + (ivt + qstart - 2) * *n], &iq[start + k * *n],
467 			 &q[start + (difl + qstart - 2) * *n], &q[start + (
468 			difr + qstart - 2) * *n], &q[start + (z__ + qstart -
469 			2) * *n], &q[start + (poles + qstart - 2) * *n], &iq[
470 			start + givptr * *n], &iq[start + givcol * *n], n, &
471 			iq[start + perm * *n], &q[start + (givnum + qstart -
472 			2) * *n], &q[start + (ic + qstart - 2) * *n], &q[
473 			start + (is + qstart - 2) * *n], &work[wstart], &
474 			iwork[1], info);
475 	    }
476 	    if (*info != 0) {
477 		return 0;
478 	    }
479 	    start = i__ + 1;
480 	}
481 /* L30: */
482     }
483 
484 /*     Unscale */
485 
486     dlascl_("G", &c__0, &c__0, &c_b15, &orgnrm, n, &c__1, &d__[1], n, &ierr);
487 L40:
488 
489 /*     Use Selection Sort to minimize swaps of singular vectors */
490 
491     i__1 = *n;
492     for (ii = 2; ii <= i__1; ++ii) {
493 	i__ = ii - 1;
494 	kk = i__;
495 	p = d__[i__];
496 	i__2 = *n;
497 	for (j = ii; j <= i__2; ++j) {
498 	    if (d__[j] > p) {
499 		kk = j;
500 		p = d__[j];
501 	    }
502 /* L50: */
503 	}
504 	if (kk != i__) {
505 	    d__[kk] = d__[i__];
506 	    d__[i__] = p;
507 	    if (icompq == 1) {
508 		iq[i__] = kk;
509 	    } else if (icompq == 2) {
510 		dswap_(n, &u[i__ * u_dim1 + 1], &c__1, &u[kk * u_dim1 + 1], &
511 			c__1);
512 		dswap_(n, &vt[i__ + vt_dim1], ldvt, &vt[kk + vt_dim1], ldvt);
513 	    }
514 	} else if (icompq == 1) {
515 	    iq[i__] = i__;
516 	}
517 /* L60: */
518     }
519 
520 /*     If ICOMPQ = 1, use IQ(N,1) as the indicator for UPLO */
521 
522     if (icompq == 1) {
523 	if (iuplo == 1) {
524 	    iq[*n] = 1;
525 	} else {
526 	    iq[*n] = 0;
527 	}
528     }
529 
530 /*
531        If B is lower bidiagonal, update U by those Givens rotations
532        which rotated B to be upper bidiagonal
533 */
534 
535     if (iuplo == 2 && icompq == 2) {
536 	dlasr_("L", "V", "B", n, n, &work[1], &work[*n], &u[u_offset], ldu);
537     }
538 
539     return 0;
540 
541 /*     End of DBDSDC */
542 
543 } /* dbdsdc_ */
544 
dbdsqr_(char * uplo,integer * n,integer * ncvt,integer * nru,integer * ncc,doublereal * d__,doublereal * e,doublereal * vt,integer * ldvt,doublereal * u,integer * ldu,doublereal * c__,integer * ldc,doublereal * work,integer * info)545 /* Subroutine */ int dbdsqr_(char *uplo, integer *n, integer *ncvt, integer *
546 	nru, integer *ncc, doublereal *d__, doublereal *e, doublereal *vt,
547 	integer *ldvt, doublereal *u, integer *ldu, doublereal *c__, integer *
548 	ldc, doublereal *work, integer *info)
549 {
550     /* System generated locals */
551     integer c_dim1, c_offset, u_dim1, u_offset, vt_dim1, vt_offset, i__1,
552 	    i__2;
553     doublereal d__1, d__2, d__3, d__4;
554 
555     /* Local variables */
556     static doublereal f, g, h__;
557     static integer i__, j, m;
558     static doublereal r__, cs;
559     static integer ll;
560     static doublereal sn, mu;
561     static integer nm1, nm12, nm13, lll;
562     static doublereal eps, sll, tol, abse;
563     static integer idir;
564     static doublereal abss;
565     static integer oldm;
566     static doublereal cosl;
567     static integer isub, iter;
568     static doublereal unfl, sinl, cosr, smin, smax, sinr;
569     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
570 	    doublereal *, integer *, doublereal *, doublereal *), dlas2_(
571 	    doublereal *, doublereal *, doublereal *, doublereal *,
572 	    doublereal *), dscal_(integer *, doublereal *, doublereal *,
573 	    integer *);
574     extern logical lsame_(char *, char *);
575     static doublereal oldcs;
576     extern /* Subroutine */ int dlasr_(char *, char *, char *, integer *,
577 	    integer *, doublereal *, doublereal *, doublereal *, integer *);
578     static integer oldll;
579     static doublereal shift, sigmn, oldsn;
580     extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *,
581 	    doublereal *, integer *);
582     static integer maxit;
583     static doublereal sminl, sigmx;
584     static logical lower;
585     extern /* Subroutine */ int dlasq1_(integer *, doublereal *, doublereal *,
586 	     doublereal *, integer *), dlasv2_(doublereal *, doublereal *,
587 	    doublereal *, doublereal *, doublereal *, doublereal *,
588 	    doublereal *, doublereal *, doublereal *);
589 
590     extern /* Subroutine */ int dlartg_(doublereal *, doublereal *,
591 	    doublereal *, doublereal *, doublereal *), xerbla_(char *,
592 	    integer *);
593     static doublereal sminoa, thresh;
594     static logical rotate;
595     static doublereal tolmul;
596 
597 
598 /*
599     -- LAPACK routine (version 3.2) --
600     -- LAPACK is a software package provided by Univ. of Tennessee,    --
601     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
602        January 2007
603 
604 
605     Purpose
606     =======
607 
608     DBDSQR computes the singular values and, optionally, the right and/or
609     left singular vectors from the singular value decomposition (SVD) of
610     a real N-by-N (upper or lower) bidiagonal matrix B using the implicit
611     zero-shift QR algorithm.  The SVD of B has the form
612 
613        B = Q * S * P**T
614 
615     where S is the diagonal matrix of singular values, Q is an orthogonal
616     matrix of left singular vectors, and P is an orthogonal matrix of
617     right singular vectors.  If left singular vectors are requested, this
618     subroutine actually returns U*Q instead of Q, and, if right singular
619     vectors are requested, this subroutine returns P**T*VT instead of
620     P**T, for given real input matrices U and VT.  When U and VT are the
621     orthogonal matrices that reduce a general matrix A to bidiagonal
622     form:  A = U*B*VT, as computed by DGEBRD, then
623 
624        A = (U*Q) * S * (P**T*VT)
625 
626     is the SVD of A.  Optionally, the subroutine may also compute Q**T*C
627     for a given real input matrix C.
628 
629     See "Computing  Small Singular Values of Bidiagonal Matrices With
630     Guaranteed High Relative Accuracy," by J. Demmel and W. Kahan,
631     LAPACK Working Note #3 (or SIAM J. Sci. Statist. Comput. vol. 11,
632     no. 5, pp. 873-912, Sept 1990) and
633     "Accurate singular values and differential qd algorithms," by
634     B. Parlett and V. Fernando, Technical Report CPAM-554, Mathematics
635     Department, University of California at Berkeley, July 1992
636     for a detailed description of the algorithm.
637 
638     Arguments
639     =========
640 
641     UPLO    (input) CHARACTER*1
642             = 'U':  B is upper bidiagonal;
643             = 'L':  B is lower bidiagonal.
644 
645     N       (input) INTEGER
646             The order of the matrix B.  N >= 0.
647 
648     NCVT    (input) INTEGER
649             The number of columns of the matrix VT. NCVT >= 0.
650 
651     NRU     (input) INTEGER
652             The number of rows of the matrix U. NRU >= 0.
653 
654     NCC     (input) INTEGER
655             The number of columns of the matrix C. NCC >= 0.
656 
657     D       (input/output) DOUBLE PRECISION array, dimension (N)
658             On entry, the n diagonal elements of the bidiagonal matrix B.
659             On exit, if INFO=0, the singular values of B in decreasing
660             order.
661 
662     E       (input/output) DOUBLE PRECISION array, dimension (N-1)
663             On entry, the N-1 offdiagonal elements of the bidiagonal
664             matrix B.
665             On exit, if INFO = 0, E is destroyed; if INFO > 0, D and E
666             will contain the diagonal and superdiagonal elements of a
667             bidiagonal matrix orthogonally equivalent to the one given
668             as input.
669 
670     VT      (input/output) DOUBLE PRECISION array, dimension (LDVT, NCVT)
671             On entry, an N-by-NCVT matrix VT.
672             On exit, VT is overwritten by P**T * VT.
673             Not referenced if NCVT = 0.
674 
675     LDVT    (input) INTEGER
676             The leading dimension of the array VT.
677             LDVT >= max(1,N) if NCVT > 0; LDVT >= 1 if NCVT = 0.
678 
679     U       (input/output) DOUBLE PRECISION array, dimension (LDU, N)
680             On entry, an NRU-by-N matrix U.
681             On exit, U is overwritten by U * Q.
682             Not referenced if NRU = 0.
683 
684     LDU     (input) INTEGER
685             The leading dimension of the array U.  LDU >= max(1,NRU).
686 
687     C       (input/output) DOUBLE PRECISION array, dimension (LDC, NCC)
688             On entry, an N-by-NCC matrix C.
689             On exit, C is overwritten by Q**T * C.
690             Not referenced if NCC = 0.
691 
692     LDC     (input) INTEGER
693             The leading dimension of the array C.
694             LDC >= max(1,N) if NCC > 0; LDC >=1 if NCC = 0.
695 
696     WORK    (workspace) DOUBLE PRECISION array, dimension (4*N)
697 
698     INFO    (output) INTEGER
699             = 0:  successful exit
700             < 0:  If INFO = -i, the i-th argument had an illegal value
701             > 0:
702                if NCVT = NRU = NCC = 0,
703                   = 1, a split was marked by a positive value in E
704                   = 2, current block of Z not diagonalized after 30*N
705                        iterations (in inner while loop)
706                   = 3, termination criterion of outer while loop not met
707                        (program created more than N unreduced blocks)
708                else NCVT = NRU = NCC = 0,
709                      the algorithm did not converge; D and E contain the
710                      elements of a bidiagonal matrix which is orthogonally
711                      similar to the input matrix B;  if INFO = i, i
712                      elements of E have not converged to zero.
713 
714     Internal Parameters
715     ===================
716 
717     TOLMUL  DOUBLE PRECISION, default = max(10,min(100,EPS**(-1/8)))
718             TOLMUL controls the convergence criterion of the QR loop.
719             If it is positive, TOLMUL*EPS is the desired relative
720                precision in the computed singular values.
721             If it is negative, abs(TOLMUL*EPS*sigma_max) is the
722                desired absolute accuracy in the computed singular
723                values (corresponds to relative accuracy
724                abs(TOLMUL*EPS) in the largest singular value.
725             abs(TOLMUL) should be between 1 and 1/EPS, and preferably
726                between 10 (for fast convergence) and .1/EPS
727                (for there to be some accuracy in the results).
728             Default is to lose at either one eighth or 2 of the
729                available decimal digits in each computed singular value
730                (whichever is smaller).
731 
732     MAXITR  INTEGER, default = 6
733             MAXITR controls the maximum number of passes of the
734             algorithm through its inner loop. The algorithms stops
735             (and so fails to converge) if the number of passes
736             through the inner loop exceeds MAXITR*N**2.
737 
738     =====================================================================
739 
740 
741        Test the input parameters.
742 */
743 
744     /* Parameter adjustments */
745     --d__;
746     --e;
747     vt_dim1 = *ldvt;
748     vt_offset = 1 + vt_dim1;
749     vt -= vt_offset;
750     u_dim1 = *ldu;
751     u_offset = 1 + u_dim1;
752     u -= u_offset;
753     c_dim1 = *ldc;
754     c_offset = 1 + c_dim1;
755     c__ -= c_offset;
756     --work;
757 
758     /* Function Body */
759     *info = 0;
760     lower = lsame_(uplo, "L");
761     if (! lsame_(uplo, "U") && ! lower) {
762 	*info = -1;
763     } else if (*n < 0) {
764 	*info = -2;
765     } else if (*ncvt < 0) {
766 	*info = -3;
767     } else if (*nru < 0) {
768 	*info = -4;
769     } else if (*ncc < 0) {
770 	*info = -5;
771     } else if (*ncvt == 0 && *ldvt < 1 || *ncvt > 0 && *ldvt < max(1,*n)) {
772 	*info = -9;
773     } else if (*ldu < max(1,*nru)) {
774 	*info = -11;
775     } else if (*ncc == 0 && *ldc < 1 || *ncc > 0 && *ldc < max(1,*n)) {
776 	*info = -13;
777     }
778     if (*info != 0) {
779 	i__1 = -(*info);
780 	xerbla_("DBDSQR", &i__1);
781 	return 0;
782     }
783     if (*n == 0) {
784 	return 0;
785     }
786     if (*n == 1) {
787 	goto L160;
788     }
789 
790 /*     ROTATE is true if any singular vectors desired, false otherwise */
791 
792     rotate = *ncvt > 0 || *nru > 0 || *ncc > 0;
793 
794 /*     If no singular vectors desired, use qd algorithm */
795 
796     if (! rotate) {
797 	dlasq1_(n, &d__[1], &e[1], &work[1], info);
798 	return 0;
799     }
800 
801     nm1 = *n - 1;
802     nm12 = nm1 + nm1;
803     nm13 = nm12 + nm1;
804     idir = 0;
805 
806 /*     Get machine constants */
807 
808     eps = EPSILON;
809     unfl = SAFEMINIMUM;
810 
811 /*
812        If matrix lower bidiagonal, rotate to be upper bidiagonal
813        by applying Givens rotations on the left
814 */
815 
816     if (lower) {
817 	i__1 = *n - 1;
818 	for (i__ = 1; i__ <= i__1; ++i__) {
819 	    dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
820 	    d__[i__] = r__;
821 	    e[i__] = sn * d__[i__ + 1];
822 	    d__[i__ + 1] = cs * d__[i__ + 1];
823 	    work[i__] = cs;
824 	    work[nm1 + i__] = sn;
825 /* L10: */
826 	}
827 
828 /*        Update singular vectors if desired */
829 
830 	if (*nru > 0) {
831 	    dlasr_("R", "V", "F", nru, n, &work[1], &work[*n], &u[u_offset],
832 		    ldu);
833 	}
834 	if (*ncc > 0) {
835 	    dlasr_("L", "V", "F", n, ncc, &work[1], &work[*n], &c__[c_offset],
836 		     ldc);
837 	}
838     }
839 
840 /*
841        Compute singular values to relative accuracy TOL
842        (By setting TOL to be negative, algorithm will compute
843        singular values to absolute accuracy ABS(TOL)*norm(input matrix))
844 
845    Computing MAX
846    Computing MIN
847 */
848     d__3 = 100., d__4 = pow_dd(&eps, &c_b94);
849     d__1 = 10., d__2 = min(d__3,d__4);
850     tolmul = max(d__1,d__2);
851     tol = tolmul * eps;
852 
853 /*     Compute approximate maximum, minimum singular values */
854 
855     smax = 0.;
856     i__1 = *n;
857     for (i__ = 1; i__ <= i__1; ++i__) {
858 /* Computing MAX */
859 	d__2 = smax, d__3 = (d__1 = d__[i__], abs(d__1));
860 	smax = max(d__2,d__3);
861 /* L20: */
862     }
863     i__1 = *n - 1;
864     for (i__ = 1; i__ <= i__1; ++i__) {
865 /* Computing MAX */
866 	d__2 = smax, d__3 = (d__1 = e[i__], abs(d__1));
867 	smax = max(d__2,d__3);
868 /* L30: */
869     }
870     sminl = 0.;
871     if (tol >= 0.) {
872 
873 /*        Relative accuracy desired */
874 
875 	sminoa = abs(d__[1]);
876 	if (sminoa == 0.) {
877 	    goto L50;
878 	}
879 	mu = sminoa;
880 	i__1 = *n;
881 	for (i__ = 2; i__ <= i__1; ++i__) {
882 	    mu = (d__2 = d__[i__], abs(d__2)) * (mu / (mu + (d__1 = e[i__ - 1]
883 		    , abs(d__1))));
884 	    sminoa = min(sminoa,mu);
885 	    if (sminoa == 0.) {
886 		goto L50;
887 	    }
888 /* L40: */
889 	}
890 L50:
891 	sminoa /= sqrt((doublereal) (*n));
892 /* Computing MAX */
893 	d__1 = tol * sminoa, d__2 = *n * 6 * *n * unfl;
894 	thresh = max(d__1,d__2);
895     } else {
896 
897 /*
898           Absolute accuracy desired
899 
900    Computing MAX
901 */
902 	d__1 = abs(tol) * smax, d__2 = *n * 6 * *n * unfl;
903 	thresh = max(d__1,d__2);
904     }
905 
906 /*
907        Prepare for main iteration loop for the singular values
908        (MAXIT is the maximum number of passes through the inner
909        loop permitted before nonconvergence signalled.)
910 */
911 
912     maxit = *n * 6 * *n;
913     iter = 0;
914     oldll = -1;
915     oldm = -1;
916 
917 /*     M points to last element of unconverged part of matrix */
918 
919     m = *n;
920 
921 /*     Begin main iteration loop */
922 
923 L60:
924 
925 /*     Check for convergence or exceeding iteration count */
926 
927     if (m <= 1) {
928 	goto L160;
929     }
930     if (iter > maxit) {
931 	goto L200;
932     }
933 
934 /*     Find diagonal block of matrix to work on */
935 
936     if (tol < 0. && (d__1 = d__[m], abs(d__1)) <= thresh) {
937 	d__[m] = 0.;
938     }
939     smax = (d__1 = d__[m], abs(d__1));
940     smin = smax;
941     i__1 = m - 1;
942     for (lll = 1; lll <= i__1; ++lll) {
943 	ll = m - lll;
944 	abss = (d__1 = d__[ll], abs(d__1));
945 	abse = (d__1 = e[ll], abs(d__1));
946 	if (tol < 0. && abss <= thresh) {
947 	    d__[ll] = 0.;
948 	}
949 	if (abse <= thresh) {
950 	    goto L80;
951 	}
952 	smin = min(smin,abss);
953 /* Computing MAX */
954 	d__1 = max(smax,abss);
955 	smax = max(d__1,abse);
956 /* L70: */
957     }
958     ll = 0;
959     goto L90;
960 L80:
961     e[ll] = 0.;
962 
963 /*     Matrix splits since E(LL) = 0 */
964 
965     if (ll == m - 1) {
966 
967 /*        Convergence of bottom singular value, return to top of loop */
968 
969 	--m;
970 	goto L60;
971     }
972 L90:
973     ++ll;
974 
975 /*     E(LL) through E(M-1) are nonzero, E(LL-1) is zero */
976 
977     if (ll == m - 1) {
978 
979 /*        2 by 2 block, handle separately */
980 
981 	dlasv2_(&d__[m - 1], &e[m - 1], &d__[m], &sigmn, &sigmx, &sinr, &cosr,
982 		 &sinl, &cosl);
983 	d__[m - 1] = sigmx;
984 	e[m - 1] = 0.;
985 	d__[m] = sigmn;
986 
987 /*        Compute singular vectors, if desired */
988 
989 	if (*ncvt > 0) {
990 	    drot_(ncvt, &vt[m - 1 + vt_dim1], ldvt, &vt[m + vt_dim1], ldvt, &
991 		    cosr, &sinr);
992 	}
993 	if (*nru > 0) {
994 	    drot_(nru, &u[(m - 1) * u_dim1 + 1], &c__1, &u[m * u_dim1 + 1], &
995 		    c__1, &cosl, &sinl);
996 	}
997 	if (*ncc > 0) {
998 	    drot_(ncc, &c__[m - 1 + c_dim1], ldc, &c__[m + c_dim1], ldc, &
999 		    cosl, &sinl);
1000 	}
1001 	m += -2;
1002 	goto L60;
1003     }
1004 
1005 /*
1006        If working on new submatrix, choose shift direction
1007        (from larger end diagonal element towards smaller)
1008 */
1009 
1010     if (ll > oldm || m < oldll) {
1011 	if ((d__1 = d__[ll], abs(d__1)) >= (d__2 = d__[m], abs(d__2))) {
1012 
1013 /*           Chase bulge from top (big end) to bottom (small end) */
1014 
1015 	    idir = 1;
1016 	} else {
1017 
1018 /*           Chase bulge from bottom (big end) to top (small end) */
1019 
1020 	    idir = 2;
1021 	}
1022     }
1023 
1024 /*     Apply convergence tests */
1025 
1026     if (idir == 1) {
1027 
1028 /*
1029           Run convergence test in forward direction
1030           First apply standard test to bottom of matrix
1031 */
1032 
1033 	if ((d__2 = e[m - 1], abs(d__2)) <= abs(tol) * (d__1 = d__[m], abs(
1034 		d__1)) || tol < 0. && (d__3 = e[m - 1], abs(d__3)) <= thresh)
1035 		{
1036 	    e[m - 1] = 0.;
1037 	    goto L60;
1038 	}
1039 
1040 	if (tol >= 0.) {
1041 
1042 /*
1043              If relative accuracy desired,
1044              apply convergence criterion forward
1045 */
1046 
1047 	    mu = (d__1 = d__[ll], abs(d__1));
1048 	    sminl = mu;
1049 	    i__1 = m - 1;
1050 	    for (lll = ll; lll <= i__1; ++lll) {
1051 		if ((d__1 = e[lll], abs(d__1)) <= tol * mu) {
1052 		    e[lll] = 0.;
1053 		    goto L60;
1054 		}
1055 		mu = (d__2 = d__[lll + 1], abs(d__2)) * (mu / (mu + (d__1 = e[
1056 			lll], abs(d__1))));
1057 		sminl = min(sminl,mu);
1058 /* L100: */
1059 	    }
1060 	}
1061 
1062     } else {
1063 
1064 /*
1065           Run convergence test in backward direction
1066           First apply standard test to top of matrix
1067 */
1068 
1069 	if ((d__2 = e[ll], abs(d__2)) <= abs(tol) * (d__1 = d__[ll], abs(d__1)
1070 		) || tol < 0. && (d__3 = e[ll], abs(d__3)) <= thresh) {
1071 	    e[ll] = 0.;
1072 	    goto L60;
1073 	}
1074 
1075 	if (tol >= 0.) {
1076 
1077 /*
1078              If relative accuracy desired,
1079              apply convergence criterion backward
1080 */
1081 
1082 	    mu = (d__1 = d__[m], abs(d__1));
1083 	    sminl = mu;
1084 	    i__1 = ll;
1085 	    for (lll = m - 1; lll >= i__1; --lll) {
1086 		if ((d__1 = e[lll], abs(d__1)) <= tol * mu) {
1087 		    e[lll] = 0.;
1088 		    goto L60;
1089 		}
1090 		mu = (d__2 = d__[lll], abs(d__2)) * (mu / (mu + (d__1 = e[lll]
1091 			, abs(d__1))));
1092 		sminl = min(sminl,mu);
1093 /* L110: */
1094 	    }
1095 	}
1096     }
1097     oldll = ll;
1098     oldm = m;
1099 
1100 /*
1101        Compute shift.  First, test if shifting would ruin relative
1102        accuracy, and if so set the shift to zero.
1103 
1104    Computing MAX
1105 */
1106     d__1 = eps, d__2 = tol * .01;
1107     if (tol >= 0. && *n * tol * (sminl / smax) <= max(d__1,d__2)) {
1108 
1109 /*        Use a zero shift to avoid loss of relative accuracy */
1110 
1111 	shift = 0.;
1112     } else {
1113 
1114 /*        Compute the shift from 2-by-2 block at end of matrix */
1115 
1116 	if (idir == 1) {
1117 	    sll = (d__1 = d__[ll], abs(d__1));
1118 	    dlas2_(&d__[m - 1], &e[m - 1], &d__[m], &shift, &r__);
1119 	} else {
1120 	    sll = (d__1 = d__[m], abs(d__1));
1121 	    dlas2_(&d__[ll], &e[ll], &d__[ll + 1], &shift, &r__);
1122 	}
1123 
1124 /*        Test if shift negligible, and if so set to zero */
1125 
1126 	if (sll > 0.) {
1127 /* Computing 2nd power */
1128 	    d__1 = shift / sll;
1129 	    if (d__1 * d__1 < eps) {
1130 		shift = 0.;
1131 	    }
1132 	}
1133     }
1134 
1135 /*     Increment iteration count */
1136 
1137     iter = iter + m - ll;
1138 
1139 /*     If SHIFT = 0, do simplified QR iteration */
1140 
1141     if (shift == 0.) {
1142 	if (idir == 1) {
1143 
1144 /*
1145              Chase bulge from top to bottom
1146              Save cosines and sines for later singular vector updates
1147 */
1148 
1149 	    cs = 1.;
1150 	    oldcs = 1.;
1151 	    i__1 = m - 1;
1152 	    for (i__ = ll; i__ <= i__1; ++i__) {
1153 		d__1 = d__[i__] * cs;
1154 		dlartg_(&d__1, &e[i__], &cs, &sn, &r__);
1155 		if (i__ > ll) {
1156 		    e[i__ - 1] = oldsn * r__;
1157 		}
1158 		d__1 = oldcs * r__;
1159 		d__2 = d__[i__ + 1] * sn;
1160 		dlartg_(&d__1, &d__2, &oldcs, &oldsn, &d__[i__]);
1161 		work[i__ - ll + 1] = cs;
1162 		work[i__ - ll + 1 + nm1] = sn;
1163 		work[i__ - ll + 1 + nm12] = oldcs;
1164 		work[i__ - ll + 1 + nm13] = oldsn;
1165 /* L120: */
1166 	    }
1167 	    h__ = d__[m] * cs;
1168 	    d__[m] = h__ * oldcs;
1169 	    e[m - 1] = h__ * oldsn;
1170 
1171 /*           Update singular vectors */
1172 
1173 	    if (*ncvt > 0) {
1174 		i__1 = m - ll + 1;
1175 		dlasr_("L", "V", "F", &i__1, ncvt, &work[1], &work[*n], &vt[
1176 			ll + vt_dim1], ldvt);
1177 	    }
1178 	    if (*nru > 0) {
1179 		i__1 = m - ll + 1;
1180 		dlasr_("R", "V", "F", nru, &i__1, &work[nm12 + 1], &work[nm13
1181 			+ 1], &u[ll * u_dim1 + 1], ldu);
1182 	    }
1183 	    if (*ncc > 0) {
1184 		i__1 = m - ll + 1;
1185 		dlasr_("L", "V", "F", &i__1, ncc, &work[nm12 + 1], &work[nm13
1186 			+ 1], &c__[ll + c_dim1], ldc);
1187 	    }
1188 
1189 /*           Test convergence */
1190 
1191 	    if ((d__1 = e[m - 1], abs(d__1)) <= thresh) {
1192 		e[m - 1] = 0.;
1193 	    }
1194 
1195 	} else {
1196 
1197 /*
1198              Chase bulge from bottom to top
1199              Save cosines and sines for later singular vector updates
1200 */
1201 
1202 	    cs = 1.;
1203 	    oldcs = 1.;
1204 	    i__1 = ll + 1;
1205 	    for (i__ = m; i__ >= i__1; --i__) {
1206 		d__1 = d__[i__] * cs;
1207 		dlartg_(&d__1, &e[i__ - 1], &cs, &sn, &r__);
1208 		if (i__ < m) {
1209 		    e[i__] = oldsn * r__;
1210 		}
1211 		d__1 = oldcs * r__;
1212 		d__2 = d__[i__ - 1] * sn;
1213 		dlartg_(&d__1, &d__2, &oldcs, &oldsn, &d__[i__]);
1214 		work[i__ - ll] = cs;
1215 		work[i__ - ll + nm1] = -sn;
1216 		work[i__ - ll + nm12] = oldcs;
1217 		work[i__ - ll + nm13] = -oldsn;
1218 /* L130: */
1219 	    }
1220 	    h__ = d__[ll] * cs;
1221 	    d__[ll] = h__ * oldcs;
1222 	    e[ll] = h__ * oldsn;
1223 
1224 /*           Update singular vectors */
1225 
1226 	    if (*ncvt > 0) {
1227 		i__1 = m - ll + 1;
1228 		dlasr_("L", "V", "B", &i__1, ncvt, &work[nm12 + 1], &work[
1229 			nm13 + 1], &vt[ll + vt_dim1], ldvt);
1230 	    }
1231 	    if (*nru > 0) {
1232 		i__1 = m - ll + 1;
1233 		dlasr_("R", "V", "B", nru, &i__1, &work[1], &work[*n], &u[ll *
1234 			 u_dim1 + 1], ldu);
1235 	    }
1236 	    if (*ncc > 0) {
1237 		i__1 = m - ll + 1;
1238 		dlasr_("L", "V", "B", &i__1, ncc, &work[1], &work[*n], &c__[
1239 			ll + c_dim1], ldc);
1240 	    }
1241 
1242 /*           Test convergence */
1243 
1244 	    if ((d__1 = e[ll], abs(d__1)) <= thresh) {
1245 		e[ll] = 0.;
1246 	    }
1247 	}
1248     } else {
1249 
1250 /*        Use nonzero shift */
1251 
1252 	if (idir == 1) {
1253 
1254 /*
1255              Chase bulge from top to bottom
1256              Save cosines and sines for later singular vector updates
1257 */
1258 
1259 	    f = ((d__1 = d__[ll], abs(d__1)) - shift) * (d_sign(&c_b15, &d__[
1260 		    ll]) + shift / d__[ll]);
1261 	    g = e[ll];
1262 	    i__1 = m - 1;
1263 	    for (i__ = ll; i__ <= i__1; ++i__) {
1264 		dlartg_(&f, &g, &cosr, &sinr, &r__);
1265 		if (i__ > ll) {
1266 		    e[i__ - 1] = r__;
1267 		}
1268 		f = cosr * d__[i__] + sinr * e[i__];
1269 		e[i__] = cosr * e[i__] - sinr * d__[i__];
1270 		g = sinr * d__[i__ + 1];
1271 		d__[i__ + 1] = cosr * d__[i__ + 1];
1272 		dlartg_(&f, &g, &cosl, &sinl, &r__);
1273 		d__[i__] = r__;
1274 		f = cosl * e[i__] + sinl * d__[i__ + 1];
1275 		d__[i__ + 1] = cosl * d__[i__ + 1] - sinl * e[i__];
1276 		if (i__ < m - 1) {
1277 		    g = sinl * e[i__ + 1];
1278 		    e[i__ + 1] = cosl * e[i__ + 1];
1279 		}
1280 		work[i__ - ll + 1] = cosr;
1281 		work[i__ - ll + 1 + nm1] = sinr;
1282 		work[i__ - ll + 1 + nm12] = cosl;
1283 		work[i__ - ll + 1 + nm13] = sinl;
1284 /* L140: */
1285 	    }
1286 	    e[m - 1] = f;
1287 
1288 /*           Update singular vectors */
1289 
1290 	    if (*ncvt > 0) {
1291 		i__1 = m - ll + 1;
1292 		dlasr_("L", "V", "F", &i__1, ncvt, &work[1], &work[*n], &vt[
1293 			ll + vt_dim1], ldvt);
1294 	    }
1295 	    if (*nru > 0) {
1296 		i__1 = m - ll + 1;
1297 		dlasr_("R", "V", "F", nru, &i__1, &work[nm12 + 1], &work[nm13
1298 			+ 1], &u[ll * u_dim1 + 1], ldu);
1299 	    }
1300 	    if (*ncc > 0) {
1301 		i__1 = m - ll + 1;
1302 		dlasr_("L", "V", "F", &i__1, ncc, &work[nm12 + 1], &work[nm13
1303 			+ 1], &c__[ll + c_dim1], ldc);
1304 	    }
1305 
1306 /*           Test convergence */
1307 
1308 	    if ((d__1 = e[m - 1], abs(d__1)) <= thresh) {
1309 		e[m - 1] = 0.;
1310 	    }
1311 
1312 	} else {
1313 
1314 /*
1315              Chase bulge from bottom to top
1316              Save cosines and sines for later singular vector updates
1317 */
1318 
1319 	    f = ((d__1 = d__[m], abs(d__1)) - shift) * (d_sign(&c_b15, &d__[m]
1320 		    ) + shift / d__[m]);
1321 	    g = e[m - 1];
1322 	    i__1 = ll + 1;
1323 	    for (i__ = m; i__ >= i__1; --i__) {
1324 		dlartg_(&f, &g, &cosr, &sinr, &r__);
1325 		if (i__ < m) {
1326 		    e[i__] = r__;
1327 		}
1328 		f = cosr * d__[i__] + sinr * e[i__ - 1];
1329 		e[i__ - 1] = cosr * e[i__ - 1] - sinr * d__[i__];
1330 		g = sinr * d__[i__ - 1];
1331 		d__[i__ - 1] = cosr * d__[i__ - 1];
1332 		dlartg_(&f, &g, &cosl, &sinl, &r__);
1333 		d__[i__] = r__;
1334 		f = cosl * e[i__ - 1] + sinl * d__[i__ - 1];
1335 		d__[i__ - 1] = cosl * d__[i__ - 1] - sinl * e[i__ - 1];
1336 		if (i__ > ll + 1) {
1337 		    g = sinl * e[i__ - 2];
1338 		    e[i__ - 2] = cosl * e[i__ - 2];
1339 		}
1340 		work[i__ - ll] = cosr;
1341 		work[i__ - ll + nm1] = -sinr;
1342 		work[i__ - ll + nm12] = cosl;
1343 		work[i__ - ll + nm13] = -sinl;
1344 /* L150: */
1345 	    }
1346 	    e[ll] = f;
1347 
1348 /*           Test convergence */
1349 
1350 	    if ((d__1 = e[ll], abs(d__1)) <= thresh) {
1351 		e[ll] = 0.;
1352 	    }
1353 
1354 /*           Update singular vectors if desired */
1355 
1356 	    if (*ncvt > 0) {
1357 		i__1 = m - ll + 1;
1358 		dlasr_("L", "V", "B", &i__1, ncvt, &work[nm12 + 1], &work[
1359 			nm13 + 1], &vt[ll + vt_dim1], ldvt);
1360 	    }
1361 	    if (*nru > 0) {
1362 		i__1 = m - ll + 1;
1363 		dlasr_("R", "V", "B", nru, &i__1, &work[1], &work[*n], &u[ll *
1364 			 u_dim1 + 1], ldu);
1365 	    }
1366 	    if (*ncc > 0) {
1367 		i__1 = m - ll + 1;
1368 		dlasr_("L", "V", "B", &i__1, ncc, &work[1], &work[*n], &c__[
1369 			ll + c_dim1], ldc);
1370 	    }
1371 	}
1372     }
1373 
1374 /*     QR iteration finished, go back and check convergence */
1375 
1376     goto L60;
1377 
1378 /*     All singular values converged, so make them positive */
1379 
1380 L160:
1381     i__1 = *n;
1382     for (i__ = 1; i__ <= i__1; ++i__) {
1383 	if (d__[i__] < 0.) {
1384 	    d__[i__] = -d__[i__];
1385 
1386 /*           Change sign of singular vectors, if desired */
1387 
1388 	    if (*ncvt > 0) {
1389 		dscal_(ncvt, &c_b151, &vt[i__ + vt_dim1], ldvt);
1390 	    }
1391 	}
1392 /* L170: */
1393     }
1394 
1395 /*
1396        Sort the singular values into decreasing order (insertion sort on
1397        singular values, but only one transposition per singular vector)
1398 */
1399 
1400     i__1 = *n - 1;
1401     for (i__ = 1; i__ <= i__1; ++i__) {
1402 
1403 /*        Scan for smallest D(I) */
1404 
1405 	isub = 1;
1406 	smin = d__[1];
1407 	i__2 = *n + 1 - i__;
1408 	for (j = 2; j <= i__2; ++j) {
1409 	    if (d__[j] <= smin) {
1410 		isub = j;
1411 		smin = d__[j];
1412 	    }
1413 /* L180: */
1414 	}
1415 	if (isub != *n + 1 - i__) {
1416 
1417 /*           Swap singular values and vectors */
1418 
1419 	    d__[isub] = d__[*n + 1 - i__];
1420 	    d__[*n + 1 - i__] = smin;
1421 	    if (*ncvt > 0) {
1422 		dswap_(ncvt, &vt[isub + vt_dim1], ldvt, &vt[*n + 1 - i__ +
1423 			vt_dim1], ldvt);
1424 	    }
1425 	    if (*nru > 0) {
1426 		dswap_(nru, &u[isub * u_dim1 + 1], &c__1, &u[(*n + 1 - i__) *
1427 			u_dim1 + 1], &c__1);
1428 	    }
1429 	    if (*ncc > 0) {
1430 		dswap_(ncc, &c__[isub + c_dim1], ldc, &c__[*n + 1 - i__ +
1431 			c_dim1], ldc);
1432 	    }
1433 	}
1434 /* L190: */
1435     }
1436     goto L220;
1437 
1438 /*     Maximum number of iterations exceeded, failure to converge */
1439 
1440 L200:
1441     *info = 0;
1442     i__1 = *n - 1;
1443     for (i__ = 1; i__ <= i__1; ++i__) {
1444 	if (e[i__] != 0.) {
1445 	    ++(*info);
1446 	}
1447 /* L210: */
1448     }
1449 L220:
1450     return 0;
1451 
1452 /*     End of DBDSQR */
1453 
1454 } /* dbdsqr_ */
1455 
dgebak_(char * job,char * side,integer * n,integer * ilo,integer * ihi,doublereal * scale,integer * m,doublereal * v,integer * ldv,integer * info)1456 /* Subroutine */ int dgebak_(char *job, char *side, integer *n, integer *ilo,
1457 	integer *ihi, doublereal *scale, integer *m, doublereal *v, integer *
1458 	ldv, integer *info)
1459 {
1460     /* System generated locals */
1461     integer v_dim1, v_offset, i__1;
1462 
1463     /* Local variables */
1464     static integer i__, k;
1465     static doublereal s;
1466     static integer ii;
1467     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
1468 	    integer *);
1469     extern logical lsame_(char *, char *);
1470     extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *,
1471 	    doublereal *, integer *);
1472     static logical leftv;
1473     extern /* Subroutine */ int xerbla_(char *, integer *);
1474     static logical rightv;
1475 
1476 
1477 /*
1478     -- LAPACK routine (version 3.2) --
1479     -- LAPACK is a software package provided by Univ. of Tennessee,    --
1480     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
1481        November 2006
1482 
1483 
1484     Purpose
1485     =======
1486 
1487     DGEBAK forms the right or left eigenvectors of a real general matrix
1488     by backward transformation on the computed eigenvectors of the
1489     balanced matrix output by DGEBAL.
1490 
1491     Arguments
1492     =========
1493 
1494     JOB     (input) CHARACTER*1
1495             Specifies the type of backward transformation required:
1496             = 'N', do nothing, return immediately;
1497             = 'P', do backward transformation for permutation only;
1498             = 'S', do backward transformation for scaling only;
1499             = 'B', do backward transformations for both permutation and
1500                    scaling.
1501             JOB must be the same as the argument JOB supplied to DGEBAL.
1502 
1503     SIDE    (input) CHARACTER*1
1504             = 'R':  V contains right eigenvectors;
1505             = 'L':  V contains left eigenvectors.
1506 
1507     N       (input) INTEGER
1508             The number of rows of the matrix V.  N >= 0.
1509 
1510     ILO     (input) INTEGER
1511     IHI     (input) INTEGER
1512             The integers ILO and IHI determined by DGEBAL.
1513             1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
1514 
1515     SCALE   (input) DOUBLE PRECISION array, dimension (N)
1516             Details of the permutation and scaling factors, as returned
1517             by DGEBAL.
1518 
1519     M       (input) INTEGER
1520             The number of columns of the matrix V.  M >= 0.
1521 
1522     V       (input/output) DOUBLE PRECISION array, dimension (LDV,M)
1523             On entry, the matrix of right or left eigenvectors to be
1524             transformed, as returned by DHSEIN or DTREVC.
1525             On exit, V is overwritten by the transformed eigenvectors.
1526 
1527     LDV     (input) INTEGER
1528             The leading dimension of the array V. LDV >= max(1,N).
1529 
1530     INFO    (output) INTEGER
1531             = 0:  successful exit
1532             < 0:  if INFO = -i, the i-th argument had an illegal value.
1533 
1534     =====================================================================
1535 
1536 
1537        Decode and Test the input parameters
1538 */
1539 
1540     /* Parameter adjustments */
1541     --scale;
1542     v_dim1 = *ldv;
1543     v_offset = 1 + v_dim1;
1544     v -= v_offset;
1545 
1546     /* Function Body */
1547     rightv = lsame_(side, "R");
1548     leftv = lsame_(side, "L");
1549 
1550     *info = 0;
1551     if (! lsame_(job, "N") && ! lsame_(job, "P") && ! lsame_(job, "S")
1552 	    && ! lsame_(job, "B")) {
1553 	*info = -1;
1554     } else if (! rightv && ! leftv) {
1555 	*info = -2;
1556     } else if (*n < 0) {
1557 	*info = -3;
1558     } else if (*ilo < 1 || *ilo > max(1,*n)) {
1559 	*info = -4;
1560     } else if (*ihi < min(*ilo,*n) || *ihi > *n) {
1561 	*info = -5;
1562     } else if (*m < 0) {
1563 	*info = -7;
1564     } else if (*ldv < max(1,*n)) {
1565 	*info = -9;
1566     }
1567     if (*info != 0) {
1568 	i__1 = -(*info);
1569 	xerbla_("DGEBAK", &i__1);
1570 	return 0;
1571     }
1572 
1573 /*     Quick return if possible */
1574 
1575     if (*n == 0) {
1576 	return 0;
1577     }
1578     if (*m == 0) {
1579 	return 0;
1580     }
1581     if (lsame_(job, "N")) {
1582 	return 0;
1583     }
1584 
1585     if (*ilo == *ihi) {
1586 	goto L30;
1587     }
1588 
1589 /*     Backward balance */
1590 
1591     if (lsame_(job, "S") || lsame_(job, "B")) {
1592 
1593 	if (rightv) {
1594 	    i__1 = *ihi;
1595 	    for (i__ = *ilo; i__ <= i__1; ++i__) {
1596 		s = scale[i__];
1597 		dscal_(m, &s, &v[i__ + v_dim1], ldv);
1598 /* L10: */
1599 	    }
1600 	}
1601 
1602 	if (leftv) {
1603 	    i__1 = *ihi;
1604 	    for (i__ = *ilo; i__ <= i__1; ++i__) {
1605 		s = 1. / scale[i__];
1606 		dscal_(m, &s, &v[i__ + v_dim1], ldv);
1607 /* L20: */
1608 	    }
1609 	}
1610 
1611     }
1612 
1613 /*
1614        Backward permutation
1615 
1616        For  I = ILO-1 step -1 until 1,
1617                 IHI+1 step 1 until N do --
1618 */
1619 
1620 L30:
1621     if (lsame_(job, "P") || lsame_(job, "B")) {
1622 	if (rightv) {
1623 	    i__1 = *n;
1624 	    for (ii = 1; ii <= i__1; ++ii) {
1625 		i__ = ii;
1626 		if (i__ >= *ilo && i__ <= *ihi) {
1627 		    goto L40;
1628 		}
1629 		if (i__ < *ilo) {
1630 		    i__ = *ilo - ii;
1631 		}
1632 		k = (integer) scale[i__];
1633 		if (k == i__) {
1634 		    goto L40;
1635 		}
1636 		dswap_(m, &v[i__ + v_dim1], ldv, &v[k + v_dim1], ldv);
1637 L40:
1638 		;
1639 	    }
1640 	}
1641 
1642 	if (leftv) {
1643 	    i__1 = *n;
1644 	    for (ii = 1; ii <= i__1; ++ii) {
1645 		i__ = ii;
1646 		if (i__ >= *ilo && i__ <= *ihi) {
1647 		    goto L50;
1648 		}
1649 		if (i__ < *ilo) {
1650 		    i__ = *ilo - ii;
1651 		}
1652 		k = (integer) scale[i__];
1653 		if (k == i__) {
1654 		    goto L50;
1655 		}
1656 		dswap_(m, &v[i__ + v_dim1], ldv, &v[k + v_dim1], ldv);
1657 L50:
1658 		;
1659 	    }
1660 	}
1661     }
1662 
1663     return 0;
1664 
1665 /*     End of DGEBAK */
1666 
1667 } /* dgebak_ */
1668 
dgebal_(char * job,integer * n,doublereal * a,integer * lda,integer * ilo,integer * ihi,doublereal * scale,integer * info)1669 /* Subroutine */ int dgebal_(char *job, integer *n, doublereal *a, integer *
1670 	lda, integer *ilo, integer *ihi, doublereal *scale, integer *info)
1671 {
1672     /* System generated locals */
1673     integer a_dim1, a_offset, i__1, i__2;
1674     doublereal d__1, d__2;
1675 
1676     /* Local variables */
1677     static doublereal c__, f, g;
1678     static integer i__, j, k, l, m;
1679     static doublereal r__, s, ca, ra;
1680     static integer ica, ira, iexc;
1681     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
1682 	    integer *);
1683     extern logical lsame_(char *, char *);
1684     extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *,
1685 	    doublereal *, integer *);
1686     static doublereal sfmin1, sfmin2, sfmax1, sfmax2;
1687 
1688     extern integer idamax_(integer *, doublereal *, integer *);
1689     extern logical disnan_(doublereal *);
1690     extern /* Subroutine */ int xerbla_(char *, integer *);
1691     static logical noconv;
1692 
1693 
1694 /*
1695     -- LAPACK routine (version 3.2.2) --
1696     -- LAPACK is a software package provided by Univ. of Tennessee,    --
1697     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
1698        June 2010
1699 
1700 
1701     Purpose
1702     =======
1703 
1704     DGEBAL balances a general real matrix A.  This involves, first,
1705     permuting A by a similarity transformation to isolate eigenvalues
1706     in the first 1 to ILO-1 and last IHI+1 to N elements on the
1707     diagonal; and second, applying a diagonal similarity transformation
1708     to rows and columns ILO to IHI to make the rows and columns as
1709     close in norm as possible.  Both steps are optional.
1710 
1711     Balancing may reduce the 1-norm of the matrix, and improve the
1712     accuracy of the computed eigenvalues and/or eigenvectors.
1713 
1714     Arguments
1715     =========
1716 
1717     JOB     (input) CHARACTER*1
1718             Specifies the operations to be performed on A:
1719             = 'N':  none:  simply set ILO = 1, IHI = N, SCALE(I) = 1.0
1720                     for i = 1,...,N;
1721             = 'P':  permute only;
1722             = 'S':  scale only;
1723             = 'B':  both permute and scale.
1724 
1725     N       (input) INTEGER
1726             The order of the matrix A.  N >= 0.
1727 
1728     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
1729             On entry, the input matrix A.
1730             On exit,  A is overwritten by the balanced matrix.
1731             If JOB = 'N', A is not referenced.
1732             See Further Details.
1733 
1734     LDA     (input) INTEGER
1735             The leading dimension of the array A.  LDA >= max(1,N).
1736 
1737     ILO     (output) INTEGER
1738     IHI     (output) INTEGER
1739             ILO and IHI are set to integers such that on exit
1740             A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N.
1741             If JOB = 'N' or 'S', ILO = 1 and IHI = N.
1742 
1743     SCALE   (output) DOUBLE PRECISION array, dimension (N)
1744             Details of the permutations and scaling factors applied to
1745             A.  If P(j) is the index of the row and column interchanged
1746             with row and column j and D(j) is the scaling factor
1747             applied to row and column j, then
1748             SCALE(j) = P(j)    for j = 1,...,ILO-1
1749                      = D(j)    for j = ILO,...,IHI
1750                      = P(j)    for j = IHI+1,...,N.
1751             The order in which the interchanges are made is N to IHI+1,
1752             then 1 to ILO-1.
1753 
1754     INFO    (output) INTEGER
1755             = 0:  successful exit.
1756             < 0:  if INFO = -i, the i-th argument had an illegal value.
1757 
1758     Further Details
1759     ===============
1760 
1761     The permutations consist of row and column interchanges which put
1762     the matrix in the form
1763 
1764                ( T1   X   Y  )
1765        P A P = (  0   B   Z  )
1766                (  0   0   T2 )
1767 
1768     where T1 and T2 are upper triangular matrices whose eigenvalues lie
1769     along the diagonal.  The column indices ILO and IHI mark the starting
1770     and ending columns of the submatrix B. Balancing consists of applying
1771     a diagonal similarity transformation inv(D) * B * D to make the
1772     1-norms of each row of B and its corresponding column nearly equal.
1773     The output matrix is
1774 
1775        ( T1     X*D          Y    )
1776        (  0  inv(D)*B*D  inv(D)*Z ).
1777        (  0      0           T2   )
1778 
1779     Information about the permutations P and the diagonal matrix D is
1780     returned in the vector SCALE.
1781 
1782     This subroutine is based on the EISPACK routine BALANC.
1783 
1784     Modified by Tzu-Yi Chen, Computer Science Division, University of
1785       California at Berkeley, USA
1786 
1787     =====================================================================
1788 
1789 
1790        Test the input parameters
1791 */
1792 
1793     /* Parameter adjustments */
1794     a_dim1 = *lda;
1795     a_offset = 1 + a_dim1;
1796     a -= a_offset;
1797     --scale;
1798 
1799     /* Function Body */
1800     *info = 0;
1801     if (! lsame_(job, "N") && ! lsame_(job, "P") && ! lsame_(job, "S")
1802 	    && ! lsame_(job, "B")) {
1803 	*info = -1;
1804     } else if (*n < 0) {
1805 	*info = -2;
1806     } else if (*lda < max(1,*n)) {
1807 	*info = -4;
1808     }
1809     if (*info != 0) {
1810 	i__1 = -(*info);
1811 	xerbla_("DGEBAL", &i__1);
1812 	return 0;
1813     }
1814 
1815     k = 1;
1816     l = *n;
1817 
1818     if (*n == 0) {
1819 	goto L210;
1820     }
1821 
1822     if (lsame_(job, "N")) {
1823 	i__1 = *n;
1824 	for (i__ = 1; i__ <= i__1; ++i__) {
1825 	    scale[i__] = 1.;
1826 /* L10: */
1827 	}
1828 	goto L210;
1829     }
1830 
1831     if (lsame_(job, "S")) {
1832 	goto L120;
1833     }
1834 
1835 /*     Permutation to isolate eigenvalues if possible */
1836 
1837     goto L50;
1838 
1839 /*     Row and column exchange. */
1840 
1841 L20:
1842     scale[m] = (doublereal) j;
1843     if (j == m) {
1844 	goto L30;
1845     }
1846 
1847     dswap_(&l, &a[j * a_dim1 + 1], &c__1, &a[m * a_dim1 + 1], &c__1);
1848     i__1 = *n - k + 1;
1849     dswap_(&i__1, &a[j + k * a_dim1], lda, &a[m + k * a_dim1], lda);
1850 
1851 L30:
1852     switch (iexc) {
1853 	case 1:  goto L40;
1854 	case 2:  goto L80;
1855     }
1856 
1857 /*     Search for rows isolating an eigenvalue and push them down. */
1858 
1859 L40:
1860     if (l == 1) {
1861 	goto L210;
1862     }
1863     --l;
1864 
1865 L50:
1866     for (j = l; j >= 1; --j) {
1867 
1868 	i__1 = l;
1869 	for (i__ = 1; i__ <= i__1; ++i__) {
1870 	    if (i__ == j) {
1871 		goto L60;
1872 	    }
1873 	    if (a[j + i__ * a_dim1] != 0.) {
1874 		goto L70;
1875 	    }
1876 L60:
1877 	    ;
1878 	}
1879 
1880 	m = l;
1881 	iexc = 1;
1882 	goto L20;
1883 L70:
1884 	;
1885     }
1886 
1887     goto L90;
1888 
1889 /*     Search for columns isolating an eigenvalue and push them left. */
1890 
1891 L80:
1892     ++k;
1893 
1894 L90:
1895     i__1 = l;
1896     for (j = k; j <= i__1; ++j) {
1897 
1898 	i__2 = l;
1899 	for (i__ = k; i__ <= i__2; ++i__) {
1900 	    if (i__ == j) {
1901 		goto L100;
1902 	    }
1903 	    if (a[i__ + j * a_dim1] != 0.) {
1904 		goto L110;
1905 	    }
1906 L100:
1907 	    ;
1908 	}
1909 
1910 	m = k;
1911 	iexc = 2;
1912 	goto L20;
1913 L110:
1914 	;
1915     }
1916 
1917 L120:
1918     i__1 = l;
1919     for (i__ = k; i__ <= i__1; ++i__) {
1920 	scale[i__] = 1.;
1921 /* L130: */
1922     }
1923 
1924     if (lsame_(job, "P")) {
1925 	goto L210;
1926     }
1927 
1928 /*
1929        Balance the submatrix in rows K to L.
1930 
1931        Iterative loop for norm reduction
1932 */
1933 
1934     sfmin1 = SAFEMINIMUM / PRECISION;
1935     sfmax1 = 1. / sfmin1;
1936     sfmin2 = sfmin1 * 2.;
1937     sfmax2 = 1. / sfmin2;
1938 L140:
1939     noconv = FALSE_;
1940 
1941     i__1 = l;
1942     for (i__ = k; i__ <= i__1; ++i__) {
1943 	c__ = 0.;
1944 	r__ = 0.;
1945 
1946 	i__2 = l;
1947 	for (j = k; j <= i__2; ++j) {
1948 	    if (j == i__) {
1949 		goto L150;
1950 	    }
1951 	    c__ += (d__1 = a[j + i__ * a_dim1], abs(d__1));
1952 	    r__ += (d__1 = a[i__ + j * a_dim1], abs(d__1));
1953 L150:
1954 	    ;
1955 	}
1956 	ica = idamax_(&l, &a[i__ * a_dim1 + 1], &c__1);
1957 	ca = (d__1 = a[ica + i__ * a_dim1], abs(d__1));
1958 	i__2 = *n - k + 1;
1959 	ira = idamax_(&i__2, &a[i__ + k * a_dim1], lda);
1960 	ra = (d__1 = a[i__ + (ira + k - 1) * a_dim1], abs(d__1));
1961 
1962 /*        Guard against zero C or R due to underflow. */
1963 
1964 	if (c__ == 0. || r__ == 0.) {
1965 	    goto L200;
1966 	}
1967 	g = r__ / 2.;
1968 	f = 1.;
1969 	s = c__ + r__;
1970 L160:
1971 /* Computing MAX */
1972 	d__1 = max(f,c__);
1973 /* Computing MIN */
1974 	d__2 = min(r__,g);
1975 	if (c__ >= g || max(d__1,ca) >= sfmax2 || min(d__2,ra) <= sfmin2) {
1976 	    goto L170;
1977 	}
1978 	d__1 = c__ + f + ca + r__ + g + ra;
1979 	if (disnan_(&d__1)) {
1980 
1981 /*           Exit if NaN to avoid infinite loop */
1982 
1983 	    *info = -3;
1984 	    i__2 = -(*info);
1985 	    xerbla_("DGEBAL", &i__2);
1986 	    return 0;
1987 	}
1988 	f *= 2.;
1989 	c__ *= 2.;
1990 	ca *= 2.;
1991 	r__ /= 2.;
1992 	g /= 2.;
1993 	ra /= 2.;
1994 	goto L160;
1995 
1996 L170:
1997 	g = c__ / 2.;
1998 L180:
1999 /* Computing MIN */
2000 	d__1 = min(f,c__), d__1 = min(d__1,g);
2001 	if (g < r__ || max(r__,ra) >= sfmax2 || min(d__1,ca) <= sfmin2) {
2002 	    goto L190;
2003 	}
2004 	f /= 2.;
2005 	c__ /= 2.;
2006 	g /= 2.;
2007 	ca /= 2.;
2008 	r__ *= 2.;
2009 	ra *= 2.;
2010 	goto L180;
2011 
2012 /*        Now balance. */
2013 
2014 L190:
2015 	if (c__ + r__ >= s * .95) {
2016 	    goto L200;
2017 	}
2018 	if (f < 1. && scale[i__] < 1.) {
2019 	    if (f * scale[i__] <= sfmin1) {
2020 		goto L200;
2021 	    }
2022 	}
2023 	if (f > 1. && scale[i__] > 1.) {
2024 	    if (scale[i__] >= sfmax1 / f) {
2025 		goto L200;
2026 	    }
2027 	}
2028 	g = 1. / f;
2029 	scale[i__] *= f;
2030 	noconv = TRUE_;
2031 
2032 	i__2 = *n - k + 1;
2033 	dscal_(&i__2, &g, &a[i__ + k * a_dim1], lda);
2034 	dscal_(&l, &f, &a[i__ * a_dim1 + 1], &c__1);
2035 
2036 L200:
2037 	;
2038     }
2039 
2040     if (noconv) {
2041 	goto L140;
2042     }
2043 
2044 L210:
2045     *ilo = k;
2046     *ihi = l;
2047 
2048     return 0;
2049 
2050 /*     End of DGEBAL */
2051 
2052 } /* dgebal_ */
2053 
dgebd2_(integer * m,integer * n,doublereal * a,integer * lda,doublereal * d__,doublereal * e,doublereal * tauq,doublereal * taup,doublereal * work,integer * info)2054 /* Subroutine */ int dgebd2_(integer *m, integer *n, doublereal *a, integer *
2055 	lda, doublereal *d__, doublereal *e, doublereal *tauq, doublereal *
2056 	taup, doublereal *work, integer *info)
2057 {
2058     /* System generated locals */
2059     integer a_dim1, a_offset, i__1, i__2, i__3;
2060 
2061     /* Local variables */
2062     static integer i__;
2063     extern /* Subroutine */ int dlarf_(char *, integer *, integer *,
2064 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
2065 	    doublereal *), dlarfg_(integer *, doublereal *,
2066 	    doublereal *, integer *, doublereal *), xerbla_(char *, integer *);
2067 
2068 
2069 /*
2070     -- LAPACK routine (version 3.2) --
2071     -- LAPACK is a software package provided by Univ. of Tennessee,    --
2072     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
2073        November 2006
2074 
2075 
2076     Purpose
2077     =======
2078 
2079     DGEBD2 reduces a real general m by n matrix A to upper or lower
2080     bidiagonal form B by an orthogonal transformation: Q' * A * P = B.
2081 
2082     If m >= n, B is upper bidiagonal; if m < n, B is lower bidiagonal.
2083 
2084     Arguments
2085     =========
2086 
2087     M       (input) INTEGER
2088             The number of rows in the matrix A.  M >= 0.
2089 
2090     N       (input) INTEGER
2091             The number of columns in the matrix A.  N >= 0.
2092 
2093     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
2094             On entry, the m by n general matrix to be reduced.
2095             On exit,
2096             if m >= n, the diagonal and the first superdiagonal are
2097               overwritten with the upper bidiagonal matrix B; the
2098               elements below the diagonal, with the array TAUQ, represent
2099               the orthogonal matrix Q as a product of elementary
2100               reflectors, and the elements above the first superdiagonal,
2101               with the array TAUP, represent the orthogonal matrix P as
2102               a product of elementary reflectors;
2103             if m < n, the diagonal and the first subdiagonal are
2104               overwritten with the lower bidiagonal matrix B; the
2105               elements below the first subdiagonal, with the array TAUQ,
2106               represent the orthogonal matrix Q as a product of
2107               elementary reflectors, and the elements above the diagonal,
2108               with the array TAUP, represent the orthogonal matrix P as
2109               a product of elementary reflectors.
2110             See Further Details.
2111 
2112     LDA     (input) INTEGER
2113             The leading dimension of the array A.  LDA >= max(1,M).
2114 
2115     D       (output) DOUBLE PRECISION array, dimension (min(M,N))
2116             The diagonal elements of the bidiagonal matrix B:
2117             D(i) = A(i,i).
2118 
2119     E       (output) DOUBLE PRECISION array, dimension (min(M,N)-1)
2120             The off-diagonal elements of the bidiagonal matrix B:
2121             if m >= n, E(i) = A(i,i+1) for i = 1,2,...,n-1;
2122             if m < n, E(i) = A(i+1,i) for i = 1,2,...,m-1.
2123 
2124     TAUQ    (output) DOUBLE PRECISION array dimension (min(M,N))
2125             The scalar factors of the elementary reflectors which
2126             represent the orthogonal matrix Q. See Further Details.
2127 
2128     TAUP    (output) DOUBLE PRECISION array, dimension (min(M,N))
2129             The scalar factors of the elementary reflectors which
2130             represent the orthogonal matrix P. See Further Details.
2131 
2132     WORK    (workspace) DOUBLE PRECISION array, dimension (max(M,N))
2133 
2134     INFO    (output) INTEGER
2135             = 0: successful exit.
2136             < 0: if INFO = -i, the i-th argument had an illegal value.
2137 
2138     Further Details
2139     ===============
2140 
2141     The matrices Q and P are represented as products of elementary
2142     reflectors:
2143 
2144     If m >= n,
2145 
2146        Q = H(1) H(2) . . . H(n)  and  P = G(1) G(2) . . . G(n-1)
2147 
2148     Each H(i) and G(i) has the form:
2149 
2150        H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u'
2151 
2152     where tauq and taup are real scalars, and v and u are real vectors;
2153     v(1:i-1) = 0, v(i) = 1, and v(i+1:m) is stored on exit in A(i+1:m,i);
2154     u(1:i) = 0, u(i+1) = 1, and u(i+2:n) is stored on exit in A(i,i+2:n);
2155     tauq is stored in TAUQ(i) and taup in TAUP(i).
2156 
2157     If m < n,
2158 
2159        Q = H(1) H(2) . . . H(m-1)  and  P = G(1) G(2) . . . G(m)
2160 
2161     Each H(i) and G(i) has the form:
2162 
2163        H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u'
2164 
2165     where tauq and taup are real scalars, and v and u are real vectors;
2166     v(1:i) = 0, v(i+1) = 1, and v(i+2:m) is stored on exit in A(i+2:m,i);
2167     u(1:i-1) = 0, u(i) = 1, and u(i+1:n) is stored on exit in A(i,i+1:n);
2168     tauq is stored in TAUQ(i) and taup in TAUP(i).
2169 
2170     The contents of A on exit are illustrated by the following examples:
2171 
2172     m = 6 and n = 5 (m > n):          m = 5 and n = 6 (m < n):
2173 
2174       (  d   e   u1  u1  u1 )           (  d   u1  u1  u1  u1  u1 )
2175       (  v1  d   e   u2  u2 )           (  e   d   u2  u2  u2  u2 )
2176       (  v1  v2  d   e   u3 )           (  v1  e   d   u3  u3  u3 )
2177       (  v1  v2  v3  d   e  )           (  v1  v2  e   d   u4  u4 )
2178       (  v1  v2  v3  v4  d  )           (  v1  v2  v3  e   d   u5 )
2179       (  v1  v2  v3  v4  v5 )
2180 
2181     where d and e denote diagonal and off-diagonal elements of B, vi
2182     denotes an element of the vector defining H(i), and ui an element of
2183     the vector defining G(i).
2184 
2185     =====================================================================
2186 
2187 
2188        Test the input parameters
2189 */
2190 
2191     /* Parameter adjustments */
2192     a_dim1 = *lda;
2193     a_offset = 1 + a_dim1;
2194     a -= a_offset;
2195     --d__;
2196     --e;
2197     --tauq;
2198     --taup;
2199     --work;
2200 
2201     /* Function Body */
2202     *info = 0;
2203     if (*m < 0) {
2204 	*info = -1;
2205     } else if (*n < 0) {
2206 	*info = -2;
2207     } else if (*lda < max(1,*m)) {
2208 	*info = -4;
2209     }
2210     if (*info < 0) {
2211 	i__1 = -(*info);
2212 	xerbla_("DGEBD2", &i__1);
2213 	return 0;
2214     }
2215 
2216     if (*m >= *n) {
2217 
2218 /*        Reduce to upper bidiagonal form */
2219 
2220 	i__1 = *n;
2221 	for (i__ = 1; i__ <= i__1; ++i__) {
2222 
2223 /*           Generate elementary reflector H(i) to annihilate A(i+1:m,i) */
2224 
2225 	    i__2 = *m - i__ + 1;
2226 /* Computing MIN */
2227 	    i__3 = i__ + 1;
2228 	    dlarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[min(i__3,*m) + i__ *
2229 		    a_dim1], &c__1, &tauq[i__]);
2230 	    d__[i__] = a[i__ + i__ * a_dim1];
2231 	    a[i__ + i__ * a_dim1] = 1.;
2232 
2233 /*           Apply H(i) to A(i:m,i+1:n) from the left */
2234 
2235 	    if (i__ < *n) {
2236 		i__2 = *m - i__ + 1;
2237 		i__3 = *n - i__;
2238 		dlarf_("Left", &i__2, &i__3, &a[i__ + i__ * a_dim1], &c__1, &
2239 			tauq[i__], &a[i__ + (i__ + 1) * a_dim1], lda, &work[1]
2240 			);
2241 	    }
2242 	    a[i__ + i__ * a_dim1] = d__[i__];
2243 
2244 	    if (i__ < *n) {
2245 
2246 /*
2247                 Generate elementary reflector G(i) to annihilate
2248                 A(i,i+2:n)
2249 */
2250 
2251 		i__2 = *n - i__;
2252 /* Computing MIN */
2253 		i__3 = i__ + 2;
2254 		dlarfg_(&i__2, &a[i__ + (i__ + 1) * a_dim1], &a[i__ + min(
2255 			i__3,*n) * a_dim1], lda, &taup[i__]);
2256 		e[i__] = a[i__ + (i__ + 1) * a_dim1];
2257 		a[i__ + (i__ + 1) * a_dim1] = 1.;
2258 
2259 /*              Apply G(i) to A(i+1:m,i+1:n) from the right */
2260 
2261 		i__2 = *m - i__;
2262 		i__3 = *n - i__;
2263 		dlarf_("Right", &i__2, &i__3, &a[i__ + (i__ + 1) * a_dim1],
2264 			lda, &taup[i__], &a[i__ + 1 + (i__ + 1) * a_dim1],
2265 			lda, &work[1]);
2266 		a[i__ + (i__ + 1) * a_dim1] = e[i__];
2267 	    } else {
2268 		taup[i__] = 0.;
2269 	    }
2270 /* L10: */
2271 	}
2272     } else {
2273 
2274 /*        Reduce to lower bidiagonal form */
2275 
2276 	i__1 = *m;
2277 	for (i__ = 1; i__ <= i__1; ++i__) {
2278 
2279 /*           Generate elementary reflector G(i) to annihilate A(i,i+1:n) */
2280 
2281 	    i__2 = *n - i__ + 1;
2282 /* Computing MIN */
2283 	    i__3 = i__ + 1;
2284 	    dlarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[i__ + min(i__3,*n) *
2285 		    a_dim1], lda, &taup[i__]);
2286 	    d__[i__] = a[i__ + i__ * a_dim1];
2287 	    a[i__ + i__ * a_dim1] = 1.;
2288 
2289 /*           Apply G(i) to A(i+1:m,i:n) from the right */
2290 
2291 	    if (i__ < *m) {
2292 		i__2 = *m - i__;
2293 		i__3 = *n - i__ + 1;
2294 		dlarf_("Right", &i__2, &i__3, &a[i__ + i__ * a_dim1], lda, &
2295 			taup[i__], &a[i__ + 1 + i__ * a_dim1], lda, &work[1]);
2296 	    }
2297 	    a[i__ + i__ * a_dim1] = d__[i__];
2298 
2299 	    if (i__ < *m) {
2300 
2301 /*
2302                 Generate elementary reflector H(i) to annihilate
2303                 A(i+2:m,i)
2304 */
2305 
2306 		i__2 = *m - i__;
2307 /* Computing MIN */
2308 		i__3 = i__ + 2;
2309 		dlarfg_(&i__2, &a[i__ + 1 + i__ * a_dim1], &a[min(i__3,*m) +
2310 			i__ * a_dim1], &c__1, &tauq[i__]);
2311 		e[i__] = a[i__ + 1 + i__ * a_dim1];
2312 		a[i__ + 1 + i__ * a_dim1] = 1.;
2313 
2314 /*              Apply H(i) to A(i+1:m,i+1:n) from the left */
2315 
2316 		i__2 = *m - i__;
2317 		i__3 = *n - i__;
2318 		dlarf_("Left", &i__2, &i__3, &a[i__ + 1 + i__ * a_dim1], &
2319 			c__1, &tauq[i__], &a[i__ + 1 + (i__ + 1) * a_dim1],
2320 			lda, &work[1]);
2321 		a[i__ + 1 + i__ * a_dim1] = e[i__];
2322 	    } else {
2323 		tauq[i__] = 0.;
2324 	    }
2325 /* L20: */
2326 	}
2327     }
2328     return 0;
2329 
2330 /*     End of DGEBD2 */
2331 
2332 } /* dgebd2_ */
2333 
dgebrd_(integer * m,integer * n,doublereal * a,integer * lda,doublereal * d__,doublereal * e,doublereal * tauq,doublereal * taup,doublereal * work,integer * lwork,integer * info)2334 /* Subroutine */ int dgebrd_(integer *m, integer *n, doublereal *a, integer *
2335 	lda, doublereal *d__, doublereal *e, doublereal *tauq, doublereal *
2336 	taup, doublereal *work, integer *lwork, integer *info)
2337 {
2338     /* System generated locals */
2339     integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
2340 
2341     /* Local variables */
2342     static integer i__, j, nb, nx;
2343     static doublereal ws;
2344     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
2345 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
2346 	    integer *, doublereal *, doublereal *, integer *);
2347     static integer nbmin, iinfo, minmn;
2348     extern /* Subroutine */ int dgebd2_(integer *, integer *, doublereal *,
2349 	    integer *, doublereal *, doublereal *, doublereal *, doublereal *,
2350 	     doublereal *, integer *), dlabrd_(integer *, integer *, integer *
2351 	    , doublereal *, integer *, doublereal *, doublereal *, doublereal
2352 	    *, doublereal *, doublereal *, integer *, doublereal *, integer *)
2353 	    , xerbla_(char *, integer *);
2354     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
2355 	    integer *, integer *, ftnlen, ftnlen);
2356     static integer ldwrkx, ldwrky, lwkopt;
2357     static logical lquery;
2358 
2359 
2360 /*
2361     -- LAPACK routine (version 3.2) --
2362     -- LAPACK is a software package provided by Univ. of Tennessee,    --
2363     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
2364        November 2006
2365 
2366 
2367     Purpose
2368     =======
2369 
2370     DGEBRD reduces a general real M-by-N matrix A to upper or lower
2371     bidiagonal form B by an orthogonal transformation: Q**T * A * P = B.
2372 
2373     If m >= n, B is upper bidiagonal; if m < n, B is lower bidiagonal.
2374 
2375     Arguments
2376     =========
2377 
2378     M       (input) INTEGER
2379             The number of rows in the matrix A.  M >= 0.
2380 
2381     N       (input) INTEGER
2382             The number of columns in the matrix A.  N >= 0.
2383 
2384     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
2385             On entry, the M-by-N general matrix to be reduced.
2386             On exit,
2387             if m >= n, the diagonal and the first superdiagonal are
2388               overwritten with the upper bidiagonal matrix B; the
2389               elements below the diagonal, with the array TAUQ, represent
2390               the orthogonal matrix Q as a product of elementary
2391               reflectors, and the elements above the first superdiagonal,
2392               with the array TAUP, represent the orthogonal matrix P as
2393               a product of elementary reflectors;
2394             if m < n, the diagonal and the first subdiagonal are
2395               overwritten with the lower bidiagonal matrix B; the
2396               elements below the first subdiagonal, with the array TAUQ,
2397               represent the orthogonal matrix Q as a product of
2398               elementary reflectors, and the elements above the diagonal,
2399               with the array TAUP, represent the orthogonal matrix P as
2400               a product of elementary reflectors.
2401             See Further Details.
2402 
2403     LDA     (input) INTEGER
2404             The leading dimension of the array A.  LDA >= max(1,M).
2405 
2406     D       (output) DOUBLE PRECISION array, dimension (min(M,N))
2407             The diagonal elements of the bidiagonal matrix B:
2408             D(i) = A(i,i).
2409 
2410     E       (output) DOUBLE PRECISION array, dimension (min(M,N)-1)
2411             The off-diagonal elements of the bidiagonal matrix B:
2412             if m >= n, E(i) = A(i,i+1) for i = 1,2,...,n-1;
2413             if m < n, E(i) = A(i+1,i) for i = 1,2,...,m-1.
2414 
2415     TAUQ    (output) DOUBLE PRECISION array dimension (min(M,N))
2416             The scalar factors of the elementary reflectors which
2417             represent the orthogonal matrix Q. See Further Details.
2418 
2419     TAUP    (output) DOUBLE PRECISION array, dimension (min(M,N))
2420             The scalar factors of the elementary reflectors which
2421             represent the orthogonal matrix P. See Further Details.
2422 
2423     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
2424             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
2425 
2426     LWORK   (input) INTEGER
2427             The length of the array WORK.  LWORK >= max(1,M,N).
2428             For optimum performance LWORK >= (M+N)*NB, where NB
2429             is the optimal blocksize.
2430 
2431             If LWORK = -1, then a workspace query is assumed; the routine
2432             only calculates the optimal size of the WORK array, returns
2433             this value as the first entry of the WORK array, and no error
2434             message related to LWORK is issued by XERBLA.
2435 
2436     INFO    (output) INTEGER
2437             = 0:  successful exit
2438             < 0:  if INFO = -i, the i-th argument had an illegal value.
2439 
2440     Further Details
2441     ===============
2442 
2443     The matrices Q and P are represented as products of elementary
2444     reflectors:
2445 
2446     If m >= n,
2447 
2448        Q = H(1) H(2) . . . H(n)  and  P = G(1) G(2) . . . G(n-1)
2449 
2450     Each H(i) and G(i) has the form:
2451 
2452        H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u'
2453 
2454     where tauq and taup are real scalars, and v and u are real vectors;
2455     v(1:i-1) = 0, v(i) = 1, and v(i+1:m) is stored on exit in A(i+1:m,i);
2456     u(1:i) = 0, u(i+1) = 1, and u(i+2:n) is stored on exit in A(i,i+2:n);
2457     tauq is stored in TAUQ(i) and taup in TAUP(i).
2458 
2459     If m < n,
2460 
2461        Q = H(1) H(2) . . . H(m-1)  and  P = G(1) G(2) . . . G(m)
2462 
2463     Each H(i) and G(i) has the form:
2464 
2465        H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u'
2466 
2467     where tauq and taup are real scalars, and v and u are real vectors;
2468     v(1:i) = 0, v(i+1) = 1, and v(i+2:m) is stored on exit in A(i+2:m,i);
2469     u(1:i-1) = 0, u(i) = 1, and u(i+1:n) is stored on exit in A(i,i+1:n);
2470     tauq is stored in TAUQ(i) and taup in TAUP(i).
2471 
2472     The contents of A on exit are illustrated by the following examples:
2473 
2474     m = 6 and n = 5 (m > n):          m = 5 and n = 6 (m < n):
2475 
2476       (  d   e   u1  u1  u1 )           (  d   u1  u1  u1  u1  u1 )
2477       (  v1  d   e   u2  u2 )           (  e   d   u2  u2  u2  u2 )
2478       (  v1  v2  d   e   u3 )           (  v1  e   d   u3  u3  u3 )
2479       (  v1  v2  v3  d   e  )           (  v1  v2  e   d   u4  u4 )
2480       (  v1  v2  v3  v4  d  )           (  v1  v2  v3  e   d   u5 )
2481       (  v1  v2  v3  v4  v5 )
2482 
2483     where d and e denote diagonal and off-diagonal elements of B, vi
2484     denotes an element of the vector defining H(i), and ui an element of
2485     the vector defining G(i).
2486 
2487     =====================================================================
2488 
2489 
2490        Test the input parameters
2491 */
2492 
2493     /* Parameter adjustments */
2494     a_dim1 = *lda;
2495     a_offset = 1 + a_dim1;
2496     a -= a_offset;
2497     --d__;
2498     --e;
2499     --tauq;
2500     --taup;
2501     --work;
2502 
2503     /* Function Body */
2504     *info = 0;
2505 /* Computing MAX */
2506     i__1 = 1, i__2 = ilaenv_(&c__1, "DGEBRD", " ", m, n, &c_n1, &c_n1, (
2507 	    ftnlen)6, (ftnlen)1);
2508     nb = max(i__1,i__2);
2509     lwkopt = (*m + *n) * nb;
2510     work[1] = (doublereal) lwkopt;
2511     lquery = *lwork == -1;
2512     if (*m < 0) {
2513 	*info = -1;
2514     } else if (*n < 0) {
2515 	*info = -2;
2516     } else if (*lda < max(1,*m)) {
2517 	*info = -4;
2518     } else /* if(complicated condition) */ {
2519 /* Computing MAX */
2520 	i__1 = max(1,*m);
2521 	if (*lwork < max(i__1,*n) && ! lquery) {
2522 	    *info = -10;
2523 	}
2524     }
2525     if (*info < 0) {
2526 	i__1 = -(*info);
2527 	xerbla_("DGEBRD", &i__1);
2528 	return 0;
2529     } else if (lquery) {
2530 	return 0;
2531     }
2532 
2533 /*     Quick return if possible */
2534 
2535     minmn = min(*m,*n);
2536     if (minmn == 0) {
2537 	work[1] = 1.;
2538 	return 0;
2539     }
2540 
2541     ws = (doublereal) max(*m,*n);
2542     ldwrkx = *m;
2543     ldwrky = *n;
2544 
2545     if (nb > 1 && nb < minmn) {
2546 
2547 /*
2548           Set the crossover point NX.
2549 
2550    Computing MAX
2551 */
2552 	i__1 = nb, i__2 = ilaenv_(&c__3, "DGEBRD", " ", m, n, &c_n1, &c_n1, (
2553 		ftnlen)6, (ftnlen)1);
2554 	nx = max(i__1,i__2);
2555 
2556 /*        Determine when to switch from blocked to unblocked code. */
2557 
2558 	if (nx < minmn) {
2559 	    ws = (doublereal) ((*m + *n) * nb);
2560 	    if ((doublereal) (*lwork) < ws) {
2561 
2562 /*
2563                 Not enough work space for the optimal NB, consider using
2564                 a smaller block size.
2565 */
2566 
2567 		nbmin = ilaenv_(&c__2, "DGEBRD", " ", m, n, &c_n1, &c_n1, (
2568 			ftnlen)6, (ftnlen)1);
2569 		if (*lwork >= (*m + *n) * nbmin) {
2570 		    nb = *lwork / (*m + *n);
2571 		} else {
2572 		    nb = 1;
2573 		    nx = minmn;
2574 		}
2575 	    }
2576 	}
2577     } else {
2578 	nx = minmn;
2579     }
2580 
2581     i__1 = minmn - nx;
2582     i__2 = nb;
2583     for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
2584 
2585 /*
2586           Reduce rows and columns i:i+nb-1 to bidiagonal form and return
2587           the matrices X and Y which are needed to update the unreduced
2588           part of the matrix
2589 */
2590 
2591 	i__3 = *m - i__ + 1;
2592 	i__4 = *n - i__ + 1;
2593 	dlabrd_(&i__3, &i__4, &nb, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[
2594 		i__], &tauq[i__], &taup[i__], &work[1], &ldwrkx, &work[ldwrkx
2595 		* nb + 1], &ldwrky);
2596 
2597 /*
2598           Update the trailing submatrix A(i+nb:m,i+nb:n), using an update
2599           of the form  A := A - V*Y' - X*U'
2600 */
2601 
2602 	i__3 = *m - i__ - nb + 1;
2603 	i__4 = *n - i__ - nb + 1;
2604 	dgemm_("No transpose", "Transpose", &i__3, &i__4, &nb, &c_b151, &a[
2605 		i__ + nb + i__ * a_dim1], lda, &work[ldwrkx * nb + nb + 1], &
2606 		ldwrky, &c_b15, &a[i__ + nb + (i__ + nb) * a_dim1], lda);
2607 	i__3 = *m - i__ - nb + 1;
2608 	i__4 = *n - i__ - nb + 1;
2609 	dgemm_("No transpose", "No transpose", &i__3, &i__4, &nb, &c_b151, &
2610 		work[nb + 1], &ldwrkx, &a[i__ + (i__ + nb) * a_dim1], lda, &
2611 		c_b15, &a[i__ + nb + (i__ + nb) * a_dim1], lda);
2612 
2613 /*        Copy diagonal and off-diagonal elements of B back into A */
2614 
2615 	if (*m >= *n) {
2616 	    i__3 = i__ + nb - 1;
2617 	    for (j = i__; j <= i__3; ++j) {
2618 		a[j + j * a_dim1] = d__[j];
2619 		a[j + (j + 1) * a_dim1] = e[j];
2620 /* L10: */
2621 	    }
2622 	} else {
2623 	    i__3 = i__ + nb - 1;
2624 	    for (j = i__; j <= i__3; ++j) {
2625 		a[j + j * a_dim1] = d__[j];
2626 		a[j + 1 + j * a_dim1] = e[j];
2627 /* L20: */
2628 	    }
2629 	}
2630 /* L30: */
2631     }
2632 
2633 /*     Use unblocked code to reduce the remainder of the matrix */
2634 
2635     i__2 = *m - i__ + 1;
2636     i__1 = *n - i__ + 1;
2637     dgebd2_(&i__2, &i__1, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[i__], &
2638 	    tauq[i__], &taup[i__], &work[1], &iinfo);
2639     work[1] = ws;
2640     return 0;
2641 
2642 /*     End of DGEBRD */
2643 
2644 } /* dgebrd_ */
2645 
dgeev_(char * jobvl,char * jobvr,integer * n,doublereal * a,integer * lda,doublereal * wr,doublereal * wi,doublereal * vl,integer * ldvl,doublereal * vr,integer * ldvr,doublereal * work,integer * lwork,integer * info)2646 /* Subroutine */ int dgeev_(char *jobvl, char *jobvr, integer *n, doublereal *
2647 	a, integer *lda, doublereal *wr, doublereal *wi, doublereal *vl,
2648 	integer *ldvl, doublereal *vr, integer *ldvr, doublereal *work,
2649 	integer *lwork, integer *info)
2650 {
2651     /* System generated locals */
2652     integer a_dim1, a_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
2653 	    i__2, i__3;
2654     doublereal d__1, d__2;
2655 
2656     /* Local variables */
2657     static integer i__, k;
2658     static doublereal r__, cs, sn;
2659     static integer ihi;
2660     static doublereal scl;
2661     static integer ilo;
2662     static doublereal dum[1], eps;
2663     static integer ibal;
2664     static char side[1];
2665     static doublereal anrm;
2666     static integer ierr, itau;
2667     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
2668 	    doublereal *, integer *, doublereal *, doublereal *);
2669     static integer iwrk, nout;
2670     extern doublereal dnrm2_(integer *, doublereal *, integer *);
2671     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
2672 	    integer *);
2673     extern logical lsame_(char *, char *);
2674     extern doublereal dlapy2_(doublereal *, doublereal *);
2675     extern /* Subroutine */ int dlabad_(doublereal *, doublereal *), dgebak_(
2676 	    char *, char *, integer *, integer *, integer *, doublereal *,
2677 	    integer *, doublereal *, integer *, integer *),
2678 	    dgebal_(char *, integer *, doublereal *, integer *, integer *,
2679 	    integer *, doublereal *, integer *);
2680     static logical scalea;
2681 
2682     static doublereal cscale;
2683     extern doublereal dlange_(char *, integer *, integer *, doublereal *,
2684 	    integer *, doublereal *);
2685     extern /* Subroutine */ int dgehrd_(integer *, integer *, integer *,
2686 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
2687 	    integer *), dlascl_(char *, integer *, integer *, doublereal *,
2688 	    doublereal *, integer *, integer *, doublereal *, integer *,
2689 	    integer *);
2690     extern integer idamax_(integer *, doublereal *, integer *);
2691     extern /* Subroutine */ int dlacpy_(char *, integer *, integer *,
2692 	    doublereal *, integer *, doublereal *, integer *),
2693 	    dlartg_(doublereal *, doublereal *, doublereal *, doublereal *,
2694 	    doublereal *), xerbla_(char *, integer *);
2695     static logical select[1];
2696     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
2697 	    integer *, integer *, ftnlen, ftnlen);
2698     static doublereal bignum;
2699     extern /* Subroutine */ int dorghr_(integer *, integer *, integer *,
2700 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
2701 	    integer *), dhseqr_(char *, char *, integer *, integer *, integer
2702 	    *, doublereal *, integer *, doublereal *, doublereal *,
2703 	    doublereal *, integer *, doublereal *, integer *, integer *), dtrevc_(char *, char *, logical *, integer *,
2704 	    doublereal *, integer *, doublereal *, integer *, doublereal *,
2705 	    integer *, integer *, integer *, doublereal *, integer *);
2706     static integer minwrk, maxwrk;
2707     static logical wantvl;
2708     static doublereal smlnum;
2709     static integer hswork;
2710     static logical lquery, wantvr;
2711 
2712 
2713 /*
2714     -- LAPACK driver routine (version 3.2) --
2715     -- LAPACK is a software package provided by Univ. of Tennessee,    --
2716     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
2717        November 2006
2718 
2719 
2720     Purpose
2721     =======
2722 
2723     DGEEV computes for an N-by-N real nonsymmetric matrix A, the
2724     eigenvalues and, optionally, the left and/or right eigenvectors.
2725 
2726     The right eigenvector v(j) of A satisfies
2727                      A * v(j) = lambda(j) * v(j)
2728     where lambda(j) is its eigenvalue.
2729     The left eigenvector u(j) of A satisfies
2730                   u(j)**H * A = lambda(j) * u(j)**H
2731     where u(j)**H denotes the conjugate transpose of u(j).
2732 
2733     The computed eigenvectors are normalized to have Euclidean norm
2734     equal to 1 and largest component real.
2735 
2736     Arguments
2737     =========
2738 
2739     JOBVL   (input) CHARACTER*1
2740             = 'N': left eigenvectors of A are not computed;
2741             = 'V': left eigenvectors of A are computed.
2742 
2743     JOBVR   (input) CHARACTER*1
2744             = 'N': right eigenvectors of A are not computed;
2745             = 'V': right eigenvectors of A are computed.
2746 
2747     N       (input) INTEGER
2748             The order of the matrix A. N >= 0.
2749 
2750     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
2751             On entry, the N-by-N matrix A.
2752             On exit, A has been overwritten.
2753 
2754     LDA     (input) INTEGER
2755             The leading dimension of the array A.  LDA >= max(1,N).
2756 
2757     WR      (output) DOUBLE PRECISION array, dimension (N)
2758     WI      (output) DOUBLE PRECISION array, dimension (N)
2759             WR and WI contain the real and imaginary parts,
2760             respectively, of the computed eigenvalues.  Complex
2761             conjugate pairs of eigenvalues appear consecutively
2762             with the eigenvalue having the positive imaginary part
2763             first.
2764 
2765     VL      (output) DOUBLE PRECISION array, dimension (LDVL,N)
2766             If JOBVL = 'V', the left eigenvectors u(j) are stored one
2767             after another in the columns of VL, in the same order
2768             as their eigenvalues.
2769             If JOBVL = 'N', VL is not referenced.
2770             If the j-th eigenvalue is real, then u(j) = VL(:,j),
2771             the j-th column of VL.
2772             If the j-th and (j+1)-st eigenvalues form a complex
2773             conjugate pair, then u(j) = VL(:,j) + i*VL(:,j+1) and
2774             u(j+1) = VL(:,j) - i*VL(:,j+1).
2775 
2776     LDVL    (input) INTEGER
2777             The leading dimension of the array VL.  LDVL >= 1; if
2778             JOBVL = 'V', LDVL >= N.
2779 
2780     VR      (output) DOUBLE PRECISION array, dimension (LDVR,N)
2781             If JOBVR = 'V', the right eigenvectors v(j) are stored one
2782             after another in the columns of VR, in the same order
2783             as their eigenvalues.
2784             If JOBVR = 'N', VR is not referenced.
2785             If the j-th eigenvalue is real, then v(j) = VR(:,j),
2786             the j-th column of VR.
2787             If the j-th and (j+1)-st eigenvalues form a complex
2788             conjugate pair, then v(j) = VR(:,j) + i*VR(:,j+1) and
2789             v(j+1) = VR(:,j) - i*VR(:,j+1).
2790 
2791     LDVR    (input) INTEGER
2792             The leading dimension of the array VR.  LDVR >= 1; if
2793             JOBVR = 'V', LDVR >= N.
2794 
2795     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
2796             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
2797 
2798     LWORK   (input) INTEGER
2799             The dimension of the array WORK.  LWORK >= max(1,3*N), and
2800             if JOBVL = 'V' or JOBVR = 'V', LWORK >= 4*N.  For good
2801             performance, LWORK must generally be larger.
2802 
2803             If LWORK = -1, then a workspace query is assumed; the routine
2804             only calculates the optimal size of the WORK array, returns
2805             this value as the first entry of the WORK array, and no error
2806             message related to LWORK is issued by XERBLA.
2807 
2808     INFO    (output) INTEGER
2809             = 0:  successful exit
2810             < 0:  if INFO = -i, the i-th argument had an illegal value.
2811             > 0:  if INFO = i, the QR algorithm failed to compute all the
2812                   eigenvalues, and no eigenvectors have been computed;
2813                   elements i+1:N of WR and WI contain eigenvalues which
2814                   have converged.
2815 
2816     =====================================================================
2817 
2818 
2819        Test the input arguments
2820 */
2821 
2822     /* Parameter adjustments */
2823     a_dim1 = *lda;
2824     a_offset = 1 + a_dim1;
2825     a -= a_offset;
2826     --wr;
2827     --wi;
2828     vl_dim1 = *ldvl;
2829     vl_offset = 1 + vl_dim1;
2830     vl -= vl_offset;
2831     vr_dim1 = *ldvr;
2832     vr_offset = 1 + vr_dim1;
2833     vr -= vr_offset;
2834     --work;
2835 
2836     /* Function Body */
2837     *info = 0;
2838     lquery = *lwork == -1;
2839     wantvl = lsame_(jobvl, "V");
2840     wantvr = lsame_(jobvr, "V");
2841     if (! wantvl && ! lsame_(jobvl, "N")) {
2842 	*info = -1;
2843     } else if (! wantvr && ! lsame_(jobvr, "N")) {
2844 	*info = -2;
2845     } else if (*n < 0) {
2846 	*info = -3;
2847     } else if (*lda < max(1,*n)) {
2848 	*info = -5;
2849     } else if (*ldvl < 1 || wantvl && *ldvl < *n) {
2850 	*info = -9;
2851     } else if (*ldvr < 1 || wantvr && *ldvr < *n) {
2852 	*info = -11;
2853     }
2854 
2855 /*
2856        Compute workspace
2857         (Note: Comments in the code beginning "Workspace:" describe the
2858          minimal amount of workspace needed at that point in the code,
2859          as well as the preferred amount for good performance.
2860          NB refers to the optimal block size for the immediately
2861          following subroutine, as returned by ILAENV.
2862          HSWORK refers to the workspace preferred by DHSEQR, as
2863          calculated below. HSWORK is computed assuming ILO=1 and IHI=N,
2864          the worst case.)
2865 */
2866 
2867     if (*info == 0) {
2868 	if (*n == 0) {
2869 	    minwrk = 1;
2870 	    maxwrk = 1;
2871 	} else {
2872 	    maxwrk = (*n << 1) + *n * ilaenv_(&c__1, "DGEHRD", " ", n, &c__1,
2873 		    n, &c__0, (ftnlen)6, (ftnlen)1);
2874 	    if (wantvl) {
2875 		minwrk = *n << 2;
2876 /* Computing MAX */
2877 		i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * ilaenv_(&c__1,
2878 			"DORGHR", " ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)
2879 			1);
2880 		maxwrk = max(i__1,i__2);
2881 		dhseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
2882 			1], &vl[vl_offset], ldvl, &work[1], &c_n1, info);
2883 		hswork = (integer) work[1];
2884 /* Computing MAX */
2885 		i__1 = maxwrk, i__2 = *n + 1, i__1 = max(i__1,i__2), i__2 = *
2886 			n + hswork;
2887 		maxwrk = max(i__1,i__2);
2888 /* Computing MAX */
2889 		i__1 = maxwrk, i__2 = *n << 2;
2890 		maxwrk = max(i__1,i__2);
2891 	    } else if (wantvr) {
2892 		minwrk = *n << 2;
2893 /* Computing MAX */
2894 		i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * ilaenv_(&c__1,
2895 			"DORGHR", " ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)
2896 			1);
2897 		maxwrk = max(i__1,i__2);
2898 		dhseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
2899 			1], &vr[vr_offset], ldvr, &work[1], &c_n1, info);
2900 		hswork = (integer) work[1];
2901 /* Computing MAX */
2902 		i__1 = maxwrk, i__2 = *n + 1, i__1 = max(i__1,i__2), i__2 = *
2903 			n + hswork;
2904 		maxwrk = max(i__1,i__2);
2905 /* Computing MAX */
2906 		i__1 = maxwrk, i__2 = *n << 2;
2907 		maxwrk = max(i__1,i__2);
2908 	    } else {
2909 		minwrk = *n * 3;
2910 		dhseqr_("E", "N", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
2911 			1], &vr[vr_offset], ldvr, &work[1], &c_n1, info);
2912 		hswork = (integer) work[1];
2913 /* Computing MAX */
2914 		i__1 = maxwrk, i__2 = *n + 1, i__1 = max(i__1,i__2), i__2 = *
2915 			n + hswork;
2916 		maxwrk = max(i__1,i__2);
2917 	    }
2918 	    maxwrk = max(maxwrk,minwrk);
2919 	}
2920 	work[1] = (doublereal) maxwrk;
2921 
2922 	if (*lwork < minwrk && ! lquery) {
2923 	    *info = -13;
2924 	}
2925     }
2926 
2927     if (*info != 0) {
2928 	i__1 = -(*info);
2929 	xerbla_("DGEEV ", &i__1);
2930 	return 0;
2931     } else if (lquery) {
2932 	return 0;
2933     }
2934 
2935 /*     Quick return if possible */
2936 
2937     if (*n == 0) {
2938 	return 0;
2939     }
2940 
2941 /*     Get machine constants */
2942 
2943     eps = PRECISION;
2944     smlnum = SAFEMINIMUM;
2945     bignum = 1. / smlnum;
2946     dlabad_(&smlnum, &bignum);
2947     smlnum = sqrt(smlnum) / eps;
2948     bignum = 1. / smlnum;
2949 
2950 /*     Scale A if max element outside range [SMLNUM,BIGNUM] */
2951 
2952     anrm = dlange_("M", n, n, &a[a_offset], lda, dum);
2953     scalea = FALSE_;
2954     if (anrm > 0. && anrm < smlnum) {
2955 	scalea = TRUE_;
2956 	cscale = smlnum;
2957     } else if (anrm > bignum) {
2958 	scalea = TRUE_;
2959 	cscale = bignum;
2960     }
2961     if (scalea) {
2962 	dlascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
2963 		ierr);
2964     }
2965 
2966 /*
2967        Balance the matrix
2968        (Workspace: need N)
2969 */
2970 
2971     ibal = 1;
2972     dgebal_("B", n, &a[a_offset], lda, &ilo, &ihi, &work[ibal], &ierr);
2973 
2974 /*
2975        Reduce to upper Hessenberg form
2976        (Workspace: need 3*N, prefer 2*N+N*NB)
2977 */
2978 
2979     itau = ibal + *n;
2980     iwrk = itau + *n;
2981     i__1 = *lwork - iwrk + 1;
2982     dgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1,
2983 	     &ierr);
2984 
2985     if (wantvl) {
2986 
2987 /*
2988           Want left eigenvectors
2989           Copy Householder vectors to VL
2990 */
2991 
2992 	*(unsigned char *)side = 'L';
2993 	dlacpy_("L", n, n, &a[a_offset], lda, &vl[vl_offset], ldvl)
2994 		;
2995 
2996 /*
2997           Generate orthogonal matrix in VL
2998           (Workspace: need 3*N-1, prefer 2*N+(N-1)*NB)
2999 */
3000 
3001 	i__1 = *lwork - iwrk + 1;
3002 	dorghr_(n, &ilo, &ihi, &vl[vl_offset], ldvl, &work[itau], &work[iwrk],
3003 		 &i__1, &ierr);
3004 
3005 /*
3006           Perform QR iteration, accumulating Schur vectors in VL
3007           (Workspace: need N+1, prefer N+HSWORK (see comments) )
3008 */
3009 
3010 	iwrk = itau;
3011 	i__1 = *lwork - iwrk + 1;
3012 	dhseqr_("S", "V", n, &ilo, &ihi, &a[a_offset], lda, &wr[1], &wi[1], &
3013 		vl[vl_offset], ldvl, &work[iwrk], &i__1, info);
3014 
3015 	if (wantvr) {
3016 
3017 /*
3018              Want left and right eigenvectors
3019              Copy Schur vectors to VR
3020 */
3021 
3022 	    *(unsigned char *)side = 'B';
3023 	    dlacpy_("F", n, n, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr);
3024 	}
3025 
3026     } else if (wantvr) {
3027 
3028 /*
3029           Want right eigenvectors
3030           Copy Householder vectors to VR
3031 */
3032 
3033 	*(unsigned char *)side = 'R';
3034 	dlacpy_("L", n, n, &a[a_offset], lda, &vr[vr_offset], ldvr)
3035 		;
3036 
3037 /*
3038           Generate orthogonal matrix in VR
3039           (Workspace: need 3*N-1, prefer 2*N+(N-1)*NB)
3040 */
3041 
3042 	i__1 = *lwork - iwrk + 1;
3043 	dorghr_(n, &ilo, &ihi, &vr[vr_offset], ldvr, &work[itau], &work[iwrk],
3044 		 &i__1, &ierr);
3045 
3046 /*
3047           Perform QR iteration, accumulating Schur vectors in VR
3048           (Workspace: need N+1, prefer N+HSWORK (see comments) )
3049 */
3050 
3051 	iwrk = itau;
3052 	i__1 = *lwork - iwrk + 1;
3053 	dhseqr_("S", "V", n, &ilo, &ihi, &a[a_offset], lda, &wr[1], &wi[1], &
3054 		vr[vr_offset], ldvr, &work[iwrk], &i__1, info);
3055 
3056     } else {
3057 
3058 /*
3059           Compute eigenvalues only
3060           (Workspace: need N+1, prefer N+HSWORK (see comments) )
3061 */
3062 
3063 	iwrk = itau;
3064 	i__1 = *lwork - iwrk + 1;
3065 	dhseqr_("E", "N", n, &ilo, &ihi, &a[a_offset], lda, &wr[1], &wi[1], &
3066 		vr[vr_offset], ldvr, &work[iwrk], &i__1, info);
3067     }
3068 
3069 /*     If INFO > 0 from DHSEQR, then quit */
3070 
3071     if (*info > 0) {
3072 	goto L50;
3073     }
3074 
3075     if (wantvl || wantvr) {
3076 
3077 /*
3078           Compute left and/or right eigenvectors
3079           (Workspace: need 4*N)
3080 */
3081 
3082 	dtrevc_(side, "B", select, n, &a[a_offset], lda, &vl[vl_offset], ldvl,
3083 		 &vr[vr_offset], ldvr, n, &nout, &work[iwrk], &ierr);
3084     }
3085 
3086     if (wantvl) {
3087 
3088 /*
3089           Undo balancing of left eigenvectors
3090           (Workspace: need N)
3091 */
3092 
3093 	dgebak_("B", "L", n, &ilo, &ihi, &work[ibal], n, &vl[vl_offset], ldvl,
3094 		 &ierr);
3095 
3096 /*        Normalize left eigenvectors and make largest component real */
3097 
3098 	i__1 = *n;
3099 	for (i__ = 1; i__ <= i__1; ++i__) {
3100 	    if (wi[i__] == 0.) {
3101 		scl = 1. / dnrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
3102 		dscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
3103 	    } else if (wi[i__] > 0.) {
3104 		d__1 = dnrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
3105 		d__2 = dnrm2_(n, &vl[(i__ + 1) * vl_dim1 + 1], &c__1);
3106 		scl = 1. / dlapy2_(&d__1, &d__2);
3107 		dscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
3108 		dscal_(n, &scl, &vl[(i__ + 1) * vl_dim1 + 1], &c__1);
3109 		i__2 = *n;
3110 		for (k = 1; k <= i__2; ++k) {
3111 /* Computing 2nd power */
3112 		    d__1 = vl[k + i__ * vl_dim1];
3113 /* Computing 2nd power */
3114 		    d__2 = vl[k + (i__ + 1) * vl_dim1];
3115 		    work[iwrk + k - 1] = d__1 * d__1 + d__2 * d__2;
3116 /* L10: */
3117 		}
3118 		k = idamax_(n, &work[iwrk], &c__1);
3119 		dlartg_(&vl[k + i__ * vl_dim1], &vl[k + (i__ + 1) * vl_dim1],
3120 			&cs, &sn, &r__);
3121 		drot_(n, &vl[i__ * vl_dim1 + 1], &c__1, &vl[(i__ + 1) *
3122 			vl_dim1 + 1], &c__1, &cs, &sn);
3123 		vl[k + (i__ + 1) * vl_dim1] = 0.;
3124 	    }
3125 /* L20: */
3126 	}
3127     }
3128 
3129     if (wantvr) {
3130 
3131 /*
3132           Undo balancing of right eigenvectors
3133           (Workspace: need N)
3134 */
3135 
3136 	dgebak_("B", "R", n, &ilo, &ihi, &work[ibal], n, &vr[vr_offset], ldvr,
3137 		 &ierr);
3138 
3139 /*        Normalize right eigenvectors and make largest component real */
3140 
3141 	i__1 = *n;
3142 	for (i__ = 1; i__ <= i__1; ++i__) {
3143 	    if (wi[i__] == 0.) {
3144 		scl = 1. / dnrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
3145 		dscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
3146 	    } else if (wi[i__] > 0.) {
3147 		d__1 = dnrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
3148 		d__2 = dnrm2_(n, &vr[(i__ + 1) * vr_dim1 + 1], &c__1);
3149 		scl = 1. / dlapy2_(&d__1, &d__2);
3150 		dscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
3151 		dscal_(n, &scl, &vr[(i__ + 1) * vr_dim1 + 1], &c__1);
3152 		i__2 = *n;
3153 		for (k = 1; k <= i__2; ++k) {
3154 /* Computing 2nd power */
3155 		    d__1 = vr[k + i__ * vr_dim1];
3156 /* Computing 2nd power */
3157 		    d__2 = vr[k + (i__ + 1) * vr_dim1];
3158 		    work[iwrk + k - 1] = d__1 * d__1 + d__2 * d__2;
3159 /* L30: */
3160 		}
3161 		k = idamax_(n, &work[iwrk], &c__1);
3162 		dlartg_(&vr[k + i__ * vr_dim1], &vr[k + (i__ + 1) * vr_dim1],
3163 			&cs, &sn, &r__);
3164 		drot_(n, &vr[i__ * vr_dim1 + 1], &c__1, &vr[(i__ + 1) *
3165 			vr_dim1 + 1], &c__1, &cs, &sn);
3166 		vr[k + (i__ + 1) * vr_dim1] = 0.;
3167 	    }
3168 /* L40: */
3169 	}
3170     }
3171 
3172 /*     Undo scaling if necessary */
3173 
3174 L50:
3175     if (scalea) {
3176 	i__1 = *n - *info;
3177 /* Computing MAX */
3178 	i__3 = *n - *info;
3179 	i__2 = max(i__3,1);
3180 	dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wr[*info +
3181 		1], &i__2, &ierr);
3182 	i__1 = *n - *info;
3183 /* Computing MAX */
3184 	i__3 = *n - *info;
3185 	i__2 = max(i__3,1);
3186 	dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[*info +
3187 		1], &i__2, &ierr);
3188 	if (*info > 0) {
3189 	    i__1 = ilo - 1;
3190 	    dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wr[1],
3191 		    n, &ierr);
3192 	    i__1 = ilo - 1;
3193 	    dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[1],
3194 		    n, &ierr);
3195 	}
3196     }
3197 
3198     work[1] = (doublereal) maxwrk;
3199     return 0;
3200 
3201 /*     End of DGEEV */
3202 
3203 } /* dgeev_ */
3204 
dgehd2_(integer * n,integer * ilo,integer * ihi,doublereal * a,integer * lda,doublereal * tau,doublereal * work,integer * info)3205 /* Subroutine */ int dgehd2_(integer *n, integer *ilo, integer *ihi,
3206 	doublereal *a, integer *lda, doublereal *tau, doublereal *work,
3207 	integer *info)
3208 {
3209     /* System generated locals */
3210     integer a_dim1, a_offset, i__1, i__2, i__3;
3211 
3212     /* Local variables */
3213     static integer i__;
3214     static doublereal aii;
3215     extern /* Subroutine */ int dlarf_(char *, integer *, integer *,
3216 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
3217 	    doublereal *), dlarfg_(integer *, doublereal *,
3218 	    doublereal *, integer *, doublereal *), xerbla_(char *, integer *);
3219 
3220 
3221 /*
3222     -- LAPACK routine (version 3.2) --
3223     -- LAPACK is a software package provided by Univ. of Tennessee,    --
3224     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
3225        November 2006
3226 
3227 
3228     Purpose
3229     =======
3230 
3231     DGEHD2 reduces a real general matrix A to upper Hessenberg form H by
3232     an orthogonal similarity transformation:  Q' * A * Q = H .
3233 
3234     Arguments
3235     =========
3236 
3237     N       (input) INTEGER
3238             The order of the matrix A.  N >= 0.
3239 
3240     ILO     (input) INTEGER
3241     IHI     (input) INTEGER
3242             It is assumed that A is already upper triangular in rows
3243             and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
3244             set by a previous call to DGEBAL; otherwise they should be
3245             set to 1 and N respectively. See Further Details.
3246             1 <= ILO <= IHI <= max(1,N).
3247 
3248     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
3249             On entry, the n by n general matrix to be reduced.
3250             On exit, the upper triangle and the first subdiagonal of A
3251             are overwritten with the upper Hessenberg matrix H, and the
3252             elements below the first subdiagonal, with the array TAU,
3253             represent the orthogonal matrix Q as a product of elementary
3254             reflectors. See Further Details.
3255 
3256     LDA     (input) INTEGER
3257             The leading dimension of the array A.  LDA >= max(1,N).
3258 
3259     TAU     (output) DOUBLE PRECISION array, dimension (N-1)
3260             The scalar factors of the elementary reflectors (see Further
3261             Details).
3262 
3263     WORK    (workspace) DOUBLE PRECISION array, dimension (N)
3264 
3265     INFO    (output) INTEGER
3266             = 0:  successful exit.
3267             < 0:  if INFO = -i, the i-th argument had an illegal value.
3268 
3269     Further Details
3270     ===============
3271 
3272     The matrix Q is represented as a product of (ihi-ilo) elementary
3273     reflectors
3274 
3275        Q = H(ilo) H(ilo+1) . . . H(ihi-1).
3276 
3277     Each H(i) has the form
3278 
3279        H(i) = I - tau * v * v'
3280 
3281     where tau is a real scalar, and v is a real vector with
3282     v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on
3283     exit in A(i+2:ihi,i), and tau in TAU(i).
3284 
3285     The contents of A are illustrated by the following example, with
3286     n = 7, ilo = 2 and ihi = 6:
3287 
3288     on entry,                        on exit,
3289 
3290     ( a   a   a   a   a   a   a )    (  a   a   h   h   h   h   a )
3291     (     a   a   a   a   a   a )    (      a   h   h   h   h   a )
3292     (     a   a   a   a   a   a )    (      h   h   h   h   h   h )
3293     (     a   a   a   a   a   a )    (      v2  h   h   h   h   h )
3294     (     a   a   a   a   a   a )    (      v2  v3  h   h   h   h )
3295     (     a   a   a   a   a   a )    (      v2  v3  v4  h   h   h )
3296     (                         a )    (                          a )
3297 
3298     where a denotes an element of the original matrix A, h denotes a
3299     modified element of the upper Hessenberg matrix H, and vi denotes an
3300     element of the vector defining H(i).
3301 
3302     =====================================================================
3303 
3304 
3305        Test the input parameters
3306 */
3307 
3308     /* Parameter adjustments */
3309     a_dim1 = *lda;
3310     a_offset = 1 + a_dim1;
3311     a -= a_offset;
3312     --tau;
3313     --work;
3314 
3315     /* Function Body */
3316     *info = 0;
3317     if (*n < 0) {
3318 	*info = -1;
3319     } else if (*ilo < 1 || *ilo > max(1,*n)) {
3320 	*info = -2;
3321     } else if (*ihi < min(*ilo,*n) || *ihi > *n) {
3322 	*info = -3;
3323     } else if (*lda < max(1,*n)) {
3324 	*info = -5;
3325     }
3326     if (*info != 0) {
3327 	i__1 = -(*info);
3328 	xerbla_("DGEHD2", &i__1);
3329 	return 0;
3330     }
3331 
3332     i__1 = *ihi - 1;
3333     for (i__ = *ilo; i__ <= i__1; ++i__) {
3334 
3335 /*        Compute elementary reflector H(i) to annihilate A(i+2:ihi,i) */
3336 
3337 	i__2 = *ihi - i__;
3338 /* Computing MIN */
3339 	i__3 = i__ + 2;
3340 	dlarfg_(&i__2, &a[i__ + 1 + i__ * a_dim1], &a[min(i__3,*n) + i__ *
3341 		a_dim1], &c__1, &tau[i__]);
3342 	aii = a[i__ + 1 + i__ * a_dim1];
3343 	a[i__ + 1 + i__ * a_dim1] = 1.;
3344 
3345 /*        Apply H(i) to A(1:ihi,i+1:ihi) from the right */
3346 
3347 	i__2 = *ihi - i__;
3348 	dlarf_("Right", ihi, &i__2, &a[i__ + 1 + i__ * a_dim1], &c__1, &tau[
3349 		i__], &a[(i__ + 1) * a_dim1 + 1], lda, &work[1]);
3350 
3351 /*        Apply H(i) to A(i+1:ihi,i+1:n) from the left */
3352 
3353 	i__2 = *ihi - i__;
3354 	i__3 = *n - i__;
3355 	dlarf_("Left", &i__2, &i__3, &a[i__ + 1 + i__ * a_dim1], &c__1, &tau[
3356 		i__], &a[i__ + 1 + (i__ + 1) * a_dim1], lda, &work[1]);
3357 
3358 	a[i__ + 1 + i__ * a_dim1] = aii;
3359 /* L10: */
3360     }
3361 
3362     return 0;
3363 
3364 /*     End of DGEHD2 */
3365 
3366 } /* dgehd2_ */
3367 
dgehrd_(integer * n,integer * ilo,integer * ihi,doublereal * a,integer * lda,doublereal * tau,doublereal * work,integer * lwork,integer * info)3368 /* Subroutine */ int dgehrd_(integer *n, integer *ilo, integer *ihi,
3369 	doublereal *a, integer *lda, doublereal *tau, doublereal *work,
3370 	integer *lwork, integer *info)
3371 {
3372     /* System generated locals */
3373     integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
3374 
3375     /* Local variables */
3376     static integer i__, j;
3377     static doublereal t[4160]	/* was [65][64] */;
3378     static integer ib;
3379     static doublereal ei;
3380     static integer nb, nh, nx, iws;
3381     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
3382 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
3383 	    integer *, doublereal *, doublereal *, integer *);
3384     static integer nbmin, iinfo;
3385     extern /* Subroutine */ int dtrmm_(char *, char *, char *, char *,
3386 	    integer *, integer *, doublereal *, doublereal *, integer *,
3387 	    doublereal *, integer *), daxpy_(
3388 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
3389 	    integer *), dgehd2_(integer *, integer *, integer *, doublereal *,
3390 	     integer *, doublereal *, doublereal *, integer *), dlahr2_(
3391 	    integer *, integer *, integer *, doublereal *, integer *,
3392 	    doublereal *, doublereal *, integer *, doublereal *, integer *),
3393 	    dlarfb_(char *, char *, char *, char *, integer *, integer *,
3394 	    integer *, doublereal *, integer *, doublereal *, integer *,
3395 	    doublereal *, integer *, doublereal *, integer *), xerbla_(char *, integer *);
3396     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
3397 	    integer *, integer *, ftnlen, ftnlen);
3398     static integer ldwork, lwkopt;
3399     static logical lquery;
3400 
3401 
3402 /*
3403     -- LAPACK routine (version 3.2.1)                                  --
3404     -- LAPACK is a software package provided by Univ. of Tennessee,    --
3405     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
3406     -- April 2009                                                      --
3407 
3408 
3409     Purpose
3410     =======
3411 
3412     DGEHRD reduces a real general matrix A to upper Hessenberg form H by
3413     an orthogonal similarity transformation:  Q' * A * Q = H .
3414 
3415     Arguments
3416     =========
3417 
3418     N       (input) INTEGER
3419             The order of the matrix A.  N >= 0.
3420 
3421     ILO     (input) INTEGER
3422     IHI     (input) INTEGER
3423             It is assumed that A is already upper triangular in rows
3424             and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
3425             set by a previous call to DGEBAL; otherwise they should be
3426             set to 1 and N respectively. See Further Details.
3427             1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
3428 
3429     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
3430             On entry, the N-by-N general matrix to be reduced.
3431             On exit, the upper triangle and the first subdiagonal of A
3432             are overwritten with the upper Hessenberg matrix H, and the
3433             elements below the first subdiagonal, with the array TAU,
3434             represent the orthogonal matrix Q as a product of elementary
3435             reflectors. See Further Details.
3436 
3437     LDA     (input) INTEGER
3438             The leading dimension of the array A.  LDA >= max(1,N).
3439 
3440     TAU     (output) DOUBLE PRECISION array, dimension (N-1)
3441             The scalar factors of the elementary reflectors (see Further
3442             Details). Elements 1:ILO-1 and IHI:N-1 of TAU are set to
3443             zero.
3444 
3445     WORK    (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
3446             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
3447 
3448     LWORK   (input) INTEGER
3449             The length of the array WORK.  LWORK >= max(1,N).
3450             For optimum performance LWORK >= N*NB, where NB is the
3451             optimal blocksize.
3452 
3453             If LWORK = -1, then a workspace query is assumed; the routine
3454             only calculates the optimal size of the WORK array, returns
3455             this value as the first entry of the WORK array, and no error
3456             message related to LWORK is issued by XERBLA.
3457 
3458     INFO    (output) INTEGER
3459             = 0:  successful exit
3460             < 0:  if INFO = -i, the i-th argument had an illegal value.
3461 
3462     Further Details
3463     ===============
3464 
3465     The matrix Q is represented as a product of (ihi-ilo) elementary
3466     reflectors
3467 
3468        Q = H(ilo) H(ilo+1) . . . H(ihi-1).
3469 
3470     Each H(i) has the form
3471 
3472        H(i) = I - tau * v * v'
3473 
3474     where tau is a real scalar, and v is a real vector with
3475     v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on
3476     exit in A(i+2:ihi,i), and tau in TAU(i).
3477 
3478     The contents of A are illustrated by the following example, with
3479     n = 7, ilo = 2 and ihi = 6:
3480 
3481     on entry,                        on exit,
3482 
3483     ( a   a   a   a   a   a   a )    (  a   a   h   h   h   h   a )
3484     (     a   a   a   a   a   a )    (      a   h   h   h   h   a )
3485     (     a   a   a   a   a   a )    (      h   h   h   h   h   h )
3486     (     a   a   a   a   a   a )    (      v2  h   h   h   h   h )
3487     (     a   a   a   a   a   a )    (      v2  v3  h   h   h   h )
3488     (     a   a   a   a   a   a )    (      v2  v3  v4  h   h   h )
3489     (                         a )    (                          a )
3490 
3491     where a denotes an element of the original matrix A, h denotes a
3492     modified element of the upper Hessenberg matrix H, and vi denotes an
3493     element of the vector defining H(i).
3494 
3495     This file is a slight modification of LAPACK-3.0's DGEHRD
3496     subroutine incorporating improvements proposed by Quintana-Orti and
3497     Van de Geijn (2006). (See DLAHR2.)
3498 
3499     =====================================================================
3500 
3501 
3502        Test the input parameters
3503 */
3504 
3505     /* Parameter adjustments */
3506     a_dim1 = *lda;
3507     a_offset = 1 + a_dim1;
3508     a -= a_offset;
3509     --tau;
3510     --work;
3511 
3512     /* Function Body */
3513     *info = 0;
3514 /* Computing MIN */
3515     i__1 = 64, i__2 = ilaenv_(&c__1, "DGEHRD", " ", n, ilo, ihi, &c_n1, (
3516 	    ftnlen)6, (ftnlen)1);
3517     nb = min(i__1,i__2);
3518     lwkopt = *n * nb;
3519     work[1] = (doublereal) lwkopt;
3520     lquery = *lwork == -1;
3521     if (*n < 0) {
3522 	*info = -1;
3523     } else if (*ilo < 1 || *ilo > max(1,*n)) {
3524 	*info = -2;
3525     } else if (*ihi < min(*ilo,*n) || *ihi > *n) {
3526 	*info = -3;
3527     } else if (*lda < max(1,*n)) {
3528 	*info = -5;
3529     } else if (*lwork < max(1,*n) && ! lquery) {
3530 	*info = -8;
3531     }
3532     if (*info != 0) {
3533 	i__1 = -(*info);
3534 	xerbla_("DGEHRD", &i__1);
3535 	return 0;
3536     } else if (lquery) {
3537 	return 0;
3538     }
3539 
3540 /*     Set elements 1:ILO-1 and IHI:N-1 of TAU to zero */
3541 
3542     i__1 = *ilo - 1;
3543     for (i__ = 1; i__ <= i__1; ++i__) {
3544 	tau[i__] = 0.;
3545 /* L10: */
3546     }
3547     i__1 = *n - 1;
3548     for (i__ = max(1,*ihi); i__ <= i__1; ++i__) {
3549 	tau[i__] = 0.;
3550 /* L20: */
3551     }
3552 
3553 /*     Quick return if possible */
3554 
3555     nh = *ihi - *ilo + 1;
3556     if (nh <= 1) {
3557 	work[1] = 1.;
3558 	return 0;
3559     }
3560 
3561 /*
3562        Determine the block size
3563 
3564    Computing MIN
3565 */
3566     i__1 = 64, i__2 = ilaenv_(&c__1, "DGEHRD", " ", n, ilo, ihi, &c_n1, (
3567 	    ftnlen)6, (ftnlen)1);
3568     nb = min(i__1,i__2);
3569     nbmin = 2;
3570     iws = 1;
3571     if (nb > 1 && nb < nh) {
3572 
3573 /*
3574           Determine when to cross over from blocked to unblocked code
3575           (last block is always handled by unblocked code)
3576 
3577    Computing MAX
3578 */
3579 	i__1 = nb, i__2 = ilaenv_(&c__3, "DGEHRD", " ", n, ilo, ihi, &c_n1, (
3580 		ftnlen)6, (ftnlen)1);
3581 	nx = max(i__1,i__2);
3582 	if (nx < nh) {
3583 
3584 /*           Determine if workspace is large enough for blocked code */
3585 
3586 	    iws = *n * nb;
3587 	    if (*lwork < iws) {
3588 
3589 /*
3590                 Not enough workspace to use optimal NB:  determine the
3591                 minimum value of NB, and reduce NB or force use of
3592                 unblocked code
3593 
3594    Computing MAX
3595 */
3596 		i__1 = 2, i__2 = ilaenv_(&c__2, "DGEHRD", " ", n, ilo, ihi, &
3597 			c_n1, (ftnlen)6, (ftnlen)1);
3598 		nbmin = max(i__1,i__2);
3599 		if (*lwork >= *n * nbmin) {
3600 		    nb = *lwork / *n;
3601 		} else {
3602 		    nb = 1;
3603 		}
3604 	    }
3605 	}
3606     }
3607     ldwork = *n;
3608 
3609     if (nb < nbmin || nb >= nh) {
3610 
3611 /*        Use unblocked code below */
3612 
3613 	i__ = *ilo;
3614 
3615     } else {
3616 
3617 /*        Use blocked code */
3618 
3619 	i__1 = *ihi - 1 - nx;
3620 	i__2 = nb;
3621 	for (i__ = *ilo; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
3622 /* Computing MIN */
3623 	    i__3 = nb, i__4 = *ihi - i__;
3624 	    ib = min(i__3,i__4);
3625 
3626 /*
3627              Reduce columns i:i+ib-1 to Hessenberg form, returning the
3628              matrices V and T of the block reflector H = I - V*T*V'
3629              which performs the reduction, and also the matrix Y = A*V*T
3630 */
3631 
3632 	    dlahr2_(ihi, &i__, &ib, &a[i__ * a_dim1 + 1], lda, &tau[i__], t, &
3633 		    c__65, &work[1], &ldwork);
3634 
3635 /*
3636              Apply the block reflector H to A(1:ihi,i+ib:ihi) from the
3637              right, computing  A := A - Y * V'. V(i+ib,ib-1) must be set
3638              to 1
3639 */
3640 
3641 	    ei = a[i__ + ib + (i__ + ib - 1) * a_dim1];
3642 	    a[i__ + ib + (i__ + ib - 1) * a_dim1] = 1.;
3643 	    i__3 = *ihi - i__ - ib + 1;
3644 	    dgemm_("No transpose", "Transpose", ihi, &i__3, &ib, &c_b151, &
3645 		    work[1], &ldwork, &a[i__ + ib + i__ * a_dim1], lda, &
3646 		    c_b15, &a[(i__ + ib) * a_dim1 + 1], lda);
3647 	    a[i__ + ib + (i__ + ib - 1) * a_dim1] = ei;
3648 
3649 /*
3650              Apply the block reflector H to A(1:i,i+1:i+ib-1) from the
3651              right
3652 */
3653 
3654 	    i__3 = ib - 1;
3655 	    dtrmm_("Right", "Lower", "Transpose", "Unit", &i__, &i__3, &c_b15,
3656 		     &a[i__ + 1 + i__ * a_dim1], lda, &work[1], &ldwork);
3657 	    i__3 = ib - 2;
3658 	    for (j = 0; j <= i__3; ++j) {
3659 		daxpy_(&i__, &c_b151, &work[ldwork * j + 1], &c__1, &a[(i__ +
3660 			j + 1) * a_dim1 + 1], &c__1);
3661 /* L30: */
3662 	    }
3663 
3664 /*
3665              Apply the block reflector H to A(i+1:ihi,i+ib:n) from the
3666              left
3667 */
3668 
3669 	    i__3 = *ihi - i__;
3670 	    i__4 = *n - i__ - ib + 1;
3671 	    dlarfb_("Left", "Transpose", "Forward", "Columnwise", &i__3, &
3672 		    i__4, &ib, &a[i__ + 1 + i__ * a_dim1], lda, t, &c__65, &a[
3673 		    i__ + 1 + (i__ + ib) * a_dim1], lda, &work[1], &ldwork);
3674 /* L40: */
3675 	}
3676     }
3677 
3678 /*     Use unblocked code to reduce the rest of the matrix */
3679 
3680     dgehd2_(n, &i__, ihi, &a[a_offset], lda, &tau[1], &work[1], &iinfo);
3681     work[1] = (doublereal) iws;
3682 
3683     return 0;
3684 
3685 /*     End of DGEHRD */
3686 
3687 } /* dgehrd_ */
3688 
dgelq2_(integer * m,integer * n,doublereal * a,integer * lda,doublereal * tau,doublereal * work,integer * info)3689 /* Subroutine */ int dgelq2_(integer *m, integer *n, doublereal *a, integer *
3690 	lda, doublereal *tau, doublereal *work, integer *info)
3691 {
3692     /* System generated locals */
3693     integer a_dim1, a_offset, i__1, i__2, i__3;
3694 
3695     /* Local variables */
3696     static integer i__, k;
3697     static doublereal aii;
3698     extern /* Subroutine */ int dlarf_(char *, integer *, integer *,
3699 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
3700 	    doublereal *), dlarfg_(integer *, doublereal *,
3701 	    doublereal *, integer *, doublereal *), xerbla_(char *, integer *);
3702 
3703 
3704 /*
3705     -- LAPACK routine (version 3.2.2) --
3706     -- LAPACK is a software package provided by Univ. of Tennessee,    --
3707     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
3708        June 2010
3709 
3710 
3711     Purpose
3712     =======
3713 
3714     DGELQ2 computes an LQ factorization of a real m by n matrix A:
3715     A = L * Q.
3716 
3717     Arguments
3718     =========
3719 
3720     M       (input) INTEGER
3721             The number of rows of the matrix A.  M >= 0.
3722 
3723     N       (input) INTEGER
3724             The number of columns of the matrix A.  N >= 0.
3725 
3726     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
3727             On entry, the m by n matrix A.
3728             On exit, the elements on and below the diagonal of the array
3729             contain the m by min(m,n) lower trapezoidal matrix L (L is
3730             lower triangular if m <= n); the elements above the diagonal,
3731             with the array TAU, represent the orthogonal matrix Q as a
3732             product of elementary reflectors (see Further Details).
3733 
3734     LDA     (input) INTEGER
3735             The leading dimension of the array A.  LDA >= max(1,M).
3736 
3737     TAU     (output) DOUBLE PRECISION array, dimension (min(M,N))
3738             The scalar factors of the elementary reflectors (see Further
3739             Details).
3740 
3741     WORK    (workspace) DOUBLE PRECISION array, dimension (M)
3742 
3743     INFO    (output) INTEGER
3744             = 0: successful exit
3745             < 0: if INFO = -i, the i-th argument had an illegal value
3746 
3747     Further Details
3748     ===============
3749 
3750     The matrix Q is represented as a product of elementary reflectors
3751 
3752        Q = H(k) . . . H(2) H(1), where k = min(m,n).
3753 
3754     Each H(i) has the form
3755 
3756        H(i) = I - tau * v * v'
3757 
3758     where tau is a real scalar, and v is a real vector with
3759     v(1:i-1) = 0 and v(i) = 1; v(i+1:n) is stored on exit in A(i,i+1:n),
3760     and tau in TAU(i).
3761 
3762     =====================================================================
3763 
3764 
3765        Test the input arguments
3766 */
3767 
3768     /* Parameter adjustments */
3769     a_dim1 = *lda;
3770     a_offset = 1 + a_dim1;
3771     a -= a_offset;
3772     --tau;
3773     --work;
3774 
3775     /* Function Body */
3776     *info = 0;
3777     if (*m < 0) {
3778 	*info = -1;
3779     } else if (*n < 0) {
3780 	*info = -2;
3781     } else if (*lda < max(1,*m)) {
3782 	*info = -4;
3783     }
3784     if (*info != 0) {
3785 	i__1 = -(*info);
3786 	xerbla_("DGELQ2", &i__1);
3787 	return 0;
3788     }
3789 
3790     k = min(*m,*n);
3791 
3792     i__1 = k;
3793     for (i__ = 1; i__ <= i__1; ++i__) {
3794 
3795 /*        Generate elementary reflector H(i) to annihilate A(i,i+1:n) */
3796 
3797 	i__2 = *n - i__ + 1;
3798 /* Computing MIN */
3799 	i__3 = i__ + 1;
3800 	dlarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[i__ + min(i__3,*n) * a_dim1]
3801 		, lda, &tau[i__]);
3802 	if (i__ < *m) {
3803 
3804 /*           Apply H(i) to A(i+1:m,i:n) from the right */
3805 
3806 	    aii = a[i__ + i__ * a_dim1];
3807 	    a[i__ + i__ * a_dim1] = 1.;
3808 	    i__2 = *m - i__;
3809 	    i__3 = *n - i__ + 1;
3810 	    dlarf_("Right", &i__2, &i__3, &a[i__ + i__ * a_dim1], lda, &tau[
3811 		    i__], &a[i__ + 1 + i__ * a_dim1], lda, &work[1]);
3812 	    a[i__ + i__ * a_dim1] = aii;
3813 	}
3814 /* L10: */
3815     }
3816     return 0;
3817 
3818 /*     End of DGELQ2 */
3819 
3820 } /* dgelq2_ */
3821 
dgelqf_(integer * m,integer * n,doublereal * a,integer * lda,doublereal * tau,doublereal * work,integer * lwork,integer * info)3822 /* Subroutine */ int dgelqf_(integer *m, integer *n, doublereal *a, integer *
3823 	lda, doublereal *tau, doublereal *work, integer *lwork, integer *info)
3824 {
3825     /* System generated locals */
3826     integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
3827 
3828     /* Local variables */
3829     static integer i__, k, ib, nb, nx, iws, nbmin, iinfo;
3830     extern /* Subroutine */ int dgelq2_(integer *, integer *, doublereal *,
3831 	    integer *, doublereal *, doublereal *, integer *), dlarfb_(char *,
3832 	     char *, char *, char *, integer *, integer *, integer *,
3833 	    doublereal *, integer *, doublereal *, integer *, doublereal *,
3834 	    integer *, doublereal *, integer *), dlarft_(char *, char *, integer *, integer *, doublereal
3835 	    *, integer *, doublereal *, doublereal *, integer *), xerbla_(char *, integer *);
3836     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
3837 	    integer *, integer *, ftnlen, ftnlen);
3838     static integer ldwork, lwkopt;
3839     static logical lquery;
3840 
3841 
3842 /*
3843     -- LAPACK routine (version 3.2) --
3844     -- LAPACK is a software package provided by Univ. of Tennessee,    --
3845     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
3846        November 2006
3847 
3848 
3849     Purpose
3850     =======
3851 
3852     DGELQF computes an LQ factorization of a real M-by-N matrix A:
3853     A = L * Q.
3854 
3855     Arguments
3856     =========
3857 
3858     M       (input) INTEGER
3859             The number of rows of the matrix A.  M >= 0.
3860 
3861     N       (input) INTEGER
3862             The number of columns of the matrix A.  N >= 0.
3863 
3864     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
3865             On entry, the M-by-N matrix A.
3866             On exit, the elements on and below the diagonal of the array
3867             contain the m-by-min(m,n) lower trapezoidal matrix L (L is
3868             lower triangular if m <= n); the elements above the diagonal,
3869             with the array TAU, represent the orthogonal matrix Q as a
3870             product of elementary reflectors (see Further Details).
3871 
3872     LDA     (input) INTEGER
3873             The leading dimension of the array A.  LDA >= max(1,M).
3874 
3875     TAU     (output) DOUBLE PRECISION array, dimension (min(M,N))
3876             The scalar factors of the elementary reflectors (see Further
3877             Details).
3878 
3879     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
3880             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
3881 
3882     LWORK   (input) INTEGER
3883             The dimension of the array WORK.  LWORK >= max(1,M).
3884             For optimum performance LWORK >= M*NB, where NB is the
3885             optimal blocksize.
3886 
3887             If LWORK = -1, then a workspace query is assumed; the routine
3888             only calculates the optimal size of the WORK array, returns
3889             this value as the first entry of the WORK array, and no error
3890             message related to LWORK is issued by XERBLA.
3891 
3892     INFO    (output) INTEGER
3893             = 0:  successful exit
3894             < 0:  if INFO = -i, the i-th argument had an illegal value
3895 
3896     Further Details
3897     ===============
3898 
3899     The matrix Q is represented as a product of elementary reflectors
3900 
3901        Q = H(k) . . . H(2) H(1), where k = min(m,n).
3902 
3903     Each H(i) has the form
3904 
3905        H(i) = I - tau * v * v'
3906 
3907     where tau is a real scalar, and v is a real vector with
3908     v(1:i-1) = 0 and v(i) = 1; v(i+1:n) is stored on exit in A(i,i+1:n),
3909     and tau in TAU(i).
3910 
3911     =====================================================================
3912 
3913 
3914        Test the input arguments
3915 */
3916 
3917     /* Parameter adjustments */
3918     a_dim1 = *lda;
3919     a_offset = 1 + a_dim1;
3920     a -= a_offset;
3921     --tau;
3922     --work;
3923 
3924     /* Function Body */
3925     *info = 0;
3926     nb = ilaenv_(&c__1, "DGELQF", " ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)
3927 	    1);
3928     lwkopt = *m * nb;
3929     work[1] = (doublereal) lwkopt;
3930     lquery = *lwork == -1;
3931     if (*m < 0) {
3932 	*info = -1;
3933     } else if (*n < 0) {
3934 	*info = -2;
3935     } else if (*lda < max(1,*m)) {
3936 	*info = -4;
3937     } else if (*lwork < max(1,*m) && ! lquery) {
3938 	*info = -7;
3939     }
3940     if (*info != 0) {
3941 	i__1 = -(*info);
3942 	xerbla_("DGELQF", &i__1);
3943 	return 0;
3944     } else if (lquery) {
3945 	return 0;
3946     }
3947 
3948 /*     Quick return if possible */
3949 
3950     k = min(*m,*n);
3951     if (k == 0) {
3952 	work[1] = 1.;
3953 	return 0;
3954     }
3955 
3956     nbmin = 2;
3957     nx = 0;
3958     iws = *m;
3959     if (nb > 1 && nb < k) {
3960 
3961 /*
3962           Determine when to cross over from blocked to unblocked code.
3963 
3964    Computing MAX
3965 */
3966 	i__1 = 0, i__2 = ilaenv_(&c__3, "DGELQF", " ", m, n, &c_n1, &c_n1, (
3967 		ftnlen)6, (ftnlen)1);
3968 	nx = max(i__1,i__2);
3969 	if (nx < k) {
3970 
3971 /*           Determine if workspace is large enough for blocked code. */
3972 
3973 	    ldwork = *m;
3974 	    iws = ldwork * nb;
3975 	    if (*lwork < iws) {
3976 
3977 /*
3978                 Not enough workspace to use optimal NB:  reduce NB and
3979                 determine the minimum value of NB.
3980 */
3981 
3982 		nb = *lwork / ldwork;
3983 /* Computing MAX */
3984 		i__1 = 2, i__2 = ilaenv_(&c__2, "DGELQF", " ", m, n, &c_n1, &
3985 			c_n1, (ftnlen)6, (ftnlen)1);
3986 		nbmin = max(i__1,i__2);
3987 	    }
3988 	}
3989     }
3990 
3991     if (nb >= nbmin && nb < k && nx < k) {
3992 
3993 /*        Use blocked code initially */
3994 
3995 	i__1 = k - nx;
3996 	i__2 = nb;
3997 	for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
3998 /* Computing MIN */
3999 	    i__3 = k - i__ + 1;
4000 	    ib = min(i__3,nb);
4001 
4002 /*
4003              Compute the LQ factorization of the current block
4004              A(i:i+ib-1,i:n)
4005 */
4006 
4007 	    i__3 = *n - i__ + 1;
4008 	    dgelq2_(&ib, &i__3, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[
4009 		    1], &iinfo);
4010 	    if (i__ + ib <= *m) {
4011 
4012 /*
4013                 Form the triangular factor of the block reflector
4014                 H = H(i) H(i+1) . . . H(i+ib-1)
4015 */
4016 
4017 		i__3 = *n - i__ + 1;
4018 		dlarft_("Forward", "Rowwise", &i__3, &ib, &a[i__ + i__ *
4019 			a_dim1], lda, &tau[i__], &work[1], &ldwork);
4020 
4021 /*              Apply H to A(i+ib:m,i:n) from the right */
4022 
4023 		i__3 = *m - i__ - ib + 1;
4024 		i__4 = *n - i__ + 1;
4025 		dlarfb_("Right", "No transpose", "Forward", "Rowwise", &i__3,
4026 			&i__4, &ib, &a[i__ + i__ * a_dim1], lda, &work[1], &
4027 			ldwork, &a[i__ + ib + i__ * a_dim1], lda, &work[ib +
4028 			1], &ldwork);
4029 	    }
4030 /* L10: */
4031 	}
4032     } else {
4033 	i__ = 1;
4034     }
4035 
4036 /*     Use unblocked code to factor the last or only block. */
4037 
4038     if (i__ <= k) {
4039 	i__2 = *m - i__ + 1;
4040 	i__1 = *n - i__ + 1;
4041 	dgelq2_(&i__2, &i__1, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[1]
4042 		, &iinfo);
4043     }
4044 
4045     work[1] = (doublereal) iws;
4046     return 0;
4047 
4048 /*     End of DGELQF */
4049 
4050 } /* dgelqf_ */
4051 
dgelsd_(integer * m,integer * n,integer * nrhs,doublereal * a,integer * lda,doublereal * b,integer * ldb,doublereal * s,doublereal * rcond,integer * rank,doublereal * work,integer * lwork,integer * iwork,integer * info)4052 /* Subroutine */ int dgelsd_(integer *m, integer *n, integer *nrhs,
4053 	doublereal *a, integer *lda, doublereal *b, integer *ldb, doublereal *
4054 	s, doublereal *rcond, integer *rank, doublereal *work, integer *lwork,
4055 	 integer *iwork, integer *info)
4056 {
4057     /* System generated locals */
4058     integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3, i__4;
4059 
4060     /* Local variables */
4061     static integer ie, il, mm;
4062     static doublereal eps, anrm, bnrm;
4063     static integer itau, nlvl, iascl, ibscl;
4064     static doublereal sfmin;
4065     static integer minmn, maxmn, itaup, itauq, mnthr, nwork;
4066     extern /* Subroutine */ int dlabad_(doublereal *, doublereal *), dgebrd_(
4067 	    integer *, integer *, doublereal *, integer *, doublereal *,
4068 	    doublereal *, doublereal *, doublereal *, doublereal *, integer *,
4069 	     integer *);
4070     extern doublereal dlamch_(char *), dlange_(char *, integer *,
4071 	    integer *, doublereal *, integer *, doublereal *);
4072     extern /* Subroutine */ int dgelqf_(integer *, integer *, doublereal *,
4073 	    integer *, doublereal *, doublereal *, integer *, integer *),
4074 	    dlalsd_(char *, integer *, integer *, integer *, doublereal *,
4075 	    doublereal *, doublereal *, integer *, doublereal *, integer *,
4076 	    doublereal *, integer *, integer *), dlascl_(char *,
4077 	    integer *, integer *, doublereal *, doublereal *, integer *,
4078 	    integer *, doublereal *, integer *, integer *), dgeqrf_(
4079 	    integer *, integer *, doublereal *, integer *, doublereal *,
4080 	    doublereal *, integer *, integer *), dlacpy_(char *, integer *,
4081 	    integer *, doublereal *, integer *, doublereal *, integer *), dlaset_(char *, integer *, integer *, doublereal *,
4082 	    doublereal *, doublereal *, integer *), xerbla_(char *,
4083 	    integer *);
4084     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
4085 	    integer *, integer *, ftnlen, ftnlen);
4086     static doublereal bignum;
4087     extern /* Subroutine */ int dormbr_(char *, char *, char *, integer *,
4088 	    integer *, integer *, doublereal *, integer *, doublereal *,
4089 	    doublereal *, integer *, doublereal *, integer *, integer *);
4090     static integer wlalsd;
4091     extern /* Subroutine */ int dormlq_(char *, char *, integer *, integer *,
4092 	    integer *, doublereal *, integer *, doublereal *, doublereal *,
4093 	    integer *, doublereal *, integer *, integer *);
4094     static integer ldwork;
4095     extern /* Subroutine */ int dormqr_(char *, char *, integer *, integer *,
4096 	    integer *, doublereal *, integer *, doublereal *, doublereal *,
4097 	    integer *, doublereal *, integer *, integer *);
4098     static integer liwork, minwrk, maxwrk;
4099     static doublereal smlnum;
4100     static logical lquery;
4101     static integer smlsiz;
4102 
4103 
4104 /*
4105     -- LAPACK driver routine (version 3.2.2) --
4106     -- LAPACK is a software package provided by Univ. of Tennessee,    --
4107     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
4108        June 2010
4109 
4110 
4111     Purpose
4112     =======
4113 
4114     DGELSD computes the minimum-norm solution to a real linear least
4115     squares problem:
4116         minimize 2-norm(| b - A*x |)
4117     using the singular value decomposition (SVD) of A. A is an M-by-N
4118     matrix which may be rank-deficient.
4119 
4120     Several right hand side vectors b and solution vectors x can be
4121     handled in a single call; they are stored as the columns of the
4122     M-by-NRHS right hand side matrix B and the N-by-NRHS solution
4123     matrix X.
4124 
4125     The problem is solved in three steps:
4126     (1) Reduce the coefficient matrix A to bidiagonal form with
4127         Householder transformations, reducing the original problem
4128         into a "bidiagonal least squares problem" (BLS)
4129     (2) Solve the BLS using a divide and conquer approach.
4130     (3) Apply back all the Householder tranformations to solve
4131         the original least squares problem.
4132 
4133     The effective rank of A is determined by treating as zero those
4134     singular values which are less than RCOND times the largest singular
4135     value.
4136 
4137     The divide and conquer algorithm makes very mild assumptions about
4138     floating point arithmetic. It will work on machines with a guard
4139     digit in add/subtract, or on those binary machines without guard
4140     digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or
4141     Cray-2. It could conceivably fail on hexadecimal or decimal machines
4142     without guard digits, but we know of none.
4143 
4144     Arguments
4145     =========
4146 
4147     M       (input) INTEGER
4148             The number of rows of A. M >= 0.
4149 
4150     N       (input) INTEGER
4151             The number of columns of A. N >= 0.
4152 
4153     NRHS    (input) INTEGER
4154             The number of right hand sides, i.e., the number of columns
4155             of the matrices B and X. NRHS >= 0.
4156 
4157     A       (input) DOUBLE PRECISION array, dimension (LDA,N)
4158             On entry, the M-by-N matrix A.
4159             On exit, A has been destroyed.
4160 
4161     LDA     (input) INTEGER
4162             The leading dimension of the array A.  LDA >= max(1,M).
4163 
4164     B       (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
4165             On entry, the M-by-NRHS right hand side matrix B.
4166             On exit, B is overwritten by the N-by-NRHS solution
4167             matrix X.  If m >= n and RANK = n, the residual
4168             sum-of-squares for the solution in the i-th column is given
4169             by the sum of squares of elements n+1:m in that column.
4170 
4171     LDB     (input) INTEGER
4172             The leading dimension of the array B. LDB >= max(1,max(M,N)).
4173 
4174     S       (output) DOUBLE PRECISION array, dimension (min(M,N))
4175             The singular values of A in decreasing order.
4176             The condition number of A in the 2-norm = S(1)/S(min(m,n)).
4177 
4178     RCOND   (input) DOUBLE PRECISION
4179             RCOND is used to determine the effective rank of A.
4180             Singular values S(i) <= RCOND*S(1) are treated as zero.
4181             If RCOND < 0, machine precision is used instead.
4182 
4183     RANK    (output) INTEGER
4184             The effective rank of A, i.e., the number of singular values
4185             which are greater than RCOND*S(1).
4186 
4187     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
4188             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
4189 
4190     LWORK   (input) INTEGER
4191             The dimension of the array WORK. LWORK must be at least 1.
4192             The exact minimum amount of workspace needed depends on M,
4193             N and NRHS. As long as LWORK is at least
4194                 12*N + 2*N*SMLSIZ + 8*N*NLVL + N*NRHS + (SMLSIZ+1)**2,
4195             if M is greater than or equal to N or
4196                 12*M + 2*M*SMLSIZ + 8*M*NLVL + M*NRHS + (SMLSIZ+1)**2,
4197             if M is less than N, the code will execute correctly.
4198             SMLSIZ is returned by ILAENV and is equal to the maximum
4199             size of the subproblems at the bottom of the computation
4200             tree (usually about 25), and
4201                NLVL = MAX( 0, INT( LOG_2( MIN( M,N )/(SMLSIZ+1) ) ) + 1 )
4202             For good performance, LWORK should generally be larger.
4203 
4204             If LWORK = -1, then a workspace query is assumed; the routine
4205             only calculates the optimal size of the WORK array, returns
4206             this value as the first entry of the WORK array, and no error
4207             message related to LWORK is issued by XERBLA.
4208 
4209     IWORK   (workspace) INTEGER array, dimension (MAX(1,LIWORK))
4210             LIWORK >= max(1, 3 * MINMN * NLVL + 11 * MINMN),
4211             where MINMN = MIN( M,N ).
4212             On exit, if INFO = 0, IWORK(1) returns the minimum LIWORK.
4213 
4214     INFO    (output) INTEGER
4215             = 0:  successful exit
4216             < 0:  if INFO = -i, the i-th argument had an illegal value.
4217             > 0:  the algorithm for computing the SVD failed to converge;
4218                   if INFO = i, i off-diagonal elements of an intermediate
4219                   bidiagonal form did not converge to zero.
4220 
4221     Further Details
4222     ===============
4223 
4224     Based on contributions by
4225        Ming Gu and Ren-Cang Li, Computer Science Division, University of
4226          California at Berkeley, USA
4227        Osni Marques, LBNL/NERSC, USA
4228 
4229     =====================================================================
4230 
4231 
4232        Test the input arguments.
4233 */
4234 
4235     /* Parameter adjustments */
4236     a_dim1 = *lda;
4237     a_offset = 1 + a_dim1;
4238     a -= a_offset;
4239     b_dim1 = *ldb;
4240     b_offset = 1 + b_dim1;
4241     b -= b_offset;
4242     --s;
4243     --work;
4244     --iwork;
4245 
4246     /* Function Body */
4247     *info = 0;
4248     minmn = min(*m,*n);
4249     maxmn = max(*m,*n);
4250     mnthr = ilaenv_(&c__6, "DGELSD", " ", m, n, nrhs, &c_n1, (ftnlen)6, (
4251 	    ftnlen)1);
4252     lquery = *lwork == -1;
4253     if (*m < 0) {
4254 	*info = -1;
4255     } else if (*n < 0) {
4256 	*info = -2;
4257     } else if (*nrhs < 0) {
4258 	*info = -3;
4259     } else if (*lda < max(1,*m)) {
4260 	*info = -5;
4261     } else if (*ldb < max(1,maxmn)) {
4262 	*info = -7;
4263     }
4264 
4265     smlsiz = ilaenv_(&c__9, "DGELSD", " ", &c__0, &c__0, &c__0, &c__0, (
4266 	    ftnlen)6, (ftnlen)1);
4267 
4268 /*
4269        Compute workspace.
4270        (Note: Comments in the code beginning "Workspace:" describe the
4271        minimal amount of workspace needed at that point in the code,
4272        as well as the preferred amount for good performance.
4273        NB refers to the optimal block size for the immediately
4274        following subroutine, as returned by ILAENV.)
4275 */
4276 
4277     minwrk = 1;
4278     liwork = 1;
4279     minmn = max(1,minmn);
4280 /* Computing MAX */
4281     i__1 = (integer) (log((doublereal) minmn / (doublereal) (smlsiz + 1)) /
4282 	    log(2.)) + 1;
4283     nlvl = max(i__1,0);
4284 
4285     if (*info == 0) {
4286 	maxwrk = 0;
4287 	liwork = minmn * 3 * nlvl + minmn * 11;
4288 	mm = *m;
4289 	if (*m >= *n && *m >= mnthr) {
4290 
4291 /*           Path 1a - overdetermined, with many more rows than columns. */
4292 
4293 	    mm = *n;
4294 /* Computing MAX */
4295 	    i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "DGEQRF", " ", m,
4296 		    n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4297 	    maxwrk = max(i__1,i__2);
4298 /* Computing MAX */
4299 	    i__1 = maxwrk, i__2 = *n + *nrhs * ilaenv_(&c__1, "DORMQR", "LT",
4300 		    m, nrhs, n, &c_n1, (ftnlen)6, (ftnlen)2);
4301 	    maxwrk = max(i__1,i__2);
4302 	}
4303 	if (*m >= *n) {
4304 
4305 /*
4306              Path 1 - overdetermined or exactly determined.
4307 
4308    Computing MAX
4309 */
4310 	    i__1 = maxwrk, i__2 = *n * 3 + (mm + *n) * ilaenv_(&c__1, "DGEBRD"
4311 		    , " ", &mm, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4312 	    maxwrk = max(i__1,i__2);
4313 /* Computing MAX */
4314 	    i__1 = maxwrk, i__2 = *n * 3 + *nrhs * ilaenv_(&c__1, "DORMBR",
4315 		    "QLT", &mm, nrhs, n, &c_n1, (ftnlen)6, (ftnlen)3);
4316 	    maxwrk = max(i__1,i__2);
4317 /* Computing MAX */
4318 	    i__1 = maxwrk, i__2 = *n * 3 + (*n - 1) * ilaenv_(&c__1, "DORMBR",
4319 		     "PLN", n, nrhs, n, &c_n1, (ftnlen)6, (ftnlen)3);
4320 	    maxwrk = max(i__1,i__2);
4321 /* Computing 2nd power */
4322 	    i__1 = smlsiz + 1;
4323 	    wlalsd = *n * 9 + (*n << 1) * smlsiz + (*n << 3) * nlvl + *n * *
4324 		    nrhs + i__1 * i__1;
4325 /* Computing MAX */
4326 	    i__1 = maxwrk, i__2 = *n * 3 + wlalsd;
4327 	    maxwrk = max(i__1,i__2);
4328 /* Computing MAX */
4329 	    i__1 = *n * 3 + mm, i__2 = *n * 3 + *nrhs, i__1 = max(i__1,i__2),
4330 		    i__2 = *n * 3 + wlalsd;
4331 	    minwrk = max(i__1,i__2);
4332 	}
4333 	if (*n > *m) {
4334 /* Computing 2nd power */
4335 	    i__1 = smlsiz + 1;
4336 	    wlalsd = *m * 9 + (*m << 1) * smlsiz + (*m << 3) * nlvl + *m * *
4337 		    nrhs + i__1 * i__1;
4338 	    if (*n >= mnthr) {
4339 
4340 /*
4341                 Path 2a - underdetermined, with many more columns
4342                 than rows.
4343 */
4344 
4345 		maxwrk = *m + *m * ilaenv_(&c__1, "DGELQF", " ", m, n, &c_n1,
4346 			&c_n1, (ftnlen)6, (ftnlen)1);
4347 /* Computing MAX */
4348 		i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + (*m << 1) *
4349 			ilaenv_(&c__1, "DGEBRD", " ", m, m, &c_n1, &c_n1, (
4350 			ftnlen)6, (ftnlen)1);
4351 		maxwrk = max(i__1,i__2);
4352 /* Computing MAX */
4353 		i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + *nrhs * ilaenv_(&
4354 			c__1, "DORMBR", "QLT", m, nrhs, m, &c_n1, (ftnlen)6, (
4355 			ftnlen)3);
4356 		maxwrk = max(i__1,i__2);
4357 /* Computing MAX */
4358 		i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + (*m - 1) *
4359 			ilaenv_(&c__1, "DORMBR", "PLN", m, nrhs, m, &c_n1, (
4360 			ftnlen)6, (ftnlen)3);
4361 		maxwrk = max(i__1,i__2);
4362 		if (*nrhs > 1) {
4363 /* Computing MAX */
4364 		    i__1 = maxwrk, i__2 = *m * *m + *m + *m * *nrhs;
4365 		    maxwrk = max(i__1,i__2);
4366 		} else {
4367 /* Computing MAX */
4368 		    i__1 = maxwrk, i__2 = *m * *m + (*m << 1);
4369 		    maxwrk = max(i__1,i__2);
4370 		}
4371 /* Computing MAX */
4372 		i__1 = maxwrk, i__2 = *m + *nrhs * ilaenv_(&c__1, "DORMLQ",
4373 			"LT", n, nrhs, m, &c_n1, (ftnlen)6, (ftnlen)2);
4374 		maxwrk = max(i__1,i__2);
4375 /* Computing MAX */
4376 		i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + wlalsd;
4377 		maxwrk = max(i__1,i__2);
4378 /*
4379        XXX: Ensure the Path 2a case below is triggered.  The workspace
4380        calculation should use queries for all routines eventually.
4381    Computing MAX
4382    Computing MAX
4383 */
4384 		i__3 = *m, i__4 = (*m << 1) - 4, i__3 = max(i__3,i__4), i__3 =
4385 			 max(i__3,*nrhs), i__4 = *n - *m * 3;
4386 		i__1 = maxwrk, i__2 = (*m << 2) + *m * *m + max(i__3,i__4);
4387 		maxwrk = max(i__1,i__2);
4388 	    } else {
4389 
4390 /*              Path 2 - remaining underdetermined cases. */
4391 
4392 		maxwrk = *m * 3 + (*n + *m) * ilaenv_(&c__1, "DGEBRD", " ", m,
4393 			 n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4394 /* Computing MAX */
4395 		i__1 = maxwrk, i__2 = *m * 3 + *nrhs * ilaenv_(&c__1, "DORMBR"
4396 			, "QLT", m, nrhs, n, &c_n1, (ftnlen)6, (ftnlen)3);
4397 		maxwrk = max(i__1,i__2);
4398 /* Computing MAX */
4399 		i__1 = maxwrk, i__2 = *m * 3 + *m * ilaenv_(&c__1, "DORMBR",
4400 			"PLN", n, nrhs, m, &c_n1, (ftnlen)6, (ftnlen)3);
4401 		maxwrk = max(i__1,i__2);
4402 /* Computing MAX */
4403 		i__1 = maxwrk, i__2 = *m * 3 + wlalsd;
4404 		maxwrk = max(i__1,i__2);
4405 	    }
4406 /* Computing MAX */
4407 	    i__1 = *m * 3 + *nrhs, i__2 = *m * 3 + *m, i__1 = max(i__1,i__2),
4408 		    i__2 = *m * 3 + wlalsd;
4409 	    minwrk = max(i__1,i__2);
4410 	}
4411 	minwrk = min(minwrk,maxwrk);
4412 	work[1] = (doublereal) maxwrk;
4413 	iwork[1] = liwork;
4414 	if (*lwork < minwrk && ! lquery) {
4415 	    *info = -12;
4416 	}
4417     }
4418 
4419     if (*info != 0) {
4420 	i__1 = -(*info);
4421 	xerbla_("DGELSD", &i__1);
4422 	return 0;
4423     } else if (lquery) {
4424 	goto L10;
4425     }
4426 
4427 /*     Quick return if possible. */
4428 
4429     if (*m == 0 || *n == 0) {
4430 	*rank = 0;
4431 	return 0;
4432     }
4433 
4434 /*     Get machine parameters. */
4435 
4436     eps = PRECISION;
4437     sfmin = SAFEMINIMUM;
4438     smlnum = sfmin / eps;
4439     bignum = 1. / smlnum;
4440     dlabad_(&smlnum, &bignum);
4441 
4442 /*     Scale A if max entry outside range [SMLNUM,BIGNUM]. */
4443 
4444     anrm = dlange_("M", m, n, &a[a_offset], lda, &work[1]);
4445     iascl = 0;
4446     if (anrm > 0. && anrm < smlnum) {
4447 
4448 /*        Scale matrix norm up to SMLNUM. */
4449 
4450 	dlascl_("G", &c__0, &c__0, &anrm, &smlnum, m, n, &a[a_offset], lda,
4451 		info);
4452 	iascl = 1;
4453     } else if (anrm > bignum) {
4454 
4455 /*        Scale matrix norm down to BIGNUM. */
4456 
4457 	dlascl_("G", &c__0, &c__0, &anrm, &bignum, m, n, &a[a_offset], lda,
4458 		info);
4459 	iascl = 2;
4460     } else if (anrm == 0.) {
4461 
4462 /*        Matrix all zero. Return zero solution. */
4463 
4464 	i__1 = max(*m,*n);
4465 	dlaset_("F", &i__1, nrhs, &c_b29, &c_b29, &b[b_offset], ldb);
4466 	dlaset_("F", &minmn, &c__1, &c_b29, &c_b29, &s[1], &c__1);
4467 	*rank = 0;
4468 	goto L10;
4469     }
4470 
4471 /*     Scale B if max entry outside range [SMLNUM,BIGNUM]. */
4472 
4473     bnrm = dlange_("M", m, nrhs, &b[b_offset], ldb, &work[1]);
4474     ibscl = 0;
4475     if (bnrm > 0. && bnrm < smlnum) {
4476 
4477 /*        Scale matrix norm up to SMLNUM. */
4478 
4479 	dlascl_("G", &c__0, &c__0, &bnrm, &smlnum, m, nrhs, &b[b_offset], ldb,
4480 		 info);
4481 	ibscl = 1;
4482     } else if (bnrm > bignum) {
4483 
4484 /*        Scale matrix norm down to BIGNUM. */
4485 
4486 	dlascl_("G", &c__0, &c__0, &bnrm, &bignum, m, nrhs, &b[b_offset], ldb,
4487 		 info);
4488 	ibscl = 2;
4489     }
4490 
4491 /*     If M < N make sure certain entries of B are zero. */
4492 
4493     if (*m < *n) {
4494 	i__1 = *n - *m;
4495 	dlaset_("F", &i__1, nrhs, &c_b29, &c_b29, &b[*m + 1 + b_dim1], ldb);
4496     }
4497 
4498 /*     Overdetermined case. */
4499 
4500     if (*m >= *n) {
4501 
4502 /*        Path 1 - overdetermined or exactly determined. */
4503 
4504 	mm = *m;
4505 	if (*m >= mnthr) {
4506 
4507 /*           Path 1a - overdetermined, with many more rows than columns. */
4508 
4509 	    mm = *n;
4510 	    itau = 1;
4511 	    nwork = itau + *n;
4512 
4513 /*
4514              Compute A=Q*R.
4515              (Workspace: need 2*N, prefer N+N*NB)
4516 */
4517 
4518 	    i__1 = *lwork - nwork + 1;
4519 	    dgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &i__1,
4520 		     info);
4521 
4522 /*
4523              Multiply B by transpose(Q).
4524              (Workspace: need N+NRHS, prefer N+NRHS*NB)
4525 */
4526 
4527 	    i__1 = *lwork - nwork + 1;
4528 	    dormqr_("L", "T", m, nrhs, n, &a[a_offset], lda, &work[itau], &b[
4529 		    b_offset], ldb, &work[nwork], &i__1, info);
4530 
4531 /*           Zero out below R. */
4532 
4533 	    if (*n > 1) {
4534 		i__1 = *n - 1;
4535 		i__2 = *n - 1;
4536 		dlaset_("L", &i__1, &i__2, &c_b29, &c_b29, &a[a_dim1 + 2],
4537 			lda);
4538 	    }
4539 	}
4540 
4541 	ie = 1;
4542 	itauq = ie + *n;
4543 	itaup = itauq + *n;
4544 	nwork = itaup + *n;
4545 
4546 /*
4547           Bidiagonalize R in A.
4548           (Workspace: need 3*N+MM, prefer 3*N+(MM+N)*NB)
4549 */
4550 
4551 	i__1 = *lwork - nwork + 1;
4552 	dgebrd_(&mm, n, &a[a_offset], lda, &s[1], &work[ie], &work[itauq], &
4553 		work[itaup], &work[nwork], &i__1, info);
4554 
4555 /*
4556           Multiply B by transpose of left bidiagonalizing vectors of R.
4557           (Workspace: need 3*N+NRHS, prefer 3*N+NRHS*NB)
4558 */
4559 
4560 	i__1 = *lwork - nwork + 1;
4561 	dormbr_("Q", "L", "T", &mm, nrhs, n, &a[a_offset], lda, &work[itauq],
4562 		&b[b_offset], ldb, &work[nwork], &i__1, info);
4563 
4564 /*        Solve the bidiagonal least squares problem. */
4565 
4566 	dlalsd_("U", &smlsiz, n, nrhs, &s[1], &work[ie], &b[b_offset], ldb,
4567 		rcond, rank, &work[nwork], &iwork[1], info);
4568 	if (*info != 0) {
4569 	    goto L10;
4570 	}
4571 
4572 /*        Multiply B by right bidiagonalizing vectors of R. */
4573 
4574 	i__1 = *lwork - nwork + 1;
4575 	dormbr_("P", "L", "N", n, nrhs, n, &a[a_offset], lda, &work[itaup], &
4576 		b[b_offset], ldb, &work[nwork], &i__1, info);
4577 
4578     } else /* if(complicated condition) */ {
4579 /* Computing MAX */
4580 	i__1 = *m, i__2 = (*m << 1) - 4, i__1 = max(i__1,i__2), i__1 = max(
4581 		i__1,*nrhs), i__2 = *n - *m * 3, i__1 = max(i__1,i__2);
4582 	if (*n >= mnthr && *lwork >= (*m << 2) + *m * *m + max(i__1,wlalsd)) {
4583 
4584 /*
4585           Path 2a - underdetermined, with many more columns than rows
4586           and sufficient workspace for an efficient algorithm.
4587 */
4588 
4589 	    ldwork = *m;
4590 /*
4591    Computing MAX
4592    Computing MAX
4593 */
4594 	    i__3 = *m, i__4 = (*m << 1) - 4, i__3 = max(i__3,i__4), i__3 =
4595 		    max(i__3,*nrhs), i__4 = *n - *m * 3;
4596 	    i__1 = (*m << 2) + *m * *lda + max(i__3,i__4), i__2 = *m * *lda +
4597 		    *m + *m * *nrhs, i__1 = max(i__1,i__2), i__2 = (*m << 2)
4598 		    + *m * *lda + wlalsd;
4599 	    if (*lwork >= max(i__1,i__2)) {
4600 		ldwork = *lda;
4601 	    }
4602 	    itau = 1;
4603 	    nwork = *m + 1;
4604 
4605 /*
4606           Compute A=L*Q.
4607           (Workspace: need 2*M, prefer M+M*NB)
4608 */
4609 
4610 	    i__1 = *lwork - nwork + 1;
4611 	    dgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &i__1,
4612 		     info);
4613 	    il = nwork;
4614 
4615 /*        Copy L to WORK(IL), zeroing out above its diagonal. */
4616 
4617 	    dlacpy_("L", m, m, &a[a_offset], lda, &work[il], &ldwork);
4618 	    i__1 = *m - 1;
4619 	    i__2 = *m - 1;
4620 	    dlaset_("U", &i__1, &i__2, &c_b29, &c_b29, &work[il + ldwork], &
4621 		    ldwork);
4622 	    ie = il + ldwork * *m;
4623 	    itauq = ie + *m;
4624 	    itaup = itauq + *m;
4625 	    nwork = itaup + *m;
4626 
4627 /*
4628           Bidiagonalize L in WORK(IL).
4629           (Workspace: need M*M+5*M, prefer M*M+4*M+2*M*NB)
4630 */
4631 
4632 	    i__1 = *lwork - nwork + 1;
4633 	    dgebrd_(m, m, &work[il], &ldwork, &s[1], &work[ie], &work[itauq],
4634 		    &work[itaup], &work[nwork], &i__1, info);
4635 
4636 /*
4637           Multiply B by transpose of left bidiagonalizing vectors of L.
4638           (Workspace: need M*M+4*M+NRHS, prefer M*M+4*M+NRHS*NB)
4639 */
4640 
4641 	    i__1 = *lwork - nwork + 1;
4642 	    dormbr_("Q", "L", "T", m, nrhs, m, &work[il], &ldwork, &work[
4643 		    itauq], &b[b_offset], ldb, &work[nwork], &i__1, info);
4644 
4645 /*        Solve the bidiagonal least squares problem. */
4646 
4647 	    dlalsd_("U", &smlsiz, m, nrhs, &s[1], &work[ie], &b[b_offset],
4648 		    ldb, rcond, rank, &work[nwork], &iwork[1], info);
4649 	    if (*info != 0) {
4650 		goto L10;
4651 	    }
4652 
4653 /*        Multiply B by right bidiagonalizing vectors of L. */
4654 
4655 	    i__1 = *lwork - nwork + 1;
4656 	    dormbr_("P", "L", "N", m, nrhs, m, &work[il], &ldwork, &work[
4657 		    itaup], &b[b_offset], ldb, &work[nwork], &i__1, info);
4658 
4659 /*        Zero out below first M rows of B. */
4660 
4661 	    i__1 = *n - *m;
4662 	    dlaset_("F", &i__1, nrhs, &c_b29, &c_b29, &b[*m + 1 + b_dim1],
4663 		    ldb);
4664 	    nwork = itau + *m;
4665 
4666 /*
4667           Multiply transpose(Q) by B.
4668           (Workspace: need M+NRHS, prefer M+NRHS*NB)
4669 */
4670 
4671 	    i__1 = *lwork - nwork + 1;
4672 	    dormlq_("L", "T", n, nrhs, m, &a[a_offset], lda, &work[itau], &b[
4673 		    b_offset], ldb, &work[nwork], &i__1, info);
4674 
4675 	} else {
4676 
4677 /*        Path 2 - remaining underdetermined cases. */
4678 
4679 	    ie = 1;
4680 	    itauq = ie + *m;
4681 	    itaup = itauq + *m;
4682 	    nwork = itaup + *m;
4683 
4684 /*
4685           Bidiagonalize A.
4686           (Workspace: need 3*M+N, prefer 3*M+(M+N)*NB)
4687 */
4688 
4689 	    i__1 = *lwork - nwork + 1;
4690 	    dgebrd_(m, n, &a[a_offset], lda, &s[1], &work[ie], &work[itauq], &
4691 		    work[itaup], &work[nwork], &i__1, info);
4692 
4693 /*
4694           Multiply B by transpose of left bidiagonalizing vectors.
4695           (Workspace: need 3*M+NRHS, prefer 3*M+NRHS*NB)
4696 */
4697 
4698 	    i__1 = *lwork - nwork + 1;
4699 	    dormbr_("Q", "L", "T", m, nrhs, n, &a[a_offset], lda, &work[itauq]
4700 		    , &b[b_offset], ldb, &work[nwork], &i__1, info);
4701 
4702 /*        Solve the bidiagonal least squares problem. */
4703 
4704 	    dlalsd_("L", &smlsiz, m, nrhs, &s[1], &work[ie], &b[b_offset],
4705 		    ldb, rcond, rank, &work[nwork], &iwork[1], info);
4706 	    if (*info != 0) {
4707 		goto L10;
4708 	    }
4709 
4710 /*        Multiply B by right bidiagonalizing vectors of A. */
4711 
4712 	    i__1 = *lwork - nwork + 1;
4713 	    dormbr_("P", "L", "N", n, nrhs, m, &a[a_offset], lda, &work[itaup]
4714 		    , &b[b_offset], ldb, &work[nwork], &i__1, info);
4715 
4716 	}
4717     }
4718 
4719 /*     Undo scaling. */
4720 
4721     if (iascl == 1) {
4722 	dlascl_("G", &c__0, &c__0, &anrm, &smlnum, n, nrhs, &b[b_offset], ldb,
4723 		 info);
4724 	dlascl_("G", &c__0, &c__0, &smlnum, &anrm, &minmn, &c__1, &s[1], &
4725 		minmn, info);
4726     } else if (iascl == 2) {
4727 	dlascl_("G", &c__0, &c__0, &anrm, &bignum, n, nrhs, &b[b_offset], ldb,
4728 		 info);
4729 	dlascl_("G", &c__0, &c__0, &bignum, &anrm, &minmn, &c__1, &s[1], &
4730 		minmn, info);
4731     }
4732     if (ibscl == 1) {
4733 	dlascl_("G", &c__0, &c__0, &smlnum, &bnrm, n, nrhs, &b[b_offset], ldb,
4734 		 info);
4735     } else if (ibscl == 2) {
4736 	dlascl_("G", &c__0, &c__0, &bignum, &bnrm, n, nrhs, &b[b_offset], ldb,
4737 		 info);
4738     }
4739 
4740 L10:
4741     work[1] = (doublereal) maxwrk;
4742     iwork[1] = liwork;
4743     return 0;
4744 
4745 /*     End of DGELSD */
4746 
4747 } /* dgelsd_ */
4748 
dgeqr2_(integer * m,integer * n,doublereal * a,integer * lda,doublereal * tau,doublereal * work,integer * info)4749 /* Subroutine */ int dgeqr2_(integer *m, integer *n, doublereal *a, integer *
4750 	lda, doublereal *tau, doublereal *work, integer *info)
4751 {
4752     /* System generated locals */
4753     integer a_dim1, a_offset, i__1, i__2, i__3;
4754 
4755     /* Local variables */
4756     static integer i__, k;
4757     static doublereal aii;
4758     extern /* Subroutine */ int dlarf_(char *, integer *, integer *,
4759 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
4760 	    doublereal *), dlarfg_(integer *, doublereal *,
4761 	    doublereal *, integer *, doublereal *), xerbla_(char *, integer *);
4762 
4763 
4764 /*
4765     -- LAPACK routine (version 3.2.2) --
4766     -- LAPACK is a software package provided by Univ. of Tennessee,    --
4767     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
4768        June 2010
4769 
4770 
4771     Purpose
4772     =======
4773 
4774     DGEQR2 computes a QR factorization of a real m by n matrix A:
4775     A = Q * R.
4776 
4777     Arguments
4778     =========
4779 
4780     M       (input) INTEGER
4781             The number of rows of the matrix A.  M >= 0.
4782 
4783     N       (input) INTEGER
4784             The number of columns of the matrix A.  N >= 0.
4785 
4786     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
4787             On entry, the m by n matrix A.
4788             On exit, the elements on and above the diagonal of the array
4789             contain the min(m,n) by n upper trapezoidal matrix R (R is
4790             upper triangular if m >= n); the elements below the diagonal,
4791             with the array TAU, represent the orthogonal matrix Q as a
4792             product of elementary reflectors (see Further Details).
4793 
4794     LDA     (input) INTEGER
4795             The leading dimension of the array A.  LDA >= max(1,M).
4796 
4797     TAU     (output) DOUBLE PRECISION array, dimension (min(M,N))
4798             The scalar factors of the elementary reflectors (see Further
4799             Details).
4800 
4801     WORK    (workspace) DOUBLE PRECISION array, dimension (N)
4802 
4803     INFO    (output) INTEGER
4804             = 0: successful exit
4805             < 0: if INFO = -i, the i-th argument had an illegal value
4806 
4807     Further Details
4808     ===============
4809 
4810     The matrix Q is represented as a product of elementary reflectors
4811 
4812        Q = H(1) H(2) . . . H(k), where k = min(m,n).
4813 
4814     Each H(i) has the form
4815 
4816        H(i) = I - tau * v * v'
4817 
4818     where tau is a real scalar, and v is a real vector with
4819     v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i),
4820     and tau in TAU(i).
4821 
4822     =====================================================================
4823 
4824 
4825        Test the input arguments
4826 */
4827 
4828     /* Parameter adjustments */
4829     a_dim1 = *lda;
4830     a_offset = 1 + a_dim1;
4831     a -= a_offset;
4832     --tau;
4833     --work;
4834 
4835     /* Function Body */
4836     *info = 0;
4837     if (*m < 0) {
4838 	*info = -1;
4839     } else if (*n < 0) {
4840 	*info = -2;
4841     } else if (*lda < max(1,*m)) {
4842 	*info = -4;
4843     }
4844     if (*info != 0) {
4845 	i__1 = -(*info);
4846 	xerbla_("DGEQR2", &i__1);
4847 	return 0;
4848     }
4849 
4850     k = min(*m,*n);
4851 
4852     i__1 = k;
4853     for (i__ = 1; i__ <= i__1; ++i__) {
4854 
4855 /*        Generate elementary reflector H(i) to annihilate A(i+1:m,i) */
4856 
4857 	i__2 = *m - i__ + 1;
4858 /* Computing MIN */
4859 	i__3 = i__ + 1;
4860 	dlarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[min(i__3,*m) + i__ * a_dim1]
4861 		, &c__1, &tau[i__]);
4862 	if (i__ < *n) {
4863 
4864 /*           Apply H(i) to A(i:m,i+1:n) from the left */
4865 
4866 	    aii = a[i__ + i__ * a_dim1];
4867 	    a[i__ + i__ * a_dim1] = 1.;
4868 	    i__2 = *m - i__ + 1;
4869 	    i__3 = *n - i__;
4870 	    dlarf_("Left", &i__2, &i__3, &a[i__ + i__ * a_dim1], &c__1, &tau[
4871 		    i__], &a[i__ + (i__ + 1) * a_dim1], lda, &work[1]);
4872 	    a[i__ + i__ * a_dim1] = aii;
4873 	}
4874 /* L10: */
4875     }
4876     return 0;
4877 
4878 /*     End of DGEQR2 */
4879 
4880 } /* dgeqr2_ */
4881 
dgeqrf_(integer * m,integer * n,doublereal * a,integer * lda,doublereal * tau,doublereal * work,integer * lwork,integer * info)4882 /* Subroutine */ int dgeqrf_(integer *m, integer *n, doublereal *a, integer *
4883 	lda, doublereal *tau, doublereal *work, integer *lwork, integer *info)
4884 {
4885     /* System generated locals */
4886     integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
4887 
4888     /* Local variables */
4889     static integer i__, k, ib, nb, nx, iws, nbmin, iinfo;
4890     extern /* Subroutine */ int dgeqr2_(integer *, integer *, doublereal *,
4891 	    integer *, doublereal *, doublereal *, integer *), dlarfb_(char *,
4892 	     char *, char *, char *, integer *, integer *, integer *,
4893 	    doublereal *, integer *, doublereal *, integer *, doublereal *,
4894 	    integer *, doublereal *, integer *), dlarft_(char *, char *, integer *, integer *, doublereal
4895 	    *, integer *, doublereal *, doublereal *, integer *), xerbla_(char *, integer *);
4896     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
4897 	    integer *, integer *, ftnlen, ftnlen);
4898     static integer ldwork, lwkopt;
4899     static logical lquery;
4900 
4901 
4902 /*
4903     -- LAPACK routine (version 3.2) --
4904     -- LAPACK is a software package provided by Univ. of Tennessee,    --
4905     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
4906        November 2006
4907 
4908 
4909     Purpose
4910     =======
4911 
4912     DGEQRF computes a QR factorization of a real M-by-N matrix A:
4913     A = Q * R.
4914 
4915     Arguments
4916     =========
4917 
4918     M       (input) INTEGER
4919             The number of rows of the matrix A.  M >= 0.
4920 
4921     N       (input) INTEGER
4922             The number of columns of the matrix A.  N >= 0.
4923 
4924     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
4925             On entry, the M-by-N matrix A.
4926             On exit, the elements on and above the diagonal of the array
4927             contain the min(M,N)-by-N upper trapezoidal matrix R (R is
4928             upper triangular if m >= n); the elements below the diagonal,
4929             with the array TAU, represent the orthogonal matrix Q as a
4930             product of min(m,n) elementary reflectors (see Further
4931             Details).
4932 
4933     LDA     (input) INTEGER
4934             The leading dimension of the array A.  LDA >= max(1,M).
4935 
4936     TAU     (output) DOUBLE PRECISION array, dimension (min(M,N))
4937             The scalar factors of the elementary reflectors (see Further
4938             Details).
4939 
4940     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
4941             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
4942 
4943     LWORK   (input) INTEGER
4944             The dimension of the array WORK.  LWORK >= max(1,N).
4945             For optimum performance LWORK >= N*NB, where NB is
4946             the optimal blocksize.
4947 
4948             If LWORK = -1, then a workspace query is assumed; the routine
4949             only calculates the optimal size of the WORK array, returns
4950             this value as the first entry of the WORK array, and no error
4951             message related to LWORK is issued by XERBLA.
4952 
4953     INFO    (output) INTEGER
4954             = 0:  successful exit
4955             < 0:  if INFO = -i, the i-th argument had an illegal value
4956 
4957     Further Details
4958     ===============
4959 
4960     The matrix Q is represented as a product of elementary reflectors
4961 
4962        Q = H(1) H(2) . . . H(k), where k = min(m,n).
4963 
4964     Each H(i) has the form
4965 
4966        H(i) = I - tau * v * v'
4967 
4968     where tau is a real scalar, and v is a real vector with
4969     v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i),
4970     and tau in TAU(i).
4971 
4972     =====================================================================
4973 
4974 
4975        Test the input arguments
4976 */
4977 
4978     /* Parameter adjustments */
4979     a_dim1 = *lda;
4980     a_offset = 1 + a_dim1;
4981     a -= a_offset;
4982     --tau;
4983     --work;
4984 
4985     /* Function Body */
4986     *info = 0;
4987     nb = ilaenv_(&c__1, "DGEQRF", " ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)
4988 	    1);
4989     lwkopt = *n * nb;
4990     work[1] = (doublereal) lwkopt;
4991     lquery = *lwork == -1;
4992     if (*m < 0) {
4993 	*info = -1;
4994     } else if (*n < 0) {
4995 	*info = -2;
4996     } else if (*lda < max(1,*m)) {
4997 	*info = -4;
4998     } else if (*lwork < max(1,*n) && ! lquery) {
4999 	*info = -7;
5000     }
5001     if (*info != 0) {
5002 	i__1 = -(*info);
5003 	xerbla_("DGEQRF", &i__1);
5004 	return 0;
5005     } else if (lquery) {
5006 	return 0;
5007     }
5008 
5009 /*     Quick return if possible */
5010 
5011     k = min(*m,*n);
5012     if (k == 0) {
5013 	work[1] = 1.;
5014 	return 0;
5015     }
5016 
5017     nbmin = 2;
5018     nx = 0;
5019     iws = *n;
5020     if (nb > 1 && nb < k) {
5021 
5022 /*
5023           Determine when to cross over from blocked to unblocked code.
5024 
5025    Computing MAX
5026 */
5027 	i__1 = 0, i__2 = ilaenv_(&c__3, "DGEQRF", " ", m, n, &c_n1, &c_n1, (
5028 		ftnlen)6, (ftnlen)1);
5029 	nx = max(i__1,i__2);
5030 	if (nx < k) {
5031 
5032 /*           Determine if workspace is large enough for blocked code. */
5033 
5034 	    ldwork = *n;
5035 	    iws = ldwork * nb;
5036 	    if (*lwork < iws) {
5037 
5038 /*
5039                 Not enough workspace to use optimal NB:  reduce NB and
5040                 determine the minimum value of NB.
5041 */
5042 
5043 		nb = *lwork / ldwork;
5044 /* Computing MAX */
5045 		i__1 = 2, i__2 = ilaenv_(&c__2, "DGEQRF", " ", m, n, &c_n1, &
5046 			c_n1, (ftnlen)6, (ftnlen)1);
5047 		nbmin = max(i__1,i__2);
5048 	    }
5049 	}
5050     }
5051 
5052     if (nb >= nbmin && nb < k && nx < k) {
5053 
5054 /*        Use blocked code initially */
5055 
5056 	i__1 = k - nx;
5057 	i__2 = nb;
5058 	for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
5059 /* Computing MIN */
5060 	    i__3 = k - i__ + 1;
5061 	    ib = min(i__3,nb);
5062 
5063 /*
5064              Compute the QR factorization of the current block
5065              A(i:m,i:i+ib-1)
5066 */
5067 
5068 	    i__3 = *m - i__ + 1;
5069 	    dgeqr2_(&i__3, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[
5070 		    1], &iinfo);
5071 	    if (i__ + ib <= *n) {
5072 
5073 /*
5074                 Form the triangular factor of the block reflector
5075                 H = H(i) H(i+1) . . . H(i+ib-1)
5076 */
5077 
5078 		i__3 = *m - i__ + 1;
5079 		dlarft_("Forward", "Columnwise", &i__3, &ib, &a[i__ + i__ *
5080 			a_dim1], lda, &tau[i__], &work[1], &ldwork);
5081 
5082 /*              Apply H' to A(i:m,i+ib:n) from the left */
5083 
5084 		i__3 = *m - i__ + 1;
5085 		i__4 = *n - i__ - ib + 1;
5086 		dlarfb_("Left", "Transpose", "Forward", "Columnwise", &i__3, &
5087 			i__4, &ib, &a[i__ + i__ * a_dim1], lda, &work[1], &
5088 			ldwork, &a[i__ + (i__ + ib) * a_dim1], lda, &work[ib
5089 			+ 1], &ldwork);
5090 	    }
5091 /* L10: */
5092 	}
5093     } else {
5094 	i__ = 1;
5095     }
5096 
5097 /*     Use unblocked code to factor the last or only block. */
5098 
5099     if (i__ <= k) {
5100 	i__2 = *m - i__ + 1;
5101 	i__1 = *n - i__ + 1;
5102 	dgeqr2_(&i__2, &i__1, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[1]
5103 		, &iinfo);
5104     }
5105 
5106     work[1] = (doublereal) iws;
5107     return 0;
5108 
5109 /*     End of DGEQRF */
5110 
5111 } /* dgeqrf_ */
5112 
dgesdd_(char * jobz,integer * m,integer * n,doublereal * a,integer * lda,doublereal * s,doublereal * u,integer * ldu,doublereal * vt,integer * ldvt,doublereal * work,integer * lwork,integer * iwork,integer * info)5113 /* Subroutine */ int dgesdd_(char *jobz, integer *m, integer *n, doublereal *
5114 	a, integer *lda, doublereal *s, doublereal *u, integer *ldu,
5115 	doublereal *vt, integer *ldvt, doublereal *work, integer *lwork,
5116 	integer *iwork, integer *info)
5117 {
5118     /* System generated locals */
5119     integer a_dim1, a_offset, u_dim1, u_offset, vt_dim1, vt_offset, i__1,
5120 	    i__2, i__3;
5121 
5122     /* Local variables */
5123     static integer i__, ie, il, ir, iu, blk;
5124     static doublereal dum[1], eps;
5125     static integer ivt, iscl;
5126     static doublereal anrm;
5127     static integer idum[1], ierr, itau;
5128     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
5129 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
5130 	    integer *, doublereal *, doublereal *, integer *);
5131     extern logical lsame_(char *, char *);
5132     static integer chunk, minmn, wrkbl, itaup, itauq, mnthr;
5133     static logical wntqa;
5134     static integer nwork;
5135     static logical wntqn, wntqo, wntqs;
5136     extern /* Subroutine */ int dbdsdc_(char *, char *, integer *, doublereal
5137 	    *, doublereal *, doublereal *, integer *, doublereal *, integer *,
5138 	     doublereal *, integer *, doublereal *, integer *, integer *), dgebrd_(integer *, integer *, doublereal *,
5139 	    integer *, doublereal *, doublereal *, doublereal *, doublereal *,
5140 	     doublereal *, integer *, integer *);
5141     extern doublereal dlamch_(char *), dlange_(char *, integer *,
5142 	    integer *, doublereal *, integer *, doublereal *);
5143     static integer bdspac;
5144     extern /* Subroutine */ int dgelqf_(integer *, integer *, doublereal *,
5145 	    integer *, doublereal *, doublereal *, integer *, integer *),
5146 	    dlascl_(char *, integer *, integer *, doublereal *, doublereal *,
5147 	    integer *, integer *, doublereal *, integer *, integer *),
5148 	     dgeqrf_(integer *, integer *, doublereal *, integer *,
5149 	    doublereal *, doublereal *, integer *, integer *), dlacpy_(char *,
5150 	     integer *, integer *, doublereal *, integer *, doublereal *,
5151 	    integer *), dlaset_(char *, integer *, integer *,
5152 	    doublereal *, doublereal *, doublereal *, integer *),
5153 	    xerbla_(char *, integer *), dorgbr_(char *, integer *,
5154 	    integer *, integer *, doublereal *, integer *, doublereal *,
5155 	    doublereal *, integer *, integer *);
5156     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
5157 	    integer *, integer *, ftnlen, ftnlen);
5158     static doublereal bignum;
5159     extern /* Subroutine */ int dormbr_(char *, char *, char *, integer *,
5160 	    integer *, integer *, doublereal *, integer *, doublereal *,
5161 	    doublereal *, integer *, doublereal *, integer *, integer *), dorglq_(integer *, integer *, integer *,
5162 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
5163 	    integer *), dorgqr_(integer *, integer *, integer *, doublereal *,
5164 	     integer *, doublereal *, doublereal *, integer *, integer *);
5165     static integer ldwrkl, ldwrkr, minwrk, ldwrku, maxwrk, ldwkvt;
5166     static doublereal smlnum;
5167     static logical wntqas, lquery;
5168 
5169 
5170 /*
5171     -- LAPACK driver routine (version 3.2.1)                                  --
5172     -- LAPACK is a software package provided by Univ. of Tennessee,    --
5173     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
5174        March 2009
5175 
5176 
5177     Purpose
5178     =======
5179 
5180     DGESDD computes the singular value decomposition (SVD) of a real
5181     M-by-N matrix A, optionally computing the left and right singular
5182     vectors.  If singular vectors are desired, it uses a
5183     divide-and-conquer algorithm.
5184 
5185     The SVD is written
5186 
5187          A = U * SIGMA * transpose(V)
5188 
5189     where SIGMA is an M-by-N matrix which is zero except for its
5190     min(m,n) diagonal elements, U is an M-by-M orthogonal matrix, and
5191     V is an N-by-N orthogonal matrix.  The diagonal elements of SIGMA
5192     are the singular values of A; they are real and non-negative, and
5193     are returned in descending order.  The first min(m,n) columns of
5194     U and V are the left and right singular vectors of A.
5195 
5196     Note that the routine returns VT = V**T, not V.
5197 
5198     The divide and conquer algorithm makes very mild assumptions about
5199     floating point arithmetic. It will work on machines with a guard
5200     digit in add/subtract, or on those binary machines without guard
5201     digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or
5202     Cray-2. It could conceivably fail on hexadecimal or decimal machines
5203     without guard digits, but we know of none.
5204 
5205     Arguments
5206     =========
5207 
5208     JOBZ    (input) CHARACTER*1
5209             Specifies options for computing all or part of the matrix U:
5210             = 'A':  all M columns of U and all N rows of V**T are
5211                     returned in the arrays U and VT;
5212             = 'S':  the first min(M,N) columns of U and the first
5213                     min(M,N) rows of V**T are returned in the arrays U
5214                     and VT;
5215             = 'O':  If M >= N, the first N columns of U are overwritten
5216                     on the array A and all rows of V**T are returned in
5217                     the array VT;
5218                     otherwise, all columns of U are returned in the
5219                     array U and the first M rows of V**T are overwritten
5220                     in the array A;
5221             = 'N':  no columns of U or rows of V**T are computed.
5222 
5223     M       (input) INTEGER
5224             The number of rows of the input matrix A.  M >= 0.
5225 
5226     N       (input) INTEGER
5227             The number of columns of the input matrix A.  N >= 0.
5228 
5229     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
5230             On entry, the M-by-N matrix A.
5231             On exit,
5232             if JOBZ = 'O',  A is overwritten with the first N columns
5233                             of U (the left singular vectors, stored
5234                             columnwise) if M >= N;
5235                             A is overwritten with the first M rows
5236                             of V**T (the right singular vectors, stored
5237                             rowwise) otherwise.
5238             if JOBZ .ne. 'O', the contents of A are destroyed.
5239 
5240     LDA     (input) INTEGER
5241             The leading dimension of the array A.  LDA >= max(1,M).
5242 
5243     S       (output) DOUBLE PRECISION array, dimension (min(M,N))
5244             The singular values of A, sorted so that S(i) >= S(i+1).
5245 
5246     U       (output) DOUBLE PRECISION array, dimension (LDU,UCOL)
5247             UCOL = M if JOBZ = 'A' or JOBZ = 'O' and M < N;
5248             UCOL = min(M,N) if JOBZ = 'S'.
5249             If JOBZ = 'A' or JOBZ = 'O' and M < N, U contains the M-by-M
5250             orthogonal matrix U;
5251             if JOBZ = 'S', U contains the first min(M,N) columns of U
5252             (the left singular vectors, stored columnwise);
5253             if JOBZ = 'O' and M >= N, or JOBZ = 'N', U is not referenced.
5254 
5255     LDU     (input) INTEGER
5256             The leading dimension of the array U.  LDU >= 1; if
5257             JOBZ = 'S' or 'A' or JOBZ = 'O' and M < N, LDU >= M.
5258 
5259     VT      (output) DOUBLE PRECISION array, dimension (LDVT,N)
5260             If JOBZ = 'A' or JOBZ = 'O' and M >= N, VT contains the
5261             N-by-N orthogonal matrix V**T;
5262             if JOBZ = 'S', VT contains the first min(M,N) rows of
5263             V**T (the right singular vectors, stored rowwise);
5264             if JOBZ = 'O' and M < N, or JOBZ = 'N', VT is not referenced.
5265 
5266     LDVT    (input) INTEGER
5267             The leading dimension of the array VT.  LDVT >= 1; if
5268             JOBZ = 'A' or JOBZ = 'O' and M >= N, LDVT >= N;
5269             if JOBZ = 'S', LDVT >= min(M,N).
5270 
5271     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
5272             On exit, if INFO = 0, WORK(1) returns the optimal LWORK;
5273 
5274     LWORK   (input) INTEGER
5275             The dimension of the array WORK. LWORK >= 1.
5276             If JOBZ = 'N',
5277               LWORK >= 3*min(M,N) + max(max(M,N),7*min(M,N)).
5278             If JOBZ = 'O',
5279               LWORK >= 3*min(M,N) +
5280                        max(max(M,N),5*min(M,N)*min(M,N)+4*min(M,N)).
5281             If JOBZ = 'S' or 'A'
5282               LWORK >= 3*min(M,N) +
5283                        max(max(M,N),4*min(M,N)*min(M,N)+4*min(M,N)).
5284             For good performance, LWORK should generally be larger.
5285             If LWORK = -1 but other input arguments are legal, WORK(1)
5286             returns the optimal LWORK.
5287 
5288     IWORK   (workspace) INTEGER array, dimension (8*min(M,N))
5289 
5290     INFO    (output) INTEGER
5291             = 0:  successful exit.
5292             < 0:  if INFO = -i, the i-th argument had an illegal value.
5293             > 0:  DBDSDC did not converge, updating process failed.
5294 
5295     Further Details
5296     ===============
5297 
5298     Based on contributions by
5299        Ming Gu and Huan Ren, Computer Science Division, University of
5300        California at Berkeley, USA
5301 
5302     =====================================================================
5303 
5304 
5305        Test the input arguments
5306 */
5307 
5308     /* Parameter adjustments */
5309     a_dim1 = *lda;
5310     a_offset = 1 + a_dim1;
5311     a -= a_offset;
5312     --s;
5313     u_dim1 = *ldu;
5314     u_offset = 1 + u_dim1;
5315     u -= u_offset;
5316     vt_dim1 = *ldvt;
5317     vt_offset = 1 + vt_dim1;
5318     vt -= vt_offset;
5319     --work;
5320     --iwork;
5321 
5322     /* Function Body */
5323     *info = 0;
5324     minmn = min(*m,*n);
5325     wntqa = lsame_(jobz, "A");
5326     wntqs = lsame_(jobz, "S");
5327     wntqas = wntqa || wntqs;
5328     wntqo = lsame_(jobz, "O");
5329     wntqn = lsame_(jobz, "N");
5330     lquery = *lwork == -1;
5331 
5332     if (! (wntqa || wntqs || wntqo || wntqn)) {
5333 	*info = -1;
5334     } else if (*m < 0) {
5335 	*info = -2;
5336     } else if (*n < 0) {
5337 	*info = -3;
5338     } else if (*lda < max(1,*m)) {
5339 	*info = -5;
5340     } else if (*ldu < 1 || wntqas && *ldu < *m || wntqo && *m < *n && *ldu < *
5341 	    m) {
5342 	*info = -8;
5343     } else if (*ldvt < 1 || wntqa && *ldvt < *n || wntqs && *ldvt < minmn ||
5344 	    wntqo && *m >= *n && *ldvt < *n) {
5345 	*info = -10;
5346     }
5347 
5348 /*
5349        Compute workspace
5350         (Note: Comments in the code beginning "Workspace:" describe the
5351          minimal amount of workspace needed at that point in the code,
5352          as well as the preferred amount for good performance.
5353          NB refers to the optimal block size for the immediately
5354          following subroutine, as returned by ILAENV.)
5355 */
5356 
5357     if (*info == 0) {
5358 	minwrk = 1;
5359 	maxwrk = 1;
5360 	if (*m >= *n && minmn > 0) {
5361 
5362 /*           Compute space needed for DBDSDC */
5363 
5364 	    mnthr = (integer) (minmn * 11. / 6.);
5365 	    if (wntqn) {
5366 		bdspac = *n * 7;
5367 	    } else {
5368 		bdspac = *n * 3 * *n + (*n << 2);
5369 	    }
5370 	    if (*m >= mnthr) {
5371 		if (wntqn) {
5372 
5373 /*                 Path 1 (M much larger than N, JOBZ='N') */
5374 
5375 		    wrkbl = *n + *n * ilaenv_(&c__1, "DGEQRF", " ", m, n, &
5376 			    c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
5377 /* Computing MAX */
5378 		    i__1 = wrkbl, i__2 = *n * 3 + (*n << 1) * ilaenv_(&c__1,
5379 			    "DGEBRD", " ", n, n, &c_n1, &c_n1, (ftnlen)6, (
5380 			    ftnlen)1);
5381 		    wrkbl = max(i__1,i__2);
5382 /* Computing MAX */
5383 		    i__1 = wrkbl, i__2 = bdspac + *n;
5384 		    maxwrk = max(i__1,i__2);
5385 		    minwrk = bdspac + *n;
5386 		} else if (wntqo) {
5387 
5388 /*                 Path 2 (M much larger than N, JOBZ='O') */
5389 
5390 		    wrkbl = *n + *n * ilaenv_(&c__1, "DGEQRF", " ", m, n, &
5391 			    c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
5392 /* Computing MAX */
5393 		    i__1 = wrkbl, i__2 = *n + *n * ilaenv_(&c__1, "DORGQR",
5394 			    " ", m, n, n, &c_n1, (ftnlen)6, (ftnlen)1);
5395 		    wrkbl = max(i__1,i__2);
5396 /* Computing MAX */
5397 		    i__1 = wrkbl, i__2 = *n * 3 + (*n << 1) * ilaenv_(&c__1,
5398 			    "DGEBRD", " ", n, n, &c_n1, &c_n1, (ftnlen)6, (
5399 			    ftnlen)1);
5400 		    wrkbl = max(i__1,i__2);
5401 /* Computing MAX */
5402 		    i__1 = wrkbl, i__2 = *n * 3 + *n * ilaenv_(&c__1, "DORMBR"
5403 			    , "QLN", n, n, n, &c_n1, (ftnlen)6, (ftnlen)3);
5404 		    wrkbl = max(i__1,i__2);
5405 /* Computing MAX */
5406 		    i__1 = wrkbl, i__2 = *n * 3 + *n * ilaenv_(&c__1, "DORMBR"
5407 			    , "PRT", n, n, n, &c_n1, (ftnlen)6, (ftnlen)3);
5408 		    wrkbl = max(i__1,i__2);
5409 /* Computing MAX */
5410 		    i__1 = wrkbl, i__2 = bdspac + *n * 3;
5411 		    wrkbl = max(i__1,i__2);
5412 		    maxwrk = wrkbl + (*n << 1) * *n;
5413 		    minwrk = bdspac + (*n << 1) * *n + *n * 3;
5414 		} else if (wntqs) {
5415 
5416 /*                 Path 3 (M much larger than N, JOBZ='S') */
5417 
5418 		    wrkbl = *n + *n * ilaenv_(&c__1, "DGEQRF", " ", m, n, &
5419 			    c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
5420 /* Computing MAX */
5421 		    i__1 = wrkbl, i__2 = *n + *n * ilaenv_(&c__1, "DORGQR",
5422 			    " ", m, n, n, &c_n1, (ftnlen)6, (ftnlen)1);
5423 		    wrkbl = max(i__1,i__2);
5424 /* Computing MAX */
5425 		    i__1 = wrkbl, i__2 = *n * 3 + (*n << 1) * ilaenv_(&c__1,
5426 			    "DGEBRD", " ", n, n, &c_n1, &c_n1, (ftnlen)6, (
5427 			    ftnlen)1);
5428 		    wrkbl = max(i__1,i__2);
5429 /* Computing MAX */
5430 		    i__1 = wrkbl, i__2 = *n * 3 + *n * ilaenv_(&c__1, "DORMBR"
5431 			    , "QLN", n, n, n, &c_n1, (ftnlen)6, (ftnlen)3);
5432 		    wrkbl = max(i__1,i__2);
5433 /* Computing MAX */
5434 		    i__1 = wrkbl, i__2 = *n * 3 + *n * ilaenv_(&c__1, "DORMBR"
5435 			    , "PRT", n, n, n, &c_n1, (ftnlen)6, (ftnlen)3);
5436 		    wrkbl = max(i__1,i__2);
5437 /* Computing MAX */
5438 		    i__1 = wrkbl, i__2 = bdspac + *n * 3;
5439 		    wrkbl = max(i__1,i__2);
5440 		    maxwrk = wrkbl + *n * *n;
5441 		    minwrk = bdspac + *n * *n + *n * 3;
5442 		} else if (wntqa) {
5443 
5444 /*                 Path 4 (M much larger than N, JOBZ='A') */
5445 
5446 		    wrkbl = *n + *n * ilaenv_(&c__1, "DGEQRF", " ", m, n, &
5447 			    c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
5448 /* Computing MAX */
5449 		    i__1 = wrkbl, i__2 = *n + *m * ilaenv_(&c__1, "DORGQR",
5450 			    " ", m, m, n, &c_n1, (ftnlen)6, (ftnlen)1);
5451 		    wrkbl = max(i__1,i__2);
5452 /* Computing MAX */
5453 		    i__1 = wrkbl, i__2 = *n * 3 + (*n << 1) * ilaenv_(&c__1,
5454 			    "DGEBRD", " ", n, n, &c_n1, &c_n1, (ftnlen)6, (
5455 			    ftnlen)1);
5456 		    wrkbl = max(i__1,i__2);
5457 /* Computing MAX */
5458 		    i__1 = wrkbl, i__2 = *n * 3 + *n * ilaenv_(&c__1, "DORMBR"
5459 			    , "QLN", n, n, n, &c_n1, (ftnlen)6, (ftnlen)3);
5460 		    wrkbl = max(i__1,i__2);
5461 /* Computing MAX */
5462 		    i__1 = wrkbl, i__2 = *n * 3 + *n * ilaenv_(&c__1, "DORMBR"
5463 			    , "PRT", n, n, n, &c_n1, (ftnlen)6, (ftnlen)3);
5464 		    wrkbl = max(i__1,i__2);
5465 /* Computing MAX */
5466 		    i__1 = wrkbl, i__2 = bdspac + *n * 3;
5467 		    wrkbl = max(i__1,i__2);
5468 		    maxwrk = wrkbl + *n * *n;
5469 		    minwrk = bdspac + *n * *n + *n * 3;
5470 		}
5471 	    } else {
5472 
5473 /*              Path 5 (M at least N, but not much larger) */
5474 
5475 		wrkbl = *n * 3 + (*m + *n) * ilaenv_(&c__1, "DGEBRD", " ", m,
5476 			n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
5477 		if (wntqn) {
5478 /* Computing MAX */
5479 		    i__1 = wrkbl, i__2 = bdspac + *n * 3;
5480 		    maxwrk = max(i__1,i__2);
5481 		    minwrk = *n * 3 + max(*m,bdspac);
5482 		} else if (wntqo) {
5483 /* Computing MAX */
5484 		    i__1 = wrkbl, i__2 = *n * 3 + *n * ilaenv_(&c__1, "DORMBR"
5485 			    , "QLN", m, n, n, &c_n1, (ftnlen)6, (ftnlen)3);
5486 		    wrkbl = max(i__1,i__2);
5487 /* Computing MAX */
5488 		    i__1 = wrkbl, i__2 = *n * 3 + *n * ilaenv_(&c__1, "DORMBR"
5489 			    , "PRT", n, n, n, &c_n1, (ftnlen)6, (ftnlen)3);
5490 		    wrkbl = max(i__1,i__2);
5491 /* Computing MAX */
5492 		    i__1 = wrkbl, i__2 = bdspac + *n * 3;
5493 		    wrkbl = max(i__1,i__2);
5494 		    maxwrk = wrkbl + *m * *n;
5495 /* Computing MAX */
5496 		    i__1 = *m, i__2 = *n * *n + bdspac;
5497 		    minwrk = *n * 3 + max(i__1,i__2);
5498 		} else if (wntqs) {
5499 /* Computing MAX */
5500 		    i__1 = wrkbl, i__2 = *n * 3 + *n * ilaenv_(&c__1, "DORMBR"
5501 			    , "QLN", m, n, n, &c_n1, (ftnlen)6, (ftnlen)3);
5502 		    wrkbl = max(i__1,i__2);
5503 /* Computing MAX */
5504 		    i__1 = wrkbl, i__2 = *n * 3 + *n * ilaenv_(&c__1, "DORMBR"
5505 			    , "PRT", n, n, n, &c_n1, (ftnlen)6, (ftnlen)3);
5506 		    wrkbl = max(i__1,i__2);
5507 /* Computing MAX */
5508 		    i__1 = wrkbl, i__2 = bdspac + *n * 3;
5509 		    maxwrk = max(i__1,i__2);
5510 		    minwrk = *n * 3 + max(*m,bdspac);
5511 		} else if (wntqa) {
5512 /* Computing MAX */
5513 		    i__1 = wrkbl, i__2 = *n * 3 + *m * ilaenv_(&c__1, "DORMBR"
5514 			    , "QLN", m, m, n, &c_n1, (ftnlen)6, (ftnlen)3);
5515 		    wrkbl = max(i__1,i__2);
5516 /* Computing MAX */
5517 		    i__1 = wrkbl, i__2 = *n * 3 + *n * ilaenv_(&c__1, "DORMBR"
5518 			    , "PRT", n, n, n, &c_n1, (ftnlen)6, (ftnlen)3);
5519 		    wrkbl = max(i__1,i__2);
5520 /* Computing MAX */
5521 		    i__1 = maxwrk, i__2 = bdspac + *n * 3;
5522 		    maxwrk = max(i__1,i__2);
5523 		    minwrk = *n * 3 + max(*m,bdspac);
5524 		}
5525 	    }
5526 	} else if (minmn > 0) {
5527 
5528 /*           Compute space needed for DBDSDC */
5529 
5530 	    mnthr = (integer) (minmn * 11. / 6.);
5531 	    if (wntqn) {
5532 		bdspac = *m * 7;
5533 	    } else {
5534 		bdspac = *m * 3 * *m + (*m << 2);
5535 	    }
5536 	    if (*n >= mnthr) {
5537 		if (wntqn) {
5538 
5539 /*                 Path 1t (N much larger than M, JOBZ='N') */
5540 
5541 		    wrkbl = *m + *m * ilaenv_(&c__1, "DGELQF", " ", m, n, &
5542 			    c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
5543 /* Computing MAX */
5544 		    i__1 = wrkbl, i__2 = *m * 3 + (*m << 1) * ilaenv_(&c__1,
5545 			    "DGEBRD", " ", m, m, &c_n1, &c_n1, (ftnlen)6, (
5546 			    ftnlen)1);
5547 		    wrkbl = max(i__1,i__2);
5548 /* Computing MAX */
5549 		    i__1 = wrkbl, i__2 = bdspac + *m;
5550 		    maxwrk = max(i__1,i__2);
5551 		    minwrk = bdspac + *m;
5552 		} else if (wntqo) {
5553 
5554 /*                 Path 2t (N much larger than M, JOBZ='O') */
5555 
5556 		    wrkbl = *m + *m * ilaenv_(&c__1, "DGELQF", " ", m, n, &
5557 			    c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
5558 /* Computing MAX */
5559 		    i__1 = wrkbl, i__2 = *m + *m * ilaenv_(&c__1, "DORGLQ",
5560 			    " ", m, n, m, &c_n1, (ftnlen)6, (ftnlen)1);
5561 		    wrkbl = max(i__1,i__2);
5562 /* Computing MAX */
5563 		    i__1 = wrkbl, i__2 = *m * 3 + (*m << 1) * ilaenv_(&c__1,
5564 			    "DGEBRD", " ", m, m, &c_n1, &c_n1, (ftnlen)6, (
5565 			    ftnlen)1);
5566 		    wrkbl = max(i__1,i__2);
5567 /* Computing MAX */
5568 		    i__1 = wrkbl, i__2 = *m * 3 + *m * ilaenv_(&c__1, "DORMBR"
5569 			    , "QLN", m, m, m, &c_n1, (ftnlen)6, (ftnlen)3);
5570 		    wrkbl = max(i__1,i__2);
5571 /* Computing MAX */
5572 		    i__1 = wrkbl, i__2 = *m * 3 + *m * ilaenv_(&c__1, "DORMBR"
5573 			    , "PRT", m, m, m, &c_n1, (ftnlen)6, (ftnlen)3);
5574 		    wrkbl = max(i__1,i__2);
5575 /* Computing MAX */
5576 		    i__1 = wrkbl, i__2 = bdspac + *m * 3;
5577 		    wrkbl = max(i__1,i__2);
5578 		    maxwrk = wrkbl + (*m << 1) * *m;
5579 		    minwrk = bdspac + (*m << 1) * *m + *m * 3;
5580 		} else if (wntqs) {
5581 
5582 /*                 Path 3t (N much larger than M, JOBZ='S') */
5583 
5584 		    wrkbl = *m + *m * ilaenv_(&c__1, "DGELQF", " ", m, n, &
5585 			    c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
5586 /* Computing MAX */
5587 		    i__1 = wrkbl, i__2 = *m + *m * ilaenv_(&c__1, "DORGLQ",
5588 			    " ", m, n, m, &c_n1, (ftnlen)6, (ftnlen)1);
5589 		    wrkbl = max(i__1,i__2);
5590 /* Computing MAX */
5591 		    i__1 = wrkbl, i__2 = *m * 3 + (*m << 1) * ilaenv_(&c__1,
5592 			    "DGEBRD", " ", m, m, &c_n1, &c_n1, (ftnlen)6, (
5593 			    ftnlen)1);
5594 		    wrkbl = max(i__1,i__2);
5595 /* Computing MAX */
5596 		    i__1 = wrkbl, i__2 = *m * 3 + *m * ilaenv_(&c__1, "DORMBR"
5597 			    , "QLN", m, m, m, &c_n1, (ftnlen)6, (ftnlen)3);
5598 		    wrkbl = max(i__1,i__2);
5599 /* Computing MAX */
5600 		    i__1 = wrkbl, i__2 = *m * 3 + *m * ilaenv_(&c__1, "DORMBR"
5601 			    , "PRT", m, m, m, &c_n1, (ftnlen)6, (ftnlen)3);
5602 		    wrkbl = max(i__1,i__2);
5603 /* Computing MAX */
5604 		    i__1 = wrkbl, i__2 = bdspac + *m * 3;
5605 		    wrkbl = max(i__1,i__2);
5606 		    maxwrk = wrkbl + *m * *m;
5607 		    minwrk = bdspac + *m * *m + *m * 3;
5608 		} else if (wntqa) {
5609 
5610 /*                 Path 4t (N much larger than M, JOBZ='A') */
5611 
5612 		    wrkbl = *m + *m * ilaenv_(&c__1, "DGELQF", " ", m, n, &
5613 			    c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
5614 /* Computing MAX */
5615 		    i__1 = wrkbl, i__2 = *m + *n * ilaenv_(&c__1, "DORGLQ",
5616 			    " ", n, n, m, &c_n1, (ftnlen)6, (ftnlen)1);
5617 		    wrkbl = max(i__1,i__2);
5618 /* Computing MAX */
5619 		    i__1 = wrkbl, i__2 = *m * 3 + (*m << 1) * ilaenv_(&c__1,
5620 			    "DGEBRD", " ", m, m, &c_n1, &c_n1, (ftnlen)6, (
5621 			    ftnlen)1);
5622 		    wrkbl = max(i__1,i__2);
5623 /* Computing MAX */
5624 		    i__1 = wrkbl, i__2 = *m * 3 + *m * ilaenv_(&c__1, "DORMBR"
5625 			    , "QLN", m, m, m, &c_n1, (ftnlen)6, (ftnlen)3);
5626 		    wrkbl = max(i__1,i__2);
5627 /* Computing MAX */
5628 		    i__1 = wrkbl, i__2 = *m * 3 + *m * ilaenv_(&c__1, "DORMBR"
5629 			    , "PRT", m, m, m, &c_n1, (ftnlen)6, (ftnlen)3);
5630 		    wrkbl = max(i__1,i__2);
5631 /* Computing MAX */
5632 		    i__1 = wrkbl, i__2 = bdspac + *m * 3;
5633 		    wrkbl = max(i__1,i__2);
5634 		    maxwrk = wrkbl + *m * *m;
5635 		    minwrk = bdspac + *m * *m + *m * 3;
5636 		}
5637 	    } else {
5638 
5639 /*              Path 5t (N greater than M, but not much larger) */
5640 
5641 		wrkbl = *m * 3 + (*m + *n) * ilaenv_(&c__1, "DGEBRD", " ", m,
5642 			n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
5643 		if (wntqn) {
5644 /* Computing MAX */
5645 		    i__1 = wrkbl, i__2 = bdspac + *m * 3;
5646 		    maxwrk = max(i__1,i__2);
5647 		    minwrk = *m * 3 + max(*n,bdspac);
5648 		} else if (wntqo) {
5649 /* Computing MAX */
5650 		    i__1 = wrkbl, i__2 = *m * 3 + *m * ilaenv_(&c__1, "DORMBR"
5651 			    , "QLN", m, m, n, &c_n1, (ftnlen)6, (ftnlen)3);
5652 		    wrkbl = max(i__1,i__2);
5653 /* Computing MAX */
5654 		    i__1 = wrkbl, i__2 = *m * 3 + *m * ilaenv_(&c__1, "DORMBR"
5655 			    , "PRT", m, n, m, &c_n1, (ftnlen)6, (ftnlen)3);
5656 		    wrkbl = max(i__1,i__2);
5657 /* Computing MAX */
5658 		    i__1 = wrkbl, i__2 = bdspac + *m * 3;
5659 		    wrkbl = max(i__1,i__2);
5660 		    maxwrk = wrkbl + *m * *n;
5661 /* Computing MAX */
5662 		    i__1 = *n, i__2 = *m * *m + bdspac;
5663 		    minwrk = *m * 3 + max(i__1,i__2);
5664 		} else if (wntqs) {
5665 /* Computing MAX */
5666 		    i__1 = wrkbl, i__2 = *m * 3 + *m * ilaenv_(&c__1, "DORMBR"
5667 			    , "QLN", m, m, n, &c_n1, (ftnlen)6, (ftnlen)3);
5668 		    wrkbl = max(i__1,i__2);
5669 /* Computing MAX */
5670 		    i__1 = wrkbl, i__2 = *m * 3 + *m * ilaenv_(&c__1, "DORMBR"
5671 			    , "PRT", m, n, m, &c_n1, (ftnlen)6, (ftnlen)3);
5672 		    wrkbl = max(i__1,i__2);
5673 /* Computing MAX */
5674 		    i__1 = wrkbl, i__2 = bdspac + *m * 3;
5675 		    maxwrk = max(i__1,i__2);
5676 		    minwrk = *m * 3 + max(*n,bdspac);
5677 		} else if (wntqa) {
5678 /* Computing MAX */
5679 		    i__1 = wrkbl, i__2 = *m * 3 + *m * ilaenv_(&c__1, "DORMBR"
5680 			    , "QLN", m, m, n, &c_n1, (ftnlen)6, (ftnlen)3);
5681 		    wrkbl = max(i__1,i__2);
5682 /* Computing MAX */
5683 		    i__1 = wrkbl, i__2 = *m * 3 + *m * ilaenv_(&c__1, "DORMBR"
5684 			    , "PRT", n, n, m, &c_n1, (ftnlen)6, (ftnlen)3);
5685 		    wrkbl = max(i__1,i__2);
5686 /* Computing MAX */
5687 		    i__1 = wrkbl, i__2 = bdspac + *m * 3;
5688 		    maxwrk = max(i__1,i__2);
5689 		    minwrk = *m * 3 + max(*n,bdspac);
5690 		}
5691 	    }
5692 	}
5693 	maxwrk = max(maxwrk,minwrk);
5694 	work[1] = (doublereal) maxwrk;
5695 
5696 	if (*lwork < minwrk && ! lquery) {
5697 	    *info = -12;
5698 	}
5699     }
5700 
5701     if (*info != 0) {
5702 	i__1 = -(*info);
5703 	xerbla_("DGESDD", &i__1);
5704 	return 0;
5705     } else if (lquery) {
5706 	return 0;
5707     }
5708 
5709 /*     Quick return if possible */
5710 
5711     if (*m == 0 || *n == 0) {
5712 	return 0;
5713     }
5714 
5715 /*     Get machine constants */
5716 
5717     eps = PRECISION;
5718     smlnum = sqrt(SAFEMINIMUM) / eps;
5719     bignum = 1. / smlnum;
5720 
5721 /*     Scale A if max element outside range [SMLNUM,BIGNUM] */
5722 
5723     anrm = dlange_("M", m, n, &a[a_offset], lda, dum);
5724     iscl = 0;
5725     if (anrm > 0. && anrm < smlnum) {
5726 	iscl = 1;
5727 	dlascl_("G", &c__0, &c__0, &anrm, &smlnum, m, n, &a[a_offset], lda, &
5728 		ierr);
5729     } else if (anrm > bignum) {
5730 	iscl = 1;
5731 	dlascl_("G", &c__0, &c__0, &anrm, &bignum, m, n, &a[a_offset], lda, &
5732 		ierr);
5733     }
5734 
5735     if (*m >= *n) {
5736 
5737 /*
5738           A has at least as many rows as columns. If A has sufficiently
5739           more rows than columns, first reduce using the QR
5740           decomposition (if sufficient workspace available)
5741 */
5742 
5743 	if (*m >= mnthr) {
5744 
5745 	    if (wntqn) {
5746 
5747 /*
5748                 Path 1 (M much larger than N, JOBZ='N')
5749                 No singular vectors to be computed
5750 */
5751 
5752 		itau = 1;
5753 		nwork = itau + *n;
5754 
5755 /*
5756                 Compute A=Q*R
5757                 (Workspace: need 2*N, prefer N+N*NB)
5758 */
5759 
5760 		i__1 = *lwork - nwork + 1;
5761 		dgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
5762 			i__1, &ierr);
5763 
5764 /*              Zero out below R */
5765 
5766 		i__1 = *n - 1;
5767 		i__2 = *n - 1;
5768 		dlaset_("L", &i__1, &i__2, &c_b29, &c_b29, &a[a_dim1 + 2],
5769 			lda);
5770 		ie = 1;
5771 		itauq = ie + *n;
5772 		itaup = itauq + *n;
5773 		nwork = itaup + *n;
5774 
5775 /*
5776                 Bidiagonalize R in A
5777                 (Workspace: need 4*N, prefer 3*N+2*N*NB)
5778 */
5779 
5780 		i__1 = *lwork - nwork + 1;
5781 		dgebrd_(n, n, &a[a_offset], lda, &s[1], &work[ie], &work[
5782 			itauq], &work[itaup], &work[nwork], &i__1, &ierr);
5783 		nwork = ie + *n;
5784 
5785 /*
5786                 Perform bidiagonal SVD, computing singular values only
5787                 (Workspace: need N+BDSPAC)
5788 */
5789 
5790 		dbdsdc_("U", "N", n, &s[1], &work[ie], dum, &c__1, dum, &c__1,
5791 			 dum, idum, &work[nwork], &iwork[1], info);
5792 
5793 	    } else if (wntqo) {
5794 
5795 /*
5796                 Path 2 (M much larger than N, JOBZ = 'O')
5797                 N left singular vectors to be overwritten on A and
5798                 N right singular vectors to be computed in VT
5799 */
5800 
5801 		ir = 1;
5802 
5803 /*              WORK(IR) is LDWRKR by N */
5804 
5805 		if (*lwork >= *lda * *n + *n * *n + *n * 3 + bdspac) {
5806 		    ldwrkr = *lda;
5807 		} else {
5808 		    ldwrkr = (*lwork - *n * *n - *n * 3 - bdspac) / *n;
5809 		}
5810 		itau = ir + ldwrkr * *n;
5811 		nwork = itau + *n;
5812 
5813 /*
5814                 Compute A=Q*R
5815                 (Workspace: need N*N+2*N, prefer N*N+N+N*NB)
5816 */
5817 
5818 		i__1 = *lwork - nwork + 1;
5819 		dgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
5820 			i__1, &ierr);
5821 
5822 /*              Copy R to WORK(IR), zeroing out below it */
5823 
5824 		dlacpy_("U", n, n, &a[a_offset], lda, &work[ir], &ldwrkr);
5825 		i__1 = *n - 1;
5826 		i__2 = *n - 1;
5827 		dlaset_("L", &i__1, &i__2, &c_b29, &c_b29, &work[ir + 1], &
5828 			ldwrkr);
5829 
5830 /*
5831                 Generate Q in A
5832                 (Workspace: need N*N+2*N, prefer N*N+N+N*NB)
5833 */
5834 
5835 		i__1 = *lwork - nwork + 1;
5836 		dorgqr_(m, n, n, &a[a_offset], lda, &work[itau], &work[nwork],
5837 			 &i__1, &ierr);
5838 		ie = itau;
5839 		itauq = ie + *n;
5840 		itaup = itauq + *n;
5841 		nwork = itaup + *n;
5842 
5843 /*
5844                 Bidiagonalize R in VT, copying result to WORK(IR)
5845                 (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)
5846 */
5847 
5848 		i__1 = *lwork - nwork + 1;
5849 		dgebrd_(n, n, &work[ir], &ldwrkr, &s[1], &work[ie], &work[
5850 			itauq], &work[itaup], &work[nwork], &i__1, &ierr);
5851 
5852 /*              WORK(IU) is N by N */
5853 
5854 		iu = nwork;
5855 		nwork = iu + *n * *n;
5856 
5857 /*
5858                 Perform bidiagonal SVD, computing left singular vectors
5859                 of bidiagonal matrix in WORK(IU) and computing right
5860                 singular vectors of bidiagonal matrix in VT
5861                 (Workspace: need N+N*N+BDSPAC)
5862 */
5863 
5864 		dbdsdc_("U", "I", n, &s[1], &work[ie], &work[iu], n, &vt[
5865 			vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
5866 			info);
5867 
5868 /*
5869                 Overwrite WORK(IU) by left singular vectors of R
5870                 and VT by right singular vectors of R
5871                 (Workspace: need 2*N*N+3*N, prefer 2*N*N+2*N+N*NB)
5872 */
5873 
5874 		i__1 = *lwork - nwork + 1;
5875 		dormbr_("Q", "L", "N", n, n, n, &work[ir], &ldwrkr, &work[
5876 			itauq], &work[iu], n, &work[nwork], &i__1, &ierr);
5877 		i__1 = *lwork - nwork + 1;
5878 		dormbr_("P", "R", "T", n, n, n, &work[ir], &ldwrkr, &work[
5879 			itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
5880 			ierr);
5881 
5882 /*
5883                 Multiply Q in A by left singular vectors of R in
5884                 WORK(IU), storing result in WORK(IR) and copying to A
5885                 (Workspace: need 2*N*N, prefer N*N+M*N)
5886 */
5887 
5888 		i__1 = *m;
5889 		i__2 = ldwrkr;
5890 		for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ +=
5891 			i__2) {
5892 /* Computing MIN */
5893 		    i__3 = *m - i__ + 1;
5894 		    chunk = min(i__3,ldwrkr);
5895 		    dgemm_("N", "N", &chunk, n, n, &c_b15, &a[i__ + a_dim1],
5896 			    lda, &work[iu], n, &c_b29, &work[ir], &ldwrkr);
5897 		    dlacpy_("F", &chunk, n, &work[ir], &ldwrkr, &a[i__ +
5898 			    a_dim1], lda);
5899 /* L10: */
5900 		}
5901 
5902 	    } else if (wntqs) {
5903 
5904 /*
5905                 Path 3 (M much larger than N, JOBZ='S')
5906                 N left singular vectors to be computed in U and
5907                 N right singular vectors to be computed in VT
5908 */
5909 
5910 		ir = 1;
5911 
5912 /*              WORK(IR) is N by N */
5913 
5914 		ldwrkr = *n;
5915 		itau = ir + ldwrkr * *n;
5916 		nwork = itau + *n;
5917 
5918 /*
5919                 Compute A=Q*R
5920                 (Workspace: need N*N+2*N, prefer N*N+N+N*NB)
5921 */
5922 
5923 		i__2 = *lwork - nwork + 1;
5924 		dgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
5925 			i__2, &ierr);
5926 
5927 /*              Copy R to WORK(IR), zeroing out below it */
5928 
5929 		dlacpy_("U", n, n, &a[a_offset], lda, &work[ir], &ldwrkr);
5930 		i__2 = *n - 1;
5931 		i__1 = *n - 1;
5932 		dlaset_("L", &i__2, &i__1, &c_b29, &c_b29, &work[ir + 1], &
5933 			ldwrkr);
5934 
5935 /*
5936                 Generate Q in A
5937                 (Workspace: need N*N+2*N, prefer N*N+N+N*NB)
5938 */
5939 
5940 		i__2 = *lwork - nwork + 1;
5941 		dorgqr_(m, n, n, &a[a_offset], lda, &work[itau], &work[nwork],
5942 			 &i__2, &ierr);
5943 		ie = itau;
5944 		itauq = ie + *n;
5945 		itaup = itauq + *n;
5946 		nwork = itaup + *n;
5947 
5948 /*
5949                 Bidiagonalize R in WORK(IR)
5950                 (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)
5951 */
5952 
5953 		i__2 = *lwork - nwork + 1;
5954 		dgebrd_(n, n, &work[ir], &ldwrkr, &s[1], &work[ie], &work[
5955 			itauq], &work[itaup], &work[nwork], &i__2, &ierr);
5956 
5957 /*
5958                 Perform bidiagonal SVD, computing left singular vectors
5959                 of bidiagoal matrix in U and computing right singular
5960                 vectors of bidiagonal matrix in VT
5961                 (Workspace: need N+BDSPAC)
5962 */
5963 
5964 		dbdsdc_("U", "I", n, &s[1], &work[ie], &u[u_offset], ldu, &vt[
5965 			vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
5966 			info);
5967 
5968 /*
5969                 Overwrite U by left singular vectors of R and VT
5970                 by right singular vectors of R
5971                 (Workspace: need N*N+3*N, prefer N*N+2*N+N*NB)
5972 */
5973 
5974 		i__2 = *lwork - nwork + 1;
5975 		dormbr_("Q", "L", "N", n, n, n, &work[ir], &ldwrkr, &work[
5976 			itauq], &u[u_offset], ldu, &work[nwork], &i__2, &ierr);
5977 
5978 		i__2 = *lwork - nwork + 1;
5979 		dormbr_("P", "R", "T", n, n, n, &work[ir], &ldwrkr, &work[
5980 			itaup], &vt[vt_offset], ldvt, &work[nwork], &i__2, &
5981 			ierr);
5982 
5983 /*
5984                 Multiply Q in A by left singular vectors of R in
5985                 WORK(IR), storing result in U
5986                 (Workspace: need N*N)
5987 */
5988 
5989 		dlacpy_("F", n, n, &u[u_offset], ldu, &work[ir], &ldwrkr);
5990 		dgemm_("N", "N", m, n, n, &c_b15, &a[a_offset], lda, &work[ir]
5991 			, &ldwrkr, &c_b29, &u[u_offset], ldu);
5992 
5993 	    } else if (wntqa) {
5994 
5995 /*
5996                 Path 4 (M much larger than N, JOBZ='A')
5997                 M left singular vectors to be computed in U and
5998                 N right singular vectors to be computed in VT
5999 */
6000 
6001 		iu = 1;
6002 
6003 /*              WORK(IU) is N by N */
6004 
6005 		ldwrku = *n;
6006 		itau = iu + ldwrku * *n;
6007 		nwork = itau + *n;
6008 
6009 /*
6010                 Compute A=Q*R, copying result to U
6011                 (Workspace: need N*N+2*N, prefer N*N+N+N*NB)
6012 */
6013 
6014 		i__2 = *lwork - nwork + 1;
6015 		dgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
6016 			i__2, &ierr);
6017 		dlacpy_("L", m, n, &a[a_offset], lda, &u[u_offset], ldu);
6018 
6019 /*
6020                 Generate Q in U
6021                 (Workspace: need N*N+2*N, prefer N*N+N+N*NB)
6022 */
6023 		i__2 = *lwork - nwork + 1;
6024 		dorgqr_(m, m, n, &u[u_offset], ldu, &work[itau], &work[nwork],
6025 			 &i__2, &ierr);
6026 
6027 /*              Produce R in A, zeroing out other entries */
6028 
6029 		i__2 = *n - 1;
6030 		i__1 = *n - 1;
6031 		dlaset_("L", &i__2, &i__1, &c_b29, &c_b29, &a[a_dim1 + 2],
6032 			lda);
6033 		ie = itau;
6034 		itauq = ie + *n;
6035 		itaup = itauq + *n;
6036 		nwork = itaup + *n;
6037 
6038 /*
6039                 Bidiagonalize R in A
6040                 (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)
6041 */
6042 
6043 		i__2 = *lwork - nwork + 1;
6044 		dgebrd_(n, n, &a[a_offset], lda, &s[1], &work[ie], &work[
6045 			itauq], &work[itaup], &work[nwork], &i__2, &ierr);
6046 
6047 /*
6048                 Perform bidiagonal SVD, computing left singular vectors
6049                 of bidiagonal matrix in WORK(IU) and computing right
6050                 singular vectors of bidiagonal matrix in VT
6051                 (Workspace: need N+N*N+BDSPAC)
6052 */
6053 
6054 		dbdsdc_("U", "I", n, &s[1], &work[ie], &work[iu], n, &vt[
6055 			vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
6056 			info);
6057 
6058 /*
6059                 Overwrite WORK(IU) by left singular vectors of R and VT
6060                 by right singular vectors of R
6061                 (Workspace: need N*N+3*N, prefer N*N+2*N+N*NB)
6062 */
6063 
6064 		i__2 = *lwork - nwork + 1;
6065 		dormbr_("Q", "L", "N", n, n, n, &a[a_offset], lda, &work[
6066 			itauq], &work[iu], &ldwrku, &work[nwork], &i__2, &
6067 			ierr);
6068 		i__2 = *lwork - nwork + 1;
6069 		dormbr_("P", "R", "T", n, n, n, &a[a_offset], lda, &work[
6070 			itaup], &vt[vt_offset], ldvt, &work[nwork], &i__2, &
6071 			ierr);
6072 
6073 /*
6074                 Multiply Q in U by left singular vectors of R in
6075                 WORK(IU), storing result in A
6076                 (Workspace: need N*N)
6077 */
6078 
6079 		dgemm_("N", "N", m, n, n, &c_b15, &u[u_offset], ldu, &work[iu]
6080 			, &ldwrku, &c_b29, &a[a_offset], lda);
6081 
6082 /*              Copy left singular vectors of A from A to U */
6083 
6084 		dlacpy_("F", m, n, &a[a_offset], lda, &u[u_offset], ldu);
6085 
6086 	    }
6087 
6088 	} else {
6089 
6090 /*
6091              M .LT. MNTHR
6092 
6093              Path 5 (M at least N, but not much larger)
6094              Reduce to bidiagonal form without QR decomposition
6095 */
6096 
6097 	    ie = 1;
6098 	    itauq = ie + *n;
6099 	    itaup = itauq + *n;
6100 	    nwork = itaup + *n;
6101 
6102 /*
6103              Bidiagonalize A
6104              (Workspace: need 3*N+M, prefer 3*N+(M+N)*NB)
6105 */
6106 
6107 	    i__2 = *lwork - nwork + 1;
6108 	    dgebrd_(m, n, &a[a_offset], lda, &s[1], &work[ie], &work[itauq], &
6109 		    work[itaup], &work[nwork], &i__2, &ierr);
6110 	    if (wntqn) {
6111 
6112 /*
6113                 Perform bidiagonal SVD, only computing singular values
6114                 (Workspace: need N+BDSPAC)
6115 */
6116 
6117 		dbdsdc_("U", "N", n, &s[1], &work[ie], dum, &c__1, dum, &c__1,
6118 			 dum, idum, &work[nwork], &iwork[1], info);
6119 	    } else if (wntqo) {
6120 		iu = nwork;
6121 		if (*lwork >= *m * *n + *n * 3 + bdspac) {
6122 
6123 /*                 WORK( IU ) is M by N */
6124 
6125 		    ldwrku = *m;
6126 		    nwork = iu + ldwrku * *n;
6127 		    dlaset_("F", m, n, &c_b29, &c_b29, &work[iu], &ldwrku);
6128 		} else {
6129 
6130 /*                 WORK( IU ) is N by N */
6131 
6132 		    ldwrku = *n;
6133 		    nwork = iu + ldwrku * *n;
6134 
6135 /*                 WORK(IR) is LDWRKR by N */
6136 
6137 		    ir = nwork;
6138 		    ldwrkr = (*lwork - *n * *n - *n * 3) / *n;
6139 		}
6140 		nwork = iu + ldwrku * *n;
6141 
6142 /*
6143                 Perform bidiagonal SVD, computing left singular vectors
6144                 of bidiagonal matrix in WORK(IU) and computing right
6145                 singular vectors of bidiagonal matrix in VT
6146                 (Workspace: need N+N*N+BDSPAC)
6147 */
6148 
6149 		dbdsdc_("U", "I", n, &s[1], &work[ie], &work[iu], &ldwrku, &
6150 			vt[vt_offset], ldvt, dum, idum, &work[nwork], &iwork[
6151 			1], info);
6152 
6153 /*
6154                 Overwrite VT by right singular vectors of A
6155                 (Workspace: need N*N+2*N, prefer N*N+N+N*NB)
6156 */
6157 
6158 		i__2 = *lwork - nwork + 1;
6159 		dormbr_("P", "R", "T", n, n, n, &a[a_offset], lda, &work[
6160 			itaup], &vt[vt_offset], ldvt, &work[nwork], &i__2, &
6161 			ierr);
6162 
6163 		if (*lwork >= *m * *n + *n * 3 + bdspac) {
6164 
6165 /*
6166                    Overwrite WORK(IU) by left singular vectors of A
6167                    (Workspace: need N*N+2*N, prefer N*N+N+N*NB)
6168 */
6169 
6170 		    i__2 = *lwork - nwork + 1;
6171 		    dormbr_("Q", "L", "N", m, n, n, &a[a_offset], lda, &work[
6172 			    itauq], &work[iu], &ldwrku, &work[nwork], &i__2, &
6173 			    ierr);
6174 
6175 /*                 Copy left singular vectors of A from WORK(IU) to A */
6176 
6177 		    dlacpy_("F", m, n, &work[iu], &ldwrku, &a[a_offset], lda);
6178 		} else {
6179 
6180 /*
6181                    Generate Q in A
6182                    (Workspace: need N*N+2*N, prefer N*N+N+N*NB)
6183 */
6184 
6185 		    i__2 = *lwork - nwork + 1;
6186 		    dorgbr_("Q", m, n, n, &a[a_offset], lda, &work[itauq], &
6187 			    work[nwork], &i__2, &ierr);
6188 
6189 /*
6190                    Multiply Q in A by left singular vectors of
6191                    bidiagonal matrix in WORK(IU), storing result in
6192                    WORK(IR) and copying to A
6193                    (Workspace: need 2*N*N, prefer N*N+M*N)
6194 */
6195 
6196 		    i__2 = *m;
6197 		    i__1 = ldwrkr;
6198 		    for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ +=
6199 			     i__1) {
6200 /* Computing MIN */
6201 			i__3 = *m - i__ + 1;
6202 			chunk = min(i__3,ldwrkr);
6203 			dgemm_("N", "N", &chunk, n, n, &c_b15, &a[i__ +
6204 				a_dim1], lda, &work[iu], &ldwrku, &c_b29, &
6205 				work[ir], &ldwrkr);
6206 			dlacpy_("F", &chunk, n, &work[ir], &ldwrkr, &a[i__ +
6207 				a_dim1], lda);
6208 /* L20: */
6209 		    }
6210 		}
6211 
6212 	    } else if (wntqs) {
6213 
6214 /*
6215                 Perform bidiagonal SVD, computing left singular vectors
6216                 of bidiagonal matrix in U and computing right singular
6217                 vectors of bidiagonal matrix in VT
6218                 (Workspace: need N+BDSPAC)
6219 */
6220 
6221 		dlaset_("F", m, n, &c_b29, &c_b29, &u[u_offset], ldu);
6222 		dbdsdc_("U", "I", n, &s[1], &work[ie], &u[u_offset], ldu, &vt[
6223 			vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
6224 			info);
6225 
6226 /*
6227                 Overwrite U by left singular vectors of A and VT
6228                 by right singular vectors of A
6229                 (Workspace: need 3*N, prefer 2*N+N*NB)
6230 */
6231 
6232 		i__1 = *lwork - nwork + 1;
6233 		dormbr_("Q", "L", "N", m, n, n, &a[a_offset], lda, &work[
6234 			itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
6235 		i__1 = *lwork - nwork + 1;
6236 		dormbr_("P", "R", "T", n, n, n, &a[a_offset], lda, &work[
6237 			itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
6238 			ierr);
6239 	    } else if (wntqa) {
6240 
6241 /*
6242                 Perform bidiagonal SVD, computing left singular vectors
6243                 of bidiagonal matrix in U and computing right singular
6244                 vectors of bidiagonal matrix in VT
6245                 (Workspace: need N+BDSPAC)
6246 */
6247 
6248 		dlaset_("F", m, m, &c_b29, &c_b29, &u[u_offset], ldu);
6249 		dbdsdc_("U", "I", n, &s[1], &work[ie], &u[u_offset], ldu, &vt[
6250 			vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
6251 			info);
6252 
6253 /*              Set the right corner of U to identity matrix */
6254 
6255 		if (*m > *n) {
6256 		    i__1 = *m - *n;
6257 		    i__2 = *m - *n;
6258 		    dlaset_("F", &i__1, &i__2, &c_b29, &c_b15, &u[*n + 1 + (*
6259 			    n + 1) * u_dim1], ldu);
6260 		}
6261 
6262 /*
6263                 Overwrite U by left singular vectors of A and VT
6264                 by right singular vectors of A
6265                 (Workspace: need N*N+2*N+M, prefer N*N+2*N+M*NB)
6266 */
6267 
6268 		i__1 = *lwork - nwork + 1;
6269 		dormbr_("Q", "L", "N", m, m, n, &a[a_offset], lda, &work[
6270 			itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
6271 		i__1 = *lwork - nwork + 1;
6272 		dormbr_("P", "R", "T", n, n, m, &a[a_offset], lda, &work[
6273 			itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
6274 			ierr);
6275 	    }
6276 
6277 	}
6278 
6279     } else {
6280 
6281 /*
6282           A has more columns than rows. If A has sufficiently more
6283           columns than rows, first reduce using the LQ decomposition (if
6284           sufficient workspace available)
6285 */
6286 
6287 	if (*n >= mnthr) {
6288 
6289 	    if (wntqn) {
6290 
6291 /*
6292                 Path 1t (N much larger than M, JOBZ='N')
6293                 No singular vectors to be computed
6294 */
6295 
6296 		itau = 1;
6297 		nwork = itau + *m;
6298 
6299 /*
6300                 Compute A=L*Q
6301                 (Workspace: need 2*M, prefer M+M*NB)
6302 */
6303 
6304 		i__1 = *lwork - nwork + 1;
6305 		dgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
6306 			i__1, &ierr);
6307 
6308 /*              Zero out above L */
6309 
6310 		i__1 = *m - 1;
6311 		i__2 = *m - 1;
6312 		dlaset_("U", &i__1, &i__2, &c_b29, &c_b29, &a[(a_dim1 << 1) +
6313 			1], lda);
6314 		ie = 1;
6315 		itauq = ie + *m;
6316 		itaup = itauq + *m;
6317 		nwork = itaup + *m;
6318 
6319 /*
6320                 Bidiagonalize L in A
6321                 (Workspace: need 4*M, prefer 3*M+2*M*NB)
6322 */
6323 
6324 		i__1 = *lwork - nwork + 1;
6325 		dgebrd_(m, m, &a[a_offset], lda, &s[1], &work[ie], &work[
6326 			itauq], &work[itaup], &work[nwork], &i__1, &ierr);
6327 		nwork = ie + *m;
6328 
6329 /*
6330                 Perform bidiagonal SVD, computing singular values only
6331                 (Workspace: need M+BDSPAC)
6332 */
6333 
6334 		dbdsdc_("U", "N", m, &s[1], &work[ie], dum, &c__1, dum, &c__1,
6335 			 dum, idum, &work[nwork], &iwork[1], info);
6336 
6337 	    } else if (wntqo) {
6338 
6339 /*
6340                 Path 2t (N much larger than M, JOBZ='O')
6341                 M right singular vectors to be overwritten on A and
6342                 M left singular vectors to be computed in U
6343 */
6344 
6345 		ivt = 1;
6346 
6347 /*              IVT is M by M */
6348 
6349 		il = ivt + *m * *m;
6350 		if (*lwork >= *m * *n + *m * *m + *m * 3 + bdspac) {
6351 
6352 /*                 WORK(IL) is M by N */
6353 
6354 		    ldwrkl = *m;
6355 		    chunk = *n;
6356 		} else {
6357 		    ldwrkl = *m;
6358 		    chunk = (*lwork - *m * *m) / *m;
6359 		}
6360 		itau = il + ldwrkl * *m;
6361 		nwork = itau + *m;
6362 
6363 /*
6364                 Compute A=L*Q
6365                 (Workspace: need M*M+2*M, prefer M*M+M+M*NB)
6366 */
6367 
6368 		i__1 = *lwork - nwork + 1;
6369 		dgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
6370 			i__1, &ierr);
6371 
6372 /*              Copy L to WORK(IL), zeroing about above it */
6373 
6374 		dlacpy_("L", m, m, &a[a_offset], lda, &work[il], &ldwrkl);
6375 		i__1 = *m - 1;
6376 		i__2 = *m - 1;
6377 		dlaset_("U", &i__1, &i__2, &c_b29, &c_b29, &work[il + ldwrkl],
6378 			 &ldwrkl);
6379 
6380 /*
6381                 Generate Q in A
6382                 (Workspace: need M*M+2*M, prefer M*M+M+M*NB)
6383 */
6384 
6385 		i__1 = *lwork - nwork + 1;
6386 		dorglq_(m, n, m, &a[a_offset], lda, &work[itau], &work[nwork],
6387 			 &i__1, &ierr);
6388 		ie = itau;
6389 		itauq = ie + *m;
6390 		itaup = itauq + *m;
6391 		nwork = itaup + *m;
6392 
6393 /*
6394                 Bidiagonalize L in WORK(IL)
6395                 (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)
6396 */
6397 
6398 		i__1 = *lwork - nwork + 1;
6399 		dgebrd_(m, m, &work[il], &ldwrkl, &s[1], &work[ie], &work[
6400 			itauq], &work[itaup], &work[nwork], &i__1, &ierr);
6401 
6402 /*
6403                 Perform bidiagonal SVD, computing left singular vectors
6404                 of bidiagonal matrix in U, and computing right singular
6405                 vectors of bidiagonal matrix in WORK(IVT)
6406                 (Workspace: need M+M*M+BDSPAC)
6407 */
6408 
6409 		dbdsdc_("U", "I", m, &s[1], &work[ie], &u[u_offset], ldu, &
6410 			work[ivt], m, dum, idum, &work[nwork], &iwork[1],
6411 			info);
6412 
6413 /*
6414                 Overwrite U by left singular vectors of L and WORK(IVT)
6415                 by right singular vectors of L
6416                 (Workspace: need 2*M*M+3*M, prefer 2*M*M+2*M+M*NB)
6417 */
6418 
6419 		i__1 = *lwork - nwork + 1;
6420 		dormbr_("Q", "L", "N", m, m, m, &work[il], &ldwrkl, &work[
6421 			itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
6422 		i__1 = *lwork - nwork + 1;
6423 		dormbr_("P", "R", "T", m, m, m, &work[il], &ldwrkl, &work[
6424 			itaup], &work[ivt], m, &work[nwork], &i__1, &ierr);
6425 
6426 /*
6427                 Multiply right singular vectors of L in WORK(IVT) by Q
6428                 in A, storing result in WORK(IL) and copying to A
6429                 (Workspace: need 2*M*M, prefer M*M+M*N)
6430 */
6431 
6432 		i__1 = *n;
6433 		i__2 = chunk;
6434 		for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ +=
6435 			i__2) {
6436 /* Computing MIN */
6437 		    i__3 = *n - i__ + 1;
6438 		    blk = min(i__3,chunk);
6439 		    dgemm_("N", "N", m, &blk, m, &c_b15, &work[ivt], m, &a[
6440 			    i__ * a_dim1 + 1], lda, &c_b29, &work[il], &
6441 			    ldwrkl);
6442 		    dlacpy_("F", m, &blk, &work[il], &ldwrkl, &a[i__ * a_dim1
6443 			    + 1], lda);
6444 /* L30: */
6445 		}
6446 
6447 	    } else if (wntqs) {
6448 
6449 /*
6450                 Path 3t (N much larger than M, JOBZ='S')
6451                 M right singular vectors to be computed in VT and
6452                 M left singular vectors to be computed in U
6453 */
6454 
6455 		il = 1;
6456 
6457 /*              WORK(IL) is M by M */
6458 
6459 		ldwrkl = *m;
6460 		itau = il + ldwrkl * *m;
6461 		nwork = itau + *m;
6462 
6463 /*
6464                 Compute A=L*Q
6465                 (Workspace: need M*M+2*M, prefer M*M+M+M*NB)
6466 */
6467 
6468 		i__2 = *lwork - nwork + 1;
6469 		dgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
6470 			i__2, &ierr);
6471 
6472 /*              Copy L to WORK(IL), zeroing out above it */
6473 
6474 		dlacpy_("L", m, m, &a[a_offset], lda, &work[il], &ldwrkl);
6475 		i__2 = *m - 1;
6476 		i__1 = *m - 1;
6477 		dlaset_("U", &i__2, &i__1, &c_b29, &c_b29, &work[il + ldwrkl],
6478 			 &ldwrkl);
6479 
6480 /*
6481                 Generate Q in A
6482                 (Workspace: need M*M+2*M, prefer M*M+M+M*NB)
6483 */
6484 
6485 		i__2 = *lwork - nwork + 1;
6486 		dorglq_(m, n, m, &a[a_offset], lda, &work[itau], &work[nwork],
6487 			 &i__2, &ierr);
6488 		ie = itau;
6489 		itauq = ie + *m;
6490 		itaup = itauq + *m;
6491 		nwork = itaup + *m;
6492 
6493 /*
6494                 Bidiagonalize L in WORK(IU), copying result to U
6495                 (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)
6496 */
6497 
6498 		i__2 = *lwork - nwork + 1;
6499 		dgebrd_(m, m, &work[il], &ldwrkl, &s[1], &work[ie], &work[
6500 			itauq], &work[itaup], &work[nwork], &i__2, &ierr);
6501 
6502 /*
6503                 Perform bidiagonal SVD, computing left singular vectors
6504                 of bidiagonal matrix in U and computing right singular
6505                 vectors of bidiagonal matrix in VT
6506                 (Workspace: need M+BDSPAC)
6507 */
6508 
6509 		dbdsdc_("U", "I", m, &s[1], &work[ie], &u[u_offset], ldu, &vt[
6510 			vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
6511 			info);
6512 
6513 /*
6514                 Overwrite U by left singular vectors of L and VT
6515                 by right singular vectors of L
6516                 (Workspace: need M*M+3*M, prefer M*M+2*M+M*NB)
6517 */
6518 
6519 		i__2 = *lwork - nwork + 1;
6520 		dormbr_("Q", "L", "N", m, m, m, &work[il], &ldwrkl, &work[
6521 			itauq], &u[u_offset], ldu, &work[nwork], &i__2, &ierr);
6522 		i__2 = *lwork - nwork + 1;
6523 		dormbr_("P", "R", "T", m, m, m, &work[il], &ldwrkl, &work[
6524 			itaup], &vt[vt_offset], ldvt, &work[nwork], &i__2, &
6525 			ierr);
6526 
6527 /*
6528                 Multiply right singular vectors of L in WORK(IL) by
6529                 Q in A, storing result in VT
6530                 (Workspace: need M*M)
6531 */
6532 
6533 		dlacpy_("F", m, m, &vt[vt_offset], ldvt, &work[il], &ldwrkl);
6534 		dgemm_("N", "N", m, n, m, &c_b15, &work[il], &ldwrkl, &a[
6535 			a_offset], lda, &c_b29, &vt[vt_offset], ldvt);
6536 
6537 	    } else if (wntqa) {
6538 
6539 /*
6540                 Path 4t (N much larger than M, JOBZ='A')
6541                 N right singular vectors to be computed in VT and
6542                 M left singular vectors to be computed in U
6543 */
6544 
6545 		ivt = 1;
6546 
6547 /*              WORK(IVT) is M by M */
6548 
6549 		ldwkvt = *m;
6550 		itau = ivt + ldwkvt * *m;
6551 		nwork = itau + *m;
6552 
6553 /*
6554                 Compute A=L*Q, copying result to VT
6555                 (Workspace: need M*M+2*M, prefer M*M+M+M*NB)
6556 */
6557 
6558 		i__2 = *lwork - nwork + 1;
6559 		dgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
6560 			i__2, &ierr);
6561 		dlacpy_("U", m, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
6562 
6563 /*
6564                 Generate Q in VT
6565                 (Workspace: need M*M+2*M, prefer M*M+M+M*NB)
6566 */
6567 
6568 		i__2 = *lwork - nwork + 1;
6569 		dorglq_(n, n, m, &vt[vt_offset], ldvt, &work[itau], &work[
6570 			nwork], &i__2, &ierr);
6571 
6572 /*              Produce L in A, zeroing out other entries */
6573 
6574 		i__2 = *m - 1;
6575 		i__1 = *m - 1;
6576 		dlaset_("U", &i__2, &i__1, &c_b29, &c_b29, &a[(a_dim1 << 1) +
6577 			1], lda);
6578 		ie = itau;
6579 		itauq = ie + *m;
6580 		itaup = itauq + *m;
6581 		nwork = itaup + *m;
6582 
6583 /*
6584                 Bidiagonalize L in A
6585                 (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)
6586 */
6587 
6588 		i__2 = *lwork - nwork + 1;
6589 		dgebrd_(m, m, &a[a_offset], lda, &s[1], &work[ie], &work[
6590 			itauq], &work[itaup], &work[nwork], &i__2, &ierr);
6591 
6592 /*
6593                 Perform bidiagonal SVD, computing left singular vectors
6594                 of bidiagonal matrix in U and computing right singular
6595                 vectors of bidiagonal matrix in WORK(IVT)
6596                 (Workspace: need M+M*M+BDSPAC)
6597 */
6598 
6599 		dbdsdc_("U", "I", m, &s[1], &work[ie], &u[u_offset], ldu, &
6600 			work[ivt], &ldwkvt, dum, idum, &work[nwork], &iwork[1]
6601 			, info);
6602 
6603 /*
6604                 Overwrite U by left singular vectors of L and WORK(IVT)
6605                 by right singular vectors of L
6606                 (Workspace: need M*M+3*M, prefer M*M+2*M+M*NB)
6607 */
6608 
6609 		i__2 = *lwork - nwork + 1;
6610 		dormbr_("Q", "L", "N", m, m, m, &a[a_offset], lda, &work[
6611 			itauq], &u[u_offset], ldu, &work[nwork], &i__2, &ierr);
6612 		i__2 = *lwork - nwork + 1;
6613 		dormbr_("P", "R", "T", m, m, m, &a[a_offset], lda, &work[
6614 			itaup], &work[ivt], &ldwkvt, &work[nwork], &i__2, &
6615 			ierr);
6616 
6617 /*
6618                 Multiply right singular vectors of L in WORK(IVT) by
6619                 Q in VT, storing result in A
6620                 (Workspace: need M*M)
6621 */
6622 
6623 		dgemm_("N", "N", m, n, m, &c_b15, &work[ivt], &ldwkvt, &vt[
6624 			vt_offset], ldvt, &c_b29, &a[a_offset], lda);
6625 
6626 /*              Copy right singular vectors of A from A to VT */
6627 
6628 		dlacpy_("F", m, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
6629 
6630 	    }
6631 
6632 	} else {
6633 
6634 /*
6635              N .LT. MNTHR
6636 
6637              Path 5t (N greater than M, but not much larger)
6638              Reduce to bidiagonal form without LQ decomposition
6639 */
6640 
6641 	    ie = 1;
6642 	    itauq = ie + *m;
6643 	    itaup = itauq + *m;
6644 	    nwork = itaup + *m;
6645 
6646 /*
6647              Bidiagonalize A
6648              (Workspace: need 3*M+N, prefer 3*M+(M+N)*NB)
6649 */
6650 
6651 	    i__2 = *lwork - nwork + 1;
6652 	    dgebrd_(m, n, &a[a_offset], lda, &s[1], &work[ie], &work[itauq], &
6653 		    work[itaup], &work[nwork], &i__2, &ierr);
6654 	    if (wntqn) {
6655 
6656 /*
6657                 Perform bidiagonal SVD, only computing singular values
6658                 (Workspace: need M+BDSPAC)
6659 */
6660 
6661 		dbdsdc_("L", "N", m, &s[1], &work[ie], dum, &c__1, dum, &c__1,
6662 			 dum, idum, &work[nwork], &iwork[1], info);
6663 	    } else if (wntqo) {
6664 		ldwkvt = *m;
6665 		ivt = nwork;
6666 		if (*lwork >= *m * *n + *m * 3 + bdspac) {
6667 
6668 /*                 WORK( IVT ) is M by N */
6669 
6670 		    dlaset_("F", m, n, &c_b29, &c_b29, &work[ivt], &ldwkvt);
6671 		    nwork = ivt + ldwkvt * *n;
6672 		} else {
6673 
6674 /*                 WORK( IVT ) is M by M */
6675 
6676 		    nwork = ivt + ldwkvt * *m;
6677 		    il = nwork;
6678 
6679 /*                 WORK(IL) is M by CHUNK */
6680 
6681 		    chunk = (*lwork - *m * *m - *m * 3) / *m;
6682 		}
6683 
6684 /*
6685                 Perform bidiagonal SVD, computing left singular vectors
6686                 of bidiagonal matrix in U and computing right singular
6687                 vectors of bidiagonal matrix in WORK(IVT)
6688                 (Workspace: need M*M+BDSPAC)
6689 */
6690 
6691 		dbdsdc_("L", "I", m, &s[1], &work[ie], &u[u_offset], ldu, &
6692 			work[ivt], &ldwkvt, dum, idum, &work[nwork], &iwork[1]
6693 			, info);
6694 
6695 /*
6696                 Overwrite U by left singular vectors of A
6697                 (Workspace: need M*M+2*M, prefer M*M+M+M*NB)
6698 */
6699 
6700 		i__2 = *lwork - nwork + 1;
6701 		dormbr_("Q", "L", "N", m, m, n, &a[a_offset], lda, &work[
6702 			itauq], &u[u_offset], ldu, &work[nwork], &i__2, &ierr);
6703 
6704 		if (*lwork >= *m * *n + *m * 3 + bdspac) {
6705 
6706 /*
6707                    Overwrite WORK(IVT) by left singular vectors of A
6708                    (Workspace: need M*M+2*M, prefer M*M+M+M*NB)
6709 */
6710 
6711 		    i__2 = *lwork - nwork + 1;
6712 		    dormbr_("P", "R", "T", m, n, m, &a[a_offset], lda, &work[
6713 			    itaup], &work[ivt], &ldwkvt, &work[nwork], &i__2,
6714 			    &ierr);
6715 
6716 /*                 Copy right singular vectors of A from WORK(IVT) to A */
6717 
6718 		    dlacpy_("F", m, n, &work[ivt], &ldwkvt, &a[a_offset], lda);
6719 		} else {
6720 
6721 /*
6722                    Generate P**T in A
6723                    (Workspace: need M*M+2*M, prefer M*M+M+M*NB)
6724 */
6725 
6726 		    i__2 = *lwork - nwork + 1;
6727 		    dorgbr_("P", m, n, m, &a[a_offset], lda, &work[itaup], &
6728 			    work[nwork], &i__2, &ierr);
6729 
6730 /*
6731                    Multiply Q in A by right singular vectors of
6732                    bidiagonal matrix in WORK(IVT), storing result in
6733                    WORK(IL) and copying to A
6734                    (Workspace: need 2*M*M, prefer M*M+M*N)
6735 */
6736 
6737 		    i__2 = *n;
6738 		    i__1 = chunk;
6739 		    for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ +=
6740 			     i__1) {
6741 /* Computing MIN */
6742 			i__3 = *n - i__ + 1;
6743 			blk = min(i__3,chunk);
6744 			dgemm_("N", "N", m, &blk, m, &c_b15, &work[ivt], &
6745 				ldwkvt, &a[i__ * a_dim1 + 1], lda, &c_b29, &
6746 				work[il], m);
6747 			dlacpy_("F", m, &blk, &work[il], m, &a[i__ * a_dim1 +
6748 				1], lda);
6749 /* L40: */
6750 		    }
6751 		}
6752 	    } else if (wntqs) {
6753 
6754 /*
6755                 Perform bidiagonal SVD, computing left singular vectors
6756                 of bidiagonal matrix in U and computing right singular
6757                 vectors of bidiagonal matrix in VT
6758                 (Workspace: need M+BDSPAC)
6759 */
6760 
6761 		dlaset_("F", m, n, &c_b29, &c_b29, &vt[vt_offset], ldvt);
6762 		dbdsdc_("L", "I", m, &s[1], &work[ie], &u[u_offset], ldu, &vt[
6763 			vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
6764 			info);
6765 
6766 /*
6767                 Overwrite U by left singular vectors of A and VT
6768                 by right singular vectors of A
6769                 (Workspace: need 3*M, prefer 2*M+M*NB)
6770 */
6771 
6772 		i__1 = *lwork - nwork + 1;
6773 		dormbr_("Q", "L", "N", m, m, n, &a[a_offset], lda, &work[
6774 			itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
6775 		i__1 = *lwork - nwork + 1;
6776 		dormbr_("P", "R", "T", m, n, m, &a[a_offset], lda, &work[
6777 			itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
6778 			ierr);
6779 	    } else if (wntqa) {
6780 
6781 /*
6782                 Perform bidiagonal SVD, computing left singular vectors
6783                 of bidiagonal matrix in U and computing right singular
6784                 vectors of bidiagonal matrix in VT
6785                 (Workspace: need M+BDSPAC)
6786 */
6787 
6788 		dlaset_("F", n, n, &c_b29, &c_b29, &vt[vt_offset], ldvt);
6789 		dbdsdc_("L", "I", m, &s[1], &work[ie], &u[u_offset], ldu, &vt[
6790 			vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
6791 			info);
6792 
6793 /*              Set the right corner of VT to identity matrix */
6794 
6795 		if (*n > *m) {
6796 		    i__1 = *n - *m;
6797 		    i__2 = *n - *m;
6798 		    dlaset_("F", &i__1, &i__2, &c_b29, &c_b15, &vt[*m + 1 + (*
6799 			    m + 1) * vt_dim1], ldvt);
6800 		}
6801 
6802 /*
6803                 Overwrite U by left singular vectors of A and VT
6804                 by right singular vectors of A
6805                 (Workspace: need 2*M+N, prefer 2*M+N*NB)
6806 */
6807 
6808 		i__1 = *lwork - nwork + 1;
6809 		dormbr_("Q", "L", "N", m, m, n, &a[a_offset], lda, &work[
6810 			itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
6811 		i__1 = *lwork - nwork + 1;
6812 		dormbr_("P", "R", "T", n, n, m, &a[a_offset], lda, &work[
6813 			itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
6814 			ierr);
6815 	    }
6816 
6817 	}
6818 
6819     }
6820 
6821 /*     Undo scaling if necessary */
6822 
6823     if (iscl == 1) {
6824 	if (anrm > bignum) {
6825 	    dlascl_("G", &c__0, &c__0, &bignum, &anrm, &minmn, &c__1, &s[1], &
6826 		    minmn, &ierr);
6827 	}
6828 	if (anrm < smlnum) {
6829 	    dlascl_("G", &c__0, &c__0, &smlnum, &anrm, &minmn, &c__1, &s[1], &
6830 		    minmn, &ierr);
6831 	}
6832     }
6833 
6834 /*     Return optimal workspace in WORK(1) */
6835 
6836     work[1] = (doublereal) maxwrk;
6837 
6838     return 0;
6839 
6840 /*     End of DGESDD */
6841 
6842 } /* dgesdd_ */
6843 
dgesv_(integer * n,integer * nrhs,doublereal * a,integer * lda,integer * ipiv,doublereal * b,integer * ldb,integer * info)6844 /* Subroutine */ int dgesv_(integer *n, integer *nrhs, doublereal *a, integer
6845 	*lda, integer *ipiv, doublereal *b, integer *ldb, integer *info)
6846 {
6847     /* System generated locals */
6848     integer a_dim1, a_offset, b_dim1, b_offset, i__1;
6849 
6850     /* Local variables */
6851     extern /* Subroutine */ int dgetrf_(integer *, integer *, doublereal *,
6852 	    integer *, integer *, integer *), xerbla_(char *, integer *), dgetrs_(char *, integer *, integer *, doublereal *,
6853 	    integer *, integer *, doublereal *, integer *, integer *);
6854 
6855 
6856 /*
6857     -- LAPACK driver routine (version 3.2) --
6858     -- LAPACK is a software package provided by Univ. of Tennessee,    --
6859     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
6860        November 2006
6861 
6862 
6863     Purpose
6864     =======
6865 
6866     DGESV computes the solution to a real system of linear equations
6867        A * X = B,
6868     where A is an N-by-N matrix and X and B are N-by-NRHS matrices.
6869 
6870     The LU decomposition with partial pivoting and row interchanges is
6871     used to factor A as
6872        A = P * L * U,
6873     where P is a permutation matrix, L is unit lower triangular, and U is
6874     upper triangular.  The factored form of A is then used to solve the
6875     system of equations A * X = B.
6876 
6877     Arguments
6878     =========
6879 
6880     N       (input) INTEGER
6881             The number of linear equations, i.e., the order of the
6882             matrix A.  N >= 0.
6883 
6884     NRHS    (input) INTEGER
6885             The number of right hand sides, i.e., the number of columns
6886             of the matrix B.  NRHS >= 0.
6887 
6888     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
6889             On entry, the N-by-N coefficient matrix A.
6890             On exit, the factors L and U from the factorization
6891             A = P*L*U; the unit diagonal elements of L are not stored.
6892 
6893     LDA     (input) INTEGER
6894             The leading dimension of the array A.  LDA >= max(1,N).
6895 
6896     IPIV    (output) INTEGER array, dimension (N)
6897             The pivot indices that define the permutation matrix P;
6898             row i of the matrix was interchanged with row IPIV(i).
6899 
6900     B       (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
6901             On entry, the N-by-NRHS matrix of right hand side matrix B.
6902             On exit, if INFO = 0, the N-by-NRHS solution matrix X.
6903 
6904     LDB     (input) INTEGER
6905             The leading dimension of the array B.  LDB >= max(1,N).
6906 
6907     INFO    (output) INTEGER
6908             = 0:  successful exit
6909             < 0:  if INFO = -i, the i-th argument had an illegal value
6910             > 0:  if INFO = i, U(i,i) is exactly zero.  The factorization
6911                   has been completed, but the factor U is exactly
6912                   singular, so the solution could not be computed.
6913 
6914     =====================================================================
6915 
6916 
6917        Test the input parameters.
6918 */
6919 
6920     /* Parameter adjustments */
6921     a_dim1 = *lda;
6922     a_offset = 1 + a_dim1;
6923     a -= a_offset;
6924     --ipiv;
6925     b_dim1 = *ldb;
6926     b_offset = 1 + b_dim1;
6927     b -= b_offset;
6928 
6929     /* Function Body */
6930     *info = 0;
6931     if (*n < 0) {
6932 	*info = -1;
6933     } else if (*nrhs < 0) {
6934 	*info = -2;
6935     } else if (*lda < max(1,*n)) {
6936 	*info = -4;
6937     } else if (*ldb < max(1,*n)) {
6938 	*info = -7;
6939     }
6940     if (*info != 0) {
6941 	i__1 = -(*info);
6942 	xerbla_("DGESV ", &i__1);
6943 	return 0;
6944     }
6945 
6946 /*     Compute the LU factorization of A. */
6947 
6948     dgetrf_(n, n, &a[a_offset], lda, &ipiv[1], info);
6949     if (*info == 0) {
6950 
6951 /*        Solve the system A*X = B, overwriting B with X. */
6952 
6953 	dgetrs_("No transpose", n, nrhs, &a[a_offset], lda, &ipiv[1], &b[
6954 		b_offset], ldb, info);
6955     }
6956     return 0;
6957 
6958 /*     End of DGESV */
6959 
6960 } /* dgesv_ */
6961 
dgetf2_(integer * m,integer * n,doublereal * a,integer * lda,integer * ipiv,integer * info)6962 /* Subroutine */ int dgetf2_(integer *m, integer *n, doublereal *a, integer *
6963 	lda, integer *ipiv, integer *info)
6964 {
6965     /* System generated locals */
6966     integer a_dim1, a_offset, i__1, i__2, i__3;
6967     doublereal d__1;
6968 
6969     /* Local variables */
6970     static integer i__, j, jp;
6971     extern /* Subroutine */ int dger_(integer *, integer *, doublereal *,
6972 	    doublereal *, integer *, doublereal *, integer *, doublereal *,
6973 	    integer *), dscal_(integer *, doublereal *, doublereal *, integer
6974 	    *);
6975     static doublereal sfmin;
6976     extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *,
6977 	    doublereal *, integer *);
6978 
6979     extern integer idamax_(integer *, doublereal *, integer *);
6980     extern /* Subroutine */ int xerbla_(char *, integer *);
6981 
6982 
6983 /*
6984     -- LAPACK routine (version 3.2) --
6985     -- LAPACK is a software package provided by Univ. of Tennessee,    --
6986     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
6987        November 2006
6988 
6989 
6990     Purpose
6991     =======
6992 
6993     DGETF2 computes an LU factorization of a general m-by-n matrix A
6994     using partial pivoting with row interchanges.
6995 
6996     The factorization has the form
6997        A = P * L * U
6998     where P is a permutation matrix, L is lower triangular with unit
6999     diagonal elements (lower trapezoidal if m > n), and U is upper
7000     triangular (upper trapezoidal if m < n).
7001 
7002     This is the right-looking Level 2 BLAS version of the algorithm.
7003 
7004     Arguments
7005     =========
7006 
7007     M       (input) INTEGER
7008             The number of rows of the matrix A.  M >= 0.
7009 
7010     N       (input) INTEGER
7011             The number of columns of the matrix A.  N >= 0.
7012 
7013     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
7014             On entry, the m by n matrix to be factored.
7015             On exit, the factors L and U from the factorization
7016             A = P*L*U; the unit diagonal elements of L are not stored.
7017 
7018     LDA     (input) INTEGER
7019             The leading dimension of the array A.  LDA >= max(1,M).
7020 
7021     IPIV    (output) INTEGER array, dimension (min(M,N))
7022             The pivot indices; for 1 <= i <= min(M,N), row i of the
7023             matrix was interchanged with row IPIV(i).
7024 
7025     INFO    (output) INTEGER
7026             = 0: successful exit
7027             < 0: if INFO = -k, the k-th argument had an illegal value
7028             > 0: if INFO = k, U(k,k) is exactly zero. The factorization
7029                  has been completed, but the factor U is exactly
7030                  singular, and division by zero will occur if it is used
7031                  to solve a system of equations.
7032 
7033     =====================================================================
7034 
7035 
7036        Test the input parameters.
7037 */
7038 
7039     /* Parameter adjustments */
7040     a_dim1 = *lda;
7041     a_offset = 1 + a_dim1;
7042     a -= a_offset;
7043     --ipiv;
7044 
7045     /* Function Body */
7046     *info = 0;
7047     if (*m < 0) {
7048 	*info = -1;
7049     } else if (*n < 0) {
7050 	*info = -2;
7051     } else if (*lda < max(1,*m)) {
7052 	*info = -4;
7053     }
7054     if (*info != 0) {
7055 	i__1 = -(*info);
7056 	xerbla_("DGETF2", &i__1);
7057 	return 0;
7058     }
7059 
7060 /*     Quick return if possible */
7061 
7062     if (*m == 0 || *n == 0) {
7063 	return 0;
7064     }
7065 
7066 /*     Compute machine safe minimum */
7067 
7068     sfmin = SAFEMINIMUM;
7069 
7070     i__1 = min(*m,*n);
7071     for (j = 1; j <= i__1; ++j) {
7072 
7073 /*        Find pivot and test for singularity. */
7074 
7075 	i__2 = *m - j + 1;
7076 	jp = j - 1 + idamax_(&i__2, &a[j + j * a_dim1], &c__1);
7077 	ipiv[j] = jp;
7078 	if (a[jp + j * a_dim1] != 0.) {
7079 
7080 /*           Apply the interchange to columns 1:N. */
7081 
7082 	    if (jp != j) {
7083 		dswap_(n, &a[j + a_dim1], lda, &a[jp + a_dim1], lda);
7084 	    }
7085 
7086 /*           Compute elements J+1:M of J-th column. */
7087 
7088 	    if (j < *m) {
7089 		if ((d__1 = a[j + j * a_dim1], abs(d__1)) >= sfmin) {
7090 		    i__2 = *m - j;
7091 		    d__1 = 1. / a[j + j * a_dim1];
7092 		    dscal_(&i__2, &d__1, &a[j + 1 + j * a_dim1], &c__1);
7093 		} else {
7094 		    i__2 = *m - j;
7095 		    for (i__ = 1; i__ <= i__2; ++i__) {
7096 			a[j + i__ + j * a_dim1] /= a[j + j * a_dim1];
7097 /* L20: */
7098 		    }
7099 		}
7100 	    }
7101 
7102 	} else if (*info == 0) {
7103 
7104 	    *info = j;
7105 	}
7106 
7107 	if (j < min(*m,*n)) {
7108 
7109 /*           Update trailing submatrix. */
7110 
7111 	    i__2 = *m - j;
7112 	    i__3 = *n - j;
7113 	    dger_(&i__2, &i__3, &c_b151, &a[j + 1 + j * a_dim1], &c__1, &a[j
7114 		    + (j + 1) * a_dim1], lda, &a[j + 1 + (j + 1) * a_dim1],
7115 		    lda);
7116 	}
7117 /* L10: */
7118     }
7119     return 0;
7120 
7121 /*     End of DGETF2 */
7122 
7123 } /* dgetf2_ */
7124 
dgetrf_(integer * m,integer * n,doublereal * a,integer * lda,integer * ipiv,integer * info)7125 /* Subroutine */ int dgetrf_(integer *m, integer *n, doublereal *a, integer *
7126 	lda, integer *ipiv, integer *info)
7127 {
7128     /* System generated locals */
7129     integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
7130 
7131     /* Local variables */
7132     static integer i__, j, jb, nb;
7133     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
7134 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
7135 	    integer *, doublereal *, doublereal *, integer *);
7136     static integer iinfo;
7137     extern /* Subroutine */ int dtrsm_(char *, char *, char *, char *,
7138 	    integer *, integer *, doublereal *, doublereal *, integer *,
7139 	    doublereal *, integer *), dgetf2_(
7140 	    integer *, integer *, doublereal *, integer *, integer *, integer
7141 	    *), xerbla_(char *, integer *);
7142     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
7143 	    integer *, integer *, ftnlen, ftnlen);
7144     extern /* Subroutine */ int dlaswp_(integer *, doublereal *, integer *,
7145 	    integer *, integer *, integer *, integer *);
7146 
7147 
7148 /*
7149     -- LAPACK routine (version 3.2) --
7150     -- LAPACK is a software package provided by Univ. of Tennessee,    --
7151     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
7152        November 2006
7153 
7154 
7155     Purpose
7156     =======
7157 
7158     DGETRF computes an LU factorization of a general M-by-N matrix A
7159     using partial pivoting with row interchanges.
7160 
7161     The factorization has the form
7162        A = P * L * U
7163     where P is a permutation matrix, L is lower triangular with unit
7164     diagonal elements (lower trapezoidal if m > n), and U is upper
7165     triangular (upper trapezoidal if m < n).
7166 
7167     This is the right-looking Level 3 BLAS version of the algorithm.
7168 
7169     Arguments
7170     =========
7171 
7172     M       (input) INTEGER
7173             The number of rows of the matrix A.  M >= 0.
7174 
7175     N       (input) INTEGER
7176             The number of columns of the matrix A.  N >= 0.
7177 
7178     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
7179             On entry, the M-by-N matrix to be factored.
7180             On exit, the factors L and U from the factorization
7181             A = P*L*U; the unit diagonal elements of L are not stored.
7182 
7183     LDA     (input) INTEGER
7184             The leading dimension of the array A.  LDA >= max(1,M).
7185 
7186     IPIV    (output) INTEGER array, dimension (min(M,N))
7187             The pivot indices; for 1 <= i <= min(M,N), row i of the
7188             matrix was interchanged with row IPIV(i).
7189 
7190     INFO    (output) INTEGER
7191             = 0:  successful exit
7192             < 0:  if INFO = -i, the i-th argument had an illegal value
7193             > 0:  if INFO = i, U(i,i) is exactly zero. The factorization
7194                   has been completed, but the factor U is exactly
7195                   singular, and division by zero will occur if it is used
7196                   to solve a system of equations.
7197 
7198     =====================================================================
7199 
7200 
7201        Test the input parameters.
7202 */
7203 
7204     /* Parameter adjustments */
7205     a_dim1 = *lda;
7206     a_offset = 1 + a_dim1;
7207     a -= a_offset;
7208     --ipiv;
7209 
7210     /* Function Body */
7211     *info = 0;
7212     if (*m < 0) {
7213 	*info = -1;
7214     } else if (*n < 0) {
7215 	*info = -2;
7216     } else if (*lda < max(1,*m)) {
7217 	*info = -4;
7218     }
7219     if (*info != 0) {
7220 	i__1 = -(*info);
7221 	xerbla_("DGETRF", &i__1);
7222 	return 0;
7223     }
7224 
7225 /*     Quick return if possible */
7226 
7227     if (*m == 0 || *n == 0) {
7228 	return 0;
7229     }
7230 
7231 /*     Determine the block size for this environment. */
7232 
7233     nb = ilaenv_(&c__1, "DGETRF", " ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)
7234 	    1);
7235     if (nb <= 1 || nb >= min(*m,*n)) {
7236 
7237 /*        Use unblocked code. */
7238 
7239 	dgetf2_(m, n, &a[a_offset], lda, &ipiv[1], info);
7240     } else {
7241 
7242 /*        Use blocked code. */
7243 
7244 	i__1 = min(*m,*n);
7245 	i__2 = nb;
7246 	for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
7247 /* Computing MIN */
7248 	    i__3 = min(*m,*n) - j + 1;
7249 	    jb = min(i__3,nb);
7250 
7251 /*
7252              Factor diagonal and subdiagonal blocks and test for exact
7253              singularity.
7254 */
7255 
7256 	    i__3 = *m - j + 1;
7257 	    dgetf2_(&i__3, &jb, &a[j + j * a_dim1], lda, &ipiv[j], &iinfo);
7258 
7259 /*           Adjust INFO and the pivot indices. */
7260 
7261 	    if (*info == 0 && iinfo > 0) {
7262 		*info = iinfo + j - 1;
7263 	    }
7264 /* Computing MIN */
7265 	    i__4 = *m, i__5 = j + jb - 1;
7266 	    i__3 = min(i__4,i__5);
7267 	    for (i__ = j; i__ <= i__3; ++i__) {
7268 		ipiv[i__] = j - 1 + ipiv[i__];
7269 /* L10: */
7270 	    }
7271 
7272 /*           Apply interchanges to columns 1:J-1. */
7273 
7274 	    i__3 = j - 1;
7275 	    i__4 = j + jb - 1;
7276 	    dlaswp_(&i__3, &a[a_offset], lda, &j, &i__4, &ipiv[1], &c__1);
7277 
7278 	    if (j + jb <= *n) {
7279 
7280 /*              Apply interchanges to columns J+JB:N. */
7281 
7282 		i__3 = *n - j - jb + 1;
7283 		i__4 = j + jb - 1;
7284 		dlaswp_(&i__3, &a[(j + jb) * a_dim1 + 1], lda, &j, &i__4, &
7285 			ipiv[1], &c__1);
7286 
7287 /*              Compute block row of U. */
7288 
7289 		i__3 = *n - j - jb + 1;
7290 		dtrsm_("Left", "Lower", "No transpose", "Unit", &jb, &i__3, &
7291 			c_b15, &a[j + j * a_dim1], lda, &a[j + (j + jb) *
7292 			a_dim1], lda);
7293 		if (j + jb <= *m) {
7294 
7295 /*                 Update trailing submatrix. */
7296 
7297 		    i__3 = *m - j - jb + 1;
7298 		    i__4 = *n - j - jb + 1;
7299 		    dgemm_("No transpose", "No transpose", &i__3, &i__4, &jb,
7300 			    &c_b151, &a[j + jb + j * a_dim1], lda, &a[j + (j
7301 			    + jb) * a_dim1], lda, &c_b15, &a[j + jb + (j + jb)
7302 			     * a_dim1], lda);
7303 		}
7304 	    }
7305 /* L20: */
7306 	}
7307     }
7308     return 0;
7309 
7310 /*     End of DGETRF */
7311 
7312 } /* dgetrf_ */
7313 
dgetrs_(char * trans,integer * n,integer * nrhs,doublereal * a,integer * lda,integer * ipiv,doublereal * b,integer * ldb,integer * info)7314 /* Subroutine */ int dgetrs_(char *trans, integer *n, integer *nrhs,
7315 	doublereal *a, integer *lda, integer *ipiv, doublereal *b, integer *
7316 	ldb, integer *info)
7317 {
7318     /* System generated locals */
7319     integer a_dim1, a_offset, b_dim1, b_offset, i__1;
7320 
7321     /* Local variables */
7322     extern logical lsame_(char *, char *);
7323     extern /* Subroutine */ int dtrsm_(char *, char *, char *, char *,
7324 	    integer *, integer *, doublereal *, doublereal *, integer *,
7325 	    doublereal *, integer *), xerbla_(
7326 	    char *, integer *), dlaswp_(integer *, doublereal *,
7327 	    integer *, integer *, integer *, integer *, integer *);
7328     static logical notran;
7329 
7330 
7331 /*
7332     -- LAPACK routine (version 3.2) --
7333     -- LAPACK is a software package provided by Univ. of Tennessee,    --
7334     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
7335        November 2006
7336 
7337 
7338     Purpose
7339     =======
7340 
7341     DGETRS solves a system of linear equations
7342        A * X = B  or  A' * X = B
7343     with a general N-by-N matrix A using the LU factorization computed
7344     by DGETRF.
7345 
7346     Arguments
7347     =========
7348 
7349     TRANS   (input) CHARACTER*1
7350             Specifies the form of the system of equations:
7351             = 'N':  A * X = B  (No transpose)
7352             = 'T':  A'* X = B  (Transpose)
7353             = 'C':  A'* X = B  (Conjugate transpose = Transpose)
7354 
7355     N       (input) INTEGER
7356             The order of the matrix A.  N >= 0.
7357 
7358     NRHS    (input) INTEGER
7359             The number of right hand sides, i.e., the number of columns
7360             of the matrix B.  NRHS >= 0.
7361 
7362     A       (input) DOUBLE PRECISION array, dimension (LDA,N)
7363             The factors L and U from the factorization A = P*L*U
7364             as computed by DGETRF.
7365 
7366     LDA     (input) INTEGER
7367             The leading dimension of the array A.  LDA >= max(1,N).
7368 
7369     IPIV    (input) INTEGER array, dimension (N)
7370             The pivot indices from DGETRF; for 1<=i<=N, row i of the
7371             matrix was interchanged with row IPIV(i).
7372 
7373     B       (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
7374             On entry, the right hand side matrix B.
7375             On exit, the solution matrix X.
7376 
7377     LDB     (input) INTEGER
7378             The leading dimension of the array B.  LDB >= max(1,N).
7379 
7380     INFO    (output) INTEGER
7381             = 0:  successful exit
7382             < 0:  if INFO = -i, the i-th argument had an illegal value
7383 
7384     =====================================================================
7385 
7386 
7387        Test the input parameters.
7388 */
7389 
7390     /* Parameter adjustments */
7391     a_dim1 = *lda;
7392     a_offset = 1 + a_dim1;
7393     a -= a_offset;
7394     --ipiv;
7395     b_dim1 = *ldb;
7396     b_offset = 1 + b_dim1;
7397     b -= b_offset;
7398 
7399     /* Function Body */
7400     *info = 0;
7401     notran = lsame_(trans, "N");
7402     if (! notran && ! lsame_(trans, "T") && ! lsame_(
7403 	    trans, "C")) {
7404 	*info = -1;
7405     } else if (*n < 0) {
7406 	*info = -2;
7407     } else if (*nrhs < 0) {
7408 	*info = -3;
7409     } else if (*lda < max(1,*n)) {
7410 	*info = -5;
7411     } else if (*ldb < max(1,*n)) {
7412 	*info = -8;
7413     }
7414     if (*info != 0) {
7415 	i__1 = -(*info);
7416 	xerbla_("DGETRS", &i__1);
7417 	return 0;
7418     }
7419 
7420 /*     Quick return if possible */
7421 
7422     if (*n == 0 || *nrhs == 0) {
7423 	return 0;
7424     }
7425 
7426     if (notran) {
7427 
7428 /*
7429           Solve A * X = B.
7430 
7431           Apply row interchanges to the right hand sides.
7432 */
7433 
7434 	dlaswp_(nrhs, &b[b_offset], ldb, &c__1, n, &ipiv[1], &c__1);
7435 
7436 /*        Solve L*X = B, overwriting B with X. */
7437 
7438 	dtrsm_("Left", "Lower", "No transpose", "Unit", n, nrhs, &c_b15, &a[
7439 		a_offset], lda, &b[b_offset], ldb);
7440 
7441 /*        Solve U*X = B, overwriting B with X. */
7442 
7443 	dtrsm_("Left", "Upper", "No transpose", "Non-unit", n, nrhs, &c_b15, &
7444 		a[a_offset], lda, &b[b_offset], ldb);
7445     } else {
7446 
7447 /*
7448           Solve A' * X = B.
7449 
7450           Solve U'*X = B, overwriting B with X.
7451 */
7452 
7453 	dtrsm_("Left", "Upper", "Transpose", "Non-unit", n, nrhs, &c_b15, &a[
7454 		a_offset], lda, &b[b_offset], ldb);
7455 
7456 /*        Solve L'*X = B, overwriting B with X. */
7457 
7458 	dtrsm_("Left", "Lower", "Transpose", "Unit", n, nrhs, &c_b15, &a[
7459 		a_offset], lda, &b[b_offset], ldb);
7460 
7461 /*        Apply row interchanges to the solution vectors. */
7462 
7463 	dlaswp_(nrhs, &b[b_offset], ldb, &c__1, n, &ipiv[1], &c_n1);
7464     }
7465 
7466     return 0;
7467 
7468 /*     End of DGETRS */
7469 
7470 } /* dgetrs_ */
7471 
dhseqr_(char * job,char * compz,integer * n,integer * ilo,integer * ihi,doublereal * h__,integer * ldh,doublereal * wr,doublereal * wi,doublereal * z__,integer * ldz,doublereal * work,integer * lwork,integer * info)7472 /* Subroutine */ int dhseqr_(char *job, char *compz, integer *n, integer *ilo,
7473 	 integer *ihi, doublereal *h__, integer *ldh, doublereal *wr,
7474 	doublereal *wi, doublereal *z__, integer *ldz, doublereal *work,
7475 	integer *lwork, integer *info)
7476 {
7477     /* System generated locals */
7478     address a__1[2];
7479     integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2[2], i__3;
7480     doublereal d__1;
7481     char ch__1[2];
7482 
7483     /* Local variables */
7484     static integer i__;
7485     static doublereal hl[2401]	/* was [49][49] */;
7486     static integer kbot, nmin;
7487     extern logical lsame_(char *, char *);
7488     static logical initz;
7489     static doublereal workl[49];
7490     static logical wantt, wantz;
7491     extern /* Subroutine */ int dlaqr0_(logical *, logical *, integer *,
7492 	    integer *, integer *, doublereal *, integer *, doublereal *,
7493 	    doublereal *, integer *, integer *, doublereal *, integer *,
7494 	    doublereal *, integer *, integer *), dlahqr_(logical *, logical *,
7495 	     integer *, integer *, integer *, doublereal *, integer *,
7496 	    doublereal *, doublereal *, integer *, integer *, doublereal *,
7497 	    integer *, integer *), dlacpy_(char *, integer *, integer *,
7498 	    doublereal *, integer *, doublereal *, integer *),
7499 	    dlaset_(char *, integer *, integer *, doublereal *, doublereal *,
7500 	    doublereal *, integer *);
7501     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
7502 	    integer *, integer *, ftnlen, ftnlen);
7503     extern /* Subroutine */ int xerbla_(char *, integer *);
7504     static logical lquery;
7505 
7506 
7507 /*
7508     -- LAPACK computational routine (version 3.2.2) --
7509        Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
7510        June 2010
7511 
7512        Purpose
7513        =======
7514 
7515        DHSEQR computes the eigenvalues of a Hessenberg matrix H
7516        and, optionally, the matrices T and Z from the Schur decomposition
7517        H = Z T Z**T, where T is an upper quasi-triangular matrix (the
7518        Schur form), and Z is the orthogonal matrix of Schur vectors.
7519 
7520        Optionally Z may be postmultiplied into an input orthogonal
7521        matrix Q so that this routine can give the Schur factorization
7522        of a matrix A which has been reduced to the Hessenberg form H
7523        by the orthogonal matrix Q:  A = Q*H*Q**T = (QZ)*T*(QZ)**T.
7524 
7525        Arguments
7526        =========
7527 
7528        JOB   (input) CHARACTER*1
7529              = 'E':  compute eigenvalues only;
7530              = 'S':  compute eigenvalues and the Schur form T.
7531 
7532        COMPZ (input) CHARACTER*1
7533              = 'N':  no Schur vectors are computed;
7534              = 'I':  Z is initialized to the unit matrix and the matrix Z
7535                      of Schur vectors of H is returned;
7536              = 'V':  Z must contain an orthogonal matrix Q on entry, and
7537                      the product Q*Z is returned.
7538 
7539        N     (input) INTEGER
7540              The order of the matrix H.  N .GE. 0.
7541 
7542        ILO   (input) INTEGER
7543        IHI   (input) INTEGER
7544              It is assumed that H is already upper triangular in rows
7545              and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
7546              set by a previous call to DGEBAL, and then passed to DGEHRD
7547              when the matrix output by DGEBAL is reduced to Hessenberg
7548              form. Otherwise ILO and IHI should be set to 1 and N
7549              respectively.  If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N.
7550              If N = 0, then ILO = 1 and IHI = 0.
7551 
7552        H     (input/output) DOUBLE PRECISION array, dimension (LDH,N)
7553              On entry, the upper Hessenberg matrix H.
7554              On exit, if INFO = 0 and JOB = 'S', then H contains the
7555              upper quasi-triangular matrix T from the Schur decomposition
7556              (the Schur form); 2-by-2 diagonal blocks (corresponding to
7557              complex conjugate pairs of eigenvalues) are returned in
7558              standard form, with H(i,i) = H(i+1,i+1) and
7559              H(i+1,i)*H(i,i+1).LT.0. If INFO = 0 and JOB = 'E', the
7560              contents of H are unspecified on exit.  (The output value of
7561              H when INFO.GT.0 is given under the description of INFO
7562              below.)
7563 
7564              Unlike earlier versions of DHSEQR, this subroutine may
7565              explicitly H(i,j) = 0 for i.GT.j and j = 1, 2, ... ILO-1
7566              or j = IHI+1, IHI+2, ... N.
7567 
7568        LDH   (input) INTEGER
7569              The leading dimension of the array H. LDH .GE. max(1,N).
7570 
7571        WR    (output) DOUBLE PRECISION array, dimension (N)
7572        WI    (output) DOUBLE PRECISION array, dimension (N)
7573              The real and imaginary parts, respectively, of the computed
7574              eigenvalues. If two eigenvalues are computed as a complex
7575              conjugate pair, they are stored in consecutive elements of
7576              WR and WI, say the i-th and (i+1)th, with WI(i) .GT. 0 and
7577              WI(i+1) .LT. 0. If JOB = 'S', the eigenvalues are stored in
7578              the same order as on the diagonal of the Schur form returned
7579              in H, with WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2
7580              diagonal block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and
7581              WI(i+1) = -WI(i).
7582 
7583        Z     (input/output) DOUBLE PRECISION array, dimension (LDZ,N)
7584              If COMPZ = 'N', Z is not referenced.
7585              If COMPZ = 'I', on entry Z need not be set and on exit,
7586              if INFO = 0, Z contains the orthogonal matrix Z of the Schur
7587              vectors of H.  If COMPZ = 'V', on entry Z must contain an
7588              N-by-N matrix Q, which is assumed to be equal to the unit
7589              matrix except for the submatrix Z(ILO:IHI,ILO:IHI). On exit,
7590              if INFO = 0, Z contains Q*Z.
7591              Normally Q is the orthogonal matrix generated by DORGHR
7592              after the call to DGEHRD which formed the Hessenberg matrix
7593              H. (The output value of Z when INFO.GT.0 is given under
7594              the description of INFO below.)
7595 
7596        LDZ   (input) INTEGER
7597              The leading dimension of the array Z.  if COMPZ = 'I' or
7598              COMPZ = 'V', then LDZ.GE.MAX(1,N).  Otherwize, LDZ.GE.1.
7599 
7600        WORK  (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
7601              On exit, if INFO = 0, WORK(1) returns an estimate of
7602              the optimal value for LWORK.
7603 
7604        LWORK (input) INTEGER
7605              The dimension of the array WORK.  LWORK .GE. max(1,N)
7606              is sufficient and delivers very good and sometimes
7607              optimal performance.  However, LWORK as large as 11*N
7608              may be required for optimal performance.  A workspace
7609              query is recommended to determine the optimal workspace
7610              size.
7611 
7612              If LWORK = -1, then DHSEQR does a workspace query.
7613              In this case, DHSEQR checks the input parameters and
7614              estimates the optimal workspace size for the given
7615              values of N, ILO and IHI.  The estimate is returned
7616              in WORK(1).  No error message related to LWORK is
7617              issued by XERBLA.  Neither H nor Z are accessed.
7618 
7619 
7620        INFO  (output) INTEGER
7621                =  0:  successful exit
7622              .LT. 0:  if INFO = -i, the i-th argument had an illegal
7623                       value
7624              .GT. 0:  if INFO = i, DHSEQR failed to compute all of
7625                   the eigenvalues.  Elements 1:ilo-1 and i+1:n of WR
7626                   and WI contain those eigenvalues which have been
7627                   successfully computed.  (Failures are rare.)
7628 
7629                   If INFO .GT. 0 and JOB = 'E', then on exit, the
7630                   remaining unconverged eigenvalues are the eigen-
7631                   values of the upper Hessenberg matrix rows and
7632                   columns ILO through INFO of the final, output
7633                   value of H.
7634 
7635                   If INFO .GT. 0 and JOB   = 'S', then on exit
7636 
7637              (*)  (initial value of H)*U  = U*(final value of H)
7638 
7639                   where U is an orthogonal matrix.  The final
7640                   value of H is upper Hessenberg and quasi-triangular
7641                   in rows and columns INFO+1 through IHI.
7642 
7643                   If INFO .GT. 0 and COMPZ = 'V', then on exit
7644 
7645                     (final value of Z)  =  (initial value of Z)*U
7646 
7647                   where U is the orthogonal matrix in (*) (regard-
7648                   less of the value of JOB.)
7649 
7650                   If INFO .GT. 0 and COMPZ = 'I', then on exit
7651                         (final value of Z)  = U
7652                   where U is the orthogonal matrix in (*) (regard-
7653                   less of the value of JOB.)
7654 
7655                   If INFO .GT. 0 and COMPZ = 'N', then Z is not
7656                   accessed.
7657 
7658        ================================================================
7659                Default values supplied by
7660                ILAENV(ISPEC,'DHSEQR',JOB(:1)//COMPZ(:1),N,ILO,IHI,LWORK).
7661                It is suggested that these defaults be adjusted in order
7662                to attain best performance in each particular
7663                computational environment.
7664 
7665               ISPEC=12: The DLAHQR vs DLAQR0 crossover point.
7666                         Default: 75. (Must be at least 11.)
7667 
7668               ISPEC=13: Recommended deflation window size.
7669                         This depends on ILO, IHI and NS.  NS is the
7670                         number of simultaneous shifts returned
7671                         by ILAENV(ISPEC=15).  (See ISPEC=15 below.)
7672                         The default for (IHI-ILO+1).LE.500 is NS.
7673                         The default for (IHI-ILO+1).GT.500 is 3*NS/2.
7674 
7675               ISPEC=14: Nibble crossover point. (See IPARMQ for
7676                         details.)  Default: 14% of deflation window
7677                         size.
7678 
7679               ISPEC=15: Number of simultaneous shifts in a multishift
7680                         QR iteration.
7681 
7682                         If IHI-ILO+1 is ...
7683 
7684                         greater than      ...but less    ... the
7685                         or equal to ...      than        default is
7686 
7687                              1               30          NS =   2(+)
7688                             30               60          NS =   4(+)
7689                             60              150          NS =  10(+)
7690                            150              590          NS =  **
7691                            590             3000          NS =  64
7692                           3000             6000          NS = 128
7693                           6000             infinity      NS = 256
7694 
7695                     (+)  By default some or all matrices of this order
7696                          are passed to the implicit double shift routine
7697                          DLAHQR and this parameter is ignored.  See
7698                          ISPEC=12 above and comments in IPARMQ for
7699                          details.
7700 
7701                    (**)  The asterisks (**) indicate an ad-hoc
7702                          function of N increasing from 10 to 64.
7703 
7704               ISPEC=16: Select structured matrix multiply.
7705                         If the number of simultaneous shifts (specified
7706                         by ISPEC=15) is less than 14, then the default
7707                         for ISPEC=16 is 0.  Otherwise the default for
7708                         ISPEC=16 is 2.
7709 
7710        ================================================================
7711        Based on contributions by
7712           Karen Braman and Ralph Byers, Department of Mathematics,
7713           University of Kansas, USA
7714 
7715        ================================================================
7716        References:
7717          K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
7718          Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
7719          Performance, SIAM Journal of Matrix Analysis, volume 23, pages
7720          929--947, 2002.
7721 
7722          K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
7723          Algorithm Part II: Aggressive Early Deflation, SIAM Journal
7724          of Matrix Analysis, volume 23, pages 948--973, 2002.
7725 
7726        ================================================================
7727 
7728        ==== Matrices of order NTINY or smaller must be processed by
7729        .    DLAHQR because of insufficient subdiagonal scratch space.
7730        .    (This is a hard limit.) ====
7731 
7732        ==== NL allocates some local workspace to help small matrices
7733        .    through a rare DLAHQR failure.  NL .GT. NTINY = 11 is
7734        .    required and NL .LE. NMIN = ILAENV(ISPEC=12,...) is recom-
7735        .    mended.  (The default value of NMIN is 75.)  Using NL = 49
7736        .    allows up to six simultaneous shifts and a 16-by-16
7737        .    deflation window.  ====
7738 
7739        ==== Decode and check the input parameters. ====
7740 */
7741 
7742     /* Parameter adjustments */
7743     h_dim1 = *ldh;
7744     h_offset = 1 + h_dim1;
7745     h__ -= h_offset;
7746     --wr;
7747     --wi;
7748     z_dim1 = *ldz;
7749     z_offset = 1 + z_dim1;
7750     z__ -= z_offset;
7751     --work;
7752 
7753     /* Function Body */
7754     wantt = lsame_(job, "S");
7755     initz = lsame_(compz, "I");
7756     wantz = initz || lsame_(compz, "V");
7757     work[1] = (doublereal) max(1,*n);
7758     lquery = *lwork == -1;
7759 
7760     *info = 0;
7761     if (! lsame_(job, "E") && ! wantt) {
7762 	*info = -1;
7763     } else if (! lsame_(compz, "N") && ! wantz) {
7764 	*info = -2;
7765     } else if (*n < 0) {
7766 	*info = -3;
7767     } else if (*ilo < 1 || *ilo > max(1,*n)) {
7768 	*info = -4;
7769     } else if (*ihi < min(*ilo,*n) || *ihi > *n) {
7770 	*info = -5;
7771     } else if (*ldh < max(1,*n)) {
7772 	*info = -7;
7773     } else if (*ldz < 1 || wantz && *ldz < max(1,*n)) {
7774 	*info = -11;
7775     } else if (*lwork < max(1,*n) && ! lquery) {
7776 	*info = -13;
7777     }
7778 
7779     if (*info != 0) {
7780 
7781 /*        ==== Quick return in case of invalid argument. ==== */
7782 
7783 	i__1 = -(*info);
7784 	xerbla_("DHSEQR", &i__1);
7785 	return 0;
7786 
7787     } else if (*n == 0) {
7788 
7789 /*        ==== Quick return in case N = 0; nothing to do. ==== */
7790 
7791 	return 0;
7792 
7793     } else if (lquery) {
7794 
7795 /*        ==== Quick return in case of a workspace query ==== */
7796 
7797 	dlaqr0_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1], &wi[
7798 		1], ilo, ihi, &z__[z_offset], ldz, &work[1], lwork, info);
7799 /*
7800           ==== Ensure reported workspace size is backward-compatible with
7801           .    previous LAPACK versions. ====
7802    Computing MAX
7803 */
7804 	d__1 = (doublereal) max(1,*n);
7805 	work[1] = max(d__1,work[1]);
7806 	return 0;
7807 
7808     } else {
7809 
7810 /*        ==== copy eigenvalues isolated by DGEBAL ==== */
7811 
7812 	i__1 = *ilo - 1;
7813 	for (i__ = 1; i__ <= i__1; ++i__) {
7814 	    wr[i__] = h__[i__ + i__ * h_dim1];
7815 	    wi[i__] = 0.;
7816 /* L10: */
7817 	}
7818 	i__1 = *n;
7819 	for (i__ = *ihi + 1; i__ <= i__1; ++i__) {
7820 	    wr[i__] = h__[i__ + i__ * h_dim1];
7821 	    wi[i__] = 0.;
7822 /* L20: */
7823 	}
7824 
7825 /*        ==== Initialize Z, if requested ==== */
7826 
7827 	if (initz) {
7828 	    dlaset_("A", n, n, &c_b29, &c_b15, &z__[z_offset], ldz)
7829 		    ;
7830 	}
7831 
7832 /*        ==== Quick return if possible ==== */
7833 
7834 	if (*ilo == *ihi) {
7835 	    wr[*ilo] = h__[*ilo + *ilo * h_dim1];
7836 	    wi[*ilo] = 0.;
7837 	    return 0;
7838 	}
7839 
7840 /*
7841           ==== DLAHQR/DLAQR0 crossover point ====
7842 
7843    Writing concatenation
7844 */
7845 	i__2[0] = 1, a__1[0] = job;
7846 	i__2[1] = 1, a__1[1] = compz;
7847 	s_cat(ch__1, a__1, i__2, &c__2, (ftnlen)2);
7848 	nmin = ilaenv_(&c__12, "DHSEQR", ch__1, n, ilo, ihi, lwork, (ftnlen)6,
7849 		 (ftnlen)2);
7850 	nmin = max(11,nmin);
7851 
7852 /*        ==== DLAQR0 for big matrices; DLAHQR for small ones ==== */
7853 
7854 	if (*n > nmin) {
7855 	    dlaqr0_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1],
7856 		    &wi[1], ilo, ihi, &z__[z_offset], ldz, &work[1], lwork,
7857 		    info);
7858 	} else {
7859 
7860 /*           ==== Small matrix ==== */
7861 
7862 	    dlahqr_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1],
7863 		    &wi[1], ilo, ihi, &z__[z_offset], ldz, info);
7864 
7865 	    if (*info > 0) {
7866 
7867 /*
7868                 ==== A rare DLAHQR failure!  DLAQR0 sometimes succeeds
7869                 .    when DLAHQR fails. ====
7870 */
7871 
7872 		kbot = *info;
7873 
7874 		if (*n >= 49) {
7875 
7876 /*
7877                    ==== Larger matrices have enough subdiagonal scratch
7878                    .    space to call DLAQR0 directly. ====
7879 */
7880 
7881 		    dlaqr0_(&wantt, &wantz, n, ilo, &kbot, &h__[h_offset],
7882 			    ldh, &wr[1], &wi[1], ilo, ihi, &z__[z_offset],
7883 			    ldz, &work[1], lwork, info);
7884 
7885 		} else {
7886 
7887 /*
7888                    ==== Tiny matrices don't have enough subdiagonal
7889                    .    scratch space to benefit from DLAQR0.  Hence,
7890                    .    tiny matrices must be copied into a larger
7891                    .    array before calling DLAQR0. ====
7892 */
7893 
7894 		    dlacpy_("A", n, n, &h__[h_offset], ldh, hl, &c__49);
7895 		    hl[*n + 1 + *n * 49 - 50] = 0.;
7896 		    i__1 = 49 - *n;
7897 		    dlaset_("A", &c__49, &i__1, &c_b29, &c_b29, &hl[(*n + 1) *
7898 			     49 - 49], &c__49);
7899 		    dlaqr0_(&wantt, &wantz, &c__49, ilo, &kbot, hl, &c__49, &
7900 			    wr[1], &wi[1], ilo, ihi, &z__[z_offset], ldz,
7901 			    workl, &c__49, info);
7902 		    if (wantt || *info != 0) {
7903 			dlacpy_("A", n, n, hl, &c__49, &h__[h_offset], ldh);
7904 		    }
7905 		}
7906 	    }
7907 	}
7908 
7909 /*        ==== Clear out the trash, if necessary. ==== */
7910 
7911 	if ((wantt || *info != 0) && *n > 2) {
7912 	    i__1 = *n - 2;
7913 	    i__3 = *n - 2;
7914 	    dlaset_("L", &i__1, &i__3, &c_b29, &c_b29, &h__[h_dim1 + 3], ldh);
7915 	}
7916 
7917 /*
7918           ==== Ensure reported workspace size is backward-compatible with
7919           .    previous LAPACK versions. ====
7920 
7921    Computing MAX
7922 */
7923 	d__1 = (doublereal) max(1,*n);
7924 	work[1] = max(d__1,work[1]);
7925     }
7926 
7927 /*     ==== End of DHSEQR ==== */
7928 
7929     return 0;
7930 } /* dhseqr_ */
7931 
disnan_(doublereal * din)7932 logical disnan_(doublereal *din)
7933 {
7934     /* System generated locals */
7935     logical ret_val;
7936 
7937     /* Local variables */
7938     extern logical dlaisnan_(doublereal *, doublereal *);
7939 
7940 
7941 /*
7942     -- LAPACK auxiliary routine (version 3.2.2) --
7943     -- LAPACK is a software package provided by Univ. of Tennessee,    --
7944     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
7945        June 2010
7946 
7947 
7948     Purpose
7949     =======
7950 
7951     DISNAN returns .TRUE. if its argument is NaN, and .FALSE.
7952     otherwise.  To be replaced by the Fortran 2003 intrinsic in the
7953     future.
7954 
7955     Arguments
7956     =========
7957 
7958     DIN     (input) DOUBLE PRECISION
7959             Input to test for NaN.
7960 
7961     =====================================================================
7962 */
7963 
7964     ret_val = dlaisnan_(din, din);
7965     return ret_val;
7966 } /* disnan_ */
7967 
dlabad_(doublereal * small,doublereal * large)7968 /* Subroutine */ int dlabad_(doublereal *small, doublereal *large)
7969 {
7970 
7971 /*
7972     -- LAPACK auxiliary routine (version 3.2) --
7973     -- LAPACK is a software package provided by Univ. of Tennessee,    --
7974     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
7975        November 2006
7976 
7977 
7978     Purpose
7979     =======
7980 
7981     DLABAD takes as input the values computed by DLAMCH for underflow and
7982     overflow, and returns the square root of each of these values if the
7983     log of LARGE is sufficiently large.  This subroutine is intended to
7984     identify machines with a large exponent range, such as the Crays, and
7985     redefine the underflow and overflow limits to be the square roots of
7986     the values computed by DLAMCH.  This subroutine is needed because
7987     DLAMCH does not compensate for poor arithmetic in the upper half of
7988     the exponent range, as is found on a Cray.
7989 
7990     Arguments
7991     =========
7992 
7993     SMALL   (input/output) DOUBLE PRECISION
7994             On entry, the underflow threshold as computed by DLAMCH.
7995             On exit, if LOG10(LARGE) is sufficiently large, the square
7996             root of SMALL, otherwise unchanged.
7997 
7998     LARGE   (input/output) DOUBLE PRECISION
7999             On entry, the overflow threshold as computed by DLAMCH.
8000             On exit, if LOG10(LARGE) is sufficiently large, the square
8001             root of LARGE, otherwise unchanged.
8002 
8003     =====================================================================
8004 
8005 
8006        If it looks like we're on a Cray, take the square root of
8007        SMALL and LARGE to avoid overflow and underflow problems.
8008 */
8009 
8010     if (d_lg10(large) > 2e3) {
8011 	*small = sqrt(*small);
8012 	*large = sqrt(*large);
8013     }
8014 
8015     return 0;
8016 
8017 /*     End of DLABAD */
8018 
8019 } /* dlabad_ */
8020 
dlabrd_(integer * m,integer * n,integer * nb,doublereal * a,integer * lda,doublereal * d__,doublereal * e,doublereal * tauq,doublereal * taup,doublereal * x,integer * ldx,doublereal * y,integer * ldy)8021 /* Subroutine */ int dlabrd_(integer *m, integer *n, integer *nb, doublereal *
8022 	a, integer *lda, doublereal *d__, doublereal *e, doublereal *tauq,
8023 	doublereal *taup, doublereal *x, integer *ldx, doublereal *y, integer
8024 	*ldy)
8025 {
8026     /* System generated locals */
8027     integer a_dim1, a_offset, x_dim1, x_offset, y_dim1, y_offset, i__1, i__2,
8028 	    i__3;
8029 
8030     /* Local variables */
8031     static integer i__;
8032     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
8033 	    integer *), dgemv_(char *, integer *, integer *, doublereal *,
8034 	    doublereal *, integer *, doublereal *, integer *, doublereal *,
8035 	    doublereal *, integer *), dlarfg_(integer *, doublereal *,
8036 	     doublereal *, integer *, doublereal *);
8037 
8038 
8039 /*
8040     -- LAPACK auxiliary routine (version 3.2) --
8041     -- LAPACK is a software package provided by Univ. of Tennessee,    --
8042     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
8043        November 2006
8044 
8045 
8046     Purpose
8047     =======
8048 
8049     DLABRD reduces the first NB rows and columns of a real general
8050     m by n matrix A to upper or lower bidiagonal form by an orthogonal
8051     transformation Q' * A * P, and returns the matrices X and Y which
8052     are needed to apply the transformation to the unreduced part of A.
8053 
8054     If m >= n, A is reduced to upper bidiagonal form; if m < n, to lower
8055     bidiagonal form.
8056 
8057     This is an auxiliary routine called by DGEBRD
8058 
8059     Arguments
8060     =========
8061 
8062     M       (input) INTEGER
8063             The number of rows in the matrix A.
8064 
8065     N       (input) INTEGER
8066             The number of columns in the matrix A.
8067 
8068     NB      (input) INTEGER
8069             The number of leading rows and columns of A to be reduced.
8070 
8071     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
8072             On entry, the m by n general matrix to be reduced.
8073             On exit, the first NB rows and columns of the matrix are
8074             overwritten; the rest of the array is unchanged.
8075             If m >= n, elements on and below the diagonal in the first NB
8076               columns, with the array TAUQ, represent the orthogonal
8077               matrix Q as a product of elementary reflectors; and
8078               elements above the diagonal in the first NB rows, with the
8079               array TAUP, represent the orthogonal matrix P as a product
8080               of elementary reflectors.
8081             If m < n, elements below the diagonal in the first NB
8082               columns, with the array TAUQ, represent the orthogonal
8083               matrix Q as a product of elementary reflectors, and
8084               elements on and above the diagonal in the first NB rows,
8085               with the array TAUP, represent the orthogonal matrix P as
8086               a product of elementary reflectors.
8087             See Further Details.
8088 
8089     LDA     (input) INTEGER
8090             The leading dimension of the array A.  LDA >= max(1,M).
8091 
8092     D       (output) DOUBLE PRECISION array, dimension (NB)
8093             The diagonal elements of the first NB rows and columns of
8094             the reduced matrix.  D(i) = A(i,i).
8095 
8096     E       (output) DOUBLE PRECISION array, dimension (NB)
8097             The off-diagonal elements of the first NB rows and columns of
8098             the reduced matrix.
8099 
8100     TAUQ    (output) DOUBLE PRECISION array dimension (NB)
8101             The scalar factors of the elementary reflectors which
8102             represent the orthogonal matrix Q. See Further Details.
8103 
8104     TAUP    (output) DOUBLE PRECISION array, dimension (NB)
8105             The scalar factors of the elementary reflectors which
8106             represent the orthogonal matrix P. See Further Details.
8107 
8108     X       (output) DOUBLE PRECISION array, dimension (LDX,NB)
8109             The m-by-nb matrix X required to update the unreduced part
8110             of A.
8111 
8112     LDX     (input) INTEGER
8113             The leading dimension of the array X. LDX >= M.
8114 
8115     Y       (output) DOUBLE PRECISION array, dimension (LDY,NB)
8116             The n-by-nb matrix Y required to update the unreduced part
8117             of A.
8118 
8119     LDY     (input) INTEGER
8120             The leading dimension of the array Y. LDY >= N.
8121 
8122     Further Details
8123     ===============
8124 
8125     The matrices Q and P are represented as products of elementary
8126     reflectors:
8127 
8128        Q = H(1) H(2) . . . H(nb)  and  P = G(1) G(2) . . . G(nb)
8129 
8130     Each H(i) and G(i) has the form:
8131 
8132        H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u'
8133 
8134     where tauq and taup are real scalars, and v and u are real vectors.
8135 
8136     If m >= n, v(1:i-1) = 0, v(i) = 1, and v(i:m) is stored on exit in
8137     A(i:m,i); u(1:i) = 0, u(i+1) = 1, and u(i+1:n) is stored on exit in
8138     A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
8139 
8140     If m < n, v(1:i) = 0, v(i+1) = 1, and v(i+1:m) is stored on exit in
8141     A(i+2:m,i); u(1:i-1) = 0, u(i) = 1, and u(i:n) is stored on exit in
8142     A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
8143 
8144     The elements of the vectors v and u together form the m-by-nb matrix
8145     V and the nb-by-n matrix U' which are needed, with X and Y, to apply
8146     the transformation to the unreduced part of the matrix, using a block
8147     update of the form:  A := A - V*Y' - X*U'.
8148 
8149     The contents of A on exit are illustrated by the following examples
8150     with nb = 2:
8151 
8152     m = 6 and n = 5 (m > n):          m = 5 and n = 6 (m < n):
8153 
8154       (  1   1   u1  u1  u1 )           (  1   u1  u1  u1  u1  u1 )
8155       (  v1  1   1   u2  u2 )           (  1   1   u2  u2  u2  u2 )
8156       (  v1  v2  a   a   a  )           (  v1  1   a   a   a   a  )
8157       (  v1  v2  a   a   a  )           (  v1  v2  a   a   a   a  )
8158       (  v1  v2  a   a   a  )           (  v1  v2  a   a   a   a  )
8159       (  v1  v2  a   a   a  )
8160 
8161     where a denotes an element of the original matrix which is unchanged,
8162     vi denotes an element of the vector defining H(i), and ui an element
8163     of the vector defining G(i).
8164 
8165     =====================================================================
8166 
8167 
8168        Quick return if possible
8169 */
8170 
8171     /* Parameter adjustments */
8172     a_dim1 = *lda;
8173     a_offset = 1 + a_dim1;
8174     a -= a_offset;
8175     --d__;
8176     --e;
8177     --tauq;
8178     --taup;
8179     x_dim1 = *ldx;
8180     x_offset = 1 + x_dim1;
8181     x -= x_offset;
8182     y_dim1 = *ldy;
8183     y_offset = 1 + y_dim1;
8184     y -= y_offset;
8185 
8186     /* Function Body */
8187     if (*m <= 0 || *n <= 0) {
8188 	return 0;
8189     }
8190 
8191     if (*m >= *n) {
8192 
8193 /*        Reduce to upper bidiagonal form */
8194 
8195 	i__1 = *nb;
8196 	for (i__ = 1; i__ <= i__1; ++i__) {
8197 
8198 /*           Update A(i:m,i) */
8199 
8200 	    i__2 = *m - i__ + 1;
8201 	    i__3 = i__ - 1;
8202 	    dgemv_("No transpose", &i__2, &i__3, &c_b151, &a[i__ + a_dim1],
8203 		    lda, &y[i__ + y_dim1], ldy, &c_b15, &a[i__ + i__ * a_dim1]
8204 		    , &c__1);
8205 	    i__2 = *m - i__ + 1;
8206 	    i__3 = i__ - 1;
8207 	    dgemv_("No transpose", &i__2, &i__3, &c_b151, &x[i__ + x_dim1],
8208 		    ldx, &a[i__ * a_dim1 + 1], &c__1, &c_b15, &a[i__ + i__ *
8209 		    a_dim1], &c__1);
8210 
8211 /*           Generate reflection Q(i) to annihilate A(i+1:m,i) */
8212 
8213 	    i__2 = *m - i__ + 1;
8214 /* Computing MIN */
8215 	    i__3 = i__ + 1;
8216 	    dlarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[min(i__3,*m) + i__ *
8217 		    a_dim1], &c__1, &tauq[i__]);
8218 	    d__[i__] = a[i__ + i__ * a_dim1];
8219 	    if (i__ < *n) {
8220 		a[i__ + i__ * a_dim1] = 1.;
8221 
8222 /*              Compute Y(i+1:n,i) */
8223 
8224 		i__2 = *m - i__ + 1;
8225 		i__3 = *n - i__;
8226 		dgemv_("Transpose", &i__2, &i__3, &c_b15, &a[i__ + (i__ + 1) *
8227 			 a_dim1], lda, &a[i__ + i__ * a_dim1], &c__1, &c_b29,
8228 			&y[i__ + 1 + i__ * y_dim1], &c__1);
8229 		i__2 = *m - i__ + 1;
8230 		i__3 = i__ - 1;
8231 		dgemv_("Transpose", &i__2, &i__3, &c_b15, &a[i__ + a_dim1],
8232 			lda, &a[i__ + i__ * a_dim1], &c__1, &c_b29, &y[i__ *
8233 			y_dim1 + 1], &c__1);
8234 		i__2 = *n - i__;
8235 		i__3 = i__ - 1;
8236 		dgemv_("No transpose", &i__2, &i__3, &c_b151, &y[i__ + 1 +
8237 			y_dim1], ldy, &y[i__ * y_dim1 + 1], &c__1, &c_b15, &y[
8238 			i__ + 1 + i__ * y_dim1], &c__1);
8239 		i__2 = *m - i__ + 1;
8240 		i__3 = i__ - 1;
8241 		dgemv_("Transpose", &i__2, &i__3, &c_b15, &x[i__ + x_dim1],
8242 			ldx, &a[i__ + i__ * a_dim1], &c__1, &c_b29, &y[i__ *
8243 			y_dim1 + 1], &c__1);
8244 		i__2 = i__ - 1;
8245 		i__3 = *n - i__;
8246 		dgemv_("Transpose", &i__2, &i__3, &c_b151, &a[(i__ + 1) *
8247 			a_dim1 + 1], lda, &y[i__ * y_dim1 + 1], &c__1, &c_b15,
8248 			 &y[i__ + 1 + i__ * y_dim1], &c__1);
8249 		i__2 = *n - i__;
8250 		dscal_(&i__2, &tauq[i__], &y[i__ + 1 + i__ * y_dim1], &c__1);
8251 
8252 /*              Update A(i,i+1:n) */
8253 
8254 		i__2 = *n - i__;
8255 		dgemv_("No transpose", &i__2, &i__, &c_b151, &y[i__ + 1 +
8256 			y_dim1], ldy, &a[i__ + a_dim1], lda, &c_b15, &a[i__ +
8257 			(i__ + 1) * a_dim1], lda);
8258 		i__2 = i__ - 1;
8259 		i__3 = *n - i__;
8260 		dgemv_("Transpose", &i__2, &i__3, &c_b151, &a[(i__ + 1) *
8261 			a_dim1 + 1], lda, &x[i__ + x_dim1], ldx, &c_b15, &a[
8262 			i__ + (i__ + 1) * a_dim1], lda);
8263 
8264 /*              Generate reflection P(i) to annihilate A(i,i+2:n) */
8265 
8266 		i__2 = *n - i__;
8267 /* Computing MIN */
8268 		i__3 = i__ + 2;
8269 		dlarfg_(&i__2, &a[i__ + (i__ + 1) * a_dim1], &a[i__ + min(
8270 			i__3,*n) * a_dim1], lda, &taup[i__]);
8271 		e[i__] = a[i__ + (i__ + 1) * a_dim1];
8272 		a[i__ + (i__ + 1) * a_dim1] = 1.;
8273 
8274 /*              Compute X(i+1:m,i) */
8275 
8276 		i__2 = *m - i__;
8277 		i__3 = *n - i__;
8278 		dgemv_("No transpose", &i__2, &i__3, &c_b15, &a[i__ + 1 + (
8279 			i__ + 1) * a_dim1], lda, &a[i__ + (i__ + 1) * a_dim1],
8280 			 lda, &c_b29, &x[i__ + 1 + i__ * x_dim1], &c__1);
8281 		i__2 = *n - i__;
8282 		dgemv_("Transpose", &i__2, &i__, &c_b15, &y[i__ + 1 + y_dim1],
8283 			 ldy, &a[i__ + (i__ + 1) * a_dim1], lda, &c_b29, &x[
8284 			i__ * x_dim1 + 1], &c__1);
8285 		i__2 = *m - i__;
8286 		dgemv_("No transpose", &i__2, &i__, &c_b151, &a[i__ + 1 +
8287 			a_dim1], lda, &x[i__ * x_dim1 + 1], &c__1, &c_b15, &x[
8288 			i__ + 1 + i__ * x_dim1], &c__1);
8289 		i__2 = i__ - 1;
8290 		i__3 = *n - i__;
8291 		dgemv_("No transpose", &i__2, &i__3, &c_b15, &a[(i__ + 1) *
8292 			a_dim1 + 1], lda, &a[i__ + (i__ + 1) * a_dim1], lda, &
8293 			c_b29, &x[i__ * x_dim1 + 1], &c__1);
8294 		i__2 = *m - i__;
8295 		i__3 = i__ - 1;
8296 		dgemv_("No transpose", &i__2, &i__3, &c_b151, &x[i__ + 1 +
8297 			x_dim1], ldx, &x[i__ * x_dim1 + 1], &c__1, &c_b15, &x[
8298 			i__ + 1 + i__ * x_dim1], &c__1);
8299 		i__2 = *m - i__;
8300 		dscal_(&i__2, &taup[i__], &x[i__ + 1 + i__ * x_dim1], &c__1);
8301 	    }
8302 /* L10: */
8303 	}
8304     } else {
8305 
8306 /*        Reduce to lower bidiagonal form */
8307 
8308 	i__1 = *nb;
8309 	for (i__ = 1; i__ <= i__1; ++i__) {
8310 
8311 /*           Update A(i,i:n) */
8312 
8313 	    i__2 = *n - i__ + 1;
8314 	    i__3 = i__ - 1;
8315 	    dgemv_("No transpose", &i__2, &i__3, &c_b151, &y[i__ + y_dim1],
8316 		    ldy, &a[i__ + a_dim1], lda, &c_b15, &a[i__ + i__ * a_dim1]
8317 		    , lda);
8318 	    i__2 = i__ - 1;
8319 	    i__3 = *n - i__ + 1;
8320 	    dgemv_("Transpose", &i__2, &i__3, &c_b151, &a[i__ * a_dim1 + 1],
8321 		    lda, &x[i__ + x_dim1], ldx, &c_b15, &a[i__ + i__ * a_dim1]
8322 		    , lda);
8323 
8324 /*           Generate reflection P(i) to annihilate A(i,i+1:n) */
8325 
8326 	    i__2 = *n - i__ + 1;
8327 /* Computing MIN */
8328 	    i__3 = i__ + 1;
8329 	    dlarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[i__ + min(i__3,*n) *
8330 		    a_dim1], lda, &taup[i__]);
8331 	    d__[i__] = a[i__ + i__ * a_dim1];
8332 	    if (i__ < *m) {
8333 		a[i__ + i__ * a_dim1] = 1.;
8334 
8335 /*              Compute X(i+1:m,i) */
8336 
8337 		i__2 = *m - i__;
8338 		i__3 = *n - i__ + 1;
8339 		dgemv_("No transpose", &i__2, &i__3, &c_b15, &a[i__ + 1 + i__
8340 			* a_dim1], lda, &a[i__ + i__ * a_dim1], lda, &c_b29, &
8341 			x[i__ + 1 + i__ * x_dim1], &c__1);
8342 		i__2 = *n - i__ + 1;
8343 		i__3 = i__ - 1;
8344 		dgemv_("Transpose", &i__2, &i__3, &c_b15, &y[i__ + y_dim1],
8345 			ldy, &a[i__ + i__ * a_dim1], lda, &c_b29, &x[i__ *
8346 			x_dim1 + 1], &c__1);
8347 		i__2 = *m - i__;
8348 		i__3 = i__ - 1;
8349 		dgemv_("No transpose", &i__2, &i__3, &c_b151, &a[i__ + 1 +
8350 			a_dim1], lda, &x[i__ * x_dim1 + 1], &c__1, &c_b15, &x[
8351 			i__ + 1 + i__ * x_dim1], &c__1);
8352 		i__2 = i__ - 1;
8353 		i__3 = *n - i__ + 1;
8354 		dgemv_("No transpose", &i__2, &i__3, &c_b15, &a[i__ * a_dim1
8355 			+ 1], lda, &a[i__ + i__ * a_dim1], lda, &c_b29, &x[
8356 			i__ * x_dim1 + 1], &c__1);
8357 		i__2 = *m - i__;
8358 		i__3 = i__ - 1;
8359 		dgemv_("No transpose", &i__2, &i__3, &c_b151, &x[i__ + 1 +
8360 			x_dim1], ldx, &x[i__ * x_dim1 + 1], &c__1, &c_b15, &x[
8361 			i__ + 1 + i__ * x_dim1], &c__1);
8362 		i__2 = *m - i__;
8363 		dscal_(&i__2, &taup[i__], &x[i__ + 1 + i__ * x_dim1], &c__1);
8364 
8365 /*              Update A(i+1:m,i) */
8366 
8367 		i__2 = *m - i__;
8368 		i__3 = i__ - 1;
8369 		dgemv_("No transpose", &i__2, &i__3, &c_b151, &a[i__ + 1 +
8370 			a_dim1], lda, &y[i__ + y_dim1], ldy, &c_b15, &a[i__ +
8371 			1 + i__ * a_dim1], &c__1);
8372 		i__2 = *m - i__;
8373 		dgemv_("No transpose", &i__2, &i__, &c_b151, &x[i__ + 1 +
8374 			x_dim1], ldx, &a[i__ * a_dim1 + 1], &c__1, &c_b15, &a[
8375 			i__ + 1 + i__ * a_dim1], &c__1);
8376 
8377 /*              Generate reflection Q(i) to annihilate A(i+2:m,i) */
8378 
8379 		i__2 = *m - i__;
8380 /* Computing MIN */
8381 		i__3 = i__ + 2;
8382 		dlarfg_(&i__2, &a[i__ + 1 + i__ * a_dim1], &a[min(i__3,*m) +
8383 			i__ * a_dim1], &c__1, &tauq[i__]);
8384 		e[i__] = a[i__ + 1 + i__ * a_dim1];
8385 		a[i__ + 1 + i__ * a_dim1] = 1.;
8386 
8387 /*              Compute Y(i+1:n,i) */
8388 
8389 		i__2 = *m - i__;
8390 		i__3 = *n - i__;
8391 		dgemv_("Transpose", &i__2, &i__3, &c_b15, &a[i__ + 1 + (i__ +
8392 			1) * a_dim1], lda, &a[i__ + 1 + i__ * a_dim1], &c__1,
8393 			&c_b29, &y[i__ + 1 + i__ * y_dim1], &c__1);
8394 		i__2 = *m - i__;
8395 		i__3 = i__ - 1;
8396 		dgemv_("Transpose", &i__2, &i__3, &c_b15, &a[i__ + 1 + a_dim1]
8397 			, lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &c_b29, &y[
8398 			i__ * y_dim1 + 1], &c__1);
8399 		i__2 = *n - i__;
8400 		i__3 = i__ - 1;
8401 		dgemv_("No transpose", &i__2, &i__3, &c_b151, &y[i__ + 1 +
8402 			y_dim1], ldy, &y[i__ * y_dim1 + 1], &c__1, &c_b15, &y[
8403 			i__ + 1 + i__ * y_dim1], &c__1);
8404 		i__2 = *m - i__;
8405 		dgemv_("Transpose", &i__2, &i__, &c_b15, &x[i__ + 1 + x_dim1],
8406 			 ldx, &a[i__ + 1 + i__ * a_dim1], &c__1, &c_b29, &y[
8407 			i__ * y_dim1 + 1], &c__1);
8408 		i__2 = *n - i__;
8409 		dgemv_("Transpose", &i__, &i__2, &c_b151, &a[(i__ + 1) *
8410 			a_dim1 + 1], lda, &y[i__ * y_dim1 + 1], &c__1, &c_b15,
8411 			 &y[i__ + 1 + i__ * y_dim1], &c__1);
8412 		i__2 = *n - i__;
8413 		dscal_(&i__2, &tauq[i__], &y[i__ + 1 + i__ * y_dim1], &c__1);
8414 	    }
8415 /* L20: */
8416 	}
8417     }
8418     return 0;
8419 
8420 /*     End of DLABRD */
8421 
8422 } /* dlabrd_ */
8423 
dlacpy_(char * uplo,integer * m,integer * n,doublereal * a,integer * lda,doublereal * b,integer * ldb)8424 /* Subroutine */ int dlacpy_(char *uplo, integer *m, integer *n, doublereal *
8425 	a, integer *lda, doublereal *b, integer *ldb)
8426 {
8427     /* System generated locals */
8428     integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2;
8429 
8430     /* Local variables */
8431     static integer i__, j;
8432     extern logical lsame_(char *, char *);
8433 
8434 
8435 /*
8436     -- LAPACK auxiliary routine (version 3.2) --
8437     -- LAPACK is a software package provided by Univ. of Tennessee,    --
8438     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
8439        November 2006
8440 
8441 
8442     Purpose
8443     =======
8444 
8445     DLACPY copies all or part of a two-dimensional matrix A to another
8446     matrix B.
8447 
8448     Arguments
8449     =========
8450 
8451     UPLO    (input) CHARACTER*1
8452             Specifies the part of the matrix A to be copied to B.
8453             = 'U':      Upper triangular part
8454             = 'L':      Lower triangular part
8455             Otherwise:  All of the matrix A
8456 
8457     M       (input) INTEGER
8458             The number of rows of the matrix A.  M >= 0.
8459 
8460     N       (input) INTEGER
8461             The number of columns of the matrix A.  N >= 0.
8462 
8463     A       (input) DOUBLE PRECISION array, dimension (LDA,N)
8464             The m by n matrix A.  If UPLO = 'U', only the upper triangle
8465             or trapezoid is accessed; if UPLO = 'L', only the lower
8466             triangle or trapezoid is accessed.
8467 
8468     LDA     (input) INTEGER
8469             The leading dimension of the array A.  LDA >= max(1,M).
8470 
8471     B       (output) DOUBLE PRECISION array, dimension (LDB,N)
8472             On exit, B = A in the locations specified by UPLO.
8473 
8474     LDB     (input) INTEGER
8475             The leading dimension of the array B.  LDB >= max(1,M).
8476 
8477     =====================================================================
8478 */
8479 
8480 
8481     /* Parameter adjustments */
8482     a_dim1 = *lda;
8483     a_offset = 1 + a_dim1;
8484     a -= a_offset;
8485     b_dim1 = *ldb;
8486     b_offset = 1 + b_dim1;
8487     b -= b_offset;
8488 
8489     /* Function Body */
8490     if (lsame_(uplo, "U")) {
8491 	i__1 = *n;
8492 	for (j = 1; j <= i__1; ++j) {
8493 	    i__2 = min(j,*m);
8494 	    for (i__ = 1; i__ <= i__2; ++i__) {
8495 		b[i__ + j * b_dim1] = a[i__ + j * a_dim1];
8496 /* L10: */
8497 	    }
8498 /* L20: */
8499 	}
8500     } else if (lsame_(uplo, "L")) {
8501 	i__1 = *n;
8502 	for (j = 1; j <= i__1; ++j) {
8503 	    i__2 = *m;
8504 	    for (i__ = j; i__ <= i__2; ++i__) {
8505 		b[i__ + j * b_dim1] = a[i__ + j * a_dim1];
8506 /* L30: */
8507 	    }
8508 /* L40: */
8509 	}
8510     } else {
8511 	i__1 = *n;
8512 	for (j = 1; j <= i__1; ++j) {
8513 	    i__2 = *m;
8514 	    for (i__ = 1; i__ <= i__2; ++i__) {
8515 		b[i__ + j * b_dim1] = a[i__ + j * a_dim1];
8516 /* L50: */
8517 	    }
8518 /* L60: */
8519 	}
8520     }
8521     return 0;
8522 
8523 /*     End of DLACPY */
8524 
8525 } /* dlacpy_ */
8526 
dladiv_(doublereal * a,doublereal * b,doublereal * c__,doublereal * d__,doublereal * p,doublereal * q)8527 /* Subroutine */ int dladiv_(doublereal *a, doublereal *b, doublereal *c__,
8528 	doublereal *d__, doublereal *p, doublereal *q)
8529 {
8530     static doublereal e, f;
8531 
8532 
8533 /*
8534     -- LAPACK auxiliary routine (version 3.2) --
8535     -- LAPACK is a software package provided by Univ. of Tennessee,    --
8536     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
8537        November 2006
8538 
8539 
8540     Purpose
8541     =======
8542 
8543     DLADIV performs complex division in  real arithmetic
8544 
8545                           a + i*b
8546                p + i*q = ---------
8547                           c + i*d
8548 
8549     The algorithm is due to Robert L. Smith and can be found
8550     in D. Knuth, The art of Computer Programming, Vol.2, p.195
8551 
8552     Arguments
8553     =========
8554 
8555     A       (input) DOUBLE PRECISION
8556     B       (input) DOUBLE PRECISION
8557     C       (input) DOUBLE PRECISION
8558     D       (input) DOUBLE PRECISION
8559             The scalars a, b, c, and d in the above expression.
8560 
8561     P       (output) DOUBLE PRECISION
8562     Q       (output) DOUBLE PRECISION
8563             The scalars p and q in the above expression.
8564 
8565     =====================================================================
8566 */
8567 
8568 
8569     if (abs(*d__) < abs(*c__)) {
8570 	e = *d__ / *c__;
8571 	f = *c__ + *d__ * e;
8572 	*p = (*a + *b * e) / f;
8573 	*q = (*b - *a * e) / f;
8574     } else {
8575 	e = *c__ / *d__;
8576 	f = *d__ + *c__ * e;
8577 	*p = (*b + *a * e) / f;
8578 	*q = (-(*a) + *b * e) / f;
8579     }
8580 
8581     return 0;
8582 
8583 /*     End of DLADIV */
8584 
8585 } /* dladiv_ */
8586 
dlae2_(doublereal * a,doublereal * b,doublereal * c__,doublereal * rt1,doublereal * rt2)8587 /* Subroutine */ int dlae2_(doublereal *a, doublereal *b, doublereal *c__,
8588 	doublereal *rt1, doublereal *rt2)
8589 {
8590     /* System generated locals */
8591     doublereal d__1;
8592 
8593     /* Local variables */
8594     static doublereal ab, df, tb, sm, rt, adf, acmn, acmx;
8595 
8596 
8597 /*
8598     -- LAPACK auxiliary routine (version 3.2) --
8599     -- LAPACK is a software package provided by Univ. of Tennessee,    --
8600     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
8601        November 2006
8602 
8603 
8604     Purpose
8605     =======
8606 
8607     DLAE2  computes the eigenvalues of a 2-by-2 symmetric matrix
8608        [  A   B  ]
8609        [  B   C  ].
8610     On return, RT1 is the eigenvalue of larger absolute value, and RT2
8611     is the eigenvalue of smaller absolute value.
8612 
8613     Arguments
8614     =========
8615 
8616     A       (input) DOUBLE PRECISION
8617             The (1,1) element of the 2-by-2 matrix.
8618 
8619     B       (input) DOUBLE PRECISION
8620             The (1,2) and (2,1) elements of the 2-by-2 matrix.
8621 
8622     C       (input) DOUBLE PRECISION
8623             The (2,2) element of the 2-by-2 matrix.
8624 
8625     RT1     (output) DOUBLE PRECISION
8626             The eigenvalue of larger absolute value.
8627 
8628     RT2     (output) DOUBLE PRECISION
8629             The eigenvalue of smaller absolute value.
8630 
8631     Further Details
8632     ===============
8633 
8634     RT1 is accurate to a few ulps barring over/underflow.
8635 
8636     RT2 may be inaccurate if there is massive cancellation in the
8637     determinant A*C-B*B; higher precision or correctly rounded or
8638     correctly truncated arithmetic would be needed to compute RT2
8639     accurately in all cases.
8640 
8641     Overflow is possible only if RT1 is within a factor of 5 of overflow.
8642     Underflow is harmless if the input data is 0 or exceeds
8643        underflow_threshold / macheps.
8644 
8645    =====================================================================
8646 
8647 
8648        Compute the eigenvalues
8649 */
8650 
8651     sm = *a + *c__;
8652     df = *a - *c__;
8653     adf = abs(df);
8654     tb = *b + *b;
8655     ab = abs(tb);
8656     if (abs(*a) > abs(*c__)) {
8657 	acmx = *a;
8658 	acmn = *c__;
8659     } else {
8660 	acmx = *c__;
8661 	acmn = *a;
8662     }
8663     if (adf > ab) {
8664 /* Computing 2nd power */
8665 	d__1 = ab / adf;
8666 	rt = adf * sqrt(d__1 * d__1 + 1.);
8667     } else if (adf < ab) {
8668 /* Computing 2nd power */
8669 	d__1 = adf / ab;
8670 	rt = ab * sqrt(d__1 * d__1 + 1.);
8671     } else {
8672 
8673 /*        Includes case AB=ADF=0 */
8674 
8675 	rt = ab * sqrt(2.);
8676     }
8677     if (sm < 0.) {
8678 	*rt1 = (sm - rt) * .5;
8679 
8680 /*
8681           Order of execution important.
8682           To get fully accurate smaller eigenvalue,
8683           next line needs to be executed in higher precision.
8684 */
8685 
8686 	*rt2 = acmx / *rt1 * acmn - *b / *rt1 * *b;
8687     } else if (sm > 0.) {
8688 	*rt1 = (sm + rt) * .5;
8689 
8690 /*
8691           Order of execution important.
8692           To get fully accurate smaller eigenvalue,
8693           next line needs to be executed in higher precision.
8694 */
8695 
8696 	*rt2 = acmx / *rt1 * acmn - *b / *rt1 * *b;
8697     } else {
8698 
8699 /*        Includes case RT1 = RT2 = 0 */
8700 
8701 	*rt1 = rt * .5;
8702 	*rt2 = rt * -.5;
8703     }
8704     return 0;
8705 
8706 /*     End of DLAE2 */
8707 
8708 } /* dlae2_ */
8709 
dlaed0_(integer * icompq,integer * qsiz,integer * n,doublereal * d__,doublereal * e,doublereal * q,integer * ldq,doublereal * qstore,integer * ldqs,doublereal * work,integer * iwork,integer * info)8710 /* Subroutine */ int dlaed0_(integer *icompq, integer *qsiz, integer *n,
8711 	doublereal *d__, doublereal *e, doublereal *q, integer *ldq,
8712 	doublereal *qstore, integer *ldqs, doublereal *work, integer *iwork,
8713 	integer *info)
8714 {
8715     /* System generated locals */
8716     integer q_dim1, q_offset, qstore_dim1, qstore_offset, i__1, i__2;
8717     doublereal d__1;
8718 
8719     /* Local variables */
8720     static integer i__, j, k, iq, lgn, msd2, smm1, spm1, spm2;
8721     static doublereal temp;
8722     static integer curr;
8723     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
8724 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
8725 	    integer *, doublereal *, doublereal *, integer *);
8726     static integer iperm;
8727     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
8728 	    doublereal *, integer *);
8729     static integer indxq, iwrem;
8730     extern /* Subroutine */ int dlaed1_(integer *, doublereal *, doublereal *,
8731 	     integer *, integer *, doublereal *, integer *, doublereal *,
8732 	    integer *, integer *);
8733     static integer iqptr;
8734     extern /* Subroutine */ int dlaed7_(integer *, integer *, integer *,
8735 	    integer *, integer *, integer *, doublereal *, doublereal *,
8736 	    integer *, integer *, doublereal *, integer *, doublereal *,
8737 	    integer *, integer *, integer *, integer *, integer *, doublereal
8738 	    *, doublereal *, integer *, integer *);
8739     static integer tlvls;
8740     extern /* Subroutine */ int dlacpy_(char *, integer *, integer *,
8741 	    doublereal *, integer *, doublereal *, integer *);
8742     static integer igivcl;
8743     extern /* Subroutine */ int xerbla_(char *, integer *);
8744     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
8745 	    integer *, integer *, ftnlen, ftnlen);
8746     static integer igivnm, submat, curprb, subpbs, igivpt;
8747     extern /* Subroutine */ int dsteqr_(char *, integer *, doublereal *,
8748 	    doublereal *, doublereal *, integer *, doublereal *, integer *);
8749     static integer curlvl, matsiz, iprmpt, smlsiz;
8750 
8751 
8752 /*
8753     -- LAPACK routine (version 3.2) --
8754     -- LAPACK is a software package provided by Univ. of Tennessee,    --
8755     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
8756        November 2006
8757 
8758 
8759     Purpose
8760     =======
8761 
8762     DLAED0 computes all eigenvalues and corresponding eigenvectors of a
8763     symmetric tridiagonal matrix using the divide and conquer method.
8764 
8765     Arguments
8766     =========
8767 
8768     ICOMPQ  (input) INTEGER
8769             = 0:  Compute eigenvalues only.
8770             = 1:  Compute eigenvectors of original dense symmetric matrix
8771                   also.  On entry, Q contains the orthogonal matrix used
8772                   to reduce the original matrix to tridiagonal form.
8773             = 2:  Compute eigenvalues and eigenvectors of tridiagonal
8774                   matrix.
8775 
8776     QSIZ   (input) INTEGER
8777            The dimension of the orthogonal matrix used to reduce
8778            the full matrix to tridiagonal form.  QSIZ >= N if ICOMPQ = 1.
8779 
8780     N      (input) INTEGER
8781            The dimension of the symmetric tridiagonal matrix.  N >= 0.
8782 
8783     D      (input/output) DOUBLE PRECISION array, dimension (N)
8784            On entry, the main diagonal of the tridiagonal matrix.
8785            On exit, its eigenvalues.
8786 
8787     E      (input) DOUBLE PRECISION array, dimension (N-1)
8788            The off-diagonal elements of the tridiagonal matrix.
8789            On exit, E has been destroyed.
8790 
8791     Q      (input/output) DOUBLE PRECISION array, dimension (LDQ, N)
8792            On entry, Q must contain an N-by-N orthogonal matrix.
8793            If ICOMPQ = 0    Q is not referenced.
8794            If ICOMPQ = 1    On entry, Q is a subset of the columns of the
8795                             orthogonal matrix used to reduce the full
8796                             matrix to tridiagonal form corresponding to
8797                             the subset of the full matrix which is being
8798                             decomposed at this time.
8799            If ICOMPQ = 2    On entry, Q will be the identity matrix.
8800                             On exit, Q contains the eigenvectors of the
8801                             tridiagonal matrix.
8802 
8803     LDQ    (input) INTEGER
8804            The leading dimension of the array Q.  If eigenvectors are
8805            desired, then  LDQ >= max(1,N).  In any case,  LDQ >= 1.
8806 
8807     QSTORE (workspace) DOUBLE PRECISION array, dimension (LDQS, N)
8808            Referenced only when ICOMPQ = 1.  Used to store parts of
8809            the eigenvector matrix when the updating matrix multiplies
8810            take place.
8811 
8812     LDQS   (input) INTEGER
8813            The leading dimension of the array QSTORE.  If ICOMPQ = 1,
8814            then  LDQS >= max(1,N).  In any case,  LDQS >= 1.
8815 
8816     WORK   (workspace) DOUBLE PRECISION array,
8817            If ICOMPQ = 0 or 1, the dimension of WORK must be at least
8818                        1 + 3*N + 2*N*lg N + 2*N**2
8819                        ( lg( N ) = smallest integer k
8820                                    such that 2^k >= N )
8821            If ICOMPQ = 2, the dimension of WORK must be at least
8822                        4*N + N**2.
8823 
8824     IWORK  (workspace) INTEGER array,
8825            If ICOMPQ = 0 or 1, the dimension of IWORK must be at least
8826                           6 + 6*N + 5*N*lg N.
8827                           ( lg( N ) = smallest integer k
8828                                       such that 2^k >= N )
8829            If ICOMPQ = 2, the dimension of IWORK must be at least
8830                           3 + 5*N.
8831 
8832     INFO   (output) INTEGER
8833             = 0:  successful exit.
8834             < 0:  if INFO = -i, the i-th argument had an illegal value.
8835             > 0:  The algorithm failed to compute an eigenvalue while
8836                   working on the submatrix lying in rows and columns
8837                   INFO/(N+1) through mod(INFO,N+1).
8838 
8839     Further Details
8840     ===============
8841 
8842     Based on contributions by
8843        Jeff Rutter, Computer Science Division, University of California
8844        at Berkeley, USA
8845 
8846     =====================================================================
8847 
8848 
8849        Test the input parameters.
8850 */
8851 
8852     /* Parameter adjustments */
8853     --d__;
8854     --e;
8855     q_dim1 = *ldq;
8856     q_offset = 1 + q_dim1;
8857     q -= q_offset;
8858     qstore_dim1 = *ldqs;
8859     qstore_offset = 1 + qstore_dim1;
8860     qstore -= qstore_offset;
8861     --work;
8862     --iwork;
8863 
8864     /* Function Body */
8865     *info = 0;
8866 
8867     if (*icompq < 0 || *icompq > 2) {
8868 	*info = -1;
8869     } else if (*icompq == 1 && *qsiz < max(0,*n)) {
8870 	*info = -2;
8871     } else if (*n < 0) {
8872 	*info = -3;
8873     } else if (*ldq < max(1,*n)) {
8874 	*info = -7;
8875     } else if (*ldqs < max(1,*n)) {
8876 	*info = -9;
8877     }
8878     if (*info != 0) {
8879 	i__1 = -(*info);
8880 	xerbla_("DLAED0", &i__1);
8881 	return 0;
8882     }
8883 
8884 /*     Quick return if possible */
8885 
8886     if (*n == 0) {
8887 	return 0;
8888     }
8889 
8890     smlsiz = ilaenv_(&c__9, "DLAED0", " ", &c__0, &c__0, &c__0, &c__0, (
8891 	    ftnlen)6, (ftnlen)1);
8892 
8893 /*
8894        Determine the size and placement of the submatrices, and save in
8895        the leading elements of IWORK.
8896 */
8897 
8898     iwork[1] = *n;
8899     subpbs = 1;
8900     tlvls = 0;
8901 L10:
8902     if (iwork[subpbs] > smlsiz) {
8903 	for (j = subpbs; j >= 1; --j) {
8904 	    iwork[j * 2] = (iwork[j] + 1) / 2;
8905 	    iwork[(j << 1) - 1] = iwork[j] / 2;
8906 /* L20: */
8907 	}
8908 	++tlvls;
8909 	subpbs <<= 1;
8910 	goto L10;
8911     }
8912     i__1 = subpbs;
8913     for (j = 2; j <= i__1; ++j) {
8914 	iwork[j] += iwork[j - 1];
8915 /* L30: */
8916     }
8917 
8918 /*
8919        Divide the matrix into SUBPBS submatrices of size at most SMLSIZ+1
8920        using rank-1 modifications (cuts).
8921 */
8922 
8923     spm1 = subpbs - 1;
8924     i__1 = spm1;
8925     for (i__ = 1; i__ <= i__1; ++i__) {
8926 	submat = iwork[i__] + 1;
8927 	smm1 = submat - 1;
8928 	d__[smm1] -= (d__1 = e[smm1], abs(d__1));
8929 	d__[submat] -= (d__1 = e[smm1], abs(d__1));
8930 /* L40: */
8931     }
8932 
8933     indxq = (*n << 2) + 3;
8934     if (*icompq != 2) {
8935 
8936 /*
8937           Set up workspaces for eigenvalues only/accumulate new vectors
8938           routine
8939 */
8940 
8941 	temp = log((doublereal) (*n)) / log(2.);
8942 	lgn = (integer) temp;
8943 	if (pow_ii(&c__2, &lgn) < *n) {
8944 	    ++lgn;
8945 	}
8946 	if (pow_ii(&c__2, &lgn) < *n) {
8947 	    ++lgn;
8948 	}
8949 	iprmpt = indxq + *n + 1;
8950 	iperm = iprmpt + *n * lgn;
8951 	iqptr = iperm + *n * lgn;
8952 	igivpt = iqptr + *n + 2;
8953 	igivcl = igivpt + *n * lgn;
8954 
8955 	igivnm = 1;
8956 	iq = igivnm + (*n << 1) * lgn;
8957 /* Computing 2nd power */
8958 	i__1 = *n;
8959 	iwrem = iq + i__1 * i__1 + 1;
8960 
8961 /*        Initialize pointers */
8962 
8963 	i__1 = subpbs;
8964 	for (i__ = 0; i__ <= i__1; ++i__) {
8965 	    iwork[iprmpt + i__] = 1;
8966 	    iwork[igivpt + i__] = 1;
8967 /* L50: */
8968 	}
8969 	iwork[iqptr] = 1;
8970     }
8971 
8972 /*
8973        Solve each submatrix eigenproblem at the bottom of the divide and
8974        conquer tree.
8975 */
8976 
8977     curr = 0;
8978     i__1 = spm1;
8979     for (i__ = 0; i__ <= i__1; ++i__) {
8980 	if (i__ == 0) {
8981 	    submat = 1;
8982 	    matsiz = iwork[1];
8983 	} else {
8984 	    submat = iwork[i__] + 1;
8985 	    matsiz = iwork[i__ + 1] - iwork[i__];
8986 	}
8987 	if (*icompq == 2) {
8988 	    dsteqr_("I", &matsiz, &d__[submat], &e[submat], &q[submat +
8989 		    submat * q_dim1], ldq, &work[1], info);
8990 	    if (*info != 0) {
8991 		goto L130;
8992 	    }
8993 	} else {
8994 	    dsteqr_("I", &matsiz, &d__[submat], &e[submat], &work[iq - 1 +
8995 		    iwork[iqptr + curr]], &matsiz, &work[1], info);
8996 	    if (*info != 0) {
8997 		goto L130;
8998 	    }
8999 	    if (*icompq == 1) {
9000 		dgemm_("N", "N", qsiz, &matsiz, &matsiz, &c_b15, &q[submat *
9001 			q_dim1 + 1], ldq, &work[iq - 1 + iwork[iqptr + curr]],
9002 			 &matsiz, &c_b29, &qstore[submat * qstore_dim1 + 1],
9003 			ldqs);
9004 	    }
9005 /* Computing 2nd power */
9006 	    i__2 = matsiz;
9007 	    iwork[iqptr + curr + 1] = iwork[iqptr + curr] + i__2 * i__2;
9008 	    ++curr;
9009 	}
9010 	k = 1;
9011 	i__2 = iwork[i__ + 1];
9012 	for (j = submat; j <= i__2; ++j) {
9013 	    iwork[indxq + j] = k;
9014 	    ++k;
9015 /* L60: */
9016 	}
9017 /* L70: */
9018     }
9019 
9020 /*
9021        Successively merge eigensystems of adjacent submatrices
9022        into eigensystem for the corresponding larger matrix.
9023 
9024        while ( SUBPBS > 1 )
9025 */
9026 
9027     curlvl = 1;
9028 L80:
9029     if (subpbs > 1) {
9030 	spm2 = subpbs - 2;
9031 	i__1 = spm2;
9032 	for (i__ = 0; i__ <= i__1; i__ += 2) {
9033 	    if (i__ == 0) {
9034 		submat = 1;
9035 		matsiz = iwork[2];
9036 		msd2 = iwork[1];
9037 		curprb = 0;
9038 	    } else {
9039 		submat = iwork[i__] + 1;
9040 		matsiz = iwork[i__ + 2] - iwork[i__];
9041 		msd2 = matsiz / 2;
9042 		++curprb;
9043 	    }
9044 
9045 /*
9046        Merge lower order eigensystems (of size MSD2 and MATSIZ - MSD2)
9047        into an eigensystem of size MATSIZ.
9048        DLAED1 is used only for the full eigensystem of a tridiagonal
9049        matrix.
9050        DLAED7 handles the cases in which eigenvalues only or eigenvalues
9051        and eigenvectors of a full symmetric matrix (which was reduced to
9052        tridiagonal form) are desired.
9053 */
9054 
9055 	    if (*icompq == 2) {
9056 		dlaed1_(&matsiz, &d__[submat], &q[submat + submat * q_dim1],
9057 			ldq, &iwork[indxq + submat], &e[submat + msd2 - 1], &
9058 			msd2, &work[1], &iwork[subpbs + 1], info);
9059 	    } else {
9060 		dlaed7_(icompq, &matsiz, qsiz, &tlvls, &curlvl, &curprb, &d__[
9061 			submat], &qstore[submat * qstore_dim1 + 1], ldqs, &
9062 			iwork[indxq + submat], &e[submat + msd2 - 1], &msd2, &
9063 			work[iq], &iwork[iqptr], &iwork[iprmpt], &iwork[iperm]
9064 			, &iwork[igivpt], &iwork[igivcl], &work[igivnm], &
9065 			work[iwrem], &iwork[subpbs + 1], info);
9066 	    }
9067 	    if (*info != 0) {
9068 		goto L130;
9069 	    }
9070 	    iwork[i__ / 2 + 1] = iwork[i__ + 2];
9071 /* L90: */
9072 	}
9073 	subpbs /= 2;
9074 	++curlvl;
9075 	goto L80;
9076     }
9077 
9078 /*
9079        end while
9080 
9081        Re-merge the eigenvalues/vectors which were deflated at the final
9082        merge step.
9083 */
9084 
9085     if (*icompq == 1) {
9086 	i__1 = *n;
9087 	for (i__ = 1; i__ <= i__1; ++i__) {
9088 	    j = iwork[indxq + i__];
9089 	    work[i__] = d__[j];
9090 	    dcopy_(qsiz, &qstore[j * qstore_dim1 + 1], &c__1, &q[i__ * q_dim1
9091 		    + 1], &c__1);
9092 /* L100: */
9093 	}
9094 	dcopy_(n, &work[1], &c__1, &d__[1], &c__1);
9095     } else if (*icompq == 2) {
9096 	i__1 = *n;
9097 	for (i__ = 1; i__ <= i__1; ++i__) {
9098 	    j = iwork[indxq + i__];
9099 	    work[i__] = d__[j];
9100 	    dcopy_(n, &q[j * q_dim1 + 1], &c__1, &work[*n * i__ + 1], &c__1);
9101 /* L110: */
9102 	}
9103 	dcopy_(n, &work[1], &c__1, &d__[1], &c__1);
9104 	dlacpy_("A", n, n, &work[*n + 1], n, &q[q_offset], ldq);
9105     } else {
9106 	i__1 = *n;
9107 	for (i__ = 1; i__ <= i__1; ++i__) {
9108 	    j = iwork[indxq + i__];
9109 	    work[i__] = d__[j];
9110 /* L120: */
9111 	}
9112 	dcopy_(n, &work[1], &c__1, &d__[1], &c__1);
9113     }
9114     goto L140;
9115 
9116 L130:
9117     *info = submat * (*n + 1) + submat + matsiz - 1;
9118 
9119 L140:
9120     return 0;
9121 
9122 /*     End of DLAED0 */
9123 
9124 } /* dlaed0_ */
9125 
dlaed1_(integer * n,doublereal * d__,doublereal * q,integer * ldq,integer * indxq,doublereal * rho,integer * cutpnt,doublereal * work,integer * iwork,integer * info)9126 /* Subroutine */ int dlaed1_(integer *n, doublereal *d__, doublereal *q,
9127 	integer *ldq, integer *indxq, doublereal *rho, integer *cutpnt,
9128 	doublereal *work, integer *iwork, integer *info)
9129 {
9130     /* System generated locals */
9131     integer q_dim1, q_offset, i__1, i__2;
9132 
9133     /* Local variables */
9134     static integer i__, k, n1, n2, is, iw, iz, iq2, zpp1, indx, indxc;
9135     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
9136 	    doublereal *, integer *);
9137     static integer indxp;
9138     extern /* Subroutine */ int dlaed2_(integer *, integer *, integer *,
9139 	    doublereal *, doublereal *, integer *, integer *, doublereal *,
9140 	    doublereal *, doublereal *, doublereal *, doublereal *, integer *,
9141 	     integer *, integer *, integer *, integer *), dlaed3_(integer *,
9142 	    integer *, integer *, doublereal *, doublereal *, integer *,
9143 	    doublereal *, doublereal *, doublereal *, integer *, integer *,
9144 	    doublereal *, doublereal *, integer *);
9145     static integer idlmda;
9146     extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *,
9147 	    integer *, integer *, integer *), xerbla_(char *, integer *);
9148     static integer coltyp;
9149 
9150 
9151 /*
9152     -- LAPACK routine (version 3.2) --
9153     -- LAPACK is a software package provided by Univ. of Tennessee,    --
9154     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
9155        November 2006
9156 
9157 
9158     Purpose
9159     =======
9160 
9161     DLAED1 computes the updated eigensystem of a diagonal
9162     matrix after modification by a rank-one symmetric matrix.  This
9163     routine is used only for the eigenproblem which requires all
9164     eigenvalues and eigenvectors of a tridiagonal matrix.  DLAED7 handles
9165     the case in which eigenvalues only or eigenvalues and eigenvectors
9166     of a full symmetric matrix (which was reduced to tridiagonal form)
9167     are desired.
9168 
9169       T = Q(in) ( D(in) + RHO * Z*Z' ) Q'(in) = Q(out) * D(out) * Q'(out)
9170 
9171        where Z = Q'u, u is a vector of length N with ones in the
9172        CUTPNT and CUTPNT + 1 th elements and zeros elsewhere.
9173 
9174        The eigenvectors of the original matrix are stored in Q, and the
9175        eigenvalues are in D.  The algorithm consists of three stages:
9176 
9177           The first stage consists of deflating the size of the problem
9178           when there are multiple eigenvalues or if there is a zero in
9179           the Z vector.  For each such occurence the dimension of the
9180           secular equation problem is reduced by one.  This stage is
9181           performed by the routine DLAED2.
9182 
9183           The second stage consists of calculating the updated
9184           eigenvalues. This is done by finding the roots of the secular
9185           equation via the routine DLAED4 (as called by DLAED3).
9186           This routine also calculates the eigenvectors of the current
9187           problem.
9188 
9189           The final stage consists of computing the updated eigenvectors
9190           directly using the updated eigenvalues.  The eigenvectors for
9191           the current problem are multiplied with the eigenvectors from
9192           the overall problem.
9193 
9194     Arguments
9195     =========
9196 
9197     N      (input) INTEGER
9198            The dimension of the symmetric tridiagonal matrix.  N >= 0.
9199 
9200     D      (input/output) DOUBLE PRECISION array, dimension (N)
9201            On entry, the eigenvalues of the rank-1-perturbed matrix.
9202            On exit, the eigenvalues of the repaired matrix.
9203 
9204     Q      (input/output) DOUBLE PRECISION array, dimension (LDQ,N)
9205            On entry, the eigenvectors of the rank-1-perturbed matrix.
9206            On exit, the eigenvectors of the repaired tridiagonal matrix.
9207 
9208     LDQ    (input) INTEGER
9209            The leading dimension of the array Q.  LDQ >= max(1,N).
9210 
9211     INDXQ  (input/output) INTEGER array, dimension (N)
9212            On entry, the permutation which separately sorts the two
9213            subproblems in D into ascending order.
9214            On exit, the permutation which will reintegrate the
9215            subproblems back into sorted order,
9216            i.e. D( INDXQ( I = 1, N ) ) will be in ascending order.
9217 
9218     RHO    (input) DOUBLE PRECISION
9219            The subdiagonal entry used to create the rank-1 modification.
9220 
9221     CUTPNT (input) INTEGER
9222            The location of the last eigenvalue in the leading sub-matrix.
9223            min(1,N) <= CUTPNT <= N/2.
9224 
9225     WORK   (workspace) DOUBLE PRECISION array, dimension (4*N + N**2)
9226 
9227     IWORK  (workspace) INTEGER array, dimension (4*N)
9228 
9229     INFO   (output) INTEGER
9230             = 0:  successful exit.
9231             < 0:  if INFO = -i, the i-th argument had an illegal value.
9232             > 0:  if INFO = 1, an eigenvalue did not converge
9233 
9234     Further Details
9235     ===============
9236 
9237     Based on contributions by
9238        Jeff Rutter, Computer Science Division, University of California
9239        at Berkeley, USA
9240     Modified by Francoise Tisseur, University of Tennessee.
9241 
9242     =====================================================================
9243 
9244 
9245        Test the input parameters.
9246 */
9247 
9248     /* Parameter adjustments */
9249     --d__;
9250     q_dim1 = *ldq;
9251     q_offset = 1 + q_dim1;
9252     q -= q_offset;
9253     --indxq;
9254     --work;
9255     --iwork;
9256 
9257     /* Function Body */
9258     *info = 0;
9259 
9260     if (*n < 0) {
9261 	*info = -1;
9262     } else if (*ldq < max(1,*n)) {
9263 	*info = -4;
9264     } else /* if(complicated condition) */ {
9265 /* Computing MIN */
9266 	i__1 = 1, i__2 = *n / 2;
9267 	if (min(i__1,i__2) > *cutpnt || *n / 2 < *cutpnt) {
9268 	    *info = -7;
9269 	}
9270     }
9271     if (*info != 0) {
9272 	i__1 = -(*info);
9273 	xerbla_("DLAED1", &i__1);
9274 	return 0;
9275     }
9276 
9277 /*     Quick return if possible */
9278 
9279     if (*n == 0) {
9280 	return 0;
9281     }
9282 
9283 /*
9284        The following values are integer pointers which indicate
9285        the portion of the workspace
9286        used by a particular array in DLAED2 and DLAED3.
9287 */
9288 
9289     iz = 1;
9290     idlmda = iz + *n;
9291     iw = idlmda + *n;
9292     iq2 = iw + *n;
9293 
9294     indx = 1;
9295     indxc = indx + *n;
9296     coltyp = indxc + *n;
9297     indxp = coltyp + *n;
9298 
9299 
9300 /*
9301        Form the z-vector which consists of the last row of Q_1 and the
9302        first row of Q_2.
9303 */
9304 
9305     dcopy_(cutpnt, &q[*cutpnt + q_dim1], ldq, &work[iz], &c__1);
9306     zpp1 = *cutpnt + 1;
9307     i__1 = *n - *cutpnt;
9308     dcopy_(&i__1, &q[zpp1 + zpp1 * q_dim1], ldq, &work[iz + *cutpnt], &c__1);
9309 
9310 /*     Deflate eigenvalues. */
9311 
9312     dlaed2_(&k, n, cutpnt, &d__[1], &q[q_offset], ldq, &indxq[1], rho, &work[
9313 	    iz], &work[idlmda], &work[iw], &work[iq2], &iwork[indx], &iwork[
9314 	    indxc], &iwork[indxp], &iwork[coltyp], info);
9315 
9316     if (*info != 0) {
9317 	goto L20;
9318     }
9319 
9320 /*     Solve Secular Equation. */
9321 
9322     if (k != 0) {
9323 	is = (iwork[coltyp] + iwork[coltyp + 1]) * *cutpnt + (iwork[coltyp +
9324 		1] + iwork[coltyp + 2]) * (*n - *cutpnt) + iq2;
9325 	dlaed3_(&k, n, cutpnt, &d__[1], &q[q_offset], ldq, rho, &work[idlmda],
9326 		 &work[iq2], &iwork[indxc], &iwork[coltyp], &work[iw], &work[
9327 		is], info);
9328 	if (*info != 0) {
9329 	    goto L20;
9330 	}
9331 
9332 /*     Prepare the INDXQ sorting permutation. */
9333 
9334 	n1 = k;
9335 	n2 = *n - k;
9336 	dlamrg_(&n1, &n2, &d__[1], &c__1, &c_n1, &indxq[1]);
9337     } else {
9338 	i__1 = *n;
9339 	for (i__ = 1; i__ <= i__1; ++i__) {
9340 	    indxq[i__] = i__;
9341 /* L10: */
9342 	}
9343     }
9344 
9345 L20:
9346     return 0;
9347 
9348 /*     End of DLAED1 */
9349 
9350 } /* dlaed1_ */
9351 
dlaed2_(integer * k,integer * n,integer * n1,doublereal * d__,doublereal * q,integer * ldq,integer * indxq,doublereal * rho,doublereal * z__,doublereal * dlamda,doublereal * w,doublereal * q2,integer * indx,integer * indxc,integer * indxp,integer * coltyp,integer * info)9352 /* Subroutine */ int dlaed2_(integer *k, integer *n, integer *n1, doublereal *
9353 	d__, doublereal *q, integer *ldq, integer *indxq, doublereal *rho,
9354 	doublereal *z__, doublereal *dlamda, doublereal *w, doublereal *q2,
9355 	integer *indx, integer *indxc, integer *indxp, integer *coltyp,
9356 	integer *info)
9357 {
9358     /* System generated locals */
9359     integer q_dim1, q_offset, i__1, i__2;
9360     doublereal d__1, d__2, d__3, d__4;
9361 
9362     /* Local variables */
9363     static doublereal c__;
9364     static integer i__, j;
9365     static doublereal s, t;
9366     static integer k2, n2, ct, nj, pj, js, iq1, iq2, n1p1;
9367     static doublereal eps, tau, tol;
9368     static integer psm[4], imax, jmax;
9369     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
9370 	    doublereal *, integer *, doublereal *, doublereal *);
9371     static integer ctot[4];
9372     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
9373 	    integer *), dcopy_(integer *, doublereal *, integer *, doublereal
9374 	    *, integer *);
9375 
9376     extern integer idamax_(integer *, doublereal *, integer *);
9377     extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *,
9378 	    integer *, integer *, integer *), dlacpy_(char *, integer *,
9379 	    integer *, doublereal *, integer *, doublereal *, integer *), xerbla_(char *, integer *);
9380 
9381 
9382 /*
9383     -- LAPACK routine (version 3.2) --
9384     -- LAPACK is a software package provided by Univ. of Tennessee,    --
9385     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
9386        November 2006
9387 
9388 
9389     Purpose
9390     =======
9391 
9392     DLAED2 merges the two sets of eigenvalues together into a single
9393     sorted set.  Then it tries to deflate the size of the problem.
9394     There are two ways in which deflation can occur:  when two or more
9395     eigenvalues are close together or if there is a tiny entry in the
9396     Z vector.  For each such occurrence the order of the related secular
9397     equation problem is reduced by one.
9398 
9399     Arguments
9400     =========
9401 
9402     K      (output) INTEGER
9403            The number of non-deflated eigenvalues, and the order of the
9404            related secular equation. 0 <= K <=N.
9405 
9406     N      (input) INTEGER
9407            The dimension of the symmetric tridiagonal matrix.  N >= 0.
9408 
9409     N1     (input) INTEGER
9410            The location of the last eigenvalue in the leading sub-matrix.
9411            min(1,N) <= N1 <= N/2.
9412 
9413     D      (input/output) DOUBLE PRECISION array, dimension (N)
9414            On entry, D contains the eigenvalues of the two submatrices to
9415            be combined.
9416            On exit, D contains the trailing (N-K) updated eigenvalues
9417            (those which were deflated) sorted into increasing order.
9418 
9419     Q      (input/output) DOUBLE PRECISION array, dimension (LDQ, N)
9420            On entry, Q contains the eigenvectors of two submatrices in
9421            the two square blocks with corners at (1,1), (N1,N1)
9422            and (N1+1, N1+1), (N,N).
9423            On exit, Q contains the trailing (N-K) updated eigenvectors
9424            (those which were deflated) in its last N-K columns.
9425 
9426     LDQ    (input) INTEGER
9427            The leading dimension of the array Q.  LDQ >= max(1,N).
9428 
9429     INDXQ  (input/output) INTEGER array, dimension (N)
9430            The permutation which separately sorts the two sub-problems
9431            in D into ascending order.  Note that elements in the second
9432            half of this permutation must first have N1 added to their
9433            values. Destroyed on exit.
9434 
9435     RHO    (input/output) DOUBLE PRECISION
9436            On entry, the off-diagonal element associated with the rank-1
9437            cut which originally split the two submatrices which are now
9438            being recombined.
9439            On exit, RHO has been modified to the value required by
9440            DLAED3.
9441 
9442     Z      (input) DOUBLE PRECISION array, dimension (N)
9443            On entry, Z contains the updating vector (the last
9444            row of the first sub-eigenvector matrix and the first row of
9445            the second sub-eigenvector matrix).
9446            On exit, the contents of Z have been destroyed by the updating
9447            process.
9448 
9449     DLAMDA (output) DOUBLE PRECISION array, dimension (N)
9450            A copy of the first K eigenvalues which will be used by
9451            DLAED3 to form the secular equation.
9452 
9453     W      (output) DOUBLE PRECISION array, dimension (N)
9454            The first k values of the final deflation-altered z-vector
9455            which will be passed to DLAED3.
9456 
9457     Q2     (output) DOUBLE PRECISION array, dimension (N1**2+(N-N1)**2)
9458            A copy of the first K eigenvectors which will be used by
9459            DLAED3 in a matrix multiply (DGEMM) to solve for the new
9460            eigenvectors.
9461 
9462     INDX   (workspace) INTEGER array, dimension (N)
9463            The permutation used to sort the contents of DLAMDA into
9464            ascending order.
9465 
9466     INDXC  (output) INTEGER array, dimension (N)
9467            The permutation used to arrange the columns of the deflated
9468            Q matrix into three groups:  the first group contains non-zero
9469            elements only at and above N1, the second contains
9470            non-zero elements only below N1, and the third is dense.
9471 
9472     INDXP  (workspace) INTEGER array, dimension (N)
9473            The permutation used to place deflated values of D at the end
9474            of the array.  INDXP(1:K) points to the nondeflated D-values
9475            and INDXP(K+1:N) points to the deflated eigenvalues.
9476 
9477     COLTYP (workspace/output) INTEGER array, dimension (N)
9478            During execution, a label which will indicate which of the
9479            following types a column in the Q2 matrix is:
9480            1 : non-zero in the upper half only;
9481            2 : dense;
9482            3 : non-zero in the lower half only;
9483            4 : deflated.
9484            On exit, COLTYP(i) is the number of columns of type i,
9485            for i=1 to 4 only.
9486 
9487     INFO   (output) INTEGER
9488             = 0:  successful exit.
9489             < 0:  if INFO = -i, the i-th argument had an illegal value.
9490 
9491     Further Details
9492     ===============
9493 
9494     Based on contributions by
9495        Jeff Rutter, Computer Science Division, University of California
9496        at Berkeley, USA
9497     Modified by Francoise Tisseur, University of Tennessee.
9498 
9499     =====================================================================
9500 
9501 
9502        Test the input parameters.
9503 */
9504 
9505     /* Parameter adjustments */
9506     --d__;
9507     q_dim1 = *ldq;
9508     q_offset = 1 + q_dim1;
9509     q -= q_offset;
9510     --indxq;
9511     --z__;
9512     --dlamda;
9513     --w;
9514     --q2;
9515     --indx;
9516     --indxc;
9517     --indxp;
9518     --coltyp;
9519 
9520     /* Function Body */
9521     *info = 0;
9522 
9523     if (*n < 0) {
9524 	*info = -2;
9525     } else if (*ldq < max(1,*n)) {
9526 	*info = -6;
9527     } else /* if(complicated condition) */ {
9528 /* Computing MIN */
9529 	i__1 = 1, i__2 = *n / 2;
9530 	if (min(i__1,i__2) > *n1 || *n / 2 < *n1) {
9531 	    *info = -3;
9532 	}
9533     }
9534     if (*info != 0) {
9535 	i__1 = -(*info);
9536 	xerbla_("DLAED2", &i__1);
9537 	return 0;
9538     }
9539 
9540 /*     Quick return if possible */
9541 
9542     if (*n == 0) {
9543 	return 0;
9544     }
9545 
9546     n2 = *n - *n1;
9547     n1p1 = *n1 + 1;
9548 
9549     if (*rho < 0.) {
9550 	dscal_(&n2, &c_b151, &z__[n1p1], &c__1);
9551     }
9552 
9553 /*
9554        Normalize z so that norm(z) = 1.  Since z is the concatenation of
9555        two normalized vectors, norm2(z) = sqrt(2).
9556 */
9557 
9558     t = 1. / sqrt(2.);
9559     dscal_(n, &t, &z__[1], &c__1);
9560 
9561 /*     RHO = ABS( norm(z)**2 * RHO ) */
9562 
9563     *rho = (d__1 = *rho * 2., abs(d__1));
9564 
9565 /*     Sort the eigenvalues into increasing order */
9566 
9567     i__1 = *n;
9568     for (i__ = n1p1; i__ <= i__1; ++i__) {
9569 	indxq[i__] += *n1;
9570 /* L10: */
9571     }
9572 
9573 /*     re-integrate the deflated parts from the last pass */
9574 
9575     i__1 = *n;
9576     for (i__ = 1; i__ <= i__1; ++i__) {
9577 	dlamda[i__] = d__[indxq[i__]];
9578 /* L20: */
9579     }
9580     dlamrg_(n1, &n2, &dlamda[1], &c__1, &c__1, &indxc[1]);
9581     i__1 = *n;
9582     for (i__ = 1; i__ <= i__1; ++i__) {
9583 	indx[i__] = indxq[indxc[i__]];
9584 /* L30: */
9585     }
9586 
9587 /*     Calculate the allowable deflation tolerance */
9588 
9589     imax = idamax_(n, &z__[1], &c__1);
9590     jmax = idamax_(n, &d__[1], &c__1);
9591     eps = EPSILON;
9592 /* Computing MAX */
9593     d__3 = (d__1 = d__[jmax], abs(d__1)), d__4 = (d__2 = z__[imax], abs(d__2))
9594 	    ;
9595     tol = eps * 8. * max(d__3,d__4);
9596 
9597 /*
9598        If the rank-1 modifier is small enough, no more needs to be done
9599        except to reorganize Q so that its columns correspond with the
9600        elements in D.
9601 */
9602 
9603     if (*rho * (d__1 = z__[imax], abs(d__1)) <= tol) {
9604 	*k = 0;
9605 	iq2 = 1;
9606 	i__1 = *n;
9607 	for (j = 1; j <= i__1; ++j) {
9608 	    i__ = indx[j];
9609 	    dcopy_(n, &q[i__ * q_dim1 + 1], &c__1, &q2[iq2], &c__1);
9610 	    dlamda[j] = d__[i__];
9611 	    iq2 += *n;
9612 /* L40: */
9613 	}
9614 	dlacpy_("A", n, n, &q2[1], n, &q[q_offset], ldq);
9615 	dcopy_(n, &dlamda[1], &c__1, &d__[1], &c__1);
9616 	goto L190;
9617     }
9618 
9619 /*
9620        If there are multiple eigenvalues then the problem deflates.  Here
9621        the number of equal eigenvalues are found.  As each equal
9622        eigenvalue is found, an elementary reflector is computed to rotate
9623        the corresponding eigensubspace so that the corresponding
9624        components of Z are zero in this new basis.
9625 */
9626 
9627     i__1 = *n1;
9628     for (i__ = 1; i__ <= i__1; ++i__) {
9629 	coltyp[i__] = 1;
9630 /* L50: */
9631     }
9632     i__1 = *n;
9633     for (i__ = n1p1; i__ <= i__1; ++i__) {
9634 	coltyp[i__] = 3;
9635 /* L60: */
9636     }
9637 
9638 
9639     *k = 0;
9640     k2 = *n + 1;
9641     i__1 = *n;
9642     for (j = 1; j <= i__1; ++j) {
9643 	nj = indx[j];
9644 	if (*rho * (d__1 = z__[nj], abs(d__1)) <= tol) {
9645 
9646 /*           Deflate due to small z component. */
9647 
9648 	    --k2;
9649 	    coltyp[nj] = 4;
9650 	    indxp[k2] = nj;
9651 	    if (j == *n) {
9652 		goto L100;
9653 	    }
9654 	} else {
9655 	    pj = nj;
9656 	    goto L80;
9657 	}
9658 /* L70: */
9659     }
9660 L80:
9661     ++j;
9662     nj = indx[j];
9663     if (j > *n) {
9664 	goto L100;
9665     }
9666     if (*rho * (d__1 = z__[nj], abs(d__1)) <= tol) {
9667 
9668 /*        Deflate due to small z component. */
9669 
9670 	--k2;
9671 	coltyp[nj] = 4;
9672 	indxp[k2] = nj;
9673     } else {
9674 
9675 /*        Check if eigenvalues are close enough to allow deflation. */
9676 
9677 	s = z__[pj];
9678 	c__ = z__[nj];
9679 
9680 /*
9681           Find sqrt(a**2+b**2) without overflow or
9682           destructive underflow.
9683 */
9684 
9685 	tau = dlapy2_(&c__, &s);
9686 	t = d__[nj] - d__[pj];
9687 	c__ /= tau;
9688 	s = -s / tau;
9689 	if ((d__1 = t * c__ * s, abs(d__1)) <= tol) {
9690 
9691 /*           Deflation is possible. */
9692 
9693 	    z__[nj] = tau;
9694 	    z__[pj] = 0.;
9695 	    if (coltyp[nj] != coltyp[pj]) {
9696 		coltyp[nj] = 2;
9697 	    }
9698 	    coltyp[pj] = 4;
9699 	    drot_(n, &q[pj * q_dim1 + 1], &c__1, &q[nj * q_dim1 + 1], &c__1, &
9700 		    c__, &s);
9701 /* Computing 2nd power */
9702 	    d__1 = c__;
9703 /* Computing 2nd power */
9704 	    d__2 = s;
9705 	    t = d__[pj] * (d__1 * d__1) + d__[nj] * (d__2 * d__2);
9706 /* Computing 2nd power */
9707 	    d__1 = s;
9708 /* Computing 2nd power */
9709 	    d__2 = c__;
9710 	    d__[nj] = d__[pj] * (d__1 * d__1) + d__[nj] * (d__2 * d__2);
9711 	    d__[pj] = t;
9712 	    --k2;
9713 	    i__ = 1;
9714 L90:
9715 	    if (k2 + i__ <= *n) {
9716 		if (d__[pj] < d__[indxp[k2 + i__]]) {
9717 		    indxp[k2 + i__ - 1] = indxp[k2 + i__];
9718 		    indxp[k2 + i__] = pj;
9719 		    ++i__;
9720 		    goto L90;
9721 		} else {
9722 		    indxp[k2 + i__ - 1] = pj;
9723 		}
9724 	    } else {
9725 		indxp[k2 + i__ - 1] = pj;
9726 	    }
9727 	    pj = nj;
9728 	} else {
9729 	    ++(*k);
9730 	    dlamda[*k] = d__[pj];
9731 	    w[*k] = z__[pj];
9732 	    indxp[*k] = pj;
9733 	    pj = nj;
9734 	}
9735     }
9736     goto L80;
9737 L100:
9738 
9739 /*     Record the last eigenvalue. */
9740 
9741     ++(*k);
9742     dlamda[*k] = d__[pj];
9743     w[*k] = z__[pj];
9744     indxp[*k] = pj;
9745 
9746 /*
9747        Count up the total number of the various types of columns, then
9748        form a permutation which positions the four column types into
9749        four uniform groups (although one or more of these groups may be
9750        empty).
9751 */
9752 
9753     for (j = 1; j <= 4; ++j) {
9754 	ctot[j - 1] = 0;
9755 /* L110: */
9756     }
9757     i__1 = *n;
9758     for (j = 1; j <= i__1; ++j) {
9759 	ct = coltyp[j];
9760 	++ctot[ct - 1];
9761 /* L120: */
9762     }
9763 
9764 /*     PSM(*) = Position in SubMatrix (of types 1 through 4) */
9765 
9766     psm[0] = 1;
9767     psm[1] = ctot[0] + 1;
9768     psm[2] = psm[1] + ctot[1];
9769     psm[3] = psm[2] + ctot[2];
9770     *k = *n - ctot[3];
9771 
9772 /*
9773        Fill out the INDXC array so that the permutation which it induces
9774        will place all type-1 columns first, all type-2 columns next,
9775        then all type-3's, and finally all type-4's.
9776 */
9777 
9778     i__1 = *n;
9779     for (j = 1; j <= i__1; ++j) {
9780 	js = indxp[j];
9781 	ct = coltyp[js];
9782 	indx[psm[ct - 1]] = js;
9783 	indxc[psm[ct - 1]] = j;
9784 	++psm[ct - 1];
9785 /* L130: */
9786     }
9787 
9788 /*
9789        Sort the eigenvalues and corresponding eigenvectors into DLAMDA
9790        and Q2 respectively.  The eigenvalues/vectors which were not
9791        deflated go into the first K slots of DLAMDA and Q2 respectively,
9792        while those which were deflated go into the last N - K slots.
9793 */
9794 
9795     i__ = 1;
9796     iq1 = 1;
9797     iq2 = (ctot[0] + ctot[1]) * *n1 + 1;
9798     i__1 = ctot[0];
9799     for (j = 1; j <= i__1; ++j) {
9800 	js = indx[i__];
9801 	dcopy_(n1, &q[js * q_dim1 + 1], &c__1, &q2[iq1], &c__1);
9802 	z__[i__] = d__[js];
9803 	++i__;
9804 	iq1 += *n1;
9805 /* L140: */
9806     }
9807 
9808     i__1 = ctot[1];
9809     for (j = 1; j <= i__1; ++j) {
9810 	js = indx[i__];
9811 	dcopy_(n1, &q[js * q_dim1 + 1], &c__1, &q2[iq1], &c__1);
9812 	dcopy_(&n2, &q[*n1 + 1 + js * q_dim1], &c__1, &q2[iq2], &c__1);
9813 	z__[i__] = d__[js];
9814 	++i__;
9815 	iq1 += *n1;
9816 	iq2 += n2;
9817 /* L150: */
9818     }
9819 
9820     i__1 = ctot[2];
9821     for (j = 1; j <= i__1; ++j) {
9822 	js = indx[i__];
9823 	dcopy_(&n2, &q[*n1 + 1 + js * q_dim1], &c__1, &q2[iq2], &c__1);
9824 	z__[i__] = d__[js];
9825 	++i__;
9826 	iq2 += n2;
9827 /* L160: */
9828     }
9829 
9830     iq1 = iq2;
9831     i__1 = ctot[3];
9832     for (j = 1; j <= i__1; ++j) {
9833 	js = indx[i__];
9834 	dcopy_(n, &q[js * q_dim1 + 1], &c__1, &q2[iq2], &c__1);
9835 	iq2 += *n;
9836 	z__[i__] = d__[js];
9837 	++i__;
9838 /* L170: */
9839     }
9840 
9841 /*
9842        The deflated eigenvalues and their corresponding vectors go back
9843        into the last N - K slots of D and Q respectively.
9844 */
9845 
9846     dlacpy_("A", n, &ctot[3], &q2[iq1], n, &q[(*k + 1) * q_dim1 + 1], ldq);
9847     i__1 = *n - *k;
9848     dcopy_(&i__1, &z__[*k + 1], &c__1, &d__[*k + 1], &c__1);
9849 
9850 /*     Copy CTOT into COLTYP for referencing in DLAED3. */
9851 
9852     for (j = 1; j <= 4; ++j) {
9853 	coltyp[j] = ctot[j - 1];
9854 /* L180: */
9855     }
9856 
9857 L190:
9858     return 0;
9859 
9860 /*     End of DLAED2 */
9861 
9862 } /* dlaed2_ */
9863 
dlaed3_(integer * k,integer * n,integer * n1,doublereal * d__,doublereal * q,integer * ldq,doublereal * rho,doublereal * dlamda,doublereal * q2,integer * indx,integer * ctot,doublereal * w,doublereal * s,integer * info)9864 /* Subroutine */ int dlaed3_(integer *k, integer *n, integer *n1, doublereal *
9865 	d__, doublereal *q, integer *ldq, doublereal *rho, doublereal *dlamda,
9866 	 doublereal *q2, integer *indx, integer *ctot, doublereal *w,
9867 	doublereal *s, integer *info)
9868 {
9869     /* System generated locals */
9870     integer q_dim1, q_offset, i__1, i__2;
9871     doublereal d__1;
9872 
9873     /* Local variables */
9874     static integer i__, j, n2, n12, ii, n23, iq2;
9875     static doublereal temp;
9876     extern doublereal dnrm2_(integer *, doublereal *, integer *);
9877     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
9878 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
9879 	    integer *, doublereal *, doublereal *, integer *),
9880 	     dcopy_(integer *, doublereal *, integer *, doublereal *, integer
9881 	    *), dlaed4_(integer *, integer *, doublereal *, doublereal *,
9882 	    doublereal *, doublereal *, doublereal *, integer *);
9883     extern doublereal dlamc3_(doublereal *, doublereal *);
9884     extern /* Subroutine */ int dlacpy_(char *, integer *, integer *,
9885 	    doublereal *, integer *, doublereal *, integer *),
9886 	    dlaset_(char *, integer *, integer *, doublereal *, doublereal *,
9887 	    doublereal *, integer *), xerbla_(char *, integer *);
9888 
9889 
9890 /*
9891     -- LAPACK routine (version 3.2) --
9892     -- LAPACK is a software package provided by Univ. of Tennessee,    --
9893     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
9894        November 2006
9895 
9896 
9897     Purpose
9898     =======
9899 
9900     DLAED3 finds the roots of the secular equation, as defined by the
9901     values in D, W, and RHO, between 1 and K.  It makes the
9902     appropriate calls to DLAED4 and then updates the eigenvectors by
9903     multiplying the matrix of eigenvectors of the pair of eigensystems
9904     being combined by the matrix of eigenvectors of the K-by-K system
9905     which is solved here.
9906 
9907     This code makes very mild assumptions about floating point
9908     arithmetic. It will work on machines with a guard digit in
9909     add/subtract, or on those binary machines without guard digits
9910     which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or Cray-2.
9911     It could conceivably fail on hexadecimal or decimal machines
9912     without guard digits, but we know of none.
9913 
9914     Arguments
9915     =========
9916 
9917     K       (input) INTEGER
9918             The number of terms in the rational function to be solved by
9919             DLAED4.  K >= 0.
9920 
9921     N       (input) INTEGER
9922             The number of rows and columns in the Q matrix.
9923             N >= K (deflation may result in N>K).
9924 
9925     N1      (input) INTEGER
9926             The location of the last eigenvalue in the leading submatrix.
9927             min(1,N) <= N1 <= N/2.
9928 
9929     D       (output) DOUBLE PRECISION array, dimension (N)
9930             D(I) contains the updated eigenvalues for
9931             1 <= I <= K.
9932 
9933     Q       (output) DOUBLE PRECISION array, dimension (LDQ,N)
9934             Initially the first K columns are used as workspace.
9935             On output the columns 1 to K contain
9936             the updated eigenvectors.
9937 
9938     LDQ     (input) INTEGER
9939             The leading dimension of the array Q.  LDQ >= max(1,N).
9940 
9941     RHO     (input) DOUBLE PRECISION
9942             The value of the parameter in the rank one update equation.
9943             RHO >= 0 required.
9944 
9945     DLAMDA  (input/output) DOUBLE PRECISION array, dimension (K)
9946             The first K elements of this array contain the old roots
9947             of the deflated updating problem.  These are the poles
9948             of the secular equation. May be changed on output by
9949             having lowest order bit set to zero on Cray X-MP, Cray Y-MP,
9950             Cray-2, or Cray C-90, as described above.
9951 
9952     Q2      (input) DOUBLE PRECISION array, dimension (LDQ2, N)
9953             The first K columns of this matrix contain the non-deflated
9954             eigenvectors for the split problem.
9955 
9956     INDX    (input) INTEGER array, dimension (N)
9957             The permutation used to arrange the columns of the deflated
9958             Q matrix into three groups (see DLAED2).
9959             The rows of the eigenvectors found by DLAED4 must be likewise
9960             permuted before the matrix multiply can take place.
9961 
9962     CTOT    (input) INTEGER array, dimension (4)
9963             A count of the total number of the various types of columns
9964             in Q, as described in INDX.  The fourth column type is any
9965             column which has been deflated.
9966 
9967     W       (input/output) DOUBLE PRECISION array, dimension (K)
9968             The first K elements of this array contain the components
9969             of the deflation-adjusted updating vector. Destroyed on
9970             output.
9971 
9972     S       (workspace) DOUBLE PRECISION array, dimension (N1 + 1)*K
9973             Will contain the eigenvectors of the repaired matrix which
9974             will be multiplied by the previously accumulated eigenvectors
9975             to update the system.
9976 
9977     LDS     (input) INTEGER
9978             The leading dimension of S.  LDS >= max(1,K).
9979 
9980     INFO    (output) INTEGER
9981             = 0:  successful exit.
9982             < 0:  if INFO = -i, the i-th argument had an illegal value.
9983             > 0:  if INFO = 1, an eigenvalue did not converge
9984 
9985     Further Details
9986     ===============
9987 
9988     Based on contributions by
9989        Jeff Rutter, Computer Science Division, University of California
9990        at Berkeley, USA
9991     Modified by Francoise Tisseur, University of Tennessee.
9992 
9993     =====================================================================
9994 
9995 
9996        Test the input parameters.
9997 */
9998 
9999     /* Parameter adjustments */
10000     --d__;
10001     q_dim1 = *ldq;
10002     q_offset = 1 + q_dim1;
10003     q -= q_offset;
10004     --dlamda;
10005     --q2;
10006     --indx;
10007     --ctot;
10008     --w;
10009     --s;
10010 
10011     /* Function Body */
10012     *info = 0;
10013 
10014     if (*k < 0) {
10015 	*info = -1;
10016     } else if (*n < *k) {
10017 	*info = -2;
10018     } else if (*ldq < max(1,*n)) {
10019 	*info = -6;
10020     }
10021     if (*info != 0) {
10022 	i__1 = -(*info);
10023 	xerbla_("DLAED3", &i__1);
10024 	return 0;
10025     }
10026 
10027 /*     Quick return if possible */
10028 
10029     if (*k == 0) {
10030 	return 0;
10031     }
10032 
10033 /*
10034        Modify values DLAMDA(i) to make sure all DLAMDA(i)-DLAMDA(j) can
10035        be computed with high relative accuracy (barring over/underflow).
10036        This is a problem on machines without a guard digit in
10037        add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2).
10038        The following code replaces DLAMDA(I) by 2*DLAMDA(I)-DLAMDA(I),
10039        which on any of these machines zeros out the bottommost
10040        bit of DLAMDA(I) if it is 1; this makes the subsequent
10041        subtractions DLAMDA(I)-DLAMDA(J) unproblematic when cancellation
10042        occurs. On binary machines with a guard digit (almost all
10043        machines) it does not change DLAMDA(I) at all. On hexadecimal
10044        and decimal machines with a guard digit, it slightly
10045        changes the bottommost bits of DLAMDA(I). It does not account
10046        for hexadecimal or decimal machines without guard digits
10047        (we know of none). We use a subroutine call to compute
10048        2*DLAMBDA(I) to prevent optimizing compilers from eliminating
10049        this code.
10050 */
10051 
10052     i__1 = *k;
10053     for (i__ = 1; i__ <= i__1; ++i__) {
10054 	dlamda[i__] = dlamc3_(&dlamda[i__], &dlamda[i__]) - dlamda[i__];
10055 /* L10: */
10056     }
10057 
10058     i__1 = *k;
10059     for (j = 1; j <= i__1; ++j) {
10060 	dlaed4_(k, &j, &dlamda[1], &w[1], &q[j * q_dim1 + 1], rho, &d__[j],
10061 		info);
10062 
10063 /*        If the zero finder fails, the computation is terminated. */
10064 
10065 	if (*info != 0) {
10066 	    goto L120;
10067 	}
10068 /* L20: */
10069     }
10070 
10071     if (*k == 1) {
10072 	goto L110;
10073     }
10074     if (*k == 2) {
10075 	i__1 = *k;
10076 	for (j = 1; j <= i__1; ++j) {
10077 	    w[1] = q[j * q_dim1 + 1];
10078 	    w[2] = q[j * q_dim1 + 2];
10079 	    ii = indx[1];
10080 	    q[j * q_dim1 + 1] = w[ii];
10081 	    ii = indx[2];
10082 	    q[j * q_dim1 + 2] = w[ii];
10083 /* L30: */
10084 	}
10085 	goto L110;
10086     }
10087 
10088 /*     Compute updated W. */
10089 
10090     dcopy_(k, &w[1], &c__1, &s[1], &c__1);
10091 
10092 /*     Initialize W(I) = Q(I,I) */
10093 
10094     i__1 = *ldq + 1;
10095     dcopy_(k, &q[q_offset], &i__1, &w[1], &c__1);
10096     i__1 = *k;
10097     for (j = 1; j <= i__1; ++j) {
10098 	i__2 = j - 1;
10099 	for (i__ = 1; i__ <= i__2; ++i__) {
10100 	    w[i__] *= q[i__ + j * q_dim1] / (dlamda[i__] - dlamda[j]);
10101 /* L40: */
10102 	}
10103 	i__2 = *k;
10104 	for (i__ = j + 1; i__ <= i__2; ++i__) {
10105 	    w[i__] *= q[i__ + j * q_dim1] / (dlamda[i__] - dlamda[j]);
10106 /* L50: */
10107 	}
10108 /* L60: */
10109     }
10110     i__1 = *k;
10111     for (i__ = 1; i__ <= i__1; ++i__) {
10112 	d__1 = sqrt(-w[i__]);
10113 	w[i__] = d_sign(&d__1, &s[i__]);
10114 /* L70: */
10115     }
10116 
10117 /*     Compute eigenvectors of the modified rank-1 modification. */
10118 
10119     i__1 = *k;
10120     for (j = 1; j <= i__1; ++j) {
10121 	i__2 = *k;
10122 	for (i__ = 1; i__ <= i__2; ++i__) {
10123 	    s[i__] = w[i__] / q[i__ + j * q_dim1];
10124 /* L80: */
10125 	}
10126 	temp = dnrm2_(k, &s[1], &c__1);
10127 	i__2 = *k;
10128 	for (i__ = 1; i__ <= i__2; ++i__) {
10129 	    ii = indx[i__];
10130 	    q[i__ + j * q_dim1] = s[ii] / temp;
10131 /* L90: */
10132 	}
10133 /* L100: */
10134     }
10135 
10136 /*     Compute the updated eigenvectors. */
10137 
10138 L110:
10139 
10140     n2 = *n - *n1;
10141     n12 = ctot[1] + ctot[2];
10142     n23 = ctot[2] + ctot[3];
10143 
10144     dlacpy_("A", &n23, k, &q[ctot[1] + 1 + q_dim1], ldq, &s[1], &n23);
10145     iq2 = *n1 * n12 + 1;
10146     if (n23 != 0) {
10147 	dgemm_("N", "N", &n2, k, &n23, &c_b15, &q2[iq2], &n2, &s[1], &n23, &
10148 		c_b29, &q[*n1 + 1 + q_dim1], ldq);
10149     } else {
10150 	dlaset_("A", &n2, k, &c_b29, &c_b29, &q[*n1 + 1 + q_dim1], ldq);
10151     }
10152 
10153     dlacpy_("A", &n12, k, &q[q_offset], ldq, &s[1], &n12);
10154     if (n12 != 0) {
10155 	dgemm_("N", "N", n1, k, &n12, &c_b15, &q2[1], n1, &s[1], &n12, &c_b29,
10156 		 &q[q_offset], ldq);
10157     } else {
10158 	dlaset_("A", n1, k, &c_b29, &c_b29, &q[q_dim1 + 1], ldq);
10159     }
10160 
10161 
10162 L120:
10163     return 0;
10164 
10165 /*     End of DLAED3 */
10166 
10167 } /* dlaed3_ */
10168 
dlaed4_(integer * n,integer * i__,doublereal * d__,doublereal * z__,doublereal * delta,doublereal * rho,doublereal * dlam,integer * info)10169 /* Subroutine */ int dlaed4_(integer *n, integer *i__, doublereal *d__,
10170 	doublereal *z__, doublereal *delta, doublereal *rho, doublereal *dlam,
10171 	 integer *info)
10172 {
10173     /* System generated locals */
10174     integer i__1;
10175     doublereal d__1;
10176 
10177     /* Local variables */
10178     static doublereal a, b, c__;
10179     static integer j;
10180     static doublereal w;
10181     static integer ii;
10182     static doublereal dw, zz[3];
10183     static integer ip1;
10184     static doublereal del, eta, phi, eps, tau, psi;
10185     static integer iim1, iip1;
10186     static doublereal dphi, dpsi;
10187     static integer iter;
10188     static doublereal temp, prew, temp1, dltlb, dltub, midpt;
10189     static integer niter;
10190     static logical swtch;
10191     extern /* Subroutine */ int dlaed5_(integer *, doublereal *, doublereal *,
10192 	     doublereal *, doublereal *, doublereal *), dlaed6_(integer *,
10193 	    logical *, doublereal *, doublereal *, doublereal *, doublereal *,
10194 	     doublereal *, integer *);
10195     static logical swtch3;
10196 
10197     static logical orgati;
10198     static doublereal erretm, rhoinv;
10199 
10200 
10201 /*
10202     -- LAPACK routine (version 3.2) --
10203     -- LAPACK is a software package provided by Univ. of Tennessee,    --
10204     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
10205        November 2006
10206 
10207 
10208     Purpose
10209     =======
10210 
10211     This subroutine computes the I-th updated eigenvalue of a symmetric
10212     rank-one modification to a diagonal matrix whose elements are
10213     given in the array d, and that
10214 
10215                D(i) < D(j)  for  i < j
10216 
10217     and that RHO > 0.  This is arranged by the calling routine, and is
10218     no loss in generality.  The rank-one modified system is thus
10219 
10220                diag( D )  +  RHO *  Z * Z_transpose.
10221 
10222     where we assume the Euclidean norm of Z is 1.
10223 
10224     The method consists of approximating the rational functions in the
10225     secular equation by simpler interpolating rational functions.
10226 
10227     Arguments
10228     =========
10229 
10230     N      (input) INTEGER
10231            The length of all arrays.
10232 
10233     I      (input) INTEGER
10234            The index of the eigenvalue to be computed.  1 <= I <= N.
10235 
10236     D      (input) DOUBLE PRECISION array, dimension (N)
10237            The original eigenvalues.  It is assumed that they are in
10238            order, D(I) < D(J)  for I < J.
10239 
10240     Z      (input) DOUBLE PRECISION array, dimension (N)
10241            The components of the updating vector.
10242 
10243     DELTA  (output) DOUBLE PRECISION array, dimension (N)
10244            If N .GT. 2, DELTA contains (D(j) - lambda_I) in its  j-th
10245            component.  If N = 1, then DELTA(1) = 1. If N = 2, see DLAED5
10246            for detail. The vector DELTA contains the information necessary
10247            to construct the eigenvectors by DLAED3 and DLAED9.
10248 
10249     RHO    (input) DOUBLE PRECISION
10250            The scalar in the symmetric updating formula.
10251 
10252     DLAM   (output) DOUBLE PRECISION
10253            The computed lambda_I, the I-th updated eigenvalue.
10254 
10255     INFO   (output) INTEGER
10256            = 0:  successful exit
10257            > 0:  if INFO = 1, the updating process failed.
10258 
10259     Internal Parameters
10260     ===================
10261 
10262     Logical variable ORGATI (origin-at-i?) is used for distinguishing
10263     whether D(i) or D(i+1) is treated as the origin.
10264 
10265               ORGATI = .true.    origin at i
10266               ORGATI = .false.   origin at i+1
10267 
10268      Logical variable SWTCH3 (switch-for-3-poles?) is for noting
10269      if we are working with THREE poles!
10270 
10271      MAXIT is the maximum number of iterations allowed for each
10272      eigenvalue.
10273 
10274     Further Details
10275     ===============
10276 
10277     Based on contributions by
10278        Ren-Cang Li, Computer Science Division, University of California
10279        at Berkeley, USA
10280 
10281     =====================================================================
10282 
10283 
10284        Since this routine is called in an inner loop, we do no argument
10285        checking.
10286 
10287        Quick return for N=1 and 2.
10288 */
10289 
10290     /* Parameter adjustments */
10291     --delta;
10292     --z__;
10293     --d__;
10294 
10295     /* Function Body */
10296     *info = 0;
10297     if (*n == 1) {
10298 
10299 /*         Presumably, I=1 upon entry */
10300 
10301 	*dlam = d__[1] + *rho * z__[1] * z__[1];
10302 	delta[1] = 1.;
10303 	return 0;
10304     }
10305     if (*n == 2) {
10306 	dlaed5_(i__, &d__[1], &z__[1], &delta[1], rho, dlam);
10307 	return 0;
10308     }
10309 
10310 /*     Compute machine epsilon */
10311 
10312     eps = EPSILON;
10313     rhoinv = 1. / *rho;
10314 
10315 /*     The case I = N */
10316 
10317     if (*i__ == *n) {
10318 
10319 /*        Initialize some basic variables */
10320 
10321 	ii = *n - 1;
10322 	niter = 1;
10323 
10324 /*        Calculate initial guess */
10325 
10326 	midpt = *rho / 2.;
10327 
10328 /*
10329           If ||Z||_2 is not one, then TEMP should be set to
10330           RHO * ||Z||_2^2 / TWO
10331 */
10332 
10333 	i__1 = *n;
10334 	for (j = 1; j <= i__1; ++j) {
10335 	    delta[j] = d__[j] - d__[*i__] - midpt;
10336 /* L10: */
10337 	}
10338 
10339 	psi = 0.;
10340 	i__1 = *n - 2;
10341 	for (j = 1; j <= i__1; ++j) {
10342 	    psi += z__[j] * z__[j] / delta[j];
10343 /* L20: */
10344 	}
10345 
10346 	c__ = rhoinv + psi;
10347 	w = c__ + z__[ii] * z__[ii] / delta[ii] + z__[*n] * z__[*n] / delta[*
10348 		n];
10349 
10350 	if (w <= 0.) {
10351 	    temp = z__[*n - 1] * z__[*n - 1] / (d__[*n] - d__[*n - 1] + *rho)
10352 		    + z__[*n] * z__[*n] / *rho;
10353 	    if (c__ <= temp) {
10354 		tau = *rho;
10355 	    } else {
10356 		del = d__[*n] - d__[*n - 1];
10357 		a = -c__ * del + z__[*n - 1] * z__[*n - 1] + z__[*n] * z__[*n]
10358 			;
10359 		b = z__[*n] * z__[*n] * del;
10360 		if (a < 0.) {
10361 		    tau = b * 2. / (sqrt(a * a + b * 4. * c__) - a);
10362 		} else {
10363 		    tau = (a + sqrt(a * a + b * 4. * c__)) / (c__ * 2.);
10364 		}
10365 	    }
10366 
10367 /*
10368              It can be proved that
10369                  D(N)+RHO/2 <= LAMBDA(N) < D(N)+TAU <= D(N)+RHO
10370 */
10371 
10372 	    dltlb = midpt;
10373 	    dltub = *rho;
10374 	} else {
10375 	    del = d__[*n] - d__[*n - 1];
10376 	    a = -c__ * del + z__[*n - 1] * z__[*n - 1] + z__[*n] * z__[*n];
10377 	    b = z__[*n] * z__[*n] * del;
10378 	    if (a < 0.) {
10379 		tau = b * 2. / (sqrt(a * a + b * 4. * c__) - a);
10380 	    } else {
10381 		tau = (a + sqrt(a * a + b * 4. * c__)) / (c__ * 2.);
10382 	    }
10383 
10384 /*
10385              It can be proved that
10386                  D(N) < D(N)+TAU < LAMBDA(N) < D(N)+RHO/2
10387 */
10388 
10389 	    dltlb = 0.;
10390 	    dltub = midpt;
10391 	}
10392 
10393 	i__1 = *n;
10394 	for (j = 1; j <= i__1; ++j) {
10395 	    delta[j] = d__[j] - d__[*i__] - tau;
10396 /* L30: */
10397 	}
10398 
10399 /*        Evaluate PSI and the derivative DPSI */
10400 
10401 	dpsi = 0.;
10402 	psi = 0.;
10403 	erretm = 0.;
10404 	i__1 = ii;
10405 	for (j = 1; j <= i__1; ++j) {
10406 	    temp = z__[j] / delta[j];
10407 	    psi += z__[j] * temp;
10408 	    dpsi += temp * temp;
10409 	    erretm += psi;
10410 /* L40: */
10411 	}
10412 	erretm = abs(erretm);
10413 
10414 /*        Evaluate PHI and the derivative DPHI */
10415 
10416 	temp = z__[*n] / delta[*n];
10417 	phi = z__[*n] * temp;
10418 	dphi = temp * temp;
10419 	erretm = (-phi - psi) * 8. + erretm - phi + rhoinv + abs(tau) * (dpsi
10420 		+ dphi);
10421 
10422 	w = rhoinv + phi + psi;
10423 
10424 /*        Test for convergence */
10425 
10426 	if (abs(w) <= eps * erretm) {
10427 	    *dlam = d__[*i__] + tau;
10428 	    goto L250;
10429 	}
10430 
10431 	if (w <= 0.) {
10432 	    dltlb = max(dltlb,tau);
10433 	} else {
10434 	    dltub = min(dltub,tau);
10435 	}
10436 
10437 /*        Calculate the new step */
10438 
10439 	++niter;
10440 	c__ = w - delta[*n - 1] * dpsi - delta[*n] * dphi;
10441 	a = (delta[*n - 1] + delta[*n]) * w - delta[*n - 1] * delta[*n] * (
10442 		dpsi + dphi);
10443 	b = delta[*n - 1] * delta[*n] * w;
10444 	if (c__ < 0.) {
10445 	    c__ = abs(c__);
10446 	}
10447 	if (c__ == 0.) {
10448 /*
10449             ETA = B/A
10450              ETA = RHO - TAU
10451 */
10452 	    eta = dltub - tau;
10453 	} else if (a >= 0.) {
10454 	    eta = (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (c__
10455 		    * 2.);
10456 	} else {
10457 	    eta = b * 2. / (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))
10458 		    );
10459 	}
10460 
10461 /*
10462           Note, eta should be positive if w is negative, and
10463           eta should be negative otherwise. However,
10464           if for some reason caused by roundoff, eta*w > 0,
10465           we simply use one Newton step instead. This way
10466           will guarantee eta*w < 0.
10467 */
10468 
10469 	if (w * eta > 0.) {
10470 	    eta = -w / (dpsi + dphi);
10471 	}
10472 	temp = tau + eta;
10473 	if (temp > dltub || temp < dltlb) {
10474 	    if (w < 0.) {
10475 		eta = (dltub - tau) / 2.;
10476 	    } else {
10477 		eta = (dltlb - tau) / 2.;
10478 	    }
10479 	}
10480 	i__1 = *n;
10481 	for (j = 1; j <= i__1; ++j) {
10482 	    delta[j] -= eta;
10483 /* L50: */
10484 	}
10485 
10486 	tau += eta;
10487 
10488 /*        Evaluate PSI and the derivative DPSI */
10489 
10490 	dpsi = 0.;
10491 	psi = 0.;
10492 	erretm = 0.;
10493 	i__1 = ii;
10494 	for (j = 1; j <= i__1; ++j) {
10495 	    temp = z__[j] / delta[j];
10496 	    psi += z__[j] * temp;
10497 	    dpsi += temp * temp;
10498 	    erretm += psi;
10499 /* L60: */
10500 	}
10501 	erretm = abs(erretm);
10502 
10503 /*        Evaluate PHI and the derivative DPHI */
10504 
10505 	temp = z__[*n] / delta[*n];
10506 	phi = z__[*n] * temp;
10507 	dphi = temp * temp;
10508 	erretm = (-phi - psi) * 8. + erretm - phi + rhoinv + abs(tau) * (dpsi
10509 		+ dphi);
10510 
10511 	w = rhoinv + phi + psi;
10512 
10513 /*        Main loop to update the values of the array   DELTA */
10514 
10515 	iter = niter + 1;
10516 
10517 	for (niter = iter; niter <= 30; ++niter) {
10518 
10519 /*           Test for convergence */
10520 
10521 	    if (abs(w) <= eps * erretm) {
10522 		*dlam = d__[*i__] + tau;
10523 		goto L250;
10524 	    }
10525 
10526 	    if (w <= 0.) {
10527 		dltlb = max(dltlb,tau);
10528 	    } else {
10529 		dltub = min(dltub,tau);
10530 	    }
10531 
10532 /*           Calculate the new step */
10533 
10534 	    c__ = w - delta[*n - 1] * dpsi - delta[*n] * dphi;
10535 	    a = (delta[*n - 1] + delta[*n]) * w - delta[*n - 1] * delta[*n] *
10536 		    (dpsi + dphi);
10537 	    b = delta[*n - 1] * delta[*n] * w;
10538 	    if (a >= 0.) {
10539 		eta = (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
10540 			c__ * 2.);
10541 	    } else {
10542 		eta = b * 2. / (a - sqrt((d__1 = a * a - b * 4. * c__, abs(
10543 			d__1))));
10544 	    }
10545 
10546 /*
10547              Note, eta should be positive if w is negative, and
10548              eta should be negative otherwise. However,
10549              if for some reason caused by roundoff, eta*w > 0,
10550              we simply use one Newton step instead. This way
10551              will guarantee eta*w < 0.
10552 */
10553 
10554 	    if (w * eta > 0.) {
10555 		eta = -w / (dpsi + dphi);
10556 	    }
10557 	    temp = tau + eta;
10558 	    if (temp > dltub || temp < dltlb) {
10559 		if (w < 0.) {
10560 		    eta = (dltub - tau) / 2.;
10561 		} else {
10562 		    eta = (dltlb - tau) / 2.;
10563 		}
10564 	    }
10565 	    i__1 = *n;
10566 	    for (j = 1; j <= i__1; ++j) {
10567 		delta[j] -= eta;
10568 /* L70: */
10569 	    }
10570 
10571 	    tau += eta;
10572 
10573 /*           Evaluate PSI and the derivative DPSI */
10574 
10575 	    dpsi = 0.;
10576 	    psi = 0.;
10577 	    erretm = 0.;
10578 	    i__1 = ii;
10579 	    for (j = 1; j <= i__1; ++j) {
10580 		temp = z__[j] / delta[j];
10581 		psi += z__[j] * temp;
10582 		dpsi += temp * temp;
10583 		erretm += psi;
10584 /* L80: */
10585 	    }
10586 	    erretm = abs(erretm);
10587 
10588 /*           Evaluate PHI and the derivative DPHI */
10589 
10590 	    temp = z__[*n] / delta[*n];
10591 	    phi = z__[*n] * temp;
10592 	    dphi = temp * temp;
10593 	    erretm = (-phi - psi) * 8. + erretm - phi + rhoinv + abs(tau) * (
10594 		    dpsi + dphi);
10595 
10596 	    w = rhoinv + phi + psi;
10597 /* L90: */
10598 	}
10599 
10600 /*        Return with INFO = 1, NITER = MAXIT and not converged */
10601 
10602 	*info = 1;
10603 	*dlam = d__[*i__] + tau;
10604 	goto L250;
10605 
10606 /*        End for the case I = N */
10607 
10608     } else {
10609 
10610 /*        The case for I < N */
10611 
10612 	niter = 1;
10613 	ip1 = *i__ + 1;
10614 
10615 /*        Calculate initial guess */
10616 
10617 	del = d__[ip1] - d__[*i__];
10618 	midpt = del / 2.;
10619 	i__1 = *n;
10620 	for (j = 1; j <= i__1; ++j) {
10621 	    delta[j] = d__[j] - d__[*i__] - midpt;
10622 /* L100: */
10623 	}
10624 
10625 	psi = 0.;
10626 	i__1 = *i__ - 1;
10627 	for (j = 1; j <= i__1; ++j) {
10628 	    psi += z__[j] * z__[j] / delta[j];
10629 /* L110: */
10630 	}
10631 
10632 	phi = 0.;
10633 	i__1 = *i__ + 2;
10634 	for (j = *n; j >= i__1; --j) {
10635 	    phi += z__[j] * z__[j] / delta[j];
10636 /* L120: */
10637 	}
10638 	c__ = rhoinv + psi + phi;
10639 	w = c__ + z__[*i__] * z__[*i__] / delta[*i__] + z__[ip1] * z__[ip1] /
10640 		delta[ip1];
10641 
10642 	if (w > 0.) {
10643 
10644 /*
10645              d(i)< the ith eigenvalue < (d(i)+d(i+1))/2
10646 
10647              We choose d(i) as origin.
10648 */
10649 
10650 	    orgati = TRUE_;
10651 	    a = c__ * del + z__[*i__] * z__[*i__] + z__[ip1] * z__[ip1];
10652 	    b = z__[*i__] * z__[*i__] * del;
10653 	    if (a > 0.) {
10654 		tau = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(
10655 			d__1))));
10656 	    } else {
10657 		tau = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
10658 			c__ * 2.);
10659 	    }
10660 	    dltlb = 0.;
10661 	    dltub = midpt;
10662 	} else {
10663 
10664 /*
10665              (d(i)+d(i+1))/2 <= the ith eigenvalue < d(i+1)
10666 
10667              We choose d(i+1) as origin.
10668 */
10669 
10670 	    orgati = FALSE_;
10671 	    a = c__ * del - z__[*i__] * z__[*i__] - z__[ip1] * z__[ip1];
10672 	    b = z__[ip1] * z__[ip1] * del;
10673 	    if (a < 0.) {
10674 		tau = b * 2. / (a - sqrt((d__1 = a * a + b * 4. * c__, abs(
10675 			d__1))));
10676 	    } else {
10677 		tau = -(a + sqrt((d__1 = a * a + b * 4. * c__, abs(d__1)))) /
10678 			(c__ * 2.);
10679 	    }
10680 	    dltlb = -midpt;
10681 	    dltub = 0.;
10682 	}
10683 
10684 	if (orgati) {
10685 	    i__1 = *n;
10686 	    for (j = 1; j <= i__1; ++j) {
10687 		delta[j] = d__[j] - d__[*i__] - tau;
10688 /* L130: */
10689 	    }
10690 	} else {
10691 	    i__1 = *n;
10692 	    for (j = 1; j <= i__1; ++j) {
10693 		delta[j] = d__[j] - d__[ip1] - tau;
10694 /* L140: */
10695 	    }
10696 	}
10697 	if (orgati) {
10698 	    ii = *i__;
10699 	} else {
10700 	    ii = *i__ + 1;
10701 	}
10702 	iim1 = ii - 1;
10703 	iip1 = ii + 1;
10704 
10705 /*        Evaluate PSI and the derivative DPSI */
10706 
10707 	dpsi = 0.;
10708 	psi = 0.;
10709 	erretm = 0.;
10710 	i__1 = iim1;
10711 	for (j = 1; j <= i__1; ++j) {
10712 	    temp = z__[j] / delta[j];
10713 	    psi += z__[j] * temp;
10714 	    dpsi += temp * temp;
10715 	    erretm += psi;
10716 /* L150: */
10717 	}
10718 	erretm = abs(erretm);
10719 
10720 /*        Evaluate PHI and the derivative DPHI */
10721 
10722 	dphi = 0.;
10723 	phi = 0.;
10724 	i__1 = iip1;
10725 	for (j = *n; j >= i__1; --j) {
10726 	    temp = z__[j] / delta[j];
10727 	    phi += z__[j] * temp;
10728 	    dphi += temp * temp;
10729 	    erretm += phi;
10730 /* L160: */
10731 	}
10732 
10733 	w = rhoinv + phi + psi;
10734 
10735 /*
10736           W is the value of the secular function with
10737           its ii-th element removed.
10738 */
10739 
10740 	swtch3 = FALSE_;
10741 	if (orgati) {
10742 	    if (w < 0.) {
10743 		swtch3 = TRUE_;
10744 	    }
10745 	} else {
10746 	    if (w > 0.) {
10747 		swtch3 = TRUE_;
10748 	    }
10749 	}
10750 	if (ii == 1 || ii == *n) {
10751 	    swtch3 = FALSE_;
10752 	}
10753 
10754 	temp = z__[ii] / delta[ii];
10755 	dw = dpsi + dphi + temp * temp;
10756 	temp = z__[ii] * temp;
10757 	w += temp;
10758 	erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3. +
10759 		abs(tau) * dw;
10760 
10761 /*        Test for convergence */
10762 
10763 	if (abs(w) <= eps * erretm) {
10764 	    if (orgati) {
10765 		*dlam = d__[*i__] + tau;
10766 	    } else {
10767 		*dlam = d__[ip1] + tau;
10768 	    }
10769 	    goto L250;
10770 	}
10771 
10772 	if (w <= 0.) {
10773 	    dltlb = max(dltlb,tau);
10774 	} else {
10775 	    dltub = min(dltub,tau);
10776 	}
10777 
10778 /*        Calculate the new step */
10779 
10780 	++niter;
10781 	if (! swtch3) {
10782 	    if (orgati) {
10783 /* Computing 2nd power */
10784 		d__1 = z__[*i__] / delta[*i__];
10785 		c__ = w - delta[ip1] * dw - (d__[*i__] - d__[ip1]) * (d__1 *
10786 			d__1);
10787 	    } else {
10788 /* Computing 2nd power */
10789 		d__1 = z__[ip1] / delta[ip1];
10790 		c__ = w - delta[*i__] * dw - (d__[ip1] - d__[*i__]) * (d__1 *
10791 			d__1);
10792 	    }
10793 	    a = (delta[*i__] + delta[ip1]) * w - delta[*i__] * delta[ip1] *
10794 		    dw;
10795 	    b = delta[*i__] * delta[ip1] * w;
10796 	    if (c__ == 0.) {
10797 		if (a == 0.) {
10798 		    if (orgati) {
10799 			a = z__[*i__] * z__[*i__] + delta[ip1] * delta[ip1] *
10800 				(dpsi + dphi);
10801 		    } else {
10802 			a = z__[ip1] * z__[ip1] + delta[*i__] * delta[*i__] *
10803 				(dpsi + dphi);
10804 		    }
10805 		}
10806 		eta = b / a;
10807 	    } else if (a <= 0.) {
10808 		eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
10809 			c__ * 2.);
10810 	    } else {
10811 		eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(
10812 			d__1))));
10813 	    }
10814 	} else {
10815 
10816 /*           Interpolation using THREE most relevant poles */
10817 
10818 	    temp = rhoinv + psi + phi;
10819 	    if (orgati) {
10820 		temp1 = z__[iim1] / delta[iim1];
10821 		temp1 *= temp1;
10822 		c__ = temp - delta[iip1] * (dpsi + dphi) - (d__[iim1] - d__[
10823 			iip1]) * temp1;
10824 		zz[0] = z__[iim1] * z__[iim1];
10825 		zz[2] = delta[iip1] * delta[iip1] * (dpsi - temp1 + dphi);
10826 	    } else {
10827 		temp1 = z__[iip1] / delta[iip1];
10828 		temp1 *= temp1;
10829 		c__ = temp - delta[iim1] * (dpsi + dphi) - (d__[iip1] - d__[
10830 			iim1]) * temp1;
10831 		zz[0] = delta[iim1] * delta[iim1] * (dpsi + (dphi - temp1));
10832 		zz[2] = z__[iip1] * z__[iip1];
10833 	    }
10834 	    zz[1] = z__[ii] * z__[ii];
10835 	    dlaed6_(&niter, &orgati, &c__, &delta[iim1], zz, &w, &eta, info);
10836 	    if (*info != 0) {
10837 		goto L250;
10838 	    }
10839 	}
10840 
10841 /*
10842           Note, eta should be positive if w is negative, and
10843           eta should be negative otherwise. However,
10844           if for some reason caused by roundoff, eta*w > 0,
10845           we simply use one Newton step instead. This way
10846           will guarantee eta*w < 0.
10847 */
10848 
10849 	if (w * eta >= 0.) {
10850 	    eta = -w / dw;
10851 	}
10852 	temp = tau + eta;
10853 	if (temp > dltub || temp < dltlb) {
10854 	    if (w < 0.) {
10855 		eta = (dltub - tau) / 2.;
10856 	    } else {
10857 		eta = (dltlb - tau) / 2.;
10858 	    }
10859 	}
10860 
10861 	prew = w;
10862 
10863 	i__1 = *n;
10864 	for (j = 1; j <= i__1; ++j) {
10865 	    delta[j] -= eta;
10866 /* L180: */
10867 	}
10868 
10869 /*        Evaluate PSI and the derivative DPSI */
10870 
10871 	dpsi = 0.;
10872 	psi = 0.;
10873 	erretm = 0.;
10874 	i__1 = iim1;
10875 	for (j = 1; j <= i__1; ++j) {
10876 	    temp = z__[j] / delta[j];
10877 	    psi += z__[j] * temp;
10878 	    dpsi += temp * temp;
10879 	    erretm += psi;
10880 /* L190: */
10881 	}
10882 	erretm = abs(erretm);
10883 
10884 /*        Evaluate PHI and the derivative DPHI */
10885 
10886 	dphi = 0.;
10887 	phi = 0.;
10888 	i__1 = iip1;
10889 	for (j = *n; j >= i__1; --j) {
10890 	    temp = z__[j] / delta[j];
10891 	    phi += z__[j] * temp;
10892 	    dphi += temp * temp;
10893 	    erretm += phi;
10894 /* L200: */
10895 	}
10896 
10897 	temp = z__[ii] / delta[ii];
10898 	dw = dpsi + dphi + temp * temp;
10899 	temp = z__[ii] * temp;
10900 	w = rhoinv + phi + psi + temp;
10901 	erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3. + (
10902 		d__1 = tau + eta, abs(d__1)) * dw;
10903 
10904 	swtch = FALSE_;
10905 	if (orgati) {
10906 	    if (-w > abs(prew) / 10.) {
10907 		swtch = TRUE_;
10908 	    }
10909 	} else {
10910 	    if (w > abs(prew) / 10.) {
10911 		swtch = TRUE_;
10912 	    }
10913 	}
10914 
10915 	tau += eta;
10916 
10917 /*        Main loop to update the values of the array   DELTA */
10918 
10919 	iter = niter + 1;
10920 
10921 	for (niter = iter; niter <= 30; ++niter) {
10922 
10923 /*           Test for convergence */
10924 
10925 	    if (abs(w) <= eps * erretm) {
10926 		if (orgati) {
10927 		    *dlam = d__[*i__] + tau;
10928 		} else {
10929 		    *dlam = d__[ip1] + tau;
10930 		}
10931 		goto L250;
10932 	    }
10933 
10934 	    if (w <= 0.) {
10935 		dltlb = max(dltlb,tau);
10936 	    } else {
10937 		dltub = min(dltub,tau);
10938 	    }
10939 
10940 /*           Calculate the new step */
10941 
10942 	    if (! swtch3) {
10943 		if (! swtch) {
10944 		    if (orgati) {
10945 /* Computing 2nd power */
10946 			d__1 = z__[*i__] / delta[*i__];
10947 			c__ = w - delta[ip1] * dw - (d__[*i__] - d__[ip1]) * (
10948 				d__1 * d__1);
10949 		    } else {
10950 /* Computing 2nd power */
10951 			d__1 = z__[ip1] / delta[ip1];
10952 			c__ = w - delta[*i__] * dw - (d__[ip1] - d__[*i__]) *
10953 				(d__1 * d__1);
10954 		    }
10955 		} else {
10956 		    temp = z__[ii] / delta[ii];
10957 		    if (orgati) {
10958 			dpsi += temp * temp;
10959 		    } else {
10960 			dphi += temp * temp;
10961 		    }
10962 		    c__ = w - delta[*i__] * dpsi - delta[ip1] * dphi;
10963 		}
10964 		a = (delta[*i__] + delta[ip1]) * w - delta[*i__] * delta[ip1]
10965 			* dw;
10966 		b = delta[*i__] * delta[ip1] * w;
10967 		if (c__ == 0.) {
10968 		    if (a == 0.) {
10969 			if (! swtch) {
10970 			    if (orgati) {
10971 				a = z__[*i__] * z__[*i__] + delta[ip1] *
10972 					delta[ip1] * (dpsi + dphi);
10973 			    } else {
10974 				a = z__[ip1] * z__[ip1] + delta[*i__] * delta[
10975 					*i__] * (dpsi + dphi);
10976 			    }
10977 			} else {
10978 			    a = delta[*i__] * delta[*i__] * dpsi + delta[ip1]
10979 				    * delta[ip1] * dphi;
10980 			}
10981 		    }
10982 		    eta = b / a;
10983 		} else if (a <= 0.) {
10984 		    eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1))))
10985 			     / (c__ * 2.);
10986 		} else {
10987 		    eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__,
10988 			    abs(d__1))));
10989 		}
10990 	    } else {
10991 
10992 /*              Interpolation using THREE most relevant poles */
10993 
10994 		temp = rhoinv + psi + phi;
10995 		if (swtch) {
10996 		    c__ = temp - delta[iim1] * dpsi - delta[iip1] * dphi;
10997 		    zz[0] = delta[iim1] * delta[iim1] * dpsi;
10998 		    zz[2] = delta[iip1] * delta[iip1] * dphi;
10999 		} else {
11000 		    if (orgati) {
11001 			temp1 = z__[iim1] / delta[iim1];
11002 			temp1 *= temp1;
11003 			c__ = temp - delta[iip1] * (dpsi + dphi) - (d__[iim1]
11004 				- d__[iip1]) * temp1;
11005 			zz[0] = z__[iim1] * z__[iim1];
11006 			zz[2] = delta[iip1] * delta[iip1] * (dpsi - temp1 +
11007 				dphi);
11008 		    } else {
11009 			temp1 = z__[iip1] / delta[iip1];
11010 			temp1 *= temp1;
11011 			c__ = temp - delta[iim1] * (dpsi + dphi) - (d__[iip1]
11012 				- d__[iim1]) * temp1;
11013 			zz[0] = delta[iim1] * delta[iim1] * (dpsi + (dphi -
11014 				temp1));
11015 			zz[2] = z__[iip1] * z__[iip1];
11016 		    }
11017 		}
11018 		dlaed6_(&niter, &orgati, &c__, &delta[iim1], zz, &w, &eta,
11019 			info);
11020 		if (*info != 0) {
11021 		    goto L250;
11022 		}
11023 	    }
11024 
11025 /*
11026              Note, eta should be positive if w is negative, and
11027              eta should be negative otherwise. However,
11028              if for some reason caused by roundoff, eta*w > 0,
11029              we simply use one Newton step instead. This way
11030              will guarantee eta*w < 0.
11031 */
11032 
11033 	    if (w * eta >= 0.) {
11034 		eta = -w / dw;
11035 	    }
11036 	    temp = tau + eta;
11037 	    if (temp > dltub || temp < dltlb) {
11038 		if (w < 0.) {
11039 		    eta = (dltub - tau) / 2.;
11040 		} else {
11041 		    eta = (dltlb - tau) / 2.;
11042 		}
11043 	    }
11044 
11045 	    i__1 = *n;
11046 	    for (j = 1; j <= i__1; ++j) {
11047 		delta[j] -= eta;
11048 /* L210: */
11049 	    }
11050 
11051 	    tau += eta;
11052 	    prew = w;
11053 
11054 /*           Evaluate PSI and the derivative DPSI */
11055 
11056 	    dpsi = 0.;
11057 	    psi = 0.;
11058 	    erretm = 0.;
11059 	    i__1 = iim1;
11060 	    for (j = 1; j <= i__1; ++j) {
11061 		temp = z__[j] / delta[j];
11062 		psi += z__[j] * temp;
11063 		dpsi += temp * temp;
11064 		erretm += psi;
11065 /* L220: */
11066 	    }
11067 	    erretm = abs(erretm);
11068 
11069 /*           Evaluate PHI and the derivative DPHI */
11070 
11071 	    dphi = 0.;
11072 	    phi = 0.;
11073 	    i__1 = iip1;
11074 	    for (j = *n; j >= i__1; --j) {
11075 		temp = z__[j] / delta[j];
11076 		phi += z__[j] * temp;
11077 		dphi += temp * temp;
11078 		erretm += phi;
11079 /* L230: */
11080 	    }
11081 
11082 	    temp = z__[ii] / delta[ii];
11083 	    dw = dpsi + dphi + temp * temp;
11084 	    temp = z__[ii] * temp;
11085 	    w = rhoinv + phi + psi + temp;
11086 	    erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3.
11087 		    + abs(tau) * dw;
11088 	    if (w * prew > 0. && abs(w) > abs(prew) / 10.) {
11089 		swtch = ! swtch;
11090 	    }
11091 
11092 /* L240: */
11093 	}
11094 
11095 /*        Return with INFO = 1, NITER = MAXIT and not converged */
11096 
11097 	*info = 1;
11098 	if (orgati) {
11099 	    *dlam = d__[*i__] + tau;
11100 	} else {
11101 	    *dlam = d__[ip1] + tau;
11102 	}
11103 
11104     }
11105 
11106 L250:
11107 
11108     return 0;
11109 
11110 /*     End of DLAED4 */
11111 
11112 } /* dlaed4_ */
11113 
dlaed5_(integer * i__,doublereal * d__,doublereal * z__,doublereal * delta,doublereal * rho,doublereal * dlam)11114 /* Subroutine */ int dlaed5_(integer *i__, doublereal *d__, doublereal *z__,
11115 	doublereal *delta, doublereal *rho, doublereal *dlam)
11116 {
11117     /* System generated locals */
11118     doublereal d__1;
11119 
11120     /* Local variables */
11121     static doublereal b, c__, w, del, tau, temp;
11122 
11123 
11124 /*
11125     -- LAPACK routine (version 3.2) --
11126     -- LAPACK is a software package provided by Univ. of Tennessee,    --
11127     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
11128        November 2006
11129 
11130 
11131     Purpose
11132     =======
11133 
11134     This subroutine computes the I-th eigenvalue of a symmetric rank-one
11135     modification of a 2-by-2 diagonal matrix
11136 
11137                diag( D )  +  RHO *  Z * transpose(Z) .
11138 
11139     The diagonal elements in the array D are assumed to satisfy
11140 
11141                D(i) < D(j)  for  i < j .
11142 
11143     We also assume RHO > 0 and that the Euclidean norm of the vector
11144     Z is one.
11145 
11146     Arguments
11147     =========
11148 
11149     I      (input) INTEGER
11150            The index of the eigenvalue to be computed.  I = 1 or I = 2.
11151 
11152     D      (input) DOUBLE PRECISION array, dimension (2)
11153            The original eigenvalues.  We assume D(1) < D(2).
11154 
11155     Z      (input) DOUBLE PRECISION array, dimension (2)
11156            The components of the updating vector.
11157 
11158     DELTA  (output) DOUBLE PRECISION array, dimension (2)
11159            The vector DELTA contains the information necessary
11160            to construct the eigenvectors.
11161 
11162     RHO    (input) DOUBLE PRECISION
11163            The scalar in the symmetric updating formula.
11164 
11165     DLAM   (output) DOUBLE PRECISION
11166            The computed lambda_I, the I-th updated eigenvalue.
11167 
11168     Further Details
11169     ===============
11170 
11171     Based on contributions by
11172        Ren-Cang Li, Computer Science Division, University of California
11173        at Berkeley, USA
11174 
11175     =====================================================================
11176 */
11177 
11178 
11179     /* Parameter adjustments */
11180     --delta;
11181     --z__;
11182     --d__;
11183 
11184     /* Function Body */
11185     del = d__[2] - d__[1];
11186     if (*i__ == 1) {
11187 	w = *rho * 2. * (z__[2] * z__[2] - z__[1] * z__[1]) / del + 1.;
11188 	if (w > 0.) {
11189 	    b = del + *rho * (z__[1] * z__[1] + z__[2] * z__[2]);
11190 	    c__ = *rho * z__[1] * z__[1] * del;
11191 
11192 /*           B > ZERO, always */
11193 
11194 	    tau = c__ * 2. / (b + sqrt((d__1 = b * b - c__ * 4., abs(d__1))));
11195 	    *dlam = d__[1] + tau;
11196 	    delta[1] = -z__[1] / tau;
11197 	    delta[2] = z__[2] / (del - tau);
11198 	} else {
11199 	    b = -del + *rho * (z__[1] * z__[1] + z__[2] * z__[2]);
11200 	    c__ = *rho * z__[2] * z__[2] * del;
11201 	    if (b > 0.) {
11202 		tau = c__ * -2. / (b + sqrt(b * b + c__ * 4.));
11203 	    } else {
11204 		tau = (b - sqrt(b * b + c__ * 4.)) / 2.;
11205 	    }
11206 	    *dlam = d__[2] + tau;
11207 	    delta[1] = -z__[1] / (del + tau);
11208 	    delta[2] = -z__[2] / tau;
11209 	}
11210 	temp = sqrt(delta[1] * delta[1] + delta[2] * delta[2]);
11211 	delta[1] /= temp;
11212 	delta[2] /= temp;
11213     } else {
11214 
11215 /*     Now I=2 */
11216 
11217 	b = -del + *rho * (z__[1] * z__[1] + z__[2] * z__[2]);
11218 	c__ = *rho * z__[2] * z__[2] * del;
11219 	if (b > 0.) {
11220 	    tau = (b + sqrt(b * b + c__ * 4.)) / 2.;
11221 	} else {
11222 	    tau = c__ * 2. / (-b + sqrt(b * b + c__ * 4.));
11223 	}
11224 	*dlam = d__[2] + tau;
11225 	delta[1] = -z__[1] / (del + tau);
11226 	delta[2] = -z__[2] / tau;
11227 	temp = sqrt(delta[1] * delta[1] + delta[2] * delta[2]);
11228 	delta[1] /= temp;
11229 	delta[2] /= temp;
11230     }
11231     return 0;
11232 
11233 /*     End OF DLAED5 */
11234 
11235 } /* dlaed5_ */
11236 
dlaed6_(integer * kniter,logical * orgati,doublereal * rho,doublereal * d__,doublereal * z__,doublereal * finit,doublereal * tau,integer * info)11237 /* Subroutine */ int dlaed6_(integer *kniter, logical *orgati, doublereal *
11238 	rho, doublereal *d__, doublereal *z__, doublereal *finit, doublereal *
11239 	tau, integer *info)
11240 {
11241     /* System generated locals */
11242     integer i__1;
11243     doublereal d__1, d__2, d__3, d__4;
11244 
11245     /* Local variables */
11246     static doublereal a, b, c__, f;
11247     static integer i__;
11248     static doublereal fc, df, ddf, lbd, eta, ubd, eps, base;
11249     static integer iter;
11250     static doublereal temp, temp1, temp2, temp3, temp4;
11251     static logical scale;
11252     static integer niter;
11253     static doublereal small1, small2, sminv1, sminv2;
11254 
11255     static doublereal dscale[3], sclfac, zscale[3], erretm, sclinv;
11256 
11257 
11258 /*
11259     -- LAPACK routine (version 3.2) --
11260     -- LAPACK is a software package provided by Univ. of Tennessee,    --
11261     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
11262        February 2007
11263 
11264 
11265     Purpose
11266     =======
11267 
11268     DLAED6 computes the positive or negative root (closest to the origin)
11269     of
11270                      z(1)        z(2)        z(3)
11271     f(x) =   rho + --------- + ---------- + ---------
11272                     d(1)-x      d(2)-x      d(3)-x
11273 
11274     It is assumed that
11275 
11276           if ORGATI = .true. the root is between d(2) and d(3);
11277           otherwise it is between d(1) and d(2)
11278 
11279     This routine will be called by DLAED4 when necessary. In most cases,
11280     the root sought is the smallest in magnitude, though it might not be
11281     in some extremely rare situations.
11282 
11283     Arguments
11284     =========
11285 
11286     KNITER       (input) INTEGER
11287                  Refer to DLAED4 for its significance.
11288 
11289     ORGATI       (input) LOGICAL
11290                  If ORGATI is true, the needed root is between d(2) and
11291                  d(3); otherwise it is between d(1) and d(2).  See
11292                  DLAED4 for further details.
11293 
11294     RHO          (input) DOUBLE PRECISION
11295                  Refer to the equation f(x) above.
11296 
11297     D            (input) DOUBLE PRECISION array, dimension (3)
11298                  D satisfies d(1) < d(2) < d(3).
11299 
11300     Z            (input) DOUBLE PRECISION array, dimension (3)
11301                  Each of the elements in z must be positive.
11302 
11303     FINIT        (input) DOUBLE PRECISION
11304                  The value of f at 0. It is more accurate than the one
11305                  evaluated inside this routine (if someone wants to do
11306                  so).
11307 
11308     TAU          (output) DOUBLE PRECISION
11309                  The root of the equation f(x).
11310 
11311     INFO         (output) INTEGER
11312                  = 0: successful exit
11313                  > 0: if INFO = 1, failure to converge
11314 
11315     Further Details
11316     ===============
11317 
11318     30/06/99: Based on contributions by
11319        Ren-Cang Li, Computer Science Division, University of California
11320        at Berkeley, USA
11321 
11322     10/02/03: This version has a few statements commented out for thread
11323     safety (machine parameters are computed on each entry). SJH.
11324 
11325     05/10/06: Modified from a new version of Ren-Cang Li, use
11326        Gragg-Thornton-Warner cubic convergent scheme for better stability.
11327 
11328     =====================================================================
11329 */
11330 
11331 
11332     /* Parameter adjustments */
11333     --z__;
11334     --d__;
11335 
11336     /* Function Body */
11337     *info = 0;
11338 
11339     if (*orgati) {
11340 	lbd = d__[2];
11341 	ubd = d__[3];
11342     } else {
11343 	lbd = d__[1];
11344 	ubd = d__[2];
11345     }
11346     if (*finit < 0.) {
11347 	lbd = 0.;
11348     } else {
11349 	ubd = 0.;
11350     }
11351 
11352     niter = 1;
11353     *tau = 0.;
11354     if (*kniter == 2) {
11355 	if (*orgati) {
11356 	    temp = (d__[3] - d__[2]) / 2.;
11357 	    c__ = *rho + z__[1] / (d__[1] - d__[2] - temp);
11358 	    a = c__ * (d__[2] + d__[3]) + z__[2] + z__[3];
11359 	    b = c__ * d__[2] * d__[3] + z__[2] * d__[3] + z__[3] * d__[2];
11360 	} else {
11361 	    temp = (d__[1] - d__[2]) / 2.;
11362 	    c__ = *rho + z__[3] / (d__[3] - d__[2] - temp);
11363 	    a = c__ * (d__[1] + d__[2]) + z__[1] + z__[2];
11364 	    b = c__ * d__[1] * d__[2] + z__[1] * d__[2] + z__[2] * d__[1];
11365 	}
11366 /* Computing MAX */
11367 	d__1 = abs(a), d__2 = abs(b), d__1 = max(d__1,d__2), d__2 = abs(c__);
11368 	temp = max(d__1,d__2);
11369 	a /= temp;
11370 	b /= temp;
11371 	c__ /= temp;
11372 	if (c__ == 0.) {
11373 	    *tau = b / a;
11374 	} else if (a <= 0.) {
11375 	    *tau = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
11376 		    c__ * 2.);
11377 	} else {
11378 	    *tau = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1))
11379 		    ));
11380 	}
11381 	if (*tau < lbd || *tau > ubd) {
11382 	    *tau = (lbd + ubd) / 2.;
11383 	}
11384 	if (d__[1] == *tau || d__[2] == *tau || d__[3] == *tau) {
11385 	    *tau = 0.;
11386 	} else {
11387 	    temp = *finit + *tau * z__[1] / (d__[1] * (d__[1] - *tau)) + *tau
11388 		    * z__[2] / (d__[2] * (d__[2] - *tau)) + *tau * z__[3] / (
11389 		    d__[3] * (d__[3] - *tau));
11390 	    if (temp <= 0.) {
11391 		lbd = *tau;
11392 	    } else {
11393 		ubd = *tau;
11394 	    }
11395 	    if (abs(*finit) <= abs(temp)) {
11396 		*tau = 0.;
11397 	    }
11398 	}
11399     }
11400 
11401 /*
11402        get machine parameters for possible scaling to avoid overflow
11403 
11404        modified by Sven: parameters SMALL1, SMINV1, SMALL2,
11405        SMINV2, EPS are not SAVEd anymore between one call to the
11406        others but recomputed at each call
11407 */
11408 
11409     eps = EPSILON;
11410     base = BASE;
11411     i__1 = (integer) (log(SAFEMINIMUM) / log(base) / 3.);
11412     small1 = pow_di(&base, &i__1);
11413     sminv1 = 1. / small1;
11414     small2 = small1 * small1;
11415     sminv2 = sminv1 * sminv1;
11416 
11417 /*
11418        Determine if scaling of inputs necessary to avoid overflow
11419        when computing 1/TEMP**3
11420 */
11421 
11422     if (*orgati) {
11423 /* Computing MIN */
11424 	d__3 = (d__1 = d__[2] - *tau, abs(d__1)), d__4 = (d__2 = d__[3] - *
11425 		tau, abs(d__2));
11426 	temp = min(d__3,d__4);
11427     } else {
11428 /* Computing MIN */
11429 	d__3 = (d__1 = d__[1] - *tau, abs(d__1)), d__4 = (d__2 = d__[2] - *
11430 		tau, abs(d__2));
11431 	temp = min(d__3,d__4);
11432     }
11433     scale = FALSE_;
11434     if (temp <= small1) {
11435 	scale = TRUE_;
11436 	if (temp <= small2) {
11437 
11438 /*        Scale up by power of radix nearest 1/SAFMIN**(2/3) */
11439 
11440 	    sclfac = sminv2;
11441 	    sclinv = small2;
11442 	} else {
11443 
11444 /*        Scale up by power of radix nearest 1/SAFMIN**(1/3) */
11445 
11446 	    sclfac = sminv1;
11447 	    sclinv = small1;
11448 	}
11449 
11450 /*        Scaling up safe because D, Z, TAU scaled elsewhere to be O(1) */
11451 
11452 	for (i__ = 1; i__ <= 3; ++i__) {
11453 	    dscale[i__ - 1] = d__[i__] * sclfac;
11454 	    zscale[i__ - 1] = z__[i__] * sclfac;
11455 /* L10: */
11456 	}
11457 	*tau *= sclfac;
11458 	lbd *= sclfac;
11459 	ubd *= sclfac;
11460     } else {
11461 
11462 /*        Copy D and Z to DSCALE and ZSCALE */
11463 
11464 	for (i__ = 1; i__ <= 3; ++i__) {
11465 	    dscale[i__ - 1] = d__[i__];
11466 	    zscale[i__ - 1] = z__[i__];
11467 /* L20: */
11468 	}
11469     }
11470 
11471     fc = 0.;
11472     df = 0.;
11473     ddf = 0.;
11474     for (i__ = 1; i__ <= 3; ++i__) {
11475 	temp = 1. / (dscale[i__ - 1] - *tau);
11476 	temp1 = zscale[i__ - 1] * temp;
11477 	temp2 = temp1 * temp;
11478 	temp3 = temp2 * temp;
11479 	fc += temp1 / dscale[i__ - 1];
11480 	df += temp2;
11481 	ddf += temp3;
11482 /* L30: */
11483     }
11484     f = *finit + *tau * fc;
11485 
11486     if (abs(f) <= 0.) {
11487 	goto L60;
11488     }
11489     if (f <= 0.) {
11490 	lbd = *tau;
11491     } else {
11492 	ubd = *tau;
11493     }
11494 
11495 /*
11496           Iteration begins -- Use Gragg-Thornton-Warner cubic convergent
11497                               scheme
11498 
11499        It is not hard to see that
11500 
11501              1) Iterations will go up monotonically
11502                 if FINIT < 0;
11503 
11504              2) Iterations will go down monotonically
11505                 if FINIT > 0.
11506 */
11507 
11508     iter = niter + 1;
11509 
11510     for (niter = iter; niter <= 40; ++niter) {
11511 
11512 	if (*orgati) {
11513 	    temp1 = dscale[1] - *tau;
11514 	    temp2 = dscale[2] - *tau;
11515 	} else {
11516 	    temp1 = dscale[0] - *tau;
11517 	    temp2 = dscale[1] - *tau;
11518 	}
11519 	a = (temp1 + temp2) * f - temp1 * temp2 * df;
11520 	b = temp1 * temp2 * f;
11521 	c__ = f - (temp1 + temp2) * df + temp1 * temp2 * ddf;
11522 /* Computing MAX */
11523 	d__1 = abs(a), d__2 = abs(b), d__1 = max(d__1,d__2), d__2 = abs(c__);
11524 	temp = max(d__1,d__2);
11525 	a /= temp;
11526 	b /= temp;
11527 	c__ /= temp;
11528 	if (c__ == 0.) {
11529 	    eta = b / a;
11530 	} else if (a <= 0.) {
11531 	    eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (c__
11532 		    * 2.);
11533 	} else {
11534 	    eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))
11535 		    );
11536 	}
11537 	if (f * eta >= 0.) {
11538 	    eta = -f / df;
11539 	}
11540 
11541 	*tau += eta;
11542 	if (*tau < lbd || *tau > ubd) {
11543 	    *tau = (lbd + ubd) / 2.;
11544 	}
11545 
11546 	fc = 0.;
11547 	erretm = 0.;
11548 	df = 0.;
11549 	ddf = 0.;
11550 	for (i__ = 1; i__ <= 3; ++i__) {
11551 	    temp = 1. / (dscale[i__ - 1] - *tau);
11552 	    temp1 = zscale[i__ - 1] * temp;
11553 	    temp2 = temp1 * temp;
11554 	    temp3 = temp2 * temp;
11555 	    temp4 = temp1 / dscale[i__ - 1];
11556 	    fc += temp4;
11557 	    erretm += abs(temp4);
11558 	    df += temp2;
11559 	    ddf += temp3;
11560 /* L40: */
11561 	}
11562 	f = *finit + *tau * fc;
11563 	erretm = (abs(*finit) + abs(*tau) * erretm) * 8. + abs(*tau) * df;
11564 	if (abs(f) <= eps * erretm) {
11565 	    goto L60;
11566 	}
11567 	if (f <= 0.) {
11568 	    lbd = *tau;
11569 	} else {
11570 	    ubd = *tau;
11571 	}
11572 /* L50: */
11573     }
11574     *info = 1;
11575 L60:
11576 
11577 /*     Undo scaling */
11578 
11579     if (scale) {
11580 	*tau *= sclinv;
11581     }
11582     return 0;
11583 
11584 /*     End of DLAED6 */
11585 
11586 } /* dlaed6_ */
11587 
dlaed7_(integer * icompq,integer * n,integer * qsiz,integer * tlvls,integer * curlvl,integer * curpbm,doublereal * d__,doublereal * q,integer * ldq,integer * indxq,doublereal * rho,integer * cutpnt,doublereal * qstore,integer * qptr,integer * prmptr,integer * perm,integer * givptr,integer * givcol,doublereal * givnum,doublereal * work,integer * iwork,integer * info)11588 /* Subroutine */ int dlaed7_(integer *icompq, integer *n, integer *qsiz,
11589 	integer *tlvls, integer *curlvl, integer *curpbm, doublereal *d__,
11590 	doublereal *q, integer *ldq, integer *indxq, doublereal *rho, integer
11591 	*cutpnt, doublereal *qstore, integer *qptr, integer *prmptr, integer *
11592 	perm, integer *givptr, integer *givcol, doublereal *givnum,
11593 	doublereal *work, integer *iwork, integer *info)
11594 {
11595     /* System generated locals */
11596     integer q_dim1, q_offset, i__1, i__2;
11597 
11598     /* Local variables */
11599     static integer i__, k, n1, n2, is, iw, iz, iq2, ptr, ldq2, indx, curr;
11600     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
11601 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
11602 	    integer *, doublereal *, doublereal *, integer *);
11603     static integer indxc, indxp;
11604     extern /* Subroutine */ int dlaed8_(integer *, integer *, integer *,
11605 	    integer *, doublereal *, doublereal *, integer *, integer *,
11606 	    doublereal *, integer *, doublereal *, doublereal *, doublereal *,
11607 	     integer *, doublereal *, integer *, integer *, integer *,
11608 	    doublereal *, integer *, integer *, integer *), dlaed9_(integer *,
11609 	     integer *, integer *, integer *, doublereal *, doublereal *,
11610 	    integer *, doublereal *, doublereal *, doublereal *, doublereal *,
11611 	     integer *, integer *), dlaeda_(integer *, integer *, integer *,
11612 	    integer *, integer *, integer *, integer *, integer *, doublereal
11613 	    *, doublereal *, integer *, doublereal *, doublereal *, integer *)
11614 	    ;
11615     static integer idlmda;
11616     extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *,
11617 	    integer *, integer *, integer *), xerbla_(char *, integer *);
11618     static integer coltyp;
11619 
11620 
11621 /*
11622     -- LAPACK routine (version 3.2) --
11623     -- LAPACK is a software package provided by Univ. of Tennessee,    --
11624     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
11625        November 2006
11626 
11627 
11628     Purpose
11629     =======
11630 
11631     DLAED7 computes the updated eigensystem of a diagonal
11632     matrix after modification by a rank-one symmetric matrix. This
11633     routine is used only for the eigenproblem which requires all
11634     eigenvalues and optionally eigenvectors of a dense symmetric matrix
11635     that has been reduced to tridiagonal form.  DLAED1 handles
11636     the case in which all eigenvalues and eigenvectors of a symmetric
11637     tridiagonal matrix are desired.
11638 
11639       T = Q(in) ( D(in) + RHO * Z*Z' ) Q'(in) = Q(out) * D(out) * Q'(out)
11640 
11641        where Z = Q'u, u is a vector of length N with ones in the
11642        CUTPNT and CUTPNT + 1 th elements and zeros elsewhere.
11643 
11644        The eigenvectors of the original matrix are stored in Q, and the
11645        eigenvalues are in D.  The algorithm consists of three stages:
11646 
11647           The first stage consists of deflating the size of the problem
11648           when there are multiple eigenvalues or if there is a zero in
11649           the Z vector.  For each such occurence the dimension of the
11650           secular equation problem is reduced by one.  This stage is
11651           performed by the routine DLAED8.
11652 
11653           The second stage consists of calculating the updated
11654           eigenvalues. This is done by finding the roots of the secular
11655           equation via the routine DLAED4 (as called by DLAED9).
11656           This routine also calculates the eigenvectors of the current
11657           problem.
11658 
11659           The final stage consists of computing the updated eigenvectors
11660           directly using the updated eigenvalues.  The eigenvectors for
11661           the current problem are multiplied with the eigenvectors from
11662           the overall problem.
11663 
11664     Arguments
11665     =========
11666 
11667     ICOMPQ  (input) INTEGER
11668             = 0:  Compute eigenvalues only.
11669             = 1:  Compute eigenvectors of original dense symmetric matrix
11670                   also.  On entry, Q contains the orthogonal matrix used
11671                   to reduce the original matrix to tridiagonal form.
11672 
11673     N      (input) INTEGER
11674            The dimension of the symmetric tridiagonal matrix.  N >= 0.
11675 
11676     QSIZ   (input) INTEGER
11677            The dimension of the orthogonal matrix used to reduce
11678            the full matrix to tridiagonal form.  QSIZ >= N if ICOMPQ = 1.
11679 
11680     TLVLS  (input) INTEGER
11681            The total number of merging levels in the overall divide and
11682            conquer tree.
11683 
11684     CURLVL (input) INTEGER
11685            The current level in the overall merge routine,
11686            0 <= CURLVL <= TLVLS.
11687 
11688     CURPBM (input) INTEGER
11689            The current problem in the current level in the overall
11690            merge routine (counting from upper left to lower right).
11691 
11692     D      (input/output) DOUBLE PRECISION array, dimension (N)
11693            On entry, the eigenvalues of the rank-1-perturbed matrix.
11694            On exit, the eigenvalues of the repaired matrix.
11695 
11696     Q      (input/output) DOUBLE PRECISION array, dimension (LDQ, N)
11697            On entry, the eigenvectors of the rank-1-perturbed matrix.
11698            On exit, the eigenvectors of the repaired tridiagonal matrix.
11699 
11700     LDQ    (input) INTEGER
11701            The leading dimension of the array Q.  LDQ >= max(1,N).
11702 
11703     INDXQ  (output) INTEGER array, dimension (N)
11704            The permutation which will reintegrate the subproblem just
11705            solved back into sorted order, i.e., D( INDXQ( I = 1, N ) )
11706            will be in ascending order.
11707 
11708     RHO    (input) DOUBLE PRECISION
11709            The subdiagonal element used to create the rank-1
11710            modification.
11711 
11712     CUTPNT (input) INTEGER
11713            Contains the location of the last eigenvalue in the leading
11714            sub-matrix.  min(1,N) <= CUTPNT <= N.
11715 
11716     QSTORE (input/output) DOUBLE PRECISION array, dimension (N**2+1)
11717            Stores eigenvectors of submatrices encountered during
11718            divide and conquer, packed together. QPTR points to
11719            beginning of the submatrices.
11720 
11721     QPTR   (input/output) INTEGER array, dimension (N+2)
11722            List of indices pointing to beginning of submatrices stored
11723            in QSTORE. The submatrices are numbered starting at the
11724            bottom left of the divide and conquer tree, from left to
11725            right and bottom to top.
11726 
11727     PRMPTR (input) INTEGER array, dimension (N lg N)
11728            Contains a list of pointers which indicate where in PERM a
11729            level's permutation is stored.  PRMPTR(i+1) - PRMPTR(i)
11730            indicates the size of the permutation and also the size of
11731            the full, non-deflated problem.
11732 
11733     PERM   (input) INTEGER array, dimension (N lg N)
11734            Contains the permutations (from deflation and sorting) to be
11735            applied to each eigenblock.
11736 
11737     GIVPTR (input) INTEGER array, dimension (N lg N)
11738            Contains a list of pointers which indicate where in GIVCOL a
11739            level's Givens rotations are stored.  GIVPTR(i+1) - GIVPTR(i)
11740            indicates the number of Givens rotations.
11741 
11742     GIVCOL (input) INTEGER array, dimension (2, N lg N)
11743            Each pair of numbers indicates a pair of columns to take place
11744            in a Givens rotation.
11745 
11746     GIVNUM (input) DOUBLE PRECISION array, dimension (2, N lg N)
11747            Each number indicates the S value to be used in the
11748            corresponding Givens rotation.
11749 
11750     WORK   (workspace) DOUBLE PRECISION array, dimension (3*N+QSIZ*N)
11751 
11752     IWORK  (workspace) INTEGER array, dimension (4*N)
11753 
11754     INFO   (output) INTEGER
11755             = 0:  successful exit.
11756             < 0:  if INFO = -i, the i-th argument had an illegal value.
11757             > 0:  if INFO = 1, an eigenvalue did not converge
11758 
11759     Further Details
11760     ===============
11761 
11762     Based on contributions by
11763        Jeff Rutter, Computer Science Division, University of California
11764        at Berkeley, USA
11765 
11766     =====================================================================
11767 
11768 
11769        Test the input parameters.
11770 */
11771 
11772     /* Parameter adjustments */
11773     --d__;
11774     q_dim1 = *ldq;
11775     q_offset = 1 + q_dim1;
11776     q -= q_offset;
11777     --indxq;
11778     --qstore;
11779     --qptr;
11780     --prmptr;
11781     --perm;
11782     --givptr;
11783     givcol -= 3;
11784     givnum -= 3;
11785     --work;
11786     --iwork;
11787 
11788     /* Function Body */
11789     *info = 0;
11790 
11791     if (*icompq < 0 || *icompq > 1) {
11792 	*info = -1;
11793     } else if (*n < 0) {
11794 	*info = -2;
11795     } else if (*icompq == 1 && *qsiz < *n) {
11796 	*info = -4;
11797     } else if (*ldq < max(1,*n)) {
11798 	*info = -9;
11799     } else if (min(1,*n) > *cutpnt || *n < *cutpnt) {
11800 	*info = -12;
11801     }
11802     if (*info != 0) {
11803 	i__1 = -(*info);
11804 	xerbla_("DLAED7", &i__1);
11805 	return 0;
11806     }
11807 
11808 /*     Quick return if possible */
11809 
11810     if (*n == 0) {
11811 	return 0;
11812     }
11813 
11814 /*
11815        The following values are for bookkeeping purposes only.  They are
11816        integer pointers which indicate the portion of the workspace
11817        used by a particular array in DLAED8 and DLAED9.
11818 */
11819 
11820     if (*icompq == 1) {
11821 	ldq2 = *qsiz;
11822     } else {
11823 	ldq2 = *n;
11824     }
11825 
11826     iz = 1;
11827     idlmda = iz + *n;
11828     iw = idlmda + *n;
11829     iq2 = iw + *n;
11830     is = iq2 + *n * ldq2;
11831 
11832     indx = 1;
11833     indxc = indx + *n;
11834     coltyp = indxc + *n;
11835     indxp = coltyp + *n;
11836 
11837 /*
11838        Form the z-vector which consists of the last row of Q_1 and the
11839        first row of Q_2.
11840 */
11841 
11842     ptr = pow_ii(&c__2, tlvls) + 1;
11843     i__1 = *curlvl - 1;
11844     for (i__ = 1; i__ <= i__1; ++i__) {
11845 	i__2 = *tlvls - i__;
11846 	ptr += pow_ii(&c__2, &i__2);
11847 /* L10: */
11848     }
11849     curr = ptr + *curpbm;
11850     dlaeda_(n, tlvls, curlvl, curpbm, &prmptr[1], &perm[1], &givptr[1], &
11851 	    givcol[3], &givnum[3], &qstore[1], &qptr[1], &work[iz], &work[iz
11852 	    + *n], info);
11853 
11854 /*
11855        When solving the final problem, we no longer need the stored data,
11856        so we will overwrite the data from this level onto the previously
11857        used storage space.
11858 */
11859 
11860     if (*curlvl == *tlvls) {
11861 	qptr[curr] = 1;
11862 	prmptr[curr] = 1;
11863 	givptr[curr] = 1;
11864     }
11865 
11866 /*     Sort and Deflate eigenvalues. */
11867 
11868     dlaed8_(icompq, &k, n, qsiz, &d__[1], &q[q_offset], ldq, &indxq[1], rho,
11869 	    cutpnt, &work[iz], &work[idlmda], &work[iq2], &ldq2, &work[iw], &
11870 	    perm[prmptr[curr]], &givptr[curr + 1], &givcol[(givptr[curr] << 1)
11871 	     + 1], &givnum[(givptr[curr] << 1) + 1], &iwork[indxp], &iwork[
11872 	    indx], info);
11873     prmptr[curr + 1] = prmptr[curr] + *n;
11874     givptr[curr + 1] += givptr[curr];
11875 
11876 /*     Solve Secular Equation. */
11877 
11878     if (k != 0) {
11879 	dlaed9_(&k, &c__1, &k, n, &d__[1], &work[is], &k, rho, &work[idlmda],
11880 		&work[iw], &qstore[qptr[curr]], &k, info);
11881 	if (*info != 0) {
11882 	    goto L30;
11883 	}
11884 	if (*icompq == 1) {
11885 	    dgemm_("N", "N", qsiz, &k, &k, &c_b15, &work[iq2], &ldq2, &qstore[
11886 		    qptr[curr]], &k, &c_b29, &q[q_offset], ldq);
11887 	}
11888 /* Computing 2nd power */
11889 	i__1 = k;
11890 	qptr[curr + 1] = qptr[curr] + i__1 * i__1;
11891 
11892 /*     Prepare the INDXQ sorting permutation. */
11893 
11894 	n1 = k;
11895 	n2 = *n - k;
11896 	dlamrg_(&n1, &n2, &d__[1], &c__1, &c_n1, &indxq[1]);
11897     } else {
11898 	qptr[curr + 1] = qptr[curr];
11899 	i__1 = *n;
11900 	for (i__ = 1; i__ <= i__1; ++i__) {
11901 	    indxq[i__] = i__;
11902 /* L20: */
11903 	}
11904     }
11905 
11906 L30:
11907     return 0;
11908 
11909 /*     End of DLAED7 */
11910 
11911 } /* dlaed7_ */
11912 
dlaed8_(integer * icompq,integer * k,integer * n,integer * qsiz,doublereal * d__,doublereal * q,integer * ldq,integer * indxq,doublereal * rho,integer * cutpnt,doublereal * z__,doublereal * dlamda,doublereal * q2,integer * ldq2,doublereal * w,integer * perm,integer * givptr,integer * givcol,doublereal * givnum,integer * indxp,integer * indx,integer * info)11913 /* Subroutine */ int dlaed8_(integer *icompq, integer *k, integer *n, integer
11914 	*qsiz, doublereal *d__, doublereal *q, integer *ldq, integer *indxq,
11915 	doublereal *rho, integer *cutpnt, doublereal *z__, doublereal *dlamda,
11916 	 doublereal *q2, integer *ldq2, doublereal *w, integer *perm, integer
11917 	*givptr, integer *givcol, doublereal *givnum, integer *indxp, integer
11918 	*indx, integer *info)
11919 {
11920     /* System generated locals */
11921     integer q_dim1, q_offset, q2_dim1, q2_offset, i__1;
11922     doublereal d__1;
11923 
11924     /* Local variables */
11925     static doublereal c__;
11926     static integer i__, j;
11927     static doublereal s, t;
11928     static integer k2, n1, n2, jp, n1p1;
11929     static doublereal eps, tau, tol;
11930     static integer jlam, imax, jmax;
11931     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
11932 	    doublereal *, integer *, doublereal *, doublereal *), dscal_(
11933 	    integer *, doublereal *, doublereal *, integer *), dcopy_(integer
11934 	    *, doublereal *, integer *, doublereal *, integer *);
11935 
11936     extern integer idamax_(integer *, doublereal *, integer *);
11937     extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *,
11938 	    integer *, integer *, integer *), dlacpy_(char *, integer *,
11939 	    integer *, doublereal *, integer *, doublereal *, integer *), xerbla_(char *, integer *);
11940 
11941 
11942 /*
11943     -- LAPACK routine (version 3.2.2) --
11944     -- LAPACK is a software package provided by Univ. of Tennessee,    --
11945     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
11946        June 2010
11947 
11948 
11949     Purpose
11950     =======
11951 
11952     DLAED8 merges the two sets of eigenvalues together into a single
11953     sorted set.  Then it tries to deflate the size of the problem.
11954     There are two ways in which deflation can occur:  when two or more
11955     eigenvalues are close together or if there is a tiny element in the
11956     Z vector.  For each such occurrence the order of the related secular
11957     equation problem is reduced by one.
11958 
11959     Arguments
11960     =========
11961 
11962     ICOMPQ  (input) INTEGER
11963             = 0:  Compute eigenvalues only.
11964             = 1:  Compute eigenvectors of original dense symmetric matrix
11965                   also.  On entry, Q contains the orthogonal matrix used
11966                   to reduce the original matrix to tridiagonal form.
11967 
11968     K      (output) INTEGER
11969            The number of non-deflated eigenvalues, and the order of the
11970            related secular equation.
11971 
11972     N      (input) INTEGER
11973            The dimension of the symmetric tridiagonal matrix.  N >= 0.
11974 
11975     QSIZ   (input) INTEGER
11976            The dimension of the orthogonal matrix used to reduce
11977            the full matrix to tridiagonal form.  QSIZ >= N if ICOMPQ = 1.
11978 
11979     D      (input/output) DOUBLE PRECISION array, dimension (N)
11980            On entry, the eigenvalues of the two submatrices to be
11981            combined.  On exit, the trailing (N-K) updated eigenvalues
11982            (those which were deflated) sorted into increasing order.
11983 
11984     Q      (input/output) DOUBLE PRECISION array, dimension (LDQ,N)
11985            If ICOMPQ = 0, Q is not referenced.  Otherwise,
11986            on entry, Q contains the eigenvectors of the partially solved
11987            system which has been previously updated in matrix
11988            multiplies with other partially solved eigensystems.
11989            On exit, Q contains the trailing (N-K) updated eigenvectors
11990            (those which were deflated) in its last N-K columns.
11991 
11992     LDQ    (input) INTEGER
11993            The leading dimension of the array Q.  LDQ >= max(1,N).
11994 
11995     INDXQ  (input) INTEGER array, dimension (N)
11996            The permutation which separately sorts the two sub-problems
11997            in D into ascending order.  Note that elements in the second
11998            half of this permutation must first have CUTPNT added to
11999            their values in order to be accurate.
12000 
12001     RHO    (input/output) DOUBLE PRECISION
12002            On entry, the off-diagonal element associated with the rank-1
12003            cut which originally split the two submatrices which are now
12004            being recombined.
12005            On exit, RHO has been modified to the value required by
12006            DLAED3.
12007 
12008     CUTPNT (input) INTEGER
12009            The location of the last eigenvalue in the leading
12010            sub-matrix.  min(1,N) <= CUTPNT <= N.
12011 
12012     Z      (input) DOUBLE PRECISION array, dimension (N)
12013            On entry, Z contains the updating vector (the last row of
12014            the first sub-eigenvector matrix and the first row of the
12015            second sub-eigenvector matrix).
12016            On exit, the contents of Z are destroyed by the updating
12017            process.
12018 
12019     DLAMDA (output) DOUBLE PRECISION array, dimension (N)
12020            A copy of the first K eigenvalues which will be used by
12021            DLAED3 to form the secular equation.
12022 
12023     Q2     (output) DOUBLE PRECISION array, dimension (LDQ2,N)
12024            If ICOMPQ = 0, Q2 is not referenced.  Otherwise,
12025            a copy of the first K eigenvectors which will be used by
12026            DLAED7 in a matrix multiply (DGEMM) to update the new
12027            eigenvectors.
12028 
12029     LDQ2   (input) INTEGER
12030            The leading dimension of the array Q2.  LDQ2 >= max(1,N).
12031 
12032     W      (output) DOUBLE PRECISION array, dimension (N)
12033            The first k values of the final deflation-altered z-vector and
12034            will be passed to DLAED3.
12035 
12036     PERM   (output) INTEGER array, dimension (N)
12037            The permutations (from deflation and sorting) to be applied
12038            to each eigenblock.
12039 
12040     GIVPTR (output) INTEGER
12041            The number of Givens rotations which took place in this
12042            subproblem.
12043 
12044     GIVCOL (output) INTEGER array, dimension (2, N)
12045            Each pair of numbers indicates a pair of columns to take place
12046            in a Givens rotation.
12047 
12048     GIVNUM (output) DOUBLE PRECISION array, dimension (2, N)
12049            Each number indicates the S value to be used in the
12050            corresponding Givens rotation.
12051 
12052     INDXP  (workspace) INTEGER array, dimension (N)
12053            The permutation used to place deflated values of D at the end
12054            of the array.  INDXP(1:K) points to the nondeflated D-values
12055            and INDXP(K+1:N) points to the deflated eigenvalues.
12056 
12057     INDX   (workspace) INTEGER array, dimension (N)
12058            The permutation used to sort the contents of D into ascending
12059            order.
12060 
12061     INFO   (output) INTEGER
12062             = 0:  successful exit.
12063             < 0:  if INFO = -i, the i-th argument had an illegal value.
12064 
12065     Further Details
12066     ===============
12067 
12068     Based on contributions by
12069        Jeff Rutter, Computer Science Division, University of California
12070        at Berkeley, USA
12071 
12072     =====================================================================
12073 
12074 
12075        Test the input parameters.
12076 */
12077 
12078     /* Parameter adjustments */
12079     --d__;
12080     q_dim1 = *ldq;
12081     q_offset = 1 + q_dim1;
12082     q -= q_offset;
12083     --indxq;
12084     --z__;
12085     --dlamda;
12086     q2_dim1 = *ldq2;
12087     q2_offset = 1 + q2_dim1;
12088     q2 -= q2_offset;
12089     --w;
12090     --perm;
12091     givcol -= 3;
12092     givnum -= 3;
12093     --indxp;
12094     --indx;
12095 
12096     /* Function Body */
12097     *info = 0;
12098 
12099     if (*icompq < 0 || *icompq > 1) {
12100 	*info = -1;
12101     } else if (*n < 0) {
12102 	*info = -3;
12103     } else if (*icompq == 1 && *qsiz < *n) {
12104 	*info = -4;
12105     } else if (*ldq < max(1,*n)) {
12106 	*info = -7;
12107     } else if (*cutpnt < min(1,*n) || *cutpnt > *n) {
12108 	*info = -10;
12109     } else if (*ldq2 < max(1,*n)) {
12110 	*info = -14;
12111     }
12112     if (*info != 0) {
12113 	i__1 = -(*info);
12114 	xerbla_("DLAED8", &i__1);
12115 	return 0;
12116     }
12117 
12118 /*
12119        Need to initialize GIVPTR to O here in case of quick exit
12120        to prevent an unspecified code behavior (usually sigfault)
12121        when IWORK array on entry to *stedc is not zeroed
12122        (or at least some IWORK entries which used in *laed7 for GIVPTR).
12123 */
12124 
12125     *givptr = 0;
12126 
12127 /*     Quick return if possible */
12128 
12129     if (*n == 0) {
12130 	return 0;
12131     }
12132 
12133     n1 = *cutpnt;
12134     n2 = *n - n1;
12135     n1p1 = n1 + 1;
12136 
12137     if (*rho < 0.) {
12138 	dscal_(&n2, &c_b151, &z__[n1p1], &c__1);
12139     }
12140 
12141 /*     Normalize z so that norm(z) = 1 */
12142 
12143     t = 1. / sqrt(2.);
12144     i__1 = *n;
12145     for (j = 1; j <= i__1; ++j) {
12146 	indx[j] = j;
12147 /* L10: */
12148     }
12149     dscal_(n, &t, &z__[1], &c__1);
12150     *rho = (d__1 = *rho * 2., abs(d__1));
12151 
12152 /*     Sort the eigenvalues into increasing order */
12153 
12154     i__1 = *n;
12155     for (i__ = *cutpnt + 1; i__ <= i__1; ++i__) {
12156 	indxq[i__] += *cutpnt;
12157 /* L20: */
12158     }
12159     i__1 = *n;
12160     for (i__ = 1; i__ <= i__1; ++i__) {
12161 	dlamda[i__] = d__[indxq[i__]];
12162 	w[i__] = z__[indxq[i__]];
12163 /* L30: */
12164     }
12165     i__ = 1;
12166     j = *cutpnt + 1;
12167     dlamrg_(&n1, &n2, &dlamda[1], &c__1, &c__1, &indx[1]);
12168     i__1 = *n;
12169     for (i__ = 1; i__ <= i__1; ++i__) {
12170 	d__[i__] = dlamda[indx[i__]];
12171 	z__[i__] = w[indx[i__]];
12172 /* L40: */
12173     }
12174 
12175 /*     Calculate the allowable deflation tolerence */
12176 
12177     imax = idamax_(n, &z__[1], &c__1);
12178     jmax = idamax_(n, &d__[1], &c__1);
12179     eps = EPSILON;
12180     tol = eps * 8. * (d__1 = d__[jmax], abs(d__1));
12181 
12182 /*
12183        If the rank-1 modifier is small enough, no more needs to be done
12184        except to reorganize Q so that its columns correspond with the
12185        elements in D.
12186 */
12187 
12188     if (*rho * (d__1 = z__[imax], abs(d__1)) <= tol) {
12189 	*k = 0;
12190 	if (*icompq == 0) {
12191 	    i__1 = *n;
12192 	    for (j = 1; j <= i__1; ++j) {
12193 		perm[j] = indxq[indx[j]];
12194 /* L50: */
12195 	    }
12196 	} else {
12197 	    i__1 = *n;
12198 	    for (j = 1; j <= i__1; ++j) {
12199 		perm[j] = indxq[indx[j]];
12200 		dcopy_(qsiz, &q[perm[j] * q_dim1 + 1], &c__1, &q2[j * q2_dim1
12201 			+ 1], &c__1);
12202 /* L60: */
12203 	    }
12204 	    dlacpy_("A", qsiz, n, &q2[q2_dim1 + 1], ldq2, &q[q_dim1 + 1], ldq);
12205 	}
12206 	return 0;
12207     }
12208 
12209 /*
12210        If there are multiple eigenvalues then the problem deflates.  Here
12211        the number of equal eigenvalues are found.  As each equal
12212        eigenvalue is found, an elementary reflector is computed to rotate
12213        the corresponding eigensubspace so that the corresponding
12214        components of Z are zero in this new basis.
12215 */
12216 
12217     *k = 0;
12218     k2 = *n + 1;
12219     i__1 = *n;
12220     for (j = 1; j <= i__1; ++j) {
12221 	if (*rho * (d__1 = z__[j], abs(d__1)) <= tol) {
12222 
12223 /*           Deflate due to small z component. */
12224 
12225 	    --k2;
12226 	    indxp[k2] = j;
12227 	    if (j == *n) {
12228 		goto L110;
12229 	    }
12230 	} else {
12231 	    jlam = j;
12232 	    goto L80;
12233 	}
12234 /* L70: */
12235     }
12236 L80:
12237     ++j;
12238     if (j > *n) {
12239 	goto L100;
12240     }
12241     if (*rho * (d__1 = z__[j], abs(d__1)) <= tol) {
12242 
12243 /*        Deflate due to small z component. */
12244 
12245 	--k2;
12246 	indxp[k2] = j;
12247     } else {
12248 
12249 /*        Check if eigenvalues are close enough to allow deflation. */
12250 
12251 	s = z__[jlam];
12252 	c__ = z__[j];
12253 
12254 /*
12255           Find sqrt(a**2+b**2) without overflow or
12256           destructive underflow.
12257 */
12258 
12259 	tau = dlapy2_(&c__, &s);
12260 	t = d__[j] - d__[jlam];
12261 	c__ /= tau;
12262 	s = -s / tau;
12263 	if ((d__1 = t * c__ * s, abs(d__1)) <= tol) {
12264 
12265 /*           Deflation is possible. */
12266 
12267 	    z__[j] = tau;
12268 	    z__[jlam] = 0.;
12269 
12270 /*           Record the appropriate Givens rotation */
12271 
12272 	    ++(*givptr);
12273 	    givcol[(*givptr << 1) + 1] = indxq[indx[jlam]];
12274 	    givcol[(*givptr << 1) + 2] = indxq[indx[j]];
12275 	    givnum[(*givptr << 1) + 1] = c__;
12276 	    givnum[(*givptr << 1) + 2] = s;
12277 	    if (*icompq == 1) {
12278 		drot_(qsiz, &q[indxq[indx[jlam]] * q_dim1 + 1], &c__1, &q[
12279 			indxq[indx[j]] * q_dim1 + 1], &c__1, &c__, &s);
12280 	    }
12281 	    t = d__[jlam] * c__ * c__ + d__[j] * s * s;
12282 	    d__[j] = d__[jlam] * s * s + d__[j] * c__ * c__;
12283 	    d__[jlam] = t;
12284 	    --k2;
12285 	    i__ = 1;
12286 L90:
12287 	    if (k2 + i__ <= *n) {
12288 		if (d__[jlam] < d__[indxp[k2 + i__]]) {
12289 		    indxp[k2 + i__ - 1] = indxp[k2 + i__];
12290 		    indxp[k2 + i__] = jlam;
12291 		    ++i__;
12292 		    goto L90;
12293 		} else {
12294 		    indxp[k2 + i__ - 1] = jlam;
12295 		}
12296 	    } else {
12297 		indxp[k2 + i__ - 1] = jlam;
12298 	    }
12299 	    jlam = j;
12300 	} else {
12301 	    ++(*k);
12302 	    w[*k] = z__[jlam];
12303 	    dlamda[*k] = d__[jlam];
12304 	    indxp[*k] = jlam;
12305 	    jlam = j;
12306 	}
12307     }
12308     goto L80;
12309 L100:
12310 
12311 /*     Record the last eigenvalue. */
12312 
12313     ++(*k);
12314     w[*k] = z__[jlam];
12315     dlamda[*k] = d__[jlam];
12316     indxp[*k] = jlam;
12317 
12318 L110:
12319 
12320 /*
12321        Sort the eigenvalues and corresponding eigenvectors into DLAMDA
12322        and Q2 respectively.  The eigenvalues/vectors which were not
12323        deflated go into the first K slots of DLAMDA and Q2 respectively,
12324        while those which were deflated go into the last N - K slots.
12325 */
12326 
12327     if (*icompq == 0) {
12328 	i__1 = *n;
12329 	for (j = 1; j <= i__1; ++j) {
12330 	    jp = indxp[j];
12331 	    dlamda[j] = d__[jp];
12332 	    perm[j] = indxq[indx[jp]];
12333 /* L120: */
12334 	}
12335     } else {
12336 	i__1 = *n;
12337 	for (j = 1; j <= i__1; ++j) {
12338 	    jp = indxp[j];
12339 	    dlamda[j] = d__[jp];
12340 	    perm[j] = indxq[indx[jp]];
12341 	    dcopy_(qsiz, &q[perm[j] * q_dim1 + 1], &c__1, &q2[j * q2_dim1 + 1]
12342 		    , &c__1);
12343 /* L130: */
12344 	}
12345     }
12346 
12347 /*
12348        The deflated eigenvalues and their corresponding vectors go back
12349        into the last N - K slots of D and Q respectively.
12350 */
12351 
12352     if (*k < *n) {
12353 	if (*icompq == 0) {
12354 	    i__1 = *n - *k;
12355 	    dcopy_(&i__1, &dlamda[*k + 1], &c__1, &d__[*k + 1], &c__1);
12356 	} else {
12357 	    i__1 = *n - *k;
12358 	    dcopy_(&i__1, &dlamda[*k + 1], &c__1, &d__[*k + 1], &c__1);
12359 	    i__1 = *n - *k;
12360 	    dlacpy_("A", qsiz, &i__1, &q2[(*k + 1) * q2_dim1 + 1], ldq2, &q[(*
12361 		    k + 1) * q_dim1 + 1], ldq);
12362 	}
12363     }
12364 
12365     return 0;
12366 
12367 /*     End of DLAED8 */
12368 
12369 } /* dlaed8_ */
12370 
dlaed9_(integer * k,integer * kstart,integer * kstop,integer * n,doublereal * d__,doublereal * q,integer * ldq,doublereal * rho,doublereal * dlamda,doublereal * w,doublereal * s,integer * lds,integer * info)12371 /* Subroutine */ int dlaed9_(integer *k, integer *kstart, integer *kstop,
12372 	integer *n, doublereal *d__, doublereal *q, integer *ldq, doublereal *
12373 	rho, doublereal *dlamda, doublereal *w, doublereal *s, integer *lds,
12374 	integer *info)
12375 {
12376     /* System generated locals */
12377     integer q_dim1, q_offset, s_dim1, s_offset, i__1, i__2;
12378     doublereal d__1;
12379 
12380     /* Local variables */
12381     static integer i__, j;
12382     static doublereal temp;
12383     extern doublereal dnrm2_(integer *, doublereal *, integer *);
12384     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
12385 	    doublereal *, integer *), dlaed4_(integer *, integer *,
12386 	    doublereal *, doublereal *, doublereal *, doublereal *,
12387 	    doublereal *, integer *);
12388     extern doublereal dlamc3_(doublereal *, doublereal *);
12389     extern /* Subroutine */ int xerbla_(char *, integer *);
12390 
12391 
12392 /*
12393     -- LAPACK routine (version 3.2) --
12394     -- LAPACK is a software package provided by Univ. of Tennessee,    --
12395     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
12396        November 2006
12397 
12398 
12399     Purpose
12400     =======
12401 
12402     DLAED9 finds the roots of the secular equation, as defined by the
12403     values in D, Z, and RHO, between KSTART and KSTOP.  It makes the
12404     appropriate calls to DLAED4 and then stores the new matrix of
12405     eigenvectors for use in calculating the next level of Z vectors.
12406 
12407     Arguments
12408     =========
12409 
12410     K       (input) INTEGER
12411             The number of terms in the rational function to be solved by
12412             DLAED4.  K >= 0.
12413 
12414     KSTART  (input) INTEGER
12415     KSTOP   (input) INTEGER
12416             The updated eigenvalues Lambda(I), KSTART <= I <= KSTOP
12417             are to be computed.  1 <= KSTART <= KSTOP <= K.
12418 
12419     N       (input) INTEGER
12420             The number of rows and columns in the Q matrix.
12421             N >= K (delation may result in N > K).
12422 
12423     D       (output) DOUBLE PRECISION array, dimension (N)
12424             D(I) contains the updated eigenvalues
12425             for KSTART <= I <= KSTOP.
12426 
12427     Q       (workspace) DOUBLE PRECISION array, dimension (LDQ,N)
12428 
12429     LDQ     (input) INTEGER
12430             The leading dimension of the array Q.  LDQ >= max( 1, N ).
12431 
12432     RHO     (input) DOUBLE PRECISION
12433             The value of the parameter in the rank one update equation.
12434             RHO >= 0 required.
12435 
12436     DLAMDA  (input) DOUBLE PRECISION array, dimension (K)
12437             The first K elements of this array contain the old roots
12438             of the deflated updating problem.  These are the poles
12439             of the secular equation.
12440 
12441     W       (input) DOUBLE PRECISION array, dimension (K)
12442             The first K elements of this array contain the components
12443             of the deflation-adjusted updating vector.
12444 
12445     S       (output) DOUBLE PRECISION array, dimension (LDS, K)
12446             Will contain the eigenvectors of the repaired matrix which
12447             will be stored for subsequent Z vector calculation and
12448             multiplied by the previously accumulated eigenvectors
12449             to update the system.
12450 
12451     LDS     (input) INTEGER
12452             The leading dimension of S.  LDS >= max( 1, K ).
12453 
12454     INFO    (output) INTEGER
12455             = 0:  successful exit.
12456             < 0:  if INFO = -i, the i-th argument had an illegal value.
12457             > 0:  if INFO = 1, an eigenvalue did not converge
12458 
12459     Further Details
12460     ===============
12461 
12462     Based on contributions by
12463        Jeff Rutter, Computer Science Division, University of California
12464        at Berkeley, USA
12465 
12466     =====================================================================
12467 
12468 
12469        Test the input parameters.
12470 */
12471 
12472     /* Parameter adjustments */
12473     --d__;
12474     q_dim1 = *ldq;
12475     q_offset = 1 + q_dim1;
12476     q -= q_offset;
12477     --dlamda;
12478     --w;
12479     s_dim1 = *lds;
12480     s_offset = 1 + s_dim1;
12481     s -= s_offset;
12482 
12483     /* Function Body */
12484     *info = 0;
12485 
12486     if (*k < 0) {
12487 	*info = -1;
12488     } else if (*kstart < 1 || *kstart > max(1,*k)) {
12489 	*info = -2;
12490     } else if (max(1,*kstop) < *kstart || *kstop > max(1,*k)) {
12491 	*info = -3;
12492     } else if (*n < *k) {
12493 	*info = -4;
12494     } else if (*ldq < max(1,*k)) {
12495 	*info = -7;
12496     } else if (*lds < max(1,*k)) {
12497 	*info = -12;
12498     }
12499     if (*info != 0) {
12500 	i__1 = -(*info);
12501 	xerbla_("DLAED9", &i__1);
12502 	return 0;
12503     }
12504 
12505 /*     Quick return if possible */
12506 
12507     if (*k == 0) {
12508 	return 0;
12509     }
12510 
12511 /*
12512        Modify values DLAMDA(i) to make sure all DLAMDA(i)-DLAMDA(j) can
12513        be computed with high relative accuracy (barring over/underflow).
12514        This is a problem on machines without a guard digit in
12515        add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2).
12516        The following code replaces DLAMDA(I) by 2*DLAMDA(I)-DLAMDA(I),
12517        which on any of these machines zeros out the bottommost
12518        bit of DLAMDA(I) if it is 1; this makes the subsequent
12519        subtractions DLAMDA(I)-DLAMDA(J) unproblematic when cancellation
12520        occurs. On binary machines with a guard digit (almost all
12521        machines) it does not change DLAMDA(I) at all. On hexadecimal
12522        and decimal machines with a guard digit, it slightly
12523        changes the bottommost bits of DLAMDA(I). It does not account
12524        for hexadecimal or decimal machines without guard digits
12525        (we know of none). We use a subroutine call to compute
12526        2*DLAMBDA(I) to prevent optimizing compilers from eliminating
12527        this code.
12528 */
12529 
12530     i__1 = *n;
12531     for (i__ = 1; i__ <= i__1; ++i__) {
12532 	dlamda[i__] = dlamc3_(&dlamda[i__], &dlamda[i__]) - dlamda[i__];
12533 /* L10: */
12534     }
12535 
12536     i__1 = *kstop;
12537     for (j = *kstart; j <= i__1; ++j) {
12538 	dlaed4_(k, &j, &dlamda[1], &w[1], &q[j * q_dim1 + 1], rho, &d__[j],
12539 		info);
12540 
12541 /*        If the zero finder fails, the computation is terminated. */
12542 
12543 	if (*info != 0) {
12544 	    goto L120;
12545 	}
12546 /* L20: */
12547     }
12548 
12549     if (*k == 1 || *k == 2) {
12550 	i__1 = *k;
12551 	for (i__ = 1; i__ <= i__1; ++i__) {
12552 	    i__2 = *k;
12553 	    for (j = 1; j <= i__2; ++j) {
12554 		s[j + i__ * s_dim1] = q[j + i__ * q_dim1];
12555 /* L30: */
12556 	    }
12557 /* L40: */
12558 	}
12559 	goto L120;
12560     }
12561 
12562 /*     Compute updated W. */
12563 
12564     dcopy_(k, &w[1], &c__1, &s[s_offset], &c__1);
12565 
12566 /*     Initialize W(I) = Q(I,I) */
12567 
12568     i__1 = *ldq + 1;
12569     dcopy_(k, &q[q_offset], &i__1, &w[1], &c__1);
12570     i__1 = *k;
12571     for (j = 1; j <= i__1; ++j) {
12572 	i__2 = j - 1;
12573 	for (i__ = 1; i__ <= i__2; ++i__) {
12574 	    w[i__] *= q[i__ + j * q_dim1] / (dlamda[i__] - dlamda[j]);
12575 /* L50: */
12576 	}
12577 	i__2 = *k;
12578 	for (i__ = j + 1; i__ <= i__2; ++i__) {
12579 	    w[i__] *= q[i__ + j * q_dim1] / (dlamda[i__] - dlamda[j]);
12580 /* L60: */
12581 	}
12582 /* L70: */
12583     }
12584     i__1 = *k;
12585     for (i__ = 1; i__ <= i__1; ++i__) {
12586 	d__1 = sqrt(-w[i__]);
12587 	w[i__] = d_sign(&d__1, &s[i__ + s_dim1]);
12588 /* L80: */
12589     }
12590 
12591 /*     Compute eigenvectors of the modified rank-1 modification. */
12592 
12593     i__1 = *k;
12594     for (j = 1; j <= i__1; ++j) {
12595 	i__2 = *k;
12596 	for (i__ = 1; i__ <= i__2; ++i__) {
12597 	    q[i__ + j * q_dim1] = w[i__] / q[i__ + j * q_dim1];
12598 /* L90: */
12599 	}
12600 	temp = dnrm2_(k, &q[j * q_dim1 + 1], &c__1);
12601 	i__2 = *k;
12602 	for (i__ = 1; i__ <= i__2; ++i__) {
12603 	    s[i__ + j * s_dim1] = q[i__ + j * q_dim1] / temp;
12604 /* L100: */
12605 	}
12606 /* L110: */
12607     }
12608 
12609 L120:
12610     return 0;
12611 
12612 /*     End of DLAED9 */
12613 
12614 } /* dlaed9_ */
12615 
dlaeda_(integer * n,integer * tlvls,integer * curlvl,integer * curpbm,integer * prmptr,integer * perm,integer * givptr,integer * givcol,doublereal * givnum,doublereal * q,integer * qptr,doublereal * z__,doublereal * ztemp,integer * info)12616 /* Subroutine */ int dlaeda_(integer *n, integer *tlvls, integer *curlvl,
12617 	integer *curpbm, integer *prmptr, integer *perm, integer *givptr,
12618 	integer *givcol, doublereal *givnum, doublereal *q, integer *qptr,
12619 	doublereal *z__, doublereal *ztemp, integer *info)
12620 {
12621     /* System generated locals */
12622     integer i__1, i__2, i__3;
12623 
12624     /* Local variables */
12625     static integer i__, k, mid, ptr;
12626     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
12627 	    doublereal *, integer *, doublereal *, doublereal *);
12628     static integer curr, bsiz1, bsiz2, psiz1, psiz2, zptr1;
12629     extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
12630 	    doublereal *, doublereal *, integer *, doublereal *, integer *,
12631 	    doublereal *, doublereal *, integer *), dcopy_(integer *,
12632 	    doublereal *, integer *, doublereal *, integer *), xerbla_(char *,
12633 	     integer *);
12634 
12635 
12636 /*
12637     -- LAPACK routine (version 3.2.2) --
12638     -- LAPACK is a software package provided by Univ. of Tennessee,    --
12639     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
12640        June 2010
12641 
12642 
12643     Purpose
12644     =======
12645 
12646     DLAEDA computes the Z vector corresponding to the merge step in the
12647     CURLVLth step of the merge process with TLVLS steps for the CURPBMth
12648     problem.
12649 
12650     Arguments
12651     =========
12652 
12653     N      (input) INTEGER
12654            The dimension of the symmetric tridiagonal matrix.  N >= 0.
12655 
12656     TLVLS  (input) INTEGER
12657            The total number of merging levels in the overall divide and
12658            conquer tree.
12659 
12660     CURLVL (input) INTEGER
12661            The current level in the overall merge routine,
12662            0 <= curlvl <= tlvls.
12663 
12664     CURPBM (input) INTEGER
12665            The current problem in the current level in the overall
12666            merge routine (counting from upper left to lower right).
12667 
12668     PRMPTR (input) INTEGER array, dimension (N lg N)
12669            Contains a list of pointers which indicate where in PERM a
12670            level's permutation is stored.  PRMPTR(i+1) - PRMPTR(i)
12671            indicates the size of the permutation and incidentally the
12672            size of the full, non-deflated problem.
12673 
12674     PERM   (input) INTEGER array, dimension (N lg N)
12675            Contains the permutations (from deflation and sorting) to be
12676            applied to each eigenblock.
12677 
12678     GIVPTR (input) INTEGER array, dimension (N lg N)
12679            Contains a list of pointers which indicate where in GIVCOL a
12680            level's Givens rotations are stored.  GIVPTR(i+1) - GIVPTR(i)
12681            indicates the number of Givens rotations.
12682 
12683     GIVCOL (input) INTEGER array, dimension (2, N lg N)
12684            Each pair of numbers indicates a pair of columns to take place
12685            in a Givens rotation.
12686 
12687     GIVNUM (input) DOUBLE PRECISION array, dimension (2, N lg N)
12688            Each number indicates the S value to be used in the
12689            corresponding Givens rotation.
12690 
12691     Q      (input) DOUBLE PRECISION array, dimension (N**2)
12692            Contains the square eigenblocks from previous levels, the
12693            starting positions for blocks are given by QPTR.
12694 
12695     QPTR   (input) INTEGER array, dimension (N+2)
12696            Contains a list of pointers which indicate where in Q an
12697            eigenblock is stored.  SQRT( QPTR(i+1) - QPTR(i) ) indicates
12698            the size of the block.
12699 
12700     Z      (output) DOUBLE PRECISION array, dimension (N)
12701            On output this vector contains the updating vector (the last
12702            row of the first sub-eigenvector matrix and the first row of
12703            the second sub-eigenvector matrix).
12704 
12705     ZTEMP  (workspace) DOUBLE PRECISION array, dimension (N)
12706 
12707     INFO   (output) INTEGER
12708             = 0:  successful exit.
12709             < 0:  if INFO = -i, the i-th argument had an illegal value.
12710 
12711     Further Details
12712     ===============
12713 
12714     Based on contributions by
12715        Jeff Rutter, Computer Science Division, University of California
12716        at Berkeley, USA
12717 
12718     =====================================================================
12719 
12720 
12721        Test the input parameters.
12722 */
12723 
12724     /* Parameter adjustments */
12725     --ztemp;
12726     --z__;
12727     --qptr;
12728     --q;
12729     givnum -= 3;
12730     givcol -= 3;
12731     --givptr;
12732     --perm;
12733     --prmptr;
12734 
12735     /* Function Body */
12736     *info = 0;
12737 
12738     if (*n < 0) {
12739 	*info = -1;
12740     }
12741     if (*info != 0) {
12742 	i__1 = -(*info);
12743 	xerbla_("DLAEDA", &i__1);
12744 	return 0;
12745     }
12746 
12747 /*     Quick return if possible */
12748 
12749     if (*n == 0) {
12750 	return 0;
12751     }
12752 
12753 /*     Determine location of first number in second half. */
12754 
12755     mid = *n / 2 + 1;
12756 
12757 /*     Gather last/first rows of appropriate eigenblocks into center of Z */
12758 
12759     ptr = 1;
12760 
12761 /*
12762        Determine location of lowest level subproblem in the full storage
12763        scheme
12764 */
12765 
12766     i__1 = *curlvl - 1;
12767     curr = ptr + *curpbm * pow_ii(&c__2, curlvl) + pow_ii(&c__2, &i__1) - 1;
12768 
12769 /*
12770        Determine size of these matrices.  We add HALF to the value of
12771        the SQRT in case the machine underestimates one of these square
12772        roots.
12773 */
12774 
12775     bsiz1 = (integer) (sqrt((doublereal) (qptr[curr + 1] - qptr[curr])) + .5);
12776     bsiz2 = (integer) (sqrt((doublereal) (qptr[curr + 2] - qptr[curr + 1])) +
12777 	    .5);
12778     i__1 = mid - bsiz1 - 1;
12779     for (k = 1; k <= i__1; ++k) {
12780 	z__[k] = 0.;
12781 /* L10: */
12782     }
12783     dcopy_(&bsiz1, &q[qptr[curr] + bsiz1 - 1], &bsiz1, &z__[mid - bsiz1], &
12784 	    c__1);
12785     dcopy_(&bsiz2, &q[qptr[curr + 1]], &bsiz2, &z__[mid], &c__1);
12786     i__1 = *n;
12787     for (k = mid + bsiz2; k <= i__1; ++k) {
12788 	z__[k] = 0.;
12789 /* L20: */
12790     }
12791 
12792 /*
12793        Loop through remaining levels 1 -> CURLVL applying the Givens
12794        rotations and permutation and then multiplying the center matrices
12795        against the current Z.
12796 */
12797 
12798     ptr = pow_ii(&c__2, tlvls) + 1;
12799     i__1 = *curlvl - 1;
12800     for (k = 1; k <= i__1; ++k) {
12801 	i__2 = *curlvl - k;
12802 	i__3 = *curlvl - k - 1;
12803 	curr = ptr + *curpbm * pow_ii(&c__2, &i__2) + pow_ii(&c__2, &i__3) -
12804 		1;
12805 	psiz1 = prmptr[curr + 1] - prmptr[curr];
12806 	psiz2 = prmptr[curr + 2] - prmptr[curr + 1];
12807 	zptr1 = mid - psiz1;
12808 
12809 /*       Apply Givens at CURR and CURR+1 */
12810 
12811 	i__2 = givptr[curr + 1] - 1;
12812 	for (i__ = givptr[curr]; i__ <= i__2; ++i__) {
12813 	    drot_(&c__1, &z__[zptr1 + givcol[(i__ << 1) + 1] - 1], &c__1, &
12814 		    z__[zptr1 + givcol[(i__ << 1) + 2] - 1], &c__1, &givnum[(
12815 		    i__ << 1) + 1], &givnum[(i__ << 1) + 2]);
12816 /* L30: */
12817 	}
12818 	i__2 = givptr[curr + 2] - 1;
12819 	for (i__ = givptr[curr + 1]; i__ <= i__2; ++i__) {
12820 	    drot_(&c__1, &z__[mid - 1 + givcol[(i__ << 1) + 1]], &c__1, &z__[
12821 		    mid - 1 + givcol[(i__ << 1) + 2]], &c__1, &givnum[(i__ <<
12822 		    1) + 1], &givnum[(i__ << 1) + 2]);
12823 /* L40: */
12824 	}
12825 	psiz1 = prmptr[curr + 1] - prmptr[curr];
12826 	psiz2 = prmptr[curr + 2] - prmptr[curr + 1];
12827 	i__2 = psiz1 - 1;
12828 	for (i__ = 0; i__ <= i__2; ++i__) {
12829 	    ztemp[i__ + 1] = z__[zptr1 + perm[prmptr[curr] + i__] - 1];
12830 /* L50: */
12831 	}
12832 	i__2 = psiz2 - 1;
12833 	for (i__ = 0; i__ <= i__2; ++i__) {
12834 	    ztemp[psiz1 + i__ + 1] = z__[mid + perm[prmptr[curr + 1] + i__] -
12835 		    1];
12836 /* L60: */
12837 	}
12838 
12839 /*
12840           Multiply Blocks at CURR and CURR+1
12841 
12842           Determine size of these matrices.  We add HALF to the value of
12843           the SQRT in case the machine underestimates one of these
12844           square roots.
12845 */
12846 
12847 	bsiz1 = (integer) (sqrt((doublereal) (qptr[curr + 1] - qptr[curr])) +
12848 		.5);
12849 	bsiz2 = (integer) (sqrt((doublereal) (qptr[curr + 2] - qptr[curr + 1])
12850 		) + .5);
12851 	if (bsiz1 > 0) {
12852 	    dgemv_("T", &bsiz1, &bsiz1, &c_b15, &q[qptr[curr]], &bsiz1, &
12853 		    ztemp[1], &c__1, &c_b29, &z__[zptr1], &c__1);
12854 	}
12855 	i__2 = psiz1 - bsiz1;
12856 	dcopy_(&i__2, &ztemp[bsiz1 + 1], &c__1, &z__[zptr1 + bsiz1], &c__1);
12857 	if (bsiz2 > 0) {
12858 	    dgemv_("T", &bsiz2, &bsiz2, &c_b15, &q[qptr[curr + 1]], &bsiz2, &
12859 		    ztemp[psiz1 + 1], &c__1, &c_b29, &z__[mid], &c__1);
12860 	}
12861 	i__2 = psiz2 - bsiz2;
12862 	dcopy_(&i__2, &ztemp[psiz1 + bsiz2 + 1], &c__1, &z__[mid + bsiz2], &
12863 		c__1);
12864 
12865 	i__2 = *tlvls - k;
12866 	ptr += pow_ii(&c__2, &i__2);
12867 /* L70: */
12868     }
12869 
12870     return 0;
12871 
12872 /*     End of DLAEDA */
12873 
12874 } /* dlaeda_ */
12875 
dlaev2_(doublereal * a,doublereal * b,doublereal * c__,doublereal * rt1,doublereal * rt2,doublereal * cs1,doublereal * sn1)12876 /* Subroutine */ int dlaev2_(doublereal *a, doublereal *b, doublereal *c__,
12877 	doublereal *rt1, doublereal *rt2, doublereal *cs1, doublereal *sn1)
12878 {
12879     /* System generated locals */
12880     doublereal d__1;
12881 
12882     /* Local variables */
12883     static doublereal ab, df, cs, ct, tb, sm, tn, rt, adf, acs;
12884     static integer sgn1, sgn2;
12885     static doublereal acmn, acmx;
12886 
12887 
12888 /*
12889     -- LAPACK auxiliary routine (version 3.2) --
12890     -- LAPACK is a software package provided by Univ. of Tennessee,    --
12891     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
12892        November 2006
12893 
12894 
12895     Purpose
12896     =======
12897 
12898     DLAEV2 computes the eigendecomposition of a 2-by-2 symmetric matrix
12899        [  A   B  ]
12900        [  B   C  ].
12901     On return, RT1 is the eigenvalue of larger absolute value, RT2 is the
12902     eigenvalue of smaller absolute value, and (CS1,SN1) is the unit right
12903     eigenvector for RT1, giving the decomposition
12904 
12905        [ CS1  SN1 ] [  A   B  ] [ CS1 -SN1 ]  =  [ RT1  0  ]
12906        [-SN1  CS1 ] [  B   C  ] [ SN1  CS1 ]     [  0  RT2 ].
12907 
12908     Arguments
12909     =========
12910 
12911     A       (input) DOUBLE PRECISION
12912             The (1,1) element of the 2-by-2 matrix.
12913 
12914     B       (input) DOUBLE PRECISION
12915             The (1,2) element and the conjugate of the (2,1) element of
12916             the 2-by-2 matrix.
12917 
12918     C       (input) DOUBLE PRECISION
12919             The (2,2) element of the 2-by-2 matrix.
12920 
12921     RT1     (output) DOUBLE PRECISION
12922             The eigenvalue of larger absolute value.
12923 
12924     RT2     (output) DOUBLE PRECISION
12925             The eigenvalue of smaller absolute value.
12926 
12927     CS1     (output) DOUBLE PRECISION
12928     SN1     (output) DOUBLE PRECISION
12929             The vector (CS1, SN1) is a unit right eigenvector for RT1.
12930 
12931     Further Details
12932     ===============
12933 
12934     RT1 is accurate to a few ulps barring over/underflow.
12935 
12936     RT2 may be inaccurate if there is massive cancellation in the
12937     determinant A*C-B*B; higher precision or correctly rounded or
12938     correctly truncated arithmetic would be needed to compute RT2
12939     accurately in all cases.
12940 
12941     CS1 and SN1 are accurate to a few ulps barring over/underflow.
12942 
12943     Overflow is possible only if RT1 is within a factor of 5 of overflow.
12944     Underflow is harmless if the input data is 0 or exceeds
12945        underflow_threshold / macheps.
12946 
12947    =====================================================================
12948 
12949 
12950        Compute the eigenvalues
12951 */
12952 
12953     sm = *a + *c__;
12954     df = *a - *c__;
12955     adf = abs(df);
12956     tb = *b + *b;
12957     ab = abs(tb);
12958     if (abs(*a) > abs(*c__)) {
12959 	acmx = *a;
12960 	acmn = *c__;
12961     } else {
12962 	acmx = *c__;
12963 	acmn = *a;
12964     }
12965     if (adf > ab) {
12966 /* Computing 2nd power */
12967 	d__1 = ab / adf;
12968 	rt = adf * sqrt(d__1 * d__1 + 1.);
12969     } else if (adf < ab) {
12970 /* Computing 2nd power */
12971 	d__1 = adf / ab;
12972 	rt = ab * sqrt(d__1 * d__1 + 1.);
12973     } else {
12974 
12975 /*        Includes case AB=ADF=0 */
12976 
12977 	rt = ab * sqrt(2.);
12978     }
12979     if (sm < 0.) {
12980 	*rt1 = (sm - rt) * .5;
12981 	sgn1 = -1;
12982 
12983 /*
12984           Order of execution important.
12985           To get fully accurate smaller eigenvalue,
12986           next line needs to be executed in higher precision.
12987 */
12988 
12989 	*rt2 = acmx / *rt1 * acmn - *b / *rt1 * *b;
12990     } else if (sm > 0.) {
12991 	*rt1 = (sm + rt) * .5;
12992 	sgn1 = 1;
12993 
12994 /*
12995           Order of execution important.
12996           To get fully accurate smaller eigenvalue,
12997           next line needs to be executed in higher precision.
12998 */
12999 
13000 	*rt2 = acmx / *rt1 * acmn - *b / *rt1 * *b;
13001     } else {
13002 
13003 /*        Includes case RT1 = RT2 = 0 */
13004 
13005 	*rt1 = rt * .5;
13006 	*rt2 = rt * -.5;
13007 	sgn1 = 1;
13008     }
13009 
13010 /*     Compute the eigenvector */
13011 
13012     if (df >= 0.) {
13013 	cs = df + rt;
13014 	sgn2 = 1;
13015     } else {
13016 	cs = df - rt;
13017 	sgn2 = -1;
13018     }
13019     acs = abs(cs);
13020     if (acs > ab) {
13021 	ct = -tb / cs;
13022 	*sn1 = 1. / sqrt(ct * ct + 1.);
13023 	*cs1 = ct * *sn1;
13024     } else {
13025 	if (ab == 0.) {
13026 	    *cs1 = 1.;
13027 	    *sn1 = 0.;
13028 	} else {
13029 	    tn = -cs / tb;
13030 	    *cs1 = 1. / sqrt(tn * tn + 1.);
13031 	    *sn1 = tn * *cs1;
13032 	}
13033     }
13034     if (sgn1 == sgn2) {
13035 	tn = *cs1;
13036 	*cs1 = -(*sn1);
13037 	*sn1 = tn;
13038     }
13039     return 0;
13040 
13041 /*     End of DLAEV2 */
13042 
13043 } /* dlaev2_ */
13044 
dlaexc_(logical * wantq,integer * n,doublereal * t,integer * ldt,doublereal * q,integer * ldq,integer * j1,integer * n1,integer * n2,doublereal * work,integer * info)13045 /* Subroutine */ int dlaexc_(logical *wantq, integer *n, doublereal *t,
13046 	integer *ldt, doublereal *q, integer *ldq, integer *j1, integer *n1,
13047 	integer *n2, doublereal *work, integer *info)
13048 {
13049     /* System generated locals */
13050     integer q_dim1, q_offset, t_dim1, t_offset, i__1;
13051     doublereal d__1, d__2, d__3;
13052 
13053     /* Local variables */
13054     static doublereal d__[16]	/* was [4][4] */;
13055     static integer k;
13056     static doublereal u[3], x[4]	/* was [2][2] */;
13057     static integer j2, j3, j4;
13058     static doublereal u1[3], u2[3];
13059     static integer nd;
13060     static doublereal cs, t11, t22, t33, sn, wi1, wi2, wr1, wr2, eps, tau,
13061 	    tau1, tau2;
13062     static integer ierr;
13063     static doublereal temp;
13064     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
13065 	    doublereal *, integer *, doublereal *, doublereal *);
13066     static doublereal scale, dnorm, xnorm;
13067     extern /* Subroutine */ int dlanv2_(doublereal *, doublereal *,
13068 	    doublereal *, doublereal *, doublereal *, doublereal *,
13069 	    doublereal *, doublereal *, doublereal *, doublereal *), dlasy2_(
13070 	    logical *, logical *, integer *, integer *, integer *, doublereal
13071 	    *, integer *, doublereal *, integer *, doublereal *, integer *,
13072 	    doublereal *, doublereal *, integer *, doublereal *, integer *);
13073     extern doublereal dlamch_(char *), dlange_(char *, integer *,
13074 	    integer *, doublereal *, integer *, doublereal *);
13075     extern /* Subroutine */ int dlarfg_(integer *, doublereal *, doublereal *,
13076 	     integer *, doublereal *), dlacpy_(char *, integer *, integer *,
13077 	    doublereal *, integer *, doublereal *, integer *),
13078 	    dlartg_(doublereal *, doublereal *, doublereal *, doublereal *,
13079 	    doublereal *), dlarfx_(char *, integer *, integer *, doublereal *,
13080 	     doublereal *, doublereal *, integer *, doublereal *);
13081     static doublereal thresh, smlnum;
13082 
13083 
13084 /*
13085     -- LAPACK auxiliary routine (version 3.2.2) --
13086     -- LAPACK is a software package provided by Univ. of Tennessee,    --
13087     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
13088        June 2010
13089 
13090 
13091     Purpose
13092     =======
13093 
13094     DLAEXC swaps adjacent diagonal blocks T11 and T22 of order 1 or 2 in
13095     an upper quasi-triangular matrix T by an orthogonal similarity
13096     transformation.
13097 
13098     T must be in Schur canonical form, that is, block upper triangular
13099     with 1-by-1 and 2-by-2 diagonal blocks; each 2-by-2 diagonal block
13100     has its diagonal elemnts equal and its off-diagonal elements of
13101     opposite sign.
13102 
13103     Arguments
13104     =========
13105 
13106     WANTQ   (input) LOGICAL
13107             = .TRUE. : accumulate the transformation in the matrix Q;
13108             = .FALSE.: do not accumulate the transformation.
13109 
13110     N       (input) INTEGER
13111             The order of the matrix T. N >= 0.
13112 
13113     T       (input/output) DOUBLE PRECISION array, dimension (LDT,N)
13114             On entry, the upper quasi-triangular matrix T, in Schur
13115             canonical form.
13116             On exit, the updated matrix T, again in Schur canonical form.
13117 
13118     LDT     (input) INTEGER
13119             The leading dimension of the array T. LDT >= max(1,N).
13120 
13121     Q       (input/output) DOUBLE PRECISION array, dimension (LDQ,N)
13122             On entry, if WANTQ is .TRUE., the orthogonal matrix Q.
13123             On exit, if WANTQ is .TRUE., the updated matrix Q.
13124             If WANTQ is .FALSE., Q is not referenced.
13125 
13126     LDQ     (input) INTEGER
13127             The leading dimension of the array Q.
13128             LDQ >= 1; and if WANTQ is .TRUE., LDQ >= N.
13129 
13130     J1      (input) INTEGER
13131             The index of the first row of the first block T11.
13132 
13133     N1      (input) INTEGER
13134             The order of the first block T11. N1 = 0, 1 or 2.
13135 
13136     N2      (input) INTEGER
13137             The order of the second block T22. N2 = 0, 1 or 2.
13138 
13139     WORK    (workspace) DOUBLE PRECISION array, dimension (N)
13140 
13141     INFO    (output) INTEGER
13142             = 0: successful exit
13143             = 1: the transformed matrix T would be too far from Schur
13144                  form; the blocks are not swapped and T and Q are
13145                  unchanged.
13146 
13147     =====================================================================
13148 */
13149 
13150 
13151     /* Parameter adjustments */
13152     t_dim1 = *ldt;
13153     t_offset = 1 + t_dim1;
13154     t -= t_offset;
13155     q_dim1 = *ldq;
13156     q_offset = 1 + q_dim1;
13157     q -= q_offset;
13158     --work;
13159 
13160     /* Function Body */
13161     *info = 0;
13162 
13163 /*     Quick return if possible */
13164 
13165     if (*n == 0 || *n1 == 0 || *n2 == 0) {
13166 	return 0;
13167     }
13168     if (*j1 + *n1 > *n) {
13169 	return 0;
13170     }
13171 
13172     j2 = *j1 + 1;
13173     j3 = *j1 + 2;
13174     j4 = *j1 + 3;
13175 
13176     if (*n1 == 1 && *n2 == 1) {
13177 
13178 /*        Swap two 1-by-1 blocks. */
13179 
13180 	t11 = t[*j1 + *j1 * t_dim1];
13181 	t22 = t[j2 + j2 * t_dim1];
13182 
13183 /*        Determine the transformation to perform the interchange. */
13184 
13185 	d__1 = t22 - t11;
13186 	dlartg_(&t[*j1 + j2 * t_dim1], &d__1, &cs, &sn, &temp);
13187 
13188 /*        Apply transformation to the matrix T. */
13189 
13190 	if (j3 <= *n) {
13191 	    i__1 = *n - *j1 - 1;
13192 	    drot_(&i__1, &t[*j1 + j3 * t_dim1], ldt, &t[j2 + j3 * t_dim1],
13193 		    ldt, &cs, &sn);
13194 	}
13195 	i__1 = *j1 - 1;
13196 	drot_(&i__1, &t[*j1 * t_dim1 + 1], &c__1, &t[j2 * t_dim1 + 1], &c__1,
13197 		&cs, &sn);
13198 
13199 	t[*j1 + *j1 * t_dim1] = t22;
13200 	t[j2 + j2 * t_dim1] = t11;
13201 
13202 	if (*wantq) {
13203 
13204 /*           Accumulate transformation in the matrix Q. */
13205 
13206 	    drot_(n, &q[*j1 * q_dim1 + 1], &c__1, &q[j2 * q_dim1 + 1], &c__1,
13207 		    &cs, &sn);
13208 	}
13209 
13210     } else {
13211 
13212 /*
13213           Swapping involves at least one 2-by-2 block.
13214 
13215           Copy the diagonal block of order N1+N2 to the local array D
13216           and compute its norm.
13217 */
13218 
13219 	nd = *n1 + *n2;
13220 	dlacpy_("Full", &nd, &nd, &t[*j1 + *j1 * t_dim1], ldt, d__, &c__4);
13221 	dnorm = dlange_("Max", &nd, &nd, d__, &c__4, &work[1]);
13222 
13223 /*
13224           Compute machine-dependent threshold for test for accepting
13225           swap.
13226 */
13227 
13228 	eps = PRECISION;
13229 	smlnum = SAFEMINIMUM / eps;
13230 /* Computing MAX */
13231 	d__1 = eps * 10. * dnorm;
13232 	thresh = max(d__1,smlnum);
13233 
13234 /*        Solve T11*X - X*T22 = scale*T12 for X. */
13235 
13236 	dlasy2_(&c_false, &c_false, &c_n1, n1, n2, d__, &c__4, &d__[*n1 + 1 +
13237 		(*n1 + 1 << 2) - 5], &c__4, &d__[(*n1 + 1 << 2) - 4], &c__4, &
13238 		scale, x, &c__2, &xnorm, &ierr);
13239 
13240 /*        Swap the adjacent diagonal blocks. */
13241 
13242 	k = *n1 + *n1 + *n2 - 3;
13243 	switch (k) {
13244 	    case 1:  goto L10;
13245 	    case 2:  goto L20;
13246 	    case 3:  goto L30;
13247 	}
13248 
13249 L10:
13250 
13251 /*
13252           N1 = 1, N2 = 2: generate elementary reflector H so that:
13253 
13254           ( scale, X11, X12 ) H = ( 0, 0, * )
13255 */
13256 
13257 	u[0] = scale;
13258 	u[1] = x[0];
13259 	u[2] = x[2];
13260 	dlarfg_(&c__3, &u[2], u, &c__1, &tau);
13261 	u[2] = 1.;
13262 	t11 = t[*j1 + *j1 * t_dim1];
13263 
13264 /*        Perform swap provisionally on diagonal block in D. */
13265 
13266 	dlarfx_("L", &c__3, &c__3, u, &tau, d__, &c__4, &work[1]);
13267 	dlarfx_("R", &c__3, &c__3, u, &tau, d__, &c__4, &work[1]);
13268 
13269 /*
13270           Test whether to reject swap.
13271 
13272    Computing MAX
13273 */
13274 	d__2 = abs(d__[2]), d__3 = abs(d__[6]), d__2 = max(d__2,d__3), d__3 =
13275 		(d__1 = d__[10] - t11, abs(d__1));
13276 	if (max(d__2,d__3) > thresh) {
13277 	    goto L50;
13278 	}
13279 
13280 /*        Accept swap: apply transformation to the entire matrix T. */
13281 
13282 	i__1 = *n - *j1 + 1;
13283 	dlarfx_("L", &c__3, &i__1, u, &tau, &t[*j1 + *j1 * t_dim1], ldt, &
13284 		work[1]);
13285 	dlarfx_("R", &j2, &c__3, u, &tau, &t[*j1 * t_dim1 + 1], ldt, &work[1]);
13286 
13287 	t[j3 + *j1 * t_dim1] = 0.;
13288 	t[j3 + j2 * t_dim1] = 0.;
13289 	t[j3 + j3 * t_dim1] = t11;
13290 
13291 	if (*wantq) {
13292 
13293 /*           Accumulate transformation in the matrix Q. */
13294 
13295 	    dlarfx_("R", n, &c__3, u, &tau, &q[*j1 * q_dim1 + 1], ldq, &work[
13296 		    1]);
13297 	}
13298 	goto L40;
13299 
13300 L20:
13301 
13302 /*
13303           N1 = 2, N2 = 1: generate elementary reflector H so that:
13304 
13305           H (  -X11 ) = ( * )
13306             (  -X21 ) = ( 0 )
13307             ( scale ) = ( 0 )
13308 */
13309 
13310 	u[0] = -x[0];
13311 	u[1] = -x[1];
13312 	u[2] = scale;
13313 	dlarfg_(&c__3, u, &u[1], &c__1, &tau);
13314 	u[0] = 1.;
13315 	t33 = t[j3 + j3 * t_dim1];
13316 
13317 /*        Perform swap provisionally on diagonal block in D. */
13318 
13319 	dlarfx_("L", &c__3, &c__3, u, &tau, d__, &c__4, &work[1]);
13320 	dlarfx_("R", &c__3, &c__3, u, &tau, d__, &c__4, &work[1]);
13321 
13322 /*
13323           Test whether to reject swap.
13324 
13325    Computing MAX
13326 */
13327 	d__2 = abs(d__[1]), d__3 = abs(d__[2]), d__2 = max(d__2,d__3), d__3 =
13328 		(d__1 = d__[0] - t33, abs(d__1));
13329 	if (max(d__2,d__3) > thresh) {
13330 	    goto L50;
13331 	}
13332 
13333 /*        Accept swap: apply transformation to the entire matrix T. */
13334 
13335 	dlarfx_("R", &j3, &c__3, u, &tau, &t[*j1 * t_dim1 + 1], ldt, &work[1]);
13336 	i__1 = *n - *j1;
13337 	dlarfx_("L", &c__3, &i__1, u, &tau, &t[*j1 + j2 * t_dim1], ldt, &work[
13338 		1]);
13339 
13340 	t[*j1 + *j1 * t_dim1] = t33;
13341 	t[j2 + *j1 * t_dim1] = 0.;
13342 	t[j3 + *j1 * t_dim1] = 0.;
13343 
13344 	if (*wantq) {
13345 
13346 /*           Accumulate transformation in the matrix Q. */
13347 
13348 	    dlarfx_("R", n, &c__3, u, &tau, &q[*j1 * q_dim1 + 1], ldq, &work[
13349 		    1]);
13350 	}
13351 	goto L40;
13352 
13353 L30:
13354 
13355 /*
13356           N1 = 2, N2 = 2: generate elementary reflectors H(1) and H(2) so
13357           that:
13358 
13359           H(2) H(1) (  -X11  -X12 ) = (  *  * )
13360                     (  -X21  -X22 )   (  0  * )
13361                     ( scale    0  )   (  0  0 )
13362                     (    0  scale )   (  0  0 )
13363 */
13364 
13365 	u1[0] = -x[0];
13366 	u1[1] = -x[1];
13367 	u1[2] = scale;
13368 	dlarfg_(&c__3, u1, &u1[1], &c__1, &tau1);
13369 	u1[0] = 1.;
13370 
13371 	temp = -tau1 * (x[2] + u1[1] * x[3]);
13372 	u2[0] = -temp * u1[1] - x[3];
13373 	u2[1] = -temp * u1[2];
13374 	u2[2] = scale;
13375 	dlarfg_(&c__3, u2, &u2[1], &c__1, &tau2);
13376 	u2[0] = 1.;
13377 
13378 /*        Perform swap provisionally on diagonal block in D. */
13379 
13380 	dlarfx_("L", &c__3, &c__4, u1, &tau1, d__, &c__4, &work[1])
13381 		;
13382 	dlarfx_("R", &c__4, &c__3, u1, &tau1, d__, &c__4, &work[1])
13383 		;
13384 	dlarfx_("L", &c__3, &c__4, u2, &tau2, &d__[1], &c__4, &work[1]);
13385 	dlarfx_("R", &c__4, &c__3, u2, &tau2, &d__[4], &c__4, &work[1]);
13386 
13387 /*
13388           Test whether to reject swap.
13389 
13390    Computing MAX
13391 */
13392 	d__1 = abs(d__[2]), d__2 = abs(d__[6]), d__1 = max(d__1,d__2), d__2 =
13393 		abs(d__[3]), d__1 = max(d__1,d__2), d__2 = abs(d__[7]);
13394 	if (max(d__1,d__2) > thresh) {
13395 	    goto L50;
13396 	}
13397 
13398 /*        Accept swap: apply transformation to the entire matrix T. */
13399 
13400 	i__1 = *n - *j1 + 1;
13401 	dlarfx_("L", &c__3, &i__1, u1, &tau1, &t[*j1 + *j1 * t_dim1], ldt, &
13402 		work[1]);
13403 	dlarfx_("R", &j4, &c__3, u1, &tau1, &t[*j1 * t_dim1 + 1], ldt, &work[
13404 		1]);
13405 	i__1 = *n - *j1 + 1;
13406 	dlarfx_("L", &c__3, &i__1, u2, &tau2, &t[j2 + *j1 * t_dim1], ldt, &
13407 		work[1]);
13408 	dlarfx_("R", &j4, &c__3, u2, &tau2, &t[j2 * t_dim1 + 1], ldt, &work[1]
13409 		);
13410 
13411 	t[j3 + *j1 * t_dim1] = 0.;
13412 	t[j3 + j2 * t_dim1] = 0.;
13413 	t[j4 + *j1 * t_dim1] = 0.;
13414 	t[j4 + j2 * t_dim1] = 0.;
13415 
13416 	if (*wantq) {
13417 
13418 /*           Accumulate transformation in the matrix Q. */
13419 
13420 	    dlarfx_("R", n, &c__3, u1, &tau1, &q[*j1 * q_dim1 + 1], ldq, &
13421 		    work[1]);
13422 	    dlarfx_("R", n, &c__3, u2, &tau2, &q[j2 * q_dim1 + 1], ldq, &work[
13423 		    1]);
13424 	}
13425 
13426 L40:
13427 
13428 	if (*n2 == 2) {
13429 
13430 /*           Standardize new 2-by-2 block T11 */
13431 
13432 	    dlanv2_(&t[*j1 + *j1 * t_dim1], &t[*j1 + j2 * t_dim1], &t[j2 + *
13433 		    j1 * t_dim1], &t[j2 + j2 * t_dim1], &wr1, &wi1, &wr2, &
13434 		    wi2, &cs, &sn);
13435 	    i__1 = *n - *j1 - 1;
13436 	    drot_(&i__1, &t[*j1 + (*j1 + 2) * t_dim1], ldt, &t[j2 + (*j1 + 2)
13437 		    * t_dim1], ldt, &cs, &sn);
13438 	    i__1 = *j1 - 1;
13439 	    drot_(&i__1, &t[*j1 * t_dim1 + 1], &c__1, &t[j2 * t_dim1 + 1], &
13440 		    c__1, &cs, &sn);
13441 	    if (*wantq) {
13442 		drot_(n, &q[*j1 * q_dim1 + 1], &c__1, &q[j2 * q_dim1 + 1], &
13443 			c__1, &cs, &sn);
13444 	    }
13445 	}
13446 
13447 	if (*n1 == 2) {
13448 
13449 /*           Standardize new 2-by-2 block T22 */
13450 
13451 	    j3 = *j1 + *n2;
13452 	    j4 = j3 + 1;
13453 	    dlanv2_(&t[j3 + j3 * t_dim1], &t[j3 + j4 * t_dim1], &t[j4 + j3 *
13454 		    t_dim1], &t[j4 + j4 * t_dim1], &wr1, &wi1, &wr2, &wi2, &
13455 		    cs, &sn);
13456 	    if (j3 + 2 <= *n) {
13457 		i__1 = *n - j3 - 1;
13458 		drot_(&i__1, &t[j3 + (j3 + 2) * t_dim1], ldt, &t[j4 + (j3 + 2)
13459 			 * t_dim1], ldt, &cs, &sn);
13460 	    }
13461 	    i__1 = j3 - 1;
13462 	    drot_(&i__1, &t[j3 * t_dim1 + 1], &c__1, &t[j4 * t_dim1 + 1], &
13463 		    c__1, &cs, &sn);
13464 	    if (*wantq) {
13465 		drot_(n, &q[j3 * q_dim1 + 1], &c__1, &q[j4 * q_dim1 + 1], &
13466 			c__1, &cs, &sn);
13467 	    }
13468 	}
13469 
13470     }
13471     return 0;
13472 
13473 /*     Exit with INFO = 1 if swap was rejected. */
13474 
13475 L50:
13476     *info = 1;
13477     return 0;
13478 
13479 /*     End of DLAEXC */
13480 
13481 } /* dlaexc_ */
13482 
dlahqr_(logical * wantt,logical * wantz,integer * n,integer * ilo,integer * ihi,doublereal * h__,integer * ldh,doublereal * wr,doublereal * wi,integer * iloz,integer * ihiz,doublereal * z__,integer * ldz,integer * info)13483 /* Subroutine */ int dlahqr_(logical *wantt, logical *wantz, integer *n,
13484 	integer *ilo, integer *ihi, doublereal *h__, integer *ldh, doublereal
13485 	*wr, doublereal *wi, integer *iloz, integer *ihiz, doublereal *z__,
13486 	integer *ldz, integer *info)
13487 {
13488     /* System generated locals */
13489     integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3;
13490     doublereal d__1, d__2, d__3, d__4;
13491 
13492     /* Local variables */
13493     static integer i__, j, k, l, m;
13494     static doublereal s, v[3];
13495     static integer i1, i2;
13496     static doublereal t1, t2, t3, v2, v3, aa, ab, ba, bb, h11, h12, h21, h22,
13497 	    cs;
13498     static integer nh;
13499     static doublereal sn;
13500     static integer nr;
13501     static doublereal tr;
13502     static integer nz;
13503     static doublereal det, h21s;
13504     static integer its;
13505     static doublereal ulp, sum, tst, rt1i, rt2i, rt1r, rt2r;
13506     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
13507 	    doublereal *, integer *, doublereal *, doublereal *), dcopy_(
13508 	    integer *, doublereal *, integer *, doublereal *, integer *),
13509 	    dlanv2_(doublereal *, doublereal *, doublereal *, doublereal *,
13510 	    doublereal *, doublereal *, doublereal *, doublereal *,
13511 	    doublereal *, doublereal *), dlabad_(doublereal *, doublereal *);
13512 
13513     extern /* Subroutine */ int dlarfg_(integer *, doublereal *, doublereal *,
13514 	     integer *, doublereal *);
13515     static doublereal safmin, safmax, rtdisc, smlnum;
13516 
13517 
13518 /*
13519     -- LAPACK auxiliary routine (version 3.2) --
13520        Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
13521        November 2006
13522 
13523 
13524        Purpose
13525        =======
13526 
13527        DLAHQR is an auxiliary routine called by DHSEQR to update the
13528        eigenvalues and Schur decomposition already computed by DHSEQR, by
13529        dealing with the Hessenberg submatrix in rows and columns ILO to
13530        IHI.
13531 
13532        Arguments
13533        =========
13534 
13535        WANTT   (input) LOGICAL
13536             = .TRUE. : the full Schur form T is required;
13537             = .FALSE.: only eigenvalues are required.
13538 
13539        WANTZ   (input) LOGICAL
13540             = .TRUE. : the matrix of Schur vectors Z is required;
13541             = .FALSE.: Schur vectors are not required.
13542 
13543        N       (input) INTEGER
13544             The order of the matrix H.  N >= 0.
13545 
13546        ILO     (input) INTEGER
13547        IHI     (input) INTEGER
13548             It is assumed that H is already upper quasi-triangular in
13549             rows and columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless
13550             ILO = 1). DLAHQR works primarily with the Hessenberg
13551             submatrix in rows and columns ILO to IHI, but applies
13552             transformations to all of H if WANTT is .TRUE..
13553             1 <= ILO <= max(1,IHI); IHI <= N.
13554 
13555        H       (input/output) DOUBLE PRECISION array, dimension (LDH,N)
13556             On entry, the upper Hessenberg matrix H.
13557             On exit, if INFO is zero and if WANTT is .TRUE., H is upper
13558             quasi-triangular in rows and columns ILO:IHI, with any
13559             2-by-2 diagonal blocks in standard form. If INFO is zero
13560             and WANTT is .FALSE., the contents of H are unspecified on
13561             exit.  The output state of H if INFO is nonzero is given
13562             below under the description of INFO.
13563 
13564        LDH     (input) INTEGER
13565             The leading dimension of the array H. LDH >= max(1,N).
13566 
13567        WR      (output) DOUBLE PRECISION array, dimension (N)
13568        WI      (output) DOUBLE PRECISION array, dimension (N)
13569             The real and imaginary parts, respectively, of the computed
13570             eigenvalues ILO to IHI are stored in the corresponding
13571             elements of WR and WI. If two eigenvalues are computed as a
13572             complex conjugate pair, they are stored in consecutive
13573             elements of WR and WI, say the i-th and (i+1)th, with
13574             WI(i) > 0 and WI(i+1) < 0. If WANTT is .TRUE., the
13575             eigenvalues are stored in the same order as on the diagonal
13576             of the Schur form returned in H, with WR(i) = H(i,i), and, if
13577             H(i:i+1,i:i+1) is a 2-by-2 diagonal block,
13578             WI(i) = sqrt(H(i+1,i)*H(i,i+1)) and WI(i+1) = -WI(i).
13579 
13580        ILOZ    (input) INTEGER
13581        IHIZ    (input) INTEGER
13582             Specify the rows of Z to which transformations must be
13583             applied if WANTZ is .TRUE..
13584             1 <= ILOZ <= ILO; IHI <= IHIZ <= N.
13585 
13586        Z       (input/output) DOUBLE PRECISION array, dimension (LDZ,N)
13587             If WANTZ is .TRUE., on entry Z must contain the current
13588             matrix Z of transformations accumulated by DHSEQR, and on
13589             exit Z has been updated; transformations are applied only to
13590             the submatrix Z(ILOZ:IHIZ,ILO:IHI).
13591             If WANTZ is .FALSE., Z is not referenced.
13592 
13593        LDZ     (input) INTEGER
13594             The leading dimension of the array Z. LDZ >= max(1,N).
13595 
13596        INFO    (output) INTEGER
13597              =   0: successful exit
13598             .GT. 0: If INFO = i, DLAHQR failed to compute all the
13599                     eigenvalues ILO to IHI in a total of 30 iterations
13600                     per eigenvalue; elements i+1:ihi of WR and WI
13601                     contain those eigenvalues which have been
13602                     successfully computed.
13603 
13604                     If INFO .GT. 0 and WANTT is .FALSE., then on exit,
13605                     the remaining unconverged eigenvalues are the
13606                     eigenvalues of the upper Hessenberg matrix rows
13607                     and columns ILO thorugh INFO of the final, output
13608                     value of H.
13609 
13610                     If INFO .GT. 0 and WANTT is .TRUE., then on exit
13611             (*)       (initial value of H)*U  = U*(final value of H)
13612                     where U is an orthognal matrix.    The final
13613                     value of H is upper Hessenberg and triangular in
13614                     rows and columns INFO+1 through IHI.
13615 
13616                     If INFO .GT. 0 and WANTZ is .TRUE., then on exit
13617                         (final value of Z)  = (initial value of Z)*U
13618                     where U is the orthogonal matrix in (*)
13619                     (regardless of the value of WANTT.)
13620 
13621        Further Details
13622        ===============
13623 
13624        02-96 Based on modifications by
13625        David Day, Sandia National Laboratory, USA
13626 
13627        12-04 Further modifications by
13628        Ralph Byers, University of Kansas, USA
13629        This is a modified version of DLAHQR from LAPACK version 3.0.
13630        It is (1) more robust against overflow and underflow and
13631        (2) adopts the more conservative Ahues & Tisseur stopping
13632        criterion (LAWN 122, 1997).
13633 
13634        =========================================================
13635 */
13636 
13637 
13638     /* Parameter adjustments */
13639     h_dim1 = *ldh;
13640     h_offset = 1 + h_dim1;
13641     h__ -= h_offset;
13642     --wr;
13643     --wi;
13644     z_dim1 = *ldz;
13645     z_offset = 1 + z_dim1;
13646     z__ -= z_offset;
13647 
13648     /* Function Body */
13649     *info = 0;
13650 
13651 /*     Quick return if possible */
13652 
13653     if (*n == 0) {
13654 	return 0;
13655     }
13656     if (*ilo == *ihi) {
13657 	wr[*ilo] = h__[*ilo + *ilo * h_dim1];
13658 	wi[*ilo] = 0.;
13659 	return 0;
13660     }
13661 
13662 /*     ==== clear out the trash ==== */
13663     i__1 = *ihi - 3;
13664     for (j = *ilo; j <= i__1; ++j) {
13665 	h__[j + 2 + j * h_dim1] = 0.;
13666 	h__[j + 3 + j * h_dim1] = 0.;
13667 /* L10: */
13668     }
13669     if (*ilo <= *ihi - 2) {
13670 	h__[*ihi + (*ihi - 2) * h_dim1] = 0.;
13671     }
13672 
13673     nh = *ihi - *ilo + 1;
13674     nz = *ihiz - *iloz + 1;
13675 
13676 /*     Set machine-dependent constants for the stopping criterion. */
13677 
13678     safmin = SAFEMINIMUM;
13679     safmax = 1. / safmin;
13680     dlabad_(&safmin, &safmax);
13681     ulp = PRECISION;
13682     smlnum = safmin * ((doublereal) nh / ulp);
13683 
13684 /*
13685        I1 and I2 are the indices of the first row and last column of H
13686        to which transformations must be applied. If eigenvalues only are
13687        being computed, I1 and I2 are set inside the main loop.
13688 */
13689 
13690     if (*wantt) {
13691 	i1 = 1;
13692 	i2 = *n;
13693     }
13694 
13695 /*
13696        The main loop begins here. I is the loop index and decreases from
13697        IHI to ILO in steps of 1 or 2. Each iteration of the loop works
13698        with the active submatrix in rows and columns L to I.
13699        Eigenvalues I+1 to IHI have already converged. Either L = ILO or
13700        H(L,L-1) is negligible so that the matrix splits.
13701 */
13702 
13703     i__ = *ihi;
13704 L20:
13705     l = *ilo;
13706     if (i__ < *ilo) {
13707 	goto L160;
13708     }
13709 
13710 /*
13711        Perform QR iterations on rows and columns ILO to I until a
13712        submatrix of order 1 or 2 splits off at the bottom because a
13713        subdiagonal element has become negligible.
13714 */
13715 
13716     for (its = 0; its <= 30; ++its) {
13717 
13718 /*        Look for a single small subdiagonal element. */
13719 
13720 	i__1 = l + 1;
13721 	for (k = i__; k >= i__1; --k) {
13722 	    if ((d__1 = h__[k + (k - 1) * h_dim1], abs(d__1)) <= smlnum) {
13723 		goto L40;
13724 	    }
13725 	    tst = (d__1 = h__[k - 1 + (k - 1) * h_dim1], abs(d__1)) + (d__2 =
13726 		    h__[k + k * h_dim1], abs(d__2));
13727 	    if (tst == 0.) {
13728 		if (k - 2 >= *ilo) {
13729 		    tst += (d__1 = h__[k - 1 + (k - 2) * h_dim1], abs(d__1));
13730 		}
13731 		if (k + 1 <= *ihi) {
13732 		    tst += (d__1 = h__[k + 1 + k * h_dim1], abs(d__1));
13733 		}
13734 	    }
13735 /*
13736              ==== The following is a conservative small subdiagonal
13737              .    deflation  criterion due to Ahues & Tisseur (LAWN 122,
13738              .    1997). It has better mathematical foundation and
13739              .    improves accuracy in some cases.  ====
13740 */
13741 	    if ((d__1 = h__[k + (k - 1) * h_dim1], abs(d__1)) <= ulp * tst) {
13742 /* Computing MAX */
13743 		d__3 = (d__1 = h__[k + (k - 1) * h_dim1], abs(d__1)), d__4 = (
13744 			d__2 = h__[k - 1 + k * h_dim1], abs(d__2));
13745 		ab = max(d__3,d__4);
13746 /* Computing MIN */
13747 		d__3 = (d__1 = h__[k + (k - 1) * h_dim1], abs(d__1)), d__4 = (
13748 			d__2 = h__[k - 1 + k * h_dim1], abs(d__2));
13749 		ba = min(d__3,d__4);
13750 /* Computing MAX */
13751 		d__3 = (d__1 = h__[k + k * h_dim1], abs(d__1)), d__4 = (d__2 =
13752 			 h__[k - 1 + (k - 1) * h_dim1] - h__[k + k * h_dim1],
13753 			abs(d__2));
13754 		aa = max(d__3,d__4);
13755 /* Computing MIN */
13756 		d__3 = (d__1 = h__[k + k * h_dim1], abs(d__1)), d__4 = (d__2 =
13757 			 h__[k - 1 + (k - 1) * h_dim1] - h__[k + k * h_dim1],
13758 			abs(d__2));
13759 		bb = min(d__3,d__4);
13760 		s = aa + ab;
13761 /* Computing MAX */
13762 		d__1 = smlnum, d__2 = ulp * (bb * (aa / s));
13763 		if (ba * (ab / s) <= max(d__1,d__2)) {
13764 		    goto L40;
13765 		}
13766 	    }
13767 /* L30: */
13768 	}
13769 L40:
13770 	l = k;
13771 	if (l > *ilo) {
13772 
13773 /*           H(L,L-1) is negligible */
13774 
13775 	    h__[l + (l - 1) * h_dim1] = 0.;
13776 	}
13777 
13778 /*        Exit from loop if a submatrix of order 1 or 2 has split off. */
13779 
13780 	if (l >= i__ - 1) {
13781 	    goto L150;
13782 	}
13783 
13784 /*
13785           Now the active submatrix is in rows and columns L to I. If
13786           eigenvalues only are being computed, only the active submatrix
13787           need be transformed.
13788 */
13789 
13790 	if (! (*wantt)) {
13791 	    i1 = l;
13792 	    i2 = i__;
13793 	}
13794 
13795 	if (its == 10) {
13796 
13797 /*           Exceptional shift. */
13798 
13799 	    s = (d__1 = h__[l + 1 + l * h_dim1], abs(d__1)) + (d__2 = h__[l +
13800 		    2 + (l + 1) * h_dim1], abs(d__2));
13801 	    h11 = s * .75 + h__[l + l * h_dim1];
13802 	    h12 = s * -.4375;
13803 	    h21 = s;
13804 	    h22 = h11;
13805 	} else if (its == 20) {
13806 
13807 /*           Exceptional shift. */
13808 
13809 	    s = (d__1 = h__[i__ + (i__ - 1) * h_dim1], abs(d__1)) + (d__2 =
13810 		    h__[i__ - 1 + (i__ - 2) * h_dim1], abs(d__2));
13811 	    h11 = s * .75 + h__[i__ + i__ * h_dim1];
13812 	    h12 = s * -.4375;
13813 	    h21 = s;
13814 	    h22 = h11;
13815 	} else {
13816 
13817 /*
13818              Prepare to use Francis' double shift
13819              (i.e. 2nd degree generalized Rayleigh quotient)
13820 */
13821 
13822 	    h11 = h__[i__ - 1 + (i__ - 1) * h_dim1];
13823 	    h21 = h__[i__ + (i__ - 1) * h_dim1];
13824 	    h12 = h__[i__ - 1 + i__ * h_dim1];
13825 	    h22 = h__[i__ + i__ * h_dim1];
13826 	}
13827 	s = abs(h11) + abs(h12) + abs(h21) + abs(h22);
13828 	if (s == 0.) {
13829 	    rt1r = 0.;
13830 	    rt1i = 0.;
13831 	    rt2r = 0.;
13832 	    rt2i = 0.;
13833 	} else {
13834 	    h11 /= s;
13835 	    h21 /= s;
13836 	    h12 /= s;
13837 	    h22 /= s;
13838 	    tr = (h11 + h22) / 2.;
13839 	    det = (h11 - tr) * (h22 - tr) - h12 * h21;
13840 	    rtdisc = sqrt((abs(det)));
13841 	    if (det >= 0.) {
13842 
13843 /*              ==== complex conjugate shifts ==== */
13844 
13845 		rt1r = tr * s;
13846 		rt2r = rt1r;
13847 		rt1i = rtdisc * s;
13848 		rt2i = -rt1i;
13849 	    } else {
13850 
13851 /*              ==== real shifts (use only one of them)  ==== */
13852 
13853 		rt1r = tr + rtdisc;
13854 		rt2r = tr - rtdisc;
13855 		if ((d__1 = rt1r - h22, abs(d__1)) <= (d__2 = rt2r - h22, abs(
13856 			d__2))) {
13857 		    rt1r *= s;
13858 		    rt2r = rt1r;
13859 		} else {
13860 		    rt2r *= s;
13861 		    rt1r = rt2r;
13862 		}
13863 		rt1i = 0.;
13864 		rt2i = 0.;
13865 	    }
13866 	}
13867 
13868 /*        Look for two consecutive small subdiagonal elements. */
13869 
13870 	i__1 = l;
13871 	for (m = i__ - 2; m >= i__1; --m) {
13872 /*
13873              Determine the effect of starting the double-shift QR
13874              iteration at row M, and see if this would make H(M,M-1)
13875              negligible.  (The following uses scaling to avoid
13876              overflows and most underflows.)
13877 */
13878 
13879 	    h21s = h__[m + 1 + m * h_dim1];
13880 	    s = (d__1 = h__[m + m * h_dim1] - rt2r, abs(d__1)) + abs(rt2i) +
13881 		    abs(h21s);
13882 	    h21s = h__[m + 1 + m * h_dim1] / s;
13883 	    v[0] = h21s * h__[m + (m + 1) * h_dim1] + (h__[m + m * h_dim1] -
13884 		    rt1r) * ((h__[m + m * h_dim1] - rt2r) / s) - rt1i * (rt2i
13885 		    / s);
13886 	    v[1] = h21s * (h__[m + m * h_dim1] + h__[m + 1 + (m + 1) * h_dim1]
13887 		     - rt1r - rt2r);
13888 	    v[2] = h21s * h__[m + 2 + (m + 1) * h_dim1];
13889 	    s = abs(v[0]) + abs(v[1]) + abs(v[2]);
13890 	    v[0] /= s;
13891 	    v[1] /= s;
13892 	    v[2] /= s;
13893 	    if (m == l) {
13894 		goto L60;
13895 	    }
13896 	    if ((d__1 = h__[m + (m - 1) * h_dim1], abs(d__1)) * (abs(v[1]) +
13897 		    abs(v[2])) <= ulp * abs(v[0]) * ((d__2 = h__[m - 1 + (m -
13898 		    1) * h_dim1], abs(d__2)) + (d__3 = h__[m + m * h_dim1],
13899 		    abs(d__3)) + (d__4 = h__[m + 1 + (m + 1) * h_dim1], abs(
13900 		    d__4)))) {
13901 		goto L60;
13902 	    }
13903 /* L50: */
13904 	}
13905 L60:
13906 
13907 /*        Double-shift QR step */
13908 
13909 	i__1 = i__ - 1;
13910 	for (k = m; k <= i__1; ++k) {
13911 
13912 /*
13913              The first iteration of this loop determines a reflection G
13914              from the vector V and applies it from left and right to H,
13915              thus creating a nonzero bulge below the subdiagonal.
13916 
13917              Each subsequent iteration determines a reflection G to
13918              restore the Hessenberg form in the (K-1)th column, and thus
13919              chases the bulge one step toward the bottom of the active
13920              submatrix. NR is the order of G.
13921 
13922    Computing MIN
13923 */
13924 	    i__2 = 3, i__3 = i__ - k + 1;
13925 	    nr = min(i__2,i__3);
13926 	    if (k > m) {
13927 		dcopy_(&nr, &h__[k + (k - 1) * h_dim1], &c__1, v, &c__1);
13928 	    }
13929 	    dlarfg_(&nr, v, &v[1], &c__1, &t1);
13930 	    if (k > m) {
13931 		h__[k + (k - 1) * h_dim1] = v[0];
13932 		h__[k + 1 + (k - 1) * h_dim1] = 0.;
13933 		if (k < i__ - 1) {
13934 		    h__[k + 2 + (k - 1) * h_dim1] = 0.;
13935 		}
13936 	    } else if (m > l) {
13937 /*
13938                  ==== Use the following instead of
13939                  .    H( K, K-1 ) = -H( K, K-1 ) to
13940                  .    avoid a bug when v(2) and v(3)
13941                  .    underflow. ====
13942 */
13943 		h__[k + (k - 1) * h_dim1] *= 1. - t1;
13944 	    }
13945 	    v2 = v[1];
13946 	    t2 = t1 * v2;
13947 	    if (nr == 3) {
13948 		v3 = v[2];
13949 		t3 = t1 * v3;
13950 
13951 /*
13952                 Apply G from the left to transform the rows of the matrix
13953                 in columns K to I2.
13954 */
13955 
13956 		i__2 = i2;
13957 		for (j = k; j <= i__2; ++j) {
13958 		    sum = h__[k + j * h_dim1] + v2 * h__[k + 1 + j * h_dim1]
13959 			    + v3 * h__[k + 2 + j * h_dim1];
13960 		    h__[k + j * h_dim1] -= sum * t1;
13961 		    h__[k + 1 + j * h_dim1] -= sum * t2;
13962 		    h__[k + 2 + j * h_dim1] -= sum * t3;
13963 /* L70: */
13964 		}
13965 
13966 /*
13967                 Apply G from the right to transform the columns of the
13968                 matrix in rows I1 to min(K+3,I).
13969 
13970    Computing MIN
13971 */
13972 		i__3 = k + 3;
13973 		i__2 = min(i__3,i__);
13974 		for (j = i1; j <= i__2; ++j) {
13975 		    sum = h__[j + k * h_dim1] + v2 * h__[j + (k + 1) * h_dim1]
13976 			     + v3 * h__[j + (k + 2) * h_dim1];
13977 		    h__[j + k * h_dim1] -= sum * t1;
13978 		    h__[j + (k + 1) * h_dim1] -= sum * t2;
13979 		    h__[j + (k + 2) * h_dim1] -= sum * t3;
13980 /* L80: */
13981 		}
13982 
13983 		if (*wantz) {
13984 
13985 /*                 Accumulate transformations in the matrix Z */
13986 
13987 		    i__2 = *ihiz;
13988 		    for (j = *iloz; j <= i__2; ++j) {
13989 			sum = z__[j + k * z_dim1] + v2 * z__[j + (k + 1) *
13990 				z_dim1] + v3 * z__[j + (k + 2) * z_dim1];
13991 			z__[j + k * z_dim1] -= sum * t1;
13992 			z__[j + (k + 1) * z_dim1] -= sum * t2;
13993 			z__[j + (k + 2) * z_dim1] -= sum * t3;
13994 /* L90: */
13995 		    }
13996 		}
13997 	    } else if (nr == 2) {
13998 
13999 /*
14000                 Apply G from the left to transform the rows of the matrix
14001                 in columns K to I2.
14002 */
14003 
14004 		i__2 = i2;
14005 		for (j = k; j <= i__2; ++j) {
14006 		    sum = h__[k + j * h_dim1] + v2 * h__[k + 1 + j * h_dim1];
14007 		    h__[k + j * h_dim1] -= sum * t1;
14008 		    h__[k + 1 + j * h_dim1] -= sum * t2;
14009 /* L100: */
14010 		}
14011 
14012 /*
14013                 Apply G from the right to transform the columns of the
14014                 matrix in rows I1 to min(K+3,I).
14015 */
14016 
14017 		i__2 = i__;
14018 		for (j = i1; j <= i__2; ++j) {
14019 		    sum = h__[j + k * h_dim1] + v2 * h__[j + (k + 1) * h_dim1]
14020 			    ;
14021 		    h__[j + k * h_dim1] -= sum * t1;
14022 		    h__[j + (k + 1) * h_dim1] -= sum * t2;
14023 /* L110: */
14024 		}
14025 
14026 		if (*wantz) {
14027 
14028 /*                 Accumulate transformations in the matrix Z */
14029 
14030 		    i__2 = *ihiz;
14031 		    for (j = *iloz; j <= i__2; ++j) {
14032 			sum = z__[j + k * z_dim1] + v2 * z__[j + (k + 1) *
14033 				z_dim1];
14034 			z__[j + k * z_dim1] -= sum * t1;
14035 			z__[j + (k + 1) * z_dim1] -= sum * t2;
14036 /* L120: */
14037 		    }
14038 		}
14039 	    }
14040 /* L130: */
14041 	}
14042 
14043 /* L140: */
14044     }
14045 
14046 /*     Failure to converge in remaining number of iterations */
14047 
14048     *info = i__;
14049     return 0;
14050 
14051 L150:
14052 
14053     if (l == i__) {
14054 
14055 /*        H(I,I-1) is negligible: one eigenvalue has converged. */
14056 
14057 	wr[i__] = h__[i__ + i__ * h_dim1];
14058 	wi[i__] = 0.;
14059     } else if (l == i__ - 1) {
14060 
14061 /*
14062           H(I-1,I-2) is negligible: a pair of eigenvalues have converged.
14063 
14064           Transform the 2-by-2 submatrix to standard Schur form,
14065           and compute and store the eigenvalues.
14066 */
14067 
14068 	dlanv2_(&h__[i__ - 1 + (i__ - 1) * h_dim1], &h__[i__ - 1 + i__ *
14069 		h_dim1], &h__[i__ + (i__ - 1) * h_dim1], &h__[i__ + i__ *
14070 		h_dim1], &wr[i__ - 1], &wi[i__ - 1], &wr[i__], &wi[i__], &cs,
14071 		&sn);
14072 
14073 	if (*wantt) {
14074 
14075 /*           Apply the transformation to the rest of H. */
14076 
14077 	    if (i2 > i__) {
14078 		i__1 = i2 - i__;
14079 		drot_(&i__1, &h__[i__ - 1 + (i__ + 1) * h_dim1], ldh, &h__[
14080 			i__ + (i__ + 1) * h_dim1], ldh, &cs, &sn);
14081 	    }
14082 	    i__1 = i__ - i1 - 1;
14083 	    drot_(&i__1, &h__[i1 + (i__ - 1) * h_dim1], &c__1, &h__[i1 + i__ *
14084 		     h_dim1], &c__1, &cs, &sn);
14085 	}
14086 	if (*wantz) {
14087 
14088 /*           Apply the transformation to Z. */
14089 
14090 	    drot_(&nz, &z__[*iloz + (i__ - 1) * z_dim1], &c__1, &z__[*iloz +
14091 		    i__ * z_dim1], &c__1, &cs, &sn);
14092 	}
14093     }
14094 
14095 /*     return to start of the main loop with new value of I. */
14096 
14097     i__ = l - 1;
14098     goto L20;
14099 
14100 L160:
14101     return 0;
14102 
14103 /*     End of DLAHQR */
14104 
14105 } /* dlahqr_ */
14106 
dlahr2_(integer * n,integer * k,integer * nb,doublereal * a,integer * lda,doublereal * tau,doublereal * t,integer * ldt,doublereal * y,integer * ldy)14107 /* Subroutine */ int dlahr2_(integer *n, integer *k, integer *nb, doublereal *
14108 	a, integer *lda, doublereal *tau, doublereal *t, integer *ldt,
14109 	doublereal *y, integer *ldy)
14110 {
14111     /* System generated locals */
14112     integer a_dim1, a_offset, t_dim1, t_offset, y_dim1, y_offset, i__1, i__2,
14113 	    i__3;
14114     doublereal d__1;
14115 
14116     /* Local variables */
14117     static integer i__;
14118     static doublereal ei;
14119     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
14120 	    integer *), dgemm_(char *, char *, integer *, integer *, integer *
14121 	    , doublereal *, doublereal *, integer *, doublereal *, integer *,
14122 	    doublereal *, doublereal *, integer *), dgemv_(
14123 	    char *, integer *, integer *, doublereal *, doublereal *, integer
14124 	    *, doublereal *, integer *, doublereal *, doublereal *, integer *), dcopy_(integer *, doublereal *, integer *, doublereal *,
14125 	     integer *), dtrmm_(char *, char *, char *, char *, integer *,
14126 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
14127 	    integer *), daxpy_(integer *,
14128 	    doublereal *, doublereal *, integer *, doublereal *, integer *),
14129 	    dtrmv_(char *, char *, char *, integer *, doublereal *, integer *,
14130 	     doublereal *, integer *), dlarfg_(
14131 	    integer *, doublereal *, doublereal *, integer *, doublereal *),
14132 	    dlacpy_(char *, integer *, integer *, doublereal *, integer *,
14133 	    doublereal *, integer *);
14134 
14135 
14136 /*
14137     -- LAPACK auxiliary routine (version 3.2.1)                        --
14138     -- LAPACK is a software package provided by Univ. of Tennessee,    --
14139     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
14140     -- April 2009                                                      --
14141 
14142 
14143     Purpose
14144     =======
14145 
14146     DLAHR2 reduces the first NB columns of A real general n-BY-(n-k+1)
14147     matrix A so that elements below the k-th subdiagonal are zero. The
14148     reduction is performed by an orthogonal similarity transformation
14149     Q' * A * Q. The routine returns the matrices V and T which determine
14150     Q as a block reflector I - V*T*V', and also the matrix Y = A * V * T.
14151 
14152     This is an auxiliary routine called by DGEHRD.
14153 
14154     Arguments
14155     =========
14156 
14157     N       (input) INTEGER
14158             The order of the matrix A.
14159 
14160     K       (input) INTEGER
14161             The offset for the reduction. Elements below the k-th
14162             subdiagonal in the first NB columns are reduced to zero.
14163             K < N.
14164 
14165     NB      (input) INTEGER
14166             The number of columns to be reduced.
14167 
14168     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N-K+1)
14169             On entry, the n-by-(n-k+1) general matrix A.
14170             On exit, the elements on and above the k-th subdiagonal in
14171             the first NB columns are overwritten with the corresponding
14172             elements of the reduced matrix; the elements below the k-th
14173             subdiagonal, with the array TAU, represent the matrix Q as a
14174             product of elementary reflectors. The other columns of A are
14175             unchanged. See Further Details.
14176 
14177     LDA     (input) INTEGER
14178             The leading dimension of the array A.  LDA >= max(1,N).
14179 
14180     TAU     (output) DOUBLE PRECISION array, dimension (NB)
14181             The scalar factors of the elementary reflectors. See Further
14182             Details.
14183 
14184     T       (output) DOUBLE PRECISION array, dimension (LDT,NB)
14185             The upper triangular matrix T.
14186 
14187     LDT     (input) INTEGER
14188             The leading dimension of the array T.  LDT >= NB.
14189 
14190     Y       (output) DOUBLE PRECISION array, dimension (LDY,NB)
14191             The n-by-nb matrix Y.
14192 
14193     LDY     (input) INTEGER
14194             The leading dimension of the array Y. LDY >= N.
14195 
14196     Further Details
14197     ===============
14198 
14199     The matrix Q is represented as a product of nb elementary reflectors
14200 
14201        Q = H(1) H(2) . . . H(nb).
14202 
14203     Each H(i) has the form
14204 
14205        H(i) = I - tau * v * v'
14206 
14207     where tau is a real scalar, and v is a real vector with
14208     v(1:i+k-1) = 0, v(i+k) = 1; v(i+k+1:n) is stored on exit in
14209     A(i+k+1:n,i), and tau in TAU(i).
14210 
14211     The elements of the vectors v together form the (n-k+1)-by-nb matrix
14212     V which is needed, with T and Y, to apply the transformation to the
14213     unreduced part of the matrix, using an update of the form:
14214     A := (I - V*T*V') * (A - Y*V').
14215 
14216     The contents of A on exit are illustrated by the following example
14217     with n = 7, k = 3 and nb = 2:
14218 
14219        ( a   a   a   a   a )
14220        ( a   a   a   a   a )
14221        ( a   a   a   a   a )
14222        ( h   h   a   a   a )
14223        ( v1  h   a   a   a )
14224        ( v1  v2  a   a   a )
14225        ( v1  v2  a   a   a )
14226 
14227     where a denotes an element of the original matrix A, h denotes a
14228     modified element of the upper Hessenberg matrix H, and vi denotes an
14229     element of the vector defining H(i).
14230 
14231     This subroutine is a slight modification of LAPACK-3.0's DLAHRD
14232     incorporating improvements proposed by Quintana-Orti and Van de
14233     Gejin. Note that the entries of A(1:K,2:NB) differ from those
14234     returned by the original LAPACK-3.0's DLAHRD routine. (This
14235     subroutine is not backward compatible with LAPACK-3.0's DLAHRD.)
14236 
14237     References
14238     ==========
14239 
14240     Gregorio Quintana-Orti and Robert van de Geijn, "Improving the
14241     performance of reduction to Hessenberg form," ACM Transactions on
14242     Mathematical Software, 32(2):180-194, June 2006.
14243 
14244     =====================================================================
14245 
14246 
14247        Quick return if possible
14248 */
14249 
14250     /* Parameter adjustments */
14251     --tau;
14252     a_dim1 = *lda;
14253     a_offset = 1 + a_dim1;
14254     a -= a_offset;
14255     t_dim1 = *ldt;
14256     t_offset = 1 + t_dim1;
14257     t -= t_offset;
14258     y_dim1 = *ldy;
14259     y_offset = 1 + y_dim1;
14260     y -= y_offset;
14261 
14262     /* Function Body */
14263     if (*n <= 1) {
14264 	return 0;
14265     }
14266 
14267     i__1 = *nb;
14268     for (i__ = 1; i__ <= i__1; ++i__) {
14269 	if (i__ > 1) {
14270 
14271 /*
14272              Update A(K+1:N,I)
14273 
14274              Update I-th column of A - Y * V'
14275 */
14276 
14277 	    i__2 = *n - *k;
14278 	    i__3 = i__ - 1;
14279 	    dgemv_("NO TRANSPOSE", &i__2, &i__3, &c_b151, &y[*k + 1 + y_dim1],
14280 		     ldy, &a[*k + i__ - 1 + a_dim1], lda, &c_b15, &a[*k + 1 +
14281 		    i__ * a_dim1], &c__1);
14282 
14283 /*
14284              Apply I - V * T' * V' to this column (call it b) from the
14285              left, using the last column of T as workspace
14286 
14287              Let  V = ( V1 )   and   b = ( b1 )   (first I-1 rows)
14288                       ( V2 )             ( b2 )
14289 
14290              where V1 is unit lower triangular
14291 
14292              w := V1' * b1
14293 */
14294 
14295 	    i__2 = i__ - 1;
14296 	    dcopy_(&i__2, &a[*k + 1 + i__ * a_dim1], &c__1, &t[*nb * t_dim1 +
14297 		    1], &c__1);
14298 	    i__2 = i__ - 1;
14299 	    dtrmv_("Lower", "Transpose", "UNIT", &i__2, &a[*k + 1 + a_dim1],
14300 		    lda, &t[*nb * t_dim1 + 1], &c__1);
14301 
14302 /*           w := w + V2'*b2 */
14303 
14304 	    i__2 = *n - *k - i__ + 1;
14305 	    i__3 = i__ - 1;
14306 	    dgemv_("Transpose", &i__2, &i__3, &c_b15, &a[*k + i__ + a_dim1],
14307 		    lda, &a[*k + i__ + i__ * a_dim1], &c__1, &c_b15, &t[*nb *
14308 		    t_dim1 + 1], &c__1);
14309 
14310 /*           w := T'*w */
14311 
14312 	    i__2 = i__ - 1;
14313 	    dtrmv_("Upper", "Transpose", "NON-UNIT", &i__2, &t[t_offset], ldt,
14314 		     &t[*nb * t_dim1 + 1], &c__1);
14315 
14316 /*           b2 := b2 - V2*w */
14317 
14318 	    i__2 = *n - *k - i__ + 1;
14319 	    i__3 = i__ - 1;
14320 	    dgemv_("NO TRANSPOSE", &i__2, &i__3, &c_b151, &a[*k + i__ +
14321 		    a_dim1], lda, &t[*nb * t_dim1 + 1], &c__1, &c_b15, &a[*k
14322 		    + i__ + i__ * a_dim1], &c__1);
14323 
14324 /*           b1 := b1 - V1*w */
14325 
14326 	    i__2 = i__ - 1;
14327 	    dtrmv_("Lower", "NO TRANSPOSE", "UNIT", &i__2, &a[*k + 1 + a_dim1]
14328 		    , lda, &t[*nb * t_dim1 + 1], &c__1);
14329 	    i__2 = i__ - 1;
14330 	    daxpy_(&i__2, &c_b151, &t[*nb * t_dim1 + 1], &c__1, &a[*k + 1 +
14331 		    i__ * a_dim1], &c__1);
14332 
14333 	    a[*k + i__ - 1 + (i__ - 1) * a_dim1] = ei;
14334 	}
14335 
14336 /*
14337           Generate the elementary reflector H(I) to annihilate
14338           A(K+I+1:N,I)
14339 */
14340 
14341 	i__2 = *n - *k - i__ + 1;
14342 /* Computing MIN */
14343 	i__3 = *k + i__ + 1;
14344 	dlarfg_(&i__2, &a[*k + i__ + i__ * a_dim1], &a[min(i__3,*n) + i__ *
14345 		a_dim1], &c__1, &tau[i__]);
14346 	ei = a[*k + i__ + i__ * a_dim1];
14347 	a[*k + i__ + i__ * a_dim1] = 1.;
14348 
14349 /*        Compute  Y(K+1:N,I) */
14350 
14351 	i__2 = *n - *k;
14352 	i__3 = *n - *k - i__ + 1;
14353 	dgemv_("NO TRANSPOSE", &i__2, &i__3, &c_b15, &a[*k + 1 + (i__ + 1) *
14354 		a_dim1], lda, &a[*k + i__ + i__ * a_dim1], &c__1, &c_b29, &y[*
14355 		k + 1 + i__ * y_dim1], &c__1);
14356 	i__2 = *n - *k - i__ + 1;
14357 	i__3 = i__ - 1;
14358 	dgemv_("Transpose", &i__2, &i__3, &c_b15, &a[*k + i__ + a_dim1], lda,
14359 		&a[*k + i__ + i__ * a_dim1], &c__1, &c_b29, &t[i__ * t_dim1 +
14360 		1], &c__1);
14361 	i__2 = *n - *k;
14362 	i__3 = i__ - 1;
14363 	dgemv_("NO TRANSPOSE", &i__2, &i__3, &c_b151, &y[*k + 1 + y_dim1],
14364 		ldy, &t[i__ * t_dim1 + 1], &c__1, &c_b15, &y[*k + 1 + i__ *
14365 		y_dim1], &c__1);
14366 	i__2 = *n - *k;
14367 	dscal_(&i__2, &tau[i__], &y[*k + 1 + i__ * y_dim1], &c__1);
14368 
14369 /*        Compute T(1:I,I) */
14370 
14371 	i__2 = i__ - 1;
14372 	d__1 = -tau[i__];
14373 	dscal_(&i__2, &d__1, &t[i__ * t_dim1 + 1], &c__1);
14374 	i__2 = i__ - 1;
14375 	dtrmv_("Upper", "No Transpose", "NON-UNIT", &i__2, &t[t_offset], ldt,
14376 		&t[i__ * t_dim1 + 1], &c__1)
14377 		;
14378 	t[i__ + i__ * t_dim1] = tau[i__];
14379 
14380 /* L10: */
14381     }
14382     a[*k + *nb + *nb * a_dim1] = ei;
14383 
14384 /*     Compute Y(1:K,1:NB) */
14385 
14386     dlacpy_("ALL", k, nb, &a[(a_dim1 << 1) + 1], lda, &y[y_offset], ldy);
14387     dtrmm_("RIGHT", "Lower", "NO TRANSPOSE", "UNIT", k, nb, &c_b15, &a[*k + 1
14388 	    + a_dim1], lda, &y[y_offset], ldy);
14389     if (*n > *k + *nb) {
14390 	i__1 = *n - *k - *nb;
14391 	dgemm_("NO TRANSPOSE", "NO TRANSPOSE", k, nb, &i__1, &c_b15, &a[(*nb
14392 		+ 2) * a_dim1 + 1], lda, &a[*k + 1 + *nb + a_dim1], lda, &
14393 		c_b15, &y[y_offset], ldy);
14394     }
14395     dtrmm_("RIGHT", "Upper", "NO TRANSPOSE", "NON-UNIT", k, nb, &c_b15, &t[
14396 	    t_offset], ldt, &y[y_offset], ldy);
14397 
14398     return 0;
14399 
14400 /*     End of DLAHR2 */
14401 
14402 } /* dlahr2_ */
14403 
dlaisnan_(doublereal * din1,doublereal * din2)14404 logical dlaisnan_(doublereal *din1, doublereal *din2)
14405 {
14406     /* System generated locals */
14407     logical ret_val;
14408 
14409 
14410 /*
14411     -- LAPACK auxiliary routine (version 3.2.2) --
14412     -- LAPACK is a software package provided by Univ. of Tennessee,    --
14413     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
14414        June 2010
14415 
14416 
14417     Purpose
14418     =======
14419 
14420     This routine is not for general use.  It exists solely to avoid
14421     over-optimization in DISNAN.
14422 
14423     DLAISNAN checks for NaNs by comparing its two arguments for
14424     inequality.  NaN is the only floating-point value where NaN != NaN
14425     returns .TRUE.  To check for NaNs, pass the same variable as both
14426     arguments.
14427 
14428     A compiler must assume that the two arguments are
14429     not the same variable, and the test will not be optimized away.
14430     Interprocedural or whole-program optimization may delete this
14431     test.  The ISNAN functions will be replaced by the correct
14432     Fortran 03 intrinsic once the intrinsic is widely available.
14433 
14434     Arguments
14435     =========
14436 
14437     DIN1    (input) DOUBLE PRECISION
14438 
14439     DIN2    (input) DOUBLE PRECISION
14440             Two numbers to compare for inequality.
14441 
14442     =====================================================================
14443 */
14444 
14445     ret_val = *din1 != *din2;
14446     return ret_val;
14447 } /* dlaisnan_ */
14448 
dlaln2_(logical * ltrans,integer * na,integer * nw,doublereal * smin,doublereal * ca,doublereal * a,integer * lda,doublereal * d1,doublereal * d2,doublereal * b,integer * ldb,doublereal * wr,doublereal * wi,doublereal * x,integer * ldx,doublereal * scale,doublereal * xnorm,integer * info)14449 /* Subroutine */ int dlaln2_(logical *ltrans, integer *na, integer *nw,
14450 	doublereal *smin, doublereal *ca, doublereal *a, integer *lda,
14451 	doublereal *d1, doublereal *d2, doublereal *b, integer *ldb,
14452 	doublereal *wr, doublereal *wi, doublereal *x, integer *ldx,
14453 	doublereal *scale, doublereal *xnorm, integer *info)
14454 {
14455     /* Initialized data */
14456 
14457     static logical zswap[4] = { FALSE_,FALSE_,TRUE_,TRUE_ };
14458     static logical rswap[4] = { FALSE_,TRUE_,FALSE_,TRUE_ };
14459     static integer ipivot[16]	/* was [4][4] */ = { 1,2,3,4,2,1,4,3,3,4,1,2,
14460 	    4,3,2,1 };
14461 
14462     /* System generated locals */
14463     integer a_dim1, a_offset, b_dim1, b_offset, x_dim1, x_offset;
14464     doublereal d__1, d__2, d__3, d__4, d__5, d__6;
14465     static doublereal equiv_0[4], equiv_1[4];
14466 
14467     /* Local variables */
14468     static integer j;
14469 #define ci (equiv_0)
14470 #define cr (equiv_1)
14471     static doublereal bi1, bi2, br1, br2, xi1, xi2, xr1, xr2, ci21, ci22,
14472 	    cr21, cr22, li21, csi, ui11, lr21, ui12, ui22;
14473 #define civ (equiv_0)
14474     static doublereal csr, ur11, ur12, ur22;
14475 #define crv (equiv_1)
14476     static doublereal bbnd, cmax, ui11r, ui12s, temp, ur11r, ur12s, u22abs;
14477     static integer icmax;
14478     static doublereal bnorm, cnorm, smini;
14479 
14480     extern /* Subroutine */ int dladiv_(doublereal *, doublereal *,
14481 	    doublereal *, doublereal *, doublereal *, doublereal *);
14482     static doublereal bignum, smlnum;
14483 
14484 
14485 /*
14486     -- LAPACK auxiliary routine (version 3.2) --
14487     -- LAPACK is a software package provided by Univ. of Tennessee,    --
14488     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
14489        November 2006
14490 
14491 
14492     Purpose
14493     =======
14494 
14495     DLALN2 solves a system of the form  (ca A - w D ) X = s B
14496     or (ca A' - w D) X = s B   with possible scaling ("s") and
14497     perturbation of A.  (A' means A-transpose.)
14498 
14499     A is an NA x NA real matrix, ca is a real scalar, D is an NA x NA
14500     real diagonal matrix, w is a real or complex value, and X and B are
14501     NA x 1 matrices -- real if w is real, complex if w is complex.  NA
14502     may be 1 or 2.
14503 
14504     If w is complex, X and B are represented as NA x 2 matrices,
14505     the first column of each being the real part and the second
14506     being the imaginary part.
14507 
14508     "s" is a scaling factor (.LE. 1), computed by DLALN2, which is
14509     so chosen that X can be computed without overflow.  X is further
14510     scaled if necessary to assure that norm(ca A - w D)*norm(X) is less
14511     than overflow.
14512 
14513     If both singular values of (ca A - w D) are less than SMIN,
14514     SMIN*identity will be used instead of (ca A - w D).  If only one
14515     singular value is less than SMIN, one element of (ca A - w D) will be
14516     perturbed enough to make the smallest singular value roughly SMIN.
14517     If both singular values are at least SMIN, (ca A - w D) will not be
14518     perturbed.  In any case, the perturbation will be at most some small
14519     multiple of max( SMIN, ulp*norm(ca A - w D) ).  The singular values
14520     are computed by infinity-norm approximations, and thus will only be
14521     correct to a factor of 2 or so.
14522 
14523     Note: all input quantities are assumed to be smaller than overflow
14524     by a reasonable factor.  (See BIGNUM.)
14525 
14526     Arguments
14527     ==========
14528 
14529     LTRANS  (input) LOGICAL
14530             =.TRUE.:  A-transpose will be used.
14531             =.FALSE.: A will be used (not transposed.)
14532 
14533     NA      (input) INTEGER
14534             The size of the matrix A.  It may (only) be 1 or 2.
14535 
14536     NW      (input) INTEGER
14537             1 if "w" is real, 2 if "w" is complex.  It may only be 1
14538             or 2.
14539 
14540     SMIN    (input) DOUBLE PRECISION
14541             The desired lower bound on the singular values of A.  This
14542             should be a safe distance away from underflow or overflow,
14543             say, between (underflow/machine precision) and  (machine
14544             precision * overflow ).  (See BIGNUM and ULP.)
14545 
14546     CA      (input) DOUBLE PRECISION
14547             The coefficient c, which A is multiplied by.
14548 
14549     A       (input) DOUBLE PRECISION array, dimension (LDA,NA)
14550             The NA x NA matrix A.
14551 
14552     LDA     (input) INTEGER
14553             The leading dimension of A.  It must be at least NA.
14554 
14555     D1      (input) DOUBLE PRECISION
14556             The 1,1 element in the diagonal matrix D.
14557 
14558     D2      (input) DOUBLE PRECISION
14559             The 2,2 element in the diagonal matrix D.  Not used if NW=1.
14560 
14561     B       (input) DOUBLE PRECISION array, dimension (LDB,NW)
14562             The NA x NW matrix B (right-hand side).  If NW=2 ("w" is
14563             complex), column 1 contains the real part of B and column 2
14564             contains the imaginary part.
14565 
14566     LDB     (input) INTEGER
14567             The leading dimension of B.  It must be at least NA.
14568 
14569     WR      (input) DOUBLE PRECISION
14570             The real part of the scalar "w".
14571 
14572     WI      (input) DOUBLE PRECISION
14573             The imaginary part of the scalar "w".  Not used if NW=1.
14574 
14575     X       (output) DOUBLE PRECISION array, dimension (LDX,NW)
14576             The NA x NW matrix X (unknowns), as computed by DLALN2.
14577             If NW=2 ("w" is complex), on exit, column 1 will contain
14578             the real part of X and column 2 will contain the imaginary
14579             part.
14580 
14581     LDX     (input) INTEGER
14582             The leading dimension of X.  It must be at least NA.
14583 
14584     SCALE   (output) DOUBLE PRECISION
14585             The scale factor that B must be multiplied by to insure
14586             that overflow does not occur when computing X.  Thus,
14587             (ca A - w D) X  will be SCALE*B, not B (ignoring
14588             perturbations of A.)  It will be at most 1.
14589 
14590     XNORM   (output) DOUBLE PRECISION
14591             The infinity-norm of X, when X is regarded as an NA x NW
14592             real matrix.
14593 
14594     INFO    (output) INTEGER
14595             An error flag.  It will be set to zero if no error occurs,
14596             a negative number if an argument is in error, or a positive
14597             number if  ca A - w D  had to be perturbed.
14598             The possible values are:
14599             = 0: No error occurred, and (ca A - w D) did not have to be
14600                    perturbed.
14601             = 1: (ca A - w D) had to be perturbed to make its smallest
14602                  (or only) singular value greater than SMIN.
14603             NOTE: In the interests of speed, this routine does not
14604                   check the inputs for errors.
14605 
14606    =====================================================================
14607 */
14608 
14609     /* Parameter adjustments */
14610     a_dim1 = *lda;
14611     a_offset = 1 + a_dim1;
14612     a -= a_offset;
14613     b_dim1 = *ldb;
14614     b_offset = 1 + b_dim1;
14615     b -= b_offset;
14616     x_dim1 = *ldx;
14617     x_offset = 1 + x_dim1;
14618     x -= x_offset;
14619 
14620     /* Function Body */
14621 
14622 /*     Compute BIGNUM */
14623 
14624     smlnum = 2. * SAFEMINIMUM;
14625     bignum = 1. / smlnum;
14626     smini = max(*smin,smlnum);
14627 
14628 /*     Don't check for input errors */
14629 
14630     *info = 0;
14631 
14632 /*     Standard Initializations */
14633 
14634     *scale = 1.;
14635 
14636     if (*na == 1) {
14637 
14638 /*        1 x 1  (i.e., scalar) system   C X = B */
14639 
14640 	if (*nw == 1) {
14641 
14642 /*
14643              Real 1x1 system.
14644 
14645              C = ca A - w D
14646 */
14647 
14648 	    csr = *ca * a[a_dim1 + 1] - *wr * *d1;
14649 	    cnorm = abs(csr);
14650 
14651 /*           If | C | < SMINI, use C = SMINI */
14652 
14653 	    if (cnorm < smini) {
14654 		csr = smini;
14655 		cnorm = smini;
14656 		*info = 1;
14657 	    }
14658 
14659 /*           Check scaling for  X = B / C */
14660 
14661 	    bnorm = (d__1 = b[b_dim1 + 1], abs(d__1));
14662 	    if (cnorm < 1. && bnorm > 1.) {
14663 		if (bnorm > bignum * cnorm) {
14664 		    *scale = 1. / bnorm;
14665 		}
14666 	    }
14667 
14668 /*           Compute X */
14669 
14670 	    x[x_dim1 + 1] = b[b_dim1 + 1] * *scale / csr;
14671 	    *xnorm = (d__1 = x[x_dim1 + 1], abs(d__1));
14672 	} else {
14673 
14674 /*
14675              Complex 1x1 system (w is complex)
14676 
14677              C = ca A - w D
14678 */
14679 
14680 	    csr = *ca * a[a_dim1 + 1] - *wr * *d1;
14681 	    csi = -(*wi) * *d1;
14682 	    cnorm = abs(csr) + abs(csi);
14683 
14684 /*           If | C | < SMINI, use C = SMINI */
14685 
14686 	    if (cnorm < smini) {
14687 		csr = smini;
14688 		csi = 0.;
14689 		cnorm = smini;
14690 		*info = 1;
14691 	    }
14692 
14693 /*           Check scaling for  X = B / C */
14694 
14695 	    bnorm = (d__1 = b[b_dim1 + 1], abs(d__1)) + (d__2 = b[(b_dim1 <<
14696 		    1) + 1], abs(d__2));
14697 	    if (cnorm < 1. && bnorm > 1.) {
14698 		if (bnorm > bignum * cnorm) {
14699 		    *scale = 1. / bnorm;
14700 		}
14701 	    }
14702 
14703 /*           Compute X */
14704 
14705 	    d__1 = *scale * b[b_dim1 + 1];
14706 	    d__2 = *scale * b[(b_dim1 << 1) + 1];
14707 	    dladiv_(&d__1, &d__2, &csr, &csi, &x[x_dim1 + 1], &x[(x_dim1 << 1)
14708 		     + 1]);
14709 	    *xnorm = (d__1 = x[x_dim1 + 1], abs(d__1)) + (d__2 = x[(x_dim1 <<
14710 		    1) + 1], abs(d__2));
14711 	}
14712 
14713     } else {
14714 
14715 /*
14716           2x2 System
14717 
14718           Compute the real part of  C = ca A - w D  (or  ca A' - w D )
14719 */
14720 
14721 	cr[0] = *ca * a[a_dim1 + 1] - *wr * *d1;
14722 	cr[3] = *ca * a[(a_dim1 << 1) + 2] - *wr * *d2;
14723 	if (*ltrans) {
14724 	    cr[2] = *ca * a[a_dim1 + 2];
14725 	    cr[1] = *ca * a[(a_dim1 << 1) + 1];
14726 	} else {
14727 	    cr[1] = *ca * a[a_dim1 + 2];
14728 	    cr[2] = *ca * a[(a_dim1 << 1) + 1];
14729 	}
14730 
14731 	if (*nw == 1) {
14732 
14733 /*
14734              Real 2x2 system  (w is real)
14735 
14736              Find the largest element in C
14737 */
14738 
14739 	    cmax = 0.;
14740 	    icmax = 0;
14741 
14742 	    for (j = 1; j <= 4; ++j) {
14743 		if ((d__1 = crv[j - 1], abs(d__1)) > cmax) {
14744 		    cmax = (d__1 = crv[j - 1], abs(d__1));
14745 		    icmax = j;
14746 		}
14747 /* L10: */
14748 	    }
14749 
14750 /*           If norm(C) < SMINI, use SMINI*identity. */
14751 
14752 	    if (cmax < smini) {
14753 /* Computing MAX */
14754 		d__3 = (d__1 = b[b_dim1 + 1], abs(d__1)), d__4 = (d__2 = b[
14755 			b_dim1 + 2], abs(d__2));
14756 		bnorm = max(d__3,d__4);
14757 		if (smini < 1. && bnorm > 1.) {
14758 		    if (bnorm > bignum * smini) {
14759 			*scale = 1. / bnorm;
14760 		    }
14761 		}
14762 		temp = *scale / smini;
14763 		x[x_dim1 + 1] = temp * b[b_dim1 + 1];
14764 		x[x_dim1 + 2] = temp * b[b_dim1 + 2];
14765 		*xnorm = temp * bnorm;
14766 		*info = 1;
14767 		return 0;
14768 	    }
14769 
14770 /*           Gaussian elimination with complete pivoting. */
14771 
14772 	    ur11 = crv[icmax - 1];
14773 	    cr21 = crv[ipivot[(icmax << 2) - 3] - 1];
14774 	    ur12 = crv[ipivot[(icmax << 2) - 2] - 1];
14775 	    cr22 = crv[ipivot[(icmax << 2) - 1] - 1];
14776 	    ur11r = 1. / ur11;
14777 	    lr21 = ur11r * cr21;
14778 	    ur22 = cr22 - ur12 * lr21;
14779 
14780 /*           If smaller pivot < SMINI, use SMINI */
14781 
14782 	    if (abs(ur22) < smini) {
14783 		ur22 = smini;
14784 		*info = 1;
14785 	    }
14786 	    if (rswap[icmax - 1]) {
14787 		br1 = b[b_dim1 + 2];
14788 		br2 = b[b_dim1 + 1];
14789 	    } else {
14790 		br1 = b[b_dim1 + 1];
14791 		br2 = b[b_dim1 + 2];
14792 	    }
14793 	    br2 -= lr21 * br1;
14794 /* Computing MAX */
14795 	    d__2 = (d__1 = br1 * (ur22 * ur11r), abs(d__1)), d__3 = abs(br2);
14796 	    bbnd = max(d__2,d__3);
14797 	    if (bbnd > 1. && abs(ur22) < 1.) {
14798 		if (bbnd >= bignum * abs(ur22)) {
14799 		    *scale = 1. / bbnd;
14800 		}
14801 	    }
14802 
14803 	    xr2 = br2 * *scale / ur22;
14804 	    xr1 = *scale * br1 * ur11r - xr2 * (ur11r * ur12);
14805 	    if (zswap[icmax - 1]) {
14806 		x[x_dim1 + 1] = xr2;
14807 		x[x_dim1 + 2] = xr1;
14808 	    } else {
14809 		x[x_dim1 + 1] = xr1;
14810 		x[x_dim1 + 2] = xr2;
14811 	    }
14812 /* Computing MAX */
14813 	    d__1 = abs(xr1), d__2 = abs(xr2);
14814 	    *xnorm = max(d__1,d__2);
14815 
14816 /*           Further scaling if  norm(A) norm(X) > overflow */
14817 
14818 	    if (*xnorm > 1. && cmax > 1.) {
14819 		if (*xnorm > bignum / cmax) {
14820 		    temp = cmax / bignum;
14821 		    x[x_dim1 + 1] = temp * x[x_dim1 + 1];
14822 		    x[x_dim1 + 2] = temp * x[x_dim1 + 2];
14823 		    *xnorm = temp * *xnorm;
14824 		    *scale = temp * *scale;
14825 		}
14826 	    }
14827 	} else {
14828 
14829 /*
14830              Complex 2x2 system  (w is complex)
14831 
14832              Find the largest element in C
14833 */
14834 
14835 	    ci[0] = -(*wi) * *d1;
14836 	    ci[1] = 0.;
14837 	    ci[2] = 0.;
14838 	    ci[3] = -(*wi) * *d2;
14839 	    cmax = 0.;
14840 	    icmax = 0;
14841 
14842 	    for (j = 1; j <= 4; ++j) {
14843 		if ((d__1 = crv[j - 1], abs(d__1)) + (d__2 = civ[j - 1], abs(
14844 			d__2)) > cmax) {
14845 		    cmax = (d__1 = crv[j - 1], abs(d__1)) + (d__2 = civ[j - 1]
14846 			    , abs(d__2));
14847 		    icmax = j;
14848 		}
14849 /* L20: */
14850 	    }
14851 
14852 /*           If norm(C) < SMINI, use SMINI*identity. */
14853 
14854 	    if (cmax < smini) {
14855 /* Computing MAX */
14856 		d__5 = (d__1 = b[b_dim1 + 1], abs(d__1)) + (d__2 = b[(b_dim1
14857 			<< 1) + 1], abs(d__2)), d__6 = (d__3 = b[b_dim1 + 2],
14858 			abs(d__3)) + (d__4 = b[(b_dim1 << 1) + 2], abs(d__4));
14859 		bnorm = max(d__5,d__6);
14860 		if (smini < 1. && bnorm > 1.) {
14861 		    if (bnorm > bignum * smini) {
14862 			*scale = 1. / bnorm;
14863 		    }
14864 		}
14865 		temp = *scale / smini;
14866 		x[x_dim1 + 1] = temp * b[b_dim1 + 1];
14867 		x[x_dim1 + 2] = temp * b[b_dim1 + 2];
14868 		x[(x_dim1 << 1) + 1] = temp * b[(b_dim1 << 1) + 1];
14869 		x[(x_dim1 << 1) + 2] = temp * b[(b_dim1 << 1) + 2];
14870 		*xnorm = temp * bnorm;
14871 		*info = 1;
14872 		return 0;
14873 	    }
14874 
14875 /*           Gaussian elimination with complete pivoting. */
14876 
14877 	    ur11 = crv[icmax - 1];
14878 	    ui11 = civ[icmax - 1];
14879 	    cr21 = crv[ipivot[(icmax << 2) - 3] - 1];
14880 	    ci21 = civ[ipivot[(icmax << 2) - 3] - 1];
14881 	    ur12 = crv[ipivot[(icmax << 2) - 2] - 1];
14882 	    ui12 = civ[ipivot[(icmax << 2) - 2] - 1];
14883 	    cr22 = crv[ipivot[(icmax << 2) - 1] - 1];
14884 	    ci22 = civ[ipivot[(icmax << 2) - 1] - 1];
14885 	    if (icmax == 1 || icmax == 4) {
14886 
14887 /*              Code when off-diagonals of pivoted C are real */
14888 
14889 		if (abs(ur11) > abs(ui11)) {
14890 		    temp = ui11 / ur11;
14891 /* Computing 2nd power */
14892 		    d__1 = temp;
14893 		    ur11r = 1. / (ur11 * (d__1 * d__1 + 1.));
14894 		    ui11r = -temp * ur11r;
14895 		} else {
14896 		    temp = ur11 / ui11;
14897 /* Computing 2nd power */
14898 		    d__1 = temp;
14899 		    ui11r = -1. / (ui11 * (d__1 * d__1 + 1.));
14900 		    ur11r = -temp * ui11r;
14901 		}
14902 		lr21 = cr21 * ur11r;
14903 		li21 = cr21 * ui11r;
14904 		ur12s = ur12 * ur11r;
14905 		ui12s = ur12 * ui11r;
14906 		ur22 = cr22 - ur12 * lr21;
14907 		ui22 = ci22 - ur12 * li21;
14908 	    } else {
14909 
14910 /*              Code when diagonals of pivoted C are real */
14911 
14912 		ur11r = 1. / ur11;
14913 		ui11r = 0.;
14914 		lr21 = cr21 * ur11r;
14915 		li21 = ci21 * ur11r;
14916 		ur12s = ur12 * ur11r;
14917 		ui12s = ui12 * ur11r;
14918 		ur22 = cr22 - ur12 * lr21 + ui12 * li21;
14919 		ui22 = -ur12 * li21 - ui12 * lr21;
14920 	    }
14921 	    u22abs = abs(ur22) + abs(ui22);
14922 
14923 /*           If smaller pivot < SMINI, use SMINI */
14924 
14925 	    if (u22abs < smini) {
14926 		ur22 = smini;
14927 		ui22 = 0.;
14928 		*info = 1;
14929 	    }
14930 	    if (rswap[icmax - 1]) {
14931 		br2 = b[b_dim1 + 1];
14932 		br1 = b[b_dim1 + 2];
14933 		bi2 = b[(b_dim1 << 1) + 1];
14934 		bi1 = b[(b_dim1 << 1) + 2];
14935 	    } else {
14936 		br1 = b[b_dim1 + 1];
14937 		br2 = b[b_dim1 + 2];
14938 		bi1 = b[(b_dim1 << 1) + 1];
14939 		bi2 = b[(b_dim1 << 1) + 2];
14940 	    }
14941 	    br2 = br2 - lr21 * br1 + li21 * bi1;
14942 	    bi2 = bi2 - li21 * br1 - lr21 * bi1;
14943 /* Computing MAX */
14944 	    d__1 = (abs(br1) + abs(bi1)) * (u22abs * (abs(ur11r) + abs(ui11r))
14945 		    ), d__2 = abs(br2) + abs(bi2);
14946 	    bbnd = max(d__1,d__2);
14947 	    if (bbnd > 1. && u22abs < 1.) {
14948 		if (bbnd >= bignum * u22abs) {
14949 		    *scale = 1. / bbnd;
14950 		    br1 = *scale * br1;
14951 		    bi1 = *scale * bi1;
14952 		    br2 = *scale * br2;
14953 		    bi2 = *scale * bi2;
14954 		}
14955 	    }
14956 
14957 	    dladiv_(&br2, &bi2, &ur22, &ui22, &xr2, &xi2);
14958 	    xr1 = ur11r * br1 - ui11r * bi1 - ur12s * xr2 + ui12s * xi2;
14959 	    xi1 = ui11r * br1 + ur11r * bi1 - ui12s * xr2 - ur12s * xi2;
14960 	    if (zswap[icmax - 1]) {
14961 		x[x_dim1 + 1] = xr2;
14962 		x[x_dim1 + 2] = xr1;
14963 		x[(x_dim1 << 1) + 1] = xi2;
14964 		x[(x_dim1 << 1) + 2] = xi1;
14965 	    } else {
14966 		x[x_dim1 + 1] = xr1;
14967 		x[x_dim1 + 2] = xr2;
14968 		x[(x_dim1 << 1) + 1] = xi1;
14969 		x[(x_dim1 << 1) + 2] = xi2;
14970 	    }
14971 /* Computing MAX */
14972 	    d__1 = abs(xr1) + abs(xi1), d__2 = abs(xr2) + abs(xi2);
14973 	    *xnorm = max(d__1,d__2);
14974 
14975 /*           Further scaling if  norm(A) norm(X) > overflow */
14976 
14977 	    if (*xnorm > 1. && cmax > 1.) {
14978 		if (*xnorm > bignum / cmax) {
14979 		    temp = cmax / bignum;
14980 		    x[x_dim1 + 1] = temp * x[x_dim1 + 1];
14981 		    x[x_dim1 + 2] = temp * x[x_dim1 + 2];
14982 		    x[(x_dim1 << 1) + 1] = temp * x[(x_dim1 << 1) + 1];
14983 		    x[(x_dim1 << 1) + 2] = temp * x[(x_dim1 << 1) + 2];
14984 		    *xnorm = temp * *xnorm;
14985 		    *scale = temp * *scale;
14986 		}
14987 	    }
14988 	}
14989     }
14990 
14991     return 0;
14992 
14993 /*     End of DLALN2 */
14994 
14995 } /* dlaln2_ */
14996 
14997 #undef crv
14998 #undef civ
14999 #undef cr
15000 #undef ci
15001 
15002 
dlals0_(integer * icompq,integer * nl,integer * nr,integer * sqre,integer * nrhs,doublereal * b,integer * ldb,doublereal * bx,integer * ldbx,integer * perm,integer * givptr,integer * givcol,integer * ldgcol,doublereal * givnum,integer * ldgnum,doublereal * poles,doublereal * difl,doublereal * difr,doublereal * z__,integer * k,doublereal * c__,doublereal * s,doublereal * work,integer * info)15003 /* Subroutine */ int dlals0_(integer *icompq, integer *nl, integer *nr,
15004 	integer *sqre, integer *nrhs, doublereal *b, integer *ldb, doublereal
15005 	*bx, integer *ldbx, integer *perm, integer *givptr, integer *givcol,
15006 	integer *ldgcol, doublereal *givnum, integer *ldgnum, doublereal *
15007 	poles, doublereal *difl, doublereal *difr, doublereal *z__, integer *
15008 	k, doublereal *c__, doublereal *s, doublereal *work, integer *info)
15009 {
15010     /* System generated locals */
15011     integer givcol_dim1, givcol_offset, b_dim1, b_offset, bx_dim1, bx_offset,
15012 	    difr_dim1, difr_offset, givnum_dim1, givnum_offset, poles_dim1,
15013 	    poles_offset, i__1, i__2;
15014     doublereal d__1;
15015 
15016     /* Local variables */
15017     static integer i__, j, m, n;
15018     static doublereal dj;
15019     static integer nlp1;
15020     static doublereal temp;
15021     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
15022 	    doublereal *, integer *, doublereal *, doublereal *);
15023     extern doublereal dnrm2_(integer *, doublereal *, integer *);
15024     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
15025 	    integer *);
15026     static doublereal diflj, difrj, dsigj;
15027     extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
15028 	    doublereal *, doublereal *, integer *, doublereal *, integer *,
15029 	    doublereal *, doublereal *, integer *), dcopy_(integer *,
15030 	    doublereal *, integer *, doublereal *, integer *);
15031     extern doublereal dlamc3_(doublereal *, doublereal *);
15032     extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
15033 	    doublereal *, doublereal *, integer *, integer *, doublereal *,
15034 	    integer *, integer *), dlacpy_(char *, integer *, integer
15035 	    *, doublereal *, integer *, doublereal *, integer *),
15036 	    xerbla_(char *, integer *);
15037     static doublereal dsigjp;
15038 
15039 
15040 /*
15041     -- LAPACK routine (version 3.2) --
15042     -- LAPACK is a software package provided by Univ. of Tennessee,    --
15043     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
15044        November 2006
15045 
15046 
15047     Purpose
15048     =======
15049 
15050     DLALS0 applies back the multiplying factors of either the left or the
15051     right singular vector matrix of a diagonal matrix appended by a row
15052     to the right hand side matrix B in solving the least squares problem
15053     using the divide-and-conquer SVD approach.
15054 
15055     For the left singular vector matrix, three types of orthogonal
15056     matrices are involved:
15057 
15058     (1L) Givens rotations: the number of such rotations is GIVPTR; the
15059          pairs of columns/rows they were applied to are stored in GIVCOL;
15060          and the C- and S-values of these rotations are stored in GIVNUM.
15061 
15062     (2L) Permutation. The (NL+1)-st row of B is to be moved to the first
15063          row, and for J=2:N, PERM(J)-th row of B is to be moved to the
15064          J-th row.
15065 
15066     (3L) The left singular vector matrix of the remaining matrix.
15067 
15068     For the right singular vector matrix, four types of orthogonal
15069     matrices are involved:
15070 
15071     (1R) The right singular vector matrix of the remaining matrix.
15072 
15073     (2R) If SQRE = 1, one extra Givens rotation to generate the right
15074          null space.
15075 
15076     (3R) The inverse transformation of (2L).
15077 
15078     (4R) The inverse transformation of (1L).
15079 
15080     Arguments
15081     =========
15082 
15083     ICOMPQ (input) INTEGER
15084            Specifies whether singular vectors are to be computed in
15085            factored form:
15086            = 0: Left singular vector matrix.
15087            = 1: Right singular vector matrix.
15088 
15089     NL     (input) INTEGER
15090            The row dimension of the upper block. NL >= 1.
15091 
15092     NR     (input) INTEGER
15093            The row dimension of the lower block. NR >= 1.
15094 
15095     SQRE   (input) INTEGER
15096            = 0: the lower block is an NR-by-NR square matrix.
15097            = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
15098 
15099            The bidiagonal matrix has row dimension N = NL + NR + 1,
15100            and column dimension M = N + SQRE.
15101 
15102     NRHS   (input) INTEGER
15103            The number of columns of B and BX. NRHS must be at least 1.
15104 
15105     B      (input/output) DOUBLE PRECISION array, dimension ( LDB, NRHS )
15106            On input, B contains the right hand sides of the least
15107            squares problem in rows 1 through M. On output, B contains
15108            the solution X in rows 1 through N.
15109 
15110     LDB    (input) INTEGER
15111            The leading dimension of B. LDB must be at least
15112            max(1,MAX( M, N ) ).
15113 
15114     BX     (workspace) DOUBLE PRECISION array, dimension ( LDBX, NRHS )
15115 
15116     LDBX   (input) INTEGER
15117            The leading dimension of BX.
15118 
15119     PERM   (input) INTEGER array, dimension ( N )
15120            The permutations (from deflation and sorting) applied
15121            to the two blocks.
15122 
15123     GIVPTR (input) INTEGER
15124            The number of Givens rotations which took place in this
15125            subproblem.
15126 
15127     GIVCOL (input) INTEGER array, dimension ( LDGCOL, 2 )
15128            Each pair of numbers indicates a pair of rows/columns
15129            involved in a Givens rotation.
15130 
15131     LDGCOL (input) INTEGER
15132            The leading dimension of GIVCOL, must be at least N.
15133 
15134     GIVNUM (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 )
15135            Each number indicates the C or S value used in the
15136            corresponding Givens rotation.
15137 
15138     LDGNUM (input) INTEGER
15139            The leading dimension of arrays DIFR, POLES and
15140            GIVNUM, must be at least K.
15141 
15142     POLES  (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 )
15143            On entry, POLES(1:K, 1) contains the new singular
15144            values obtained from solving the secular equation, and
15145            POLES(1:K, 2) is an array containing the poles in the secular
15146            equation.
15147 
15148     DIFL   (input) DOUBLE PRECISION array, dimension ( K ).
15149            On entry, DIFL(I) is the distance between I-th updated
15150            (undeflated) singular value and the I-th (undeflated) old
15151            singular value.
15152 
15153     DIFR   (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 ).
15154            On entry, DIFR(I, 1) contains the distances between I-th
15155            updated (undeflated) singular value and the I+1-th
15156            (undeflated) old singular value. And DIFR(I, 2) is the
15157            normalizing factor for the I-th right singular vector.
15158 
15159     Z      (input) DOUBLE PRECISION array, dimension ( K )
15160            Contain the components of the deflation-adjusted updating row
15161            vector.
15162 
15163     K      (input) INTEGER
15164            Contains the dimension of the non-deflated matrix,
15165            This is the order of the related secular equation. 1 <= K <=N.
15166 
15167     C      (input) DOUBLE PRECISION
15168            C contains garbage if SQRE =0 and the C-value of a Givens
15169            rotation related to the right null space if SQRE = 1.
15170 
15171     S      (input) DOUBLE PRECISION
15172            S contains garbage if SQRE =0 and the S-value of a Givens
15173            rotation related to the right null space if SQRE = 1.
15174 
15175     WORK   (workspace) DOUBLE PRECISION array, dimension ( K )
15176 
15177     INFO   (output) INTEGER
15178             = 0:  successful exit.
15179             < 0:  if INFO = -i, the i-th argument had an illegal value.
15180 
15181     Further Details
15182     ===============
15183 
15184     Based on contributions by
15185        Ming Gu and Ren-Cang Li, Computer Science Division, University of
15186          California at Berkeley, USA
15187        Osni Marques, LBNL/NERSC, USA
15188 
15189     =====================================================================
15190 
15191 
15192        Test the input parameters.
15193 */
15194 
15195     /* Parameter adjustments */
15196     b_dim1 = *ldb;
15197     b_offset = 1 + b_dim1;
15198     b -= b_offset;
15199     bx_dim1 = *ldbx;
15200     bx_offset = 1 + bx_dim1;
15201     bx -= bx_offset;
15202     --perm;
15203     givcol_dim1 = *ldgcol;
15204     givcol_offset = 1 + givcol_dim1;
15205     givcol -= givcol_offset;
15206     difr_dim1 = *ldgnum;
15207     difr_offset = 1 + difr_dim1;
15208     difr -= difr_offset;
15209     poles_dim1 = *ldgnum;
15210     poles_offset = 1 + poles_dim1;
15211     poles -= poles_offset;
15212     givnum_dim1 = *ldgnum;
15213     givnum_offset = 1 + givnum_dim1;
15214     givnum -= givnum_offset;
15215     --difl;
15216     --z__;
15217     --work;
15218 
15219     /* Function Body */
15220     *info = 0;
15221 
15222     if (*icompq < 0 || *icompq > 1) {
15223 	*info = -1;
15224     } else if (*nl < 1) {
15225 	*info = -2;
15226     } else if (*nr < 1) {
15227 	*info = -3;
15228     } else if (*sqre < 0 || *sqre > 1) {
15229 	*info = -4;
15230     }
15231 
15232     n = *nl + *nr + 1;
15233 
15234     if (*nrhs < 1) {
15235 	*info = -5;
15236     } else if (*ldb < n) {
15237 	*info = -7;
15238     } else if (*ldbx < n) {
15239 	*info = -9;
15240     } else if (*givptr < 0) {
15241 	*info = -11;
15242     } else if (*ldgcol < n) {
15243 	*info = -13;
15244     } else if (*ldgnum < n) {
15245 	*info = -15;
15246     } else if (*k < 1) {
15247 	*info = -20;
15248     }
15249     if (*info != 0) {
15250 	i__1 = -(*info);
15251 	xerbla_("DLALS0", &i__1);
15252 	return 0;
15253     }
15254 
15255     m = n + *sqre;
15256     nlp1 = *nl + 1;
15257 
15258     if (*icompq == 0) {
15259 
15260 /*
15261           Apply back orthogonal transformations from the left.
15262 
15263           Step (1L): apply back the Givens rotations performed.
15264 */
15265 
15266 	i__1 = *givptr;
15267 	for (i__ = 1; i__ <= i__1; ++i__) {
15268 	    drot_(nrhs, &b[givcol[i__ + (givcol_dim1 << 1)] + b_dim1], ldb, &
15269 		    b[givcol[i__ + givcol_dim1] + b_dim1], ldb, &givnum[i__ +
15270 		    (givnum_dim1 << 1)], &givnum[i__ + givnum_dim1]);
15271 /* L10: */
15272 	}
15273 
15274 /*        Step (2L): permute rows of B. */
15275 
15276 	dcopy_(nrhs, &b[nlp1 + b_dim1], ldb, &bx[bx_dim1 + 1], ldbx);
15277 	i__1 = n;
15278 	for (i__ = 2; i__ <= i__1; ++i__) {
15279 	    dcopy_(nrhs, &b[perm[i__] + b_dim1], ldb, &bx[i__ + bx_dim1],
15280 		    ldbx);
15281 /* L20: */
15282 	}
15283 
15284 /*
15285           Step (3L): apply the inverse of the left singular vector
15286           matrix to BX.
15287 */
15288 
15289 	if (*k == 1) {
15290 	    dcopy_(nrhs, &bx[bx_offset], ldbx, &b[b_offset], ldb);
15291 	    if (z__[1] < 0.) {
15292 		dscal_(nrhs, &c_b151, &b[b_offset], ldb);
15293 	    }
15294 	} else {
15295 	    i__1 = *k;
15296 	    for (j = 1; j <= i__1; ++j) {
15297 		diflj = difl[j];
15298 		dj = poles[j + poles_dim1];
15299 		dsigj = -poles[j + (poles_dim1 << 1)];
15300 		if (j < *k) {
15301 		    difrj = -difr[j + difr_dim1];
15302 		    dsigjp = -poles[j + 1 + (poles_dim1 << 1)];
15303 		}
15304 		if (z__[j] == 0. || poles[j + (poles_dim1 << 1)] == 0.) {
15305 		    work[j] = 0.;
15306 		} else {
15307 		    work[j] = -poles[j + (poles_dim1 << 1)] * z__[j] / diflj /
15308 			     (poles[j + (poles_dim1 << 1)] + dj);
15309 		}
15310 		i__2 = j - 1;
15311 		for (i__ = 1; i__ <= i__2; ++i__) {
15312 		    if (z__[i__] == 0. || poles[i__ + (poles_dim1 << 1)] ==
15313 			    0.) {
15314 			work[i__] = 0.;
15315 		    } else {
15316 			work[i__] = poles[i__ + (poles_dim1 << 1)] * z__[i__]
15317 				/ (dlamc3_(&poles[i__ + (poles_dim1 << 1)], &
15318 				dsigj) - diflj) / (poles[i__ + (poles_dim1 <<
15319 				1)] + dj);
15320 		    }
15321 /* L30: */
15322 		}
15323 		i__2 = *k;
15324 		for (i__ = j + 1; i__ <= i__2; ++i__) {
15325 		    if (z__[i__] == 0. || poles[i__ + (poles_dim1 << 1)] ==
15326 			    0.) {
15327 			work[i__] = 0.;
15328 		    } else {
15329 			work[i__] = poles[i__ + (poles_dim1 << 1)] * z__[i__]
15330 				/ (dlamc3_(&poles[i__ + (poles_dim1 << 1)], &
15331 				dsigjp) + difrj) / (poles[i__ + (poles_dim1 <<
15332 				 1)] + dj);
15333 		    }
15334 /* L40: */
15335 		}
15336 		work[1] = -1.;
15337 		temp = dnrm2_(k, &work[1], &c__1);
15338 		dgemv_("T", k, nrhs, &c_b15, &bx[bx_offset], ldbx, &work[1], &
15339 			c__1, &c_b29, &b[j + b_dim1], ldb);
15340 		dlascl_("G", &c__0, &c__0, &temp, &c_b15, &c__1, nrhs, &b[j +
15341 			b_dim1], ldb, info);
15342 /* L50: */
15343 	    }
15344 	}
15345 
15346 /*        Move the deflated rows of BX to B also. */
15347 
15348 	if (*k < max(m,n)) {
15349 	    i__1 = n - *k;
15350 	    dlacpy_("A", &i__1, nrhs, &bx[*k + 1 + bx_dim1], ldbx, &b[*k + 1
15351 		    + b_dim1], ldb);
15352 	}
15353     } else {
15354 
15355 /*
15356           Apply back the right orthogonal transformations.
15357 
15358           Step (1R): apply back the new right singular vector matrix
15359           to B.
15360 */
15361 
15362 	if (*k == 1) {
15363 	    dcopy_(nrhs, &b[b_offset], ldb, &bx[bx_offset], ldbx);
15364 	} else {
15365 	    i__1 = *k;
15366 	    for (j = 1; j <= i__1; ++j) {
15367 		dsigj = poles[j + (poles_dim1 << 1)];
15368 		if (z__[j] == 0.) {
15369 		    work[j] = 0.;
15370 		} else {
15371 		    work[j] = -z__[j] / difl[j] / (dsigj + poles[j +
15372 			    poles_dim1]) / difr[j + (difr_dim1 << 1)];
15373 		}
15374 		i__2 = j - 1;
15375 		for (i__ = 1; i__ <= i__2; ++i__) {
15376 		    if (z__[j] == 0.) {
15377 			work[i__] = 0.;
15378 		    } else {
15379 			d__1 = -poles[i__ + 1 + (poles_dim1 << 1)];
15380 			work[i__] = z__[j] / (dlamc3_(&dsigj, &d__1) - difr[
15381 				i__ + difr_dim1]) / (dsigj + poles[i__ +
15382 				poles_dim1]) / difr[i__ + (difr_dim1 << 1)];
15383 		    }
15384 /* L60: */
15385 		}
15386 		i__2 = *k;
15387 		for (i__ = j + 1; i__ <= i__2; ++i__) {
15388 		    if (z__[j] == 0.) {
15389 			work[i__] = 0.;
15390 		    } else {
15391 			d__1 = -poles[i__ + (poles_dim1 << 1)];
15392 			work[i__] = z__[j] / (dlamc3_(&dsigj, &d__1) - difl[
15393 				i__]) / (dsigj + poles[i__ + poles_dim1]) /
15394 				difr[i__ + (difr_dim1 << 1)];
15395 		    }
15396 /* L70: */
15397 		}
15398 		dgemv_("T", k, nrhs, &c_b15, &b[b_offset], ldb, &work[1], &
15399 			c__1, &c_b29, &bx[j + bx_dim1], ldbx);
15400 /* L80: */
15401 	    }
15402 	}
15403 
15404 /*
15405           Step (2R): if SQRE = 1, apply back the rotation that is
15406           related to the right null space of the subproblem.
15407 */
15408 
15409 	if (*sqre == 1) {
15410 	    dcopy_(nrhs, &b[m + b_dim1], ldb, &bx[m + bx_dim1], ldbx);
15411 	    drot_(nrhs, &bx[bx_dim1 + 1], ldbx, &bx[m + bx_dim1], ldbx, c__,
15412 		    s);
15413 	}
15414 	if (*k < max(m,n)) {
15415 	    i__1 = n - *k;
15416 	    dlacpy_("A", &i__1, nrhs, &b[*k + 1 + b_dim1], ldb, &bx[*k + 1 +
15417 		    bx_dim1], ldbx);
15418 	}
15419 
15420 /*        Step (3R): permute rows of B. */
15421 
15422 	dcopy_(nrhs, &bx[bx_dim1 + 1], ldbx, &b[nlp1 + b_dim1], ldb);
15423 	if (*sqre == 1) {
15424 	    dcopy_(nrhs, &bx[m + bx_dim1], ldbx, &b[m + b_dim1], ldb);
15425 	}
15426 	i__1 = n;
15427 	for (i__ = 2; i__ <= i__1; ++i__) {
15428 	    dcopy_(nrhs, &bx[i__ + bx_dim1], ldbx, &b[perm[i__] + b_dim1],
15429 		    ldb);
15430 /* L90: */
15431 	}
15432 
15433 /*        Step (4R): apply back the Givens rotations performed. */
15434 
15435 	for (i__ = *givptr; i__ >= 1; --i__) {
15436 	    d__1 = -givnum[i__ + givnum_dim1];
15437 	    drot_(nrhs, &b[givcol[i__ + (givcol_dim1 << 1)] + b_dim1], ldb, &
15438 		    b[givcol[i__ + givcol_dim1] + b_dim1], ldb, &givnum[i__ +
15439 		    (givnum_dim1 << 1)], &d__1);
15440 /* L100: */
15441 	}
15442     }
15443 
15444     return 0;
15445 
15446 /*     End of DLALS0 */
15447 
15448 } /* dlals0_ */
15449 
dlalsa_(integer * icompq,integer * smlsiz,integer * n,integer * nrhs,doublereal * b,integer * ldb,doublereal * bx,integer * ldbx,doublereal * u,integer * ldu,doublereal * vt,integer * k,doublereal * difl,doublereal * difr,doublereal * z__,doublereal * poles,integer * givptr,integer * givcol,integer * ldgcol,integer * perm,doublereal * givnum,doublereal * c__,doublereal * s,doublereal * work,integer * iwork,integer * info)15450 /* Subroutine */ int dlalsa_(integer *icompq, integer *smlsiz, integer *n,
15451 	integer *nrhs, doublereal *b, integer *ldb, doublereal *bx, integer *
15452 	ldbx, doublereal *u, integer *ldu, doublereal *vt, integer *k,
15453 	doublereal *difl, doublereal *difr, doublereal *z__, doublereal *
15454 	poles, integer *givptr, integer *givcol, integer *ldgcol, integer *
15455 	perm, doublereal *givnum, doublereal *c__, doublereal *s, doublereal *
15456 	work, integer *iwork, integer *info)
15457 {
15458     /* System generated locals */
15459     integer givcol_dim1, givcol_offset, perm_dim1, perm_offset, b_dim1,
15460 	    b_offset, bx_dim1, bx_offset, difl_dim1, difl_offset, difr_dim1,
15461 	    difr_offset, givnum_dim1, givnum_offset, poles_dim1, poles_offset,
15462 	     u_dim1, u_offset, vt_dim1, vt_offset, z_dim1, z_offset, i__1,
15463 	    i__2;
15464 
15465     /* Local variables */
15466     static integer i__, j, i1, ic, lf, nd, ll, nl, nr, im1, nlf, nrf, lvl,
15467 	    ndb1, nlp1, lvl2, nrp1, nlvl, sqre;
15468     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
15469 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
15470 	    integer *, doublereal *, doublereal *, integer *);
15471     static integer inode, ndiml, ndimr;
15472     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
15473 	    doublereal *, integer *), dlals0_(integer *, integer *, integer *,
15474 	     integer *, integer *, doublereal *, integer *, doublereal *,
15475 	    integer *, integer *, integer *, integer *, integer *, doublereal
15476 	    *, integer *, doublereal *, doublereal *, doublereal *,
15477 	    doublereal *, integer *, doublereal *, doublereal *, doublereal *,
15478 	     integer *), dlasdt_(integer *, integer *, integer *, integer *,
15479 	    integer *, integer *, integer *), xerbla_(char *, integer *);
15480 
15481 
15482 /*
15483     -- LAPACK routine (version 3.2) --
15484     -- LAPACK is a software package provided by Univ. of Tennessee,    --
15485     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
15486        November 2006
15487 
15488 
15489     Purpose
15490     =======
15491 
15492     DLALSA is an itermediate step in solving the least squares problem
15493     by computing the SVD of the coefficient matrix in compact form (The
15494     singular vectors are computed as products of simple orthorgonal
15495     matrices.).
15496 
15497     If ICOMPQ = 0, DLALSA applies the inverse of the left singular vector
15498     matrix of an upper bidiagonal matrix to the right hand side; and if
15499     ICOMPQ = 1, DLALSA applies the right singular vector matrix to the
15500     right hand side. The singular vector matrices were generated in
15501     compact form by DLALSA.
15502 
15503     Arguments
15504     =========
15505 
15506 
15507     ICOMPQ (input) INTEGER
15508            Specifies whether the left or the right singular vector
15509            matrix is involved.
15510            = 0: Left singular vector matrix
15511            = 1: Right singular vector matrix
15512 
15513     SMLSIZ (input) INTEGER
15514            The maximum size of the subproblems at the bottom of the
15515            computation tree.
15516 
15517     N      (input) INTEGER
15518            The row and column dimensions of the upper bidiagonal matrix.
15519 
15520     NRHS   (input) INTEGER
15521            The number of columns of B and BX. NRHS must be at least 1.
15522 
15523     B      (input/output) DOUBLE PRECISION array, dimension ( LDB, NRHS )
15524            On input, B contains the right hand sides of the least
15525            squares problem in rows 1 through M.
15526            On output, B contains the solution X in rows 1 through N.
15527 
15528     LDB    (input) INTEGER
15529            The leading dimension of B in the calling subprogram.
15530            LDB must be at least max(1,MAX( M, N ) ).
15531 
15532     BX     (output) DOUBLE PRECISION array, dimension ( LDBX, NRHS )
15533            On exit, the result of applying the left or right singular
15534            vector matrix to B.
15535 
15536     LDBX   (input) INTEGER
15537            The leading dimension of BX.
15538 
15539     U      (input) DOUBLE PRECISION array, dimension ( LDU, SMLSIZ ).
15540            On entry, U contains the left singular vector matrices of all
15541            subproblems at the bottom level.
15542 
15543     LDU    (input) INTEGER, LDU = > N.
15544            The leading dimension of arrays U, VT, DIFL, DIFR,
15545            POLES, GIVNUM, and Z.
15546 
15547     VT     (input) DOUBLE PRECISION array, dimension ( LDU, SMLSIZ+1 ).
15548            On entry, VT' contains the right singular vector matrices of
15549            all subproblems at the bottom level.
15550 
15551     K      (input) INTEGER array, dimension ( N ).
15552 
15553     DIFL   (input) DOUBLE PRECISION array, dimension ( LDU, NLVL ).
15554            where NLVL = INT(log_2 (N/(SMLSIZ+1))) + 1.
15555 
15556     DIFR   (input) DOUBLE PRECISION array, dimension ( LDU, 2 * NLVL ).
15557            On entry, DIFL(*, I) and DIFR(*, 2 * I -1) record
15558            distances between singular values on the I-th level and
15559            singular values on the (I -1)-th level, and DIFR(*, 2 * I)
15560            record the normalizing factors of the right singular vectors
15561            matrices of subproblems on I-th level.
15562 
15563     Z      (input) DOUBLE PRECISION array, dimension ( LDU, NLVL ).
15564            On entry, Z(1, I) contains the components of the deflation-
15565            adjusted updating row vector for subproblems on the I-th
15566            level.
15567 
15568     POLES  (input) DOUBLE PRECISION array, dimension ( LDU, 2 * NLVL ).
15569            On entry, POLES(*, 2 * I -1: 2 * I) contains the new and old
15570            singular values involved in the secular equations on the I-th
15571            level.
15572 
15573     GIVPTR (input) INTEGER array, dimension ( N ).
15574            On entry, GIVPTR( I ) records the number of Givens
15575            rotations performed on the I-th problem on the computation
15576            tree.
15577 
15578     GIVCOL (input) INTEGER array, dimension ( LDGCOL, 2 * NLVL ).
15579            On entry, for each I, GIVCOL(*, 2 * I - 1: 2 * I) records the
15580            locations of Givens rotations performed on the I-th level on
15581            the computation tree.
15582 
15583     LDGCOL (input) INTEGER, LDGCOL = > N.
15584            The leading dimension of arrays GIVCOL and PERM.
15585 
15586     PERM   (input) INTEGER array, dimension ( LDGCOL, NLVL ).
15587            On entry, PERM(*, I) records permutations done on the I-th
15588            level of the computation tree.
15589 
15590     GIVNUM (input) DOUBLE PRECISION array, dimension ( LDU, 2 * NLVL ).
15591            On entry, GIVNUM(*, 2 *I -1 : 2 * I) records the C- and S-
15592            values of Givens rotations performed on the I-th level on the
15593            computation tree.
15594 
15595     C      (input) DOUBLE PRECISION array, dimension ( N ).
15596            On entry, if the I-th subproblem is not square,
15597            C( I ) contains the C-value of a Givens rotation related to
15598            the right null space of the I-th subproblem.
15599 
15600     S      (input) DOUBLE PRECISION array, dimension ( N ).
15601            On entry, if the I-th subproblem is not square,
15602            S( I ) contains the S-value of a Givens rotation related to
15603            the right null space of the I-th subproblem.
15604 
15605     WORK   (workspace) DOUBLE PRECISION array.
15606            The dimension must be at least N.
15607 
15608     IWORK  (workspace) INTEGER array.
15609            The dimension must be at least 3 * N
15610 
15611     INFO   (output) INTEGER
15612             = 0:  successful exit.
15613             < 0:  if INFO = -i, the i-th argument had an illegal value.
15614 
15615     Further Details
15616     ===============
15617 
15618     Based on contributions by
15619        Ming Gu and Ren-Cang Li, Computer Science Division, University of
15620          California at Berkeley, USA
15621        Osni Marques, LBNL/NERSC, USA
15622 
15623     =====================================================================
15624 
15625 
15626        Test the input parameters.
15627 */
15628 
15629     /* Parameter adjustments */
15630     b_dim1 = *ldb;
15631     b_offset = 1 + b_dim1;
15632     b -= b_offset;
15633     bx_dim1 = *ldbx;
15634     bx_offset = 1 + bx_dim1;
15635     bx -= bx_offset;
15636     givnum_dim1 = *ldu;
15637     givnum_offset = 1 + givnum_dim1;
15638     givnum -= givnum_offset;
15639     poles_dim1 = *ldu;
15640     poles_offset = 1 + poles_dim1;
15641     poles -= poles_offset;
15642     z_dim1 = *ldu;
15643     z_offset = 1 + z_dim1;
15644     z__ -= z_offset;
15645     difr_dim1 = *ldu;
15646     difr_offset = 1 + difr_dim1;
15647     difr -= difr_offset;
15648     difl_dim1 = *ldu;
15649     difl_offset = 1 + difl_dim1;
15650     difl -= difl_offset;
15651     vt_dim1 = *ldu;
15652     vt_offset = 1 + vt_dim1;
15653     vt -= vt_offset;
15654     u_dim1 = *ldu;
15655     u_offset = 1 + u_dim1;
15656     u -= u_offset;
15657     --k;
15658     --givptr;
15659     perm_dim1 = *ldgcol;
15660     perm_offset = 1 + perm_dim1;
15661     perm -= perm_offset;
15662     givcol_dim1 = *ldgcol;
15663     givcol_offset = 1 + givcol_dim1;
15664     givcol -= givcol_offset;
15665     --c__;
15666     --s;
15667     --work;
15668     --iwork;
15669 
15670     /* Function Body */
15671     *info = 0;
15672 
15673     if (*icompq < 0 || *icompq > 1) {
15674 	*info = -1;
15675     } else if (*smlsiz < 3) {
15676 	*info = -2;
15677     } else if (*n < *smlsiz) {
15678 	*info = -3;
15679     } else if (*nrhs < 1) {
15680 	*info = -4;
15681     } else if (*ldb < *n) {
15682 	*info = -6;
15683     } else if (*ldbx < *n) {
15684 	*info = -8;
15685     } else if (*ldu < *n) {
15686 	*info = -10;
15687     } else if (*ldgcol < *n) {
15688 	*info = -19;
15689     }
15690     if (*info != 0) {
15691 	i__1 = -(*info);
15692 	xerbla_("DLALSA", &i__1);
15693 	return 0;
15694     }
15695 
15696 /*     Book-keeping and  setting up the computation tree. */
15697 
15698     inode = 1;
15699     ndiml = inode + *n;
15700     ndimr = ndiml + *n;
15701 
15702     dlasdt_(n, &nlvl, &nd, &iwork[inode], &iwork[ndiml], &iwork[ndimr],
15703 	    smlsiz);
15704 
15705 /*
15706        The following code applies back the left singular vector factors.
15707        For applying back the right singular vector factors, go to 50.
15708 */
15709 
15710     if (*icompq == 1) {
15711 	goto L50;
15712     }
15713 
15714 /*
15715        The nodes on the bottom level of the tree were solved
15716        by DLASDQ. The corresponding left and right singular vector
15717        matrices are in explicit form. First apply back the left
15718        singular vector matrices.
15719 */
15720 
15721     ndb1 = (nd + 1) / 2;
15722     i__1 = nd;
15723     for (i__ = ndb1; i__ <= i__1; ++i__) {
15724 
15725 /*
15726           IC : center row of each node
15727           NL : number of rows of left  subproblem
15728           NR : number of rows of right subproblem
15729           NLF: starting row of the left   subproblem
15730           NRF: starting row of the right  subproblem
15731 */
15732 
15733 	i1 = i__ - 1;
15734 	ic = iwork[inode + i1];
15735 	nl = iwork[ndiml + i1];
15736 	nr = iwork[ndimr + i1];
15737 	nlf = ic - nl;
15738 	nrf = ic + 1;
15739 	dgemm_("T", "N", &nl, nrhs, &nl, &c_b15, &u[nlf + u_dim1], ldu, &b[
15740 		nlf + b_dim1], ldb, &c_b29, &bx[nlf + bx_dim1], ldbx);
15741 	dgemm_("T", "N", &nr, nrhs, &nr, &c_b15, &u[nrf + u_dim1], ldu, &b[
15742 		nrf + b_dim1], ldb, &c_b29, &bx[nrf + bx_dim1], ldbx);
15743 /* L10: */
15744     }
15745 
15746 /*
15747        Next copy the rows of B that correspond to unchanged rows
15748        in the bidiagonal matrix to BX.
15749 */
15750 
15751     i__1 = nd;
15752     for (i__ = 1; i__ <= i__1; ++i__) {
15753 	ic = iwork[inode + i__ - 1];
15754 	dcopy_(nrhs, &b[ic + b_dim1], ldb, &bx[ic + bx_dim1], ldbx);
15755 /* L20: */
15756     }
15757 
15758 /*
15759        Finally go through the left singular vector matrices of all
15760        the other subproblems bottom-up on the tree.
15761 */
15762 
15763     j = pow_ii(&c__2, &nlvl);
15764     sqre = 0;
15765 
15766     for (lvl = nlvl; lvl >= 1; --lvl) {
15767 	lvl2 = (lvl << 1) - 1;
15768 
15769 /*
15770           find the first node LF and last node LL on
15771           the current level LVL
15772 */
15773 
15774 	if (lvl == 1) {
15775 	    lf = 1;
15776 	    ll = 1;
15777 	} else {
15778 	    i__1 = lvl - 1;
15779 	    lf = pow_ii(&c__2, &i__1);
15780 	    ll = (lf << 1) - 1;
15781 	}
15782 	i__1 = ll;
15783 	for (i__ = lf; i__ <= i__1; ++i__) {
15784 	    im1 = i__ - 1;
15785 	    ic = iwork[inode + im1];
15786 	    nl = iwork[ndiml + im1];
15787 	    nr = iwork[ndimr + im1];
15788 	    nlf = ic - nl;
15789 	    nrf = ic + 1;
15790 	    --j;
15791 	    dlals0_(icompq, &nl, &nr, &sqre, nrhs, &bx[nlf + bx_dim1], ldbx, &
15792 		    b[nlf + b_dim1], ldb, &perm[nlf + lvl * perm_dim1], &
15793 		    givptr[j], &givcol[nlf + lvl2 * givcol_dim1], ldgcol, &
15794 		    givnum[nlf + lvl2 * givnum_dim1], ldu, &poles[nlf + lvl2 *
15795 		     poles_dim1], &difl[nlf + lvl * difl_dim1], &difr[nlf +
15796 		    lvl2 * difr_dim1], &z__[nlf + lvl * z_dim1], &k[j], &c__[
15797 		    j], &s[j], &work[1], info);
15798 /* L30: */
15799 	}
15800 /* L40: */
15801     }
15802     goto L90;
15803 
15804 /*     ICOMPQ = 1: applying back the right singular vector factors. */
15805 
15806 L50:
15807 
15808 /*
15809        First now go through the right singular vector matrices of all
15810        the tree nodes top-down.
15811 */
15812 
15813     j = 0;
15814     i__1 = nlvl;
15815     for (lvl = 1; lvl <= i__1; ++lvl) {
15816 	lvl2 = (lvl << 1) - 1;
15817 
15818 /*
15819           Find the first node LF and last node LL on
15820           the current level LVL.
15821 */
15822 
15823 	if (lvl == 1) {
15824 	    lf = 1;
15825 	    ll = 1;
15826 	} else {
15827 	    i__2 = lvl - 1;
15828 	    lf = pow_ii(&c__2, &i__2);
15829 	    ll = (lf << 1) - 1;
15830 	}
15831 	i__2 = lf;
15832 	for (i__ = ll; i__ >= i__2; --i__) {
15833 	    im1 = i__ - 1;
15834 	    ic = iwork[inode + im1];
15835 	    nl = iwork[ndiml + im1];
15836 	    nr = iwork[ndimr + im1];
15837 	    nlf = ic - nl;
15838 	    nrf = ic + 1;
15839 	    if (i__ == ll) {
15840 		sqre = 0;
15841 	    } else {
15842 		sqre = 1;
15843 	    }
15844 	    ++j;
15845 	    dlals0_(icompq, &nl, &nr, &sqre, nrhs, &b[nlf + b_dim1], ldb, &bx[
15846 		    nlf + bx_dim1], ldbx, &perm[nlf + lvl * perm_dim1], &
15847 		    givptr[j], &givcol[nlf + lvl2 * givcol_dim1], ldgcol, &
15848 		    givnum[nlf + lvl2 * givnum_dim1], ldu, &poles[nlf + lvl2 *
15849 		     poles_dim1], &difl[nlf + lvl * difl_dim1], &difr[nlf +
15850 		    lvl2 * difr_dim1], &z__[nlf + lvl * z_dim1], &k[j], &c__[
15851 		    j], &s[j], &work[1], info);
15852 /* L60: */
15853 	}
15854 /* L70: */
15855     }
15856 
15857 /*
15858        The nodes on the bottom level of the tree were solved
15859        by DLASDQ. The corresponding right singular vector
15860        matrices are in explicit form. Apply them back.
15861 */
15862 
15863     ndb1 = (nd + 1) / 2;
15864     i__1 = nd;
15865     for (i__ = ndb1; i__ <= i__1; ++i__) {
15866 	i1 = i__ - 1;
15867 	ic = iwork[inode + i1];
15868 	nl = iwork[ndiml + i1];
15869 	nr = iwork[ndimr + i1];
15870 	nlp1 = nl + 1;
15871 	if (i__ == nd) {
15872 	    nrp1 = nr;
15873 	} else {
15874 	    nrp1 = nr + 1;
15875 	}
15876 	nlf = ic - nl;
15877 	nrf = ic + 1;
15878 	dgemm_("T", "N", &nlp1, nrhs, &nlp1, &c_b15, &vt[nlf + vt_dim1], ldu,
15879 		&b[nlf + b_dim1], ldb, &c_b29, &bx[nlf + bx_dim1], ldbx);
15880 	dgemm_("T", "N", &nrp1, nrhs, &nrp1, &c_b15, &vt[nrf + vt_dim1], ldu,
15881 		&b[nrf + b_dim1], ldb, &c_b29, &bx[nrf + bx_dim1], ldbx);
15882 /* L80: */
15883     }
15884 
15885 L90:
15886 
15887     return 0;
15888 
15889 /*     End of DLALSA */
15890 
15891 } /* dlalsa_ */
15892 
dlalsd_(char * uplo,integer * smlsiz,integer * n,integer * nrhs,doublereal * d__,doublereal * e,doublereal * b,integer * ldb,doublereal * rcond,integer * rank,doublereal * work,integer * iwork,integer * info)15893 /* Subroutine */ int dlalsd_(char *uplo, integer *smlsiz, integer *n, integer
15894 	*nrhs, doublereal *d__, doublereal *e, doublereal *b, integer *ldb,
15895 	doublereal *rcond, integer *rank, doublereal *work, integer *iwork,
15896 	integer *info)
15897 {
15898     /* System generated locals */
15899     integer b_dim1, b_offset, i__1, i__2;
15900     doublereal d__1;
15901 
15902     /* Local variables */
15903     static integer c__, i__, j, k;
15904     static doublereal r__;
15905     static integer s, u, z__;
15906     static doublereal cs;
15907     static integer bx;
15908     static doublereal sn;
15909     static integer st, vt, nm1, st1;
15910     static doublereal eps;
15911     static integer iwk;
15912     static doublereal tol;
15913     static integer difl, difr;
15914     static doublereal rcnd;
15915     static integer perm, nsub;
15916     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
15917 	    doublereal *, integer *, doublereal *, doublereal *);
15918     static integer nlvl, sqre, bxst;
15919     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
15920 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
15921 	    integer *, doublereal *, doublereal *, integer *),
15922 	     dcopy_(integer *, doublereal *, integer *, doublereal *, integer
15923 	    *);
15924     static integer poles, sizei, nsize, nwork, icmpq1, icmpq2;
15925 
15926     extern /* Subroutine */ int dlasda_(integer *, integer *, integer *,
15927 	    integer *, doublereal *, doublereal *, doublereal *, integer *,
15928 	    doublereal *, integer *, doublereal *, doublereal *, doublereal *,
15929 	     doublereal *, integer *, integer *, integer *, integer *,
15930 	    doublereal *, doublereal *, doublereal *, doublereal *, integer *,
15931 	     integer *), dlalsa_(integer *, integer *, integer *, integer *,
15932 	    doublereal *, integer *, doublereal *, integer *, doublereal *,
15933 	    integer *, doublereal *, integer *, doublereal *, doublereal *,
15934 	    doublereal *, doublereal *, integer *, integer *, integer *,
15935 	    integer *, doublereal *, doublereal *, doublereal *, doublereal *,
15936 	     integer *, integer *), dlascl_(char *, integer *, integer *,
15937 	    doublereal *, doublereal *, integer *, integer *, doublereal *,
15938 	    integer *, integer *);
15939     extern integer idamax_(integer *, doublereal *, integer *);
15940     extern /* Subroutine */ int dlasdq_(char *, integer *, integer *, integer
15941 	    *, integer *, integer *, doublereal *, doublereal *, doublereal *,
15942 	     integer *, doublereal *, integer *, doublereal *, integer *,
15943 	    doublereal *, integer *), dlacpy_(char *, integer *,
15944 	    integer *, doublereal *, integer *, doublereal *, integer *), dlartg_(doublereal *, doublereal *, doublereal *,
15945 	    doublereal *, doublereal *), dlaset_(char *, integer *, integer *,
15946 	     doublereal *, doublereal *, doublereal *, integer *),
15947 	    xerbla_(char *, integer *);
15948     static integer givcol;
15949     extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
15950     extern /* Subroutine */ int dlasrt_(char *, integer *, doublereal *,
15951 	    integer *);
15952     static doublereal orgnrm;
15953     static integer givnum, givptr, smlszp;
15954 
15955 
15956 /*
15957     -- LAPACK routine (version 3.2.2) --
15958     -- LAPACK is a software package provided by Univ. of Tennessee,    --
15959     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
15960        June 2010
15961 
15962 
15963     Purpose
15964     =======
15965 
15966     DLALSD uses the singular value decomposition of A to solve the least
15967     squares problem of finding X to minimize the Euclidean norm of each
15968     column of A*X-B, where A is N-by-N upper bidiagonal, and X and B
15969     are N-by-NRHS. The solution X overwrites B.
15970 
15971     The singular values of A smaller than RCOND times the largest
15972     singular value are treated as zero in solving the least squares
15973     problem; in this case a minimum norm solution is returned.
15974     The actual singular values are returned in D in ascending order.
15975 
15976     This code makes very mild assumptions about floating point
15977     arithmetic. It will work on machines with a guard digit in
15978     add/subtract, or on those binary machines without guard digits
15979     which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2.
15980     It could conceivably fail on hexadecimal or decimal machines
15981     without guard digits, but we know of none.
15982 
15983     Arguments
15984     =========
15985 
15986     UPLO   (input) CHARACTER*1
15987            = 'U': D and E define an upper bidiagonal matrix.
15988            = 'L': D and E define a  lower bidiagonal matrix.
15989 
15990     SMLSIZ (input) INTEGER
15991            The maximum size of the subproblems at the bottom of the
15992            computation tree.
15993 
15994     N      (input) INTEGER
15995            The dimension of the  bidiagonal matrix.  N >= 0.
15996 
15997     NRHS   (input) INTEGER
15998            The number of columns of B. NRHS must be at least 1.
15999 
16000     D      (input/output) DOUBLE PRECISION array, dimension (N)
16001            On entry D contains the main diagonal of the bidiagonal
16002            matrix. On exit, if INFO = 0, D contains its singular values.
16003 
16004     E      (input/output) DOUBLE PRECISION array, dimension (N-1)
16005            Contains the super-diagonal entries of the bidiagonal matrix.
16006            On exit, E has been destroyed.
16007 
16008     B      (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
16009            On input, B contains the right hand sides of the least
16010            squares problem. On output, B contains the solution X.
16011 
16012     LDB    (input) INTEGER
16013            The leading dimension of B in the calling subprogram.
16014            LDB must be at least max(1,N).
16015 
16016     RCOND  (input) DOUBLE PRECISION
16017            The singular values of A less than or equal to RCOND times
16018            the largest singular value are treated as zero in solving
16019            the least squares problem. If RCOND is negative,
16020            machine precision is used instead.
16021            For example, if diag(S)*X=B were the least squares problem,
16022            where diag(S) is a diagonal matrix of singular values, the
16023            solution would be X(i) = B(i) / S(i) if S(i) is greater than
16024            RCOND*max(S), and X(i) = 0 if S(i) is less than or equal to
16025            RCOND*max(S).
16026 
16027     RANK   (output) INTEGER
16028            The number of singular values of A greater than RCOND times
16029            the largest singular value.
16030 
16031     WORK   (workspace) DOUBLE PRECISION array, dimension at least
16032            (9*N + 2*N*SMLSIZ + 8*N*NLVL + N*NRHS + (SMLSIZ+1)**2),
16033            where NLVL = max(0, INT(log_2 (N/(SMLSIZ+1))) + 1).
16034 
16035     IWORK  (workspace) INTEGER array, dimension at least
16036            (3*N*NLVL + 11*N)
16037 
16038     INFO   (output) INTEGER
16039            = 0:  successful exit.
16040            < 0:  if INFO = -i, the i-th argument had an illegal value.
16041            > 0:  The algorithm failed to compute a singular value while
16042                  working on the submatrix lying in rows and columns
16043                  INFO/(N+1) through MOD(INFO,N+1).
16044 
16045     Further Details
16046     ===============
16047 
16048     Based on contributions by
16049        Ming Gu and Ren-Cang Li, Computer Science Division, University of
16050          California at Berkeley, USA
16051        Osni Marques, LBNL/NERSC, USA
16052 
16053     =====================================================================
16054 
16055 
16056        Test the input parameters.
16057 */
16058 
16059     /* Parameter adjustments */
16060     --d__;
16061     --e;
16062     b_dim1 = *ldb;
16063     b_offset = 1 + b_dim1;
16064     b -= b_offset;
16065     --work;
16066     --iwork;
16067 
16068     /* Function Body */
16069     *info = 0;
16070 
16071     if (*n < 0) {
16072 	*info = -3;
16073     } else if (*nrhs < 1) {
16074 	*info = -4;
16075     } else if (*ldb < 1 || *ldb < *n) {
16076 	*info = -8;
16077     }
16078     if (*info != 0) {
16079 	i__1 = -(*info);
16080 	xerbla_("DLALSD", &i__1);
16081 	return 0;
16082     }
16083 
16084     eps = EPSILON;
16085 
16086 /*     Set up the tolerance. */
16087 
16088     if (*rcond <= 0. || *rcond >= 1.) {
16089 	rcnd = eps;
16090     } else {
16091 	rcnd = *rcond;
16092     }
16093 
16094     *rank = 0;
16095 
16096 /*     Quick return if possible. */
16097 
16098     if (*n == 0) {
16099 	return 0;
16100     } else if (*n == 1) {
16101 	if (d__[1] == 0.) {
16102 	    dlaset_("A", &c__1, nrhs, &c_b29, &c_b29, &b[b_offset], ldb);
16103 	} else {
16104 	    *rank = 1;
16105 	    dlascl_("G", &c__0, &c__0, &d__[1], &c_b15, &c__1, nrhs, &b[
16106 		    b_offset], ldb, info);
16107 	    d__[1] = abs(d__[1]);
16108 	}
16109 	return 0;
16110     }
16111 
16112 /*     Rotate the matrix if it is lower bidiagonal. */
16113 
16114     if (*(unsigned char *)uplo == 'L') {
16115 	i__1 = *n - 1;
16116 	for (i__ = 1; i__ <= i__1; ++i__) {
16117 	    dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
16118 	    d__[i__] = r__;
16119 	    e[i__] = sn * d__[i__ + 1];
16120 	    d__[i__ + 1] = cs * d__[i__ + 1];
16121 	    if (*nrhs == 1) {
16122 		drot_(&c__1, &b[i__ + b_dim1], &c__1, &b[i__ + 1 + b_dim1], &
16123 			c__1, &cs, &sn);
16124 	    } else {
16125 		work[(i__ << 1) - 1] = cs;
16126 		work[i__ * 2] = sn;
16127 	    }
16128 /* L10: */
16129 	}
16130 	if (*nrhs > 1) {
16131 	    i__1 = *nrhs;
16132 	    for (i__ = 1; i__ <= i__1; ++i__) {
16133 		i__2 = *n - 1;
16134 		for (j = 1; j <= i__2; ++j) {
16135 		    cs = work[(j << 1) - 1];
16136 		    sn = work[j * 2];
16137 		    drot_(&c__1, &b[j + i__ * b_dim1], &c__1, &b[j + 1 + i__ *
16138 			     b_dim1], &c__1, &cs, &sn);
16139 /* L20: */
16140 		}
16141 /* L30: */
16142 	    }
16143 	}
16144     }
16145 
16146 /*     Scale. */
16147 
16148     nm1 = *n - 1;
16149     orgnrm = dlanst_("M", n, &d__[1], &e[1]);
16150     if (orgnrm == 0.) {
16151 	dlaset_("A", n, nrhs, &c_b29, &c_b29, &b[b_offset], ldb);
16152 	return 0;
16153     }
16154 
16155     dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, n, &c__1, &d__[1], n, info);
16156     dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, &nm1, &c__1, &e[1], &nm1,
16157 	    info);
16158 
16159 /*
16160        If N is smaller than the minimum divide size SMLSIZ, then solve
16161        the problem with another solver.
16162 */
16163 
16164     if (*n <= *smlsiz) {
16165 	nwork = *n * *n + 1;
16166 	dlaset_("A", n, n, &c_b29, &c_b15, &work[1], n);
16167 	dlasdq_("U", &c__0, n, n, &c__0, nrhs, &d__[1], &e[1], &work[1], n, &
16168 		work[1], n, &b[b_offset], ldb, &work[nwork], info);
16169 	if (*info != 0) {
16170 	    return 0;
16171 	}
16172 	tol = rcnd * (d__1 = d__[idamax_(n, &d__[1], &c__1)], abs(d__1));
16173 	i__1 = *n;
16174 	for (i__ = 1; i__ <= i__1; ++i__) {
16175 	    if (d__[i__] <= tol) {
16176 		dlaset_("A", &c__1, nrhs, &c_b29, &c_b29, &b[i__ + b_dim1],
16177 			ldb);
16178 	    } else {
16179 		dlascl_("G", &c__0, &c__0, &d__[i__], &c_b15, &c__1, nrhs, &b[
16180 			i__ + b_dim1], ldb, info);
16181 		++(*rank);
16182 	    }
16183 /* L40: */
16184 	}
16185 	dgemm_("T", "N", n, nrhs, n, &c_b15, &work[1], n, &b[b_offset], ldb, &
16186 		c_b29, &work[nwork], n);
16187 	dlacpy_("A", n, nrhs, &work[nwork], n, &b[b_offset], ldb);
16188 
16189 /*        Unscale. */
16190 
16191 	dlascl_("G", &c__0, &c__0, &c_b15, &orgnrm, n, &c__1, &d__[1], n,
16192 		info);
16193 	dlasrt_("D", n, &d__[1], info);
16194 	dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, n, nrhs, &b[b_offset],
16195 		ldb, info);
16196 
16197 	return 0;
16198     }
16199 
16200 /*     Book-keeping and setting up some constants. */
16201 
16202     nlvl = (integer) (log((doublereal) (*n) / (doublereal) (*smlsiz + 1)) /
16203 	    log(2.)) + 1;
16204 
16205     smlszp = *smlsiz + 1;
16206 
16207     u = 1;
16208     vt = *smlsiz * *n + 1;
16209     difl = vt + smlszp * *n;
16210     difr = difl + nlvl * *n;
16211     z__ = difr + (nlvl * *n << 1);
16212     c__ = z__ + nlvl * *n;
16213     s = c__ + *n;
16214     poles = s + *n;
16215     givnum = poles + (nlvl << 1) * *n;
16216     bx = givnum + (nlvl << 1) * *n;
16217     nwork = bx + *n * *nrhs;
16218 
16219     sizei = *n + 1;
16220     k = sizei + *n;
16221     givptr = k + *n;
16222     perm = givptr + *n;
16223     givcol = perm + nlvl * *n;
16224     iwk = givcol + (nlvl * *n << 1);
16225 
16226     st = 1;
16227     sqre = 0;
16228     icmpq1 = 1;
16229     icmpq2 = 0;
16230     nsub = 0;
16231 
16232     i__1 = *n;
16233     for (i__ = 1; i__ <= i__1; ++i__) {
16234 	if ((d__1 = d__[i__], abs(d__1)) < eps) {
16235 	    d__[i__] = d_sign(&eps, &d__[i__]);
16236 	}
16237 /* L50: */
16238     }
16239 
16240     i__1 = nm1;
16241     for (i__ = 1; i__ <= i__1; ++i__) {
16242 	if ((d__1 = e[i__], abs(d__1)) < eps || i__ == nm1) {
16243 	    ++nsub;
16244 	    iwork[nsub] = st;
16245 
16246 /*
16247              Subproblem found. First determine its size and then
16248              apply divide and conquer on it.
16249 */
16250 
16251 	    if (i__ < nm1) {
16252 
16253 /*              A subproblem with E(I) small for I < NM1. */
16254 
16255 		nsize = i__ - st + 1;
16256 		iwork[sizei + nsub - 1] = nsize;
16257 	    } else if ((d__1 = e[i__], abs(d__1)) >= eps) {
16258 
16259 /*              A subproblem with E(NM1) not too small but I = NM1. */
16260 
16261 		nsize = *n - st + 1;
16262 		iwork[sizei + nsub - 1] = nsize;
16263 	    } else {
16264 
16265 /*
16266                 A subproblem with E(NM1) small. This implies an
16267                 1-by-1 subproblem at D(N), which is not solved
16268                 explicitly.
16269 */
16270 
16271 		nsize = i__ - st + 1;
16272 		iwork[sizei + nsub - 1] = nsize;
16273 		++nsub;
16274 		iwork[nsub] = *n;
16275 		iwork[sizei + nsub - 1] = 1;
16276 		dcopy_(nrhs, &b[*n + b_dim1], ldb, &work[bx + nm1], n);
16277 	    }
16278 	    st1 = st - 1;
16279 	    if (nsize == 1) {
16280 
16281 /*
16282                 This is a 1-by-1 subproblem and is not solved
16283                 explicitly.
16284 */
16285 
16286 		dcopy_(nrhs, &b[st + b_dim1], ldb, &work[bx + st1], n);
16287 	    } else if (nsize <= *smlsiz) {
16288 
16289 /*              This is a small subproblem and is solved by DLASDQ. */
16290 
16291 		dlaset_("A", &nsize, &nsize, &c_b29, &c_b15, &work[vt + st1],
16292 			n);
16293 		dlasdq_("U", &c__0, &nsize, &nsize, &c__0, nrhs, &d__[st], &e[
16294 			st], &work[vt + st1], n, &work[nwork], n, &b[st +
16295 			b_dim1], ldb, &work[nwork], info);
16296 		if (*info != 0) {
16297 		    return 0;
16298 		}
16299 		dlacpy_("A", &nsize, nrhs, &b[st + b_dim1], ldb, &work[bx +
16300 			st1], n);
16301 	    } else {
16302 
16303 /*              A large problem. Solve it using divide and conquer. */
16304 
16305 		dlasda_(&icmpq1, smlsiz, &nsize, &sqre, &d__[st], &e[st], &
16306 			work[u + st1], n, &work[vt + st1], &iwork[k + st1], &
16307 			work[difl + st1], &work[difr + st1], &work[z__ + st1],
16308 			 &work[poles + st1], &iwork[givptr + st1], &iwork[
16309 			givcol + st1], n, &iwork[perm + st1], &work[givnum +
16310 			st1], &work[c__ + st1], &work[s + st1], &work[nwork],
16311 			&iwork[iwk], info);
16312 		if (*info != 0) {
16313 		    return 0;
16314 		}
16315 		bxst = bx + st1;
16316 		dlalsa_(&icmpq2, smlsiz, &nsize, nrhs, &b[st + b_dim1], ldb, &
16317 			work[bxst], n, &work[u + st1], n, &work[vt + st1], &
16318 			iwork[k + st1], &work[difl + st1], &work[difr + st1],
16319 			&work[z__ + st1], &work[poles + st1], &iwork[givptr +
16320 			st1], &iwork[givcol + st1], n, &iwork[perm + st1], &
16321 			work[givnum + st1], &work[c__ + st1], &work[s + st1],
16322 			&work[nwork], &iwork[iwk], info);
16323 		if (*info != 0) {
16324 		    return 0;
16325 		}
16326 	    }
16327 	    st = i__ + 1;
16328 	}
16329 /* L60: */
16330     }
16331 
16332 /*     Apply the singular values and treat the tiny ones as zero. */
16333 
16334     tol = rcnd * (d__1 = d__[idamax_(n, &d__[1], &c__1)], abs(d__1));
16335 
16336     i__1 = *n;
16337     for (i__ = 1; i__ <= i__1; ++i__) {
16338 
16339 /*
16340           Some of the elements in D can be negative because 1-by-1
16341           subproblems were not solved explicitly.
16342 */
16343 
16344 	if ((d__1 = d__[i__], abs(d__1)) <= tol) {
16345 	    dlaset_("A", &c__1, nrhs, &c_b29, &c_b29, &work[bx + i__ - 1], n);
16346 	} else {
16347 	    ++(*rank);
16348 	    dlascl_("G", &c__0, &c__0, &d__[i__], &c_b15, &c__1, nrhs, &work[
16349 		    bx + i__ - 1], n, info);
16350 	}
16351 	d__[i__] = (d__1 = d__[i__], abs(d__1));
16352 /* L70: */
16353     }
16354 
16355 /*     Now apply back the right singular vectors. */
16356 
16357     icmpq2 = 1;
16358     i__1 = nsub;
16359     for (i__ = 1; i__ <= i__1; ++i__) {
16360 	st = iwork[i__];
16361 	st1 = st - 1;
16362 	nsize = iwork[sizei + i__ - 1];
16363 	bxst = bx + st1;
16364 	if (nsize == 1) {
16365 	    dcopy_(nrhs, &work[bxst], n, &b[st + b_dim1], ldb);
16366 	} else if (nsize <= *smlsiz) {
16367 	    dgemm_("T", "N", &nsize, nrhs, &nsize, &c_b15, &work[vt + st1], n,
16368 		     &work[bxst], n, &c_b29, &b[st + b_dim1], ldb);
16369 	} else {
16370 	    dlalsa_(&icmpq2, smlsiz, &nsize, nrhs, &work[bxst], n, &b[st +
16371 		    b_dim1], ldb, &work[u + st1], n, &work[vt + st1], &iwork[
16372 		    k + st1], &work[difl + st1], &work[difr + st1], &work[z__
16373 		    + st1], &work[poles + st1], &iwork[givptr + st1], &iwork[
16374 		    givcol + st1], n, &iwork[perm + st1], &work[givnum + st1],
16375 		     &work[c__ + st1], &work[s + st1], &work[nwork], &iwork[
16376 		    iwk], info);
16377 	    if (*info != 0) {
16378 		return 0;
16379 	    }
16380 	}
16381 /* L80: */
16382     }
16383 
16384 /*     Unscale and sort the singular values. */
16385 
16386     dlascl_("G", &c__0, &c__0, &c_b15, &orgnrm, n, &c__1, &d__[1], n, info);
16387     dlasrt_("D", n, &d__[1], info);
16388     dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, n, nrhs, &b[b_offset], ldb,
16389 	    info);
16390 
16391     return 0;
16392 
16393 /*     End of DLALSD */
16394 
16395 } /* dlalsd_ */
16396 
dlamrg_(integer * n1,integer * n2,doublereal * a,integer * dtrd1,integer * dtrd2,integer * index)16397 /* Subroutine */ int dlamrg_(integer *n1, integer *n2, doublereal *a, integer
16398 	*dtrd1, integer *dtrd2, integer *index)
16399 {
16400     /* System generated locals */
16401     integer i__1;
16402 
16403     /* Local variables */
16404     static integer i__, ind1, ind2, n1sv, n2sv;
16405 
16406 
16407 /*
16408     -- LAPACK routine (version 3.2) --
16409     -- LAPACK is a software package provided by Univ. of Tennessee,    --
16410     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
16411        November 2006
16412 
16413 
16414     Purpose
16415     =======
16416 
16417     DLAMRG will create a permutation list which will merge the elements
16418     of A (which is composed of two independently sorted sets) into a
16419     single set which is sorted in ascending order.
16420 
16421     Arguments
16422     =========
16423 
16424     N1     (input) INTEGER
16425     N2     (input) INTEGER
16426            These arguements contain the respective lengths of the two
16427            sorted lists to be merged.
16428 
16429     A      (input) DOUBLE PRECISION array, dimension (N1+N2)
16430            The first N1 elements of A contain a list of numbers which
16431            are sorted in either ascending or descending order.  Likewise
16432            for the final N2 elements.
16433 
16434     DTRD1  (input) INTEGER
16435     DTRD2  (input) INTEGER
16436            These are the strides to be taken through the array A.
16437            Allowable strides are 1 and -1.  They indicate whether a
16438            subset of A is sorted in ascending (DTRDx = 1) or descending
16439            (DTRDx = -1) order.
16440 
16441     INDEX  (output) INTEGER array, dimension (N1+N2)
16442            On exit this array will contain a permutation such that
16443            if B( I ) = A( INDEX( I ) ) for I=1,N1+N2, then B will be
16444            sorted in ascending order.
16445 
16446     =====================================================================
16447 */
16448 
16449 
16450     /* Parameter adjustments */
16451     --index;
16452     --a;
16453 
16454     /* Function Body */
16455     n1sv = *n1;
16456     n2sv = *n2;
16457     if (*dtrd1 > 0) {
16458 	ind1 = 1;
16459     } else {
16460 	ind1 = *n1;
16461     }
16462     if (*dtrd2 > 0) {
16463 	ind2 = *n1 + 1;
16464     } else {
16465 	ind2 = *n1 + *n2;
16466     }
16467     i__ = 1;
16468 /*     while ( (N1SV > 0) & (N2SV > 0) ) */
16469 L10:
16470     if (n1sv > 0 && n2sv > 0) {
16471 	if (a[ind1] <= a[ind2]) {
16472 	    index[i__] = ind1;
16473 	    ++i__;
16474 	    ind1 += *dtrd1;
16475 	    --n1sv;
16476 	} else {
16477 	    index[i__] = ind2;
16478 	    ++i__;
16479 	    ind2 += *dtrd2;
16480 	    --n2sv;
16481 	}
16482 	goto L10;
16483     }
16484 /*     end while */
16485     if (n1sv == 0) {
16486 	i__1 = n2sv;
16487 	for (n1sv = 1; n1sv <= i__1; ++n1sv) {
16488 	    index[i__] = ind2;
16489 	    ++i__;
16490 	    ind2 += *dtrd2;
16491 /* L20: */
16492 	}
16493     } else {
16494 /*     N2SV .EQ. 0 */
16495 	i__1 = n1sv;
16496 	for (n2sv = 1; n2sv <= i__1; ++n2sv) {
16497 	    index[i__] = ind1;
16498 	    ++i__;
16499 	    ind1 += *dtrd1;
16500 /* L30: */
16501 	}
16502     }
16503 
16504     return 0;
16505 
16506 /*     End of DLAMRG */
16507 
16508 } /* dlamrg_ */
16509 
dlange_(char * norm,integer * m,integer * n,doublereal * a,integer * lda,doublereal * work)16510 doublereal dlange_(char *norm, integer *m, integer *n, doublereal *a, integer
16511 	*lda, doublereal *work)
16512 {
16513     /* System generated locals */
16514     integer a_dim1, a_offset, i__1, i__2;
16515     doublereal ret_val, d__1, d__2, d__3;
16516 
16517     /* Local variables */
16518     static integer i__, j;
16519     static doublereal sum, scale;
16520     extern logical lsame_(char *, char *);
16521     static doublereal value;
16522     extern /* Subroutine */ int dlassq_(integer *, doublereal *, integer *,
16523 	    doublereal *, doublereal *);
16524 
16525 
16526 /*
16527     -- LAPACK auxiliary routine (version 3.2) --
16528     -- LAPACK is a software package provided by Univ. of Tennessee,    --
16529     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
16530        November 2006
16531 
16532 
16533     Purpose
16534     =======
16535 
16536     DLANGE  returns the value of the one norm,  or the Frobenius norm, or
16537     the  infinity norm,  or the  element of  largest absolute value  of a
16538     real matrix A.
16539 
16540     Description
16541     ===========
16542 
16543     DLANGE returns the value
16544 
16545        DLANGE = ( max(abs(A(i,j))), NORM = 'M' or 'm'
16546                 (
16547                 ( norm1(A),         NORM = '1', 'O' or 'o'
16548                 (
16549                 ( normI(A),         NORM = 'I' or 'i'
16550                 (
16551                 ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
16552 
16553     where  norm1  denotes the  one norm of a matrix (maximum column sum),
16554     normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
16555     normF  denotes the  Frobenius norm of a matrix (square root of sum of
16556     squares).  Note that  max(abs(A(i,j)))  is not a consistent matrix norm.
16557 
16558     Arguments
16559     =========
16560 
16561     NORM    (input) CHARACTER*1
16562             Specifies the value to be returned in DLANGE as described
16563             above.
16564 
16565     M       (input) INTEGER
16566             The number of rows of the matrix A.  M >= 0.  When M = 0,
16567             DLANGE is set to zero.
16568 
16569     N       (input) INTEGER
16570             The number of columns of the matrix A.  N >= 0.  When N = 0,
16571             DLANGE is set to zero.
16572 
16573     A       (input) DOUBLE PRECISION array, dimension (LDA,N)
16574             The m by n matrix A.
16575 
16576     LDA     (input) INTEGER
16577             The leading dimension of the array A.  LDA >= max(M,1).
16578 
16579     WORK    (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),
16580             where LWORK >= M when NORM = 'I'; otherwise, WORK is not
16581             referenced.
16582 
16583    =====================================================================
16584 */
16585 
16586 
16587     /* Parameter adjustments */
16588     a_dim1 = *lda;
16589     a_offset = 1 + a_dim1;
16590     a -= a_offset;
16591     --work;
16592 
16593     /* Function Body */
16594     if (min(*m,*n) == 0) {
16595 	value = 0.;
16596     } else if (lsame_(norm, "M")) {
16597 
16598 /*        Find max(abs(A(i,j))). */
16599 
16600 	value = 0.;
16601 	i__1 = *n;
16602 	for (j = 1; j <= i__1; ++j) {
16603 	    i__2 = *m;
16604 	    for (i__ = 1; i__ <= i__2; ++i__) {
16605 /* Computing MAX */
16606 		d__2 = value, d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
16607 		value = max(d__2,d__3);
16608 /* L10: */
16609 	    }
16610 /* L20: */
16611 	}
16612     } else if (lsame_(norm, "O") || *(unsigned char *)
16613 	    norm == '1') {
16614 
16615 /*        Find norm1(A). */
16616 
16617 	value = 0.;
16618 	i__1 = *n;
16619 	for (j = 1; j <= i__1; ++j) {
16620 	    sum = 0.;
16621 	    i__2 = *m;
16622 	    for (i__ = 1; i__ <= i__2; ++i__) {
16623 		sum += (d__1 = a[i__ + j * a_dim1], abs(d__1));
16624 /* L30: */
16625 	    }
16626 	    value = max(value,sum);
16627 /* L40: */
16628 	}
16629     } else if (lsame_(norm, "I")) {
16630 
16631 /*        Find normI(A). */
16632 
16633 	i__1 = *m;
16634 	for (i__ = 1; i__ <= i__1; ++i__) {
16635 	    work[i__] = 0.;
16636 /* L50: */
16637 	}
16638 	i__1 = *n;
16639 	for (j = 1; j <= i__1; ++j) {
16640 	    i__2 = *m;
16641 	    for (i__ = 1; i__ <= i__2; ++i__) {
16642 		work[i__] += (d__1 = a[i__ + j * a_dim1], abs(d__1));
16643 /* L60: */
16644 	    }
16645 /* L70: */
16646 	}
16647 	value = 0.;
16648 	i__1 = *m;
16649 	for (i__ = 1; i__ <= i__1; ++i__) {
16650 /* Computing MAX */
16651 	    d__1 = value, d__2 = work[i__];
16652 	    value = max(d__1,d__2);
16653 /* L80: */
16654 	}
16655     } else if (lsame_(norm, "F") || lsame_(norm, "E")) {
16656 
16657 /*        Find normF(A). */
16658 
16659 	scale = 0.;
16660 	sum = 1.;
16661 	i__1 = *n;
16662 	for (j = 1; j <= i__1; ++j) {
16663 	    dlassq_(m, &a[j * a_dim1 + 1], &c__1, &scale, &sum);
16664 /* L90: */
16665 	}
16666 	value = scale * sqrt(sum);
16667     }
16668 
16669     ret_val = value;
16670     return ret_val;
16671 
16672 /*     End of DLANGE */
16673 
16674 } /* dlange_ */
16675 
dlanst_(char * norm,integer * n,doublereal * d__,doublereal * e)16676 doublereal dlanst_(char *norm, integer *n, doublereal *d__, doublereal *e)
16677 {
16678     /* System generated locals */
16679     integer i__1;
16680     doublereal ret_val, d__1, d__2, d__3, d__4, d__5;
16681 
16682     /* Local variables */
16683     static integer i__;
16684     static doublereal sum, scale;
16685     extern logical lsame_(char *, char *);
16686     static doublereal anorm;
16687     extern /* Subroutine */ int dlassq_(integer *, doublereal *, integer *,
16688 	    doublereal *, doublereal *);
16689 
16690 
16691 /*
16692     -- LAPACK auxiliary routine (version 3.2) --
16693     -- LAPACK is a software package provided by Univ. of Tennessee,    --
16694     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
16695        November 2006
16696 
16697 
16698     Purpose
16699     =======
16700 
16701     DLANST  returns the value of the one norm,  or the Frobenius norm, or
16702     the  infinity norm,  or the  element of  largest absolute value  of a
16703     real symmetric tridiagonal matrix A.
16704 
16705     Description
16706     ===========
16707 
16708     DLANST returns the value
16709 
16710        DLANST = ( max(abs(A(i,j))), NORM = 'M' or 'm'
16711                 (
16712                 ( norm1(A),         NORM = '1', 'O' or 'o'
16713                 (
16714                 ( normI(A),         NORM = 'I' or 'i'
16715                 (
16716                 ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
16717 
16718     where  norm1  denotes the  one norm of a matrix (maximum column sum),
16719     normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
16720     normF  denotes the  Frobenius norm of a matrix (square root of sum of
16721     squares).  Note that  max(abs(A(i,j)))  is not a consistent matrix norm.
16722 
16723     Arguments
16724     =========
16725 
16726     NORM    (input) CHARACTER*1
16727             Specifies the value to be returned in DLANST as described
16728             above.
16729 
16730     N       (input) INTEGER
16731             The order of the matrix A.  N >= 0.  When N = 0, DLANST is
16732             set to zero.
16733 
16734     D       (input) DOUBLE PRECISION array, dimension (N)
16735             The diagonal elements of A.
16736 
16737     E       (input) DOUBLE PRECISION array, dimension (N-1)
16738             The (n-1) sub-diagonal or super-diagonal elements of A.
16739 
16740     =====================================================================
16741 */
16742 
16743 
16744     /* Parameter adjustments */
16745     --e;
16746     --d__;
16747 
16748     /* Function Body */
16749     if (*n <= 0) {
16750 	anorm = 0.;
16751     } else if (lsame_(norm, "M")) {
16752 
16753 /*        Find max(abs(A(i,j))). */
16754 
16755 	anorm = (d__1 = d__[*n], abs(d__1));
16756 	i__1 = *n - 1;
16757 	for (i__ = 1; i__ <= i__1; ++i__) {
16758 /* Computing MAX */
16759 	    d__2 = anorm, d__3 = (d__1 = d__[i__], abs(d__1));
16760 	    anorm = max(d__2,d__3);
16761 /* Computing MAX */
16762 	    d__2 = anorm, d__3 = (d__1 = e[i__], abs(d__1));
16763 	    anorm = max(d__2,d__3);
16764 /* L10: */
16765 	}
16766     } else if (lsame_(norm, "O") || *(unsigned char *)
16767 	    norm == '1' || lsame_(norm, "I")) {
16768 
16769 /*        Find norm1(A). */
16770 
16771 	if (*n == 1) {
16772 	    anorm = abs(d__[1]);
16773 	} else {
16774 /* Computing MAX */
16775 	    d__3 = abs(d__[1]) + abs(e[1]), d__4 = (d__1 = e[*n - 1], abs(
16776 		    d__1)) + (d__2 = d__[*n], abs(d__2));
16777 	    anorm = max(d__3,d__4);
16778 	    i__1 = *n - 1;
16779 	    for (i__ = 2; i__ <= i__1; ++i__) {
16780 /* Computing MAX */
16781 		d__4 = anorm, d__5 = (d__1 = d__[i__], abs(d__1)) + (d__2 = e[
16782 			i__], abs(d__2)) + (d__3 = e[i__ - 1], abs(d__3));
16783 		anorm = max(d__4,d__5);
16784 /* L20: */
16785 	    }
16786 	}
16787     } else if (lsame_(norm, "F") || lsame_(norm, "E")) {
16788 
16789 /*        Find normF(A). */
16790 
16791 	scale = 0.;
16792 	sum = 1.;
16793 	if (*n > 1) {
16794 	    i__1 = *n - 1;
16795 	    dlassq_(&i__1, &e[1], &c__1, &scale, &sum);
16796 	    sum *= 2;
16797 	}
16798 	dlassq_(n, &d__[1], &c__1, &scale, &sum);
16799 	anorm = scale * sqrt(sum);
16800     }
16801 
16802     ret_val = anorm;
16803     return ret_val;
16804 
16805 /*     End of DLANST */
16806 
16807 } /* dlanst_ */
16808 
dlansy_(char * norm,char * uplo,integer * n,doublereal * a,integer * lda,doublereal * work)16809 doublereal dlansy_(char *norm, char *uplo, integer *n, doublereal *a, integer
16810 	*lda, doublereal *work)
16811 {
16812     /* System generated locals */
16813     integer a_dim1, a_offset, i__1, i__2;
16814     doublereal ret_val, d__1, d__2, d__3;
16815 
16816     /* Local variables */
16817     static integer i__, j;
16818     static doublereal sum, absa, scale;
16819     extern logical lsame_(char *, char *);
16820     static doublereal value;
16821     extern /* Subroutine */ int dlassq_(integer *, doublereal *, integer *,
16822 	    doublereal *, doublereal *);
16823 
16824 
16825 /*
16826     -- LAPACK auxiliary routine (version 3.2) --
16827     -- LAPACK is a software package provided by Univ. of Tennessee,    --
16828     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
16829        November 2006
16830 
16831 
16832     Purpose
16833     =======
16834 
16835     DLANSY  returns the value of the one norm,  or the Frobenius norm, or
16836     the  infinity norm,  or the  element of  largest absolute value  of a
16837     real symmetric matrix A.
16838 
16839     Description
16840     ===========
16841 
16842     DLANSY returns the value
16843 
16844        DLANSY = ( max(abs(A(i,j))), NORM = 'M' or 'm'
16845                 (
16846                 ( norm1(A),         NORM = '1', 'O' or 'o'
16847                 (
16848                 ( normI(A),         NORM = 'I' or 'i'
16849                 (
16850                 ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
16851 
16852     where  norm1  denotes the  one norm of a matrix (maximum column sum),
16853     normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
16854     normF  denotes the  Frobenius norm of a matrix (square root of sum of
16855     squares).  Note that  max(abs(A(i,j)))  is not a consistent matrix norm.
16856 
16857     Arguments
16858     =========
16859 
16860     NORM    (input) CHARACTER*1
16861             Specifies the value to be returned in DLANSY as described
16862             above.
16863 
16864     UPLO    (input) CHARACTER*1
16865             Specifies whether the upper or lower triangular part of the
16866             symmetric matrix A is to be referenced.
16867             = 'U':  Upper triangular part of A is referenced
16868             = 'L':  Lower triangular part of A is referenced
16869 
16870     N       (input) INTEGER
16871             The order of the matrix A.  N >= 0.  When N = 0, DLANSY is
16872             set to zero.
16873 
16874     A       (input) DOUBLE PRECISION array, dimension (LDA,N)
16875             The symmetric matrix A.  If UPLO = 'U', the leading n by n
16876             upper triangular part of A contains the upper triangular part
16877             of the matrix A, and the strictly lower triangular part of A
16878             is not referenced.  If UPLO = 'L', the leading n by n lower
16879             triangular part of A contains the lower triangular part of
16880             the matrix A, and the strictly upper triangular part of A is
16881             not referenced.
16882 
16883     LDA     (input) INTEGER
16884             The leading dimension of the array A.  LDA >= max(N,1).
16885 
16886     WORK    (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),
16887             where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
16888             WORK is not referenced.
16889 
16890    =====================================================================
16891 */
16892 
16893 
16894     /* Parameter adjustments */
16895     a_dim1 = *lda;
16896     a_offset = 1 + a_dim1;
16897     a -= a_offset;
16898     --work;
16899 
16900     /* Function Body */
16901     if (*n == 0) {
16902 	value = 0.;
16903     } else if (lsame_(norm, "M")) {
16904 
16905 /*        Find max(abs(A(i,j))). */
16906 
16907 	value = 0.;
16908 	if (lsame_(uplo, "U")) {
16909 	    i__1 = *n;
16910 	    for (j = 1; j <= i__1; ++j) {
16911 		i__2 = j;
16912 		for (i__ = 1; i__ <= i__2; ++i__) {
16913 /* Computing MAX */
16914 		    d__2 = value, d__3 = (d__1 = a[i__ + j * a_dim1], abs(
16915 			    d__1));
16916 		    value = max(d__2,d__3);
16917 /* L10: */
16918 		}
16919 /* L20: */
16920 	    }
16921 	} else {
16922 	    i__1 = *n;
16923 	    for (j = 1; j <= i__1; ++j) {
16924 		i__2 = *n;
16925 		for (i__ = j; i__ <= i__2; ++i__) {
16926 /* Computing MAX */
16927 		    d__2 = value, d__3 = (d__1 = a[i__ + j * a_dim1], abs(
16928 			    d__1));
16929 		    value = max(d__2,d__3);
16930 /* L30: */
16931 		}
16932 /* L40: */
16933 	    }
16934 	}
16935     } else if (lsame_(norm, "I") || lsame_(norm, "O") || *(unsigned char *)norm == '1') {
16936 
16937 /*        Find normI(A) ( = norm1(A), since A is symmetric). */
16938 
16939 	value = 0.;
16940 	if (lsame_(uplo, "U")) {
16941 	    i__1 = *n;
16942 	    for (j = 1; j <= i__1; ++j) {
16943 		sum = 0.;
16944 		i__2 = j - 1;
16945 		for (i__ = 1; i__ <= i__2; ++i__) {
16946 		    absa = (d__1 = a[i__ + j * a_dim1], abs(d__1));
16947 		    sum += absa;
16948 		    work[i__] += absa;
16949 /* L50: */
16950 		}
16951 		work[j] = sum + (d__1 = a[j + j * a_dim1], abs(d__1));
16952 /* L60: */
16953 	    }
16954 	    i__1 = *n;
16955 	    for (i__ = 1; i__ <= i__1; ++i__) {
16956 /* Computing MAX */
16957 		d__1 = value, d__2 = work[i__];
16958 		value = max(d__1,d__2);
16959 /* L70: */
16960 	    }
16961 	} else {
16962 	    i__1 = *n;
16963 	    for (i__ = 1; i__ <= i__1; ++i__) {
16964 		work[i__] = 0.;
16965 /* L80: */
16966 	    }
16967 	    i__1 = *n;
16968 	    for (j = 1; j <= i__1; ++j) {
16969 		sum = work[j] + (d__1 = a[j + j * a_dim1], abs(d__1));
16970 		i__2 = *n;
16971 		for (i__ = j + 1; i__ <= i__2; ++i__) {
16972 		    absa = (d__1 = a[i__ + j * a_dim1], abs(d__1));
16973 		    sum += absa;
16974 		    work[i__] += absa;
16975 /* L90: */
16976 		}
16977 		value = max(value,sum);
16978 /* L100: */
16979 	    }
16980 	}
16981     } else if (lsame_(norm, "F") || lsame_(norm, "E")) {
16982 
16983 /*        Find normF(A). */
16984 
16985 	scale = 0.;
16986 	sum = 1.;
16987 	if (lsame_(uplo, "U")) {
16988 	    i__1 = *n;
16989 	    for (j = 2; j <= i__1; ++j) {
16990 		i__2 = j - 1;
16991 		dlassq_(&i__2, &a[j * a_dim1 + 1], &c__1, &scale, &sum);
16992 /* L110: */
16993 	    }
16994 	} else {
16995 	    i__1 = *n - 1;
16996 	    for (j = 1; j <= i__1; ++j) {
16997 		i__2 = *n - j;
16998 		dlassq_(&i__2, &a[j + 1 + j * a_dim1], &c__1, &scale, &sum);
16999 /* L120: */
17000 	    }
17001 	}
17002 	sum *= 2;
17003 	i__1 = *lda + 1;
17004 	dlassq_(n, &a[a_offset], &i__1, &scale, &sum);
17005 	value = scale * sqrt(sum);
17006     }
17007 
17008     ret_val = value;
17009     return ret_val;
17010 
17011 /*     End of DLANSY */
17012 
17013 } /* dlansy_ */
17014 
dlanv2_(doublereal * a,doublereal * b,doublereal * c__,doublereal * d__,doublereal * rt1r,doublereal * rt1i,doublereal * rt2r,doublereal * rt2i,doublereal * cs,doublereal * sn)17015 /* Subroutine */ int dlanv2_(doublereal *a, doublereal *b, doublereal *c__,
17016 	doublereal *d__, doublereal *rt1r, doublereal *rt1i, doublereal *rt2r,
17017 	 doublereal *rt2i, doublereal *cs, doublereal *sn)
17018 {
17019     /* System generated locals */
17020     doublereal d__1, d__2;
17021 
17022     /* Local variables */
17023     static doublereal p, z__, aa, bb, cc, dd, cs1, sn1, sab, sac, eps, tau,
17024 	    temp, scale, bcmax, bcmis, sigma;
17025 
17026 
17027 
17028 /*
17029     -- LAPACK auxiliary routine (version 3.2.2) --
17030     -- LAPACK is a software package provided by Univ. of Tennessee,    --
17031     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
17032        June 2010
17033 
17034 
17035     Purpose
17036     =======
17037 
17038     DLANV2 computes the Schur factorization of a real 2-by-2 nonsymmetric
17039     matrix in standard form:
17040 
17041          [ A  B ] = [ CS -SN ] [ AA  BB ] [ CS  SN ]
17042          [ C  D ]   [ SN  CS ] [ CC  DD ] [-SN  CS ]
17043 
17044     where either
17045     1) CC = 0 so that AA and DD are real eigenvalues of the matrix, or
17046     2) AA = DD and BB*CC < 0, so that AA + or - sqrt(BB*CC) are complex
17047     conjugate eigenvalues.
17048 
17049     Arguments
17050     =========
17051 
17052     A       (input/output) DOUBLE PRECISION
17053     B       (input/output) DOUBLE PRECISION
17054     C       (input/output) DOUBLE PRECISION
17055     D       (input/output) DOUBLE PRECISION
17056             On entry, the elements of the input matrix.
17057             On exit, they are overwritten by the elements of the
17058             standardised Schur form.
17059 
17060     RT1R    (output) DOUBLE PRECISION
17061     RT1I    (output) DOUBLE PRECISION
17062     RT2R    (output) DOUBLE PRECISION
17063     RT2I    (output) DOUBLE PRECISION
17064             The real and imaginary parts of the eigenvalues. If the
17065             eigenvalues are a complex conjugate pair, RT1I > 0.
17066 
17067     CS      (output) DOUBLE PRECISION
17068     SN      (output) DOUBLE PRECISION
17069             Parameters of the rotation matrix.
17070 
17071     Further Details
17072     ===============
17073 
17074     Modified by V. Sima, Research Institute for Informatics, Bucharest,
17075     Romania, to reduce the risk of cancellation errors,
17076     when computing real eigenvalues, and to ensure, if possible, that
17077     abs(RT1R) >= abs(RT2R).
17078 
17079     =====================================================================
17080 */
17081 
17082 
17083     eps = PRECISION;
17084     if (*c__ == 0.) {
17085 	*cs = 1.;
17086 	*sn = 0.;
17087 	goto L10;
17088 
17089     } else if (*b == 0.) {
17090 
17091 /*        Swap rows and columns */
17092 
17093 	*cs = 0.;
17094 	*sn = 1.;
17095 	temp = *d__;
17096 	*d__ = *a;
17097 	*a = temp;
17098 	*b = -(*c__);
17099 	*c__ = 0.;
17100 	goto L10;
17101     } else if (*a - *d__ == 0. && d_sign(&c_b15, b) != d_sign(&c_b15, c__)) {
17102 	*cs = 1.;
17103 	*sn = 0.;
17104 	goto L10;
17105     } else {
17106 
17107 	temp = *a - *d__;
17108 	p = temp * .5;
17109 /* Computing MAX */
17110 	d__1 = abs(*b), d__2 = abs(*c__);
17111 	bcmax = max(d__1,d__2);
17112 /* Computing MIN */
17113 	d__1 = abs(*b), d__2 = abs(*c__);
17114 	bcmis = min(d__1,d__2) * d_sign(&c_b15, b) * d_sign(&c_b15, c__);
17115 /* Computing MAX */
17116 	d__1 = abs(p);
17117 	scale = max(d__1,bcmax);
17118 	z__ = p / scale * p + bcmax / scale * bcmis;
17119 
17120 /*
17121           If Z is of the order of the machine accuracy, postpone the
17122           decision on the nature of eigenvalues
17123 */
17124 
17125 	if (z__ >= eps * 4.) {
17126 
17127 /*           Real eigenvalues. Compute A and D. */
17128 
17129 	    d__1 = sqrt(scale) * sqrt(z__);
17130 	    z__ = p + d_sign(&d__1, &p);
17131 	    *a = *d__ + z__;
17132 	    *d__ -= bcmax / z__ * bcmis;
17133 
17134 /*           Compute B and the rotation matrix */
17135 
17136 	    tau = dlapy2_(c__, &z__);
17137 	    *cs = z__ / tau;
17138 	    *sn = *c__ / tau;
17139 	    *b -= *c__;
17140 	    *c__ = 0.;
17141 	} else {
17142 
17143 /*
17144              Complex eigenvalues, or real (almost) equal eigenvalues.
17145              Make diagonal elements equal.
17146 */
17147 
17148 	    sigma = *b + *c__;
17149 	    tau = dlapy2_(&sigma, &temp);
17150 	    *cs = sqrt((abs(sigma) / tau + 1.) * .5);
17151 	    *sn = -(p / (tau * *cs)) * d_sign(&c_b15, &sigma);
17152 
17153 /*
17154              Compute [ AA  BB ] = [ A  B ] [ CS -SN ]
17155                      [ CC  DD ]   [ C  D ] [ SN  CS ]
17156 */
17157 
17158 	    aa = *a * *cs + *b * *sn;
17159 	    bb = -(*a) * *sn + *b * *cs;
17160 	    cc = *c__ * *cs + *d__ * *sn;
17161 	    dd = -(*c__) * *sn + *d__ * *cs;
17162 
17163 /*
17164              Compute [ A  B ] = [ CS  SN ] [ AA  BB ]
17165                      [ C  D ]   [-SN  CS ] [ CC  DD ]
17166 */
17167 
17168 	    *a = aa * *cs + cc * *sn;
17169 	    *b = bb * *cs + dd * *sn;
17170 	    *c__ = -aa * *sn + cc * *cs;
17171 	    *d__ = -bb * *sn + dd * *cs;
17172 
17173 	    temp = (*a + *d__) * .5;
17174 	    *a = temp;
17175 	    *d__ = temp;
17176 
17177 	    if (*c__ != 0.) {
17178 		if (*b != 0.) {
17179 		    if (d_sign(&c_b15, b) == d_sign(&c_b15, c__)) {
17180 
17181 /*                    Real eigenvalues: reduce to upper triangular form */
17182 
17183 			sab = sqrt((abs(*b)));
17184 			sac = sqrt((abs(*c__)));
17185 			d__1 = sab * sac;
17186 			p = d_sign(&d__1, c__);
17187 			tau = 1. / sqrt((d__1 = *b + *c__, abs(d__1)));
17188 			*a = temp + p;
17189 			*d__ = temp - p;
17190 			*b -= *c__;
17191 			*c__ = 0.;
17192 			cs1 = sab * tau;
17193 			sn1 = sac * tau;
17194 			temp = *cs * cs1 - *sn * sn1;
17195 			*sn = *cs * sn1 + *sn * cs1;
17196 			*cs = temp;
17197 		    }
17198 		} else {
17199 		    *b = -(*c__);
17200 		    *c__ = 0.;
17201 		    temp = *cs;
17202 		    *cs = -(*sn);
17203 		    *sn = temp;
17204 		}
17205 	    }
17206 	}
17207 
17208     }
17209 
17210 L10:
17211 
17212 /*     Store eigenvalues in (RT1R,RT1I) and (RT2R,RT2I). */
17213 
17214     *rt1r = *a;
17215     *rt2r = *d__;
17216     if (*c__ == 0.) {
17217 	*rt1i = 0.;
17218 	*rt2i = 0.;
17219     } else {
17220 	*rt1i = sqrt((abs(*b))) * sqrt((abs(*c__)));
17221 	*rt2i = -(*rt1i);
17222     }
17223     return 0;
17224 
17225 /*     End of DLANV2 */
17226 
17227 } /* dlanv2_ */
17228 
dlapy2_(doublereal * x,doublereal * y)17229 doublereal dlapy2_(doublereal *x, doublereal *y)
17230 {
17231     /* System generated locals */
17232     doublereal ret_val, d__1;
17233 
17234     /* Local variables */
17235     static doublereal w, z__, xabs, yabs;
17236 
17237 
17238 /*
17239     -- LAPACK auxiliary routine (version 3.2) --
17240     -- LAPACK is a software package provided by Univ. of Tennessee,    --
17241     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
17242        November 2006
17243 
17244 
17245     Purpose
17246     =======
17247 
17248     DLAPY2 returns sqrt(x**2+y**2), taking care not to cause unnecessary
17249     overflow.
17250 
17251     Arguments
17252     =========
17253 
17254     X       (input) DOUBLE PRECISION
17255     Y       (input) DOUBLE PRECISION
17256             X and Y specify the values x and y.
17257 
17258     =====================================================================
17259 */
17260 
17261 
17262     xabs = abs(*x);
17263     yabs = abs(*y);
17264     w = max(xabs,yabs);
17265     z__ = min(xabs,yabs);
17266     if (z__ == 0.) {
17267 	ret_val = w;
17268     } else {
17269 /* Computing 2nd power */
17270 	d__1 = z__ / w;
17271 	ret_val = w * sqrt(d__1 * d__1 + 1.);
17272     }
17273     return ret_val;
17274 
17275 /*     End of DLAPY2 */
17276 
17277 } /* dlapy2_ */
17278 
dlapy3_(doublereal * x,doublereal * y,doublereal * z__)17279 doublereal dlapy3_(doublereal *x, doublereal *y, doublereal *z__)
17280 {
17281     /* System generated locals */
17282     doublereal ret_val, d__1, d__2, d__3;
17283 
17284     /* Local variables */
17285     static doublereal w, xabs, yabs, zabs;
17286 
17287 
17288 /*
17289     -- LAPACK auxiliary routine (version 3.2) --
17290     -- LAPACK is a software package provided by Univ. of Tennessee,    --
17291     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
17292        November 2006
17293 
17294 
17295     Purpose
17296     =======
17297 
17298     DLAPY3 returns sqrt(x**2+y**2+z**2), taking care not to cause
17299     unnecessary overflow.
17300 
17301     Arguments
17302     =========
17303 
17304     X       (input) DOUBLE PRECISION
17305     Y       (input) DOUBLE PRECISION
17306     Z       (input) DOUBLE PRECISION
17307             X, Y and Z specify the values x, y and z.
17308 
17309     =====================================================================
17310 */
17311 
17312 
17313     xabs = abs(*x);
17314     yabs = abs(*y);
17315     zabs = abs(*z__);
17316 /* Computing MAX */
17317     d__1 = max(xabs,yabs);
17318     w = max(d__1,zabs);
17319     if (w == 0.) {
17320 /*
17321        W can be zero for max(0,nan,0)
17322        adding all three entries together will make sure
17323        NaN will not disappear.
17324 */
17325 	ret_val = xabs + yabs + zabs;
17326     } else {
17327 /* Computing 2nd power */
17328 	d__1 = xabs / w;
17329 /* Computing 2nd power */
17330 	d__2 = yabs / w;
17331 /* Computing 2nd power */
17332 	d__3 = zabs / w;
17333 	ret_val = w * sqrt(d__1 * d__1 + d__2 * d__2 + d__3 * d__3);
17334     }
17335     return ret_val;
17336 
17337 /*     End of DLAPY3 */
17338 
17339 } /* dlapy3_ */
17340 
dlaqr0_(logical * wantt,logical * wantz,integer * n,integer * ilo,integer * ihi,doublereal * h__,integer * ldh,doublereal * wr,doublereal * wi,integer * iloz,integer * ihiz,doublereal * z__,integer * ldz,doublereal * work,integer * lwork,integer * info)17341 /* Subroutine */ int dlaqr0_(logical *wantt, logical *wantz, integer *n,
17342 	integer *ilo, integer *ihi, doublereal *h__, integer *ldh, doublereal
17343 	*wr, doublereal *wi, integer *iloz, integer *ihiz, doublereal *z__,
17344 	integer *ldz, doublereal *work, integer *lwork, integer *info)
17345 {
17346     /* System generated locals */
17347     integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
17348     doublereal d__1, d__2, d__3, d__4;
17349 
17350     /* Local variables */
17351     static integer i__, k;
17352     static doublereal aa, bb, cc, dd;
17353     static integer ld;
17354     static doublereal cs;
17355     static integer nh, it, ks, kt;
17356     static doublereal sn;
17357     static integer ku, kv, ls, ns;
17358     static doublereal ss;
17359     static integer nw, inf, kdu, nho, nve, kwh, nsr, nwr, kwv, ndec, ndfl,
17360 	    kbot, nmin;
17361     static doublereal swap;
17362     static integer ktop;
17363     static doublereal zdum[1]	/* was [1][1] */;
17364     static integer kacc22, itmax, nsmax, nwmax, kwtop;
17365     extern /* Subroutine */ int dlanv2_(doublereal *, doublereal *,
17366 	    doublereal *, doublereal *, doublereal *, doublereal *,
17367 	    doublereal *, doublereal *, doublereal *, doublereal *), dlaqr3_(
17368 	    logical *, logical *, integer *, integer *, integer *, integer *,
17369 	    doublereal *, integer *, integer *, integer *, doublereal *,
17370 	    integer *, integer *, integer *, doublereal *, doublereal *,
17371 	    doublereal *, integer *, integer *, doublereal *, integer *,
17372 	    integer *, doublereal *, integer *, doublereal *, integer *),
17373 	    dlaqr4_(logical *, logical *, integer *, integer *, integer *,
17374 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
17375 	    integer *, doublereal *, integer *, doublereal *, integer *,
17376 	    integer *), dlaqr5_(logical *, logical *, integer *, integer *,
17377 	    integer *, integer *, integer *, doublereal *, doublereal *,
17378 	    doublereal *, integer *, integer *, integer *, doublereal *,
17379 	    integer *, doublereal *, integer *, doublereal *, integer *,
17380 	    integer *, doublereal *, integer *, integer *, doublereal *,
17381 	    integer *);
17382     static integer nibble;
17383     extern /* Subroutine */ int dlahqr_(logical *, logical *, integer *,
17384 	    integer *, integer *, doublereal *, integer *, doublereal *,
17385 	    doublereal *, integer *, integer *, doublereal *, integer *,
17386 	    integer *), dlacpy_(char *, integer *, integer *, doublereal *,
17387 	    integer *, doublereal *, integer *);
17388     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
17389 	    integer *, integer *, ftnlen, ftnlen);
17390     static char jbcmpz[2];
17391     static integer nwupbd;
17392     static logical sorted;
17393     static integer lwkopt;
17394 
17395 
17396 /*
17397     -- LAPACK auxiliary routine (version 3.2) --
17398        Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
17399        November 2006
17400 
17401 
17402        Purpose
17403        =======
17404 
17405        DLAQR0 computes the eigenvalues of a Hessenberg matrix H
17406        and, optionally, the matrices T and Z from the Schur decomposition
17407        H = Z T Z**T, where T is an upper quasi-triangular matrix (the
17408        Schur form), and Z is the orthogonal matrix of Schur vectors.
17409 
17410        Optionally Z may be postmultiplied into an input orthogonal
17411        matrix Q so that this routine can give the Schur factorization
17412        of a matrix A which has been reduced to the Hessenberg form H
17413        by the orthogonal matrix Q:  A = Q*H*Q**T = (QZ)*T*(QZ)**T.
17414 
17415        Arguments
17416        =========
17417 
17418        WANTT   (input) LOGICAL
17419             = .TRUE. : the full Schur form T is required;
17420             = .FALSE.: only eigenvalues are required.
17421 
17422        WANTZ   (input) LOGICAL
17423             = .TRUE. : the matrix of Schur vectors Z is required;
17424             = .FALSE.: Schur vectors are not required.
17425 
17426        N     (input) INTEGER
17427              The order of the matrix H.  N .GE. 0.
17428 
17429        ILO   (input) INTEGER
17430        IHI   (input) INTEGER
17431              It is assumed that H is already upper triangular in rows
17432              and columns 1:ILO-1 and IHI+1:N and, if ILO.GT.1,
17433              H(ILO,ILO-1) is zero. ILO and IHI are normally set by a
17434              previous call to DGEBAL, and then passed to DGEHRD when the
17435              matrix output by DGEBAL is reduced to Hessenberg form.
17436              Otherwise, ILO and IHI should be set to 1 and N,
17437              respectively.  If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N.
17438              If N = 0, then ILO = 1 and IHI = 0.
17439 
17440        H     (input/output) DOUBLE PRECISION array, dimension (LDH,N)
17441              On entry, the upper Hessenberg matrix H.
17442              On exit, if INFO = 0 and WANTT is .TRUE., then H contains
17443              the upper quasi-triangular matrix T from the Schur
17444              decomposition (the Schur form); 2-by-2 diagonal blocks
17445              (corresponding to complex conjugate pairs of eigenvalues)
17446              are returned in standard form, with H(i,i) = H(i+1,i+1)
17447              and H(i+1,i)*H(i,i+1).LT.0. If INFO = 0 and WANTT is
17448              .FALSE., then the contents of H are unspecified on exit.
17449              (The output value of H when INFO.GT.0 is given under the
17450              description of INFO below.)
17451 
17452              This subroutine may explicitly set H(i,j) = 0 for i.GT.j and
17453              j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N.
17454 
17455        LDH   (input) INTEGER
17456              The leading dimension of the array H. LDH .GE. max(1,N).
17457 
17458        WR    (output) DOUBLE PRECISION array, dimension (IHI)
17459        WI    (output) DOUBLE PRECISION array, dimension (IHI)
17460              The real and imaginary parts, respectively, of the computed
17461              eigenvalues of H(ILO:IHI,ILO:IHI) are stored in WR(ILO:IHI)
17462              and WI(ILO:IHI). If two eigenvalues are computed as a
17463              complex conjugate pair, they are stored in consecutive
17464              elements of WR and WI, say the i-th and (i+1)th, with
17465              WI(i) .GT. 0 and WI(i+1) .LT. 0. If WANTT is .TRUE., then
17466              the eigenvalues are stored in the same order as on the
17467              diagonal of the Schur form returned in H, with
17468              WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2 diagonal
17469              block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and
17470              WI(i+1) = -WI(i).
17471 
17472        ILOZ     (input) INTEGER
17473        IHIZ     (input) INTEGER
17474              Specify the rows of Z to which transformations must be
17475              applied if WANTZ is .TRUE..
17476              1 .LE. ILOZ .LE. ILO; IHI .LE. IHIZ .LE. N.
17477 
17478        Z     (input/output) DOUBLE PRECISION array, dimension (LDZ,IHI)
17479              If WANTZ is .FALSE., then Z is not referenced.
17480              If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is
17481              replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the
17482              orthogonal Schur factor of H(ILO:IHI,ILO:IHI).
17483              (The output value of Z when INFO.GT.0 is given under
17484              the description of INFO below.)
17485 
17486        LDZ   (input) INTEGER
17487              The leading dimension of the array Z.  if WANTZ is .TRUE.
17488              then LDZ.GE.MAX(1,IHIZ).  Otherwize, LDZ.GE.1.
17489 
17490        WORK  (workspace/output) DOUBLE PRECISION array, dimension LWORK
17491              On exit, if LWORK = -1, WORK(1) returns an estimate of
17492              the optimal value for LWORK.
17493 
17494        LWORK (input) INTEGER
17495              The dimension of the array WORK.  LWORK .GE. max(1,N)
17496              is sufficient, but LWORK typically as large as 6*N may
17497              be required for optimal performance.  A workspace query
17498              to determine the optimal workspace size is recommended.
17499 
17500              If LWORK = -1, then DLAQR0 does a workspace query.
17501              In this case, DLAQR0 checks the input parameters and
17502              estimates the optimal workspace size for the given
17503              values of N, ILO and IHI.  The estimate is returned
17504              in WORK(1).  No error message related to LWORK is
17505              issued by XERBLA.  Neither H nor Z are accessed.
17506 
17507 
17508        INFO  (output) INTEGER
17509                =  0:  successful exit
17510              .GT. 0:  if INFO = i, DLAQR0 failed to compute all of
17511                   the eigenvalues.  Elements 1:ilo-1 and i+1:n of WR
17512                   and WI contain those eigenvalues which have been
17513                   successfully computed.  (Failures are rare.)
17514 
17515                   If INFO .GT. 0 and WANT is .FALSE., then on exit,
17516                   the remaining unconverged eigenvalues are the eigen-
17517                   values of the upper Hessenberg matrix rows and
17518                   columns ILO through INFO of the final, output
17519                   value of H.
17520 
17521                   If INFO .GT. 0 and WANTT is .TRUE., then on exit
17522 
17523              (*)  (initial value of H)*U  = U*(final value of H)
17524 
17525                   where U is an orthogonal matrix.  The final
17526                   value of H is upper Hessenberg and quasi-triangular
17527                   in rows and columns INFO+1 through IHI.
17528 
17529                   If INFO .GT. 0 and WANTZ is .TRUE., then on exit
17530 
17531                     (final value of Z(ILO:IHI,ILOZ:IHIZ)
17532                      =  (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U
17533 
17534                   where U is the orthogonal matrix in (*) (regard-
17535                   less of the value of WANTT.)
17536 
17537                   If INFO .GT. 0 and WANTZ is .FALSE., then Z is not
17538                   accessed.
17539 
17540        ================================================================
17541        Based on contributions by
17542           Karen Braman and Ralph Byers, Department of Mathematics,
17543           University of Kansas, USA
17544 
17545        ================================================================
17546        References:
17547          K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
17548          Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
17549          Performance, SIAM Journal of Matrix Analysis, volume 23, pages
17550          929--947, 2002.
17551 
17552          K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
17553          Algorithm Part II: Aggressive Early Deflation, SIAM Journal
17554          of Matrix Analysis, volume 23, pages 948--973, 2002.
17555 
17556        ================================================================
17557 
17558        ==== Matrices of order NTINY or smaller must be processed by
17559        .    DLAHQR because of insufficient subdiagonal scratch space.
17560        .    (This is a hard limit.) ====
17561 
17562        ==== Exceptional deflation windows:  try to cure rare
17563        .    slow convergence by varying the size of the
17564        .    deflation window after KEXNW iterations. ====
17565 
17566        ==== Exceptional shifts: try to cure rare slow convergence
17567        .    with ad-hoc exceptional shifts every KEXSH iterations.
17568        .    ====
17569 
17570        ==== The constants WILK1 and WILK2 are used to form the
17571        .    exceptional shifts. ====
17572 */
17573     /* Parameter adjustments */
17574     h_dim1 = *ldh;
17575     h_offset = 1 + h_dim1;
17576     h__ -= h_offset;
17577     --wr;
17578     --wi;
17579     z_dim1 = *ldz;
17580     z_offset = 1 + z_dim1;
17581     z__ -= z_offset;
17582     --work;
17583 
17584     /* Function Body */
17585     *info = 0;
17586 
17587 /*     ==== Quick return for N = 0: nothing to do. ==== */
17588 
17589     if (*n == 0) {
17590 	work[1] = 1.;
17591 	return 0;
17592     }
17593 
17594     if (*n <= 11) {
17595 
17596 /*        ==== Tiny matrices must use DLAHQR. ==== */
17597 
17598 	lwkopt = 1;
17599 	if (*lwork != -1) {
17600 	    dlahqr_(wantt, wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1], &
17601 		    wi[1], iloz, ihiz, &z__[z_offset], ldz, info);
17602 	}
17603     } else {
17604 
17605 /*
17606           ==== Use small bulge multi-shift QR with aggressive early
17607           .    deflation on larger-than-tiny matrices. ====
17608 
17609           ==== Hope for the best. ====
17610 */
17611 
17612 	*info = 0;
17613 
17614 /*        ==== Set up job flags for ILAENV. ==== */
17615 
17616 	if (*wantt) {
17617 	    *(unsigned char *)jbcmpz = 'S';
17618 	} else {
17619 	    *(unsigned char *)jbcmpz = 'E';
17620 	}
17621 	if (*wantz) {
17622 	    *(unsigned char *)&jbcmpz[1] = 'V';
17623 	} else {
17624 	    *(unsigned char *)&jbcmpz[1] = 'N';
17625 	}
17626 
17627 /*
17628           ==== NWR = recommended deflation window size.  At this
17629           .    point,  N .GT. NTINY = 11, so there is enough
17630           .    subdiagonal workspace for NWR.GE.2 as required.
17631           .    (In fact, there is enough subdiagonal space for
17632           .    NWR.GE.3.) ====
17633 */
17634 
17635 	nwr = ilaenv_(&c__13, "DLAQR0", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
17636 		 (ftnlen)2);
17637 	nwr = max(2,nwr);
17638 /* Computing MIN */
17639 	i__1 = *ihi - *ilo + 1, i__2 = (*n - 1) / 3, i__1 = min(i__1,i__2);
17640 	nwr = min(i__1,nwr);
17641 
17642 /*
17643           ==== NSR = recommended number of simultaneous shifts.
17644           .    At this point N .GT. NTINY = 11, so there is at
17645           .    enough subdiagonal workspace for NSR to be even
17646           .    and greater than or equal to two as required. ====
17647 */
17648 
17649 	nsr = ilaenv_(&c__15, "DLAQR0", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
17650 		 (ftnlen)2);
17651 /* Computing MIN */
17652 	i__1 = nsr, i__2 = (*n + 6) / 9, i__1 = min(i__1,i__2), i__2 = *ihi -
17653 		*ilo;
17654 	nsr = min(i__1,i__2);
17655 /* Computing MAX */
17656 	i__1 = 2, i__2 = nsr - nsr % 2;
17657 	nsr = max(i__1,i__2);
17658 
17659 /*
17660           ==== Estimate optimal workspace ====
17661 
17662           ==== Workspace query call to DLAQR3 ====
17663 */
17664 
17665 	i__1 = nwr + 1;
17666 	dlaqr3_(wantt, wantz, n, ilo, ihi, &i__1, &h__[h_offset], ldh, iloz,
17667 		ihiz, &z__[z_offset], ldz, &ls, &ld, &wr[1], &wi[1], &h__[
17668 		h_offset], ldh, n, &h__[h_offset], ldh, n, &h__[h_offset],
17669 		ldh, &work[1], &c_n1);
17670 
17671 /*
17672           ==== Optimal workspace = MAX(DLAQR5, DLAQR3) ====
17673 
17674    Computing MAX
17675 */
17676 	i__1 = nsr * 3 / 2, i__2 = (integer) work[1];
17677 	lwkopt = max(i__1,i__2);
17678 
17679 /*        ==== Quick return in case of workspace query. ==== */
17680 
17681 	if (*lwork == -1) {
17682 	    work[1] = (doublereal) lwkopt;
17683 	    return 0;
17684 	}
17685 
17686 /*        ==== DLAHQR/DLAQR0 crossover point ==== */
17687 
17688 	nmin = ilaenv_(&c__12, "DLAQR0", jbcmpz, n, ilo, ihi, lwork, (ftnlen)
17689 		6, (ftnlen)2);
17690 	nmin = max(11,nmin);
17691 
17692 /*        ==== Nibble crossover point ==== */
17693 
17694 	nibble = ilaenv_(&c__14, "DLAQR0", jbcmpz, n, ilo, ihi, lwork, (
17695 		ftnlen)6, (ftnlen)2);
17696 	nibble = max(0,nibble);
17697 
17698 /*
17699           ==== Accumulate reflections during ttswp?  Use block
17700           .    2-by-2 structure during matrix-matrix multiply? ====
17701 */
17702 
17703 	kacc22 = ilaenv_(&c__16, "DLAQR0", jbcmpz, n, ilo, ihi, lwork, (
17704 		ftnlen)6, (ftnlen)2);
17705 	kacc22 = max(0,kacc22);
17706 	kacc22 = min(2,kacc22);
17707 
17708 /*
17709           ==== NWMAX = the largest possible deflation window for
17710           .    which there is sufficient workspace. ====
17711 
17712    Computing MIN
17713 */
17714 	i__1 = (*n - 1) / 3, i__2 = *lwork / 2;
17715 	nwmax = min(i__1,i__2);
17716 	nw = nwmax;
17717 
17718 /*
17719           ==== NSMAX = the Largest number of simultaneous shifts
17720           .    for which there is sufficient workspace. ====
17721 
17722    Computing MIN
17723 */
17724 	i__1 = (*n + 6) / 9, i__2 = (*lwork << 1) / 3;
17725 	nsmax = min(i__1,i__2);
17726 	nsmax -= nsmax % 2;
17727 
17728 /*        ==== NDFL: an iteration count restarted at deflation. ==== */
17729 
17730 	ndfl = 1;
17731 
17732 /*
17733           ==== ITMAX = iteration limit ====
17734 
17735    Computing MAX
17736 */
17737 	i__1 = 10, i__2 = *ihi - *ilo + 1;
17738 	itmax = max(i__1,i__2) * 30;
17739 
17740 /*        ==== Last row and column in the active block ==== */
17741 
17742 	kbot = *ihi;
17743 
17744 /*        ==== Main Loop ==== */
17745 
17746 	i__1 = itmax;
17747 	for (it = 1; it <= i__1; ++it) {
17748 
17749 /*           ==== Done when KBOT falls below ILO ==== */
17750 
17751 	    if (kbot < *ilo) {
17752 		goto L90;
17753 	    }
17754 
17755 /*           ==== Locate active block ==== */
17756 
17757 	    i__2 = *ilo + 1;
17758 	    for (k = kbot; k >= i__2; --k) {
17759 		if (h__[k + (k - 1) * h_dim1] == 0.) {
17760 		    goto L20;
17761 		}
17762 /* L10: */
17763 	    }
17764 	    k = *ilo;
17765 L20:
17766 	    ktop = k;
17767 
17768 /*
17769              ==== Select deflation window size:
17770              .    Typical Case:
17771              .      If possible and advisable, nibble the entire
17772              .      active block.  If not, use size MIN(NWR,NWMAX)
17773              .      or MIN(NWR+1,NWMAX) depending upon which has
17774              .      the smaller corresponding subdiagonal entry
17775              .      (a heuristic).
17776              .
17777              .    Exceptional Case:
17778              .      If there have been no deflations in KEXNW or
17779              .      more iterations, then vary the deflation window
17780              .      size.   At first, because, larger windows are,
17781              .      in general, more powerful than smaller ones,
17782              .      rapidly increase the window to the maximum possible.
17783              .      Then, gradually reduce the window size. ====
17784 */
17785 
17786 	    nh = kbot - ktop + 1;
17787 	    nwupbd = min(nh,nwmax);
17788 	    if (ndfl < 5) {
17789 		nw = min(nwupbd,nwr);
17790 	    } else {
17791 /* Computing MIN */
17792 		i__2 = nwupbd, i__3 = nw << 1;
17793 		nw = min(i__2,i__3);
17794 	    }
17795 	    if (nw < nwmax) {
17796 		if (nw >= nh - 1) {
17797 		    nw = nh;
17798 		} else {
17799 		    kwtop = kbot - nw + 1;
17800 		    if ((d__1 = h__[kwtop + (kwtop - 1) * h_dim1], abs(d__1))
17801 			    > (d__2 = h__[kwtop - 1 + (kwtop - 2) * h_dim1],
17802 			    abs(d__2))) {
17803 			++nw;
17804 		    }
17805 		}
17806 	    }
17807 	    if (ndfl < 5) {
17808 		ndec = -1;
17809 	    } else if (ndec >= 0 || nw >= nwupbd) {
17810 		++ndec;
17811 		if (nw - ndec < 2) {
17812 		    ndec = 0;
17813 		}
17814 		nw -= ndec;
17815 	    }
17816 
17817 /*
17818              ==== Aggressive early deflation:
17819              .    split workspace under the subdiagonal into
17820              .      - an nw-by-nw work array V in the lower
17821              .        left-hand-corner,
17822              .      - an NW-by-at-least-NW-but-more-is-better
17823              .        (NW-by-NHO) horizontal work array along
17824              .        the bottom edge,
17825              .      - an at-least-NW-but-more-is-better (NHV-by-NW)
17826              .        vertical work array along the left-hand-edge.
17827              .        ====
17828 */
17829 
17830 	    kv = *n - nw + 1;
17831 	    kt = nw + 1;
17832 	    nho = *n - nw - 1 - kt + 1;
17833 	    kwv = nw + 2;
17834 	    nve = *n - nw - kwv + 1;
17835 
17836 /*           ==== Aggressive early deflation ==== */
17837 
17838 	    dlaqr3_(wantt, wantz, n, &ktop, &kbot, &nw, &h__[h_offset], ldh,
17839 		    iloz, ihiz, &z__[z_offset], ldz, &ls, &ld, &wr[1], &wi[1],
17840 		     &h__[kv + h_dim1], ldh, &nho, &h__[kv + kt * h_dim1],
17841 		    ldh, &nve, &h__[kwv + h_dim1], ldh, &work[1], lwork);
17842 
17843 /*           ==== Adjust KBOT accounting for new deflations. ==== */
17844 
17845 	    kbot -= ld;
17846 
17847 /*           ==== KS points to the shifts. ==== */
17848 
17849 	    ks = kbot - ls + 1;
17850 
17851 /*
17852              ==== Skip an expensive QR sweep if there is a (partly
17853              .    heuristic) reason to expect that many eigenvalues
17854              .    will deflate without it.  Here, the QR sweep is
17855              .    skipped if many eigenvalues have just been deflated
17856              .    or if the remaining active block is small.
17857 */
17858 
17859 	    if (ld == 0 || ld * 100 <= nw * nibble && kbot - ktop + 1 > min(
17860 		    nmin,nwmax)) {
17861 
17862 /*
17863                 ==== NS = nominal number of simultaneous shifts.
17864                 .    This may be lowered (slightly) if DLAQR3
17865                 .    did not provide that many shifts. ====
17866 
17867    Computing MIN
17868    Computing MAX
17869 */
17870 		i__4 = 2, i__5 = kbot - ktop;
17871 		i__2 = min(nsmax,nsr), i__3 = max(i__4,i__5);
17872 		ns = min(i__2,i__3);
17873 		ns -= ns % 2;
17874 
17875 /*
17876                 ==== If there have been no deflations
17877                 .    in a multiple of KEXSH iterations,
17878                 .    then try exceptional shifts.
17879                 .    Otherwise use shifts provided by
17880                 .    DLAQR3 above or from the eigenvalues
17881                 .    of a trailing principal submatrix. ====
17882 */
17883 
17884 		if (ndfl % 6 == 0) {
17885 		    ks = kbot - ns + 1;
17886 /* Computing MAX */
17887 		    i__3 = ks + 1, i__4 = ktop + 2;
17888 		    i__2 = max(i__3,i__4);
17889 		    for (i__ = kbot; i__ >= i__2; i__ += -2) {
17890 			ss = (d__1 = h__[i__ + (i__ - 1) * h_dim1], abs(d__1))
17891 				 + (d__2 = h__[i__ - 1 + (i__ - 2) * h_dim1],
17892 				abs(d__2));
17893 			aa = ss * .75 + h__[i__ + i__ * h_dim1];
17894 			bb = ss;
17895 			cc = ss * -.4375;
17896 			dd = aa;
17897 			dlanv2_(&aa, &bb, &cc, &dd, &wr[i__ - 1], &wi[i__ - 1]
17898 				, &wr[i__], &wi[i__], &cs, &sn);
17899 /* L30: */
17900 		    }
17901 		    if (ks == ktop) {
17902 			wr[ks + 1] = h__[ks + 1 + (ks + 1) * h_dim1];
17903 			wi[ks + 1] = 0.;
17904 			wr[ks] = wr[ks + 1];
17905 			wi[ks] = wi[ks + 1];
17906 		    }
17907 		} else {
17908 
17909 /*
17910                    ==== Got NS/2 or fewer shifts? Use DLAQR4 or
17911                    .    DLAHQR on a trailing principal submatrix to
17912                    .    get more. (Since NS.LE.NSMAX.LE.(N+6)/9,
17913                    .    there is enough space below the subdiagonal
17914                    .    to fit an NS-by-NS scratch array.) ====
17915 */
17916 
17917 		    if (kbot - ks + 1 <= ns / 2) {
17918 			ks = kbot - ns + 1;
17919 			kt = *n - ns + 1;
17920 			dlacpy_("A", &ns, &ns, &h__[ks + ks * h_dim1], ldh, &
17921 				h__[kt + h_dim1], ldh);
17922 			if (ns > nmin) {
17923 			    dlaqr4_(&c_false, &c_false, &ns, &c__1, &ns, &h__[
17924 				    kt + h_dim1], ldh, &wr[ks], &wi[ks], &
17925 				    c__1, &c__1, zdum, &c__1, &work[1], lwork,
17926 				     &inf);
17927 			} else {
17928 			    dlahqr_(&c_false, &c_false, &ns, &c__1, &ns, &h__[
17929 				    kt + h_dim1], ldh, &wr[ks], &wi[ks], &
17930 				    c__1, &c__1, zdum, &c__1, &inf);
17931 			}
17932 			ks += inf;
17933 
17934 /*
17935                       ==== In case of a rare QR failure use
17936                       .    eigenvalues of the trailing 2-by-2
17937                       .    principal submatrix.  ====
17938 */
17939 
17940 			if (ks >= kbot) {
17941 			    aa = h__[kbot - 1 + (kbot - 1) * h_dim1];
17942 			    cc = h__[kbot + (kbot - 1) * h_dim1];
17943 			    bb = h__[kbot - 1 + kbot * h_dim1];
17944 			    dd = h__[kbot + kbot * h_dim1];
17945 			    dlanv2_(&aa, &bb, &cc, &dd, &wr[kbot - 1], &wi[
17946 				    kbot - 1], &wr[kbot], &wi[kbot], &cs, &sn)
17947 				    ;
17948 			    ks = kbot - 1;
17949 			}
17950 		    }
17951 
17952 		    if (kbot - ks + 1 > ns) {
17953 
17954 /*
17955                       ==== Sort the shifts (Helps a little)
17956                       .    Bubble sort keeps complex conjugate
17957                       .    pairs together. ====
17958 */
17959 
17960 			sorted = FALSE_;
17961 			i__2 = ks + 1;
17962 			for (k = kbot; k >= i__2; --k) {
17963 			    if (sorted) {
17964 				goto L60;
17965 			    }
17966 			    sorted = TRUE_;
17967 			    i__3 = k - 1;
17968 			    for (i__ = ks; i__ <= i__3; ++i__) {
17969 				if ((d__1 = wr[i__], abs(d__1)) + (d__2 = wi[
17970 					i__], abs(d__2)) < (d__3 = wr[i__ + 1]
17971 					, abs(d__3)) + (d__4 = wi[i__ + 1],
17972 					abs(d__4))) {
17973 				    sorted = FALSE_;
17974 
17975 				    swap = wr[i__];
17976 				    wr[i__] = wr[i__ + 1];
17977 				    wr[i__ + 1] = swap;
17978 
17979 				    swap = wi[i__];
17980 				    wi[i__] = wi[i__ + 1];
17981 				    wi[i__ + 1] = swap;
17982 				}
17983 /* L40: */
17984 			    }
17985 /* L50: */
17986 			}
17987 L60:
17988 			;
17989 		    }
17990 
17991 /*
17992                    ==== Shuffle shifts into pairs of real shifts
17993                    .    and pairs of complex conjugate shifts
17994                    .    assuming complex conjugate shifts are
17995                    .    already adjacent to one another. (Yes,
17996                    .    they are.)  ====
17997 */
17998 
17999 		    i__2 = ks + 2;
18000 		    for (i__ = kbot; i__ >= i__2; i__ += -2) {
18001 			if (wi[i__] != -wi[i__ - 1]) {
18002 
18003 			    swap = wr[i__];
18004 			    wr[i__] = wr[i__ - 1];
18005 			    wr[i__ - 1] = wr[i__ - 2];
18006 			    wr[i__ - 2] = swap;
18007 
18008 			    swap = wi[i__];
18009 			    wi[i__] = wi[i__ - 1];
18010 			    wi[i__ - 1] = wi[i__ - 2];
18011 			    wi[i__ - 2] = swap;
18012 			}
18013 /* L70: */
18014 		    }
18015 		}
18016 
18017 /*
18018                 ==== If there are only two shifts and both are
18019                 .    real, then use only one.  ====
18020 */
18021 
18022 		if (kbot - ks + 1 == 2) {
18023 		    if (wi[kbot] == 0.) {
18024 			if ((d__1 = wr[kbot] - h__[kbot + kbot * h_dim1], abs(
18025 				d__1)) < (d__2 = wr[kbot - 1] - h__[kbot +
18026 				kbot * h_dim1], abs(d__2))) {
18027 			    wr[kbot - 1] = wr[kbot];
18028 			} else {
18029 			    wr[kbot] = wr[kbot - 1];
18030 			}
18031 		    }
18032 		}
18033 
18034 /*
18035                 ==== Use up to NS of the the smallest magnatiude
18036                 .    shifts.  If there aren't NS shifts available,
18037                 .    then use them all, possibly dropping one to
18038                 .    make the number of shifts even. ====
18039 
18040    Computing MIN
18041 */
18042 		i__2 = ns, i__3 = kbot - ks + 1;
18043 		ns = min(i__2,i__3);
18044 		ns -= ns % 2;
18045 		ks = kbot - ns + 1;
18046 
18047 /*
18048                 ==== Small-bulge multi-shift QR sweep:
18049                 .    split workspace under the subdiagonal into
18050                 .    - a KDU-by-KDU work array U in the lower
18051                 .      left-hand-corner,
18052                 .    - a KDU-by-at-least-KDU-but-more-is-better
18053                 .      (KDU-by-NHo) horizontal work array WH along
18054                 .      the bottom edge,
18055                 .    - and an at-least-KDU-but-more-is-better-by-KDU
18056                 .      (NVE-by-KDU) vertical work WV arrow along
18057                 .      the left-hand-edge. ====
18058 */
18059 
18060 		kdu = ns * 3 - 3;
18061 		ku = *n - kdu + 1;
18062 		kwh = kdu + 1;
18063 		nho = *n - kdu - 3 - (kdu + 1) + 1;
18064 		kwv = kdu + 4;
18065 		nve = *n - kdu - kwv + 1;
18066 
18067 /*              ==== Small-bulge multi-shift QR sweep ==== */
18068 
18069 		dlaqr5_(wantt, wantz, &kacc22, n, &ktop, &kbot, &ns, &wr[ks],
18070 			&wi[ks], &h__[h_offset], ldh, iloz, ihiz, &z__[
18071 			z_offset], ldz, &work[1], &c__3, &h__[ku + h_dim1],
18072 			ldh, &nve, &h__[kwv + h_dim1], ldh, &nho, &h__[ku +
18073 			kwh * h_dim1], ldh);
18074 	    }
18075 
18076 /*           ==== Note progress (or the lack of it). ==== */
18077 
18078 	    if (ld > 0) {
18079 		ndfl = 1;
18080 	    } else {
18081 		++ndfl;
18082 	    }
18083 
18084 /*
18085              ==== End of main loop ====
18086    L80:
18087 */
18088 	}
18089 
18090 /*
18091           ==== Iteration limit exceeded.  Set INFO to show where
18092           .    the problem occurred and exit. ====
18093 */
18094 
18095 	*info = kbot;
18096 L90:
18097 	;
18098     }
18099 
18100 /*     ==== Return the optimal value of LWORK. ==== */
18101 
18102     work[1] = (doublereal) lwkopt;
18103 
18104 /*     ==== End of DLAQR0 ==== */
18105 
18106     return 0;
18107 } /* dlaqr0_ */
18108 
dlaqr1_(integer * n,doublereal * h__,integer * ldh,doublereal * sr1,doublereal * si1,doublereal * sr2,doublereal * si2,doublereal * v)18109 /* Subroutine */ int dlaqr1_(integer *n, doublereal *h__, integer *ldh,
18110 	doublereal *sr1, doublereal *si1, doublereal *sr2, doublereal *si2,
18111 	doublereal *v)
18112 {
18113     /* System generated locals */
18114     integer h_dim1, h_offset;
18115     doublereal d__1, d__2, d__3;
18116 
18117     /* Local variables */
18118     static doublereal s, h21s, h31s;
18119 
18120 
18121 /*
18122     -- LAPACK auxiliary routine (version 3.2) --
18123        Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
18124        November 2006
18125 
18126 
18127          Given a 2-by-2 or 3-by-3 matrix H, DLAQR1 sets v to a
18128          scalar multiple of the first column of the product
18129 
18130          (*)  K = (H - (sr1 + i*si1)*I)*(H - (sr2 + i*si2)*I)
18131 
18132          scaling to avoid overflows and most underflows. It
18133          is assumed that either
18134 
18135                  1) sr1 = sr2 and si1 = -si2
18136              or
18137                  2) si1 = si2 = 0.
18138 
18139          This is useful for starting double implicit shift bulges
18140          in the QR algorithm.
18141 
18142 
18143          N      (input) integer
18144                 Order of the matrix H. N must be either 2 or 3.
18145 
18146          H      (input) DOUBLE PRECISION array of dimension (LDH,N)
18147                 The 2-by-2 or 3-by-3 matrix H in (*).
18148 
18149          LDH    (input) integer
18150                 The leading dimension of H as declared in
18151                 the calling procedure.  LDH.GE.N
18152 
18153          SR1    (input) DOUBLE PRECISION
18154          SI1    The shifts in (*).
18155          SR2
18156          SI2
18157 
18158          V      (output) DOUBLE PRECISION array of dimension N
18159                 A scalar multiple of the first column of the
18160                 matrix K in (*).
18161 
18162        ================================================================
18163        Based on contributions by
18164           Karen Braman and Ralph Byers, Department of Mathematics,
18165           University of Kansas, USA
18166 
18167        ================================================================
18168 */
18169 
18170     /* Parameter adjustments */
18171     h_dim1 = *ldh;
18172     h_offset = 1 + h_dim1;
18173     h__ -= h_offset;
18174     --v;
18175 
18176     /* Function Body */
18177     if (*n == 2) {
18178 	s = (d__1 = h__[h_dim1 + 1] - *sr2, abs(d__1)) + abs(*si2) + (d__2 =
18179 		h__[h_dim1 + 2], abs(d__2));
18180 	if (s == 0.) {
18181 	    v[1] = 0.;
18182 	    v[2] = 0.;
18183 	} else {
18184 	    h21s = h__[h_dim1 + 2] / s;
18185 	    v[1] = h21s * h__[(h_dim1 << 1) + 1] + (h__[h_dim1 + 1] - *sr1) *
18186 		    ((h__[h_dim1 + 1] - *sr2) / s) - *si1 * (*si2 / s);
18187 	    v[2] = h21s * (h__[h_dim1 + 1] + h__[(h_dim1 << 1) + 2] - *sr1 - *
18188 		    sr2);
18189 	}
18190     } else {
18191 	s = (d__1 = h__[h_dim1 + 1] - *sr2, abs(d__1)) + abs(*si2) + (d__2 =
18192 		h__[h_dim1 + 2], abs(d__2)) + (d__3 = h__[h_dim1 + 3], abs(
18193 		d__3));
18194 	if (s == 0.) {
18195 	    v[1] = 0.;
18196 	    v[2] = 0.;
18197 	    v[3] = 0.;
18198 	} else {
18199 	    h21s = h__[h_dim1 + 2] / s;
18200 	    h31s = h__[h_dim1 + 3] / s;
18201 	    v[1] = (h__[h_dim1 + 1] - *sr1) * ((h__[h_dim1 + 1] - *sr2) / s)
18202 		    - *si1 * (*si2 / s) + h__[(h_dim1 << 1) + 1] * h21s + h__[
18203 		    h_dim1 * 3 + 1] * h31s;
18204 	    v[2] = h21s * (h__[h_dim1 + 1] + h__[(h_dim1 << 1) + 2] - *sr1 - *
18205 		    sr2) + h__[h_dim1 * 3 + 2] * h31s;
18206 	    v[3] = h31s * (h__[h_dim1 + 1] + h__[h_dim1 * 3 + 3] - *sr1 - *
18207 		    sr2) + h21s * h__[(h_dim1 << 1) + 3];
18208 	}
18209     }
18210     return 0;
18211 } /* dlaqr1_ */
18212 
dlaqr2_(logical * wantt,logical * wantz,integer * n,integer * ktop,integer * kbot,integer * nw,doublereal * h__,integer * ldh,integer * iloz,integer * ihiz,doublereal * z__,integer * ldz,integer * ns,integer * nd,doublereal * sr,doublereal * si,doublereal * v,integer * ldv,integer * nh,doublereal * t,integer * ldt,integer * nv,doublereal * wv,integer * ldwv,doublereal * work,integer * lwork)18213 /* Subroutine */ int dlaqr2_(logical *wantt, logical *wantz, integer *n,
18214 	integer *ktop, integer *kbot, integer *nw, doublereal *h__, integer *
18215 	ldh, integer *iloz, integer *ihiz, doublereal *z__, integer *ldz,
18216 	integer *ns, integer *nd, doublereal *sr, doublereal *si, doublereal *
18217 	v, integer *ldv, integer *nh, doublereal *t, integer *ldt, integer *
18218 	nv, doublereal *wv, integer *ldwv, doublereal *work, integer *lwork)
18219 {
18220     /* System generated locals */
18221     integer h_dim1, h_offset, t_dim1, t_offset, v_dim1, v_offset, wv_dim1,
18222 	    wv_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4;
18223     doublereal d__1, d__2, d__3, d__4, d__5, d__6;
18224 
18225     /* Local variables */
18226     static integer i__, j, k;
18227     static doublereal s, aa, bb, cc, dd, cs, sn;
18228     static integer jw;
18229     static doublereal evi, evk, foo;
18230     static integer kln;
18231     static doublereal tau, ulp;
18232     static integer lwk1, lwk2;
18233     static doublereal beta;
18234     static integer kend, kcol, info, ifst, ilst, ltop, krow;
18235     extern /* Subroutine */ int dlarf_(char *, integer *, integer *,
18236 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
18237 	    doublereal *), dgemm_(char *, char *, integer *, integer *
18238 	    , integer *, doublereal *, doublereal *, integer *, doublereal *,
18239 	    integer *, doublereal *, doublereal *, integer *);
18240     static logical bulge;
18241     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
18242 	    doublereal *, integer *);
18243     static integer infqr, kwtop;
18244     extern /* Subroutine */ int dlanv2_(doublereal *, doublereal *,
18245 	    doublereal *, doublereal *, doublereal *, doublereal *,
18246 	    doublereal *, doublereal *, doublereal *, doublereal *), dlabad_(
18247 	    doublereal *, doublereal *);
18248 
18249     extern /* Subroutine */ int dgehrd_(integer *, integer *, integer *,
18250 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
18251 	    integer *), dlarfg_(integer *, doublereal *, doublereal *,
18252 	    integer *, doublereal *), dlahqr_(logical *, logical *, integer *,
18253 	     integer *, integer *, doublereal *, integer *, doublereal *,
18254 	    doublereal *, integer *, integer *, doublereal *, integer *,
18255 	    integer *), dlacpy_(char *, integer *, integer *, doublereal *,
18256 	    integer *, doublereal *, integer *);
18257     static doublereal safmin;
18258     extern /* Subroutine */ int dlaset_(char *, integer *, integer *,
18259 	    doublereal *, doublereal *, doublereal *, integer *);
18260     static doublereal safmax;
18261     extern /* Subroutine */ int dtrexc_(char *, integer *, doublereal *,
18262 	    integer *, doublereal *, integer *, integer *, integer *,
18263 	    doublereal *, integer *), dormhr_(char *, char *, integer
18264 	    *, integer *, integer *, integer *, doublereal *, integer *,
18265 	    doublereal *, doublereal *, integer *, doublereal *, integer *,
18266 	    integer *);
18267     static logical sorted;
18268     static doublereal smlnum;
18269     static integer lwkopt;
18270 
18271 
18272 /*
18273     -- LAPACK auxiliary routine (version 3.2.2)                        --
18274        Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
18275     -- June 2010                                                       --
18276 
18277 
18278        This subroutine is identical to DLAQR3 except that it avoids
18279        recursion by calling DLAHQR instead of DLAQR4.
18280 
18281 
18282        ******************************************************************
18283        Aggressive early deflation:
18284 
18285        This subroutine accepts as input an upper Hessenberg matrix
18286        H and performs an orthogonal similarity transformation
18287        designed to detect and deflate fully converged eigenvalues from
18288        a trailing principal submatrix.  On output H has been over-
18289        written by a new Hessenberg matrix that is a perturbation of
18290        an orthogonal similarity transformation of H.  It is to be
18291        hoped that the final version of H has many zero subdiagonal
18292        entries.
18293 
18294        ******************************************************************
18295        WANTT   (input) LOGICAL
18296             If .TRUE., then the Hessenberg matrix H is fully updated
18297             so that the quasi-triangular Schur factor may be
18298             computed (in cooperation with the calling subroutine).
18299             If .FALSE., then only enough of H is updated to preserve
18300             the eigenvalues.
18301 
18302        WANTZ   (input) LOGICAL
18303             If .TRUE., then the orthogonal matrix Z is updated so
18304             so that the orthogonal Schur factor may be computed
18305             (in cooperation with the calling subroutine).
18306             If .FALSE., then Z is not referenced.
18307 
18308        N       (input) INTEGER
18309             The order of the matrix H and (if WANTZ is .TRUE.) the
18310             order of the orthogonal matrix Z.
18311 
18312        KTOP    (input) INTEGER
18313             It is assumed that either KTOP = 1 or H(KTOP,KTOP-1)=0.
18314             KBOT and KTOP together determine an isolated block
18315             along the diagonal of the Hessenberg matrix.
18316 
18317        KBOT    (input) INTEGER
18318             It is assumed without a check that either
18319             KBOT = N or H(KBOT+1,KBOT)=0.  KBOT and KTOP together
18320             determine an isolated block along the diagonal of the
18321             Hessenberg matrix.
18322 
18323        NW      (input) INTEGER
18324             Deflation window size.  1 .LE. NW .LE. (KBOT-KTOP+1).
18325 
18326        H       (input/output) DOUBLE PRECISION array, dimension (LDH,N)
18327             On input the initial N-by-N section of H stores the
18328             Hessenberg matrix undergoing aggressive early deflation.
18329             On output H has been transformed by an orthogonal
18330             similarity transformation, perturbed, and the returned
18331             to Hessenberg form that (it is to be hoped) has some
18332             zero subdiagonal entries.
18333 
18334        LDH     (input) integer
18335             Leading dimension of H just as declared in the calling
18336             subroutine.  N .LE. LDH
18337 
18338        ILOZ    (input) INTEGER
18339        IHIZ    (input) INTEGER
18340             Specify the rows of Z to which transformations must be
18341             applied if WANTZ is .TRUE.. 1 .LE. ILOZ .LE. IHIZ .LE. N.
18342 
18343        Z       (input/output) DOUBLE PRECISION array, dimension (LDZ,N)
18344             IF WANTZ is .TRUE., then on output, the orthogonal
18345             similarity transformation mentioned above has been
18346             accumulated into Z(ILOZ:IHIZ,ILO:IHI) from the right.
18347             If WANTZ is .FALSE., then Z is unreferenced.
18348 
18349        LDZ     (input) integer
18350             The leading dimension of Z just as declared in the
18351             calling subroutine.  1 .LE. LDZ.
18352 
18353        NS      (output) integer
18354             The number of unconverged (ie approximate) eigenvalues
18355             returned in SR and SI that may be used as shifts by the
18356             calling subroutine.
18357 
18358        ND      (output) integer
18359             The number of converged eigenvalues uncovered by this
18360             subroutine.
18361 
18362        SR      (output) DOUBLE PRECISION array, dimension (KBOT)
18363        SI      (output) DOUBLE PRECISION array, dimension (KBOT)
18364             On output, the real and imaginary parts of approximate
18365             eigenvalues that may be used for shifts are stored in
18366             SR(KBOT-ND-NS+1) through SR(KBOT-ND) and
18367             SI(KBOT-ND-NS+1) through SI(KBOT-ND), respectively.
18368             The real and imaginary parts of converged eigenvalues
18369             are stored in SR(KBOT-ND+1) through SR(KBOT) and
18370             SI(KBOT-ND+1) through SI(KBOT), respectively.
18371 
18372        V       (workspace) DOUBLE PRECISION array, dimension (LDV,NW)
18373             An NW-by-NW work array.
18374 
18375        LDV     (input) integer scalar
18376             The leading dimension of V just as declared in the
18377             calling subroutine.  NW .LE. LDV
18378 
18379        NH      (input) integer scalar
18380             The number of columns of T.  NH.GE.NW.
18381 
18382        T       (workspace) DOUBLE PRECISION array, dimension (LDT,NW)
18383 
18384        LDT     (input) integer
18385             The leading dimension of T just as declared in the
18386             calling subroutine.  NW .LE. LDT
18387 
18388        NV      (input) integer
18389             The number of rows of work array WV available for
18390             workspace.  NV.GE.NW.
18391 
18392        WV      (workspace) DOUBLE PRECISION array, dimension (LDWV,NW)
18393 
18394        LDWV    (input) integer
18395             The leading dimension of W just as declared in the
18396             calling subroutine.  NW .LE. LDV
18397 
18398        WORK    (workspace) DOUBLE PRECISION array, dimension (LWORK)
18399             On exit, WORK(1) is set to an estimate of the optimal value
18400             of LWORK for the given values of N, NW, KTOP and KBOT.
18401 
18402        LWORK   (input) integer
18403             The dimension of the work array WORK.  LWORK = 2*NW
18404             suffices, but greater efficiency may result from larger
18405             values of LWORK.
18406 
18407             If LWORK = -1, then a workspace query is assumed; DLAQR2
18408             only estimates the optimal workspace size for the given
18409             values of N, NW, KTOP and KBOT.  The estimate is returned
18410             in WORK(1).  No error message related to LWORK is issued
18411             by XERBLA.  Neither H nor Z are accessed.
18412 
18413        ================================================================
18414        Based on contributions by
18415           Karen Braman and Ralph Byers, Department of Mathematics,
18416           University of Kansas, USA
18417 
18418        ================================================================
18419 
18420        ==== Estimate optimal workspace. ====
18421 */
18422 
18423     /* Parameter adjustments */
18424     h_dim1 = *ldh;
18425     h_offset = 1 + h_dim1;
18426     h__ -= h_offset;
18427     z_dim1 = *ldz;
18428     z_offset = 1 + z_dim1;
18429     z__ -= z_offset;
18430     --sr;
18431     --si;
18432     v_dim1 = *ldv;
18433     v_offset = 1 + v_dim1;
18434     v -= v_offset;
18435     t_dim1 = *ldt;
18436     t_offset = 1 + t_dim1;
18437     t -= t_offset;
18438     wv_dim1 = *ldwv;
18439     wv_offset = 1 + wv_dim1;
18440     wv -= wv_offset;
18441     --work;
18442 
18443     /* Function Body */
18444 /* Computing MIN */
18445     i__1 = *nw, i__2 = *kbot - *ktop + 1;
18446     jw = min(i__1,i__2);
18447     if (jw <= 2) {
18448 	lwkopt = 1;
18449     } else {
18450 
18451 /*        ==== Workspace query call to DGEHRD ==== */
18452 
18453 	i__1 = jw - 1;
18454 	dgehrd_(&jw, &c__1, &i__1, &t[t_offset], ldt, &work[1], &work[1], &
18455 		c_n1, &info);
18456 	lwk1 = (integer) work[1];
18457 
18458 /*        ==== Workspace query call to DORMHR ==== */
18459 
18460 	i__1 = jw - 1;
18461 	dormhr_("R", "N", &jw, &jw, &c__1, &i__1, &t[t_offset], ldt, &work[1],
18462 		 &v[v_offset], ldv, &work[1], &c_n1, &info);
18463 	lwk2 = (integer) work[1];
18464 
18465 /*        ==== Optimal workspace ==== */
18466 
18467 	lwkopt = jw + max(lwk1,lwk2);
18468     }
18469 
18470 /*     ==== Quick return in case of workspace query. ==== */
18471 
18472     if (*lwork == -1) {
18473 	work[1] = (doublereal) lwkopt;
18474 	return 0;
18475     }
18476 
18477 /*
18478        ==== Nothing to do ...
18479        ... for an empty active block ... ====
18480 */
18481     *ns = 0;
18482     *nd = 0;
18483     work[1] = 1.;
18484     if (*ktop > *kbot) {
18485 	return 0;
18486     }
18487 /*     ... nor for an empty deflation window. ==== */
18488     if (*nw < 1) {
18489 	return 0;
18490     }
18491 
18492 /*     ==== Machine constants ==== */
18493 
18494     safmin = SAFEMINIMUM;
18495     safmax = 1. / safmin;
18496     dlabad_(&safmin, &safmax);
18497     ulp = PRECISION;
18498     smlnum = safmin * ((doublereal) (*n) / ulp);
18499 
18500 /*
18501        ==== Setup deflation window ====
18502 
18503    Computing MIN
18504 */
18505     i__1 = *nw, i__2 = *kbot - *ktop + 1;
18506     jw = min(i__1,i__2);
18507     kwtop = *kbot - jw + 1;
18508     if (kwtop == *ktop) {
18509 	s = 0.;
18510     } else {
18511 	s = h__[kwtop + (kwtop - 1) * h_dim1];
18512     }
18513 
18514     if (*kbot == kwtop) {
18515 
18516 /*        ==== 1-by-1 deflation window: not much to do ==== */
18517 
18518 	sr[kwtop] = h__[kwtop + kwtop * h_dim1];
18519 	si[kwtop] = 0.;
18520 	*ns = 1;
18521 	*nd = 0;
18522 /* Computing MAX */
18523 	d__2 = smlnum, d__3 = ulp * (d__1 = h__[kwtop + kwtop * h_dim1], abs(
18524 		d__1));
18525 	if (abs(s) <= max(d__2,d__3)) {
18526 	    *ns = 0;
18527 	    *nd = 1;
18528 	    if (kwtop > *ktop) {
18529 		h__[kwtop + (kwtop - 1) * h_dim1] = 0.;
18530 	    }
18531 	}
18532 	work[1] = 1.;
18533 	return 0;
18534     }
18535 
18536 /*
18537        ==== Convert to spike-triangular form.  (In case of a
18538        .    rare QR failure, this routine continues to do
18539        .    aggressive early deflation using that part of
18540        .    the deflation window that converged using INFQR
18541        .    here and there to keep track.) ====
18542 */
18543 
18544     dlacpy_("U", &jw, &jw, &h__[kwtop + kwtop * h_dim1], ldh, &t[t_offset],
18545 	    ldt);
18546     i__1 = jw - 1;
18547     i__2 = *ldh + 1;
18548     i__3 = *ldt + 1;
18549     dcopy_(&i__1, &h__[kwtop + 1 + kwtop * h_dim1], &i__2, &t[t_dim1 + 2], &
18550 	    i__3);
18551 
18552     dlaset_("A", &jw, &jw, &c_b29, &c_b15, &v[v_offset], ldv);
18553     dlahqr_(&c_true, &c_true, &jw, &c__1, &jw, &t[t_offset], ldt, &sr[kwtop],
18554 	    &si[kwtop], &c__1, &jw, &v[v_offset], ldv, &infqr);
18555 
18556 /*     ==== DTREXC needs a clean margin near the diagonal ==== */
18557 
18558     i__1 = jw - 3;
18559     for (j = 1; j <= i__1; ++j) {
18560 	t[j + 2 + j * t_dim1] = 0.;
18561 	t[j + 3 + j * t_dim1] = 0.;
18562 /* L10: */
18563     }
18564     if (jw > 2) {
18565 	t[jw + (jw - 2) * t_dim1] = 0.;
18566     }
18567 
18568 /*     ==== Deflation detection loop ==== */
18569 
18570     *ns = jw;
18571     ilst = infqr + 1;
18572 L20:
18573     if (ilst <= *ns) {
18574 	if (*ns == 1) {
18575 	    bulge = FALSE_;
18576 	} else {
18577 	    bulge = t[*ns + (*ns - 1) * t_dim1] != 0.;
18578 	}
18579 
18580 /*        ==== Small spike tip test for deflation ==== */
18581 
18582 	if (! bulge) {
18583 
18584 /*           ==== Real eigenvalue ==== */
18585 
18586 	    foo = (d__1 = t[*ns + *ns * t_dim1], abs(d__1));
18587 	    if (foo == 0.) {
18588 		foo = abs(s);
18589 	    }
18590 /* Computing MAX */
18591 	    d__2 = smlnum, d__3 = ulp * foo;
18592 	    if ((d__1 = s * v[*ns * v_dim1 + 1], abs(d__1)) <= max(d__2,d__3))
18593 		     {
18594 
18595 /*              ==== Deflatable ==== */
18596 
18597 		--(*ns);
18598 	    } else {
18599 
18600 /*
18601                 ==== Undeflatable.   Move it up out of the way.
18602                 .    (DTREXC can not fail in this case.) ====
18603 */
18604 
18605 		ifst = *ns;
18606 		dtrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst,
18607 			 &ilst, &work[1], &info);
18608 		++ilst;
18609 	    }
18610 	} else {
18611 
18612 /*           ==== Complex conjugate pair ==== */
18613 
18614 	    foo = (d__3 = t[*ns + *ns * t_dim1], abs(d__3)) + sqrt((d__1 = t[*
18615 		    ns + (*ns - 1) * t_dim1], abs(d__1))) * sqrt((d__2 = t[*
18616 		    ns - 1 + *ns * t_dim1], abs(d__2)));
18617 	    if (foo == 0.) {
18618 		foo = abs(s);
18619 	    }
18620 /* Computing MAX */
18621 	    d__3 = (d__1 = s * v[*ns * v_dim1 + 1], abs(d__1)), d__4 = (d__2 =
18622 		     s * v[(*ns - 1) * v_dim1 + 1], abs(d__2));
18623 /* Computing MAX */
18624 	    d__5 = smlnum, d__6 = ulp * foo;
18625 	    if (max(d__3,d__4) <= max(d__5,d__6)) {
18626 
18627 /*              ==== Deflatable ==== */
18628 
18629 		*ns += -2;
18630 	    } else {
18631 
18632 /*
18633                 ==== Undeflatable. Move them up out of the way.
18634                 .    Fortunately, DTREXC does the right thing with
18635                 .    ILST in case of a rare exchange failure. ====
18636 */
18637 
18638 		ifst = *ns;
18639 		dtrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst,
18640 			 &ilst, &work[1], &info);
18641 		ilst += 2;
18642 	    }
18643 	}
18644 
18645 /*        ==== End deflation detection loop ==== */
18646 
18647 	goto L20;
18648     }
18649 
18650 /*        ==== Return to Hessenberg form ==== */
18651 
18652     if (*ns == 0) {
18653 	s = 0.;
18654     }
18655 
18656     if (*ns < jw) {
18657 
18658 /*
18659           ==== sorting diagonal blocks of T improves accuracy for
18660           .    graded matrices.  Bubble sort deals well with
18661           .    exchange failures. ====
18662 */
18663 
18664 	sorted = FALSE_;
18665 	i__ = *ns + 1;
18666 L30:
18667 	if (sorted) {
18668 	    goto L50;
18669 	}
18670 	sorted = TRUE_;
18671 
18672 	kend = i__ - 1;
18673 	i__ = infqr + 1;
18674 	if (i__ == *ns) {
18675 	    k = i__ + 1;
18676 	} else if (t[i__ + 1 + i__ * t_dim1] == 0.) {
18677 	    k = i__ + 1;
18678 	} else {
18679 	    k = i__ + 2;
18680 	}
18681 L40:
18682 	if (k <= kend) {
18683 	    if (k == i__ + 1) {
18684 		evi = (d__1 = t[i__ + i__ * t_dim1], abs(d__1));
18685 	    } else {
18686 		evi = (d__3 = t[i__ + i__ * t_dim1], abs(d__3)) + sqrt((d__1 =
18687 			 t[i__ + 1 + i__ * t_dim1], abs(d__1))) * sqrt((d__2 =
18688 			 t[i__ + (i__ + 1) * t_dim1], abs(d__2)));
18689 	    }
18690 
18691 	    if (k == kend) {
18692 		evk = (d__1 = t[k + k * t_dim1], abs(d__1));
18693 	    } else if (t[k + 1 + k * t_dim1] == 0.) {
18694 		evk = (d__1 = t[k + k * t_dim1], abs(d__1));
18695 	    } else {
18696 		evk = (d__3 = t[k + k * t_dim1], abs(d__3)) + sqrt((d__1 = t[
18697 			k + 1 + k * t_dim1], abs(d__1))) * sqrt((d__2 = t[k +
18698 			(k + 1) * t_dim1], abs(d__2)));
18699 	    }
18700 
18701 	    if (evi >= evk) {
18702 		i__ = k;
18703 	    } else {
18704 		sorted = FALSE_;
18705 		ifst = i__;
18706 		ilst = k;
18707 		dtrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst,
18708 			 &ilst, &work[1], &info);
18709 		if (info == 0) {
18710 		    i__ = ilst;
18711 		} else {
18712 		    i__ = k;
18713 		}
18714 	    }
18715 	    if (i__ == kend) {
18716 		k = i__ + 1;
18717 	    } else if (t[i__ + 1 + i__ * t_dim1] == 0.) {
18718 		k = i__ + 1;
18719 	    } else {
18720 		k = i__ + 2;
18721 	    }
18722 	    goto L40;
18723 	}
18724 	goto L30;
18725 L50:
18726 	;
18727     }
18728 
18729 /*     ==== Restore shift/eigenvalue array from T ==== */
18730 
18731     i__ = jw;
18732 L60:
18733     if (i__ >= infqr + 1) {
18734 	if (i__ == infqr + 1) {
18735 	    sr[kwtop + i__ - 1] = t[i__ + i__ * t_dim1];
18736 	    si[kwtop + i__ - 1] = 0.;
18737 	    --i__;
18738 	} else if (t[i__ + (i__ - 1) * t_dim1] == 0.) {
18739 	    sr[kwtop + i__ - 1] = t[i__ + i__ * t_dim1];
18740 	    si[kwtop + i__ - 1] = 0.;
18741 	    --i__;
18742 	} else {
18743 	    aa = t[i__ - 1 + (i__ - 1) * t_dim1];
18744 	    cc = t[i__ + (i__ - 1) * t_dim1];
18745 	    bb = t[i__ - 1 + i__ * t_dim1];
18746 	    dd = t[i__ + i__ * t_dim1];
18747 	    dlanv2_(&aa, &bb, &cc, &dd, &sr[kwtop + i__ - 2], &si[kwtop + i__
18748 		    - 2], &sr[kwtop + i__ - 1], &si[kwtop + i__ - 1], &cs, &
18749 		    sn);
18750 	    i__ += -2;
18751 	}
18752 	goto L60;
18753     }
18754 
18755     if (*ns < jw || s == 0.) {
18756 	if (*ns > 1 && s != 0.) {
18757 
18758 /*           ==== Reflect spike back into lower triangle ==== */
18759 
18760 	    dcopy_(ns, &v[v_offset], ldv, &work[1], &c__1);
18761 	    beta = work[1];
18762 	    dlarfg_(ns, &beta, &work[2], &c__1, &tau);
18763 	    work[1] = 1.;
18764 
18765 	    i__1 = jw - 2;
18766 	    i__2 = jw - 2;
18767 	    dlaset_("L", &i__1, &i__2, &c_b29, &c_b29, &t[t_dim1 + 3], ldt);
18768 
18769 	    dlarf_("L", ns, &jw, &work[1], &c__1, &tau, &t[t_offset], ldt, &
18770 		    work[jw + 1]);
18771 	    dlarf_("R", ns, ns, &work[1], &c__1, &tau, &t[t_offset], ldt, &
18772 		    work[jw + 1]);
18773 	    dlarf_("R", &jw, ns, &work[1], &c__1, &tau, &v[v_offset], ldv, &
18774 		    work[jw + 1]);
18775 
18776 	    i__1 = *lwork - jw;
18777 	    dgehrd_(&jw, &c__1, ns, &t[t_offset], ldt, &work[1], &work[jw + 1]
18778 		    , &i__1, &info);
18779 	}
18780 
18781 /*        ==== Copy updated reduced window into place ==== */
18782 
18783 	if (kwtop > 1) {
18784 	    h__[kwtop + (kwtop - 1) * h_dim1] = s * v[v_dim1 + 1];
18785 	}
18786 	dlacpy_("U", &jw, &jw, &t[t_offset], ldt, &h__[kwtop + kwtop * h_dim1]
18787 		, ldh);
18788 	i__1 = jw - 1;
18789 	i__2 = *ldt + 1;
18790 	i__3 = *ldh + 1;
18791 	dcopy_(&i__1, &t[t_dim1 + 2], &i__2, &h__[kwtop + 1 + kwtop * h_dim1],
18792 		 &i__3);
18793 
18794 /*
18795           ==== Accumulate orthogonal matrix in order update
18796           .    H and Z, if requested.  ====
18797 */
18798 
18799 	if (*ns > 1 && s != 0.) {
18800 	    i__1 = *lwork - jw;
18801 	    dormhr_("R", "N", &jw, ns, &c__1, ns, &t[t_offset], ldt, &work[1],
18802 		     &v[v_offset], ldv, &work[jw + 1], &i__1, &info);
18803 	}
18804 
18805 /*        ==== Update vertical slab in H ==== */
18806 
18807 	if (*wantt) {
18808 	    ltop = 1;
18809 	} else {
18810 	    ltop = *ktop;
18811 	}
18812 	i__1 = kwtop - 1;
18813 	i__2 = *nv;
18814 	for (krow = ltop; i__2 < 0 ? krow >= i__1 : krow <= i__1; krow +=
18815 		i__2) {
18816 /* Computing MIN */
18817 	    i__3 = *nv, i__4 = kwtop - krow;
18818 	    kln = min(i__3,i__4);
18819 	    dgemm_("N", "N", &kln, &jw, &jw, &c_b15, &h__[krow + kwtop *
18820 		    h_dim1], ldh, &v[v_offset], ldv, &c_b29, &wv[wv_offset],
18821 		    ldwv);
18822 	    dlacpy_("A", &kln, &jw, &wv[wv_offset], ldwv, &h__[krow + kwtop *
18823 		    h_dim1], ldh);
18824 /* L70: */
18825 	}
18826 
18827 /*        ==== Update horizontal slab in H ==== */
18828 
18829 	if (*wantt) {
18830 	    i__2 = *n;
18831 	    i__1 = *nh;
18832 	    for (kcol = *kbot + 1; i__1 < 0 ? kcol >= i__2 : kcol <= i__2;
18833 		    kcol += i__1) {
18834 /* Computing MIN */
18835 		i__3 = *nh, i__4 = *n - kcol + 1;
18836 		kln = min(i__3,i__4);
18837 		dgemm_("C", "N", &jw, &kln, &jw, &c_b15, &v[v_offset], ldv, &
18838 			h__[kwtop + kcol * h_dim1], ldh, &c_b29, &t[t_offset],
18839 			 ldt);
18840 		dlacpy_("A", &jw, &kln, &t[t_offset], ldt, &h__[kwtop + kcol *
18841 			 h_dim1], ldh);
18842 /* L80: */
18843 	    }
18844 	}
18845 
18846 /*        ==== Update vertical slab in Z ==== */
18847 
18848 	if (*wantz) {
18849 	    i__1 = *ihiz;
18850 	    i__2 = *nv;
18851 	    for (krow = *iloz; i__2 < 0 ? krow >= i__1 : krow <= i__1; krow +=
18852 		     i__2) {
18853 /* Computing MIN */
18854 		i__3 = *nv, i__4 = *ihiz - krow + 1;
18855 		kln = min(i__3,i__4);
18856 		dgemm_("N", "N", &kln, &jw, &jw, &c_b15, &z__[krow + kwtop *
18857 			z_dim1], ldz, &v[v_offset], ldv, &c_b29, &wv[
18858 			wv_offset], ldwv);
18859 		dlacpy_("A", &kln, &jw, &wv[wv_offset], ldwv, &z__[krow +
18860 			kwtop * z_dim1], ldz);
18861 /* L90: */
18862 	    }
18863 	}
18864     }
18865 
18866 /*     ==== Return the number of deflations ... ==== */
18867 
18868     *nd = jw - *ns;
18869 
18870 /*
18871        ==== ... and the number of shifts. (Subtracting
18872        .    INFQR from the spike length takes care
18873        .    of the case of a rare QR failure while
18874        .    calculating eigenvalues of the deflation
18875        .    window.)  ====
18876 */
18877 
18878     *ns -= infqr;
18879 
18880 /*      ==== Return optimal workspace. ==== */
18881 
18882     work[1] = (doublereal) lwkopt;
18883 
18884 /*     ==== End of DLAQR2 ==== */
18885 
18886     return 0;
18887 } /* dlaqr2_ */
18888 
dlaqr3_(logical * wantt,logical * wantz,integer * n,integer * ktop,integer * kbot,integer * nw,doublereal * h__,integer * ldh,integer * iloz,integer * ihiz,doublereal * z__,integer * ldz,integer * ns,integer * nd,doublereal * sr,doublereal * si,doublereal * v,integer * ldv,integer * nh,doublereal * t,integer * ldt,integer * nv,doublereal * wv,integer * ldwv,doublereal * work,integer * lwork)18889 /* Subroutine */ int dlaqr3_(logical *wantt, logical *wantz, integer *n,
18890 	integer *ktop, integer *kbot, integer *nw, doublereal *h__, integer *
18891 	ldh, integer *iloz, integer *ihiz, doublereal *z__, integer *ldz,
18892 	integer *ns, integer *nd, doublereal *sr, doublereal *si, doublereal *
18893 	v, integer *ldv, integer *nh, doublereal *t, integer *ldt, integer *
18894 	nv, doublereal *wv, integer *ldwv, doublereal *work, integer *lwork)
18895 {
18896     /* System generated locals */
18897     integer h_dim1, h_offset, t_dim1, t_offset, v_dim1, v_offset, wv_dim1,
18898 	    wv_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4;
18899     doublereal d__1, d__2, d__3, d__4, d__5, d__6;
18900 
18901     /* Local variables */
18902     static integer i__, j, k;
18903     static doublereal s, aa, bb, cc, dd, cs, sn;
18904     static integer jw;
18905     static doublereal evi, evk, foo;
18906     static integer kln;
18907     static doublereal tau, ulp;
18908     static integer lwk1, lwk2, lwk3;
18909     static doublereal beta;
18910     static integer kend, kcol, info, nmin, ifst, ilst, ltop, krow;
18911     extern /* Subroutine */ int dlarf_(char *, integer *, integer *,
18912 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
18913 	    doublereal *), dgemm_(char *, char *, integer *, integer *
18914 	    , integer *, doublereal *, doublereal *, integer *, doublereal *,
18915 	    integer *, doublereal *, doublereal *, integer *);
18916     static logical bulge;
18917     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
18918 	    doublereal *, integer *);
18919     static integer infqr, kwtop;
18920     extern /* Subroutine */ int dlanv2_(doublereal *, doublereal *,
18921 	    doublereal *, doublereal *, doublereal *, doublereal *,
18922 	    doublereal *, doublereal *, doublereal *, doublereal *), dlaqr4_(
18923 	    logical *, logical *, integer *, integer *, integer *, doublereal
18924 	    *, integer *, doublereal *, doublereal *, integer *, integer *,
18925 	    doublereal *, integer *, doublereal *, integer *, integer *),
18926 	    dlabad_(doublereal *, doublereal *);
18927 
18928     extern /* Subroutine */ int dgehrd_(integer *, integer *, integer *,
18929 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
18930 	    integer *), dlarfg_(integer *, doublereal *, doublereal *,
18931 	    integer *, doublereal *), dlahqr_(logical *, logical *, integer *,
18932 	     integer *, integer *, doublereal *, integer *, doublereal *,
18933 	    doublereal *, integer *, integer *, doublereal *, integer *,
18934 	    integer *), dlacpy_(char *, integer *, integer *, doublereal *,
18935 	    integer *, doublereal *, integer *);
18936     static doublereal safmin;
18937     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
18938 	    integer *, integer *, ftnlen, ftnlen);
18939     static doublereal safmax;
18940     extern /* Subroutine */ int dlaset_(char *, integer *, integer *,
18941 	    doublereal *, doublereal *, doublereal *, integer *),
18942 	    dtrexc_(char *, integer *, doublereal *, integer *, doublereal *,
18943 	    integer *, integer *, integer *, doublereal *, integer *),
18944 	     dormhr_(char *, char *, integer *, integer *, integer *, integer
18945 	    *, doublereal *, integer *, doublereal *, doublereal *, integer *,
18946 	     doublereal *, integer *, integer *);
18947     static logical sorted;
18948     static doublereal smlnum;
18949     static integer lwkopt;
18950 
18951 
18952 /*
18953     -- LAPACK auxiliary routine (version 3.2.2)                        --
18954        Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
18955     -- June 2010                                                       --
18956 
18957 
18958        ******************************************************************
18959        Aggressive early deflation:
18960 
18961        This subroutine accepts as input an upper Hessenberg matrix
18962        H and performs an orthogonal similarity transformation
18963        designed to detect and deflate fully converged eigenvalues from
18964        a trailing principal submatrix.  On output H has been over-
18965        written by a new Hessenberg matrix that is a perturbation of
18966        an orthogonal similarity transformation of H.  It is to be
18967        hoped that the final version of H has many zero subdiagonal
18968        entries.
18969 
18970        ******************************************************************
18971        WANTT   (input) LOGICAL
18972             If .TRUE., then the Hessenberg matrix H is fully updated
18973             so that the quasi-triangular Schur factor may be
18974             computed (in cooperation with the calling subroutine).
18975             If .FALSE., then only enough of H is updated to preserve
18976             the eigenvalues.
18977 
18978        WANTZ   (input) LOGICAL
18979             If .TRUE., then the orthogonal matrix Z is updated so
18980             so that the orthogonal Schur factor may be computed
18981             (in cooperation with the calling subroutine).
18982             If .FALSE., then Z is not referenced.
18983 
18984        N       (input) INTEGER
18985             The order of the matrix H and (if WANTZ is .TRUE.) the
18986             order of the orthogonal matrix Z.
18987 
18988        KTOP    (input) INTEGER
18989             It is assumed that either KTOP = 1 or H(KTOP,KTOP-1)=0.
18990             KBOT and KTOP together determine an isolated block
18991             along the diagonal of the Hessenberg matrix.
18992 
18993        KBOT    (input) INTEGER
18994             It is assumed without a check that either
18995             KBOT = N or H(KBOT+1,KBOT)=0.  KBOT and KTOP together
18996             determine an isolated block along the diagonal of the
18997             Hessenberg matrix.
18998 
18999        NW      (input) INTEGER
19000             Deflation window size.  1 .LE. NW .LE. (KBOT-KTOP+1).
19001 
19002        H       (input/output) DOUBLE PRECISION array, dimension (LDH,N)
19003             On input the initial N-by-N section of H stores the
19004             Hessenberg matrix undergoing aggressive early deflation.
19005             On output H has been transformed by an orthogonal
19006             similarity transformation, perturbed, and the returned
19007             to Hessenberg form that (it is to be hoped) has some
19008             zero subdiagonal entries.
19009 
19010        LDH     (input) integer
19011             Leading dimension of H just as declared in the calling
19012             subroutine.  N .LE. LDH
19013 
19014        ILOZ    (input) INTEGER
19015        IHIZ    (input) INTEGER
19016             Specify the rows of Z to which transformations must be
19017             applied if WANTZ is .TRUE.. 1 .LE. ILOZ .LE. IHIZ .LE. N.
19018 
19019        Z       (input/output) DOUBLE PRECISION array, dimension (LDZ,N)
19020             IF WANTZ is .TRUE., then on output, the orthogonal
19021             similarity transformation mentioned above has been
19022             accumulated into Z(ILOZ:IHIZ,ILO:IHI) from the right.
19023             If WANTZ is .FALSE., then Z is unreferenced.
19024 
19025        LDZ     (input) integer
19026             The leading dimension of Z just as declared in the
19027             calling subroutine.  1 .LE. LDZ.
19028 
19029        NS      (output) integer
19030             The number of unconverged (ie approximate) eigenvalues
19031             returned in SR and SI that may be used as shifts by the
19032             calling subroutine.
19033 
19034        ND      (output) integer
19035             The number of converged eigenvalues uncovered by this
19036             subroutine.
19037 
19038        SR      (output) DOUBLE PRECISION array, dimension (KBOT)
19039        SI      (output) DOUBLE PRECISION array, dimension (KBOT)
19040             On output, the real and imaginary parts of approximate
19041             eigenvalues that may be used for shifts are stored in
19042             SR(KBOT-ND-NS+1) through SR(KBOT-ND) and
19043             SI(KBOT-ND-NS+1) through SI(KBOT-ND), respectively.
19044             The real and imaginary parts of converged eigenvalues
19045             are stored in SR(KBOT-ND+1) through SR(KBOT) and
19046             SI(KBOT-ND+1) through SI(KBOT), respectively.
19047 
19048        V       (workspace) DOUBLE PRECISION array, dimension (LDV,NW)
19049             An NW-by-NW work array.
19050 
19051        LDV     (input) integer scalar
19052             The leading dimension of V just as declared in the
19053             calling subroutine.  NW .LE. LDV
19054 
19055        NH      (input) integer scalar
19056             The number of columns of T.  NH.GE.NW.
19057 
19058        T       (workspace) DOUBLE PRECISION array, dimension (LDT,NW)
19059 
19060        LDT     (input) integer
19061             The leading dimension of T just as declared in the
19062             calling subroutine.  NW .LE. LDT
19063 
19064        NV      (input) integer
19065             The number of rows of work array WV available for
19066             workspace.  NV.GE.NW.
19067 
19068        WV      (workspace) DOUBLE PRECISION array, dimension (LDWV,NW)
19069 
19070        LDWV    (input) integer
19071             The leading dimension of W just as declared in the
19072             calling subroutine.  NW .LE. LDV
19073 
19074        WORK    (workspace) DOUBLE PRECISION array, dimension (LWORK)
19075             On exit, WORK(1) is set to an estimate of the optimal value
19076             of LWORK for the given values of N, NW, KTOP and KBOT.
19077 
19078        LWORK   (input) integer
19079             The dimension of the work array WORK.  LWORK = 2*NW
19080             suffices, but greater efficiency may result from larger
19081             values of LWORK.
19082 
19083             If LWORK = -1, then a workspace query is assumed; DLAQR3
19084             only estimates the optimal workspace size for the given
19085             values of N, NW, KTOP and KBOT.  The estimate is returned
19086             in WORK(1).  No error message related to LWORK is issued
19087             by XERBLA.  Neither H nor Z are accessed.
19088 
19089        ================================================================
19090        Based on contributions by
19091           Karen Braman and Ralph Byers, Department of Mathematics,
19092           University of Kansas, USA
19093 
19094        ================================================================
19095 
19096        ==== Estimate optimal workspace. ====
19097 */
19098 
19099     /* Parameter adjustments */
19100     h_dim1 = *ldh;
19101     h_offset = 1 + h_dim1;
19102     h__ -= h_offset;
19103     z_dim1 = *ldz;
19104     z_offset = 1 + z_dim1;
19105     z__ -= z_offset;
19106     --sr;
19107     --si;
19108     v_dim1 = *ldv;
19109     v_offset = 1 + v_dim1;
19110     v -= v_offset;
19111     t_dim1 = *ldt;
19112     t_offset = 1 + t_dim1;
19113     t -= t_offset;
19114     wv_dim1 = *ldwv;
19115     wv_offset = 1 + wv_dim1;
19116     wv -= wv_offset;
19117     --work;
19118 
19119     /* Function Body */
19120 /* Computing MIN */
19121     i__1 = *nw, i__2 = *kbot - *ktop + 1;
19122     jw = min(i__1,i__2);
19123     if (jw <= 2) {
19124 	lwkopt = 1;
19125     } else {
19126 
19127 /*        ==== Workspace query call to DGEHRD ==== */
19128 
19129 	i__1 = jw - 1;
19130 	dgehrd_(&jw, &c__1, &i__1, &t[t_offset], ldt, &work[1], &work[1], &
19131 		c_n1, &info);
19132 	lwk1 = (integer) work[1];
19133 
19134 /*        ==== Workspace query call to DORMHR ==== */
19135 
19136 	i__1 = jw - 1;
19137 	dormhr_("R", "N", &jw, &jw, &c__1, &i__1, &t[t_offset], ldt, &work[1],
19138 		 &v[v_offset], ldv, &work[1], &c_n1, &info);
19139 	lwk2 = (integer) work[1];
19140 
19141 /*        ==== Workspace query call to DLAQR4 ==== */
19142 
19143 	dlaqr4_(&c_true, &c_true, &jw, &c__1, &jw, &t[t_offset], ldt, &sr[1],
19144 		&si[1], &c__1, &jw, &v[v_offset], ldv, &work[1], &c_n1, &
19145 		infqr);
19146 	lwk3 = (integer) work[1];
19147 
19148 /*
19149           ==== Optimal workspace ====
19150 
19151    Computing MAX
19152 */
19153 	i__1 = jw + max(lwk1,lwk2);
19154 	lwkopt = max(i__1,lwk3);
19155     }
19156 
19157 /*     ==== Quick return in case of workspace query. ==== */
19158 
19159     if (*lwork == -1) {
19160 	work[1] = (doublereal) lwkopt;
19161 	return 0;
19162     }
19163 
19164 /*
19165        ==== Nothing to do ...
19166        ... for an empty active block ... ====
19167 */
19168     *ns = 0;
19169     *nd = 0;
19170     work[1] = 1.;
19171     if (*ktop > *kbot) {
19172 	return 0;
19173     }
19174 /*     ... nor for an empty deflation window. ==== */
19175     if (*nw < 1) {
19176 	return 0;
19177     }
19178 
19179 /*     ==== Machine constants ==== */
19180 
19181     safmin = SAFEMINIMUM;
19182     safmax = 1. / safmin;
19183     dlabad_(&safmin, &safmax);
19184     ulp = PRECISION;
19185     smlnum = safmin * ((doublereal) (*n) / ulp);
19186 
19187 /*
19188        ==== Setup deflation window ====
19189 
19190    Computing MIN
19191 */
19192     i__1 = *nw, i__2 = *kbot - *ktop + 1;
19193     jw = min(i__1,i__2);
19194     kwtop = *kbot - jw + 1;
19195     if (kwtop == *ktop) {
19196 	s = 0.;
19197     } else {
19198 	s = h__[kwtop + (kwtop - 1) * h_dim1];
19199     }
19200 
19201     if (*kbot == kwtop) {
19202 
19203 /*        ==== 1-by-1 deflation window: not much to do ==== */
19204 
19205 	sr[kwtop] = h__[kwtop + kwtop * h_dim1];
19206 	si[kwtop] = 0.;
19207 	*ns = 1;
19208 	*nd = 0;
19209 /* Computing MAX */
19210 	d__2 = smlnum, d__3 = ulp * (d__1 = h__[kwtop + kwtop * h_dim1], abs(
19211 		d__1));
19212 	if (abs(s) <= max(d__2,d__3)) {
19213 	    *ns = 0;
19214 	    *nd = 1;
19215 	    if (kwtop > *ktop) {
19216 		h__[kwtop + (kwtop - 1) * h_dim1] = 0.;
19217 	    }
19218 	}
19219 	work[1] = 1.;
19220 	return 0;
19221     }
19222 
19223 /*
19224        ==== Convert to spike-triangular form.  (In case of a
19225        .    rare QR failure, this routine continues to do
19226        .    aggressive early deflation using that part of
19227        .    the deflation window that converged using INFQR
19228        .    here and there to keep track.) ====
19229 */
19230 
19231     dlacpy_("U", &jw, &jw, &h__[kwtop + kwtop * h_dim1], ldh, &t[t_offset],
19232 	    ldt);
19233     i__1 = jw - 1;
19234     i__2 = *ldh + 1;
19235     i__3 = *ldt + 1;
19236     dcopy_(&i__1, &h__[kwtop + 1 + kwtop * h_dim1], &i__2, &t[t_dim1 + 2], &
19237 	    i__3);
19238 
19239     dlaset_("A", &jw, &jw, &c_b29, &c_b15, &v[v_offset], ldv);
19240     nmin = ilaenv_(&c__12, "DLAQR3", "SV", &jw, &c__1, &jw, lwork, (ftnlen)6,
19241 	    (ftnlen)2);
19242     if (jw > nmin) {
19243 	dlaqr4_(&c_true, &c_true, &jw, &c__1, &jw, &t[t_offset], ldt, &sr[
19244 		kwtop], &si[kwtop], &c__1, &jw, &v[v_offset], ldv, &work[1],
19245 		lwork, &infqr);
19246     } else {
19247 	dlahqr_(&c_true, &c_true, &jw, &c__1, &jw, &t[t_offset], ldt, &sr[
19248 		kwtop], &si[kwtop], &c__1, &jw, &v[v_offset], ldv, &infqr);
19249     }
19250 
19251 /*     ==== DTREXC needs a clean margin near the diagonal ==== */
19252 
19253     i__1 = jw - 3;
19254     for (j = 1; j <= i__1; ++j) {
19255 	t[j + 2 + j * t_dim1] = 0.;
19256 	t[j + 3 + j * t_dim1] = 0.;
19257 /* L10: */
19258     }
19259     if (jw > 2) {
19260 	t[jw + (jw - 2) * t_dim1] = 0.;
19261     }
19262 
19263 /*     ==== Deflation detection loop ==== */
19264 
19265     *ns = jw;
19266     ilst = infqr + 1;
19267 L20:
19268     if (ilst <= *ns) {
19269 	if (*ns == 1) {
19270 	    bulge = FALSE_;
19271 	} else {
19272 	    bulge = t[*ns + (*ns - 1) * t_dim1] != 0.;
19273 	}
19274 
19275 /*        ==== Small spike tip test for deflation ==== */
19276 
19277 	if (! bulge) {
19278 
19279 /*           ==== Real eigenvalue ==== */
19280 
19281 	    foo = (d__1 = t[*ns + *ns * t_dim1], abs(d__1));
19282 	    if (foo == 0.) {
19283 		foo = abs(s);
19284 	    }
19285 /* Computing MAX */
19286 	    d__2 = smlnum, d__3 = ulp * foo;
19287 	    if ((d__1 = s * v[*ns * v_dim1 + 1], abs(d__1)) <= max(d__2,d__3))
19288 		     {
19289 
19290 /*              ==== Deflatable ==== */
19291 
19292 		--(*ns);
19293 	    } else {
19294 
19295 /*
19296                 ==== Undeflatable.   Move it up out of the way.
19297                 .    (DTREXC can not fail in this case.) ====
19298 */
19299 
19300 		ifst = *ns;
19301 		dtrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst,
19302 			 &ilst, &work[1], &info);
19303 		++ilst;
19304 	    }
19305 	} else {
19306 
19307 /*           ==== Complex conjugate pair ==== */
19308 
19309 	    foo = (d__3 = t[*ns + *ns * t_dim1], abs(d__3)) + sqrt((d__1 = t[*
19310 		    ns + (*ns - 1) * t_dim1], abs(d__1))) * sqrt((d__2 = t[*
19311 		    ns - 1 + *ns * t_dim1], abs(d__2)));
19312 	    if (foo == 0.) {
19313 		foo = abs(s);
19314 	    }
19315 /* Computing MAX */
19316 	    d__3 = (d__1 = s * v[*ns * v_dim1 + 1], abs(d__1)), d__4 = (d__2 =
19317 		     s * v[(*ns - 1) * v_dim1 + 1], abs(d__2));
19318 /* Computing MAX */
19319 	    d__5 = smlnum, d__6 = ulp * foo;
19320 	    if (max(d__3,d__4) <= max(d__5,d__6)) {
19321 
19322 /*              ==== Deflatable ==== */
19323 
19324 		*ns += -2;
19325 	    } else {
19326 
19327 /*
19328                 ==== Undeflatable. Move them up out of the way.
19329                 .    Fortunately, DTREXC does the right thing with
19330                 .    ILST in case of a rare exchange failure. ====
19331 */
19332 
19333 		ifst = *ns;
19334 		dtrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst,
19335 			 &ilst, &work[1], &info);
19336 		ilst += 2;
19337 	    }
19338 	}
19339 
19340 /*        ==== End deflation detection loop ==== */
19341 
19342 	goto L20;
19343     }
19344 
19345 /*        ==== Return to Hessenberg form ==== */
19346 
19347     if (*ns == 0) {
19348 	s = 0.;
19349     }
19350 
19351     if (*ns < jw) {
19352 
19353 /*
19354           ==== sorting diagonal blocks of T improves accuracy for
19355           .    graded matrices.  Bubble sort deals well with
19356           .    exchange failures. ====
19357 */
19358 
19359 	sorted = FALSE_;
19360 	i__ = *ns + 1;
19361 L30:
19362 	if (sorted) {
19363 	    goto L50;
19364 	}
19365 	sorted = TRUE_;
19366 
19367 	kend = i__ - 1;
19368 	i__ = infqr + 1;
19369 	if (i__ == *ns) {
19370 	    k = i__ + 1;
19371 	} else if (t[i__ + 1 + i__ * t_dim1] == 0.) {
19372 	    k = i__ + 1;
19373 	} else {
19374 	    k = i__ + 2;
19375 	}
19376 L40:
19377 	if (k <= kend) {
19378 	    if (k == i__ + 1) {
19379 		evi = (d__1 = t[i__ + i__ * t_dim1], abs(d__1));
19380 	    } else {
19381 		evi = (d__3 = t[i__ + i__ * t_dim1], abs(d__3)) + sqrt((d__1 =
19382 			 t[i__ + 1 + i__ * t_dim1], abs(d__1))) * sqrt((d__2 =
19383 			 t[i__ + (i__ + 1) * t_dim1], abs(d__2)));
19384 	    }
19385 
19386 	    if (k == kend) {
19387 		evk = (d__1 = t[k + k * t_dim1], abs(d__1));
19388 	    } else if (t[k + 1 + k * t_dim1] == 0.) {
19389 		evk = (d__1 = t[k + k * t_dim1], abs(d__1));
19390 	    } else {
19391 		evk = (d__3 = t[k + k * t_dim1], abs(d__3)) + sqrt((d__1 = t[
19392 			k + 1 + k * t_dim1], abs(d__1))) * sqrt((d__2 = t[k +
19393 			(k + 1) * t_dim1], abs(d__2)));
19394 	    }
19395 
19396 	    if (evi >= evk) {
19397 		i__ = k;
19398 	    } else {
19399 		sorted = FALSE_;
19400 		ifst = i__;
19401 		ilst = k;
19402 		dtrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst,
19403 			 &ilst, &work[1], &info);
19404 		if (info == 0) {
19405 		    i__ = ilst;
19406 		} else {
19407 		    i__ = k;
19408 		}
19409 	    }
19410 	    if (i__ == kend) {
19411 		k = i__ + 1;
19412 	    } else if (t[i__ + 1 + i__ * t_dim1] == 0.) {
19413 		k = i__ + 1;
19414 	    } else {
19415 		k = i__ + 2;
19416 	    }
19417 	    goto L40;
19418 	}
19419 	goto L30;
19420 L50:
19421 	;
19422     }
19423 
19424 /*     ==== Restore shift/eigenvalue array from T ==== */
19425 
19426     i__ = jw;
19427 L60:
19428     if (i__ >= infqr + 1) {
19429 	if (i__ == infqr + 1) {
19430 	    sr[kwtop + i__ - 1] = t[i__ + i__ * t_dim1];
19431 	    si[kwtop + i__ - 1] = 0.;
19432 	    --i__;
19433 	} else if (t[i__ + (i__ - 1) * t_dim1] == 0.) {
19434 	    sr[kwtop + i__ - 1] = t[i__ + i__ * t_dim1];
19435 	    si[kwtop + i__ - 1] = 0.;
19436 	    --i__;
19437 	} else {
19438 	    aa = t[i__ - 1 + (i__ - 1) * t_dim1];
19439 	    cc = t[i__ + (i__ - 1) * t_dim1];
19440 	    bb = t[i__ - 1 + i__ * t_dim1];
19441 	    dd = t[i__ + i__ * t_dim1];
19442 	    dlanv2_(&aa, &bb, &cc, &dd, &sr[kwtop + i__ - 2], &si[kwtop + i__
19443 		    - 2], &sr[kwtop + i__ - 1], &si[kwtop + i__ - 1], &cs, &
19444 		    sn);
19445 	    i__ += -2;
19446 	}
19447 	goto L60;
19448     }
19449 
19450     if (*ns < jw || s == 0.) {
19451 	if (*ns > 1 && s != 0.) {
19452 
19453 /*           ==== Reflect spike back into lower triangle ==== */
19454 
19455 	    dcopy_(ns, &v[v_offset], ldv, &work[1], &c__1);
19456 	    beta = work[1];
19457 	    dlarfg_(ns, &beta, &work[2], &c__1, &tau);
19458 	    work[1] = 1.;
19459 
19460 	    i__1 = jw - 2;
19461 	    i__2 = jw - 2;
19462 	    dlaset_("L", &i__1, &i__2, &c_b29, &c_b29, &t[t_dim1 + 3], ldt);
19463 
19464 	    dlarf_("L", ns, &jw, &work[1], &c__1, &tau, &t[t_offset], ldt, &
19465 		    work[jw + 1]);
19466 	    dlarf_("R", ns, ns, &work[1], &c__1, &tau, &t[t_offset], ldt, &
19467 		    work[jw + 1]);
19468 	    dlarf_("R", &jw, ns, &work[1], &c__1, &tau, &v[v_offset], ldv, &
19469 		    work[jw + 1]);
19470 
19471 	    i__1 = *lwork - jw;
19472 	    dgehrd_(&jw, &c__1, ns, &t[t_offset], ldt, &work[1], &work[jw + 1]
19473 		    , &i__1, &info);
19474 	}
19475 
19476 /*        ==== Copy updated reduced window into place ==== */
19477 
19478 	if (kwtop > 1) {
19479 	    h__[kwtop + (kwtop - 1) * h_dim1] = s * v[v_dim1 + 1];
19480 	}
19481 	dlacpy_("U", &jw, &jw, &t[t_offset], ldt, &h__[kwtop + kwtop * h_dim1]
19482 		, ldh);
19483 	i__1 = jw - 1;
19484 	i__2 = *ldt + 1;
19485 	i__3 = *ldh + 1;
19486 	dcopy_(&i__1, &t[t_dim1 + 2], &i__2, &h__[kwtop + 1 + kwtop * h_dim1],
19487 		 &i__3);
19488 
19489 /*
19490           ==== Accumulate orthogonal matrix in order update
19491           .    H and Z, if requested.  ====
19492 */
19493 
19494 	if (*ns > 1 && s != 0.) {
19495 	    i__1 = *lwork - jw;
19496 	    dormhr_("R", "N", &jw, ns, &c__1, ns, &t[t_offset], ldt, &work[1],
19497 		     &v[v_offset], ldv, &work[jw + 1], &i__1, &info);
19498 	}
19499 
19500 /*        ==== Update vertical slab in H ==== */
19501 
19502 	if (*wantt) {
19503 	    ltop = 1;
19504 	} else {
19505 	    ltop = *ktop;
19506 	}
19507 	i__1 = kwtop - 1;
19508 	i__2 = *nv;
19509 	for (krow = ltop; i__2 < 0 ? krow >= i__1 : krow <= i__1; krow +=
19510 		i__2) {
19511 /* Computing MIN */
19512 	    i__3 = *nv, i__4 = kwtop - krow;
19513 	    kln = min(i__3,i__4);
19514 	    dgemm_("N", "N", &kln, &jw, &jw, &c_b15, &h__[krow + kwtop *
19515 		    h_dim1], ldh, &v[v_offset], ldv, &c_b29, &wv[wv_offset],
19516 		    ldwv);
19517 	    dlacpy_("A", &kln, &jw, &wv[wv_offset], ldwv, &h__[krow + kwtop *
19518 		    h_dim1], ldh);
19519 /* L70: */
19520 	}
19521 
19522 /*        ==== Update horizontal slab in H ==== */
19523 
19524 	if (*wantt) {
19525 	    i__2 = *n;
19526 	    i__1 = *nh;
19527 	    for (kcol = *kbot + 1; i__1 < 0 ? kcol >= i__2 : kcol <= i__2;
19528 		    kcol += i__1) {
19529 /* Computing MIN */
19530 		i__3 = *nh, i__4 = *n - kcol + 1;
19531 		kln = min(i__3,i__4);
19532 		dgemm_("C", "N", &jw, &kln, &jw, &c_b15, &v[v_offset], ldv, &
19533 			h__[kwtop + kcol * h_dim1], ldh, &c_b29, &t[t_offset],
19534 			 ldt);
19535 		dlacpy_("A", &jw, &kln, &t[t_offset], ldt, &h__[kwtop + kcol *
19536 			 h_dim1], ldh);
19537 /* L80: */
19538 	    }
19539 	}
19540 
19541 /*        ==== Update vertical slab in Z ==== */
19542 
19543 	if (*wantz) {
19544 	    i__1 = *ihiz;
19545 	    i__2 = *nv;
19546 	    for (krow = *iloz; i__2 < 0 ? krow >= i__1 : krow <= i__1; krow +=
19547 		     i__2) {
19548 /* Computing MIN */
19549 		i__3 = *nv, i__4 = *ihiz - krow + 1;
19550 		kln = min(i__3,i__4);
19551 		dgemm_("N", "N", &kln, &jw, &jw, &c_b15, &z__[krow + kwtop *
19552 			z_dim1], ldz, &v[v_offset], ldv, &c_b29, &wv[
19553 			wv_offset], ldwv);
19554 		dlacpy_("A", &kln, &jw, &wv[wv_offset], ldwv, &z__[krow +
19555 			kwtop * z_dim1], ldz);
19556 /* L90: */
19557 	    }
19558 	}
19559     }
19560 
19561 /*     ==== Return the number of deflations ... ==== */
19562 
19563     *nd = jw - *ns;
19564 
19565 /*
19566        ==== ... and the number of shifts. (Subtracting
19567        .    INFQR from the spike length takes care
19568        .    of the case of a rare QR failure while
19569        .    calculating eigenvalues of the deflation
19570        .    window.)  ====
19571 */
19572 
19573     *ns -= infqr;
19574 
19575 /*      ==== Return optimal workspace. ==== */
19576 
19577     work[1] = (doublereal) lwkopt;
19578 
19579 /*     ==== End of DLAQR3 ==== */
19580 
19581     return 0;
19582 } /* dlaqr3_ */
19583 
dlaqr4_(logical * wantt,logical * wantz,integer * n,integer * ilo,integer * ihi,doublereal * h__,integer * ldh,doublereal * wr,doublereal * wi,integer * iloz,integer * ihiz,doublereal * z__,integer * ldz,doublereal * work,integer * lwork,integer * info)19584 /* Subroutine */ int dlaqr4_(logical *wantt, logical *wantz, integer *n,
19585 	integer *ilo, integer *ihi, doublereal *h__, integer *ldh, doublereal
19586 	*wr, doublereal *wi, integer *iloz, integer *ihiz, doublereal *z__,
19587 	integer *ldz, doublereal *work, integer *lwork, integer *info)
19588 {
19589     /* System generated locals */
19590     integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
19591     doublereal d__1, d__2, d__3, d__4;
19592 
19593     /* Local variables */
19594     static integer i__, k;
19595     static doublereal aa, bb, cc, dd;
19596     static integer ld;
19597     static doublereal cs;
19598     static integer nh, it, ks, kt;
19599     static doublereal sn;
19600     static integer ku, kv, ls, ns;
19601     static doublereal ss;
19602     static integer nw, inf, kdu, nho, nve, kwh, nsr, nwr, kwv, ndec, ndfl,
19603 	    kbot, nmin;
19604     static doublereal swap;
19605     static integer ktop;
19606     static doublereal zdum[1]	/* was [1][1] */;
19607     static integer kacc22, itmax, nsmax, nwmax, kwtop;
19608     extern /* Subroutine */ int dlaqr2_(logical *, logical *, integer *,
19609 	    integer *, integer *, integer *, doublereal *, integer *, integer
19610 	    *, integer *, doublereal *, integer *, integer *, integer *,
19611 	    doublereal *, doublereal *, doublereal *, integer *, integer *,
19612 	    doublereal *, integer *, integer *, doublereal *, integer *,
19613 	    doublereal *, integer *), dlanv2_(doublereal *, doublereal *,
19614 	    doublereal *, doublereal *, doublereal *, doublereal *,
19615 	    doublereal *, doublereal *, doublereal *, doublereal *), dlaqr5_(
19616 	    logical *, logical *, integer *, integer *, integer *, integer *,
19617 	    integer *, doublereal *, doublereal *, doublereal *, integer *,
19618 	    integer *, integer *, doublereal *, integer *, doublereal *,
19619 	    integer *, doublereal *, integer *, integer *, doublereal *,
19620 	    integer *, integer *, doublereal *, integer *);
19621     static integer nibble;
19622     extern /* Subroutine */ int dlahqr_(logical *, logical *, integer *,
19623 	    integer *, integer *, doublereal *, integer *, doublereal *,
19624 	    doublereal *, integer *, integer *, doublereal *, integer *,
19625 	    integer *), dlacpy_(char *, integer *, integer *, doublereal *,
19626 	    integer *, doublereal *, integer *);
19627     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
19628 	    integer *, integer *, ftnlen, ftnlen);
19629     static char jbcmpz[2];
19630     static integer nwupbd;
19631     static logical sorted;
19632     static integer lwkopt;
19633 
19634 
19635 /*
19636     -- LAPACK auxiliary routine (version 3.2) --
19637        Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
19638        November 2006
19639 
19640 
19641        This subroutine implements one level of recursion for DLAQR0.
19642        It is a complete implementation of the small bulge multi-shift
19643        QR algorithm.  It may be called by DLAQR0 and, for large enough
19644        deflation window size, it may be called by DLAQR3.  This
19645        subroutine is identical to DLAQR0 except that it calls DLAQR2
19646        instead of DLAQR3.
19647 
19648        Purpose
19649        =======
19650 
19651        DLAQR4 computes the eigenvalues of a Hessenberg matrix H
19652        and, optionally, the matrices T and Z from the Schur decomposition
19653        H = Z T Z**T, where T is an upper quasi-triangular matrix (the
19654        Schur form), and Z is the orthogonal matrix of Schur vectors.
19655 
19656        Optionally Z may be postmultiplied into an input orthogonal
19657        matrix Q so that this routine can give the Schur factorization
19658        of a matrix A which has been reduced to the Hessenberg form H
19659        by the orthogonal matrix Q:  A = Q*H*Q**T = (QZ)*T*(QZ)**T.
19660 
19661        Arguments
19662        =========
19663 
19664        WANTT   (input) LOGICAL
19665             = .TRUE. : the full Schur form T is required;
19666             = .FALSE.: only eigenvalues are required.
19667 
19668        WANTZ   (input) LOGICAL
19669             = .TRUE. : the matrix of Schur vectors Z is required;
19670             = .FALSE.: Schur vectors are not required.
19671 
19672        N     (input) INTEGER
19673              The order of the matrix H.  N .GE. 0.
19674 
19675        ILO   (input) INTEGER
19676        IHI   (input) INTEGER
19677              It is assumed that H is already upper triangular in rows
19678              and columns 1:ILO-1 and IHI+1:N and, if ILO.GT.1,
19679              H(ILO,ILO-1) is zero. ILO and IHI are normally set by a
19680              previous call to DGEBAL, and then passed to DGEHRD when the
19681              matrix output by DGEBAL is reduced to Hessenberg form.
19682              Otherwise, ILO and IHI should be set to 1 and N,
19683              respectively.  If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N.
19684              If N = 0, then ILO = 1 and IHI = 0.
19685 
19686        H     (input/output) DOUBLE PRECISION array, dimension (LDH,N)
19687              On entry, the upper Hessenberg matrix H.
19688              On exit, if INFO = 0 and WANTT is .TRUE., then H contains
19689              the upper quasi-triangular matrix T from the Schur
19690              decomposition (the Schur form); 2-by-2 diagonal blocks
19691              (corresponding to complex conjugate pairs of eigenvalues)
19692              are returned in standard form, with H(i,i) = H(i+1,i+1)
19693              and H(i+1,i)*H(i,i+1).LT.0. If INFO = 0 and WANTT is
19694              .FALSE., then the contents of H are unspecified on exit.
19695              (The output value of H when INFO.GT.0 is given under the
19696              description of INFO below.)
19697 
19698              This subroutine may explicitly set H(i,j) = 0 for i.GT.j and
19699              j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N.
19700 
19701        LDH   (input) INTEGER
19702              The leading dimension of the array H. LDH .GE. max(1,N).
19703 
19704        WR    (output) DOUBLE PRECISION array, dimension (IHI)
19705        WI    (output) DOUBLE PRECISION array, dimension (IHI)
19706              The real and imaginary parts, respectively, of the computed
19707              eigenvalues of H(ILO:IHI,ILO:IHI) are stored in WR(ILO:IHI)
19708              and WI(ILO:IHI). If two eigenvalues are computed as a
19709              complex conjugate pair, they are stored in consecutive
19710              elements of WR and WI, say the i-th and (i+1)th, with
19711              WI(i) .GT. 0 and WI(i+1) .LT. 0. If WANTT is .TRUE., then
19712              the eigenvalues are stored in the same order as on the
19713              diagonal of the Schur form returned in H, with
19714              WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2 diagonal
19715              block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and
19716              WI(i+1) = -WI(i).
19717 
19718        ILOZ     (input) INTEGER
19719        IHIZ     (input) INTEGER
19720              Specify the rows of Z to which transformations must be
19721              applied if WANTZ is .TRUE..
19722              1 .LE. ILOZ .LE. ILO; IHI .LE. IHIZ .LE. N.
19723 
19724        Z     (input/output) DOUBLE PRECISION array, dimension (LDZ,IHI)
19725              If WANTZ is .FALSE., then Z is not referenced.
19726              If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is
19727              replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the
19728              orthogonal Schur factor of H(ILO:IHI,ILO:IHI).
19729              (The output value of Z when INFO.GT.0 is given under
19730              the description of INFO below.)
19731 
19732        LDZ   (input) INTEGER
19733              The leading dimension of the array Z.  if WANTZ is .TRUE.
19734              then LDZ.GE.MAX(1,IHIZ).  Otherwize, LDZ.GE.1.
19735 
19736        WORK  (workspace/output) DOUBLE PRECISION array, dimension LWORK
19737              On exit, if LWORK = -1, WORK(1) returns an estimate of
19738              the optimal value for LWORK.
19739 
19740        LWORK (input) INTEGER
19741              The dimension of the array WORK.  LWORK .GE. max(1,N)
19742              is sufficient, but LWORK typically as large as 6*N may
19743              be required for optimal performance.  A workspace query
19744              to determine the optimal workspace size is recommended.
19745 
19746              If LWORK = -1, then DLAQR4 does a workspace query.
19747              In this case, DLAQR4 checks the input parameters and
19748              estimates the optimal workspace size for the given
19749              values of N, ILO and IHI.  The estimate is returned
19750              in WORK(1).  No error message related to LWORK is
19751              issued by XERBLA.  Neither H nor Z are accessed.
19752 
19753 
19754        INFO  (output) INTEGER
19755                =  0:  successful exit
19756              .GT. 0:  if INFO = i, DLAQR4 failed to compute all of
19757                   the eigenvalues.  Elements 1:ilo-1 and i+1:n of WR
19758                   and WI contain those eigenvalues which have been
19759                   successfully computed.  (Failures are rare.)
19760 
19761                   If INFO .GT. 0 and WANT is .FALSE., then on exit,
19762                   the remaining unconverged eigenvalues are the eigen-
19763                   values of the upper Hessenberg matrix rows and
19764                   columns ILO through INFO of the final, output
19765                   value of H.
19766 
19767                   If INFO .GT. 0 and WANTT is .TRUE., then on exit
19768 
19769              (*)  (initial value of H)*U  = U*(final value of H)
19770 
19771                   where U is an orthogonal matrix.  The final
19772                   value of H is upper Hessenberg and quasi-triangular
19773                   in rows and columns INFO+1 through IHI.
19774 
19775                   If INFO .GT. 0 and WANTZ is .TRUE., then on exit
19776 
19777                     (final value of Z(ILO:IHI,ILOZ:IHIZ)
19778                      =  (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U
19779 
19780                   where U is the orthogonal matrix in (*) (regard-
19781                   less of the value of WANTT.)
19782 
19783                   If INFO .GT. 0 and WANTZ is .FALSE., then Z is not
19784                   accessed.
19785 
19786        ================================================================
19787        Based on contributions by
19788           Karen Braman and Ralph Byers, Department of Mathematics,
19789           University of Kansas, USA
19790 
19791        ================================================================
19792        References:
19793          K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
19794          Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
19795          Performance, SIAM Journal of Matrix Analysis, volume 23, pages
19796          929--947, 2002.
19797 
19798          K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
19799          Algorithm Part II: Aggressive Early Deflation, SIAM Journal
19800          of Matrix Analysis, volume 23, pages 948--973, 2002.
19801 
19802        ================================================================
19803 
19804        ==== Matrices of order NTINY or smaller must be processed by
19805        .    DLAHQR because of insufficient subdiagonal scratch space.
19806        .    (This is a hard limit.) ====
19807 
19808        ==== Exceptional deflation windows:  try to cure rare
19809        .    slow convergence by varying the size of the
19810        .    deflation window after KEXNW iterations. ====
19811 
19812        ==== Exceptional shifts: try to cure rare slow convergence
19813        .    with ad-hoc exceptional shifts every KEXSH iterations.
19814        .    ====
19815 
19816        ==== The constants WILK1 and WILK2 are used to form the
19817        .    exceptional shifts. ====
19818 */
19819     /* Parameter adjustments */
19820     h_dim1 = *ldh;
19821     h_offset = 1 + h_dim1;
19822     h__ -= h_offset;
19823     --wr;
19824     --wi;
19825     z_dim1 = *ldz;
19826     z_offset = 1 + z_dim1;
19827     z__ -= z_offset;
19828     --work;
19829 
19830     /* Function Body */
19831     *info = 0;
19832 
19833 /*     ==== Quick return for N = 0: nothing to do. ==== */
19834 
19835     if (*n == 0) {
19836 	work[1] = 1.;
19837 	return 0;
19838     }
19839 
19840     if (*n <= 11) {
19841 
19842 /*        ==== Tiny matrices must use DLAHQR. ==== */
19843 
19844 	lwkopt = 1;
19845 	if (*lwork != -1) {
19846 	    dlahqr_(wantt, wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1], &
19847 		    wi[1], iloz, ihiz, &z__[z_offset], ldz, info);
19848 	}
19849     } else {
19850 
19851 /*
19852           ==== Use small bulge multi-shift QR with aggressive early
19853           .    deflation on larger-than-tiny matrices. ====
19854 
19855           ==== Hope for the best. ====
19856 */
19857 
19858 	*info = 0;
19859 
19860 /*        ==== Set up job flags for ILAENV. ==== */
19861 
19862 	if (*wantt) {
19863 	    *(unsigned char *)jbcmpz = 'S';
19864 	} else {
19865 	    *(unsigned char *)jbcmpz = 'E';
19866 	}
19867 	if (*wantz) {
19868 	    *(unsigned char *)&jbcmpz[1] = 'V';
19869 	} else {
19870 	    *(unsigned char *)&jbcmpz[1] = 'N';
19871 	}
19872 
19873 /*
19874           ==== NWR = recommended deflation window size.  At this
19875           .    point,  N .GT. NTINY = 11, so there is enough
19876           .    subdiagonal workspace for NWR.GE.2 as required.
19877           .    (In fact, there is enough subdiagonal space for
19878           .    NWR.GE.3.) ====
19879 */
19880 
19881 	nwr = ilaenv_(&c__13, "DLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
19882 		 (ftnlen)2);
19883 	nwr = max(2,nwr);
19884 /* Computing MIN */
19885 	i__1 = *ihi - *ilo + 1, i__2 = (*n - 1) / 3, i__1 = min(i__1,i__2);
19886 	nwr = min(i__1,nwr);
19887 
19888 /*
19889           ==== NSR = recommended number of simultaneous shifts.
19890           .    At this point N .GT. NTINY = 11, so there is at
19891           .    enough subdiagonal workspace for NSR to be even
19892           .    and greater than or equal to two as required. ====
19893 */
19894 
19895 	nsr = ilaenv_(&c__15, "DLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
19896 		 (ftnlen)2);
19897 /* Computing MIN */
19898 	i__1 = nsr, i__2 = (*n + 6) / 9, i__1 = min(i__1,i__2), i__2 = *ihi -
19899 		*ilo;
19900 	nsr = min(i__1,i__2);
19901 /* Computing MAX */
19902 	i__1 = 2, i__2 = nsr - nsr % 2;
19903 	nsr = max(i__1,i__2);
19904 
19905 /*
19906           ==== Estimate optimal workspace ====
19907 
19908           ==== Workspace query call to DLAQR2 ====
19909 */
19910 
19911 	i__1 = nwr + 1;
19912 	dlaqr2_(wantt, wantz, n, ilo, ihi, &i__1, &h__[h_offset], ldh, iloz,
19913 		ihiz, &z__[z_offset], ldz, &ls, &ld, &wr[1], &wi[1], &h__[
19914 		h_offset], ldh, n, &h__[h_offset], ldh, n, &h__[h_offset],
19915 		ldh, &work[1], &c_n1);
19916 
19917 /*
19918           ==== Optimal workspace = MAX(DLAQR5, DLAQR2) ====
19919 
19920    Computing MAX
19921 */
19922 	i__1 = nsr * 3 / 2, i__2 = (integer) work[1];
19923 	lwkopt = max(i__1,i__2);
19924 
19925 /*        ==== Quick return in case of workspace query. ==== */
19926 
19927 	if (*lwork == -1) {
19928 	    work[1] = (doublereal) lwkopt;
19929 	    return 0;
19930 	}
19931 
19932 /*        ==== DLAHQR/DLAQR0 crossover point ==== */
19933 
19934 	nmin = ilaenv_(&c__12, "DLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)
19935 		6, (ftnlen)2);
19936 	nmin = max(11,nmin);
19937 
19938 /*        ==== Nibble crossover point ==== */
19939 
19940 	nibble = ilaenv_(&c__14, "DLAQR4", jbcmpz, n, ilo, ihi, lwork, (
19941 		ftnlen)6, (ftnlen)2);
19942 	nibble = max(0,nibble);
19943 
19944 /*
19945           ==== Accumulate reflections during ttswp?  Use block
19946           .    2-by-2 structure during matrix-matrix multiply? ====
19947 */
19948 
19949 	kacc22 = ilaenv_(&c__16, "DLAQR4", jbcmpz, n, ilo, ihi, lwork, (
19950 		ftnlen)6, (ftnlen)2);
19951 	kacc22 = max(0,kacc22);
19952 	kacc22 = min(2,kacc22);
19953 
19954 /*
19955           ==== NWMAX = the largest possible deflation window for
19956           .    which there is sufficient workspace. ====
19957 
19958    Computing MIN
19959 */
19960 	i__1 = (*n - 1) / 3, i__2 = *lwork / 2;
19961 	nwmax = min(i__1,i__2);
19962 	nw = nwmax;
19963 
19964 /*
19965           ==== NSMAX = the Largest number of simultaneous shifts
19966           .    for which there is sufficient workspace. ====
19967 
19968    Computing MIN
19969 */
19970 	i__1 = (*n + 6) / 9, i__2 = (*lwork << 1) / 3;
19971 	nsmax = min(i__1,i__2);
19972 	nsmax -= nsmax % 2;
19973 
19974 /*        ==== NDFL: an iteration count restarted at deflation. ==== */
19975 
19976 	ndfl = 1;
19977 
19978 /*
19979           ==== ITMAX = iteration limit ====
19980 
19981    Computing MAX
19982 */
19983 	i__1 = 10, i__2 = *ihi - *ilo + 1;
19984 	itmax = max(i__1,i__2) * 30;
19985 
19986 /*        ==== Last row and column in the active block ==== */
19987 
19988 	kbot = *ihi;
19989 
19990 /*        ==== Main Loop ==== */
19991 
19992 	i__1 = itmax;
19993 	for (it = 1; it <= i__1; ++it) {
19994 
19995 /*           ==== Done when KBOT falls below ILO ==== */
19996 
19997 	    if (kbot < *ilo) {
19998 		goto L90;
19999 	    }
20000 
20001 /*           ==== Locate active block ==== */
20002 
20003 	    i__2 = *ilo + 1;
20004 	    for (k = kbot; k >= i__2; --k) {
20005 		if (h__[k + (k - 1) * h_dim1] == 0.) {
20006 		    goto L20;
20007 		}
20008 /* L10: */
20009 	    }
20010 	    k = *ilo;
20011 L20:
20012 	    ktop = k;
20013 
20014 /*
20015              ==== Select deflation window size:
20016              .    Typical Case:
20017              .      If possible and advisable, nibble the entire
20018              .      active block.  If not, use size MIN(NWR,NWMAX)
20019              .      or MIN(NWR+1,NWMAX) depending upon which has
20020              .      the smaller corresponding subdiagonal entry
20021              .      (a heuristic).
20022              .
20023              .    Exceptional Case:
20024              .      If there have been no deflations in KEXNW or
20025              .      more iterations, then vary the deflation window
20026              .      size.   At first, because, larger windows are,
20027              .      in general, more powerful than smaller ones,
20028              .      rapidly increase the window to the maximum possible.
20029              .      Then, gradually reduce the window size. ====
20030 */
20031 
20032 	    nh = kbot - ktop + 1;
20033 	    nwupbd = min(nh,nwmax);
20034 	    if (ndfl < 5) {
20035 		nw = min(nwupbd,nwr);
20036 	    } else {
20037 /* Computing MIN */
20038 		i__2 = nwupbd, i__3 = nw << 1;
20039 		nw = min(i__2,i__3);
20040 	    }
20041 	    if (nw < nwmax) {
20042 		if (nw >= nh - 1) {
20043 		    nw = nh;
20044 		} else {
20045 		    kwtop = kbot - nw + 1;
20046 		    if ((d__1 = h__[kwtop + (kwtop - 1) * h_dim1], abs(d__1))
20047 			    > (d__2 = h__[kwtop - 1 + (kwtop - 2) * h_dim1],
20048 			    abs(d__2))) {
20049 			++nw;
20050 		    }
20051 		}
20052 	    }
20053 	    if (ndfl < 5) {
20054 		ndec = -1;
20055 	    } else if (ndec >= 0 || nw >= nwupbd) {
20056 		++ndec;
20057 		if (nw - ndec < 2) {
20058 		    ndec = 0;
20059 		}
20060 		nw -= ndec;
20061 	    }
20062 
20063 /*
20064              ==== Aggressive early deflation:
20065              .    split workspace under the subdiagonal into
20066              .      - an nw-by-nw work array V in the lower
20067              .        left-hand-corner,
20068              .      - an NW-by-at-least-NW-but-more-is-better
20069              .        (NW-by-NHO) horizontal work array along
20070              .        the bottom edge,
20071              .      - an at-least-NW-but-more-is-better (NHV-by-NW)
20072              .        vertical work array along the left-hand-edge.
20073              .        ====
20074 */
20075 
20076 	    kv = *n - nw + 1;
20077 	    kt = nw + 1;
20078 	    nho = *n - nw - 1 - kt + 1;
20079 	    kwv = nw + 2;
20080 	    nve = *n - nw - kwv + 1;
20081 
20082 /*           ==== Aggressive early deflation ==== */
20083 
20084 	    dlaqr2_(wantt, wantz, n, &ktop, &kbot, &nw, &h__[h_offset], ldh,
20085 		    iloz, ihiz, &z__[z_offset], ldz, &ls, &ld, &wr[1], &wi[1],
20086 		     &h__[kv + h_dim1], ldh, &nho, &h__[kv + kt * h_dim1],
20087 		    ldh, &nve, &h__[kwv + h_dim1], ldh, &work[1], lwork);
20088 
20089 /*           ==== Adjust KBOT accounting for new deflations. ==== */
20090 
20091 	    kbot -= ld;
20092 
20093 /*           ==== KS points to the shifts. ==== */
20094 
20095 	    ks = kbot - ls + 1;
20096 
20097 /*
20098              ==== Skip an expensive QR sweep if there is a (partly
20099              .    heuristic) reason to expect that many eigenvalues
20100              .    will deflate without it.  Here, the QR sweep is
20101              .    skipped if many eigenvalues have just been deflated
20102              .    or if the remaining active block is small.
20103 */
20104 
20105 	    if (ld == 0 || ld * 100 <= nw * nibble && kbot - ktop + 1 > min(
20106 		    nmin,nwmax)) {
20107 
20108 /*
20109                 ==== NS = nominal number of simultaneous shifts.
20110                 .    This may be lowered (slightly) if DLAQR2
20111                 .    did not provide that many shifts. ====
20112 
20113    Computing MIN
20114    Computing MAX
20115 */
20116 		i__4 = 2, i__5 = kbot - ktop;
20117 		i__2 = min(nsmax,nsr), i__3 = max(i__4,i__5);
20118 		ns = min(i__2,i__3);
20119 		ns -= ns % 2;
20120 
20121 /*
20122                 ==== If there have been no deflations
20123                 .    in a multiple of KEXSH iterations,
20124                 .    then try exceptional shifts.
20125                 .    Otherwise use shifts provided by
20126                 .    DLAQR2 above or from the eigenvalues
20127                 .    of a trailing principal submatrix. ====
20128 */
20129 
20130 		if (ndfl % 6 == 0) {
20131 		    ks = kbot - ns + 1;
20132 /* Computing MAX */
20133 		    i__3 = ks + 1, i__4 = ktop + 2;
20134 		    i__2 = max(i__3,i__4);
20135 		    for (i__ = kbot; i__ >= i__2; i__ += -2) {
20136 			ss = (d__1 = h__[i__ + (i__ - 1) * h_dim1], abs(d__1))
20137 				 + (d__2 = h__[i__ - 1 + (i__ - 2) * h_dim1],
20138 				abs(d__2));
20139 			aa = ss * .75 + h__[i__ + i__ * h_dim1];
20140 			bb = ss;
20141 			cc = ss * -.4375;
20142 			dd = aa;
20143 			dlanv2_(&aa, &bb, &cc, &dd, &wr[i__ - 1], &wi[i__ - 1]
20144 				, &wr[i__], &wi[i__], &cs, &sn);
20145 /* L30: */
20146 		    }
20147 		    if (ks == ktop) {
20148 			wr[ks + 1] = h__[ks + 1 + (ks + 1) * h_dim1];
20149 			wi[ks + 1] = 0.;
20150 			wr[ks] = wr[ks + 1];
20151 			wi[ks] = wi[ks + 1];
20152 		    }
20153 		} else {
20154 
20155 /*
20156                    ==== Got NS/2 or fewer shifts? Use DLAHQR
20157                    .    on a trailing principal submatrix to
20158                    .    get more. (Since NS.LE.NSMAX.LE.(N+6)/9,
20159                    .    there is enough space below the subdiagonal
20160                    .    to fit an NS-by-NS scratch array.) ====
20161 */
20162 
20163 		    if (kbot - ks + 1 <= ns / 2) {
20164 			ks = kbot - ns + 1;
20165 			kt = *n - ns + 1;
20166 			dlacpy_("A", &ns, &ns, &h__[ks + ks * h_dim1], ldh, &
20167 				h__[kt + h_dim1], ldh);
20168 			dlahqr_(&c_false, &c_false, &ns, &c__1, &ns, &h__[kt
20169 				+ h_dim1], ldh, &wr[ks], &wi[ks], &c__1, &
20170 				c__1, zdum, &c__1, &inf);
20171 			ks += inf;
20172 
20173 /*
20174                       ==== In case of a rare QR failure use
20175                       .    eigenvalues of the trailing 2-by-2
20176                       .    principal submatrix.  ====
20177 */
20178 
20179 			if (ks >= kbot) {
20180 			    aa = h__[kbot - 1 + (kbot - 1) * h_dim1];
20181 			    cc = h__[kbot + (kbot - 1) * h_dim1];
20182 			    bb = h__[kbot - 1 + kbot * h_dim1];
20183 			    dd = h__[kbot + kbot * h_dim1];
20184 			    dlanv2_(&aa, &bb, &cc, &dd, &wr[kbot - 1], &wi[
20185 				    kbot - 1], &wr[kbot], &wi[kbot], &cs, &sn)
20186 				    ;
20187 			    ks = kbot - 1;
20188 			}
20189 		    }
20190 
20191 		    if (kbot - ks + 1 > ns) {
20192 
20193 /*
20194                       ==== Sort the shifts (Helps a little)
20195                       .    Bubble sort keeps complex conjugate
20196                       .    pairs together. ====
20197 */
20198 
20199 			sorted = FALSE_;
20200 			i__2 = ks + 1;
20201 			for (k = kbot; k >= i__2; --k) {
20202 			    if (sorted) {
20203 				goto L60;
20204 			    }
20205 			    sorted = TRUE_;
20206 			    i__3 = k - 1;
20207 			    for (i__ = ks; i__ <= i__3; ++i__) {
20208 				if ((d__1 = wr[i__], abs(d__1)) + (d__2 = wi[
20209 					i__], abs(d__2)) < (d__3 = wr[i__ + 1]
20210 					, abs(d__3)) + (d__4 = wi[i__ + 1],
20211 					abs(d__4))) {
20212 				    sorted = FALSE_;
20213 
20214 				    swap = wr[i__];
20215 				    wr[i__] = wr[i__ + 1];
20216 				    wr[i__ + 1] = swap;
20217 
20218 				    swap = wi[i__];
20219 				    wi[i__] = wi[i__ + 1];
20220 				    wi[i__ + 1] = swap;
20221 				}
20222 /* L40: */
20223 			    }
20224 /* L50: */
20225 			}
20226 L60:
20227 			;
20228 		    }
20229 
20230 /*
20231                    ==== Shuffle shifts into pairs of real shifts
20232                    .    and pairs of complex conjugate shifts
20233                    .    assuming complex conjugate shifts are
20234                    .    already adjacent to one another. (Yes,
20235                    .    they are.)  ====
20236 */
20237 
20238 		    i__2 = ks + 2;
20239 		    for (i__ = kbot; i__ >= i__2; i__ += -2) {
20240 			if (wi[i__] != -wi[i__ - 1]) {
20241 
20242 			    swap = wr[i__];
20243 			    wr[i__] = wr[i__ - 1];
20244 			    wr[i__ - 1] = wr[i__ - 2];
20245 			    wr[i__ - 2] = swap;
20246 
20247 			    swap = wi[i__];
20248 			    wi[i__] = wi[i__ - 1];
20249 			    wi[i__ - 1] = wi[i__ - 2];
20250 			    wi[i__ - 2] = swap;
20251 			}
20252 /* L70: */
20253 		    }
20254 		}
20255 
20256 /*
20257                 ==== If there are only two shifts and both are
20258                 .    real, then use only one.  ====
20259 */
20260 
20261 		if (kbot - ks + 1 == 2) {
20262 		    if (wi[kbot] == 0.) {
20263 			if ((d__1 = wr[kbot] - h__[kbot + kbot * h_dim1], abs(
20264 				d__1)) < (d__2 = wr[kbot - 1] - h__[kbot +
20265 				kbot * h_dim1], abs(d__2))) {
20266 			    wr[kbot - 1] = wr[kbot];
20267 			} else {
20268 			    wr[kbot] = wr[kbot - 1];
20269 			}
20270 		    }
20271 		}
20272 
20273 /*
20274                 ==== Use up to NS of the the smallest magnatiude
20275                 .    shifts.  If there aren't NS shifts available,
20276                 .    then use them all, possibly dropping one to
20277                 .    make the number of shifts even. ====
20278 
20279    Computing MIN
20280 */
20281 		i__2 = ns, i__3 = kbot - ks + 1;
20282 		ns = min(i__2,i__3);
20283 		ns -= ns % 2;
20284 		ks = kbot - ns + 1;
20285 
20286 /*
20287                 ==== Small-bulge multi-shift QR sweep:
20288                 .    split workspace under the subdiagonal into
20289                 .    - a KDU-by-KDU work array U in the lower
20290                 .      left-hand-corner,
20291                 .    - a KDU-by-at-least-KDU-but-more-is-better
20292                 .      (KDU-by-NHo) horizontal work array WH along
20293                 .      the bottom edge,
20294                 .    - and an at-least-KDU-but-more-is-better-by-KDU
20295                 .      (NVE-by-KDU) vertical work WV arrow along
20296                 .      the left-hand-edge. ====
20297 */
20298 
20299 		kdu = ns * 3 - 3;
20300 		ku = *n - kdu + 1;
20301 		kwh = kdu + 1;
20302 		nho = *n - kdu - 3 - (kdu + 1) + 1;
20303 		kwv = kdu + 4;
20304 		nve = *n - kdu - kwv + 1;
20305 
20306 /*              ==== Small-bulge multi-shift QR sweep ==== */
20307 
20308 		dlaqr5_(wantt, wantz, &kacc22, n, &ktop, &kbot, &ns, &wr[ks],
20309 			&wi[ks], &h__[h_offset], ldh, iloz, ihiz, &z__[
20310 			z_offset], ldz, &work[1], &c__3, &h__[ku + h_dim1],
20311 			ldh, &nve, &h__[kwv + h_dim1], ldh, &nho, &h__[ku +
20312 			kwh * h_dim1], ldh);
20313 	    }
20314 
20315 /*           ==== Note progress (or the lack of it). ==== */
20316 
20317 	    if (ld > 0) {
20318 		ndfl = 1;
20319 	    } else {
20320 		++ndfl;
20321 	    }
20322 
20323 /*
20324              ==== End of main loop ====
20325    L80:
20326 */
20327 	}
20328 
20329 /*
20330           ==== Iteration limit exceeded.  Set INFO to show where
20331           .    the problem occurred and exit. ====
20332 */
20333 
20334 	*info = kbot;
20335 L90:
20336 	;
20337     }
20338 
20339 /*     ==== Return the optimal value of LWORK. ==== */
20340 
20341     work[1] = (doublereal) lwkopt;
20342 
20343 /*     ==== End of DLAQR4 ==== */
20344 
20345     return 0;
20346 } /* dlaqr4_ */
20347 
dlaqr5_(logical * wantt,logical * wantz,integer * kacc22,integer * n,integer * ktop,integer * kbot,integer * nshfts,doublereal * sr,doublereal * si,doublereal * h__,integer * ldh,integer * iloz,integer * ihiz,doublereal * z__,integer * ldz,doublereal * v,integer * ldv,doublereal * u,integer * ldu,integer * nv,doublereal * wv,integer * ldwv,integer * nh,doublereal * wh,integer * ldwh)20348 /* Subroutine */ int dlaqr5_(logical *wantt, logical *wantz, integer *kacc22,
20349 	integer *n, integer *ktop, integer *kbot, integer *nshfts, doublereal
20350 	*sr, doublereal *si, doublereal *h__, integer *ldh, integer *iloz,
20351 	integer *ihiz, doublereal *z__, integer *ldz, doublereal *v, integer *
20352 	ldv, doublereal *u, integer *ldu, integer *nv, doublereal *wv,
20353 	integer *ldwv, integer *nh, doublereal *wh, integer *ldwh)
20354 {
20355     /* System generated locals */
20356     integer h_dim1, h_offset, u_dim1, u_offset, v_dim1, v_offset, wh_dim1,
20357 	    wh_offset, wv_dim1, wv_offset, z_dim1, z_offset, i__1, i__2, i__3,
20358 	     i__4, i__5, i__6, i__7;
20359     doublereal d__1, d__2, d__3, d__4, d__5;
20360 
20361     /* Local variables */
20362     static integer i__, j, k, m, i2, j2, i4, j4, k1;
20363     static doublereal h11, h12, h21, h22;
20364     static integer m22, ns, nu;
20365     static doublereal vt[3], scl;
20366     static integer kdu, kms;
20367     static doublereal ulp;
20368     static integer knz, kzs;
20369     static doublereal tst1, tst2, beta;
20370     static logical blk22, bmp22;
20371     static integer mend, jcol, jlen, jbot, mbot;
20372     static doublereal swap;
20373     static integer jtop, jrow, mtop;
20374     static doublereal alpha;
20375     static logical accum;
20376     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
20377 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
20378 	    integer *, doublereal *, doublereal *, integer *);
20379     static integer ndcol, incol, krcol, nbmps;
20380     extern /* Subroutine */ int dtrmm_(char *, char *, char *, char *,
20381 	    integer *, integer *, doublereal *, doublereal *, integer *,
20382 	    doublereal *, integer *), dlaqr1_(
20383 	    integer *, doublereal *, integer *, doublereal *, doublereal *,
20384 	    doublereal *, doublereal *, doublereal *), dlabad_(doublereal *,
20385 	    doublereal *);
20386 
20387     extern /* Subroutine */ int dlarfg_(integer *, doublereal *, doublereal *,
20388 	     integer *, doublereal *), dlacpy_(char *, integer *, integer *,
20389 	    doublereal *, integer *, doublereal *, integer *);
20390     static doublereal safmin;
20391     extern /* Subroutine */ int dlaset_(char *, integer *, integer *,
20392 	    doublereal *, doublereal *, doublereal *, integer *);
20393     static doublereal safmax, refsum;
20394     static integer mstart;
20395     static doublereal smlnum;
20396 
20397 
20398 /*
20399     -- LAPACK auxiliary routine (version 3.2) --
20400     -- LAPACK is a software package provided by Univ. of Tennessee,    --
20401     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
20402        November 2006
20403 
20404 
20405        This auxiliary subroutine called by DLAQR0 performs a
20406        single small-bulge multi-shift QR sweep.
20407 
20408         WANTT  (input) logical scalar
20409                WANTT = .true. if the quasi-triangular Schur factor
20410                is being computed.  WANTT is set to .false. otherwise.
20411 
20412         WANTZ  (input) logical scalar
20413                WANTZ = .true. if the orthogonal Schur factor is being
20414                computed.  WANTZ is set to .false. otherwise.
20415 
20416         KACC22 (input) integer with value 0, 1, or 2.
20417                Specifies the computation mode of far-from-diagonal
20418                orthogonal updates.
20419           = 0: DLAQR5 does not accumulate reflections and does not
20420                use matrix-matrix multiply to update far-from-diagonal
20421                matrix entries.
20422           = 1: DLAQR5 accumulates reflections and uses matrix-matrix
20423                multiply to update the far-from-diagonal matrix entries.
20424           = 2: DLAQR5 accumulates reflections, uses matrix-matrix
20425                multiply to update the far-from-diagonal matrix entries,
20426                and takes advantage of 2-by-2 block structure during
20427                matrix multiplies.
20428 
20429         N      (input) integer scalar
20430                N is the order of the Hessenberg matrix H upon which this
20431                subroutine operates.
20432 
20433         KTOP   (input) integer scalar
20434         KBOT   (input) integer scalar
20435                These are the first and last rows and columns of an
20436                isolated diagonal block upon which the QR sweep is to be
20437                applied. It is assumed without a check that
20438                          either KTOP = 1  or   H(KTOP,KTOP-1) = 0
20439                and
20440                          either KBOT = N  or   H(KBOT+1,KBOT) = 0.
20441 
20442         NSHFTS (input) integer scalar
20443                NSHFTS gives the number of simultaneous shifts.  NSHFTS
20444                must be positive and even.
20445 
20446         SR     (input/output) DOUBLE PRECISION array of size (NSHFTS)
20447         SI     (input/output) DOUBLE PRECISION array of size (NSHFTS)
20448                SR contains the real parts and SI contains the imaginary
20449                parts of the NSHFTS shifts of origin that define the
20450                multi-shift QR sweep.  On output SR and SI may be
20451                reordered.
20452 
20453         H      (input/output) DOUBLE PRECISION array of size (LDH,N)
20454                On input H contains a Hessenberg matrix.  On output a
20455                multi-shift QR sweep with shifts SR(J)+i*SI(J) is applied
20456                to the isolated diagonal block in rows and columns KTOP
20457                through KBOT.
20458 
20459         LDH    (input) integer scalar
20460                LDH is the leading dimension of H just as declared in the
20461                calling procedure.  LDH.GE.MAX(1,N).
20462 
20463         ILOZ   (input) INTEGER
20464         IHIZ   (input) INTEGER
20465                Specify the rows of Z to which transformations must be
20466                applied if WANTZ is .TRUE.. 1 .LE. ILOZ .LE. IHIZ .LE. N
20467 
20468         Z      (input/output) DOUBLE PRECISION array of size (LDZ,IHI)
20469                If WANTZ = .TRUE., then the QR Sweep orthogonal
20470                similarity transformation is accumulated into
20471                Z(ILOZ:IHIZ,ILO:IHI) from the right.
20472                If WANTZ = .FALSE., then Z is unreferenced.
20473 
20474         LDZ    (input) integer scalar
20475                LDA is the leading dimension of Z just as declared in
20476                the calling procedure. LDZ.GE.N.
20477 
20478         V      (workspace) DOUBLE PRECISION array of size (LDV,NSHFTS/2)
20479 
20480         LDV    (input) integer scalar
20481                LDV is the leading dimension of V as declared in the
20482                calling procedure.  LDV.GE.3.
20483 
20484         U      (workspace) DOUBLE PRECISION array of size
20485                (LDU,3*NSHFTS-3)
20486 
20487         LDU    (input) integer scalar
20488                LDU is the leading dimension of U just as declared in the
20489                in the calling subroutine.  LDU.GE.3*NSHFTS-3.
20490 
20491         NH     (input) integer scalar
20492                NH is the number of columns in array WH available for
20493                workspace. NH.GE.1.
20494 
20495         WH     (workspace) DOUBLE PRECISION array of size (LDWH,NH)
20496 
20497         LDWH   (input) integer scalar
20498                Leading dimension of WH just as declared in the
20499                calling procedure.  LDWH.GE.3*NSHFTS-3.
20500 
20501         NV     (input) integer scalar
20502                NV is the number of rows in WV agailable for workspace.
20503                NV.GE.1.
20504 
20505         WV     (workspace) DOUBLE PRECISION array of size
20506                (LDWV,3*NSHFTS-3)
20507 
20508         LDWV   (input) integer scalar
20509                LDWV is the leading dimension of WV as declared in the
20510                in the calling subroutine.  LDWV.GE.NV.
20511 
20512        ================================================================
20513        Based on contributions by
20514           Karen Braman and Ralph Byers, Department of Mathematics,
20515           University of Kansas, USA
20516 
20517        ================================================================
20518        Reference:
20519 
20520        K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
20521        Algorithm Part I: Maintaining Well Focused Shifts, and
20522        Level 3 Performance, SIAM Journal of Matrix Analysis,
20523        volume 23, pages 929--947, 2002.
20524 
20525        ================================================================
20526 
20527 
20528        ==== If there are no shifts, then there is nothing to do. ====
20529 */
20530 
20531     /* Parameter adjustments */
20532     --sr;
20533     --si;
20534     h_dim1 = *ldh;
20535     h_offset = 1 + h_dim1;
20536     h__ -= h_offset;
20537     z_dim1 = *ldz;
20538     z_offset = 1 + z_dim1;
20539     z__ -= z_offset;
20540     v_dim1 = *ldv;
20541     v_offset = 1 + v_dim1;
20542     v -= v_offset;
20543     u_dim1 = *ldu;
20544     u_offset = 1 + u_dim1;
20545     u -= u_offset;
20546     wv_dim1 = *ldwv;
20547     wv_offset = 1 + wv_dim1;
20548     wv -= wv_offset;
20549     wh_dim1 = *ldwh;
20550     wh_offset = 1 + wh_dim1;
20551     wh -= wh_offset;
20552 
20553     /* Function Body */
20554     if (*nshfts < 2) {
20555 	return 0;
20556     }
20557 
20558 /*
20559        ==== If the active block is empty or 1-by-1, then there
20560        .    is nothing to do. ====
20561 */
20562 
20563     if (*ktop >= *kbot) {
20564 	return 0;
20565     }
20566 
20567 /*
20568        ==== Shuffle shifts into pairs of real shifts and pairs
20569        .    of complex conjugate shifts assuming complex
20570        .    conjugate shifts are already adjacent to one
20571        .    another. ====
20572 */
20573 
20574     i__1 = *nshfts - 2;
20575     for (i__ = 1; i__ <= i__1; i__ += 2) {
20576 	if (si[i__] != -si[i__ + 1]) {
20577 
20578 	    swap = sr[i__];
20579 	    sr[i__] = sr[i__ + 1];
20580 	    sr[i__ + 1] = sr[i__ + 2];
20581 	    sr[i__ + 2] = swap;
20582 
20583 	    swap = si[i__];
20584 	    si[i__] = si[i__ + 1];
20585 	    si[i__ + 1] = si[i__ + 2];
20586 	    si[i__ + 2] = swap;
20587 	}
20588 /* L10: */
20589     }
20590 
20591 /*
20592        ==== NSHFTS is supposed to be even, but if it is odd,
20593        .    then simply reduce it by one.  The shuffle above
20594        .    ensures that the dropped shift is real and that
20595        .    the remaining shifts are paired. ====
20596 */
20597 
20598     ns = *nshfts - *nshfts % 2;
20599 
20600 /*     ==== Machine constants for deflation ==== */
20601 
20602     safmin = SAFEMINIMUM;
20603     safmax = 1. / safmin;
20604     dlabad_(&safmin, &safmax);
20605     ulp = PRECISION;
20606     smlnum = safmin * ((doublereal) (*n) / ulp);
20607 
20608 /*
20609        ==== Use accumulated reflections to update far-from-diagonal
20610        .    entries ? ====
20611 */
20612 
20613     accum = *kacc22 == 1 || *kacc22 == 2;
20614 
20615 /*     ==== If so, exploit the 2-by-2 block structure? ==== */
20616 
20617     blk22 = ns > 2 && *kacc22 == 2;
20618 
20619 /*     ==== clear trash ==== */
20620 
20621     if (*ktop + 2 <= *kbot) {
20622 	h__[*ktop + 2 + *ktop * h_dim1] = 0.;
20623     }
20624 
20625 /*     ==== NBMPS = number of 2-shift bulges in the chain ==== */
20626 
20627     nbmps = ns / 2;
20628 
20629 /*     ==== KDU = width of slab ==== */
20630 
20631     kdu = nbmps * 6 - 3;
20632 
20633 /*     ==== Create and chase chains of NBMPS bulges ==== */
20634 
20635     i__1 = *kbot - 2;
20636     i__2 = nbmps * 3 - 2;
20637     for (incol = (1 - nbmps) * 3 + *ktop - 1; i__2 < 0 ? incol >= i__1 :
20638 	    incol <= i__1; incol += i__2) {
20639 	ndcol = incol + kdu;
20640 	if (accum) {
20641 	    dlaset_("ALL", &kdu, &kdu, &c_b29, &c_b15, &u[u_offset], ldu);
20642 	}
20643 
20644 /*
20645           ==== Near-the-diagonal bulge chase.  The following loop
20646           .    performs the near-the-diagonal part of a small bulge
20647           .    multi-shift QR sweep.  Each 6*NBMPS-2 column diagonal
20648           .    chunk extends from column INCOL to column NDCOL
20649           .    (including both column INCOL and column NDCOL). The
20650           .    following loop chases a 3*NBMPS column long chain of
20651           .    NBMPS bulges 3*NBMPS-2 columns to the right.  (INCOL
20652           .    may be less than KTOP and and NDCOL may be greater than
20653           .    KBOT indicating phantom columns from which to chase
20654           .    bulges before they are actually introduced or to which
20655           .    to chase bulges beyond column KBOT.)  ====
20656 
20657    Computing MIN
20658 */
20659 	i__4 = incol + nbmps * 3 - 3, i__5 = *kbot - 2;
20660 	i__3 = min(i__4,i__5);
20661 	for (krcol = incol; krcol <= i__3; ++krcol) {
20662 
20663 /*
20664              ==== Bulges number MTOP to MBOT are active double implicit
20665              .    shift bulges.  There may or may not also be small
20666              .    2-by-2 bulge, if there is room.  The inactive bulges
20667              .    (if any) must wait until the active bulges have moved
20668              .    down the diagonal to make room.  The phantom matrix
20669              .    paradigm described above helps keep track.  ====
20670 
20671    Computing MAX
20672 */
20673 	    i__4 = 1, i__5 = (*ktop - 1 - krcol + 2) / 3 + 1;
20674 	    mtop = max(i__4,i__5);
20675 /* Computing MIN */
20676 	    i__4 = nbmps, i__5 = (*kbot - krcol) / 3;
20677 	    mbot = min(i__4,i__5);
20678 	    m22 = mbot + 1;
20679 	    bmp22 = mbot < nbmps && krcol + (m22 - 1) * 3 == *kbot - 2;
20680 
20681 /*
20682              ==== Generate reflections to chase the chain right
20683              .    one column.  (The minimum value of K is KTOP-1.) ====
20684 */
20685 
20686 	    i__4 = mbot;
20687 	    for (m = mtop; m <= i__4; ++m) {
20688 		k = krcol + (m - 1) * 3;
20689 		if (k == *ktop - 1) {
20690 		    dlaqr1_(&c__3, &h__[*ktop + *ktop * h_dim1], ldh, &sr[(m
20691 			    << 1) - 1], &si[(m << 1) - 1], &sr[m * 2], &si[m *
20692 			     2], &v[m * v_dim1 + 1]);
20693 		    alpha = v[m * v_dim1 + 1];
20694 		    dlarfg_(&c__3, &alpha, &v[m * v_dim1 + 2], &c__1, &v[m *
20695 			    v_dim1 + 1]);
20696 		} else {
20697 		    beta = h__[k + 1 + k * h_dim1];
20698 		    v[m * v_dim1 + 2] = h__[k + 2 + k * h_dim1];
20699 		    v[m * v_dim1 + 3] = h__[k + 3 + k * h_dim1];
20700 		    dlarfg_(&c__3, &beta, &v[m * v_dim1 + 2], &c__1, &v[m *
20701 			    v_dim1 + 1]);
20702 
20703 /*
20704                    ==== A Bulge may collapse because of vigilant
20705                    .    deflation or destructive underflow.  In the
20706                    .    underflow case, try the two-small-subdiagonals
20707                    .    trick to try to reinflate the bulge.  ====
20708 */
20709 
20710 		    if (h__[k + 3 + k * h_dim1] != 0. || h__[k + 3 + (k + 1) *
20711 			     h_dim1] != 0. || h__[k + 3 + (k + 2) * h_dim1] ==
20712 			     0.) {
20713 
20714 /*                    ==== Typical case: not collapsed (yet). ==== */
20715 
20716 			h__[k + 1 + k * h_dim1] = beta;
20717 			h__[k + 2 + k * h_dim1] = 0.;
20718 			h__[k + 3 + k * h_dim1] = 0.;
20719 		    } else {
20720 
20721 /*
20722                       ==== Atypical case: collapsed.  Attempt to
20723                       .    reintroduce ignoring H(K+1,K) and H(K+2,K).
20724                       .    If the fill resulting from the new
20725                       .    reflector is too large, then abandon it.
20726                       .    Otherwise, use the new one. ====
20727 */
20728 
20729 			dlaqr1_(&c__3, &h__[k + 1 + (k + 1) * h_dim1], ldh, &
20730 				sr[(m << 1) - 1], &si[(m << 1) - 1], &sr[m *
20731 				2], &si[m * 2], vt);
20732 			alpha = vt[0];
20733 			dlarfg_(&c__3, &alpha, &vt[1], &c__1, vt);
20734 			refsum = vt[0] * (h__[k + 1 + k * h_dim1] + vt[1] *
20735 				h__[k + 2 + k * h_dim1]);
20736 
20737 			if ((d__1 = h__[k + 2 + k * h_dim1] - refsum * vt[1],
20738 				abs(d__1)) + (d__2 = refsum * vt[2], abs(d__2)
20739 				) > ulp * ((d__3 = h__[k + k * h_dim1], abs(
20740 				d__3)) + (d__4 = h__[k + 1 + (k + 1) * h_dim1]
20741 				, abs(d__4)) + (d__5 = h__[k + 2 + (k + 2) *
20742 				h_dim1], abs(d__5)))) {
20743 
20744 /*
20745                          ==== Starting a new bulge here would
20746                          .    create non-negligible fill.  Use
20747                          .    the old one with trepidation. ====
20748 */
20749 
20750 			    h__[k + 1 + k * h_dim1] = beta;
20751 			    h__[k + 2 + k * h_dim1] = 0.;
20752 			    h__[k + 3 + k * h_dim1] = 0.;
20753 			} else {
20754 
20755 /*
20756                          ==== Stating a new bulge here would
20757                          .    create only negligible fill.
20758                          .    Replace the old reflector with
20759                          .    the new one. ====
20760 */
20761 
20762 			    h__[k + 1 + k * h_dim1] -= refsum;
20763 			    h__[k + 2 + k * h_dim1] = 0.;
20764 			    h__[k + 3 + k * h_dim1] = 0.;
20765 			    v[m * v_dim1 + 1] = vt[0];
20766 			    v[m * v_dim1 + 2] = vt[1];
20767 			    v[m * v_dim1 + 3] = vt[2];
20768 			}
20769 		    }
20770 		}
20771 /* L20: */
20772 	    }
20773 
20774 /*           ==== Generate a 2-by-2 reflection, if needed. ==== */
20775 
20776 	    k = krcol + (m22 - 1) * 3;
20777 	    if (bmp22) {
20778 		if (k == *ktop - 1) {
20779 		    dlaqr1_(&c__2, &h__[k + 1 + (k + 1) * h_dim1], ldh, &sr[(
20780 			    m22 << 1) - 1], &si[(m22 << 1) - 1], &sr[m22 * 2],
20781 			     &si[m22 * 2], &v[m22 * v_dim1 + 1]);
20782 		    beta = v[m22 * v_dim1 + 1];
20783 		    dlarfg_(&c__2, &beta, &v[m22 * v_dim1 + 2], &c__1, &v[m22
20784 			    * v_dim1 + 1]);
20785 		} else {
20786 		    beta = h__[k + 1 + k * h_dim1];
20787 		    v[m22 * v_dim1 + 2] = h__[k + 2 + k * h_dim1];
20788 		    dlarfg_(&c__2, &beta, &v[m22 * v_dim1 + 2], &c__1, &v[m22
20789 			    * v_dim1 + 1]);
20790 		    h__[k + 1 + k * h_dim1] = beta;
20791 		    h__[k + 2 + k * h_dim1] = 0.;
20792 		}
20793 	    }
20794 
20795 /*           ==== Multiply H by reflections from the left ==== */
20796 
20797 	    if (accum) {
20798 		jbot = min(ndcol,*kbot);
20799 	    } else if (*wantt) {
20800 		jbot = *n;
20801 	    } else {
20802 		jbot = *kbot;
20803 	    }
20804 	    i__4 = jbot;
20805 	    for (j = max(*ktop,krcol); j <= i__4; ++j) {
20806 /* Computing MIN */
20807 		i__5 = mbot, i__6 = (j - krcol + 2) / 3;
20808 		mend = min(i__5,i__6);
20809 		i__5 = mend;
20810 		for (m = mtop; m <= i__5; ++m) {
20811 		    k = krcol + (m - 1) * 3;
20812 		    refsum = v[m * v_dim1 + 1] * (h__[k + 1 + j * h_dim1] + v[
20813 			    m * v_dim1 + 2] * h__[k + 2 + j * h_dim1] + v[m *
20814 			    v_dim1 + 3] * h__[k + 3 + j * h_dim1]);
20815 		    h__[k + 1 + j * h_dim1] -= refsum;
20816 		    h__[k + 2 + j * h_dim1] -= refsum * v[m * v_dim1 + 2];
20817 		    h__[k + 3 + j * h_dim1] -= refsum * v[m * v_dim1 + 3];
20818 /* L30: */
20819 		}
20820 /* L40: */
20821 	    }
20822 	    if (bmp22) {
20823 		k = krcol + (m22 - 1) * 3;
20824 /* Computing MAX */
20825 		i__4 = k + 1;
20826 		i__5 = jbot;
20827 		for (j = max(i__4,*ktop); j <= i__5; ++j) {
20828 		    refsum = v[m22 * v_dim1 + 1] * (h__[k + 1 + j * h_dim1] +
20829 			    v[m22 * v_dim1 + 2] * h__[k + 2 + j * h_dim1]);
20830 		    h__[k + 1 + j * h_dim1] -= refsum;
20831 		    h__[k + 2 + j * h_dim1] -= refsum * v[m22 * v_dim1 + 2];
20832 /* L50: */
20833 		}
20834 	    }
20835 
20836 /*
20837              ==== Multiply H by reflections from the right.
20838              .    Delay filling in the last row until the
20839              .    vigilant deflation check is complete. ====
20840 */
20841 
20842 	    if (accum) {
20843 		jtop = max(*ktop,incol);
20844 	    } else if (*wantt) {
20845 		jtop = 1;
20846 	    } else {
20847 		jtop = *ktop;
20848 	    }
20849 	    i__5 = mbot;
20850 	    for (m = mtop; m <= i__5; ++m) {
20851 		if (v[m * v_dim1 + 1] != 0.) {
20852 		    k = krcol + (m - 1) * 3;
20853 /* Computing MIN */
20854 		    i__6 = *kbot, i__7 = k + 3;
20855 		    i__4 = min(i__6,i__7);
20856 		    for (j = jtop; j <= i__4; ++j) {
20857 			refsum = v[m * v_dim1 + 1] * (h__[j + (k + 1) *
20858 				h_dim1] + v[m * v_dim1 + 2] * h__[j + (k + 2)
20859 				* h_dim1] + v[m * v_dim1 + 3] * h__[j + (k +
20860 				3) * h_dim1]);
20861 			h__[j + (k + 1) * h_dim1] -= refsum;
20862 			h__[j + (k + 2) * h_dim1] -= refsum * v[m * v_dim1 +
20863 				2];
20864 			h__[j + (k + 3) * h_dim1] -= refsum * v[m * v_dim1 +
20865 				3];
20866 /* L60: */
20867 		    }
20868 
20869 		    if (accum) {
20870 
20871 /*
20872                       ==== Accumulate U. (If necessary, update Z later
20873                       .    with with an efficient matrix-matrix
20874                       .    multiply.) ====
20875 */
20876 
20877 			kms = k - incol;
20878 /* Computing MAX */
20879 			i__4 = 1, i__6 = *ktop - incol;
20880 			i__7 = kdu;
20881 			for (j = max(i__4,i__6); j <= i__7; ++j) {
20882 			    refsum = v[m * v_dim1 + 1] * (u[j + (kms + 1) *
20883 				    u_dim1] + v[m * v_dim1 + 2] * u[j + (kms
20884 				    + 2) * u_dim1] + v[m * v_dim1 + 3] * u[j
20885 				    + (kms + 3) * u_dim1]);
20886 			    u[j + (kms + 1) * u_dim1] -= refsum;
20887 			    u[j + (kms + 2) * u_dim1] -= refsum * v[m *
20888 				    v_dim1 + 2];
20889 			    u[j + (kms + 3) * u_dim1] -= refsum * v[m *
20890 				    v_dim1 + 3];
20891 /* L70: */
20892 			}
20893 		    } else if (*wantz) {
20894 
20895 /*
20896                       ==== U is not accumulated, so update Z
20897                       .    now by multiplying by reflections
20898                       .    from the right. ====
20899 */
20900 
20901 			i__7 = *ihiz;
20902 			for (j = *iloz; j <= i__7; ++j) {
20903 			    refsum = v[m * v_dim1 + 1] * (z__[j + (k + 1) *
20904 				    z_dim1] + v[m * v_dim1 + 2] * z__[j + (k
20905 				    + 2) * z_dim1] + v[m * v_dim1 + 3] * z__[
20906 				    j + (k + 3) * z_dim1]);
20907 			    z__[j + (k + 1) * z_dim1] -= refsum;
20908 			    z__[j + (k + 2) * z_dim1] -= refsum * v[m *
20909 				    v_dim1 + 2];
20910 			    z__[j + (k + 3) * z_dim1] -= refsum * v[m *
20911 				    v_dim1 + 3];
20912 /* L80: */
20913 			}
20914 		    }
20915 		}
20916 /* L90: */
20917 	    }
20918 
20919 /*           ==== Special case: 2-by-2 reflection (if needed) ==== */
20920 
20921 	    k = krcol + (m22 - 1) * 3;
20922 	    if (bmp22 && v[m22 * v_dim1 + 1] != 0.) {
20923 /* Computing MIN */
20924 		i__7 = *kbot, i__4 = k + 3;
20925 		i__5 = min(i__7,i__4);
20926 		for (j = jtop; j <= i__5; ++j) {
20927 		    refsum = v[m22 * v_dim1 + 1] * (h__[j + (k + 1) * h_dim1]
20928 			    + v[m22 * v_dim1 + 2] * h__[j + (k + 2) * h_dim1])
20929 			    ;
20930 		    h__[j + (k + 1) * h_dim1] -= refsum;
20931 		    h__[j + (k + 2) * h_dim1] -= refsum * v[m22 * v_dim1 + 2];
20932 /* L100: */
20933 		}
20934 
20935 		if (accum) {
20936 		    kms = k - incol;
20937 /* Computing MAX */
20938 		    i__5 = 1, i__7 = *ktop - incol;
20939 		    i__4 = kdu;
20940 		    for (j = max(i__5,i__7); j <= i__4; ++j) {
20941 			refsum = v[m22 * v_dim1 + 1] * (u[j + (kms + 1) *
20942 				u_dim1] + v[m22 * v_dim1 + 2] * u[j + (kms +
20943 				2) * u_dim1]);
20944 			u[j + (kms + 1) * u_dim1] -= refsum;
20945 			u[j + (kms + 2) * u_dim1] -= refsum * v[m22 * v_dim1
20946 				+ 2];
20947 /* L110: */
20948 		    }
20949 		} else if (*wantz) {
20950 		    i__4 = *ihiz;
20951 		    for (j = *iloz; j <= i__4; ++j) {
20952 			refsum = v[m22 * v_dim1 + 1] * (z__[j + (k + 1) *
20953 				z_dim1] + v[m22 * v_dim1 + 2] * z__[j + (k +
20954 				2) * z_dim1]);
20955 			z__[j + (k + 1) * z_dim1] -= refsum;
20956 			z__[j + (k + 2) * z_dim1] -= refsum * v[m22 * v_dim1
20957 				+ 2];
20958 /* L120: */
20959 		    }
20960 		}
20961 	    }
20962 
20963 /*           ==== Vigilant deflation check ==== */
20964 
20965 	    mstart = mtop;
20966 	    if (krcol + (mstart - 1) * 3 < *ktop) {
20967 		++mstart;
20968 	    }
20969 	    mend = mbot;
20970 	    if (bmp22) {
20971 		++mend;
20972 	    }
20973 	    if (krcol == *kbot - 2) {
20974 		++mend;
20975 	    }
20976 	    i__4 = mend;
20977 	    for (m = mstart; m <= i__4; ++m) {
20978 /* Computing MIN */
20979 		i__5 = *kbot - 1, i__7 = krcol + (m - 1) * 3;
20980 		k = min(i__5,i__7);
20981 
20982 /*
20983                 ==== The following convergence test requires that
20984                 .    the tradition small-compared-to-nearby-diagonals
20985                 .    criterion and the Ahues & Tisseur (LAWN 122, 1997)
20986                 .    criteria both be satisfied.  The latter improves
20987                 .    accuracy in some examples. Falling back on an
20988                 .    alternate convergence criterion when TST1 or TST2
20989                 .    is zero (as done here) is traditional but probably
20990                 .    unnecessary. ====
20991 */
20992 
20993 		if (h__[k + 1 + k * h_dim1] != 0.) {
20994 		    tst1 = (d__1 = h__[k + k * h_dim1], abs(d__1)) + (d__2 =
20995 			    h__[k + 1 + (k + 1) * h_dim1], abs(d__2));
20996 		    if (tst1 == 0.) {
20997 			if (k >= *ktop + 1) {
20998 			    tst1 += (d__1 = h__[k + (k - 1) * h_dim1], abs(
20999 				    d__1));
21000 			}
21001 			if (k >= *ktop + 2) {
21002 			    tst1 += (d__1 = h__[k + (k - 2) * h_dim1], abs(
21003 				    d__1));
21004 			}
21005 			if (k >= *ktop + 3) {
21006 			    tst1 += (d__1 = h__[k + (k - 3) * h_dim1], abs(
21007 				    d__1));
21008 			}
21009 			if (k <= *kbot - 2) {
21010 			    tst1 += (d__1 = h__[k + 2 + (k + 1) * h_dim1],
21011 				    abs(d__1));
21012 			}
21013 			if (k <= *kbot - 3) {
21014 			    tst1 += (d__1 = h__[k + 3 + (k + 1) * h_dim1],
21015 				    abs(d__1));
21016 			}
21017 			if (k <= *kbot - 4) {
21018 			    tst1 += (d__1 = h__[k + 4 + (k + 1) * h_dim1],
21019 				    abs(d__1));
21020 			}
21021 		    }
21022 /* Computing MAX */
21023 		    d__2 = smlnum, d__3 = ulp * tst1;
21024 		    if ((d__1 = h__[k + 1 + k * h_dim1], abs(d__1)) <= max(
21025 			    d__2,d__3)) {
21026 /* Computing MAX */
21027 			d__3 = (d__1 = h__[k + 1 + k * h_dim1], abs(d__1)),
21028 				d__4 = (d__2 = h__[k + (k + 1) * h_dim1], abs(
21029 				d__2));
21030 			h12 = max(d__3,d__4);
21031 /* Computing MIN */
21032 			d__3 = (d__1 = h__[k + 1 + k * h_dim1], abs(d__1)),
21033 				d__4 = (d__2 = h__[k + (k + 1) * h_dim1], abs(
21034 				d__2));
21035 			h21 = min(d__3,d__4);
21036 /* Computing MAX */
21037 			d__3 = (d__1 = h__[k + 1 + (k + 1) * h_dim1], abs(
21038 				d__1)), d__4 = (d__2 = h__[k + k * h_dim1] -
21039 				h__[k + 1 + (k + 1) * h_dim1], abs(d__2));
21040 			h11 = max(d__3,d__4);
21041 /* Computing MIN */
21042 			d__3 = (d__1 = h__[k + 1 + (k + 1) * h_dim1], abs(
21043 				d__1)), d__4 = (d__2 = h__[k + k * h_dim1] -
21044 				h__[k + 1 + (k + 1) * h_dim1], abs(d__2));
21045 			h22 = min(d__3,d__4);
21046 			scl = h11 + h12;
21047 			tst2 = h22 * (h11 / scl);
21048 
21049 /* Computing MAX */
21050 			d__1 = smlnum, d__2 = ulp * tst2;
21051 			if (tst2 == 0. || h21 * (h12 / scl) <= max(d__1,d__2))
21052 				 {
21053 			    h__[k + 1 + k * h_dim1] = 0.;
21054 			}
21055 		    }
21056 		}
21057 /* L130: */
21058 	    }
21059 
21060 /*
21061              ==== Fill in the last row of each bulge. ====
21062 
21063    Computing MIN
21064 */
21065 	    i__4 = nbmps, i__5 = (*kbot - krcol - 1) / 3;
21066 	    mend = min(i__4,i__5);
21067 	    i__4 = mend;
21068 	    for (m = mtop; m <= i__4; ++m) {
21069 		k = krcol + (m - 1) * 3;
21070 		refsum = v[m * v_dim1 + 1] * v[m * v_dim1 + 3] * h__[k + 4 + (
21071 			k + 3) * h_dim1];
21072 		h__[k + 4 + (k + 1) * h_dim1] = -refsum;
21073 		h__[k + 4 + (k + 2) * h_dim1] = -refsum * v[m * v_dim1 + 2];
21074 		h__[k + 4 + (k + 3) * h_dim1] -= refsum * v[m * v_dim1 + 3];
21075 /* L140: */
21076 	    }
21077 
21078 /*
21079              ==== End of near-the-diagonal bulge chase. ====
21080 
21081    L150:
21082 */
21083 	}
21084 
21085 /*
21086           ==== Use U (if accumulated) to update far-from-diagonal
21087           .    entries in H.  If required, use U to update Z as
21088           .    well. ====
21089 */
21090 
21091 	if (accum) {
21092 	    if (*wantt) {
21093 		jtop = 1;
21094 		jbot = *n;
21095 	    } else {
21096 		jtop = *ktop;
21097 		jbot = *kbot;
21098 	    }
21099 	    if (! blk22 || incol < *ktop || ndcol > *kbot || ns <= 2) {
21100 
21101 /*
21102                 ==== Updates not exploiting the 2-by-2 block
21103                 .    structure of U.  K1 and NU keep track of
21104                 .    the location and size of U in the special
21105                 .    cases of introducing bulges and chasing
21106                 .    bulges off the bottom.  In these special
21107                 .    cases and in case the number of shifts
21108                 .    is NS = 2, there is no 2-by-2 block
21109                 .    structure to exploit.  ====
21110 
21111    Computing MAX
21112 */
21113 		i__3 = 1, i__4 = *ktop - incol;
21114 		k1 = max(i__3,i__4);
21115 /* Computing MAX */
21116 		i__3 = 0, i__4 = ndcol - *kbot;
21117 		nu = kdu - max(i__3,i__4) - k1 + 1;
21118 
21119 /*              ==== Horizontal Multiply ==== */
21120 
21121 		i__3 = jbot;
21122 		i__4 = *nh;
21123 		for (jcol = min(ndcol,*kbot) + 1; i__4 < 0 ? jcol >= i__3 :
21124 			jcol <= i__3; jcol += i__4) {
21125 /* Computing MIN */
21126 		    i__5 = *nh, i__7 = jbot - jcol + 1;
21127 		    jlen = min(i__5,i__7);
21128 		    dgemm_("C", "N", &nu, &jlen, &nu, &c_b15, &u[k1 + k1 *
21129 			    u_dim1], ldu, &h__[incol + k1 + jcol * h_dim1],
21130 			    ldh, &c_b29, &wh[wh_offset], ldwh);
21131 		    dlacpy_("ALL", &nu, &jlen, &wh[wh_offset], ldwh, &h__[
21132 			    incol + k1 + jcol * h_dim1], ldh);
21133 /* L160: */
21134 		}
21135 
21136 /*              ==== Vertical multiply ==== */
21137 
21138 		i__4 = max(*ktop,incol) - 1;
21139 		i__3 = *nv;
21140 		for (jrow = jtop; i__3 < 0 ? jrow >= i__4 : jrow <= i__4;
21141 			jrow += i__3) {
21142 /* Computing MIN */
21143 		    i__5 = *nv, i__7 = max(*ktop,incol) - jrow;
21144 		    jlen = min(i__5,i__7);
21145 		    dgemm_("N", "N", &jlen, &nu, &nu, &c_b15, &h__[jrow + (
21146 			    incol + k1) * h_dim1], ldh, &u[k1 + k1 * u_dim1],
21147 			    ldu, &c_b29, &wv[wv_offset], ldwv);
21148 		    dlacpy_("ALL", &jlen, &nu, &wv[wv_offset], ldwv, &h__[
21149 			    jrow + (incol + k1) * h_dim1], ldh);
21150 /* L170: */
21151 		}
21152 
21153 /*              ==== Z multiply (also vertical) ==== */
21154 
21155 		if (*wantz) {
21156 		    i__3 = *ihiz;
21157 		    i__4 = *nv;
21158 		    for (jrow = *iloz; i__4 < 0 ? jrow >= i__3 : jrow <= i__3;
21159 			     jrow += i__4) {
21160 /* Computing MIN */
21161 			i__5 = *nv, i__7 = *ihiz - jrow + 1;
21162 			jlen = min(i__5,i__7);
21163 			dgemm_("N", "N", &jlen, &nu, &nu, &c_b15, &z__[jrow +
21164 				(incol + k1) * z_dim1], ldz, &u[k1 + k1 *
21165 				u_dim1], ldu, &c_b29, &wv[wv_offset], ldwv);
21166 			dlacpy_("ALL", &jlen, &nu, &wv[wv_offset], ldwv, &z__[
21167 				jrow + (incol + k1) * z_dim1], ldz)
21168 				;
21169 /* L180: */
21170 		    }
21171 		}
21172 	    } else {
21173 
21174 /*
21175                 ==== Updates exploiting U's 2-by-2 block structure.
21176                 .    (I2, I4, J2, J4 are the last rows and columns
21177                 .    of the blocks.) ====
21178 */
21179 
21180 		i2 = (kdu + 1) / 2;
21181 		i4 = kdu;
21182 		j2 = i4 - i2;
21183 		j4 = kdu;
21184 
21185 /*
21186                 ==== KZS and KNZ deal with the band of zeros
21187                 .    along the diagonal of one of the triangular
21188                 .    blocks. ====
21189 */
21190 
21191 		kzs = j4 - j2 - (ns + 1);
21192 		knz = ns + 1;
21193 
21194 /*              ==== Horizontal multiply ==== */
21195 
21196 		i__4 = jbot;
21197 		i__3 = *nh;
21198 		for (jcol = min(ndcol,*kbot) + 1; i__3 < 0 ? jcol >= i__4 :
21199 			jcol <= i__4; jcol += i__3) {
21200 /* Computing MIN */
21201 		    i__5 = *nh, i__7 = jbot - jcol + 1;
21202 		    jlen = min(i__5,i__7);
21203 
21204 /*
21205                    ==== Copy bottom of H to top+KZS of scratch ====
21206                     (The first KZS rows get multiplied by zero.) ====
21207 */
21208 
21209 		    dlacpy_("ALL", &knz, &jlen, &h__[incol + 1 + j2 + jcol *
21210 			    h_dim1], ldh, &wh[kzs + 1 + wh_dim1], ldwh);
21211 
21212 /*                 ==== Multiply by U21' ==== */
21213 
21214 		    dlaset_("ALL", &kzs, &jlen, &c_b29, &c_b29, &wh[wh_offset]
21215 			    , ldwh);
21216 		    dtrmm_("L", "U", "C", "N", &knz, &jlen, &c_b15, &u[j2 + 1
21217 			    + (kzs + 1) * u_dim1], ldu, &wh[kzs + 1 + wh_dim1]
21218 			    , ldwh);
21219 
21220 /*                 ==== Multiply top of H by U11' ==== */
21221 
21222 		    dgemm_("C", "N", &i2, &jlen, &j2, &c_b15, &u[u_offset],
21223 			    ldu, &h__[incol + 1 + jcol * h_dim1], ldh, &c_b15,
21224 			     &wh[wh_offset], ldwh);
21225 
21226 /*                 ==== Copy top of H to bottom of WH ==== */
21227 
21228 		    dlacpy_("ALL", &j2, &jlen, &h__[incol + 1 + jcol * h_dim1]
21229 			    , ldh, &wh[i2 + 1 + wh_dim1], ldwh);
21230 
21231 /*                 ==== Multiply by U21' ==== */
21232 
21233 		    dtrmm_("L", "L", "C", "N", &j2, &jlen, &c_b15, &u[(i2 + 1)
21234 			     * u_dim1 + 1], ldu, &wh[i2 + 1 + wh_dim1], ldwh);
21235 
21236 /*                 ==== Multiply by U22 ==== */
21237 
21238 		    i__5 = i4 - i2;
21239 		    i__7 = j4 - j2;
21240 		    dgemm_("C", "N", &i__5, &jlen, &i__7, &c_b15, &u[j2 + 1 +
21241 			    (i2 + 1) * u_dim1], ldu, &h__[incol + 1 + j2 +
21242 			    jcol * h_dim1], ldh, &c_b15, &wh[i2 + 1 + wh_dim1]
21243 			    , ldwh);
21244 
21245 /*                 ==== Copy it back ==== */
21246 
21247 		    dlacpy_("ALL", &kdu, &jlen, &wh[wh_offset], ldwh, &h__[
21248 			    incol + 1 + jcol * h_dim1], ldh);
21249 /* L190: */
21250 		}
21251 
21252 /*              ==== Vertical multiply ==== */
21253 
21254 		i__3 = max(incol,*ktop) - 1;
21255 		i__4 = *nv;
21256 		for (jrow = jtop; i__4 < 0 ? jrow >= i__3 : jrow <= i__3;
21257 			jrow += i__4) {
21258 /* Computing MIN */
21259 		    i__5 = *nv, i__7 = max(incol,*ktop) - jrow;
21260 		    jlen = min(i__5,i__7);
21261 
21262 /*
21263                    ==== Copy right of H to scratch (the first KZS
21264                    .    columns get multiplied by zero) ====
21265 */
21266 
21267 		    dlacpy_("ALL", &jlen, &knz, &h__[jrow + (incol + 1 + j2) *
21268 			     h_dim1], ldh, &wv[(kzs + 1) * wv_dim1 + 1], ldwv);
21269 
21270 /*                 ==== Multiply by U21 ==== */
21271 
21272 		    dlaset_("ALL", &jlen, &kzs, &c_b29, &c_b29, &wv[wv_offset]
21273 			    , ldwv);
21274 		    dtrmm_("R", "U", "N", "N", &jlen, &knz, &c_b15, &u[j2 + 1
21275 			    + (kzs + 1) * u_dim1], ldu, &wv[(kzs + 1) *
21276 			    wv_dim1 + 1], ldwv);
21277 
21278 /*                 ==== Multiply by U11 ==== */
21279 
21280 		    dgemm_("N", "N", &jlen, &i2, &j2, &c_b15, &h__[jrow + (
21281 			    incol + 1) * h_dim1], ldh, &u[u_offset], ldu, &
21282 			    c_b15, &wv[wv_offset], ldwv)
21283 			    ;
21284 
21285 /*                 ==== Copy left of H to right of scratch ==== */
21286 
21287 		    dlacpy_("ALL", &jlen, &j2, &h__[jrow + (incol + 1) *
21288 			    h_dim1], ldh, &wv[(i2 + 1) * wv_dim1 + 1], ldwv);
21289 
21290 /*                 ==== Multiply by U21 ==== */
21291 
21292 		    i__5 = i4 - i2;
21293 		    dtrmm_("R", "L", "N", "N", &jlen, &i__5, &c_b15, &u[(i2 +
21294 			    1) * u_dim1 + 1], ldu, &wv[(i2 + 1) * wv_dim1 + 1]
21295 			    , ldwv);
21296 
21297 /*                 ==== Multiply by U22 ==== */
21298 
21299 		    i__5 = i4 - i2;
21300 		    i__7 = j4 - j2;
21301 		    dgemm_("N", "N", &jlen, &i__5, &i__7, &c_b15, &h__[jrow +
21302 			    (incol + 1 + j2) * h_dim1], ldh, &u[j2 + 1 + (i2
21303 			    + 1) * u_dim1], ldu, &c_b15, &wv[(i2 + 1) *
21304 			    wv_dim1 + 1], ldwv);
21305 
21306 /*                 ==== Copy it back ==== */
21307 
21308 		    dlacpy_("ALL", &jlen, &kdu, &wv[wv_offset], ldwv, &h__[
21309 			    jrow + (incol + 1) * h_dim1], ldh);
21310 /* L200: */
21311 		}
21312 
21313 /*              ==== Multiply Z (also vertical) ==== */
21314 
21315 		if (*wantz) {
21316 		    i__4 = *ihiz;
21317 		    i__3 = *nv;
21318 		    for (jrow = *iloz; i__3 < 0 ? jrow >= i__4 : jrow <= i__4;
21319 			     jrow += i__3) {
21320 /* Computing MIN */
21321 			i__5 = *nv, i__7 = *ihiz - jrow + 1;
21322 			jlen = min(i__5,i__7);
21323 
21324 /*
21325                       ==== Copy right of Z to left of scratch (first
21326                       .     KZS columns get multiplied by zero) ====
21327 */
21328 
21329 			dlacpy_("ALL", &jlen, &knz, &z__[jrow + (incol + 1 +
21330 				j2) * z_dim1], ldz, &wv[(kzs + 1) * wv_dim1 +
21331 				1], ldwv);
21332 
21333 /*                    ==== Multiply by U12 ==== */
21334 
21335 			dlaset_("ALL", &jlen, &kzs, &c_b29, &c_b29, &wv[
21336 				wv_offset], ldwv);
21337 			dtrmm_("R", "U", "N", "N", &jlen, &knz, &c_b15, &u[j2
21338 				+ 1 + (kzs + 1) * u_dim1], ldu, &wv[(kzs + 1)
21339 				* wv_dim1 + 1], ldwv);
21340 
21341 /*                    ==== Multiply by U11 ==== */
21342 
21343 			dgemm_("N", "N", &jlen, &i2, &j2, &c_b15, &z__[jrow +
21344 				(incol + 1) * z_dim1], ldz, &u[u_offset], ldu,
21345 				 &c_b15, &wv[wv_offset], ldwv);
21346 
21347 /*                    ==== Copy left of Z to right of scratch ==== */
21348 
21349 			dlacpy_("ALL", &jlen, &j2, &z__[jrow + (incol + 1) *
21350 				z_dim1], ldz, &wv[(i2 + 1) * wv_dim1 + 1],
21351 				ldwv);
21352 
21353 /*                    ==== Multiply by U21 ==== */
21354 
21355 			i__5 = i4 - i2;
21356 			dtrmm_("R", "L", "N", "N", &jlen, &i__5, &c_b15, &u[(
21357 				i2 + 1) * u_dim1 + 1], ldu, &wv[(i2 + 1) *
21358 				wv_dim1 + 1], ldwv);
21359 
21360 /*                    ==== Multiply by U22 ==== */
21361 
21362 			i__5 = i4 - i2;
21363 			i__7 = j4 - j2;
21364 			dgemm_("N", "N", &jlen, &i__5, &i__7, &c_b15, &z__[
21365 				jrow + (incol + 1 + j2) * z_dim1], ldz, &u[j2
21366 				+ 1 + (i2 + 1) * u_dim1], ldu, &c_b15, &wv[(
21367 				i2 + 1) * wv_dim1 + 1], ldwv);
21368 
21369 /*                    ==== Copy the result back to Z ==== */
21370 
21371 			dlacpy_("ALL", &jlen, &kdu, &wv[wv_offset], ldwv, &
21372 				z__[jrow + (incol + 1) * z_dim1], ldz);
21373 /* L210: */
21374 		    }
21375 		}
21376 	    }
21377 	}
21378 /* L220: */
21379     }
21380 
21381 /*     ==== End of DLAQR5 ==== */
21382 
21383     return 0;
21384 } /* dlaqr5_ */
21385 
dlarf_(char * side,integer * m,integer * n,doublereal * v,integer * incv,doublereal * tau,doublereal * c__,integer * ldc,doublereal * work)21386 /* Subroutine */ int dlarf_(char *side, integer *m, integer *n, doublereal *v,
21387 	 integer *incv, doublereal *tau, doublereal *c__, integer *ldc,
21388 	doublereal *work)
21389 {
21390     /* System generated locals */
21391     integer c_dim1, c_offset;
21392     doublereal d__1;
21393 
21394     /* Local variables */
21395     static integer i__;
21396     static logical applyleft;
21397     extern /* Subroutine */ int dger_(integer *, integer *, doublereal *,
21398 	    doublereal *, integer *, doublereal *, integer *, doublereal *,
21399 	    integer *);
21400     extern logical lsame_(char *, char *);
21401     extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
21402 	    doublereal *, doublereal *, integer *, doublereal *, integer *,
21403 	    doublereal *, doublereal *, integer *);
21404     static integer lastc, lastv;
21405     extern integer iladlc_(integer *, integer *, doublereal *, integer *),
21406 	    iladlr_(integer *, integer *, doublereal *, integer *);
21407 
21408 
21409 /*
21410     -- LAPACK auxiliary routine (version 3.2) --
21411     -- LAPACK is a software package provided by Univ. of Tennessee,    --
21412     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
21413        November 2006
21414 
21415 
21416     Purpose
21417     =======
21418 
21419     DLARF applies a real elementary reflector H to a real m by n matrix
21420     C, from either the left or the right. H is represented in the form
21421 
21422           H = I - tau * v * v'
21423 
21424     where tau is a real scalar and v is a real vector.
21425 
21426     If tau = 0, then H is taken to be the unit matrix.
21427 
21428     Arguments
21429     =========
21430 
21431     SIDE    (input) CHARACTER*1
21432             = 'L': form  H * C
21433             = 'R': form  C * H
21434 
21435     M       (input) INTEGER
21436             The number of rows of the matrix C.
21437 
21438     N       (input) INTEGER
21439             The number of columns of the matrix C.
21440 
21441     V       (input) DOUBLE PRECISION array, dimension
21442                        (1 + (M-1)*abs(INCV)) if SIDE = 'L'
21443                     or (1 + (N-1)*abs(INCV)) if SIDE = 'R'
21444             The vector v in the representation of H. V is not used if
21445             TAU = 0.
21446 
21447     INCV    (input) INTEGER
21448             The increment between elements of v. INCV <> 0.
21449 
21450     TAU     (input) DOUBLE PRECISION
21451             The value tau in the representation of H.
21452 
21453     C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
21454             On entry, the m by n matrix C.
21455             On exit, C is overwritten by the matrix H * C if SIDE = 'L',
21456             or C * H if SIDE = 'R'.
21457 
21458     LDC     (input) INTEGER
21459             The leading dimension of the array C. LDC >= max(1,M).
21460 
21461     WORK    (workspace) DOUBLE PRECISION array, dimension
21462                            (N) if SIDE = 'L'
21463                         or (M) if SIDE = 'R'
21464 
21465     =====================================================================
21466 */
21467 
21468 
21469     /* Parameter adjustments */
21470     --v;
21471     c_dim1 = *ldc;
21472     c_offset = 1 + c_dim1;
21473     c__ -= c_offset;
21474     --work;
21475 
21476     /* Function Body */
21477     applyleft = lsame_(side, "L");
21478     lastv = 0;
21479     lastc = 0;
21480     if (*tau != 0.) {
21481 /*
21482        Set up variables for scanning V.  LASTV begins pointing to the end
21483        of V.
21484 */
21485 	if (applyleft) {
21486 	    lastv = *m;
21487 	} else {
21488 	    lastv = *n;
21489 	}
21490 	if (*incv > 0) {
21491 	    i__ = (lastv - 1) * *incv + 1;
21492 	} else {
21493 	    i__ = 1;
21494 	}
21495 /*     Look for the last non-zero row in V. */
21496 	while(lastv > 0 && v[i__] == 0.) {
21497 	    --lastv;
21498 	    i__ -= *incv;
21499 	}
21500 	if (applyleft) {
21501 /*     Scan for the last non-zero column in C(1:lastv,:). */
21502 	    lastc = iladlc_(&lastv, n, &c__[c_offset], ldc);
21503 	} else {
21504 /*     Scan for the last non-zero row in C(:,1:lastv). */
21505 	    lastc = iladlr_(m, &lastv, &c__[c_offset], ldc);
21506 	}
21507     }
21508 /*
21509        Note that lastc.eq.0 renders the BLAS operations null; no special
21510        case is needed at this level.
21511 */
21512     if (applyleft) {
21513 
21514 /*        Form  H * C */
21515 
21516 	if (lastv > 0) {
21517 
21518 /*           w(1:lastc,1) := C(1:lastv,1:lastc)' * v(1:lastv,1) */
21519 
21520 	    dgemv_("Transpose", &lastv, &lastc, &c_b15, &c__[c_offset], ldc, &
21521 		    v[1], incv, &c_b29, &work[1], &c__1);
21522 
21523 /*           C(1:lastv,1:lastc) := C(...) - v(1:lastv,1) * w(1:lastc,1)' */
21524 
21525 	    d__1 = -(*tau);
21526 	    dger_(&lastv, &lastc, &d__1, &v[1], incv, &work[1], &c__1, &c__[
21527 		    c_offset], ldc);
21528 	}
21529     } else {
21530 
21531 /*        Form  C * H */
21532 
21533 	if (lastv > 0) {
21534 
21535 /*           w(1:lastc,1) := C(1:lastc,1:lastv) * v(1:lastv,1) */
21536 
21537 	    dgemv_("No transpose", &lastc, &lastv, &c_b15, &c__[c_offset],
21538 		    ldc, &v[1], incv, &c_b29, &work[1], &c__1);
21539 
21540 /*           C(1:lastc,1:lastv) := C(...) - w(1:lastc,1) * v(1:lastv,1)' */
21541 
21542 	    d__1 = -(*tau);
21543 	    dger_(&lastc, &lastv, &d__1, &work[1], &c__1, &v[1], incv, &c__[
21544 		    c_offset], ldc);
21545 	}
21546     }
21547     return 0;
21548 
21549 /*     End of DLARF */
21550 
21551 } /* dlarf_ */
21552 
dlarfb_(char * side,char * trans,char * direct,char * storev,integer * m,integer * n,integer * k,doublereal * v,integer * ldv,doublereal * t,integer * ldt,doublereal * c__,integer * ldc,doublereal * work,integer * ldwork)21553 /* Subroutine */ int dlarfb_(char *side, char *trans, char *direct, char *
21554 	storev, integer *m, integer *n, integer *k, doublereal *v, integer *
21555 	ldv, doublereal *t, integer *ldt, doublereal *c__, integer *ldc,
21556 	doublereal *work, integer *ldwork)
21557 {
21558     /* System generated locals */
21559     integer c_dim1, c_offset, t_dim1, t_offset, v_dim1, v_offset, work_dim1,
21560 	    work_offset, i__1, i__2;
21561 
21562     /* Local variables */
21563     static integer i__, j;
21564     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
21565 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
21566 	    integer *, doublereal *, doublereal *, integer *);
21567     extern logical lsame_(char *, char *);
21568     static integer lastc;
21569     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
21570 	    doublereal *, integer *), dtrmm_(char *, char *, char *, char *,
21571 	    integer *, integer *, doublereal *, doublereal *, integer *,
21572 	    doublereal *, integer *);
21573     static integer lastv;
21574     extern integer iladlc_(integer *, integer *, doublereal *, integer *),
21575 	    iladlr_(integer *, integer *, doublereal *, integer *);
21576     static char transt[1];
21577 
21578 
21579 /*
21580     -- LAPACK auxiliary routine (version 3.2) --
21581     -- LAPACK is a software package provided by Univ. of Tennessee,    --
21582     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
21583        November 2006
21584 
21585 
21586     Purpose
21587     =======
21588 
21589     DLARFB applies a real block reflector H or its transpose H' to a
21590     real m by n matrix C, from either the left or the right.
21591 
21592     Arguments
21593     =========
21594 
21595     SIDE    (input) CHARACTER*1
21596             = 'L': apply H or H' from the Left
21597             = 'R': apply H or H' from the Right
21598 
21599     TRANS   (input) CHARACTER*1
21600             = 'N': apply H (No transpose)
21601             = 'T': apply H' (Transpose)
21602 
21603     DIRECT  (input) CHARACTER*1
21604             Indicates how H is formed from a product of elementary
21605             reflectors
21606             = 'F': H = H(1) H(2) . . . H(k) (Forward)
21607             = 'B': H = H(k) . . . H(2) H(1) (Backward)
21608 
21609     STOREV  (input) CHARACTER*1
21610             Indicates how the vectors which define the elementary
21611             reflectors are stored:
21612             = 'C': Columnwise
21613             = 'R': Rowwise
21614 
21615     M       (input) INTEGER
21616             The number of rows of the matrix C.
21617 
21618     N       (input) INTEGER
21619             The number of columns of the matrix C.
21620 
21621     K       (input) INTEGER
21622             The order of the matrix T (= the number of elementary
21623             reflectors whose product defines the block reflector).
21624 
21625     V       (input) DOUBLE PRECISION array, dimension
21626                                   (LDV,K) if STOREV = 'C'
21627                                   (LDV,M) if STOREV = 'R' and SIDE = 'L'
21628                                   (LDV,N) if STOREV = 'R' and SIDE = 'R'
21629             The matrix V. See further details.
21630 
21631     LDV     (input) INTEGER
21632             The leading dimension of the array V.
21633             If STOREV = 'C' and SIDE = 'L', LDV >= max(1,M);
21634             if STOREV = 'C' and SIDE = 'R', LDV >= max(1,N);
21635             if STOREV = 'R', LDV >= K.
21636 
21637     T       (input) DOUBLE PRECISION array, dimension (LDT,K)
21638             The triangular k by k matrix T in the representation of the
21639             block reflector.
21640 
21641     LDT     (input) INTEGER
21642             The leading dimension of the array T. LDT >= K.
21643 
21644     C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
21645             On entry, the m by n matrix C.
21646             On exit, C is overwritten by H*C or H'*C or C*H or C*H'.
21647 
21648     LDC     (input) INTEGER
21649             The leading dimension of the array C. LDA >= max(1,M).
21650 
21651     WORK    (workspace) DOUBLE PRECISION array, dimension (LDWORK,K)
21652 
21653     LDWORK  (input) INTEGER
21654             The leading dimension of the array WORK.
21655             If SIDE = 'L', LDWORK >= max(1,N);
21656             if SIDE = 'R', LDWORK >= max(1,M).
21657 
21658     =====================================================================
21659 
21660 
21661        Quick return if possible
21662 */
21663 
21664     /* Parameter adjustments */
21665     v_dim1 = *ldv;
21666     v_offset = 1 + v_dim1;
21667     v -= v_offset;
21668     t_dim1 = *ldt;
21669     t_offset = 1 + t_dim1;
21670     t -= t_offset;
21671     c_dim1 = *ldc;
21672     c_offset = 1 + c_dim1;
21673     c__ -= c_offset;
21674     work_dim1 = *ldwork;
21675     work_offset = 1 + work_dim1;
21676     work -= work_offset;
21677 
21678     /* Function Body */
21679     if (*m <= 0 || *n <= 0) {
21680 	return 0;
21681     }
21682 
21683     if (lsame_(trans, "N")) {
21684 	*(unsigned char *)transt = 'T';
21685     } else {
21686 	*(unsigned char *)transt = 'N';
21687     }
21688 
21689     if (lsame_(storev, "C")) {
21690 
21691 	if (lsame_(direct, "F")) {
21692 
21693 /*
21694              Let  V =  ( V1 )    (first K rows)
21695                        ( V2 )
21696              where  V1  is unit lower triangular.
21697 */
21698 
21699 	    if (lsame_(side, "L")) {
21700 
21701 /*
21702                 Form  H * C  or  H' * C  where  C = ( C1 )
21703                                                     ( C2 )
21704 
21705    Computing MAX
21706 */
21707 		i__1 = *k, i__2 = iladlr_(m, k, &v[v_offset], ldv);
21708 		lastv = max(i__1,i__2);
21709 		lastc = iladlc_(&lastv, n, &c__[c_offset], ldc);
21710 
21711 /*
21712                 W := C' * V  =  (C1'*V1 + C2'*V2)  (stored in WORK)
21713 
21714                 W := C1'
21715 */
21716 
21717 		i__1 = *k;
21718 		for (j = 1; j <= i__1; ++j) {
21719 		    dcopy_(&lastc, &c__[j + c_dim1], ldc, &work[j * work_dim1
21720 			    + 1], &c__1);
21721 /* L10: */
21722 		}
21723 
21724 /*              W := W * V1 */
21725 
21726 		dtrmm_("Right", "Lower", "No transpose", "Unit", &lastc, k, &
21727 			c_b15, &v[v_offset], ldv, &work[work_offset], ldwork);
21728 		if (lastv > *k) {
21729 
21730 /*                 W := W + C2'*V2 */
21731 
21732 		    i__1 = lastv - *k;
21733 		    dgemm_("Transpose", "No transpose", &lastc, k, &i__1, &
21734 			    c_b15, &c__[*k + 1 + c_dim1], ldc, &v[*k + 1 +
21735 			    v_dim1], ldv, &c_b15, &work[work_offset], ldwork);
21736 		}
21737 
21738 /*              W := W * T'  or  W * T */
21739 
21740 		dtrmm_("Right", "Upper", transt, "Non-unit", &lastc, k, &
21741 			c_b15, &t[t_offset], ldt, &work[work_offset], ldwork);
21742 
21743 /*              C := C - V * W' */
21744 
21745 		if (lastv > *k) {
21746 
21747 /*                 C2 := C2 - V2 * W' */
21748 
21749 		    i__1 = lastv - *k;
21750 		    dgemm_("No transpose", "Transpose", &i__1, &lastc, k, &
21751 			    c_b151, &v[*k + 1 + v_dim1], ldv, &work[
21752 			    work_offset], ldwork, &c_b15, &c__[*k + 1 +
21753 			    c_dim1], ldc);
21754 		}
21755 
21756 /*              W := W * V1' */
21757 
21758 		dtrmm_("Right", "Lower", "Transpose", "Unit", &lastc, k, &
21759 			c_b15, &v[v_offset], ldv, &work[work_offset], ldwork);
21760 
21761 /*              C1 := C1 - W' */
21762 
21763 		i__1 = *k;
21764 		for (j = 1; j <= i__1; ++j) {
21765 		    i__2 = lastc;
21766 		    for (i__ = 1; i__ <= i__2; ++i__) {
21767 			c__[j + i__ * c_dim1] -= work[i__ + j * work_dim1];
21768 /* L20: */
21769 		    }
21770 /* L30: */
21771 		}
21772 
21773 	    } else if (lsame_(side, "R")) {
21774 
21775 /*
21776                 Form  C * H  or  C * H'  where  C = ( C1  C2 )
21777 
21778    Computing MAX
21779 */
21780 		i__1 = *k, i__2 = iladlr_(n, k, &v[v_offset], ldv);
21781 		lastv = max(i__1,i__2);
21782 		lastc = iladlr_(m, &lastv, &c__[c_offset], ldc);
21783 
21784 /*
21785                 W := C * V  =  (C1*V1 + C2*V2)  (stored in WORK)
21786 
21787                 W := C1
21788 */
21789 
21790 		i__1 = *k;
21791 		for (j = 1; j <= i__1; ++j) {
21792 		    dcopy_(&lastc, &c__[j * c_dim1 + 1], &c__1, &work[j *
21793 			    work_dim1 + 1], &c__1);
21794 /* L40: */
21795 		}
21796 
21797 /*              W := W * V1 */
21798 
21799 		dtrmm_("Right", "Lower", "No transpose", "Unit", &lastc, k, &
21800 			c_b15, &v[v_offset], ldv, &work[work_offset], ldwork);
21801 		if (lastv > *k) {
21802 
21803 /*                 W := W + C2 * V2 */
21804 
21805 		    i__1 = lastv - *k;
21806 		    dgemm_("No transpose", "No transpose", &lastc, k, &i__1, &
21807 			    c_b15, &c__[(*k + 1) * c_dim1 + 1], ldc, &v[*k +
21808 			    1 + v_dim1], ldv, &c_b15, &work[work_offset],
21809 			    ldwork);
21810 		}
21811 
21812 /*              W := W * T  or  W * T' */
21813 
21814 		dtrmm_("Right", "Upper", trans, "Non-unit", &lastc, k, &c_b15,
21815 			 &t[t_offset], ldt, &work[work_offset], ldwork);
21816 
21817 /*              C := C - W * V' */
21818 
21819 		if (lastv > *k) {
21820 
21821 /*                 C2 := C2 - W * V2' */
21822 
21823 		    i__1 = lastv - *k;
21824 		    dgemm_("No transpose", "Transpose", &lastc, &i__1, k, &
21825 			    c_b151, &work[work_offset], ldwork, &v[*k + 1 +
21826 			    v_dim1], ldv, &c_b15, &c__[(*k + 1) * c_dim1 + 1],
21827 			     ldc);
21828 		}
21829 
21830 /*              W := W * V1' */
21831 
21832 		dtrmm_("Right", "Lower", "Transpose", "Unit", &lastc, k, &
21833 			c_b15, &v[v_offset], ldv, &work[work_offset], ldwork);
21834 
21835 /*              C1 := C1 - W */
21836 
21837 		i__1 = *k;
21838 		for (j = 1; j <= i__1; ++j) {
21839 		    i__2 = lastc;
21840 		    for (i__ = 1; i__ <= i__2; ++i__) {
21841 			c__[i__ + j * c_dim1] -= work[i__ + j * work_dim1];
21842 /* L50: */
21843 		    }
21844 /* L60: */
21845 		}
21846 	    }
21847 
21848 	} else {
21849 
21850 /*
21851              Let  V =  ( V1 )
21852                        ( V2 )    (last K rows)
21853              where  V2  is unit upper triangular.
21854 */
21855 
21856 	    if (lsame_(side, "L")) {
21857 
21858 /*
21859                 Form  H * C  or  H' * C  where  C = ( C1 )
21860                                                     ( C2 )
21861 
21862    Computing MAX
21863 */
21864 		i__1 = *k, i__2 = iladlr_(m, k, &v[v_offset], ldv);
21865 		lastv = max(i__1,i__2);
21866 		lastc = iladlc_(&lastv, n, &c__[c_offset], ldc);
21867 
21868 /*
21869                 W := C' * V  =  (C1'*V1 + C2'*V2)  (stored in WORK)
21870 
21871                 W := C2'
21872 */
21873 
21874 		i__1 = *k;
21875 		for (j = 1; j <= i__1; ++j) {
21876 		    dcopy_(&lastc, &c__[lastv - *k + j + c_dim1], ldc, &work[
21877 			    j * work_dim1 + 1], &c__1);
21878 /* L70: */
21879 		}
21880 
21881 /*              W := W * V2 */
21882 
21883 		dtrmm_("Right", "Upper", "No transpose", "Unit", &lastc, k, &
21884 			c_b15, &v[lastv - *k + 1 + v_dim1], ldv, &work[
21885 			work_offset], ldwork);
21886 		if (lastv > *k) {
21887 
21888 /*                 W := W + C1'*V1 */
21889 
21890 		    i__1 = lastv - *k;
21891 		    dgemm_("Transpose", "No transpose", &lastc, k, &i__1, &
21892 			    c_b15, &c__[c_offset], ldc, &v[v_offset], ldv, &
21893 			    c_b15, &work[work_offset], ldwork);
21894 		}
21895 
21896 /*              W := W * T'  or  W * T */
21897 
21898 		dtrmm_("Right", "Lower", transt, "Non-unit", &lastc, k, &
21899 			c_b15, &t[t_offset], ldt, &work[work_offset], ldwork);
21900 
21901 /*              C := C - V * W' */
21902 
21903 		if (lastv > *k) {
21904 
21905 /*                 C1 := C1 - V1 * W' */
21906 
21907 		    i__1 = lastv - *k;
21908 		    dgemm_("No transpose", "Transpose", &i__1, &lastc, k, &
21909 			    c_b151, &v[v_offset], ldv, &work[work_offset],
21910 			    ldwork, &c_b15, &c__[c_offset], ldc);
21911 		}
21912 
21913 /*              W := W * V2' */
21914 
21915 		dtrmm_("Right", "Upper", "Transpose", "Unit", &lastc, k, &
21916 			c_b15, &v[lastv - *k + 1 + v_dim1], ldv, &work[
21917 			work_offset], ldwork);
21918 
21919 /*              C2 := C2 - W' */
21920 
21921 		i__1 = *k;
21922 		for (j = 1; j <= i__1; ++j) {
21923 		    i__2 = lastc;
21924 		    for (i__ = 1; i__ <= i__2; ++i__) {
21925 			c__[lastv - *k + j + i__ * c_dim1] -= work[i__ + j *
21926 				work_dim1];
21927 /* L80: */
21928 		    }
21929 /* L90: */
21930 		}
21931 
21932 	    } else if (lsame_(side, "R")) {
21933 
21934 /*
21935                 Form  C * H  or  C * H'  where  C = ( C1  C2 )
21936 
21937    Computing MAX
21938 */
21939 		i__1 = *k, i__2 = iladlr_(n, k, &v[v_offset], ldv);
21940 		lastv = max(i__1,i__2);
21941 		lastc = iladlr_(m, &lastv, &c__[c_offset], ldc);
21942 
21943 /*
21944                 W := C * V  =  (C1*V1 + C2*V2)  (stored in WORK)
21945 
21946                 W := C2
21947 */
21948 
21949 		i__1 = *k;
21950 		for (j = 1; j <= i__1; ++j) {
21951 		    dcopy_(&lastc, &c__[(*n - *k + j) * c_dim1 + 1], &c__1, &
21952 			    work[j * work_dim1 + 1], &c__1);
21953 /* L100: */
21954 		}
21955 
21956 /*              W := W * V2 */
21957 
21958 		dtrmm_("Right", "Upper", "No transpose", "Unit", &lastc, k, &
21959 			c_b15, &v[lastv - *k + 1 + v_dim1], ldv, &work[
21960 			work_offset], ldwork);
21961 		if (lastv > *k) {
21962 
21963 /*                 W := W + C1 * V1 */
21964 
21965 		    i__1 = lastv - *k;
21966 		    dgemm_("No transpose", "No transpose", &lastc, k, &i__1, &
21967 			    c_b15, &c__[c_offset], ldc, &v[v_offset], ldv, &
21968 			    c_b15, &work[work_offset], ldwork);
21969 		}
21970 
21971 /*              W := W * T  or  W * T' */
21972 
21973 		dtrmm_("Right", "Lower", trans, "Non-unit", &lastc, k, &c_b15,
21974 			 &t[t_offset], ldt, &work[work_offset], ldwork);
21975 
21976 /*              C := C - W * V' */
21977 
21978 		if (lastv > *k) {
21979 
21980 /*                 C1 := C1 - W * V1' */
21981 
21982 		    i__1 = lastv - *k;
21983 		    dgemm_("No transpose", "Transpose", &lastc, &i__1, k, &
21984 			    c_b151, &work[work_offset], ldwork, &v[v_offset],
21985 			    ldv, &c_b15, &c__[c_offset], ldc);
21986 		}
21987 
21988 /*              W := W * V2' */
21989 
21990 		dtrmm_("Right", "Upper", "Transpose", "Unit", &lastc, k, &
21991 			c_b15, &v[lastv - *k + 1 + v_dim1], ldv, &work[
21992 			work_offset], ldwork);
21993 
21994 /*              C2 := C2 - W */
21995 
21996 		i__1 = *k;
21997 		for (j = 1; j <= i__1; ++j) {
21998 		    i__2 = lastc;
21999 		    for (i__ = 1; i__ <= i__2; ++i__) {
22000 			c__[i__ + (lastv - *k + j) * c_dim1] -= work[i__ + j *
22001 				 work_dim1];
22002 /* L110: */
22003 		    }
22004 /* L120: */
22005 		}
22006 	    }
22007 	}
22008 
22009     } else if (lsame_(storev, "R")) {
22010 
22011 	if (lsame_(direct, "F")) {
22012 
22013 /*
22014              Let  V =  ( V1  V2 )    (V1: first K columns)
22015              where  V1  is unit upper triangular.
22016 */
22017 
22018 	    if (lsame_(side, "L")) {
22019 
22020 /*
22021                 Form  H * C  or  H' * C  where  C = ( C1 )
22022                                                     ( C2 )
22023 
22024    Computing MAX
22025 */
22026 		i__1 = *k, i__2 = iladlc_(k, m, &v[v_offset], ldv);
22027 		lastv = max(i__1,i__2);
22028 		lastc = iladlc_(&lastv, n, &c__[c_offset], ldc);
22029 
22030 /*
22031                 W := C' * V'  =  (C1'*V1' + C2'*V2') (stored in WORK)
22032 
22033                 W := C1'
22034 */
22035 
22036 		i__1 = *k;
22037 		for (j = 1; j <= i__1; ++j) {
22038 		    dcopy_(&lastc, &c__[j + c_dim1], ldc, &work[j * work_dim1
22039 			    + 1], &c__1);
22040 /* L130: */
22041 		}
22042 
22043 /*              W := W * V1' */
22044 
22045 		dtrmm_("Right", "Upper", "Transpose", "Unit", &lastc, k, &
22046 			c_b15, &v[v_offset], ldv, &work[work_offset], ldwork);
22047 		if (lastv > *k) {
22048 
22049 /*                 W := W + C2'*V2' */
22050 
22051 		    i__1 = lastv - *k;
22052 		    dgemm_("Transpose", "Transpose", &lastc, k, &i__1, &c_b15,
22053 			     &c__[*k + 1 + c_dim1], ldc, &v[(*k + 1) * v_dim1
22054 			    + 1], ldv, &c_b15, &work[work_offset], ldwork);
22055 		}
22056 
22057 /*              W := W * T'  or  W * T */
22058 
22059 		dtrmm_("Right", "Upper", transt, "Non-unit", &lastc, k, &
22060 			c_b15, &t[t_offset], ldt, &work[work_offset], ldwork);
22061 
22062 /*              C := C - V' * W' */
22063 
22064 		if (lastv > *k) {
22065 
22066 /*                 C2 := C2 - V2' * W' */
22067 
22068 		    i__1 = lastv - *k;
22069 		    dgemm_("Transpose", "Transpose", &i__1, &lastc, k, &
22070 			    c_b151, &v[(*k + 1) * v_dim1 + 1], ldv, &work[
22071 			    work_offset], ldwork, &c_b15, &c__[*k + 1 +
22072 			    c_dim1], ldc);
22073 		}
22074 
22075 /*              W := W * V1 */
22076 
22077 		dtrmm_("Right", "Upper", "No transpose", "Unit", &lastc, k, &
22078 			c_b15, &v[v_offset], ldv, &work[work_offset], ldwork);
22079 
22080 /*              C1 := C1 - W' */
22081 
22082 		i__1 = *k;
22083 		for (j = 1; j <= i__1; ++j) {
22084 		    i__2 = lastc;
22085 		    for (i__ = 1; i__ <= i__2; ++i__) {
22086 			c__[j + i__ * c_dim1] -= work[i__ + j * work_dim1];
22087 /* L140: */
22088 		    }
22089 /* L150: */
22090 		}
22091 
22092 	    } else if (lsame_(side, "R")) {
22093 
22094 /*
22095                 Form  C * H  or  C * H'  where  C = ( C1  C2 )
22096 
22097    Computing MAX
22098 */
22099 		i__1 = *k, i__2 = iladlc_(k, n, &v[v_offset], ldv);
22100 		lastv = max(i__1,i__2);
22101 		lastc = iladlr_(m, &lastv, &c__[c_offset], ldc);
22102 
22103 /*
22104                 W := C * V'  =  (C1*V1' + C2*V2')  (stored in WORK)
22105 
22106                 W := C1
22107 */
22108 
22109 		i__1 = *k;
22110 		for (j = 1; j <= i__1; ++j) {
22111 		    dcopy_(&lastc, &c__[j * c_dim1 + 1], &c__1, &work[j *
22112 			    work_dim1 + 1], &c__1);
22113 /* L160: */
22114 		}
22115 
22116 /*              W := W * V1' */
22117 
22118 		dtrmm_("Right", "Upper", "Transpose", "Unit", &lastc, k, &
22119 			c_b15, &v[v_offset], ldv, &work[work_offset], ldwork);
22120 		if (lastv > *k) {
22121 
22122 /*                 W := W + C2 * V2' */
22123 
22124 		    i__1 = lastv - *k;
22125 		    dgemm_("No transpose", "Transpose", &lastc, k, &i__1, &
22126 			    c_b15, &c__[(*k + 1) * c_dim1 + 1], ldc, &v[(*k +
22127 			    1) * v_dim1 + 1], ldv, &c_b15, &work[work_offset],
22128 			     ldwork);
22129 		}
22130 
22131 /*              W := W * T  or  W * T' */
22132 
22133 		dtrmm_("Right", "Upper", trans, "Non-unit", &lastc, k, &c_b15,
22134 			 &t[t_offset], ldt, &work[work_offset], ldwork);
22135 
22136 /*              C := C - W * V */
22137 
22138 		if (lastv > *k) {
22139 
22140 /*                 C2 := C2 - W * V2 */
22141 
22142 		    i__1 = lastv - *k;
22143 		    dgemm_("No transpose", "No transpose", &lastc, &i__1, k, &
22144 			    c_b151, &work[work_offset], ldwork, &v[(*k + 1) *
22145 			    v_dim1 + 1], ldv, &c_b15, &c__[(*k + 1) * c_dim1
22146 			    + 1], ldc);
22147 		}
22148 
22149 /*              W := W * V1 */
22150 
22151 		dtrmm_("Right", "Upper", "No transpose", "Unit", &lastc, k, &
22152 			c_b15, &v[v_offset], ldv, &work[work_offset], ldwork);
22153 
22154 /*              C1 := C1 - W */
22155 
22156 		i__1 = *k;
22157 		for (j = 1; j <= i__1; ++j) {
22158 		    i__2 = lastc;
22159 		    for (i__ = 1; i__ <= i__2; ++i__) {
22160 			c__[i__ + j * c_dim1] -= work[i__ + j * work_dim1];
22161 /* L170: */
22162 		    }
22163 /* L180: */
22164 		}
22165 
22166 	    }
22167 
22168 	} else {
22169 
22170 /*
22171              Let  V =  ( V1  V2 )    (V2: last K columns)
22172              where  V2  is unit lower triangular.
22173 */
22174 
22175 	    if (lsame_(side, "L")) {
22176 
22177 /*
22178                 Form  H * C  or  H' * C  where  C = ( C1 )
22179                                                     ( C2 )
22180 
22181    Computing MAX
22182 */
22183 		i__1 = *k, i__2 = iladlc_(k, m, &v[v_offset], ldv);
22184 		lastv = max(i__1,i__2);
22185 		lastc = iladlc_(&lastv, n, &c__[c_offset], ldc);
22186 
22187 /*
22188                 W := C' * V'  =  (C1'*V1' + C2'*V2') (stored in WORK)
22189 
22190                 W := C2'
22191 */
22192 
22193 		i__1 = *k;
22194 		for (j = 1; j <= i__1; ++j) {
22195 		    dcopy_(&lastc, &c__[lastv - *k + j + c_dim1], ldc, &work[
22196 			    j * work_dim1 + 1], &c__1);
22197 /* L190: */
22198 		}
22199 
22200 /*              W := W * V2' */
22201 
22202 		dtrmm_("Right", "Lower", "Transpose", "Unit", &lastc, k, &
22203 			c_b15, &v[(lastv - *k + 1) * v_dim1 + 1], ldv, &work[
22204 			work_offset], ldwork);
22205 		if (lastv > *k) {
22206 
22207 /*                 W := W + C1'*V1' */
22208 
22209 		    i__1 = lastv - *k;
22210 		    dgemm_("Transpose", "Transpose", &lastc, k, &i__1, &c_b15,
22211 			     &c__[c_offset], ldc, &v[v_offset], ldv, &c_b15, &
22212 			    work[work_offset], ldwork);
22213 		}
22214 
22215 /*              W := W * T'  or  W * T */
22216 
22217 		dtrmm_("Right", "Lower", transt, "Non-unit", &lastc, k, &
22218 			c_b15, &t[t_offset], ldt, &work[work_offset], ldwork);
22219 
22220 /*              C := C - V' * W' */
22221 
22222 		if (lastv > *k) {
22223 
22224 /*                 C1 := C1 - V1' * W' */
22225 
22226 		    i__1 = lastv - *k;
22227 		    dgemm_("Transpose", "Transpose", &i__1, &lastc, k, &
22228 			    c_b151, &v[v_offset], ldv, &work[work_offset],
22229 			    ldwork, &c_b15, &c__[c_offset], ldc);
22230 		}
22231 
22232 /*              W := W * V2 */
22233 
22234 		dtrmm_("Right", "Lower", "No transpose", "Unit", &lastc, k, &
22235 			c_b15, &v[(lastv - *k + 1) * v_dim1 + 1], ldv, &work[
22236 			work_offset], ldwork);
22237 
22238 /*              C2 := C2 - W' */
22239 
22240 		i__1 = *k;
22241 		for (j = 1; j <= i__1; ++j) {
22242 		    i__2 = lastc;
22243 		    for (i__ = 1; i__ <= i__2; ++i__) {
22244 			c__[lastv - *k + j + i__ * c_dim1] -= work[i__ + j *
22245 				work_dim1];
22246 /* L200: */
22247 		    }
22248 /* L210: */
22249 		}
22250 
22251 	    } else if (lsame_(side, "R")) {
22252 
22253 /*
22254                 Form  C * H  or  C * H'  where  C = ( C1  C2 )
22255 
22256    Computing MAX
22257 */
22258 		i__1 = *k, i__2 = iladlc_(k, n, &v[v_offset], ldv);
22259 		lastv = max(i__1,i__2);
22260 		lastc = iladlr_(m, &lastv, &c__[c_offset], ldc);
22261 
22262 /*
22263                 W := C * V'  =  (C1*V1' + C2*V2')  (stored in WORK)
22264 
22265                 W := C2
22266 */
22267 
22268 		i__1 = *k;
22269 		for (j = 1; j <= i__1; ++j) {
22270 		    dcopy_(&lastc, &c__[(lastv - *k + j) * c_dim1 + 1], &c__1,
22271 			     &work[j * work_dim1 + 1], &c__1);
22272 /* L220: */
22273 		}
22274 
22275 /*              W := W * V2' */
22276 
22277 		dtrmm_("Right", "Lower", "Transpose", "Unit", &lastc, k, &
22278 			c_b15, &v[(lastv - *k + 1) * v_dim1 + 1], ldv, &work[
22279 			work_offset], ldwork);
22280 		if (lastv > *k) {
22281 
22282 /*                 W := W + C1 * V1' */
22283 
22284 		    i__1 = lastv - *k;
22285 		    dgemm_("No transpose", "Transpose", &lastc, k, &i__1, &
22286 			    c_b15, &c__[c_offset], ldc, &v[v_offset], ldv, &
22287 			    c_b15, &work[work_offset], ldwork);
22288 		}
22289 
22290 /*              W := W * T  or  W * T' */
22291 
22292 		dtrmm_("Right", "Lower", trans, "Non-unit", &lastc, k, &c_b15,
22293 			 &t[t_offset], ldt, &work[work_offset], ldwork);
22294 
22295 /*              C := C - W * V */
22296 
22297 		if (lastv > *k) {
22298 
22299 /*                 C1 := C1 - W * V1 */
22300 
22301 		    i__1 = lastv - *k;
22302 		    dgemm_("No transpose", "No transpose", &lastc, &i__1, k, &
22303 			    c_b151, &work[work_offset], ldwork, &v[v_offset],
22304 			    ldv, &c_b15, &c__[c_offset], ldc);
22305 		}
22306 
22307 /*              W := W * V2 */
22308 
22309 		dtrmm_("Right", "Lower", "No transpose", "Unit", &lastc, k, &
22310 			c_b15, &v[(lastv - *k + 1) * v_dim1 + 1], ldv, &work[
22311 			work_offset], ldwork);
22312 
22313 /*              C1 := C1 - W */
22314 
22315 		i__1 = *k;
22316 		for (j = 1; j <= i__1; ++j) {
22317 		    i__2 = lastc;
22318 		    for (i__ = 1; i__ <= i__2; ++i__) {
22319 			c__[i__ + (lastv - *k + j) * c_dim1] -= work[i__ + j *
22320 				 work_dim1];
22321 /* L230: */
22322 		    }
22323 /* L240: */
22324 		}
22325 
22326 	    }
22327 
22328 	}
22329     }
22330 
22331     return 0;
22332 
22333 /*     End of DLARFB */
22334 
22335 } /* dlarfb_ */
22336 
dlarfg_(integer * n,doublereal * alpha,doublereal * x,integer * incx,doublereal * tau)22337 /* Subroutine */ int dlarfg_(integer *n, doublereal *alpha, doublereal *x,
22338 	integer *incx, doublereal *tau)
22339 {
22340     /* System generated locals */
22341     integer i__1;
22342     doublereal d__1;
22343 
22344     /* Local variables */
22345     static integer j, knt;
22346     static doublereal beta;
22347     extern doublereal dnrm2_(integer *, doublereal *, integer *);
22348     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
22349 	    integer *);
22350     static doublereal xnorm;
22351 
22352     static doublereal safmin, rsafmn;
22353 
22354 
22355 /*
22356     -- LAPACK auxiliary routine (version 3.2) --
22357     -- LAPACK is a software package provided by Univ. of Tennessee,    --
22358     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
22359        November 2006
22360 
22361 
22362     Purpose
22363     =======
22364 
22365     DLARFG generates a real elementary reflector H of order n, such
22366     that
22367 
22368           H * ( alpha ) = ( beta ),   H' * H = I.
22369               (   x   )   (   0  )
22370 
22371     where alpha and beta are scalars, and x is an (n-1)-element real
22372     vector. H is represented in the form
22373 
22374           H = I - tau * ( 1 ) * ( 1 v' ) ,
22375                         ( v )
22376 
22377     where tau is a real scalar and v is a real (n-1)-element
22378     vector.
22379 
22380     If the elements of x are all zero, then tau = 0 and H is taken to be
22381     the unit matrix.
22382 
22383     Otherwise  1 <= tau <= 2.
22384 
22385     Arguments
22386     =========
22387 
22388     N       (input) INTEGER
22389             The order of the elementary reflector.
22390 
22391     ALPHA   (input/output) DOUBLE PRECISION
22392             On entry, the value alpha.
22393             On exit, it is overwritten with the value beta.
22394 
22395     X       (input/output) DOUBLE PRECISION array, dimension
22396                            (1+(N-2)*abs(INCX))
22397             On entry, the vector x.
22398             On exit, it is overwritten with the vector v.
22399 
22400     INCX    (input) INTEGER
22401             The increment between elements of X. INCX > 0.
22402 
22403     TAU     (output) DOUBLE PRECISION
22404             The value tau.
22405 
22406     =====================================================================
22407 */
22408 
22409 
22410     /* Parameter adjustments */
22411     --x;
22412 
22413     /* Function Body */
22414     if (*n <= 1) {
22415 	*tau = 0.;
22416 	return 0;
22417     }
22418 
22419     i__1 = *n - 1;
22420     xnorm = dnrm2_(&i__1, &x[1], incx);
22421 
22422     if (xnorm == 0.) {
22423 
22424 /*        H  =  I */
22425 
22426 	*tau = 0.;
22427     } else {
22428 
22429 /*        general case */
22430 
22431 	d__1 = dlapy2_(alpha, &xnorm);
22432 	beta = -d_sign(&d__1, alpha);
22433 	safmin = SAFEMINIMUM / EPSILON;
22434 	knt = 0;
22435 	if (abs(beta) < safmin) {
22436 
22437 /*           XNORM, BETA may be inaccurate; scale X and recompute them */
22438 
22439 	    rsafmn = 1. / safmin;
22440 L10:
22441 	    ++knt;
22442 	    i__1 = *n - 1;
22443 	    dscal_(&i__1, &rsafmn, &x[1], incx);
22444 	    beta *= rsafmn;
22445 	    *alpha *= rsafmn;
22446 	    if (abs(beta) < safmin) {
22447 		goto L10;
22448 	    }
22449 
22450 /*           New BETA is at most 1, at least SAFMIN */
22451 
22452 	    i__1 = *n - 1;
22453 	    xnorm = dnrm2_(&i__1, &x[1], incx);
22454 	    d__1 = dlapy2_(alpha, &xnorm);
22455 	    beta = -d_sign(&d__1, alpha);
22456 	}
22457 	*tau = (beta - *alpha) / beta;
22458 	i__1 = *n - 1;
22459 	d__1 = 1. / (*alpha - beta);
22460 	dscal_(&i__1, &d__1, &x[1], incx);
22461 
22462 /*        If ALPHA is subnormal, it may lose relative accuracy */
22463 
22464 	i__1 = knt;
22465 	for (j = 1; j <= i__1; ++j) {
22466 	    beta *= safmin;
22467 /* L20: */
22468 	}
22469 	*alpha = beta;
22470     }
22471 
22472     return 0;
22473 
22474 /*     End of DLARFG */
22475 
22476 } /* dlarfg_ */
22477 
dlarft_(char * direct,char * storev,integer * n,integer * k,doublereal * v,integer * ldv,doublereal * tau,doublereal * t,integer * ldt)22478 /* Subroutine */ int dlarft_(char *direct, char *storev, integer *n, integer *
22479 	k, doublereal *v, integer *ldv, doublereal *tau, doublereal *t,
22480 	integer *ldt)
22481 {
22482     /* System generated locals */
22483     integer t_dim1, t_offset, v_dim1, v_offset, i__1, i__2, i__3;
22484     doublereal d__1;
22485 
22486     /* Local variables */
22487     static integer i__, j, prevlastv;
22488     static doublereal vii;
22489     extern logical lsame_(char *, char *);
22490     extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
22491 	    doublereal *, doublereal *, integer *, doublereal *, integer *,
22492 	    doublereal *, doublereal *, integer *);
22493     static integer lastv;
22494     extern /* Subroutine */ int dtrmv_(char *, char *, char *, integer *,
22495 	    doublereal *, integer *, doublereal *, integer *);
22496 
22497 
22498 /*
22499     -- LAPACK auxiliary routine (version 3.2) --
22500     -- LAPACK is a software package provided by Univ. of Tennessee,    --
22501     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
22502        November 2006
22503 
22504 
22505     Purpose
22506     =======
22507 
22508     DLARFT forms the triangular factor T of a real block reflector H
22509     of order n, which is defined as a product of k elementary reflectors.
22510 
22511     If DIRECT = 'F', H = H(1) H(2) . . . H(k) and T is upper triangular;
22512 
22513     If DIRECT = 'B', H = H(k) . . . H(2) H(1) and T is lower triangular.
22514 
22515     If STOREV = 'C', the vector which defines the elementary reflector
22516     H(i) is stored in the i-th column of the array V, and
22517 
22518        H  =  I - V * T * V'
22519 
22520     If STOREV = 'R', the vector which defines the elementary reflector
22521     H(i) is stored in the i-th row of the array V, and
22522 
22523        H  =  I - V' * T * V
22524 
22525     Arguments
22526     =========
22527 
22528     DIRECT  (input) CHARACTER*1
22529             Specifies the order in which the elementary reflectors are
22530             multiplied to form the block reflector:
22531             = 'F': H = H(1) H(2) . . . H(k) (Forward)
22532             = 'B': H = H(k) . . . H(2) H(1) (Backward)
22533 
22534     STOREV  (input) CHARACTER*1
22535             Specifies how the vectors which define the elementary
22536             reflectors are stored (see also Further Details):
22537             = 'C': columnwise
22538             = 'R': rowwise
22539 
22540     N       (input) INTEGER
22541             The order of the block reflector H. N >= 0.
22542 
22543     K       (input) INTEGER
22544             The order of the triangular factor T (= the number of
22545             elementary reflectors). K >= 1.
22546 
22547     V       (input/output) DOUBLE PRECISION array, dimension
22548                                  (LDV,K) if STOREV = 'C'
22549                                  (LDV,N) if STOREV = 'R'
22550             The matrix V. See further details.
22551 
22552     LDV     (input) INTEGER
22553             The leading dimension of the array V.
22554             If STOREV = 'C', LDV >= max(1,N); if STOREV = 'R', LDV >= K.
22555 
22556     TAU     (input) DOUBLE PRECISION array, dimension (K)
22557             TAU(i) must contain the scalar factor of the elementary
22558             reflector H(i).
22559 
22560     T       (output) DOUBLE PRECISION array, dimension (LDT,K)
22561             The k by k triangular factor T of the block reflector.
22562             If DIRECT = 'F', T is upper triangular; if DIRECT = 'B', T is
22563             lower triangular. The rest of the array is not used.
22564 
22565     LDT     (input) INTEGER
22566             The leading dimension of the array T. LDT >= K.
22567 
22568     Further Details
22569     ===============
22570 
22571     The shape of the matrix V and the storage of the vectors which define
22572     the H(i) is best illustrated by the following example with n = 5 and
22573     k = 3. The elements equal to 1 are not stored; the corresponding
22574     array elements are modified but restored on exit. The rest of the
22575     array is not used.
22576 
22577     DIRECT = 'F' and STOREV = 'C':         DIRECT = 'F' and STOREV = 'R':
22578 
22579                  V = (  1       )                 V = (  1 v1 v1 v1 v1 )
22580                      ( v1  1    )                     (     1 v2 v2 v2 )
22581                      ( v1 v2  1 )                     (        1 v3 v3 )
22582                      ( v1 v2 v3 )
22583                      ( v1 v2 v3 )
22584 
22585     DIRECT = 'B' and STOREV = 'C':         DIRECT = 'B' and STOREV = 'R':
22586 
22587                  V = ( v1 v2 v3 )                 V = ( v1 v1  1       )
22588                      ( v1 v2 v3 )                     ( v2 v2 v2  1    )
22589                      (  1 v2 v3 )                     ( v3 v3 v3 v3  1 )
22590                      (     1 v3 )
22591                      (        1 )
22592 
22593     =====================================================================
22594 
22595 
22596        Quick return if possible
22597 */
22598 
22599     /* Parameter adjustments */
22600     v_dim1 = *ldv;
22601     v_offset = 1 + v_dim1;
22602     v -= v_offset;
22603     --tau;
22604     t_dim1 = *ldt;
22605     t_offset = 1 + t_dim1;
22606     t -= t_offset;
22607 
22608     /* Function Body */
22609     if (*n == 0) {
22610 	return 0;
22611     }
22612 
22613     if (lsame_(direct, "F")) {
22614 	prevlastv = *n;
22615 	i__1 = *k;
22616 	for (i__ = 1; i__ <= i__1; ++i__) {
22617 	    prevlastv = max(i__,prevlastv);
22618 	    if (tau[i__] == 0.) {
22619 
22620 /*              H(i)  =  I */
22621 
22622 		i__2 = i__;
22623 		for (j = 1; j <= i__2; ++j) {
22624 		    t[j + i__ * t_dim1] = 0.;
22625 /* L10: */
22626 		}
22627 	    } else {
22628 
22629 /*              general case */
22630 
22631 		vii = v[i__ + i__ * v_dim1];
22632 		v[i__ + i__ * v_dim1] = 1.;
22633 		if (lsame_(storev, "C")) {
22634 /*                 Skip any trailing zeros. */
22635 		    i__2 = i__ + 1;
22636 		    for (lastv = *n; lastv >= i__2; --lastv) {
22637 			if (v[lastv + i__ * v_dim1] != 0.) {
22638 			    goto L15;
22639 			}
22640 		    }
22641 L15:
22642 		    j = min(lastv,prevlastv);
22643 
22644 /*                 T(1:i-1,i) := - tau(i) * V(i:j,1:i-1)' * V(i:j,i) */
22645 
22646 		    i__2 = j - i__ + 1;
22647 		    i__3 = i__ - 1;
22648 		    d__1 = -tau[i__];
22649 		    dgemv_("Transpose", &i__2, &i__3, &d__1, &v[i__ + v_dim1],
22650 			     ldv, &v[i__ + i__ * v_dim1], &c__1, &c_b29, &t[
22651 			    i__ * t_dim1 + 1], &c__1);
22652 		} else {
22653 /*                 Skip any trailing zeros. */
22654 		    i__2 = i__ + 1;
22655 		    for (lastv = *n; lastv >= i__2; --lastv) {
22656 			if (v[i__ + lastv * v_dim1] != 0.) {
22657 			    goto L16;
22658 			}
22659 		    }
22660 L16:
22661 		    j = min(lastv,prevlastv);
22662 
22663 /*                 T(1:i-1,i) := - tau(i) * V(1:i-1,i:j) * V(i,i:j)' */
22664 
22665 		    i__2 = i__ - 1;
22666 		    i__3 = j - i__ + 1;
22667 		    d__1 = -tau[i__];
22668 		    dgemv_("No transpose", &i__2, &i__3, &d__1, &v[i__ *
22669 			    v_dim1 + 1], ldv, &v[i__ + i__ * v_dim1], ldv, &
22670 			    c_b29, &t[i__ * t_dim1 + 1], &c__1);
22671 		}
22672 		v[i__ + i__ * v_dim1] = vii;
22673 
22674 /*              T(1:i-1,i) := T(1:i-1,1:i-1) * T(1:i-1,i) */
22675 
22676 		i__2 = i__ - 1;
22677 		dtrmv_("Upper", "No transpose", "Non-unit", &i__2, &t[
22678 			t_offset], ldt, &t[i__ * t_dim1 + 1], &c__1);
22679 		t[i__ + i__ * t_dim1] = tau[i__];
22680 		if (i__ > 1) {
22681 		    prevlastv = max(prevlastv,lastv);
22682 		} else {
22683 		    prevlastv = lastv;
22684 		}
22685 	    }
22686 /* L20: */
22687 	}
22688     } else {
22689 	prevlastv = 1;
22690 	for (i__ = *k; i__ >= 1; --i__) {
22691 	    if (tau[i__] == 0.) {
22692 
22693 /*              H(i)  =  I */
22694 
22695 		i__1 = *k;
22696 		for (j = i__; j <= i__1; ++j) {
22697 		    t[j + i__ * t_dim1] = 0.;
22698 /* L30: */
22699 		}
22700 	    } else {
22701 
22702 /*              general case */
22703 
22704 		if (i__ < *k) {
22705 		    if (lsame_(storev, "C")) {
22706 			vii = v[*n - *k + i__ + i__ * v_dim1];
22707 			v[*n - *k + i__ + i__ * v_dim1] = 1.;
22708 /*                    Skip any leading zeros. */
22709 			i__1 = i__ - 1;
22710 			for (lastv = 1; lastv <= i__1; ++lastv) {
22711 			    if (v[lastv + i__ * v_dim1] != 0.) {
22712 				goto L35;
22713 			    }
22714 			}
22715 L35:
22716 			j = max(lastv,prevlastv);
22717 
22718 /*
22719                       T(i+1:k,i) :=
22720                               - tau(i) * V(j:n-k+i,i+1:k)' * V(j:n-k+i,i)
22721 */
22722 
22723 			i__1 = *n - *k + i__ - j + 1;
22724 			i__2 = *k - i__;
22725 			d__1 = -tau[i__];
22726 			dgemv_("Transpose", &i__1, &i__2, &d__1, &v[j + (i__
22727 				+ 1) * v_dim1], ldv, &v[j + i__ * v_dim1], &
22728 				c__1, &c_b29, &t[i__ + 1 + i__ * t_dim1], &
22729 				c__1);
22730 			v[*n - *k + i__ + i__ * v_dim1] = vii;
22731 		    } else {
22732 			vii = v[i__ + (*n - *k + i__) * v_dim1];
22733 			v[i__ + (*n - *k + i__) * v_dim1] = 1.;
22734 /*                    Skip any leading zeros. */
22735 			i__1 = i__ - 1;
22736 			for (lastv = 1; lastv <= i__1; ++lastv) {
22737 			    if (v[i__ + lastv * v_dim1] != 0.) {
22738 				goto L36;
22739 			    }
22740 			}
22741 L36:
22742 			j = max(lastv,prevlastv);
22743 
22744 /*
22745                       T(i+1:k,i) :=
22746                               - tau(i) * V(i+1:k,j:n-k+i) * V(i,j:n-k+i)'
22747 */
22748 
22749 			i__1 = *k - i__;
22750 			i__2 = *n - *k + i__ - j + 1;
22751 			d__1 = -tau[i__];
22752 			dgemv_("No transpose", &i__1, &i__2, &d__1, &v[i__ +
22753 				1 + j * v_dim1], ldv, &v[i__ + j * v_dim1],
22754 				ldv, &c_b29, &t[i__ + 1 + i__ * t_dim1], &
22755 				c__1);
22756 			v[i__ + (*n - *k + i__) * v_dim1] = vii;
22757 		    }
22758 
22759 /*                 T(i+1:k,i) := T(i+1:k,i+1:k) * T(i+1:k,i) */
22760 
22761 		    i__1 = *k - i__;
22762 		    dtrmv_("Lower", "No transpose", "Non-unit", &i__1, &t[i__
22763 			    + 1 + (i__ + 1) * t_dim1], ldt, &t[i__ + 1 + i__ *
22764 			     t_dim1], &c__1)
22765 			    ;
22766 		    if (i__ > 1) {
22767 			prevlastv = min(prevlastv,lastv);
22768 		    } else {
22769 			prevlastv = lastv;
22770 		    }
22771 		}
22772 		t[i__ + i__ * t_dim1] = tau[i__];
22773 	    }
22774 /* L40: */
22775 	}
22776     }
22777     return 0;
22778 
22779 /*     End of DLARFT */
22780 
22781 } /* dlarft_ */
22782 
dlarfx_(char * side,integer * m,integer * n,doublereal * v,doublereal * tau,doublereal * c__,integer * ldc,doublereal * work)22783 /* Subroutine */ int dlarfx_(char *side, integer *m, integer *n, doublereal *
22784 	v, doublereal *tau, doublereal *c__, integer *ldc, doublereal *work)
22785 {
22786     /* System generated locals */
22787     integer c_dim1, c_offset, i__1;
22788 
22789     /* Local variables */
22790     static integer j;
22791     static doublereal t1, t2, t3, t4, t5, t6, t7, t8, t9, v1, v2, v3, v4, v5,
22792 	    v6, v7, v8, v9, t10, v10, sum;
22793     extern /* Subroutine */ int dlarf_(char *, integer *, integer *,
22794 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
22795 	    doublereal *);
22796     extern logical lsame_(char *, char *);
22797 
22798 
22799 /*
22800     -- LAPACK auxiliary routine (version 3.2) --
22801     -- LAPACK is a software package provided by Univ. of Tennessee,    --
22802     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
22803        November 2006
22804 
22805 
22806     Purpose
22807     =======
22808 
22809     DLARFX applies a real elementary reflector H to a real m by n
22810     matrix C, from either the left or the right. H is represented in the
22811     form
22812 
22813           H = I - tau * v * v'
22814 
22815     where tau is a real scalar and v is a real vector.
22816 
22817     If tau = 0, then H is taken to be the unit matrix
22818 
22819     This version uses inline code if H has order < 11.
22820 
22821     Arguments
22822     =========
22823 
22824     SIDE    (input) CHARACTER*1
22825             = 'L': form  H * C
22826             = 'R': form  C * H
22827 
22828     M       (input) INTEGER
22829             The number of rows of the matrix C.
22830 
22831     N       (input) INTEGER
22832             The number of columns of the matrix C.
22833 
22834     V       (input) DOUBLE PRECISION array, dimension (M) if SIDE = 'L'
22835                                        or (N) if SIDE = 'R'
22836             The vector v in the representation of H.
22837 
22838     TAU     (input) DOUBLE PRECISION
22839             The value tau in the representation of H.
22840 
22841     C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
22842             On entry, the m by n matrix C.
22843             On exit, C is overwritten by the matrix H * C if SIDE = 'L',
22844             or C * H if SIDE = 'R'.
22845 
22846     LDC     (input) INTEGER
22847             The leading dimension of the array C. LDA >= (1,M).
22848 
22849     WORK    (workspace) DOUBLE PRECISION array, dimension
22850                         (N) if SIDE = 'L'
22851                         or (M) if SIDE = 'R'
22852             WORK is not referenced if H has order < 11.
22853 
22854     =====================================================================
22855 */
22856 
22857 
22858     /* Parameter adjustments */
22859     --v;
22860     c_dim1 = *ldc;
22861     c_offset = 1 + c_dim1;
22862     c__ -= c_offset;
22863     --work;
22864 
22865     /* Function Body */
22866     if (*tau == 0.) {
22867 	return 0;
22868     }
22869     if (lsame_(side, "L")) {
22870 
22871 /*        Form  H * C, where H has order m. */
22872 
22873 	switch (*m) {
22874 	    case 1:  goto L10;
22875 	    case 2:  goto L30;
22876 	    case 3:  goto L50;
22877 	    case 4:  goto L70;
22878 	    case 5:  goto L90;
22879 	    case 6:  goto L110;
22880 	    case 7:  goto L130;
22881 	    case 8:  goto L150;
22882 	    case 9:  goto L170;
22883 	    case 10:  goto L190;
22884 	}
22885 
22886 /*        Code for general M */
22887 
22888 	dlarf_(side, m, n, &v[1], &c__1, tau, &c__[c_offset], ldc, &work[1]);
22889 	goto L410;
22890 L10:
22891 
22892 /*        Special code for 1 x 1 Householder */
22893 
22894 	t1 = 1. - *tau * v[1] * v[1];
22895 	i__1 = *n;
22896 	for (j = 1; j <= i__1; ++j) {
22897 	    c__[j * c_dim1 + 1] = t1 * c__[j * c_dim1 + 1];
22898 /* L20: */
22899 	}
22900 	goto L410;
22901 L30:
22902 
22903 /*        Special code for 2 x 2 Householder */
22904 
22905 	v1 = v[1];
22906 	t1 = *tau * v1;
22907 	v2 = v[2];
22908 	t2 = *tau * v2;
22909 	i__1 = *n;
22910 	for (j = 1; j <= i__1; ++j) {
22911 	    sum = v1 * c__[j * c_dim1 + 1] + v2 * c__[j * c_dim1 + 2];
22912 	    c__[j * c_dim1 + 1] -= sum * t1;
22913 	    c__[j * c_dim1 + 2] -= sum * t2;
22914 /* L40: */
22915 	}
22916 	goto L410;
22917 L50:
22918 
22919 /*        Special code for 3 x 3 Householder */
22920 
22921 	v1 = v[1];
22922 	t1 = *tau * v1;
22923 	v2 = v[2];
22924 	t2 = *tau * v2;
22925 	v3 = v[3];
22926 	t3 = *tau * v3;
22927 	i__1 = *n;
22928 	for (j = 1; j <= i__1; ++j) {
22929 	    sum = v1 * c__[j * c_dim1 + 1] + v2 * c__[j * c_dim1 + 2] + v3 *
22930 		    c__[j * c_dim1 + 3];
22931 	    c__[j * c_dim1 + 1] -= sum * t1;
22932 	    c__[j * c_dim1 + 2] -= sum * t2;
22933 	    c__[j * c_dim1 + 3] -= sum * t3;
22934 /* L60: */
22935 	}
22936 	goto L410;
22937 L70:
22938 
22939 /*        Special code for 4 x 4 Householder */
22940 
22941 	v1 = v[1];
22942 	t1 = *tau * v1;
22943 	v2 = v[2];
22944 	t2 = *tau * v2;
22945 	v3 = v[3];
22946 	t3 = *tau * v3;
22947 	v4 = v[4];
22948 	t4 = *tau * v4;
22949 	i__1 = *n;
22950 	for (j = 1; j <= i__1; ++j) {
22951 	    sum = v1 * c__[j * c_dim1 + 1] + v2 * c__[j * c_dim1 + 2] + v3 *
22952 		    c__[j * c_dim1 + 3] + v4 * c__[j * c_dim1 + 4];
22953 	    c__[j * c_dim1 + 1] -= sum * t1;
22954 	    c__[j * c_dim1 + 2] -= sum * t2;
22955 	    c__[j * c_dim1 + 3] -= sum * t3;
22956 	    c__[j * c_dim1 + 4] -= sum * t4;
22957 /* L80: */
22958 	}
22959 	goto L410;
22960 L90:
22961 
22962 /*        Special code for 5 x 5 Householder */
22963 
22964 	v1 = v[1];
22965 	t1 = *tau * v1;
22966 	v2 = v[2];
22967 	t2 = *tau * v2;
22968 	v3 = v[3];
22969 	t3 = *tau * v3;
22970 	v4 = v[4];
22971 	t4 = *tau * v4;
22972 	v5 = v[5];
22973 	t5 = *tau * v5;
22974 	i__1 = *n;
22975 	for (j = 1; j <= i__1; ++j) {
22976 	    sum = v1 * c__[j * c_dim1 + 1] + v2 * c__[j * c_dim1 + 2] + v3 *
22977 		    c__[j * c_dim1 + 3] + v4 * c__[j * c_dim1 + 4] + v5 * c__[
22978 		    j * c_dim1 + 5];
22979 	    c__[j * c_dim1 + 1] -= sum * t1;
22980 	    c__[j * c_dim1 + 2] -= sum * t2;
22981 	    c__[j * c_dim1 + 3] -= sum * t3;
22982 	    c__[j * c_dim1 + 4] -= sum * t4;
22983 	    c__[j * c_dim1 + 5] -= sum * t5;
22984 /* L100: */
22985 	}
22986 	goto L410;
22987 L110:
22988 
22989 /*        Special code for 6 x 6 Householder */
22990 
22991 	v1 = v[1];
22992 	t1 = *tau * v1;
22993 	v2 = v[2];
22994 	t2 = *tau * v2;
22995 	v3 = v[3];
22996 	t3 = *tau * v3;
22997 	v4 = v[4];
22998 	t4 = *tau * v4;
22999 	v5 = v[5];
23000 	t5 = *tau * v5;
23001 	v6 = v[6];
23002 	t6 = *tau * v6;
23003 	i__1 = *n;
23004 	for (j = 1; j <= i__1; ++j) {
23005 	    sum = v1 * c__[j * c_dim1 + 1] + v2 * c__[j * c_dim1 + 2] + v3 *
23006 		    c__[j * c_dim1 + 3] + v4 * c__[j * c_dim1 + 4] + v5 * c__[
23007 		    j * c_dim1 + 5] + v6 * c__[j * c_dim1 + 6];
23008 	    c__[j * c_dim1 + 1] -= sum * t1;
23009 	    c__[j * c_dim1 + 2] -= sum * t2;
23010 	    c__[j * c_dim1 + 3] -= sum * t3;
23011 	    c__[j * c_dim1 + 4] -= sum * t4;
23012 	    c__[j * c_dim1 + 5] -= sum * t5;
23013 	    c__[j * c_dim1 + 6] -= sum * t6;
23014 /* L120: */
23015 	}
23016 	goto L410;
23017 L130:
23018 
23019 /*        Special code for 7 x 7 Householder */
23020 
23021 	v1 = v[1];
23022 	t1 = *tau * v1;
23023 	v2 = v[2];
23024 	t2 = *tau * v2;
23025 	v3 = v[3];
23026 	t3 = *tau * v3;
23027 	v4 = v[4];
23028 	t4 = *tau * v4;
23029 	v5 = v[5];
23030 	t5 = *tau * v5;
23031 	v6 = v[6];
23032 	t6 = *tau * v6;
23033 	v7 = v[7];
23034 	t7 = *tau * v7;
23035 	i__1 = *n;
23036 	for (j = 1; j <= i__1; ++j) {
23037 	    sum = v1 * c__[j * c_dim1 + 1] + v2 * c__[j * c_dim1 + 2] + v3 *
23038 		    c__[j * c_dim1 + 3] + v4 * c__[j * c_dim1 + 4] + v5 * c__[
23039 		    j * c_dim1 + 5] + v6 * c__[j * c_dim1 + 6] + v7 * c__[j *
23040 		    c_dim1 + 7];
23041 	    c__[j * c_dim1 + 1] -= sum * t1;
23042 	    c__[j * c_dim1 + 2] -= sum * t2;
23043 	    c__[j * c_dim1 + 3] -= sum * t3;
23044 	    c__[j * c_dim1 + 4] -= sum * t4;
23045 	    c__[j * c_dim1 + 5] -= sum * t5;
23046 	    c__[j * c_dim1 + 6] -= sum * t6;
23047 	    c__[j * c_dim1 + 7] -= sum * t7;
23048 /* L140: */
23049 	}
23050 	goto L410;
23051 L150:
23052 
23053 /*        Special code for 8 x 8 Householder */
23054 
23055 	v1 = v[1];
23056 	t1 = *tau * v1;
23057 	v2 = v[2];
23058 	t2 = *tau * v2;
23059 	v3 = v[3];
23060 	t3 = *tau * v3;
23061 	v4 = v[4];
23062 	t4 = *tau * v4;
23063 	v5 = v[5];
23064 	t5 = *tau * v5;
23065 	v6 = v[6];
23066 	t6 = *tau * v6;
23067 	v7 = v[7];
23068 	t7 = *tau * v7;
23069 	v8 = v[8];
23070 	t8 = *tau * v8;
23071 	i__1 = *n;
23072 	for (j = 1; j <= i__1; ++j) {
23073 	    sum = v1 * c__[j * c_dim1 + 1] + v2 * c__[j * c_dim1 + 2] + v3 *
23074 		    c__[j * c_dim1 + 3] + v4 * c__[j * c_dim1 + 4] + v5 * c__[
23075 		    j * c_dim1 + 5] + v6 * c__[j * c_dim1 + 6] + v7 * c__[j *
23076 		    c_dim1 + 7] + v8 * c__[j * c_dim1 + 8];
23077 	    c__[j * c_dim1 + 1] -= sum * t1;
23078 	    c__[j * c_dim1 + 2] -= sum * t2;
23079 	    c__[j * c_dim1 + 3] -= sum * t3;
23080 	    c__[j * c_dim1 + 4] -= sum * t4;
23081 	    c__[j * c_dim1 + 5] -= sum * t5;
23082 	    c__[j * c_dim1 + 6] -= sum * t6;
23083 	    c__[j * c_dim1 + 7] -= sum * t7;
23084 	    c__[j * c_dim1 + 8] -= sum * t8;
23085 /* L160: */
23086 	}
23087 	goto L410;
23088 L170:
23089 
23090 /*        Special code for 9 x 9 Householder */
23091 
23092 	v1 = v[1];
23093 	t1 = *tau * v1;
23094 	v2 = v[2];
23095 	t2 = *tau * v2;
23096 	v3 = v[3];
23097 	t3 = *tau * v3;
23098 	v4 = v[4];
23099 	t4 = *tau * v4;
23100 	v5 = v[5];
23101 	t5 = *tau * v5;
23102 	v6 = v[6];
23103 	t6 = *tau * v6;
23104 	v7 = v[7];
23105 	t7 = *tau * v7;
23106 	v8 = v[8];
23107 	t8 = *tau * v8;
23108 	v9 = v[9];
23109 	t9 = *tau * v9;
23110 	i__1 = *n;
23111 	for (j = 1; j <= i__1; ++j) {
23112 	    sum = v1 * c__[j * c_dim1 + 1] + v2 * c__[j * c_dim1 + 2] + v3 *
23113 		    c__[j * c_dim1 + 3] + v4 * c__[j * c_dim1 + 4] + v5 * c__[
23114 		    j * c_dim1 + 5] + v6 * c__[j * c_dim1 + 6] + v7 * c__[j *
23115 		    c_dim1 + 7] + v8 * c__[j * c_dim1 + 8] + v9 * c__[j *
23116 		    c_dim1 + 9];
23117 	    c__[j * c_dim1 + 1] -= sum * t1;
23118 	    c__[j * c_dim1 + 2] -= sum * t2;
23119 	    c__[j * c_dim1 + 3] -= sum * t3;
23120 	    c__[j * c_dim1 + 4] -= sum * t4;
23121 	    c__[j * c_dim1 + 5] -= sum * t5;
23122 	    c__[j * c_dim1 + 6] -= sum * t6;
23123 	    c__[j * c_dim1 + 7] -= sum * t7;
23124 	    c__[j * c_dim1 + 8] -= sum * t8;
23125 	    c__[j * c_dim1 + 9] -= sum * t9;
23126 /* L180: */
23127 	}
23128 	goto L410;
23129 L190:
23130 
23131 /*        Special code for 10 x 10 Householder */
23132 
23133 	v1 = v[1];
23134 	t1 = *tau * v1;
23135 	v2 = v[2];
23136 	t2 = *tau * v2;
23137 	v3 = v[3];
23138 	t3 = *tau * v3;
23139 	v4 = v[4];
23140 	t4 = *tau * v4;
23141 	v5 = v[5];
23142 	t5 = *tau * v5;
23143 	v6 = v[6];
23144 	t6 = *tau * v6;
23145 	v7 = v[7];
23146 	t7 = *tau * v7;
23147 	v8 = v[8];
23148 	t8 = *tau * v8;
23149 	v9 = v[9];
23150 	t9 = *tau * v9;
23151 	v10 = v[10];
23152 	t10 = *tau * v10;
23153 	i__1 = *n;
23154 	for (j = 1; j <= i__1; ++j) {
23155 	    sum = v1 * c__[j * c_dim1 + 1] + v2 * c__[j * c_dim1 + 2] + v3 *
23156 		    c__[j * c_dim1 + 3] + v4 * c__[j * c_dim1 + 4] + v5 * c__[
23157 		    j * c_dim1 + 5] + v6 * c__[j * c_dim1 + 6] + v7 * c__[j *
23158 		    c_dim1 + 7] + v8 * c__[j * c_dim1 + 8] + v9 * c__[j *
23159 		    c_dim1 + 9] + v10 * c__[j * c_dim1 + 10];
23160 	    c__[j * c_dim1 + 1] -= sum * t1;
23161 	    c__[j * c_dim1 + 2] -= sum * t2;
23162 	    c__[j * c_dim1 + 3] -= sum * t3;
23163 	    c__[j * c_dim1 + 4] -= sum * t4;
23164 	    c__[j * c_dim1 + 5] -= sum * t5;
23165 	    c__[j * c_dim1 + 6] -= sum * t6;
23166 	    c__[j * c_dim1 + 7] -= sum * t7;
23167 	    c__[j * c_dim1 + 8] -= sum * t8;
23168 	    c__[j * c_dim1 + 9] -= sum * t9;
23169 	    c__[j * c_dim1 + 10] -= sum * t10;
23170 /* L200: */
23171 	}
23172 	goto L410;
23173     } else {
23174 
23175 /*        Form  C * H, where H has order n. */
23176 
23177 	switch (*n) {
23178 	    case 1:  goto L210;
23179 	    case 2:  goto L230;
23180 	    case 3:  goto L250;
23181 	    case 4:  goto L270;
23182 	    case 5:  goto L290;
23183 	    case 6:  goto L310;
23184 	    case 7:  goto L330;
23185 	    case 8:  goto L350;
23186 	    case 9:  goto L370;
23187 	    case 10:  goto L390;
23188 	}
23189 
23190 /*        Code for general N */
23191 
23192 	dlarf_(side, m, n, &v[1], &c__1, tau, &c__[c_offset], ldc, &work[1]);
23193 	goto L410;
23194 L210:
23195 
23196 /*        Special code for 1 x 1 Householder */
23197 
23198 	t1 = 1. - *tau * v[1] * v[1];
23199 	i__1 = *m;
23200 	for (j = 1; j <= i__1; ++j) {
23201 	    c__[j + c_dim1] = t1 * c__[j + c_dim1];
23202 /* L220: */
23203 	}
23204 	goto L410;
23205 L230:
23206 
23207 /*        Special code for 2 x 2 Householder */
23208 
23209 	v1 = v[1];
23210 	t1 = *tau * v1;
23211 	v2 = v[2];
23212 	t2 = *tau * v2;
23213 	i__1 = *m;
23214 	for (j = 1; j <= i__1; ++j) {
23215 	    sum = v1 * c__[j + c_dim1] + v2 * c__[j + (c_dim1 << 1)];
23216 	    c__[j + c_dim1] -= sum * t1;
23217 	    c__[j + (c_dim1 << 1)] -= sum * t2;
23218 /* L240: */
23219 	}
23220 	goto L410;
23221 L250:
23222 
23223 /*        Special code for 3 x 3 Householder */
23224 
23225 	v1 = v[1];
23226 	t1 = *tau * v1;
23227 	v2 = v[2];
23228 	t2 = *tau * v2;
23229 	v3 = v[3];
23230 	t3 = *tau * v3;
23231 	i__1 = *m;
23232 	for (j = 1; j <= i__1; ++j) {
23233 	    sum = v1 * c__[j + c_dim1] + v2 * c__[j + (c_dim1 << 1)] + v3 *
23234 		    c__[j + c_dim1 * 3];
23235 	    c__[j + c_dim1] -= sum * t1;
23236 	    c__[j + (c_dim1 << 1)] -= sum * t2;
23237 	    c__[j + c_dim1 * 3] -= sum * t3;
23238 /* L260: */
23239 	}
23240 	goto L410;
23241 L270:
23242 
23243 /*        Special code for 4 x 4 Householder */
23244 
23245 	v1 = v[1];
23246 	t1 = *tau * v1;
23247 	v2 = v[2];
23248 	t2 = *tau * v2;
23249 	v3 = v[3];
23250 	t3 = *tau * v3;
23251 	v4 = v[4];
23252 	t4 = *tau * v4;
23253 	i__1 = *m;
23254 	for (j = 1; j <= i__1; ++j) {
23255 	    sum = v1 * c__[j + c_dim1] + v2 * c__[j + (c_dim1 << 1)] + v3 *
23256 		    c__[j + c_dim1 * 3] + v4 * c__[j + (c_dim1 << 2)];
23257 	    c__[j + c_dim1] -= sum * t1;
23258 	    c__[j + (c_dim1 << 1)] -= sum * t2;
23259 	    c__[j + c_dim1 * 3] -= sum * t3;
23260 	    c__[j + (c_dim1 << 2)] -= sum * t4;
23261 /* L280: */
23262 	}
23263 	goto L410;
23264 L290:
23265 
23266 /*        Special code for 5 x 5 Householder */
23267 
23268 	v1 = v[1];
23269 	t1 = *tau * v1;
23270 	v2 = v[2];
23271 	t2 = *tau * v2;
23272 	v3 = v[3];
23273 	t3 = *tau * v3;
23274 	v4 = v[4];
23275 	t4 = *tau * v4;
23276 	v5 = v[5];
23277 	t5 = *tau * v5;
23278 	i__1 = *m;
23279 	for (j = 1; j <= i__1; ++j) {
23280 	    sum = v1 * c__[j + c_dim1] + v2 * c__[j + (c_dim1 << 1)] + v3 *
23281 		    c__[j + c_dim1 * 3] + v4 * c__[j + (c_dim1 << 2)] + v5 *
23282 		    c__[j + c_dim1 * 5];
23283 	    c__[j + c_dim1] -= sum * t1;
23284 	    c__[j + (c_dim1 << 1)] -= sum * t2;
23285 	    c__[j + c_dim1 * 3] -= sum * t3;
23286 	    c__[j + (c_dim1 << 2)] -= sum * t4;
23287 	    c__[j + c_dim1 * 5] -= sum * t5;
23288 /* L300: */
23289 	}
23290 	goto L410;
23291 L310:
23292 
23293 /*        Special code for 6 x 6 Householder */
23294 
23295 	v1 = v[1];
23296 	t1 = *tau * v1;
23297 	v2 = v[2];
23298 	t2 = *tau * v2;
23299 	v3 = v[3];
23300 	t3 = *tau * v3;
23301 	v4 = v[4];
23302 	t4 = *tau * v4;
23303 	v5 = v[5];
23304 	t5 = *tau * v5;
23305 	v6 = v[6];
23306 	t6 = *tau * v6;
23307 	i__1 = *m;
23308 	for (j = 1; j <= i__1; ++j) {
23309 	    sum = v1 * c__[j + c_dim1] + v2 * c__[j + (c_dim1 << 1)] + v3 *
23310 		    c__[j + c_dim1 * 3] + v4 * c__[j + (c_dim1 << 2)] + v5 *
23311 		    c__[j + c_dim1 * 5] + v6 * c__[j + c_dim1 * 6];
23312 	    c__[j + c_dim1] -= sum * t1;
23313 	    c__[j + (c_dim1 << 1)] -= sum * t2;
23314 	    c__[j + c_dim1 * 3] -= sum * t3;
23315 	    c__[j + (c_dim1 << 2)] -= sum * t4;
23316 	    c__[j + c_dim1 * 5] -= sum * t5;
23317 	    c__[j + c_dim1 * 6] -= sum * t6;
23318 /* L320: */
23319 	}
23320 	goto L410;
23321 L330:
23322 
23323 /*        Special code for 7 x 7 Householder */
23324 
23325 	v1 = v[1];
23326 	t1 = *tau * v1;
23327 	v2 = v[2];
23328 	t2 = *tau * v2;
23329 	v3 = v[3];
23330 	t3 = *tau * v3;
23331 	v4 = v[4];
23332 	t4 = *tau * v4;
23333 	v5 = v[5];
23334 	t5 = *tau * v5;
23335 	v6 = v[6];
23336 	t6 = *tau * v6;
23337 	v7 = v[7];
23338 	t7 = *tau * v7;
23339 	i__1 = *m;
23340 	for (j = 1; j <= i__1; ++j) {
23341 	    sum = v1 * c__[j + c_dim1] + v2 * c__[j + (c_dim1 << 1)] + v3 *
23342 		    c__[j + c_dim1 * 3] + v4 * c__[j + (c_dim1 << 2)] + v5 *
23343 		    c__[j + c_dim1 * 5] + v6 * c__[j + c_dim1 * 6] + v7 * c__[
23344 		    j + c_dim1 * 7];
23345 	    c__[j + c_dim1] -= sum * t1;
23346 	    c__[j + (c_dim1 << 1)] -= sum * t2;
23347 	    c__[j + c_dim1 * 3] -= sum * t3;
23348 	    c__[j + (c_dim1 << 2)] -= sum * t4;
23349 	    c__[j + c_dim1 * 5] -= sum * t5;
23350 	    c__[j + c_dim1 * 6] -= sum * t6;
23351 	    c__[j + c_dim1 * 7] -= sum * t7;
23352 /* L340: */
23353 	}
23354 	goto L410;
23355 L350:
23356 
23357 /*        Special code for 8 x 8 Householder */
23358 
23359 	v1 = v[1];
23360 	t1 = *tau * v1;
23361 	v2 = v[2];
23362 	t2 = *tau * v2;
23363 	v3 = v[3];
23364 	t3 = *tau * v3;
23365 	v4 = v[4];
23366 	t4 = *tau * v4;
23367 	v5 = v[5];
23368 	t5 = *tau * v5;
23369 	v6 = v[6];
23370 	t6 = *tau * v6;
23371 	v7 = v[7];
23372 	t7 = *tau * v7;
23373 	v8 = v[8];
23374 	t8 = *tau * v8;
23375 	i__1 = *m;
23376 	for (j = 1; j <= i__1; ++j) {
23377 	    sum = v1 * c__[j + c_dim1] + v2 * c__[j + (c_dim1 << 1)] + v3 *
23378 		    c__[j + c_dim1 * 3] + v4 * c__[j + (c_dim1 << 2)] + v5 *
23379 		    c__[j + c_dim1 * 5] + v6 * c__[j + c_dim1 * 6] + v7 * c__[
23380 		    j + c_dim1 * 7] + v8 * c__[j + (c_dim1 << 3)];
23381 	    c__[j + c_dim1] -= sum * t1;
23382 	    c__[j + (c_dim1 << 1)] -= sum * t2;
23383 	    c__[j + c_dim1 * 3] -= sum * t3;
23384 	    c__[j + (c_dim1 << 2)] -= sum * t4;
23385 	    c__[j + c_dim1 * 5] -= sum * t5;
23386 	    c__[j + c_dim1 * 6] -= sum * t6;
23387 	    c__[j + c_dim1 * 7] -= sum * t7;
23388 	    c__[j + (c_dim1 << 3)] -= sum * t8;
23389 /* L360: */
23390 	}
23391 	goto L410;
23392 L370:
23393 
23394 /*        Special code for 9 x 9 Householder */
23395 
23396 	v1 = v[1];
23397 	t1 = *tau * v1;
23398 	v2 = v[2];
23399 	t2 = *tau * v2;
23400 	v3 = v[3];
23401 	t3 = *tau * v3;
23402 	v4 = v[4];
23403 	t4 = *tau * v4;
23404 	v5 = v[5];
23405 	t5 = *tau * v5;
23406 	v6 = v[6];
23407 	t6 = *tau * v6;
23408 	v7 = v[7];
23409 	t7 = *tau * v7;
23410 	v8 = v[8];
23411 	t8 = *tau * v8;
23412 	v9 = v[9];
23413 	t9 = *tau * v9;
23414 	i__1 = *m;
23415 	for (j = 1; j <= i__1; ++j) {
23416 	    sum = v1 * c__[j + c_dim1] + v2 * c__[j + (c_dim1 << 1)] + v3 *
23417 		    c__[j + c_dim1 * 3] + v4 * c__[j + (c_dim1 << 2)] + v5 *
23418 		    c__[j + c_dim1 * 5] + v6 * c__[j + c_dim1 * 6] + v7 * c__[
23419 		    j + c_dim1 * 7] + v8 * c__[j + (c_dim1 << 3)] + v9 * c__[
23420 		    j + c_dim1 * 9];
23421 	    c__[j + c_dim1] -= sum * t1;
23422 	    c__[j + (c_dim1 << 1)] -= sum * t2;
23423 	    c__[j + c_dim1 * 3] -= sum * t3;
23424 	    c__[j + (c_dim1 << 2)] -= sum * t4;
23425 	    c__[j + c_dim1 * 5] -= sum * t5;
23426 	    c__[j + c_dim1 * 6] -= sum * t6;
23427 	    c__[j + c_dim1 * 7] -= sum * t7;
23428 	    c__[j + (c_dim1 << 3)] -= sum * t8;
23429 	    c__[j + c_dim1 * 9] -= sum * t9;
23430 /* L380: */
23431 	}
23432 	goto L410;
23433 L390:
23434 
23435 /*        Special code for 10 x 10 Householder */
23436 
23437 	v1 = v[1];
23438 	t1 = *tau * v1;
23439 	v2 = v[2];
23440 	t2 = *tau * v2;
23441 	v3 = v[3];
23442 	t3 = *tau * v3;
23443 	v4 = v[4];
23444 	t4 = *tau * v4;
23445 	v5 = v[5];
23446 	t5 = *tau * v5;
23447 	v6 = v[6];
23448 	t6 = *tau * v6;
23449 	v7 = v[7];
23450 	t7 = *tau * v7;
23451 	v8 = v[8];
23452 	t8 = *tau * v8;
23453 	v9 = v[9];
23454 	t9 = *tau * v9;
23455 	v10 = v[10];
23456 	t10 = *tau * v10;
23457 	i__1 = *m;
23458 	for (j = 1; j <= i__1; ++j) {
23459 	    sum = v1 * c__[j + c_dim1] + v2 * c__[j + (c_dim1 << 1)] + v3 *
23460 		    c__[j + c_dim1 * 3] + v4 * c__[j + (c_dim1 << 2)] + v5 *
23461 		    c__[j + c_dim1 * 5] + v6 * c__[j + c_dim1 * 6] + v7 * c__[
23462 		    j + c_dim1 * 7] + v8 * c__[j + (c_dim1 << 3)] + v9 * c__[
23463 		    j + c_dim1 * 9] + v10 * c__[j + c_dim1 * 10];
23464 	    c__[j + c_dim1] -= sum * t1;
23465 	    c__[j + (c_dim1 << 1)] -= sum * t2;
23466 	    c__[j + c_dim1 * 3] -= sum * t3;
23467 	    c__[j + (c_dim1 << 2)] -= sum * t4;
23468 	    c__[j + c_dim1 * 5] -= sum * t5;
23469 	    c__[j + c_dim1 * 6] -= sum * t6;
23470 	    c__[j + c_dim1 * 7] -= sum * t7;
23471 	    c__[j + (c_dim1 << 3)] -= sum * t8;
23472 	    c__[j + c_dim1 * 9] -= sum * t9;
23473 	    c__[j + c_dim1 * 10] -= sum * t10;
23474 /* L400: */
23475 	}
23476 	goto L410;
23477     }
23478 L410:
23479     return 0;
23480 
23481 /*     End of DLARFX */
23482 
23483 } /* dlarfx_ */
23484 
dlartg_(doublereal * f,doublereal * g,doublereal * cs,doublereal * sn,doublereal * r__)23485 /* Subroutine */ int dlartg_(doublereal *f, doublereal *g, doublereal *cs,
23486 	doublereal *sn, doublereal *r__)
23487 {
23488     /* System generated locals */
23489     integer i__1;
23490     doublereal d__1, d__2;
23491 
23492     /* Local variables */
23493     static integer i__;
23494     static doublereal f1, g1, eps, scale;
23495     static integer count;
23496     static doublereal safmn2, safmx2;
23497 
23498     static doublereal safmin;
23499 
23500 
23501 /*
23502     -- LAPACK auxiliary routine (version 3.2) --
23503     -- LAPACK is a software package provided by Univ. of Tennessee,    --
23504     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
23505        November 2006
23506 
23507 
23508     Purpose
23509     =======
23510 
23511     DLARTG generate a plane rotation so that
23512 
23513        [  CS  SN  ]  .  [ F ]  =  [ R ]   where CS**2 + SN**2 = 1.
23514        [ -SN  CS  ]     [ G ]     [ 0 ]
23515 
23516     This is a slower, more accurate version of the BLAS1 routine DROTG,
23517     with the following other differences:
23518        F and G are unchanged on return.
23519        If G=0, then CS=1 and SN=0.
23520        If F=0 and (G .ne. 0), then CS=0 and SN=1 without doing any
23521           floating point operations (saves work in DBDSQR when
23522           there are zeros on the diagonal).
23523 
23524     If F exceeds G in magnitude, CS will be positive.
23525 
23526     Arguments
23527     =========
23528 
23529     F       (input) DOUBLE PRECISION
23530             The first component of vector to be rotated.
23531 
23532     G       (input) DOUBLE PRECISION
23533             The second component of vector to be rotated.
23534 
23535     CS      (output) DOUBLE PRECISION
23536             The cosine of the rotation.
23537 
23538     SN      (output) DOUBLE PRECISION
23539             The sine of the rotation.
23540 
23541     R       (output) DOUBLE PRECISION
23542             The nonzero component of the rotated vector.
23543 
23544     This version has a few statements commented out for thread safety
23545     (machine parameters are computed on each entry). 10 feb 03, SJH.
23546 
23547     =====================================================================
23548 
23549        LOGICAL            FIRST
23550        SAVE               FIRST, SAFMX2, SAFMIN, SAFMN2
23551        DATA               FIRST / .TRUE. /
23552 
23553        IF( FIRST ) THEN
23554 */
23555     safmin = SAFEMINIMUM;
23556     eps = EPSILON;
23557     d__1 = BASE;
23558     i__1 = (integer) (log(safmin / eps) / log(BASE) / 2.);
23559     safmn2 = pow_di(&d__1, &i__1);
23560     safmx2 = 1. / safmn2;
23561 /*
23562           FIRST = .FALSE.
23563        END IF
23564 */
23565     if (*g == 0.) {
23566 	*cs = 1.;
23567 	*sn = 0.;
23568 	*r__ = *f;
23569     } else if (*f == 0.) {
23570 	*cs = 0.;
23571 	*sn = 1.;
23572 	*r__ = *g;
23573     } else {
23574 	f1 = *f;
23575 	g1 = *g;
23576 /* Computing MAX */
23577 	d__1 = abs(f1), d__2 = abs(g1);
23578 	scale = max(d__1,d__2);
23579 	if (scale >= safmx2) {
23580 	    count = 0;
23581 L10:
23582 	    ++count;
23583 	    f1 *= safmn2;
23584 	    g1 *= safmn2;
23585 /* Computing MAX */
23586 	    d__1 = abs(f1), d__2 = abs(g1);
23587 	    scale = max(d__1,d__2);
23588 	    if (scale >= safmx2) {
23589 		goto L10;
23590 	    }
23591 /* Computing 2nd power */
23592 	    d__1 = f1;
23593 /* Computing 2nd power */
23594 	    d__2 = g1;
23595 	    *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
23596 	    *cs = f1 / *r__;
23597 	    *sn = g1 / *r__;
23598 	    i__1 = count;
23599 	    for (i__ = 1; i__ <= i__1; ++i__) {
23600 		*r__ *= safmx2;
23601 /* L20: */
23602 	    }
23603 	} else if (scale <= safmn2) {
23604 	    count = 0;
23605 L30:
23606 	    ++count;
23607 	    f1 *= safmx2;
23608 	    g1 *= safmx2;
23609 /* Computing MAX */
23610 	    d__1 = abs(f1), d__2 = abs(g1);
23611 	    scale = max(d__1,d__2);
23612 	    if (scale <= safmn2) {
23613 		goto L30;
23614 	    }
23615 /* Computing 2nd power */
23616 	    d__1 = f1;
23617 /* Computing 2nd power */
23618 	    d__2 = g1;
23619 	    *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
23620 	    *cs = f1 / *r__;
23621 	    *sn = g1 / *r__;
23622 	    i__1 = count;
23623 	    for (i__ = 1; i__ <= i__1; ++i__) {
23624 		*r__ *= safmn2;
23625 /* L40: */
23626 	    }
23627 	} else {
23628 /* Computing 2nd power */
23629 	    d__1 = f1;
23630 /* Computing 2nd power */
23631 	    d__2 = g1;
23632 	    *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
23633 	    *cs = f1 / *r__;
23634 	    *sn = g1 / *r__;
23635 	}
23636 	if (abs(*f) > abs(*g) && *cs < 0.) {
23637 	    *cs = -(*cs);
23638 	    *sn = -(*sn);
23639 	    *r__ = -(*r__);
23640 	}
23641     }
23642     return 0;
23643 
23644 /*     End of DLARTG */
23645 
23646 } /* dlartg_ */
23647 
dlas2_(doublereal * f,doublereal * g,doublereal * h__,doublereal * ssmin,doublereal * ssmax)23648 /* Subroutine */ int dlas2_(doublereal *f, doublereal *g, doublereal *h__,
23649 	doublereal *ssmin, doublereal *ssmax)
23650 {
23651     /* System generated locals */
23652     doublereal d__1, d__2;
23653 
23654     /* Local variables */
23655     static doublereal c__, fa, ga, ha, as, at, au, fhmn, fhmx;
23656 
23657 
23658 /*
23659     -- LAPACK auxiliary routine (version 3.2) --
23660     -- LAPACK is a software package provided by Univ. of Tennessee,    --
23661     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
23662        November 2006
23663 
23664 
23665     Purpose
23666     =======
23667 
23668     DLAS2  computes the singular values of the 2-by-2 matrix
23669        [  F   G  ]
23670        [  0   H  ].
23671     On return, SSMIN is the smaller singular value and SSMAX is the
23672     larger singular value.
23673 
23674     Arguments
23675     =========
23676 
23677     F       (input) DOUBLE PRECISION
23678             The (1,1) element of the 2-by-2 matrix.
23679 
23680     G       (input) DOUBLE PRECISION
23681             The (1,2) element of the 2-by-2 matrix.
23682 
23683     H       (input) DOUBLE PRECISION
23684             The (2,2) element of the 2-by-2 matrix.
23685 
23686     SSMIN   (output) DOUBLE PRECISION
23687             The smaller singular value.
23688 
23689     SSMAX   (output) DOUBLE PRECISION
23690             The larger singular value.
23691 
23692     Further Details
23693     ===============
23694 
23695     Barring over/underflow, all output quantities are correct to within
23696     a few units in the last place (ulps), even in the absence of a guard
23697     digit in addition/subtraction.
23698 
23699     In IEEE arithmetic, the code works correctly if one matrix element is
23700     infinite.
23701 
23702     Overflow will not occur unless the largest singular value itself
23703     overflows, or is within a few ulps of overflow. (On machines with
23704     partial overflow, like the Cray, overflow may occur if the largest
23705     singular value is within a factor of 2 of overflow.)
23706 
23707     Underflow is harmless if underflow is gradual. Otherwise, results
23708     may correspond to a matrix modified by perturbations of size near
23709     the underflow threshold.
23710 
23711     ====================================================================
23712 */
23713 
23714 
23715     fa = abs(*f);
23716     ga = abs(*g);
23717     ha = abs(*h__);
23718     fhmn = min(fa,ha);
23719     fhmx = max(fa,ha);
23720     if (fhmn == 0.) {
23721 	*ssmin = 0.;
23722 	if (fhmx == 0.) {
23723 	    *ssmax = ga;
23724 	} else {
23725 /* Computing 2nd power */
23726 	    d__1 = min(fhmx,ga) / max(fhmx,ga);
23727 	    *ssmax = max(fhmx,ga) * sqrt(d__1 * d__1 + 1.);
23728 	}
23729     } else {
23730 	if (ga < fhmx) {
23731 	    as = fhmn / fhmx + 1.;
23732 	    at = (fhmx - fhmn) / fhmx;
23733 /* Computing 2nd power */
23734 	    d__1 = ga / fhmx;
23735 	    au = d__1 * d__1;
23736 	    c__ = 2. / (sqrt(as * as + au) + sqrt(at * at + au));
23737 	    *ssmin = fhmn * c__;
23738 	    *ssmax = fhmx / c__;
23739 	} else {
23740 	    au = fhmx / ga;
23741 	    if (au == 0.) {
23742 
23743 /*
23744                 Avoid possible harmful underflow if exponent range
23745                 asymmetric (true SSMIN may not underflow even if
23746                 AU underflows)
23747 */
23748 
23749 		*ssmin = fhmn * fhmx / ga;
23750 		*ssmax = ga;
23751 	    } else {
23752 		as = fhmn / fhmx + 1.;
23753 		at = (fhmx - fhmn) / fhmx;
23754 /* Computing 2nd power */
23755 		d__1 = as * au;
23756 /* Computing 2nd power */
23757 		d__2 = at * au;
23758 		c__ = 1. / (sqrt(d__1 * d__1 + 1.) + sqrt(d__2 * d__2 + 1.));
23759 		*ssmin = fhmn * c__ * au;
23760 		*ssmin += *ssmin;
23761 		*ssmax = ga / (c__ + c__);
23762 	    }
23763 	}
23764     }
23765     return 0;
23766 
23767 /*     End of DLAS2 */
23768 
23769 } /* dlas2_ */
23770 
dlascl_(char * type__,integer * kl,integer * ku,doublereal * cfrom,doublereal * cto,integer * m,integer * n,doublereal * a,integer * lda,integer * info)23771 /* Subroutine */ int dlascl_(char *type__, integer *kl, integer *ku,
23772 	doublereal *cfrom, doublereal *cto, integer *m, integer *n,
23773 	doublereal *a, integer *lda, integer *info)
23774 {
23775     /* System generated locals */
23776     integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
23777 
23778     /* Local variables */
23779     static integer i__, j, k1, k2, k3, k4;
23780     static doublereal mul, cto1;
23781     static logical done;
23782     static doublereal ctoc;
23783     extern logical lsame_(char *, char *);
23784     static integer itype;
23785     static doublereal cfrom1;
23786 
23787     static doublereal cfromc;
23788     extern logical disnan_(doublereal *);
23789     extern /* Subroutine */ int xerbla_(char *, integer *);
23790     static doublereal bignum, smlnum;
23791 
23792 
23793 /*
23794     -- LAPACK auxiliary routine (version 3.2) --
23795     -- LAPACK is a software package provided by Univ. of Tennessee,    --
23796     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
23797        November 2006
23798 
23799 
23800     Purpose
23801     =======
23802 
23803     DLASCL multiplies the M by N real matrix A by the real scalar
23804     CTO/CFROM.  This is done without over/underflow as long as the final
23805     result CTO*A(I,J)/CFROM does not over/underflow. TYPE specifies that
23806     A may be full, upper triangular, lower triangular, upper Hessenberg,
23807     or banded.
23808 
23809     Arguments
23810     =========
23811 
23812     TYPE    (input) CHARACTER*1
23813             TYPE indices the storage type of the input matrix.
23814             = 'G':  A is a full matrix.
23815             = 'L':  A is a lower triangular matrix.
23816             = 'U':  A is an upper triangular matrix.
23817             = 'H':  A is an upper Hessenberg matrix.
23818             = 'B':  A is a symmetric band matrix with lower bandwidth KL
23819                     and upper bandwidth KU and with the only the lower
23820                     half stored.
23821             = 'Q':  A is a symmetric band matrix with lower bandwidth KL
23822                     and upper bandwidth KU and with the only the upper
23823                     half stored.
23824             = 'Z':  A is a band matrix with lower bandwidth KL and upper
23825                     bandwidth KU.
23826 
23827     KL      (input) INTEGER
23828             The lower bandwidth of A.  Referenced only if TYPE = 'B',
23829             'Q' or 'Z'.
23830 
23831     KU      (input) INTEGER
23832             The upper bandwidth of A.  Referenced only if TYPE = 'B',
23833             'Q' or 'Z'.
23834 
23835     CFROM   (input) DOUBLE PRECISION
23836     CTO     (input) DOUBLE PRECISION
23837             The matrix A is multiplied by CTO/CFROM. A(I,J) is computed
23838             without over/underflow if the final result CTO*A(I,J)/CFROM
23839             can be represented without over/underflow.  CFROM must be
23840             nonzero.
23841 
23842     M       (input) INTEGER
23843             The number of rows of the matrix A.  M >= 0.
23844 
23845     N       (input) INTEGER
23846             The number of columns of the matrix A.  N >= 0.
23847 
23848     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
23849             The matrix to be multiplied by CTO/CFROM.  See TYPE for the
23850             storage type.
23851 
23852     LDA     (input) INTEGER
23853             The leading dimension of the array A.  LDA >= max(1,M).
23854 
23855     INFO    (output) INTEGER
23856             0  - successful exit
23857             <0 - if INFO = -i, the i-th argument had an illegal value.
23858 
23859     =====================================================================
23860 
23861 
23862        Test the input arguments
23863 */
23864 
23865     /* Parameter adjustments */
23866     a_dim1 = *lda;
23867     a_offset = 1 + a_dim1;
23868     a -= a_offset;
23869 
23870     /* Function Body */
23871     *info = 0;
23872 
23873     if (lsame_(type__, "G")) {
23874 	itype = 0;
23875     } else if (lsame_(type__, "L")) {
23876 	itype = 1;
23877     } else if (lsame_(type__, "U")) {
23878 	itype = 2;
23879     } else if (lsame_(type__, "H")) {
23880 	itype = 3;
23881     } else if (lsame_(type__, "B")) {
23882 	itype = 4;
23883     } else if (lsame_(type__, "Q")) {
23884 	itype = 5;
23885     } else if (lsame_(type__, "Z")) {
23886 	itype = 6;
23887     } else {
23888 	itype = -1;
23889     }
23890 
23891     if (itype == -1) {
23892 	*info = -1;
23893     } else if (*cfrom == 0. || disnan_(cfrom)) {
23894 	*info = -4;
23895     } else if (disnan_(cto)) {
23896 	*info = -5;
23897     } else if (*m < 0) {
23898 	*info = -6;
23899     } else if (*n < 0 || itype == 4 && *n != *m || itype == 5 && *n != *m) {
23900 	*info = -7;
23901     } else if (itype <= 3 && *lda < max(1,*m)) {
23902 	*info = -9;
23903     } else if (itype >= 4) {
23904 /* Computing MAX */
23905 	i__1 = *m - 1;
23906 	if (*kl < 0 || *kl > max(i__1,0)) {
23907 	    *info = -2;
23908 	} else /* if(complicated condition) */ {
23909 /* Computing MAX */
23910 	    i__1 = *n - 1;
23911 	    if (*ku < 0 || *ku > max(i__1,0) || (itype == 4 || itype == 5) &&
23912 		    *kl != *ku) {
23913 		*info = -3;
23914 	    } else if (itype == 4 && *lda < *kl + 1 || itype == 5 && *lda < *
23915 		    ku + 1 || itype == 6 && *lda < (*kl << 1) + *ku + 1) {
23916 		*info = -9;
23917 	    }
23918 	}
23919     }
23920 
23921     if (*info != 0) {
23922 	i__1 = -(*info);
23923 	xerbla_("DLASCL", &i__1);
23924 	return 0;
23925     }
23926 
23927 /*     Quick return if possible */
23928 
23929     if (*n == 0 || *m == 0) {
23930 	return 0;
23931     }
23932 
23933 /*     Get machine parameters */
23934 
23935     smlnum = SAFEMINIMUM;
23936     bignum = 1. / smlnum;
23937 
23938     cfromc = *cfrom;
23939     ctoc = *cto;
23940 
23941 L10:
23942     cfrom1 = cfromc * smlnum;
23943     if (cfrom1 == cfromc) {
23944 /*
23945           CFROMC is an inf.  Multiply by a correctly signed zero for
23946           finite CTOC, or a NaN if CTOC is infinite.
23947 */
23948 	mul = ctoc / cfromc;
23949 	done = TRUE_;
23950 	cto1 = ctoc;
23951     } else {
23952 	cto1 = ctoc / bignum;
23953 	if (cto1 == ctoc) {
23954 /*
23955              CTOC is either 0 or an inf.  In both cases, CTOC itself
23956              serves as the correct multiplication factor.
23957 */
23958 	    mul = ctoc;
23959 	    done = TRUE_;
23960 	    cfromc = 1.;
23961 	} else if (abs(cfrom1) > abs(ctoc) && ctoc != 0.) {
23962 	    mul = smlnum;
23963 	    done = FALSE_;
23964 	    cfromc = cfrom1;
23965 	} else if (abs(cto1) > abs(cfromc)) {
23966 	    mul = bignum;
23967 	    done = FALSE_;
23968 	    ctoc = cto1;
23969 	} else {
23970 	    mul = ctoc / cfromc;
23971 	    done = TRUE_;
23972 	}
23973     }
23974 
23975     if (itype == 0) {
23976 
23977 /*        Full matrix */
23978 
23979 	i__1 = *n;
23980 	for (j = 1; j <= i__1; ++j) {
23981 	    i__2 = *m;
23982 	    for (i__ = 1; i__ <= i__2; ++i__) {
23983 		a[i__ + j * a_dim1] *= mul;
23984 /* L20: */
23985 	    }
23986 /* L30: */
23987 	}
23988 
23989     } else if (itype == 1) {
23990 
23991 /*        Lower triangular matrix */
23992 
23993 	i__1 = *n;
23994 	for (j = 1; j <= i__1; ++j) {
23995 	    i__2 = *m;
23996 	    for (i__ = j; i__ <= i__2; ++i__) {
23997 		a[i__ + j * a_dim1] *= mul;
23998 /* L40: */
23999 	    }
24000 /* L50: */
24001 	}
24002 
24003     } else if (itype == 2) {
24004 
24005 /*        Upper triangular matrix */
24006 
24007 	i__1 = *n;
24008 	for (j = 1; j <= i__1; ++j) {
24009 	    i__2 = min(j,*m);
24010 	    for (i__ = 1; i__ <= i__2; ++i__) {
24011 		a[i__ + j * a_dim1] *= mul;
24012 /* L60: */
24013 	    }
24014 /* L70: */
24015 	}
24016 
24017     } else if (itype == 3) {
24018 
24019 /*        Upper Hessenberg matrix */
24020 
24021 	i__1 = *n;
24022 	for (j = 1; j <= i__1; ++j) {
24023 /* Computing MIN */
24024 	    i__3 = j + 1;
24025 	    i__2 = min(i__3,*m);
24026 	    for (i__ = 1; i__ <= i__2; ++i__) {
24027 		a[i__ + j * a_dim1] *= mul;
24028 /* L80: */
24029 	    }
24030 /* L90: */
24031 	}
24032 
24033     } else if (itype == 4) {
24034 
24035 /*        Lower half of a symmetric band matrix */
24036 
24037 	k3 = *kl + 1;
24038 	k4 = *n + 1;
24039 	i__1 = *n;
24040 	for (j = 1; j <= i__1; ++j) {
24041 /* Computing MIN */
24042 	    i__3 = k3, i__4 = k4 - j;
24043 	    i__2 = min(i__3,i__4);
24044 	    for (i__ = 1; i__ <= i__2; ++i__) {
24045 		a[i__ + j * a_dim1] *= mul;
24046 /* L100: */
24047 	    }
24048 /* L110: */
24049 	}
24050 
24051     } else if (itype == 5) {
24052 
24053 /*        Upper half of a symmetric band matrix */
24054 
24055 	k1 = *ku + 2;
24056 	k3 = *ku + 1;
24057 	i__1 = *n;
24058 	for (j = 1; j <= i__1; ++j) {
24059 /* Computing MAX */
24060 	    i__2 = k1 - j;
24061 	    i__3 = k3;
24062 	    for (i__ = max(i__2,1); i__ <= i__3; ++i__) {
24063 		a[i__ + j * a_dim1] *= mul;
24064 /* L120: */
24065 	    }
24066 /* L130: */
24067 	}
24068 
24069     } else if (itype == 6) {
24070 
24071 /*        Band matrix */
24072 
24073 	k1 = *kl + *ku + 2;
24074 	k2 = *kl + 1;
24075 	k3 = (*kl << 1) + *ku + 1;
24076 	k4 = *kl + *ku + 1 + *m;
24077 	i__1 = *n;
24078 	for (j = 1; j <= i__1; ++j) {
24079 /* Computing MAX */
24080 	    i__3 = k1 - j;
24081 /* Computing MIN */
24082 	    i__4 = k3, i__5 = k4 - j;
24083 	    i__2 = min(i__4,i__5);
24084 	    for (i__ = max(i__3,k2); i__ <= i__2; ++i__) {
24085 		a[i__ + j * a_dim1] *= mul;
24086 /* L140: */
24087 	    }
24088 /* L150: */
24089 	}
24090 
24091     }
24092 
24093     if (! done) {
24094 	goto L10;
24095     }
24096 
24097     return 0;
24098 
24099 /*     End of DLASCL */
24100 
24101 } /* dlascl_ */
24102 
dlasd0_(integer * n,integer * sqre,doublereal * d__,doublereal * e,doublereal * u,integer * ldu,doublereal * vt,integer * ldvt,integer * smlsiz,integer * iwork,doublereal * work,integer * info)24103 /* Subroutine */ int dlasd0_(integer *n, integer *sqre, doublereal *d__,
24104 	doublereal *e, doublereal *u, integer *ldu, doublereal *vt, integer *
24105 	ldvt, integer *smlsiz, integer *iwork, doublereal *work, integer *
24106 	info)
24107 {
24108     /* System generated locals */
24109     integer u_dim1, u_offset, vt_dim1, vt_offset, i__1, i__2;
24110 
24111     /* Local variables */
24112     static integer i__, j, m, i1, ic, lf, nd, ll, nl, nr, im1, ncc, nlf, nrf,
24113 	    iwk, lvl, ndb1, nlp1, nrp1;
24114     static doublereal beta;
24115     static integer idxq, nlvl;
24116     static doublereal alpha;
24117     static integer inode, ndiml, idxqc, ndimr, itemp, sqrei;
24118     extern /* Subroutine */ int dlasd1_(integer *, integer *, integer *,
24119 	    doublereal *, doublereal *, doublereal *, doublereal *, integer *,
24120 	     doublereal *, integer *, integer *, integer *, doublereal *,
24121 	    integer *), dlasdq_(char *, integer *, integer *, integer *,
24122 	    integer *, integer *, doublereal *, doublereal *, doublereal *,
24123 	    integer *, doublereal *, integer *, doublereal *, integer *,
24124 	    doublereal *, integer *), dlasdt_(integer *, integer *,
24125 	    integer *, integer *, integer *, integer *, integer *), xerbla_(
24126 	    char *, integer *);
24127 
24128 
24129 /*
24130     -- LAPACK auxiliary routine (version 3.2.2) --
24131     -- LAPACK is a software package provided by Univ. of Tennessee,    --
24132     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
24133        June 2010
24134 
24135 
24136     Purpose
24137     =======
24138 
24139     Using a divide and conquer approach, DLASD0 computes the singular
24140     value decomposition (SVD) of a real upper bidiagonal N-by-M
24141     matrix B with diagonal D and offdiagonal E, where M = N + SQRE.
24142     The algorithm computes orthogonal matrices U and VT such that
24143     B = U * S * VT. The singular values S are overwritten on D.
24144 
24145     A related subroutine, DLASDA, computes only the singular values,
24146     and optionally, the singular vectors in compact form.
24147 
24148     Arguments
24149     =========
24150 
24151     N      (input) INTEGER
24152            On entry, the row dimension of the upper bidiagonal matrix.
24153            This is also the dimension of the main diagonal array D.
24154 
24155     SQRE   (input) INTEGER
24156            Specifies the column dimension of the bidiagonal matrix.
24157            = 0: The bidiagonal matrix has column dimension M = N;
24158            = 1: The bidiagonal matrix has column dimension M = N+1;
24159 
24160     D      (input/output) DOUBLE PRECISION array, dimension (N)
24161            On entry D contains the main diagonal of the bidiagonal
24162            matrix.
24163            On exit D, if INFO = 0, contains its singular values.
24164 
24165     E      (input) DOUBLE PRECISION array, dimension (M-1)
24166            Contains the subdiagonal entries of the bidiagonal matrix.
24167            On exit, E has been destroyed.
24168 
24169     U      (output) DOUBLE PRECISION array, dimension at least (LDQ, N)
24170            On exit, U contains the left singular vectors.
24171 
24172     LDU    (input) INTEGER
24173            On entry, leading dimension of U.
24174 
24175     VT     (output) DOUBLE PRECISION array, dimension at least (LDVT, M)
24176            On exit, VT' contains the right singular vectors.
24177 
24178     LDVT   (input) INTEGER
24179            On entry, leading dimension of VT.
24180 
24181     SMLSIZ (input) INTEGER
24182            On entry, maximum size of the subproblems at the
24183            bottom of the computation tree.
24184 
24185     IWORK  (workspace) INTEGER work array.
24186            Dimension must be at least (8 * N)
24187 
24188     WORK   (workspace) DOUBLE PRECISION work array.
24189            Dimension must be at least (3 * M**2 + 2 * M)
24190 
24191     INFO   (output) INTEGER
24192             = 0:  successful exit.
24193             < 0:  if INFO = -i, the i-th argument had an illegal value.
24194             > 0:  if INFO = 1, a singular value did not converge
24195 
24196     Further Details
24197     ===============
24198 
24199     Based on contributions by
24200        Ming Gu and Huan Ren, Computer Science Division, University of
24201        California at Berkeley, USA
24202 
24203     =====================================================================
24204 
24205 
24206        Test the input parameters.
24207 */
24208 
24209     /* Parameter adjustments */
24210     --d__;
24211     --e;
24212     u_dim1 = *ldu;
24213     u_offset = 1 + u_dim1;
24214     u -= u_offset;
24215     vt_dim1 = *ldvt;
24216     vt_offset = 1 + vt_dim1;
24217     vt -= vt_offset;
24218     --iwork;
24219     --work;
24220 
24221     /* Function Body */
24222     *info = 0;
24223 
24224     if (*n < 0) {
24225 	*info = -1;
24226     } else if (*sqre < 0 || *sqre > 1) {
24227 	*info = -2;
24228     }
24229 
24230     m = *n + *sqre;
24231 
24232     if (*ldu < *n) {
24233 	*info = -6;
24234     } else if (*ldvt < m) {
24235 	*info = -8;
24236     } else if (*smlsiz < 3) {
24237 	*info = -9;
24238     }
24239     if (*info != 0) {
24240 	i__1 = -(*info);
24241 	xerbla_("DLASD0", &i__1);
24242 	return 0;
24243     }
24244 
24245 /*     If the input matrix is too small, call DLASDQ to find the SVD. */
24246 
24247     if (*n <= *smlsiz) {
24248 	dlasdq_("U", sqre, n, &m, n, &c__0, &d__[1], &e[1], &vt[vt_offset],
24249 		ldvt, &u[u_offset], ldu, &u[u_offset], ldu, &work[1], info);
24250 	return 0;
24251     }
24252 
24253 /*     Set up the computation tree. */
24254 
24255     inode = 1;
24256     ndiml = inode + *n;
24257     ndimr = ndiml + *n;
24258     idxq = ndimr + *n;
24259     iwk = idxq + *n;
24260     dlasdt_(n, &nlvl, &nd, &iwork[inode], &iwork[ndiml], &iwork[ndimr],
24261 	    smlsiz);
24262 
24263 /*
24264        For the nodes on bottom level of the tree, solve
24265        their subproblems by DLASDQ.
24266 */
24267 
24268     ndb1 = (nd + 1) / 2;
24269     ncc = 0;
24270     i__1 = nd;
24271     for (i__ = ndb1; i__ <= i__1; ++i__) {
24272 
24273 /*
24274        IC : center row of each node
24275        NL : number of rows of left  subproblem
24276        NR : number of rows of right subproblem
24277        NLF: starting row of the left   subproblem
24278        NRF: starting row of the right  subproblem
24279 */
24280 
24281 	i1 = i__ - 1;
24282 	ic = iwork[inode + i1];
24283 	nl = iwork[ndiml + i1];
24284 	nlp1 = nl + 1;
24285 	nr = iwork[ndimr + i1];
24286 	nrp1 = nr + 1;
24287 	nlf = ic - nl;
24288 	nrf = ic + 1;
24289 	sqrei = 1;
24290 	dlasdq_("U", &sqrei, &nl, &nlp1, &nl, &ncc, &d__[nlf], &e[nlf], &vt[
24291 		nlf + nlf * vt_dim1], ldvt, &u[nlf + nlf * u_dim1], ldu, &u[
24292 		nlf + nlf * u_dim1], ldu, &work[1], info);
24293 	if (*info != 0) {
24294 	    return 0;
24295 	}
24296 	itemp = idxq + nlf - 2;
24297 	i__2 = nl;
24298 	for (j = 1; j <= i__2; ++j) {
24299 	    iwork[itemp + j] = j;
24300 /* L10: */
24301 	}
24302 	if (i__ == nd) {
24303 	    sqrei = *sqre;
24304 	} else {
24305 	    sqrei = 1;
24306 	}
24307 	nrp1 = nr + sqrei;
24308 	dlasdq_("U", &sqrei, &nr, &nrp1, &nr, &ncc, &d__[nrf], &e[nrf], &vt[
24309 		nrf + nrf * vt_dim1], ldvt, &u[nrf + nrf * u_dim1], ldu, &u[
24310 		nrf + nrf * u_dim1], ldu, &work[1], info);
24311 	if (*info != 0) {
24312 	    return 0;
24313 	}
24314 	itemp = idxq + ic;
24315 	i__2 = nr;
24316 	for (j = 1; j <= i__2; ++j) {
24317 	    iwork[itemp + j - 1] = j;
24318 /* L20: */
24319 	}
24320 /* L30: */
24321     }
24322 
24323 /*     Now conquer each subproblem bottom-up. */
24324 
24325     for (lvl = nlvl; lvl >= 1; --lvl) {
24326 
24327 /*
24328           Find the first node LF and last node LL on the
24329           current level LVL.
24330 */
24331 
24332 	if (lvl == 1) {
24333 	    lf = 1;
24334 	    ll = 1;
24335 	} else {
24336 	    i__1 = lvl - 1;
24337 	    lf = pow_ii(&c__2, &i__1);
24338 	    ll = (lf << 1) - 1;
24339 	}
24340 	i__1 = ll;
24341 	for (i__ = lf; i__ <= i__1; ++i__) {
24342 	    im1 = i__ - 1;
24343 	    ic = iwork[inode + im1];
24344 	    nl = iwork[ndiml + im1];
24345 	    nr = iwork[ndimr + im1];
24346 	    nlf = ic - nl;
24347 	    if (*sqre == 0 && i__ == ll) {
24348 		sqrei = *sqre;
24349 	    } else {
24350 		sqrei = 1;
24351 	    }
24352 	    idxqc = idxq + nlf - 1;
24353 	    alpha = d__[ic];
24354 	    beta = e[ic];
24355 	    dlasd1_(&nl, &nr, &sqrei, &d__[nlf], &alpha, &beta, &u[nlf + nlf *
24356 		     u_dim1], ldu, &vt[nlf + nlf * vt_dim1], ldvt, &iwork[
24357 		    idxqc], &iwork[iwk], &work[1], info);
24358 	    if (*info != 0) {
24359 		return 0;
24360 	    }
24361 /* L40: */
24362 	}
24363 /* L50: */
24364     }
24365 
24366     return 0;
24367 
24368 /*     End of DLASD0 */
24369 
24370 } /* dlasd0_ */
24371 
dlasd1_(integer * nl,integer * nr,integer * sqre,doublereal * d__,doublereal * alpha,doublereal * beta,doublereal * u,integer * ldu,doublereal * vt,integer * ldvt,integer * idxq,integer * iwork,doublereal * work,integer * info)24372 /* Subroutine */ int dlasd1_(integer *nl, integer *nr, integer *sqre,
24373 	doublereal *d__, doublereal *alpha, doublereal *beta, doublereal *u,
24374 	integer *ldu, doublereal *vt, integer *ldvt, integer *idxq, integer *
24375 	iwork, doublereal *work, integer *info)
24376 {
24377     /* System generated locals */
24378     integer u_dim1, u_offset, vt_dim1, vt_offset, i__1;
24379     doublereal d__1, d__2;
24380 
24381     /* Local variables */
24382     static integer i__, k, m, n, n1, n2, iq, iz, iu2, ldq, idx, ldu2, ivt2,
24383 	    idxc, idxp, ldvt2;
24384     extern /* Subroutine */ int dlasd2_(integer *, integer *, integer *,
24385 	    integer *, doublereal *, doublereal *, doublereal *, doublereal *,
24386 	     doublereal *, integer *, doublereal *, integer *, doublereal *,
24387 	    doublereal *, integer *, doublereal *, integer *, integer *,
24388 	    integer *, integer *, integer *, integer *, integer *), dlasd3_(
24389 	    integer *, integer *, integer *, integer *, doublereal *,
24390 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
24391 	    doublereal *, integer *, doublereal *, integer *, doublereal *,
24392 	    integer *, integer *, integer *, doublereal *, integer *),
24393 	    dlascl_(char *, integer *, integer *, doublereal *, doublereal *,
24394 	    integer *, integer *, doublereal *, integer *, integer *),
24395 	     dlamrg_(integer *, integer *, doublereal *, integer *, integer *,
24396 	     integer *);
24397     static integer isigma;
24398     extern /* Subroutine */ int xerbla_(char *, integer *);
24399     static doublereal orgnrm;
24400     static integer coltyp;
24401 
24402 
24403 /*
24404     -- LAPACK auxiliary routine (version 3.2.2) --
24405     -- LAPACK is a software package provided by Univ. of Tennessee,    --
24406     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
24407        June 2010
24408 
24409 
24410     Purpose
24411     =======
24412 
24413     DLASD1 computes the SVD of an upper bidiagonal N-by-M matrix B,
24414     where N = NL + NR + 1 and M = N + SQRE. DLASD1 is called from DLASD0.
24415 
24416     A related subroutine DLASD7 handles the case in which the singular
24417     values (and the singular vectors in factored form) are desired.
24418 
24419     DLASD1 computes the SVD as follows:
24420 
24421                   ( D1(in)  0    0     0 )
24422       B = U(in) * (   Z1'   a   Z2'    b ) * VT(in)
24423                   (   0     0   D2(in) 0 )
24424 
24425         = U(out) * ( D(out) 0) * VT(out)
24426 
24427     where Z' = (Z1' a Z2' b) = u' VT', and u is a vector of dimension M
24428     with ALPHA and BETA in the NL+1 and NL+2 th entries and zeros
24429     elsewhere; and the entry b is empty if SQRE = 0.
24430 
24431     The left singular vectors of the original matrix are stored in U, and
24432     the transpose of the right singular vectors are stored in VT, and the
24433     singular values are in D.  The algorithm consists of three stages:
24434 
24435        The first stage consists of deflating the size of the problem
24436        when there are multiple singular values or when there are zeros in
24437        the Z vector.  For each such occurence the dimension of the
24438        secular equation problem is reduced by one.  This stage is
24439        performed by the routine DLASD2.
24440 
24441        The second stage consists of calculating the updated
24442        singular values. This is done by finding the square roots of the
24443        roots of the secular equation via the routine DLASD4 (as called
24444        by DLASD3). This routine also calculates the singular vectors of
24445        the current problem.
24446 
24447        The final stage consists of computing the updated singular vectors
24448        directly using the updated singular values.  The singular vectors
24449        for the current problem are multiplied with the singular vectors
24450        from the overall problem.
24451 
24452     Arguments
24453     =========
24454 
24455     NL     (input) INTEGER
24456            The row dimension of the upper block.  NL >= 1.
24457 
24458     NR     (input) INTEGER
24459            The row dimension of the lower block.  NR >= 1.
24460 
24461     SQRE   (input) INTEGER
24462            = 0: the lower block is an NR-by-NR square matrix.
24463            = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
24464 
24465            The bidiagonal matrix has row dimension N = NL + NR + 1,
24466            and column dimension M = N + SQRE.
24467 
24468     D      (input/output) DOUBLE PRECISION array,
24469                           dimension (N = NL+NR+1).
24470            On entry D(1:NL,1:NL) contains the singular values of the
24471            upper block; and D(NL+2:N) contains the singular values of
24472            the lower block. On exit D(1:N) contains the singular values
24473            of the modified matrix.
24474 
24475     ALPHA  (input/output) DOUBLE PRECISION
24476            Contains the diagonal element associated with the added row.
24477 
24478     BETA   (input/output) DOUBLE PRECISION
24479            Contains the off-diagonal element associated with the added
24480            row.
24481 
24482     U      (input/output) DOUBLE PRECISION array, dimension(LDU,N)
24483            On entry U(1:NL, 1:NL) contains the left singular vectors of
24484            the upper block; U(NL+2:N, NL+2:N) contains the left singular
24485            vectors of the lower block. On exit U contains the left
24486            singular vectors of the bidiagonal matrix.
24487 
24488     LDU    (input) INTEGER
24489            The leading dimension of the array U.  LDU >= max( 1, N ).
24490 
24491     VT     (input/output) DOUBLE PRECISION array, dimension(LDVT,M)
24492            where M = N + SQRE.
24493            On entry VT(1:NL+1, 1:NL+1)' contains the right singular
24494            vectors of the upper block; VT(NL+2:M, NL+2:M)' contains
24495            the right singular vectors of the lower block. On exit
24496            VT' contains the right singular vectors of the
24497            bidiagonal matrix.
24498 
24499     LDVT   (input) INTEGER
24500            The leading dimension of the array VT.  LDVT >= max( 1, M ).
24501 
24502     IDXQ  (output) INTEGER array, dimension(N)
24503            This contains the permutation which will reintegrate the
24504            subproblem just solved back into sorted order, i.e.
24505            D( IDXQ( I = 1, N ) ) will be in ascending order.
24506 
24507     IWORK  (workspace) INTEGER array, dimension( 4 * N )
24508 
24509     WORK   (workspace) DOUBLE PRECISION array, dimension( 3*M**2 + 2*M )
24510 
24511     INFO   (output) INTEGER
24512             = 0:  successful exit.
24513             < 0:  if INFO = -i, the i-th argument had an illegal value.
24514             > 0:  if INFO = 1, a singular value did not converge
24515 
24516     Further Details
24517     ===============
24518 
24519     Based on contributions by
24520        Ming Gu and Huan Ren, Computer Science Division, University of
24521        California at Berkeley, USA
24522 
24523     =====================================================================
24524 
24525 
24526        Test the input parameters.
24527 */
24528 
24529     /* Parameter adjustments */
24530     --d__;
24531     u_dim1 = *ldu;
24532     u_offset = 1 + u_dim1;
24533     u -= u_offset;
24534     vt_dim1 = *ldvt;
24535     vt_offset = 1 + vt_dim1;
24536     vt -= vt_offset;
24537     --idxq;
24538     --iwork;
24539     --work;
24540 
24541     /* Function Body */
24542     *info = 0;
24543 
24544     if (*nl < 1) {
24545 	*info = -1;
24546     } else if (*nr < 1) {
24547 	*info = -2;
24548     } else if (*sqre < 0 || *sqre > 1) {
24549 	*info = -3;
24550     }
24551     if (*info != 0) {
24552 	i__1 = -(*info);
24553 	xerbla_("DLASD1", &i__1);
24554 	return 0;
24555     }
24556 
24557     n = *nl + *nr + 1;
24558     m = n + *sqre;
24559 
24560 /*
24561        The following values are for bookkeeping purposes only.  They are
24562        integer pointers which indicate the portion of the workspace
24563        used by a particular array in DLASD2 and DLASD3.
24564 */
24565 
24566     ldu2 = n;
24567     ldvt2 = m;
24568 
24569     iz = 1;
24570     isigma = iz + m;
24571     iu2 = isigma + n;
24572     ivt2 = iu2 + ldu2 * n;
24573     iq = ivt2 + ldvt2 * m;
24574 
24575     idx = 1;
24576     idxc = idx + n;
24577     coltyp = idxc + n;
24578     idxp = coltyp + n;
24579 
24580 /*
24581        Scale.
24582 
24583    Computing MAX
24584 */
24585     d__1 = abs(*alpha), d__2 = abs(*beta);
24586     orgnrm = max(d__1,d__2);
24587     d__[*nl + 1] = 0.;
24588     i__1 = n;
24589     for (i__ = 1; i__ <= i__1; ++i__) {
24590 	if ((d__1 = d__[i__], abs(d__1)) > orgnrm) {
24591 	    orgnrm = (d__1 = d__[i__], abs(d__1));
24592 	}
24593 /* L10: */
24594     }
24595     dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, &n, &c__1, &d__[1], &n, info);
24596     *alpha /= orgnrm;
24597     *beta /= orgnrm;
24598 
24599 /*     Deflate singular values. */
24600 
24601     dlasd2_(nl, nr, sqre, &k, &d__[1], &work[iz], alpha, beta, &u[u_offset],
24602 	    ldu, &vt[vt_offset], ldvt, &work[isigma], &work[iu2], &ldu2, &
24603 	    work[ivt2], &ldvt2, &iwork[idxp], &iwork[idx], &iwork[idxc], &
24604 	    idxq[1], &iwork[coltyp], info);
24605 
24606 /*     Solve Secular Equation and update singular vectors. */
24607 
24608     ldq = k;
24609     dlasd3_(nl, nr, sqre, &k, &d__[1], &work[iq], &ldq, &work[isigma], &u[
24610 	    u_offset], ldu, &work[iu2], &ldu2, &vt[vt_offset], ldvt, &work[
24611 	    ivt2], &ldvt2, &iwork[idxc], &iwork[coltyp], &work[iz], info);
24612     if (*info != 0) {
24613 	return 0;
24614     }
24615 
24616 /*     Unscale. */
24617 
24618     dlascl_("G", &c__0, &c__0, &c_b15, &orgnrm, &n, &c__1, &d__[1], &n, info);
24619 
24620 /*     Prepare the IDXQ sorting permutation. */
24621 
24622     n1 = k;
24623     n2 = n - k;
24624     dlamrg_(&n1, &n2, &d__[1], &c__1, &c_n1, &idxq[1]);
24625 
24626     return 0;
24627 
24628 /*     End of DLASD1 */
24629 
24630 } /* dlasd1_ */
24631 
dlasd2_(integer * nl,integer * nr,integer * sqre,integer * k,doublereal * d__,doublereal * z__,doublereal * alpha,doublereal * beta,doublereal * u,integer * ldu,doublereal * vt,integer * ldvt,doublereal * dsigma,doublereal * u2,integer * ldu2,doublereal * vt2,integer * ldvt2,integer * idxp,integer * idx,integer * idxc,integer * idxq,integer * coltyp,integer * info)24632 /* Subroutine */ int dlasd2_(integer *nl, integer *nr, integer *sqre, integer
24633 	*k, doublereal *d__, doublereal *z__, doublereal *alpha, doublereal *
24634 	beta, doublereal *u, integer *ldu, doublereal *vt, integer *ldvt,
24635 	doublereal *dsigma, doublereal *u2, integer *ldu2, doublereal *vt2,
24636 	integer *ldvt2, integer *idxp, integer *idx, integer *idxc, integer *
24637 	idxq, integer *coltyp, integer *info)
24638 {
24639     /* System generated locals */
24640     integer u_dim1, u_offset, u2_dim1, u2_offset, vt_dim1, vt_offset,
24641 	    vt2_dim1, vt2_offset, i__1;
24642     doublereal d__1, d__2;
24643 
24644     /* Local variables */
24645     static doublereal c__;
24646     static integer i__, j, m, n;
24647     static doublereal s;
24648     static integer k2;
24649     static doublereal z1;
24650     static integer ct, jp;
24651     static doublereal eps, tau, tol;
24652     static integer psm[4], nlp1, nlp2, idxi, idxj;
24653     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
24654 	    doublereal *, integer *, doublereal *, doublereal *);
24655     static integer ctot[4], idxjp;
24656     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
24657 	    doublereal *, integer *);
24658     static integer jprev;
24659 
24660     extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *,
24661 	    integer *, integer *, integer *), dlacpy_(char *, integer *,
24662 	    integer *, doublereal *, integer *, doublereal *, integer *), dlaset_(char *, integer *, integer *, doublereal *,
24663 	    doublereal *, doublereal *, integer *), xerbla_(char *,
24664 	    integer *);
24665     static doublereal hlftol;
24666 
24667 
24668 /*
24669     -- LAPACK auxiliary routine (version 3.2) --
24670     -- LAPACK is a software package provided by Univ. of Tennessee,    --
24671     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
24672        November 2006
24673 
24674 
24675     Purpose
24676     =======
24677 
24678     DLASD2 merges the two sets of singular values together into a single
24679     sorted set.  Then it tries to deflate the size of the problem.
24680     There are two ways in which deflation can occur:  when two or more
24681     singular values are close together or if there is a tiny entry in the
24682     Z vector.  For each such occurrence the order of the related secular
24683     equation problem is reduced by one.
24684 
24685     DLASD2 is called from DLASD1.
24686 
24687     Arguments
24688     =========
24689 
24690     NL     (input) INTEGER
24691            The row dimension of the upper block.  NL >= 1.
24692 
24693     NR     (input) INTEGER
24694            The row dimension of the lower block.  NR >= 1.
24695 
24696     SQRE   (input) INTEGER
24697            = 0: the lower block is an NR-by-NR square matrix.
24698            = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
24699 
24700            The bidiagonal matrix has N = NL + NR + 1 rows and
24701            M = N + SQRE >= N columns.
24702 
24703     K      (output) INTEGER
24704            Contains the dimension of the non-deflated matrix,
24705            This is the order of the related secular equation. 1 <= K <=N.
24706 
24707     D      (input/output) DOUBLE PRECISION array, dimension(N)
24708            On entry D contains the singular values of the two submatrices
24709            to be combined.  On exit D contains the trailing (N-K) updated
24710            singular values (those which were deflated) sorted into
24711            increasing order.
24712 
24713     Z      (output) DOUBLE PRECISION array, dimension(N)
24714            On exit Z contains the updating row vector in the secular
24715            equation.
24716 
24717     ALPHA  (input) DOUBLE PRECISION
24718            Contains the diagonal element associated with the added row.
24719 
24720     BETA   (input) DOUBLE PRECISION
24721            Contains the off-diagonal element associated with the added
24722            row.
24723 
24724     U      (input/output) DOUBLE PRECISION array, dimension(LDU,N)
24725            On entry U contains the left singular vectors of two
24726            submatrices in the two square blocks with corners at (1,1),
24727            (NL, NL), and (NL+2, NL+2), (N,N).
24728            On exit U contains the trailing (N-K) updated left singular
24729            vectors (those which were deflated) in its last N-K columns.
24730 
24731     LDU    (input) INTEGER
24732            The leading dimension of the array U.  LDU >= N.
24733 
24734     VT     (input/output) DOUBLE PRECISION array, dimension(LDVT,M)
24735            On entry VT' contains the right singular vectors of two
24736            submatrices in the two square blocks with corners at (1,1),
24737            (NL+1, NL+1), and (NL+2, NL+2), (M,M).
24738            On exit VT' contains the trailing (N-K) updated right singular
24739            vectors (those which were deflated) in its last N-K columns.
24740            In case SQRE =1, the last row of VT spans the right null
24741            space.
24742 
24743     LDVT   (input) INTEGER
24744            The leading dimension of the array VT.  LDVT >= M.
24745 
24746     DSIGMA (output) DOUBLE PRECISION array, dimension (N)
24747            Contains a copy of the diagonal elements (K-1 singular values
24748            and one zero) in the secular equation.
24749 
24750     U2     (output) DOUBLE PRECISION array, dimension(LDU2,N)
24751            Contains a copy of the first K-1 left singular vectors which
24752            will be used by DLASD3 in a matrix multiply (DGEMM) to solve
24753            for the new left singular vectors. U2 is arranged into four
24754            blocks. The first block contains a column with 1 at NL+1 and
24755            zero everywhere else; the second block contains non-zero
24756            entries only at and above NL; the third contains non-zero
24757            entries only below NL+1; and the fourth is dense.
24758 
24759     LDU2   (input) INTEGER
24760            The leading dimension of the array U2.  LDU2 >= N.
24761 
24762     VT2    (output) DOUBLE PRECISION array, dimension(LDVT2,N)
24763            VT2' contains a copy of the first K right singular vectors
24764            which will be used by DLASD3 in a matrix multiply (DGEMM) to
24765            solve for the new right singular vectors. VT2 is arranged into
24766            three blocks. The first block contains a row that corresponds
24767            to the special 0 diagonal element in SIGMA; the second block
24768            contains non-zeros only at and before NL +1; the third block
24769            contains non-zeros only at and after  NL +2.
24770 
24771     LDVT2  (input) INTEGER
24772            The leading dimension of the array VT2.  LDVT2 >= M.
24773 
24774     IDXP   (workspace) INTEGER array dimension(N)
24775            This will contain the permutation used to place deflated
24776            values of D at the end of the array. On output IDXP(2:K)
24777            points to the nondeflated D-values and IDXP(K+1:N)
24778            points to the deflated singular values.
24779 
24780     IDX    (workspace) INTEGER array dimension(N)
24781            This will contain the permutation used to sort the contents of
24782            D into ascending order.
24783 
24784     IDXC   (output) INTEGER array dimension(N)
24785            This will contain the permutation used to arrange the columns
24786            of the deflated U matrix into three groups:  the first group
24787            contains non-zero entries only at and above NL, the second
24788            contains non-zero entries only below NL+2, and the third is
24789            dense.
24790 
24791     IDXQ   (input/output) INTEGER array dimension(N)
24792            This contains the permutation which separately sorts the two
24793            sub-problems in D into ascending order.  Note that entries in
24794            the first hlaf of this permutation must first be moved one
24795            position backward; and entries in the second half
24796            must first have NL+1 added to their values.
24797 
24798     COLTYP (workspace/output) INTEGER array dimension(N)
24799            As workspace, this will contain a label which will indicate
24800            which of the following types a column in the U2 matrix or a
24801            row in the VT2 matrix is:
24802            1 : non-zero in the upper half only
24803            2 : non-zero in the lower half only
24804            3 : dense
24805            4 : deflated
24806 
24807            On exit, it is an array of dimension 4, with COLTYP(I) being
24808            the dimension of the I-th type columns.
24809 
24810     INFO   (output) INTEGER
24811             = 0:  successful exit.
24812             < 0:  if INFO = -i, the i-th argument had an illegal value.
24813 
24814     Further Details
24815     ===============
24816 
24817     Based on contributions by
24818        Ming Gu and Huan Ren, Computer Science Division, University of
24819        California at Berkeley, USA
24820 
24821     =====================================================================
24822 
24823 
24824        Test the input parameters.
24825 */
24826 
24827     /* Parameter adjustments */
24828     --d__;
24829     --z__;
24830     u_dim1 = *ldu;
24831     u_offset = 1 + u_dim1;
24832     u -= u_offset;
24833     vt_dim1 = *ldvt;
24834     vt_offset = 1 + vt_dim1;
24835     vt -= vt_offset;
24836     --dsigma;
24837     u2_dim1 = *ldu2;
24838     u2_offset = 1 + u2_dim1;
24839     u2 -= u2_offset;
24840     vt2_dim1 = *ldvt2;
24841     vt2_offset = 1 + vt2_dim1;
24842     vt2 -= vt2_offset;
24843     --idxp;
24844     --idx;
24845     --idxc;
24846     --idxq;
24847     --coltyp;
24848 
24849     /* Function Body */
24850     *info = 0;
24851 
24852     if (*nl < 1) {
24853 	*info = -1;
24854     } else if (*nr < 1) {
24855 	*info = -2;
24856     } else if (*sqre != 1 && *sqre != 0) {
24857 	*info = -3;
24858     }
24859 
24860     n = *nl + *nr + 1;
24861     m = n + *sqre;
24862 
24863     if (*ldu < n) {
24864 	*info = -10;
24865     } else if (*ldvt < m) {
24866 	*info = -12;
24867     } else if (*ldu2 < n) {
24868 	*info = -15;
24869     } else if (*ldvt2 < m) {
24870 	*info = -17;
24871     }
24872     if (*info != 0) {
24873 	i__1 = -(*info);
24874 	xerbla_("DLASD2", &i__1);
24875 	return 0;
24876     }
24877 
24878     nlp1 = *nl + 1;
24879     nlp2 = *nl + 2;
24880 
24881 /*
24882        Generate the first part of the vector Z; and move the singular
24883        values in the first part of D one position backward.
24884 */
24885 
24886     z1 = *alpha * vt[nlp1 + nlp1 * vt_dim1];
24887     z__[1] = z1;
24888     for (i__ = *nl; i__ >= 1; --i__) {
24889 	z__[i__ + 1] = *alpha * vt[i__ + nlp1 * vt_dim1];
24890 	d__[i__ + 1] = d__[i__];
24891 	idxq[i__ + 1] = idxq[i__] + 1;
24892 /* L10: */
24893     }
24894 
24895 /*     Generate the second part of the vector Z. */
24896 
24897     i__1 = m;
24898     for (i__ = nlp2; i__ <= i__1; ++i__) {
24899 	z__[i__] = *beta * vt[i__ + nlp2 * vt_dim1];
24900 /* L20: */
24901     }
24902 
24903 /*     Initialize some reference arrays. */
24904 
24905     i__1 = nlp1;
24906     for (i__ = 2; i__ <= i__1; ++i__) {
24907 	coltyp[i__] = 1;
24908 /* L30: */
24909     }
24910     i__1 = n;
24911     for (i__ = nlp2; i__ <= i__1; ++i__) {
24912 	coltyp[i__] = 2;
24913 /* L40: */
24914     }
24915 
24916 /*     Sort the singular values into increasing order */
24917 
24918     i__1 = n;
24919     for (i__ = nlp2; i__ <= i__1; ++i__) {
24920 	idxq[i__] += nlp1;
24921 /* L50: */
24922     }
24923 
24924 /*
24925        DSIGMA, IDXC, IDXC, and the first column of U2
24926        are used as storage space.
24927 */
24928 
24929     i__1 = n;
24930     for (i__ = 2; i__ <= i__1; ++i__) {
24931 	dsigma[i__] = d__[idxq[i__]];
24932 	u2[i__ + u2_dim1] = z__[idxq[i__]];
24933 	idxc[i__] = coltyp[idxq[i__]];
24934 /* L60: */
24935     }
24936 
24937     dlamrg_(nl, nr, &dsigma[2], &c__1, &c__1, &idx[2]);
24938 
24939     i__1 = n;
24940     for (i__ = 2; i__ <= i__1; ++i__) {
24941 	idxi = idx[i__] + 1;
24942 	d__[i__] = dsigma[idxi];
24943 	z__[i__] = u2[idxi + u2_dim1];
24944 	coltyp[i__] = idxc[idxi];
24945 /* L70: */
24946     }
24947 
24948 /*     Calculate the allowable deflation tolerance */
24949 
24950     eps = EPSILON;
24951 /* Computing MAX */
24952     d__1 = abs(*alpha), d__2 = abs(*beta);
24953     tol = max(d__1,d__2);
24954 /* Computing MAX */
24955     d__2 = (d__1 = d__[n], abs(d__1));
24956     tol = eps * 8. * max(d__2,tol);
24957 
24958 /*
24959        There are 2 kinds of deflation -- first a value in the z-vector
24960        is small, second two (or more) singular values are very close
24961        together (their difference is small).
24962 
24963        If the value in the z-vector is small, we simply permute the
24964        array so that the corresponding singular value is moved to the
24965        end.
24966 
24967        If two values in the D-vector are close, we perform a two-sided
24968        rotation designed to make one of the corresponding z-vector
24969        entries zero, and then permute the array so that the deflated
24970        singular value is moved to the end.
24971 
24972        If there are multiple singular values then the problem deflates.
24973        Here the number of equal singular values are found.  As each equal
24974        singular value is found, an elementary reflector is computed to
24975        rotate the corresponding singular subspace so that the
24976        corresponding components of Z are zero in this new basis.
24977 */
24978 
24979     *k = 1;
24980     k2 = n + 1;
24981     i__1 = n;
24982     for (j = 2; j <= i__1; ++j) {
24983 	if ((d__1 = z__[j], abs(d__1)) <= tol) {
24984 
24985 /*           Deflate due to small z component. */
24986 
24987 	    --k2;
24988 	    idxp[k2] = j;
24989 	    coltyp[j] = 4;
24990 	    if (j == n) {
24991 		goto L120;
24992 	    }
24993 	} else {
24994 	    jprev = j;
24995 	    goto L90;
24996 	}
24997 /* L80: */
24998     }
24999 L90:
25000     j = jprev;
25001 L100:
25002     ++j;
25003     if (j > n) {
25004 	goto L110;
25005     }
25006     if ((d__1 = z__[j], abs(d__1)) <= tol) {
25007 
25008 /*        Deflate due to small z component. */
25009 
25010 	--k2;
25011 	idxp[k2] = j;
25012 	coltyp[j] = 4;
25013     } else {
25014 
25015 /*        Check if singular values are close enough to allow deflation. */
25016 
25017 	if ((d__1 = d__[j] - d__[jprev], abs(d__1)) <= tol) {
25018 
25019 /*           Deflation is possible. */
25020 
25021 	    s = z__[jprev];
25022 	    c__ = z__[j];
25023 
25024 /*
25025              Find sqrt(a**2+b**2) without overflow or
25026              destructive underflow.
25027 */
25028 
25029 	    tau = dlapy2_(&c__, &s);
25030 	    c__ /= tau;
25031 	    s = -s / tau;
25032 	    z__[j] = tau;
25033 	    z__[jprev] = 0.;
25034 
25035 /*
25036              Apply back the Givens rotation to the left and right
25037              singular vector matrices.
25038 */
25039 
25040 	    idxjp = idxq[idx[jprev] + 1];
25041 	    idxj = idxq[idx[j] + 1];
25042 	    if (idxjp <= nlp1) {
25043 		--idxjp;
25044 	    }
25045 	    if (idxj <= nlp1) {
25046 		--idxj;
25047 	    }
25048 	    drot_(&n, &u[idxjp * u_dim1 + 1], &c__1, &u[idxj * u_dim1 + 1], &
25049 		    c__1, &c__, &s);
25050 	    drot_(&m, &vt[idxjp + vt_dim1], ldvt, &vt[idxj + vt_dim1], ldvt, &
25051 		    c__, &s);
25052 	    if (coltyp[j] != coltyp[jprev]) {
25053 		coltyp[j] = 3;
25054 	    }
25055 	    coltyp[jprev] = 4;
25056 	    --k2;
25057 	    idxp[k2] = jprev;
25058 	    jprev = j;
25059 	} else {
25060 	    ++(*k);
25061 	    u2[*k + u2_dim1] = z__[jprev];
25062 	    dsigma[*k] = d__[jprev];
25063 	    idxp[*k] = jprev;
25064 	    jprev = j;
25065 	}
25066     }
25067     goto L100;
25068 L110:
25069 
25070 /*     Record the last singular value. */
25071 
25072     ++(*k);
25073     u2[*k + u2_dim1] = z__[jprev];
25074     dsigma[*k] = d__[jprev];
25075     idxp[*k] = jprev;
25076 
25077 L120:
25078 
25079 /*
25080        Count up the total number of the various types of columns, then
25081        form a permutation which positions the four column types into
25082        four groups of uniform structure (although one or more of these
25083        groups may be empty).
25084 */
25085 
25086     for (j = 1; j <= 4; ++j) {
25087 	ctot[j - 1] = 0;
25088 /* L130: */
25089     }
25090     i__1 = n;
25091     for (j = 2; j <= i__1; ++j) {
25092 	ct = coltyp[j];
25093 	++ctot[ct - 1];
25094 /* L140: */
25095     }
25096 
25097 /*     PSM(*) = Position in SubMatrix (of types 1 through 4) */
25098 
25099     psm[0] = 2;
25100     psm[1] = ctot[0] + 2;
25101     psm[2] = psm[1] + ctot[1];
25102     psm[3] = psm[2] + ctot[2];
25103 
25104 /*
25105        Fill out the IDXC array so that the permutation which it induces
25106        will place all type-1 columns first, all type-2 columns next,
25107        then all type-3's, and finally all type-4's, starting from the
25108        second column. This applies similarly to the rows of VT.
25109 */
25110 
25111     i__1 = n;
25112     for (j = 2; j <= i__1; ++j) {
25113 	jp = idxp[j];
25114 	ct = coltyp[jp];
25115 	idxc[psm[ct - 1]] = j;
25116 	++psm[ct - 1];
25117 /* L150: */
25118     }
25119 
25120 /*
25121        Sort the singular values and corresponding singular vectors into
25122        DSIGMA, U2, and VT2 respectively.  The singular values/vectors
25123        which were not deflated go into the first K slots of DSIGMA, U2,
25124        and VT2 respectively, while those which were deflated go into the
25125        last N - K slots, except that the first column/row will be treated
25126        separately.
25127 */
25128 
25129     i__1 = n;
25130     for (j = 2; j <= i__1; ++j) {
25131 	jp = idxp[j];
25132 	dsigma[j] = d__[jp];
25133 	idxj = idxq[idx[idxp[idxc[j]]] + 1];
25134 	if (idxj <= nlp1) {
25135 	    --idxj;
25136 	}
25137 	dcopy_(&n, &u[idxj * u_dim1 + 1], &c__1, &u2[j * u2_dim1 + 1], &c__1);
25138 	dcopy_(&m, &vt[idxj + vt_dim1], ldvt, &vt2[j + vt2_dim1], ldvt2);
25139 /* L160: */
25140     }
25141 
25142 /*     Determine DSIGMA(1), DSIGMA(2) and Z(1) */
25143 
25144     dsigma[1] = 0.;
25145     hlftol = tol / 2.;
25146     if (abs(dsigma[2]) <= hlftol) {
25147 	dsigma[2] = hlftol;
25148     }
25149     if (m > n) {
25150 	z__[1] = dlapy2_(&z1, &z__[m]);
25151 	if (z__[1] <= tol) {
25152 	    c__ = 1.;
25153 	    s = 0.;
25154 	    z__[1] = tol;
25155 	} else {
25156 	    c__ = z1 / z__[1];
25157 	    s = z__[m] / z__[1];
25158 	}
25159     } else {
25160 	if (abs(z1) <= tol) {
25161 	    z__[1] = tol;
25162 	} else {
25163 	    z__[1] = z1;
25164 	}
25165     }
25166 
25167 /*     Move the rest of the updating row to Z. */
25168 
25169     i__1 = *k - 1;
25170     dcopy_(&i__1, &u2[u2_dim1 + 2], &c__1, &z__[2], &c__1);
25171 
25172 /*
25173        Determine the first column of U2, the first row of VT2 and the
25174        last row of VT.
25175 */
25176 
25177     dlaset_("A", &n, &c__1, &c_b29, &c_b29, &u2[u2_offset], ldu2);
25178     u2[nlp1 + u2_dim1] = 1.;
25179     if (m > n) {
25180 	i__1 = nlp1;
25181 	for (i__ = 1; i__ <= i__1; ++i__) {
25182 	    vt[m + i__ * vt_dim1] = -s * vt[nlp1 + i__ * vt_dim1];
25183 	    vt2[i__ * vt2_dim1 + 1] = c__ * vt[nlp1 + i__ * vt_dim1];
25184 /* L170: */
25185 	}
25186 	i__1 = m;
25187 	for (i__ = nlp2; i__ <= i__1; ++i__) {
25188 	    vt2[i__ * vt2_dim1 + 1] = s * vt[m + i__ * vt_dim1];
25189 	    vt[m + i__ * vt_dim1] = c__ * vt[m + i__ * vt_dim1];
25190 /* L180: */
25191 	}
25192     } else {
25193 	dcopy_(&m, &vt[nlp1 + vt_dim1], ldvt, &vt2[vt2_dim1 + 1], ldvt2);
25194     }
25195     if (m > n) {
25196 	dcopy_(&m, &vt[m + vt_dim1], ldvt, &vt2[m + vt2_dim1], ldvt2);
25197     }
25198 
25199 /*
25200        The deflated singular values and their corresponding vectors go
25201        into the back of D, U, and V respectively.
25202 */
25203 
25204     if (n > *k) {
25205 	i__1 = n - *k;
25206 	dcopy_(&i__1, &dsigma[*k + 1], &c__1, &d__[*k + 1], &c__1);
25207 	i__1 = n - *k;
25208 	dlacpy_("A", &n, &i__1, &u2[(*k + 1) * u2_dim1 + 1], ldu2, &u[(*k + 1)
25209 		 * u_dim1 + 1], ldu);
25210 	i__1 = n - *k;
25211 	dlacpy_("A", &i__1, &m, &vt2[*k + 1 + vt2_dim1], ldvt2, &vt[*k + 1 +
25212 		vt_dim1], ldvt);
25213     }
25214 
25215 /*     Copy CTOT into COLTYP for referencing in DLASD3. */
25216 
25217     for (j = 1; j <= 4; ++j) {
25218 	coltyp[j] = ctot[j - 1];
25219 /* L190: */
25220     }
25221 
25222     return 0;
25223 
25224 /*     End of DLASD2 */
25225 
25226 } /* dlasd2_ */
25227 
dlasd3_(integer * nl,integer * nr,integer * sqre,integer * k,doublereal * d__,doublereal * q,integer * ldq,doublereal * dsigma,doublereal * u,integer * ldu,doublereal * u2,integer * ldu2,doublereal * vt,integer * ldvt,doublereal * vt2,integer * ldvt2,integer * idxc,integer * ctot,doublereal * z__,integer * info)25228 /* Subroutine */ int dlasd3_(integer *nl, integer *nr, integer *sqre, integer
25229 	*k, doublereal *d__, doublereal *q, integer *ldq, doublereal *dsigma,
25230 	doublereal *u, integer *ldu, doublereal *u2, integer *ldu2,
25231 	doublereal *vt, integer *ldvt, doublereal *vt2, integer *ldvt2,
25232 	integer *idxc, integer *ctot, doublereal *z__, integer *info)
25233 {
25234     /* System generated locals */
25235     integer q_dim1, q_offset, u_dim1, u_offset, u2_dim1, u2_offset, vt_dim1,
25236 	    vt_offset, vt2_dim1, vt2_offset, i__1, i__2;
25237     doublereal d__1, d__2;
25238 
25239     /* Local variables */
25240     static integer i__, j, m, n, jc;
25241     static doublereal rho;
25242     static integer nlp1, nlp2, nrp1;
25243     static doublereal temp;
25244     extern doublereal dnrm2_(integer *, doublereal *, integer *);
25245     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
25246 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
25247 	    integer *, doublereal *, doublereal *, integer *);
25248     static integer ctemp;
25249     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
25250 	    doublereal *, integer *);
25251     static integer ktemp;
25252     extern doublereal dlamc3_(doublereal *, doublereal *);
25253     extern /* Subroutine */ int dlasd4_(integer *, integer *, doublereal *,
25254 	    doublereal *, doublereal *, doublereal *, doublereal *,
25255 	    doublereal *, integer *), dlascl_(char *, integer *, integer *,
25256 	    doublereal *, doublereal *, integer *, integer *, doublereal *,
25257 	    integer *, integer *), dlacpy_(char *, integer *, integer
25258 	    *, doublereal *, integer *, doublereal *, integer *),
25259 	    xerbla_(char *, integer *);
25260 
25261 
25262 /*
25263     -- LAPACK auxiliary routine (version 3.2.2) --
25264     -- LAPACK is a software package provided by Univ. of Tennessee,    --
25265     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
25266        June 2010
25267 
25268 
25269     Purpose
25270     =======
25271 
25272     DLASD3 finds all the square roots of the roots of the secular
25273     equation, as defined by the values in D and Z.  It makes the
25274     appropriate calls to DLASD4 and then updates the singular
25275     vectors by matrix multiplication.
25276 
25277     This code makes very mild assumptions about floating point
25278     arithmetic. It will work on machines with a guard digit in
25279     add/subtract, or on those binary machines without guard digits
25280     which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2.
25281     It could conceivably fail on hexadecimal or decimal machines
25282     without guard digits, but we know of none.
25283 
25284     DLASD3 is called from DLASD1.
25285 
25286     Arguments
25287     =========
25288 
25289     NL     (input) INTEGER
25290            The row dimension of the upper block.  NL >= 1.
25291 
25292     NR     (input) INTEGER
25293            The row dimension of the lower block.  NR >= 1.
25294 
25295     SQRE   (input) INTEGER
25296            = 0: the lower block is an NR-by-NR square matrix.
25297            = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
25298 
25299            The bidiagonal matrix has N = NL + NR + 1 rows and
25300            M = N + SQRE >= N columns.
25301 
25302     K      (input) INTEGER
25303            The size of the secular equation, 1 =< K = < N.
25304 
25305     D      (output) DOUBLE PRECISION array, dimension(K)
25306            On exit the square roots of the roots of the secular equation,
25307            in ascending order.
25308 
25309     Q      (workspace) DOUBLE PRECISION array,
25310                        dimension at least (LDQ,K).
25311 
25312     LDQ    (input) INTEGER
25313            The leading dimension of the array Q.  LDQ >= K.
25314 
25315     DSIGMA (input) DOUBLE PRECISION array, dimension(K)
25316            The first K elements of this array contain the old roots
25317            of the deflated updating problem.  These are the poles
25318            of the secular equation.
25319 
25320     U      (output) DOUBLE PRECISION array, dimension (LDU, N)
25321            The last N - K columns of this matrix contain the deflated
25322            left singular vectors.
25323 
25324     LDU    (input) INTEGER
25325            The leading dimension of the array U.  LDU >= N.
25326 
25327     U2     (input/output) DOUBLE PRECISION array, dimension (LDU2, N)
25328            The first K columns of this matrix contain the non-deflated
25329            left singular vectors for the split problem.
25330 
25331     LDU2   (input) INTEGER
25332            The leading dimension of the array U2.  LDU2 >= N.
25333 
25334     VT     (output) DOUBLE PRECISION array, dimension (LDVT, M)
25335            The last M - K columns of VT' contain the deflated
25336            right singular vectors.
25337 
25338     LDVT   (input) INTEGER
25339            The leading dimension of the array VT.  LDVT >= N.
25340 
25341     VT2    (input/output) DOUBLE PRECISION array, dimension (LDVT2, N)
25342            The first K columns of VT2' contain the non-deflated
25343            right singular vectors for the split problem.
25344 
25345     LDVT2  (input) INTEGER
25346            The leading dimension of the array VT2.  LDVT2 >= N.
25347 
25348     IDXC   (input) INTEGER array, dimension ( N )
25349            The permutation used to arrange the columns of U (and rows of
25350            VT) into three groups:  the first group contains non-zero
25351            entries only at and above (or before) NL +1; the second
25352            contains non-zero entries only at and below (or after) NL+2;
25353            and the third is dense. The first column of U and the row of
25354            VT are treated separately, however.
25355 
25356            The rows of the singular vectors found by DLASD4
25357            must be likewise permuted before the matrix multiplies can
25358            take place.
25359 
25360     CTOT   (input) INTEGER array, dimension ( 4 )
25361            A count of the total number of the various types of columns
25362            in U (or rows in VT), as described in IDXC. The fourth column
25363            type is any column which has been deflated.
25364 
25365     Z      (input) DOUBLE PRECISION array, dimension (K)
25366            The first K elements of this array contain the components
25367            of the deflation-adjusted updating row vector.
25368 
25369     INFO   (output) INTEGER
25370            = 0:  successful exit.
25371            < 0:  if INFO = -i, the i-th argument had an illegal value.
25372            > 0:  if INFO = 1, a singular value did not converge
25373 
25374     Further Details
25375     ===============
25376 
25377     Based on contributions by
25378        Ming Gu and Huan Ren, Computer Science Division, University of
25379        California at Berkeley, USA
25380 
25381     =====================================================================
25382 
25383 
25384        Test the input parameters.
25385 */
25386 
25387     /* Parameter adjustments */
25388     --d__;
25389     q_dim1 = *ldq;
25390     q_offset = 1 + q_dim1;
25391     q -= q_offset;
25392     --dsigma;
25393     u_dim1 = *ldu;
25394     u_offset = 1 + u_dim1;
25395     u -= u_offset;
25396     u2_dim1 = *ldu2;
25397     u2_offset = 1 + u2_dim1;
25398     u2 -= u2_offset;
25399     vt_dim1 = *ldvt;
25400     vt_offset = 1 + vt_dim1;
25401     vt -= vt_offset;
25402     vt2_dim1 = *ldvt2;
25403     vt2_offset = 1 + vt2_dim1;
25404     vt2 -= vt2_offset;
25405     --idxc;
25406     --ctot;
25407     --z__;
25408 
25409     /* Function Body */
25410     *info = 0;
25411 
25412     if (*nl < 1) {
25413 	*info = -1;
25414     } else if (*nr < 1) {
25415 	*info = -2;
25416     } else if (*sqre != 1 && *sqre != 0) {
25417 	*info = -3;
25418     }
25419 
25420     n = *nl + *nr + 1;
25421     m = n + *sqre;
25422     nlp1 = *nl + 1;
25423     nlp2 = *nl + 2;
25424 
25425     if (*k < 1 || *k > n) {
25426 	*info = -4;
25427     } else if (*ldq < *k) {
25428 	*info = -7;
25429     } else if (*ldu < n) {
25430 	*info = -10;
25431     } else if (*ldu2 < n) {
25432 	*info = -12;
25433     } else if (*ldvt < m) {
25434 	*info = -14;
25435     } else if (*ldvt2 < m) {
25436 	*info = -16;
25437     }
25438     if (*info != 0) {
25439 	i__1 = -(*info);
25440 	xerbla_("DLASD3", &i__1);
25441 	return 0;
25442     }
25443 
25444 /*     Quick return if possible */
25445 
25446     if (*k == 1) {
25447 	d__[1] = abs(z__[1]);
25448 	dcopy_(&m, &vt2[vt2_dim1 + 1], ldvt2, &vt[vt_dim1 + 1], ldvt);
25449 	if (z__[1] > 0.) {
25450 	    dcopy_(&n, &u2[u2_dim1 + 1], &c__1, &u[u_dim1 + 1], &c__1);
25451 	} else {
25452 	    i__1 = n;
25453 	    for (i__ = 1; i__ <= i__1; ++i__) {
25454 		u[i__ + u_dim1] = -u2[i__ + u2_dim1];
25455 /* L10: */
25456 	    }
25457 	}
25458 	return 0;
25459     }
25460 
25461 /*
25462        Modify values DSIGMA(i) to make sure all DSIGMA(i)-DSIGMA(j) can
25463        be computed with high relative accuracy (barring over/underflow).
25464        This is a problem on machines without a guard digit in
25465        add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2).
25466        The following code replaces DSIGMA(I) by 2*DSIGMA(I)-DSIGMA(I),
25467        which on any of these machines zeros out the bottommost
25468        bit of DSIGMA(I) if it is 1; this makes the subsequent
25469        subtractions DSIGMA(I)-DSIGMA(J) unproblematic when cancellation
25470        occurs. On binary machines with a guard digit (almost all
25471        machines) it does not change DSIGMA(I) at all. On hexadecimal
25472        and decimal machines with a guard digit, it slightly
25473        changes the bottommost bits of DSIGMA(I). It does not account
25474        for hexadecimal or decimal machines without guard digits
25475        (we know of none). We use a subroutine call to compute
25476        2*DSIGMA(I) to prevent optimizing compilers from eliminating
25477        this code.
25478 */
25479 
25480     i__1 = *k;
25481     for (i__ = 1; i__ <= i__1; ++i__) {
25482 	dsigma[i__] = dlamc3_(&dsigma[i__], &dsigma[i__]) - dsigma[i__];
25483 /* L20: */
25484     }
25485 
25486 /*     Keep a copy of Z. */
25487 
25488     dcopy_(k, &z__[1], &c__1, &q[q_offset], &c__1);
25489 
25490 /*     Normalize Z. */
25491 
25492     rho = dnrm2_(k, &z__[1], &c__1);
25493     dlascl_("G", &c__0, &c__0, &rho, &c_b15, k, &c__1, &z__[1], k, info);
25494     rho *= rho;
25495 
25496 /*     Find the new singular values. */
25497 
25498     i__1 = *k;
25499     for (j = 1; j <= i__1; ++j) {
25500 	dlasd4_(k, &j, &dsigma[1], &z__[1], &u[j * u_dim1 + 1], &rho, &d__[j],
25501 		 &vt[j * vt_dim1 + 1], info);
25502 
25503 /*        If the zero finder fails, the computation is terminated. */
25504 
25505 	if (*info != 0) {
25506 	    return 0;
25507 	}
25508 /* L30: */
25509     }
25510 
25511 /*     Compute updated Z. */
25512 
25513     i__1 = *k;
25514     for (i__ = 1; i__ <= i__1; ++i__) {
25515 	z__[i__] = u[i__ + *k * u_dim1] * vt[i__ + *k * vt_dim1];
25516 	i__2 = i__ - 1;
25517 	for (j = 1; j <= i__2; ++j) {
25518 	    z__[i__] *= u[i__ + j * u_dim1] * vt[i__ + j * vt_dim1] / (dsigma[
25519 		    i__] - dsigma[j]) / (dsigma[i__] + dsigma[j]);
25520 /* L40: */
25521 	}
25522 	i__2 = *k - 1;
25523 	for (j = i__; j <= i__2; ++j) {
25524 	    z__[i__] *= u[i__ + j * u_dim1] * vt[i__ + j * vt_dim1] / (dsigma[
25525 		    i__] - dsigma[j + 1]) / (dsigma[i__] + dsigma[j + 1]);
25526 /* L50: */
25527 	}
25528 	d__2 = sqrt((d__1 = z__[i__], abs(d__1)));
25529 	z__[i__] = d_sign(&d__2, &q[i__ + q_dim1]);
25530 /* L60: */
25531     }
25532 
25533 /*
25534        Compute left singular vectors of the modified diagonal matrix,
25535        and store related information for the right singular vectors.
25536 */
25537 
25538     i__1 = *k;
25539     for (i__ = 1; i__ <= i__1; ++i__) {
25540 	vt[i__ * vt_dim1 + 1] = z__[1] / u[i__ * u_dim1 + 1] / vt[i__ *
25541 		vt_dim1 + 1];
25542 	u[i__ * u_dim1 + 1] = -1.;
25543 	i__2 = *k;
25544 	for (j = 2; j <= i__2; ++j) {
25545 	    vt[j + i__ * vt_dim1] = z__[j] / u[j + i__ * u_dim1] / vt[j + i__
25546 		    * vt_dim1];
25547 	    u[j + i__ * u_dim1] = dsigma[j] * vt[j + i__ * vt_dim1];
25548 /* L70: */
25549 	}
25550 	temp = dnrm2_(k, &u[i__ * u_dim1 + 1], &c__1);
25551 	q[i__ * q_dim1 + 1] = u[i__ * u_dim1 + 1] / temp;
25552 	i__2 = *k;
25553 	for (j = 2; j <= i__2; ++j) {
25554 	    jc = idxc[j];
25555 	    q[j + i__ * q_dim1] = u[jc + i__ * u_dim1] / temp;
25556 /* L80: */
25557 	}
25558 /* L90: */
25559     }
25560 
25561 /*     Update the left singular vector matrix. */
25562 
25563     if (*k == 2) {
25564 	dgemm_("N", "N", &n, k, k, &c_b15, &u2[u2_offset], ldu2, &q[q_offset],
25565 		 ldq, &c_b29, &u[u_offset], ldu);
25566 	goto L100;
25567     }
25568     if (ctot[1] > 0) {
25569 	dgemm_("N", "N", nl, k, &ctot[1], &c_b15, &u2[(u2_dim1 << 1) + 1],
25570 		ldu2, &q[q_dim1 + 2], ldq, &c_b29, &u[u_dim1 + 1], ldu);
25571 	if (ctot[3] > 0) {
25572 	    ktemp = ctot[1] + 2 + ctot[2];
25573 	    dgemm_("N", "N", nl, k, &ctot[3], &c_b15, &u2[ktemp * u2_dim1 + 1]
25574 		    , ldu2, &q[ktemp + q_dim1], ldq, &c_b15, &u[u_dim1 + 1],
25575 		    ldu);
25576 	}
25577     } else if (ctot[3] > 0) {
25578 	ktemp = ctot[1] + 2 + ctot[2];
25579 	dgemm_("N", "N", nl, k, &ctot[3], &c_b15, &u2[ktemp * u2_dim1 + 1],
25580 		ldu2, &q[ktemp + q_dim1], ldq, &c_b29, &u[u_dim1 + 1], ldu);
25581     } else {
25582 	dlacpy_("F", nl, k, &u2[u2_offset], ldu2, &u[u_offset], ldu);
25583     }
25584     dcopy_(k, &q[q_dim1 + 1], ldq, &u[nlp1 + u_dim1], ldu);
25585     ktemp = ctot[1] + 2;
25586     ctemp = ctot[2] + ctot[3];
25587     dgemm_("N", "N", nr, k, &ctemp, &c_b15, &u2[nlp2 + ktemp * u2_dim1], ldu2,
25588 	     &q[ktemp + q_dim1], ldq, &c_b29, &u[nlp2 + u_dim1], ldu);
25589 
25590 /*     Generate the right singular vectors. */
25591 
25592 L100:
25593     i__1 = *k;
25594     for (i__ = 1; i__ <= i__1; ++i__) {
25595 	temp = dnrm2_(k, &vt[i__ * vt_dim1 + 1], &c__1);
25596 	q[i__ + q_dim1] = vt[i__ * vt_dim1 + 1] / temp;
25597 	i__2 = *k;
25598 	for (j = 2; j <= i__2; ++j) {
25599 	    jc = idxc[j];
25600 	    q[i__ + j * q_dim1] = vt[jc + i__ * vt_dim1] / temp;
25601 /* L110: */
25602 	}
25603 /* L120: */
25604     }
25605 
25606 /*     Update the right singular vector matrix. */
25607 
25608     if (*k == 2) {
25609 	dgemm_("N", "N", k, &m, k, &c_b15, &q[q_offset], ldq, &vt2[vt2_offset]
25610 		, ldvt2, &c_b29, &vt[vt_offset], ldvt);
25611 	return 0;
25612     }
25613     ktemp = ctot[1] + 1;
25614     dgemm_("N", "N", k, &nlp1, &ktemp, &c_b15, &q[q_dim1 + 1], ldq, &vt2[
25615 	    vt2_dim1 + 1], ldvt2, &c_b29, &vt[vt_dim1 + 1], ldvt);
25616     ktemp = ctot[1] + 2 + ctot[2];
25617     if (ktemp <= *ldvt2) {
25618 	dgemm_("N", "N", k, &nlp1, &ctot[3], &c_b15, &q[ktemp * q_dim1 + 1],
25619 		ldq, &vt2[ktemp + vt2_dim1], ldvt2, &c_b15, &vt[vt_dim1 + 1],
25620 		ldvt);
25621     }
25622 
25623     ktemp = ctot[1] + 1;
25624     nrp1 = *nr + *sqre;
25625     if (ktemp > 1) {
25626 	i__1 = *k;
25627 	for (i__ = 1; i__ <= i__1; ++i__) {
25628 	    q[i__ + ktemp * q_dim1] = q[i__ + q_dim1];
25629 /* L130: */
25630 	}
25631 	i__1 = m;
25632 	for (i__ = nlp2; i__ <= i__1; ++i__) {
25633 	    vt2[ktemp + i__ * vt2_dim1] = vt2[i__ * vt2_dim1 + 1];
25634 /* L140: */
25635 	}
25636     }
25637     ctemp = ctot[2] + 1 + ctot[3];
25638     dgemm_("N", "N", k, &nrp1, &ctemp, &c_b15, &q[ktemp * q_dim1 + 1], ldq, &
25639 	    vt2[ktemp + nlp2 * vt2_dim1], ldvt2, &c_b29, &vt[nlp2 * vt_dim1 +
25640 	    1], ldvt);
25641 
25642     return 0;
25643 
25644 /*     End of DLASD3 */
25645 
25646 } /* dlasd3_ */
25647 
dlasd4_(integer * n,integer * i__,doublereal * d__,doublereal * z__,doublereal * delta,doublereal * rho,doublereal * sigma,doublereal * work,integer * info)25648 /* Subroutine */ int dlasd4_(integer *n, integer *i__, doublereal *d__,
25649 	doublereal *z__, doublereal *delta, doublereal *rho, doublereal *
25650 	sigma, doublereal *work, integer *info)
25651 {
25652     /* System generated locals */
25653     integer i__1;
25654     doublereal d__1;
25655 
25656     /* Local variables */
25657     static doublereal a, b, c__;
25658     static integer j;
25659     static doublereal w, dd[3];
25660     static integer ii;
25661     static doublereal dw, zz[3];
25662     static integer ip1;
25663     static doublereal eta, phi, eps, tau, psi;
25664     static integer iim1, iip1;
25665     static doublereal dphi, dpsi;
25666     static integer iter;
25667     static doublereal temp, prew, sg2lb, sg2ub, temp1, temp2, dtiim, delsq,
25668 	    dtiip;
25669     static integer niter;
25670     static doublereal dtisq;
25671     static logical swtch;
25672     static doublereal dtnsq;
25673     extern /* Subroutine */ int dlaed6_(integer *, logical *, doublereal *,
25674 	    doublereal *, doublereal *, doublereal *, doublereal *, integer *)
25675 	    , dlasd5_(integer *, doublereal *, doublereal *, doublereal *,
25676 	    doublereal *, doublereal *, doublereal *);
25677     static doublereal delsq2, dtnsq1;
25678     static logical swtch3;
25679 
25680     static logical orgati;
25681     static doublereal erretm, dtipsq, rhoinv;
25682 
25683 
25684 /*
25685     -- LAPACK auxiliary routine (version 3.2) --
25686     -- LAPACK is a software package provided by Univ. of Tennessee,    --
25687     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
25688        November 2006
25689 
25690 
25691     Purpose
25692     =======
25693 
25694     This subroutine computes the square root of the I-th updated
25695     eigenvalue of a positive symmetric rank-one modification to
25696     a positive diagonal matrix whose entries are given as the squares
25697     of the corresponding entries in the array d, and that
25698 
25699            0 <= D(i) < D(j)  for  i < j
25700 
25701     and that RHO > 0. This is arranged by the calling routine, and is
25702     no loss in generality.  The rank-one modified system is thus
25703 
25704            diag( D ) * diag( D ) +  RHO *  Z * Z_transpose.
25705 
25706     where we assume the Euclidean norm of Z is 1.
25707 
25708     The method consists of approximating the rational functions in the
25709     secular equation by simpler interpolating rational functions.
25710 
25711     Arguments
25712     =========
25713 
25714     N      (input) INTEGER
25715            The length of all arrays.
25716 
25717     I      (input) INTEGER
25718            The index of the eigenvalue to be computed.  1 <= I <= N.
25719 
25720     D      (input) DOUBLE PRECISION array, dimension ( N )
25721            The original eigenvalues.  It is assumed that they are in
25722            order, 0 <= D(I) < D(J)  for I < J.
25723 
25724     Z      (input) DOUBLE PRECISION array, dimension ( N )
25725            The components of the updating vector.
25726 
25727     DELTA  (output) DOUBLE PRECISION array, dimension ( N )
25728            If N .ne. 1, DELTA contains (D(j) - sigma_I) in its  j-th
25729            component.  If N = 1, then DELTA(1) = 1.  The vector DELTA
25730            contains the information necessary to construct the
25731            (singular) eigenvectors.
25732 
25733     RHO    (input) DOUBLE PRECISION
25734            The scalar in the symmetric updating formula.
25735 
25736     SIGMA  (output) DOUBLE PRECISION
25737            The computed sigma_I, the I-th updated eigenvalue.
25738 
25739     WORK   (workspace) DOUBLE PRECISION array, dimension ( N )
25740            If N .ne. 1, WORK contains (D(j) + sigma_I) in its  j-th
25741            component.  If N = 1, then WORK( 1 ) = 1.
25742 
25743     INFO   (output) INTEGER
25744            = 0:  successful exit
25745            > 0:  if INFO = 1, the updating process failed.
25746 
25747     Internal Parameters
25748     ===================
25749 
25750     Logical variable ORGATI (origin-at-i?) is used for distinguishing
25751     whether D(i) or D(i+1) is treated as the origin.
25752 
25753               ORGATI = .true.    origin at i
25754               ORGATI = .false.   origin at i+1
25755 
25756     Logical variable SWTCH3 (switch-for-3-poles?) is for noting
25757     if we are working with THREE poles!
25758 
25759     MAXIT is the maximum number of iterations allowed for each
25760     eigenvalue.
25761 
25762     Further Details
25763     ===============
25764 
25765     Based on contributions by
25766        Ren-Cang Li, Computer Science Division, University of California
25767        at Berkeley, USA
25768 
25769     =====================================================================
25770 
25771 
25772        Since this routine is called in an inner loop, we do no argument
25773        checking.
25774 
25775        Quick return for N=1 and 2.
25776 */
25777 
25778     /* Parameter adjustments */
25779     --work;
25780     --delta;
25781     --z__;
25782     --d__;
25783 
25784     /* Function Body */
25785     *info = 0;
25786     if (*n == 1) {
25787 
25788 /*        Presumably, I=1 upon entry */
25789 
25790 	*sigma = sqrt(d__[1] * d__[1] + *rho * z__[1] * z__[1]);
25791 	delta[1] = 1.;
25792 	work[1] = 1.;
25793 	return 0;
25794     }
25795     if (*n == 2) {
25796 	dlasd5_(i__, &d__[1], &z__[1], &delta[1], rho, sigma, &work[1]);
25797 	return 0;
25798     }
25799 
25800 /*     Compute machine epsilon */
25801 
25802     eps = EPSILON;
25803     rhoinv = 1. / *rho;
25804 
25805 /*     The case I = N */
25806 
25807     if (*i__ == *n) {
25808 
25809 /*        Initialize some basic variables */
25810 
25811 	ii = *n - 1;
25812 	niter = 1;
25813 
25814 /*        Calculate initial guess */
25815 
25816 	temp = *rho / 2.;
25817 
25818 /*
25819           If ||Z||_2 is not one, then TEMP should be set to
25820           RHO * ||Z||_2^2 / TWO
25821 */
25822 
25823 	temp1 = temp / (d__[*n] + sqrt(d__[*n] * d__[*n] + temp));
25824 	i__1 = *n;
25825 	for (j = 1; j <= i__1; ++j) {
25826 	    work[j] = d__[j] + d__[*n] + temp1;
25827 	    delta[j] = d__[j] - d__[*n] - temp1;
25828 /* L10: */
25829 	}
25830 
25831 	psi = 0.;
25832 	i__1 = *n - 2;
25833 	for (j = 1; j <= i__1; ++j) {
25834 	    psi += z__[j] * z__[j] / (delta[j] * work[j]);
25835 /* L20: */
25836 	}
25837 
25838 	c__ = rhoinv + psi;
25839 	w = c__ + z__[ii] * z__[ii] / (delta[ii] * work[ii]) + z__[*n] * z__[*
25840 		n] / (delta[*n] * work[*n]);
25841 
25842 	if (w <= 0.) {
25843 	    temp1 = sqrt(d__[*n] * d__[*n] + *rho);
25844 	    temp = z__[*n - 1] * z__[*n - 1] / ((d__[*n - 1] + temp1) * (d__[*
25845 		    n] - d__[*n - 1] + *rho / (d__[*n] + temp1))) + z__[*n] *
25846 		    z__[*n] / *rho;
25847 
25848 /*
25849              The following TAU is to approximate
25850              SIGMA_n^2 - D( N )*D( N )
25851 */
25852 
25853 	    if (c__ <= temp) {
25854 		tau = *rho;
25855 	    } else {
25856 		delsq = (d__[*n] - d__[*n - 1]) * (d__[*n] + d__[*n - 1]);
25857 		a = -c__ * delsq + z__[*n - 1] * z__[*n - 1] + z__[*n] * z__[*
25858 			n];
25859 		b = z__[*n] * z__[*n] * delsq;
25860 		if (a < 0.) {
25861 		    tau = b * 2. / (sqrt(a * a + b * 4. * c__) - a);
25862 		} else {
25863 		    tau = (a + sqrt(a * a + b * 4. * c__)) / (c__ * 2.);
25864 		}
25865 	    }
25866 
25867 /*
25868              It can be proved that
25869                  D(N)^2+RHO/2 <= SIGMA_n^2 < D(N)^2+TAU <= D(N)^2+RHO
25870 */
25871 
25872 	} else {
25873 	    delsq = (d__[*n] - d__[*n - 1]) * (d__[*n] + d__[*n - 1]);
25874 	    a = -c__ * delsq + z__[*n - 1] * z__[*n - 1] + z__[*n] * z__[*n];
25875 	    b = z__[*n] * z__[*n] * delsq;
25876 
25877 /*
25878              The following TAU is to approximate
25879              SIGMA_n^2 - D( N )*D( N )
25880 */
25881 
25882 	    if (a < 0.) {
25883 		tau = b * 2. / (sqrt(a * a + b * 4. * c__) - a);
25884 	    } else {
25885 		tau = (a + sqrt(a * a + b * 4. * c__)) / (c__ * 2.);
25886 	    }
25887 
25888 /*
25889              It can be proved that
25890              D(N)^2 < D(N)^2+TAU < SIGMA(N)^2 < D(N)^2+RHO/2
25891 */
25892 
25893 	}
25894 
25895 /*        The following ETA is to approximate SIGMA_n - D( N ) */
25896 
25897 	eta = tau / (d__[*n] + sqrt(d__[*n] * d__[*n] + tau));
25898 
25899 	*sigma = d__[*n] + eta;
25900 	i__1 = *n;
25901 	for (j = 1; j <= i__1; ++j) {
25902 	    delta[j] = d__[j] - d__[*i__] - eta;
25903 	    work[j] = d__[j] + d__[*i__] + eta;
25904 /* L30: */
25905 	}
25906 
25907 /*        Evaluate PSI and the derivative DPSI */
25908 
25909 	dpsi = 0.;
25910 	psi = 0.;
25911 	erretm = 0.;
25912 	i__1 = ii;
25913 	for (j = 1; j <= i__1; ++j) {
25914 	    temp = z__[j] / (delta[j] * work[j]);
25915 	    psi += z__[j] * temp;
25916 	    dpsi += temp * temp;
25917 	    erretm += psi;
25918 /* L40: */
25919 	}
25920 	erretm = abs(erretm);
25921 
25922 /*        Evaluate PHI and the derivative DPHI */
25923 
25924 	temp = z__[*n] / (delta[*n] * work[*n]);
25925 	phi = z__[*n] * temp;
25926 	dphi = temp * temp;
25927 	erretm = (-phi - psi) * 8. + erretm - phi + rhoinv + abs(tau) * (dpsi
25928 		+ dphi);
25929 
25930 	w = rhoinv + phi + psi;
25931 
25932 /*        Test for convergence */
25933 
25934 	if (abs(w) <= eps * erretm) {
25935 	    goto L240;
25936 	}
25937 
25938 /*        Calculate the new step */
25939 
25940 	++niter;
25941 	dtnsq1 = work[*n - 1] * delta[*n - 1];
25942 	dtnsq = work[*n] * delta[*n];
25943 	c__ = w - dtnsq1 * dpsi - dtnsq * dphi;
25944 	a = (dtnsq + dtnsq1) * w - dtnsq * dtnsq1 * (dpsi + dphi);
25945 	b = dtnsq * dtnsq1 * w;
25946 	if (c__ < 0.) {
25947 	    c__ = abs(c__);
25948 	}
25949 	if (c__ == 0.) {
25950 	    eta = *rho - *sigma * *sigma;
25951 	} else if (a >= 0.) {
25952 	    eta = (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (c__
25953 		    * 2.);
25954 	} else {
25955 	    eta = b * 2. / (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))
25956 		    );
25957 	}
25958 
25959 /*
25960           Note, eta should be positive if w is negative, and
25961           eta should be negative otherwise. However,
25962           if for some reason caused by roundoff, eta*w > 0,
25963           we simply use one Newton step instead. This way
25964           will guarantee eta*w < 0.
25965 */
25966 
25967 	if (w * eta > 0.) {
25968 	    eta = -w / (dpsi + dphi);
25969 	}
25970 	temp = eta - dtnsq;
25971 	if (temp > *rho) {
25972 	    eta = *rho + dtnsq;
25973 	}
25974 
25975 	tau += eta;
25976 	eta /= *sigma + sqrt(eta + *sigma * *sigma);
25977 	i__1 = *n;
25978 	for (j = 1; j <= i__1; ++j) {
25979 	    delta[j] -= eta;
25980 	    work[j] += eta;
25981 /* L50: */
25982 	}
25983 
25984 	*sigma += eta;
25985 
25986 /*        Evaluate PSI and the derivative DPSI */
25987 
25988 	dpsi = 0.;
25989 	psi = 0.;
25990 	erretm = 0.;
25991 	i__1 = ii;
25992 	for (j = 1; j <= i__1; ++j) {
25993 	    temp = z__[j] / (work[j] * delta[j]);
25994 	    psi += z__[j] * temp;
25995 	    dpsi += temp * temp;
25996 	    erretm += psi;
25997 /* L60: */
25998 	}
25999 	erretm = abs(erretm);
26000 
26001 /*        Evaluate PHI and the derivative DPHI */
26002 
26003 	temp = z__[*n] / (work[*n] * delta[*n]);
26004 	phi = z__[*n] * temp;
26005 	dphi = temp * temp;
26006 	erretm = (-phi - psi) * 8. + erretm - phi + rhoinv + abs(tau) * (dpsi
26007 		+ dphi);
26008 
26009 	w = rhoinv + phi + psi;
26010 
26011 /*        Main loop to update the values of the array   DELTA */
26012 
26013 	iter = niter + 1;
26014 
26015 	for (niter = iter; niter <= 20; ++niter) {
26016 
26017 /*           Test for convergence */
26018 
26019 	    if (abs(w) <= eps * erretm) {
26020 		goto L240;
26021 	    }
26022 
26023 /*           Calculate the new step */
26024 
26025 	    dtnsq1 = work[*n - 1] * delta[*n - 1];
26026 	    dtnsq = work[*n] * delta[*n];
26027 	    c__ = w - dtnsq1 * dpsi - dtnsq * dphi;
26028 	    a = (dtnsq + dtnsq1) * w - dtnsq1 * dtnsq * (dpsi + dphi);
26029 	    b = dtnsq1 * dtnsq * w;
26030 	    if (a >= 0.) {
26031 		eta = (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
26032 			c__ * 2.);
26033 	    } else {
26034 		eta = b * 2. / (a - sqrt((d__1 = a * a - b * 4. * c__, abs(
26035 			d__1))));
26036 	    }
26037 
26038 /*
26039              Note, eta should be positive if w is negative, and
26040              eta should be negative otherwise. However,
26041              if for some reason caused by roundoff, eta*w > 0,
26042              we simply use one Newton step instead. This way
26043              will guarantee eta*w < 0.
26044 */
26045 
26046 	    if (w * eta > 0.) {
26047 		eta = -w / (dpsi + dphi);
26048 	    }
26049 	    temp = eta - dtnsq;
26050 	    if (temp <= 0.) {
26051 		eta /= 2.;
26052 	    }
26053 
26054 	    tau += eta;
26055 	    eta /= *sigma + sqrt(eta + *sigma * *sigma);
26056 	    i__1 = *n;
26057 	    for (j = 1; j <= i__1; ++j) {
26058 		delta[j] -= eta;
26059 		work[j] += eta;
26060 /* L70: */
26061 	    }
26062 
26063 	    *sigma += eta;
26064 
26065 /*           Evaluate PSI and the derivative DPSI */
26066 
26067 	    dpsi = 0.;
26068 	    psi = 0.;
26069 	    erretm = 0.;
26070 	    i__1 = ii;
26071 	    for (j = 1; j <= i__1; ++j) {
26072 		temp = z__[j] / (work[j] * delta[j]);
26073 		psi += z__[j] * temp;
26074 		dpsi += temp * temp;
26075 		erretm += psi;
26076 /* L80: */
26077 	    }
26078 	    erretm = abs(erretm);
26079 
26080 /*           Evaluate PHI and the derivative DPHI */
26081 
26082 	    temp = z__[*n] / (work[*n] * delta[*n]);
26083 	    phi = z__[*n] * temp;
26084 	    dphi = temp * temp;
26085 	    erretm = (-phi - psi) * 8. + erretm - phi + rhoinv + abs(tau) * (
26086 		    dpsi + dphi);
26087 
26088 	    w = rhoinv + phi + psi;
26089 /* L90: */
26090 	}
26091 
26092 /*        Return with INFO = 1, NITER = MAXIT and not converged */
26093 
26094 	*info = 1;
26095 	goto L240;
26096 
26097 /*        End for the case I = N */
26098 
26099     } else {
26100 
26101 /*        The case for I < N */
26102 
26103 	niter = 1;
26104 	ip1 = *i__ + 1;
26105 
26106 /*        Calculate initial guess */
26107 
26108 	delsq = (d__[ip1] - d__[*i__]) * (d__[ip1] + d__[*i__]);
26109 	delsq2 = delsq / 2.;
26110 	temp = delsq2 / (d__[*i__] + sqrt(d__[*i__] * d__[*i__] + delsq2));
26111 	i__1 = *n;
26112 	for (j = 1; j <= i__1; ++j) {
26113 	    work[j] = d__[j] + d__[*i__] + temp;
26114 	    delta[j] = d__[j] - d__[*i__] - temp;
26115 /* L100: */
26116 	}
26117 
26118 	psi = 0.;
26119 	i__1 = *i__ - 1;
26120 	for (j = 1; j <= i__1; ++j) {
26121 	    psi += z__[j] * z__[j] / (work[j] * delta[j]);
26122 /* L110: */
26123 	}
26124 
26125 	phi = 0.;
26126 	i__1 = *i__ + 2;
26127 	for (j = *n; j >= i__1; --j) {
26128 	    phi += z__[j] * z__[j] / (work[j] * delta[j]);
26129 /* L120: */
26130 	}
26131 	c__ = rhoinv + psi + phi;
26132 	w = c__ + z__[*i__] * z__[*i__] / (work[*i__] * delta[*i__]) + z__[
26133 		ip1] * z__[ip1] / (work[ip1] * delta[ip1]);
26134 
26135 	if (w > 0.) {
26136 
26137 /*
26138              d(i)^2 < the ith sigma^2 < (d(i)^2+d(i+1)^2)/2
26139 
26140              We choose d(i) as origin.
26141 */
26142 
26143 	    orgati = TRUE_;
26144 	    sg2lb = 0.;
26145 	    sg2ub = delsq2;
26146 	    a = c__ * delsq + z__[*i__] * z__[*i__] + z__[ip1] * z__[ip1];
26147 	    b = z__[*i__] * z__[*i__] * delsq;
26148 	    if (a > 0.) {
26149 		tau = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(
26150 			d__1))));
26151 	    } else {
26152 		tau = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
26153 			c__ * 2.);
26154 	    }
26155 
26156 /*
26157              TAU now is an estimation of SIGMA^2 - D( I )^2. The
26158              following, however, is the corresponding estimation of
26159              SIGMA - D( I ).
26160 */
26161 
26162 	    eta = tau / (d__[*i__] + sqrt(d__[*i__] * d__[*i__] + tau));
26163 	} else {
26164 
26165 /*
26166              (d(i)^2+d(i+1)^2)/2 <= the ith sigma^2 < d(i+1)^2/2
26167 
26168              We choose d(i+1) as origin.
26169 */
26170 
26171 	    orgati = FALSE_;
26172 	    sg2lb = -delsq2;
26173 	    sg2ub = 0.;
26174 	    a = c__ * delsq - z__[*i__] * z__[*i__] - z__[ip1] * z__[ip1];
26175 	    b = z__[ip1] * z__[ip1] * delsq;
26176 	    if (a < 0.) {
26177 		tau = b * 2. / (a - sqrt((d__1 = a * a + b * 4. * c__, abs(
26178 			d__1))));
26179 	    } else {
26180 		tau = -(a + sqrt((d__1 = a * a + b * 4. * c__, abs(d__1)))) /
26181 			(c__ * 2.);
26182 	    }
26183 
26184 /*
26185              TAU now is an estimation of SIGMA^2 - D( IP1 )^2. The
26186              following, however, is the corresponding estimation of
26187              SIGMA - D( IP1 ).
26188 */
26189 
26190 	    eta = tau / (d__[ip1] + sqrt((d__1 = d__[ip1] * d__[ip1] + tau,
26191 		    abs(d__1))));
26192 	}
26193 
26194 	if (orgati) {
26195 	    ii = *i__;
26196 	    *sigma = d__[*i__] + eta;
26197 	    i__1 = *n;
26198 	    for (j = 1; j <= i__1; ++j) {
26199 		work[j] = d__[j] + d__[*i__] + eta;
26200 		delta[j] = d__[j] - d__[*i__] - eta;
26201 /* L130: */
26202 	    }
26203 	} else {
26204 	    ii = *i__ + 1;
26205 	    *sigma = d__[ip1] + eta;
26206 	    i__1 = *n;
26207 	    for (j = 1; j <= i__1; ++j) {
26208 		work[j] = d__[j] + d__[ip1] + eta;
26209 		delta[j] = d__[j] - d__[ip1] - eta;
26210 /* L140: */
26211 	    }
26212 	}
26213 	iim1 = ii - 1;
26214 	iip1 = ii + 1;
26215 
26216 /*        Evaluate PSI and the derivative DPSI */
26217 
26218 	dpsi = 0.;
26219 	psi = 0.;
26220 	erretm = 0.;
26221 	i__1 = iim1;
26222 	for (j = 1; j <= i__1; ++j) {
26223 	    temp = z__[j] / (work[j] * delta[j]);
26224 	    psi += z__[j] * temp;
26225 	    dpsi += temp * temp;
26226 	    erretm += psi;
26227 /* L150: */
26228 	}
26229 	erretm = abs(erretm);
26230 
26231 /*        Evaluate PHI and the derivative DPHI */
26232 
26233 	dphi = 0.;
26234 	phi = 0.;
26235 	i__1 = iip1;
26236 	for (j = *n; j >= i__1; --j) {
26237 	    temp = z__[j] / (work[j] * delta[j]);
26238 	    phi += z__[j] * temp;
26239 	    dphi += temp * temp;
26240 	    erretm += phi;
26241 /* L160: */
26242 	}
26243 
26244 	w = rhoinv + phi + psi;
26245 
26246 /*
26247           W is the value of the secular function with
26248           its ii-th element removed.
26249 */
26250 
26251 	swtch3 = FALSE_;
26252 	if (orgati) {
26253 	    if (w < 0.) {
26254 		swtch3 = TRUE_;
26255 	    }
26256 	} else {
26257 	    if (w > 0.) {
26258 		swtch3 = TRUE_;
26259 	    }
26260 	}
26261 	if (ii == 1 || ii == *n) {
26262 	    swtch3 = FALSE_;
26263 	}
26264 
26265 	temp = z__[ii] / (work[ii] * delta[ii]);
26266 	dw = dpsi + dphi + temp * temp;
26267 	temp = z__[ii] * temp;
26268 	w += temp;
26269 	erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3. +
26270 		abs(tau) * dw;
26271 
26272 /*        Test for convergence */
26273 
26274 	if (abs(w) <= eps * erretm) {
26275 	    goto L240;
26276 	}
26277 
26278 	if (w <= 0.) {
26279 	    sg2lb = max(sg2lb,tau);
26280 	} else {
26281 	    sg2ub = min(sg2ub,tau);
26282 	}
26283 
26284 /*        Calculate the new step */
26285 
26286 	++niter;
26287 	if (! swtch3) {
26288 	    dtipsq = work[ip1] * delta[ip1];
26289 	    dtisq = work[*i__] * delta[*i__];
26290 	    if (orgati) {
26291 /* Computing 2nd power */
26292 		d__1 = z__[*i__] / dtisq;
26293 		c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
26294 	    } else {
26295 /* Computing 2nd power */
26296 		d__1 = z__[ip1] / dtipsq;
26297 		c__ = w - dtisq * dw - delsq * (d__1 * d__1);
26298 	    }
26299 	    a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
26300 	    b = dtipsq * dtisq * w;
26301 	    if (c__ == 0.) {
26302 		if (a == 0.) {
26303 		    if (orgati) {
26304 			a = z__[*i__] * z__[*i__] + dtipsq * dtipsq * (dpsi +
26305 				dphi);
26306 		    } else {
26307 			a = z__[ip1] * z__[ip1] + dtisq * dtisq * (dpsi +
26308 				dphi);
26309 		    }
26310 		}
26311 		eta = b / a;
26312 	    } else if (a <= 0.) {
26313 		eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
26314 			c__ * 2.);
26315 	    } else {
26316 		eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(
26317 			d__1))));
26318 	    }
26319 	} else {
26320 
26321 /*           Interpolation using THREE most relevant poles */
26322 
26323 	    dtiim = work[iim1] * delta[iim1];
26324 	    dtiip = work[iip1] * delta[iip1];
26325 	    temp = rhoinv + psi + phi;
26326 	    if (orgati) {
26327 		temp1 = z__[iim1] / dtiim;
26328 		temp1 *= temp1;
26329 		c__ = temp - dtiip * (dpsi + dphi) - (d__[iim1] - d__[iip1]) *
26330 			 (d__[iim1] + d__[iip1]) * temp1;
26331 		zz[0] = z__[iim1] * z__[iim1];
26332 		if (dpsi < temp1) {
26333 		    zz[2] = dtiip * dtiip * dphi;
26334 		} else {
26335 		    zz[2] = dtiip * dtiip * (dpsi - temp1 + dphi);
26336 		}
26337 	    } else {
26338 		temp1 = z__[iip1] / dtiip;
26339 		temp1 *= temp1;
26340 		c__ = temp - dtiim * (dpsi + dphi) - (d__[iip1] - d__[iim1]) *
26341 			 (d__[iim1] + d__[iip1]) * temp1;
26342 		if (dphi < temp1) {
26343 		    zz[0] = dtiim * dtiim * dpsi;
26344 		} else {
26345 		    zz[0] = dtiim * dtiim * (dpsi + (dphi - temp1));
26346 		}
26347 		zz[2] = z__[iip1] * z__[iip1];
26348 	    }
26349 	    zz[1] = z__[ii] * z__[ii];
26350 	    dd[0] = dtiim;
26351 	    dd[1] = delta[ii] * work[ii];
26352 	    dd[2] = dtiip;
26353 	    dlaed6_(&niter, &orgati, &c__, dd, zz, &w, &eta, info);
26354 	    if (*info != 0) {
26355 		goto L240;
26356 	    }
26357 	}
26358 
26359 /*
26360           Note, eta should be positive if w is negative, and
26361           eta should be negative otherwise. However,
26362           if for some reason caused by roundoff, eta*w > 0,
26363           we simply use one Newton step instead. This way
26364           will guarantee eta*w < 0.
26365 */
26366 
26367 	if (w * eta >= 0.) {
26368 	    eta = -w / dw;
26369 	}
26370 	if (orgati) {
26371 	    temp1 = work[*i__] * delta[*i__];
26372 	    temp = eta - temp1;
26373 	} else {
26374 	    temp1 = work[ip1] * delta[ip1];
26375 	    temp = eta - temp1;
26376 	}
26377 	if (temp > sg2ub || temp < sg2lb) {
26378 	    if (w < 0.) {
26379 		eta = (sg2ub - tau) / 2.;
26380 	    } else {
26381 		eta = (sg2lb - tau) / 2.;
26382 	    }
26383 	}
26384 
26385 	tau += eta;
26386 	eta /= *sigma + sqrt(*sigma * *sigma + eta);
26387 
26388 	prew = w;
26389 
26390 	*sigma += eta;
26391 	i__1 = *n;
26392 	for (j = 1; j <= i__1; ++j) {
26393 	    work[j] += eta;
26394 	    delta[j] -= eta;
26395 /* L170: */
26396 	}
26397 
26398 /*        Evaluate PSI and the derivative DPSI */
26399 
26400 	dpsi = 0.;
26401 	psi = 0.;
26402 	erretm = 0.;
26403 	i__1 = iim1;
26404 	for (j = 1; j <= i__1; ++j) {
26405 	    temp = z__[j] / (work[j] * delta[j]);
26406 	    psi += z__[j] * temp;
26407 	    dpsi += temp * temp;
26408 	    erretm += psi;
26409 /* L180: */
26410 	}
26411 	erretm = abs(erretm);
26412 
26413 /*        Evaluate PHI and the derivative DPHI */
26414 
26415 	dphi = 0.;
26416 	phi = 0.;
26417 	i__1 = iip1;
26418 	for (j = *n; j >= i__1; --j) {
26419 	    temp = z__[j] / (work[j] * delta[j]);
26420 	    phi += z__[j] * temp;
26421 	    dphi += temp * temp;
26422 	    erretm += phi;
26423 /* L190: */
26424 	}
26425 
26426 	temp = z__[ii] / (work[ii] * delta[ii]);
26427 	dw = dpsi + dphi + temp * temp;
26428 	temp = z__[ii] * temp;
26429 	w = rhoinv + phi + psi + temp;
26430 	erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3. +
26431 		abs(tau) * dw;
26432 
26433 	if (w <= 0.) {
26434 	    sg2lb = max(sg2lb,tau);
26435 	} else {
26436 	    sg2ub = min(sg2ub,tau);
26437 	}
26438 
26439 	swtch = FALSE_;
26440 	if (orgati) {
26441 	    if (-w > abs(prew) / 10.) {
26442 		swtch = TRUE_;
26443 	    }
26444 	} else {
26445 	    if (w > abs(prew) / 10.) {
26446 		swtch = TRUE_;
26447 	    }
26448 	}
26449 
26450 /*        Main loop to update the values of the array   DELTA and WORK */
26451 
26452 	iter = niter + 1;
26453 
26454 	for (niter = iter; niter <= 20; ++niter) {
26455 
26456 /*           Test for convergence */
26457 
26458 	    if (abs(w) <= eps * erretm) {
26459 		goto L240;
26460 	    }
26461 
26462 /*           Calculate the new step */
26463 
26464 	    if (! swtch3) {
26465 		dtipsq = work[ip1] * delta[ip1];
26466 		dtisq = work[*i__] * delta[*i__];
26467 		if (! swtch) {
26468 		    if (orgati) {
26469 /* Computing 2nd power */
26470 			d__1 = z__[*i__] / dtisq;
26471 			c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
26472 		    } else {
26473 /* Computing 2nd power */
26474 			d__1 = z__[ip1] / dtipsq;
26475 			c__ = w - dtisq * dw - delsq * (d__1 * d__1);
26476 		    }
26477 		} else {
26478 		    temp = z__[ii] / (work[ii] * delta[ii]);
26479 		    if (orgati) {
26480 			dpsi += temp * temp;
26481 		    } else {
26482 			dphi += temp * temp;
26483 		    }
26484 		    c__ = w - dtisq * dpsi - dtipsq * dphi;
26485 		}
26486 		a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
26487 		b = dtipsq * dtisq * w;
26488 		if (c__ == 0.) {
26489 		    if (a == 0.) {
26490 			if (! swtch) {
26491 			    if (orgati) {
26492 				a = z__[*i__] * z__[*i__] + dtipsq * dtipsq *
26493 					(dpsi + dphi);
26494 			    } else {
26495 				a = z__[ip1] * z__[ip1] + dtisq * dtisq * (
26496 					dpsi + dphi);
26497 			    }
26498 			} else {
26499 			    a = dtisq * dtisq * dpsi + dtipsq * dtipsq * dphi;
26500 			}
26501 		    }
26502 		    eta = b / a;
26503 		} else if (a <= 0.) {
26504 		    eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1))))
26505 			     / (c__ * 2.);
26506 		} else {
26507 		    eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__,
26508 			    abs(d__1))));
26509 		}
26510 	    } else {
26511 
26512 /*              Interpolation using THREE most relevant poles */
26513 
26514 		dtiim = work[iim1] * delta[iim1];
26515 		dtiip = work[iip1] * delta[iip1];
26516 		temp = rhoinv + psi + phi;
26517 		if (swtch) {
26518 		    c__ = temp - dtiim * dpsi - dtiip * dphi;
26519 		    zz[0] = dtiim * dtiim * dpsi;
26520 		    zz[2] = dtiip * dtiip * dphi;
26521 		} else {
26522 		    if (orgati) {
26523 			temp1 = z__[iim1] / dtiim;
26524 			temp1 *= temp1;
26525 			temp2 = (d__[iim1] - d__[iip1]) * (d__[iim1] + d__[
26526 				iip1]) * temp1;
26527 			c__ = temp - dtiip * (dpsi + dphi) - temp2;
26528 			zz[0] = z__[iim1] * z__[iim1];
26529 			if (dpsi < temp1) {
26530 			    zz[2] = dtiip * dtiip * dphi;
26531 			} else {
26532 			    zz[2] = dtiip * dtiip * (dpsi - temp1 + dphi);
26533 			}
26534 		    } else {
26535 			temp1 = z__[iip1] / dtiip;
26536 			temp1 *= temp1;
26537 			temp2 = (d__[iip1] - d__[iim1]) * (d__[iim1] + d__[
26538 				iip1]) * temp1;
26539 			c__ = temp - dtiim * (dpsi + dphi) - temp2;
26540 			if (dphi < temp1) {
26541 			    zz[0] = dtiim * dtiim * dpsi;
26542 			} else {
26543 			    zz[0] = dtiim * dtiim * (dpsi + (dphi - temp1));
26544 			}
26545 			zz[2] = z__[iip1] * z__[iip1];
26546 		    }
26547 		}
26548 		dd[0] = dtiim;
26549 		dd[1] = delta[ii] * work[ii];
26550 		dd[2] = dtiip;
26551 		dlaed6_(&niter, &orgati, &c__, dd, zz, &w, &eta, info);
26552 		if (*info != 0) {
26553 		    goto L240;
26554 		}
26555 	    }
26556 
26557 /*
26558              Note, eta should be positive if w is negative, and
26559              eta should be negative otherwise. However,
26560              if for some reason caused by roundoff, eta*w > 0,
26561              we simply use one Newton step instead. This way
26562              will guarantee eta*w < 0.
26563 */
26564 
26565 	    if (w * eta >= 0.) {
26566 		eta = -w / dw;
26567 	    }
26568 	    if (orgati) {
26569 		temp1 = work[*i__] * delta[*i__];
26570 		temp = eta - temp1;
26571 	    } else {
26572 		temp1 = work[ip1] * delta[ip1];
26573 		temp = eta - temp1;
26574 	    }
26575 	    if (temp > sg2ub || temp < sg2lb) {
26576 		if (w < 0.) {
26577 		    eta = (sg2ub - tau) / 2.;
26578 		} else {
26579 		    eta = (sg2lb - tau) / 2.;
26580 		}
26581 	    }
26582 
26583 	    tau += eta;
26584 	    eta /= *sigma + sqrt(*sigma * *sigma + eta);
26585 
26586 	    *sigma += eta;
26587 	    i__1 = *n;
26588 	    for (j = 1; j <= i__1; ++j) {
26589 		work[j] += eta;
26590 		delta[j] -= eta;
26591 /* L200: */
26592 	    }
26593 
26594 	    prew = w;
26595 
26596 /*           Evaluate PSI and the derivative DPSI */
26597 
26598 	    dpsi = 0.;
26599 	    psi = 0.;
26600 	    erretm = 0.;
26601 	    i__1 = iim1;
26602 	    for (j = 1; j <= i__1; ++j) {
26603 		temp = z__[j] / (work[j] * delta[j]);
26604 		psi += z__[j] * temp;
26605 		dpsi += temp * temp;
26606 		erretm += psi;
26607 /* L210: */
26608 	    }
26609 	    erretm = abs(erretm);
26610 
26611 /*           Evaluate PHI and the derivative DPHI */
26612 
26613 	    dphi = 0.;
26614 	    phi = 0.;
26615 	    i__1 = iip1;
26616 	    for (j = *n; j >= i__1; --j) {
26617 		temp = z__[j] / (work[j] * delta[j]);
26618 		phi += z__[j] * temp;
26619 		dphi += temp * temp;
26620 		erretm += phi;
26621 /* L220: */
26622 	    }
26623 
26624 	    temp = z__[ii] / (work[ii] * delta[ii]);
26625 	    dw = dpsi + dphi + temp * temp;
26626 	    temp = z__[ii] * temp;
26627 	    w = rhoinv + phi + psi + temp;
26628 	    erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3.
26629 		    + abs(tau) * dw;
26630 	    if (w * prew > 0. && abs(w) > abs(prew) / 10.) {
26631 		swtch = ! swtch;
26632 	    }
26633 
26634 	    if (w <= 0.) {
26635 		sg2lb = max(sg2lb,tau);
26636 	    } else {
26637 		sg2ub = min(sg2ub,tau);
26638 	    }
26639 
26640 /* L230: */
26641 	}
26642 
26643 /*        Return with INFO = 1, NITER = MAXIT and not converged */
26644 
26645 	*info = 1;
26646 
26647     }
26648 
26649 L240:
26650     return 0;
26651 
26652 /*     End of DLASD4 */
26653 
26654 } /* dlasd4_ */
26655 
dlasd5_(integer * i__,doublereal * d__,doublereal * z__,doublereal * delta,doublereal * rho,doublereal * dsigma,doublereal * work)26656 /* Subroutine */ int dlasd5_(integer *i__, doublereal *d__, doublereal *z__,
26657 	doublereal *delta, doublereal *rho, doublereal *dsigma, doublereal *
26658 	work)
26659 {
26660     /* System generated locals */
26661     doublereal d__1;
26662 
26663     /* Local variables */
26664     static doublereal b, c__, w, del, tau, delsq;
26665 
26666 
26667 /*
26668     -- LAPACK auxiliary routine (version 3.2) --
26669     -- LAPACK is a software package provided by Univ. of Tennessee,    --
26670     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
26671        November 2006
26672 
26673 
26674     Purpose
26675     =======
26676 
26677     This subroutine computes the square root of the I-th eigenvalue
26678     of a positive symmetric rank-one modification of a 2-by-2 diagonal
26679     matrix
26680 
26681                diag( D ) * diag( D ) +  RHO *  Z * transpose(Z) .
26682 
26683     The diagonal entries in the array D are assumed to satisfy
26684 
26685                0 <= D(i) < D(j)  for  i < j .
26686 
26687     We also assume RHO > 0 and that the Euclidean norm of the vector
26688     Z is one.
26689 
26690     Arguments
26691     =========
26692 
26693     I      (input) INTEGER
26694            The index of the eigenvalue to be computed.  I = 1 or I = 2.
26695 
26696     D      (input) DOUBLE PRECISION array, dimension ( 2 )
26697            The original eigenvalues.  We assume 0 <= D(1) < D(2).
26698 
26699     Z      (input) DOUBLE PRECISION array, dimension ( 2 )
26700            The components of the updating vector.
26701 
26702     DELTA  (output) DOUBLE PRECISION array, dimension ( 2 )
26703            Contains (D(j) - sigma_I) in its  j-th component.
26704            The vector DELTA contains the information necessary
26705            to construct the eigenvectors.
26706 
26707     RHO    (input) DOUBLE PRECISION
26708            The scalar in the symmetric updating formula.
26709 
26710     DSIGMA (output) DOUBLE PRECISION
26711            The computed sigma_I, the I-th updated eigenvalue.
26712 
26713     WORK   (workspace) DOUBLE PRECISION array, dimension ( 2 )
26714            WORK contains (D(j) + sigma_I) in its  j-th component.
26715 
26716     Further Details
26717     ===============
26718 
26719     Based on contributions by
26720        Ren-Cang Li, Computer Science Division, University of California
26721        at Berkeley, USA
26722 
26723     =====================================================================
26724 */
26725 
26726 
26727     /* Parameter adjustments */
26728     --work;
26729     --delta;
26730     --z__;
26731     --d__;
26732 
26733     /* Function Body */
26734     del = d__[2] - d__[1];
26735     delsq = del * (d__[2] + d__[1]);
26736     if (*i__ == 1) {
26737 	w = *rho * 4. * (z__[2] * z__[2] / (d__[1] + d__[2] * 3.) - z__[1] *
26738 		z__[1] / (d__[1] * 3. + d__[2])) / del + 1.;
26739 	if (w > 0.) {
26740 	    b = delsq + *rho * (z__[1] * z__[1] + z__[2] * z__[2]);
26741 	    c__ = *rho * z__[1] * z__[1] * delsq;
26742 
26743 /*
26744              B > ZERO, always
26745 
26746              The following TAU is DSIGMA * DSIGMA - D( 1 ) * D( 1 )
26747 */
26748 
26749 	    tau = c__ * 2. / (b + sqrt((d__1 = b * b - c__ * 4., abs(d__1))));
26750 
26751 /*           The following TAU is DSIGMA - D( 1 ) */
26752 
26753 	    tau /= d__[1] + sqrt(d__[1] * d__[1] + tau);
26754 	    *dsigma = d__[1] + tau;
26755 	    delta[1] = -tau;
26756 	    delta[2] = del - tau;
26757 	    work[1] = d__[1] * 2. + tau;
26758 	    work[2] = d__[1] + tau + d__[2];
26759 /*
26760              DELTA( 1 ) = -Z( 1 ) / TAU
26761              DELTA( 2 ) = Z( 2 ) / ( DEL-TAU )
26762 */
26763 	} else {
26764 	    b = -delsq + *rho * (z__[1] * z__[1] + z__[2] * z__[2]);
26765 	    c__ = *rho * z__[2] * z__[2] * delsq;
26766 
26767 /*           The following TAU is DSIGMA * DSIGMA - D( 2 ) * D( 2 ) */
26768 
26769 	    if (b > 0.) {
26770 		tau = c__ * -2. / (b + sqrt(b * b + c__ * 4.));
26771 	    } else {
26772 		tau = (b - sqrt(b * b + c__ * 4.)) / 2.;
26773 	    }
26774 
26775 /*           The following TAU is DSIGMA - D( 2 ) */
26776 
26777 	    tau /= d__[2] + sqrt((d__1 = d__[2] * d__[2] + tau, abs(d__1)));
26778 	    *dsigma = d__[2] + tau;
26779 	    delta[1] = -(del + tau);
26780 	    delta[2] = -tau;
26781 	    work[1] = d__[1] + tau + d__[2];
26782 	    work[2] = d__[2] * 2. + tau;
26783 /*
26784              DELTA( 1 ) = -Z( 1 ) / ( DEL+TAU )
26785              DELTA( 2 ) = -Z( 2 ) / TAU
26786 */
26787 	}
26788 /*
26789           TEMP = SQRT( DELTA( 1 )*DELTA( 1 )+DELTA( 2 )*DELTA( 2 ) )
26790           DELTA( 1 ) = DELTA( 1 ) / TEMP
26791           DELTA( 2 ) = DELTA( 2 ) / TEMP
26792 */
26793     } else {
26794 
26795 /*        Now I=2 */
26796 
26797 	b = -delsq + *rho * (z__[1] * z__[1] + z__[2] * z__[2]);
26798 	c__ = *rho * z__[2] * z__[2] * delsq;
26799 
26800 /*        The following TAU is DSIGMA * DSIGMA - D( 2 ) * D( 2 ) */
26801 
26802 	if (b > 0.) {
26803 	    tau = (b + sqrt(b * b + c__ * 4.)) / 2.;
26804 	} else {
26805 	    tau = c__ * 2. / (-b + sqrt(b * b + c__ * 4.));
26806 	}
26807 
26808 /*        The following TAU is DSIGMA - D( 2 ) */
26809 
26810 	tau /= d__[2] + sqrt(d__[2] * d__[2] + tau);
26811 	*dsigma = d__[2] + tau;
26812 	delta[1] = -(del + tau);
26813 	delta[2] = -tau;
26814 	work[1] = d__[1] + tau + d__[2];
26815 	work[2] = d__[2] * 2. + tau;
26816 /*
26817           DELTA( 1 ) = -Z( 1 ) / ( DEL+TAU )
26818           DELTA( 2 ) = -Z( 2 ) / TAU
26819           TEMP = SQRT( DELTA( 1 )*DELTA( 1 )+DELTA( 2 )*DELTA( 2 ) )
26820           DELTA( 1 ) = DELTA( 1 ) / TEMP
26821           DELTA( 2 ) = DELTA( 2 ) / TEMP
26822 */
26823     }
26824     return 0;
26825 
26826 /*     End of DLASD5 */
26827 
26828 } /* dlasd5_ */
26829 
dlasd6_(integer * icompq,integer * nl,integer * nr,integer * sqre,doublereal * d__,doublereal * vf,doublereal * vl,doublereal * alpha,doublereal * beta,integer * idxq,integer * perm,integer * givptr,integer * givcol,integer * ldgcol,doublereal * givnum,integer * ldgnum,doublereal * poles,doublereal * difl,doublereal * difr,doublereal * z__,integer * k,doublereal * c__,doublereal * s,doublereal * work,integer * iwork,integer * info)26830 /* Subroutine */ int dlasd6_(integer *icompq, integer *nl, integer *nr,
26831 	integer *sqre, doublereal *d__, doublereal *vf, doublereal *vl,
26832 	doublereal *alpha, doublereal *beta, integer *idxq, integer *perm,
26833 	integer *givptr, integer *givcol, integer *ldgcol, doublereal *givnum,
26834 	 integer *ldgnum, doublereal *poles, doublereal *difl, doublereal *
26835 	difr, doublereal *z__, integer *k, doublereal *c__, doublereal *s,
26836 	doublereal *work, integer *iwork, integer *info)
26837 {
26838     /* System generated locals */
26839     integer givcol_dim1, givcol_offset, givnum_dim1, givnum_offset,
26840 	    poles_dim1, poles_offset, i__1;
26841     doublereal d__1, d__2;
26842 
26843     /* Local variables */
26844     static integer i__, m, n, n1, n2, iw, idx, idxc, idxp, ivfw, ivlw;
26845     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
26846 	    doublereal *, integer *), dlasd7_(integer *, integer *, integer *,
26847 	     integer *, integer *, doublereal *, doublereal *, doublereal *,
26848 	    doublereal *, doublereal *, doublereal *, doublereal *,
26849 	    doublereal *, doublereal *, doublereal *, integer *, integer *,
26850 	    integer *, integer *, integer *, integer *, integer *, doublereal
26851 	    *, integer *, doublereal *, doublereal *, integer *), dlasd8_(
26852 	    integer *, integer *, doublereal *, doublereal *, doublereal *,
26853 	    doublereal *, doublereal *, doublereal *, integer *, doublereal *,
26854 	     doublereal *, integer *), dlascl_(char *, integer *, integer *,
26855 	    doublereal *, doublereal *, integer *, integer *, doublereal *,
26856 	    integer *, integer *), dlamrg_(integer *, integer *,
26857 	    doublereal *, integer *, integer *, integer *);
26858     static integer isigma;
26859     extern /* Subroutine */ int xerbla_(char *, integer *);
26860     static doublereal orgnrm;
26861 
26862 
26863 /*
26864     -- LAPACK auxiliary routine (version 3.2.2) --
26865     -- LAPACK is a software package provided by Univ. of Tennessee,    --
26866     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
26867        June 2010
26868 
26869 
26870     Purpose
26871     =======
26872 
26873     DLASD6 computes the SVD of an updated upper bidiagonal matrix B
26874     obtained by merging two smaller ones by appending a row. This
26875     routine is used only for the problem which requires all singular
26876     values and optionally singular vector matrices in factored form.
26877     B is an N-by-M matrix with N = NL + NR + 1 and M = N + SQRE.
26878     A related subroutine, DLASD1, handles the case in which all singular
26879     values and singular vectors of the bidiagonal matrix are desired.
26880 
26881     DLASD6 computes the SVD as follows:
26882 
26883                   ( D1(in)  0    0     0 )
26884       B = U(in) * (   Z1'   a   Z2'    b ) * VT(in)
26885                   (   0     0   D2(in) 0 )
26886 
26887         = U(out) * ( D(out) 0) * VT(out)
26888 
26889     where Z' = (Z1' a Z2' b) = u' VT', and u is a vector of dimension M
26890     with ALPHA and BETA in the NL+1 and NL+2 th entries and zeros
26891     elsewhere; and the entry b is empty if SQRE = 0.
26892 
26893     The singular values of B can be computed using D1, D2, the first
26894     components of all the right singular vectors of the lower block, and
26895     the last components of all the right singular vectors of the upper
26896     block. These components are stored and updated in VF and VL,
26897     respectively, in DLASD6. Hence U and VT are not explicitly
26898     referenced.
26899 
26900     The singular values are stored in D. The algorithm consists of two
26901     stages:
26902 
26903           The first stage consists of deflating the size of the problem
26904           when there are multiple singular values or if there is a zero
26905           in the Z vector. For each such occurence the dimension of the
26906           secular equation problem is reduced by one. This stage is
26907           performed by the routine DLASD7.
26908 
26909           The second stage consists of calculating the updated
26910           singular values. This is done by finding the roots of the
26911           secular equation via the routine DLASD4 (as called by DLASD8).
26912           This routine also updates VF and VL and computes the distances
26913           between the updated singular values and the old singular
26914           values.
26915 
26916     DLASD6 is called from DLASDA.
26917 
26918     Arguments
26919     =========
26920 
26921     ICOMPQ (input) INTEGER
26922            Specifies whether singular vectors are to be computed in
26923            factored form:
26924            = 0: Compute singular values only.
26925            = 1: Compute singular vectors in factored form as well.
26926 
26927     NL     (input) INTEGER
26928            The row dimension of the upper block.  NL >= 1.
26929 
26930     NR     (input) INTEGER
26931            The row dimension of the lower block.  NR >= 1.
26932 
26933     SQRE   (input) INTEGER
26934            = 0: the lower block is an NR-by-NR square matrix.
26935            = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
26936 
26937            The bidiagonal matrix has row dimension N = NL + NR + 1,
26938            and column dimension M = N + SQRE.
26939 
26940     D      (input/output) DOUBLE PRECISION array, dimension ( NL+NR+1 ).
26941            On entry D(1:NL,1:NL) contains the singular values of the
26942            upper block, and D(NL+2:N) contains the singular values
26943            of the lower block. On exit D(1:N) contains the singular
26944            values of the modified matrix.
26945 
26946     VF     (input/output) DOUBLE PRECISION array, dimension ( M )
26947            On entry, VF(1:NL+1) contains the first components of all
26948            right singular vectors of the upper block; and VF(NL+2:M)
26949            contains the first components of all right singular vectors
26950            of the lower block. On exit, VF contains the first components
26951            of all right singular vectors of the bidiagonal matrix.
26952 
26953     VL     (input/output) DOUBLE PRECISION array, dimension ( M )
26954            On entry, VL(1:NL+1) contains the  last components of all
26955            right singular vectors of the upper block; and VL(NL+2:M)
26956            contains the last components of all right singular vectors of
26957            the lower block. On exit, VL contains the last components of
26958            all right singular vectors of the bidiagonal matrix.
26959 
26960     ALPHA  (input/output) DOUBLE PRECISION
26961            Contains the diagonal element associated with the added row.
26962 
26963     BETA   (input/output) DOUBLE PRECISION
26964            Contains the off-diagonal element associated with the added
26965            row.
26966 
26967     IDXQ   (output) INTEGER array, dimension ( N )
26968            This contains the permutation which will reintegrate the
26969            subproblem just solved back into sorted order, i.e.
26970            D( IDXQ( I = 1, N ) ) will be in ascending order.
26971 
26972     PERM   (output) INTEGER array, dimension ( N )
26973            The permutations (from deflation and sorting) to be applied
26974            to each block. Not referenced if ICOMPQ = 0.
26975 
26976     GIVPTR (output) INTEGER
26977            The number of Givens rotations which took place in this
26978            subproblem. Not referenced if ICOMPQ = 0.
26979 
26980     GIVCOL (output) INTEGER array, dimension ( LDGCOL, 2 )
26981            Each pair of numbers indicates a pair of columns to take place
26982            in a Givens rotation. Not referenced if ICOMPQ = 0.
26983 
26984     LDGCOL (input) INTEGER
26985            leading dimension of GIVCOL, must be at least N.
26986 
26987     GIVNUM (output) DOUBLE PRECISION array, dimension ( LDGNUM, 2 )
26988            Each number indicates the C or S value to be used in the
26989            corresponding Givens rotation. Not referenced if ICOMPQ = 0.
26990 
26991     LDGNUM (input) INTEGER
26992            The leading dimension of GIVNUM and POLES, must be at least N.
26993 
26994     POLES  (output) DOUBLE PRECISION array, dimension ( LDGNUM, 2 )
26995            On exit, POLES(1,*) is an array containing the new singular
26996            values obtained from solving the secular equation, and
26997            POLES(2,*) is an array containing the poles in the secular
26998            equation. Not referenced if ICOMPQ = 0.
26999 
27000     DIFL   (output) DOUBLE PRECISION array, dimension ( N )
27001            On exit, DIFL(I) is the distance between I-th updated
27002            (undeflated) singular value and the I-th (undeflated) old
27003            singular value.
27004 
27005     DIFR   (output) DOUBLE PRECISION array,
27006                     dimension ( LDGNUM, 2 ) if ICOMPQ = 1 and
27007                     dimension ( N ) if ICOMPQ = 0.
27008            On exit, DIFR(I, 1) is the distance between I-th updated
27009            (undeflated) singular value and the I+1-th (undeflated) old
27010            singular value.
27011 
27012            If ICOMPQ = 1, DIFR(1:K,2) is an array containing the
27013            normalizing factors for the right singular vector matrix.
27014 
27015            See DLASD8 for details on DIFL and DIFR.
27016 
27017     Z      (output) DOUBLE PRECISION array, dimension ( M )
27018            The first elements of this array contain the components
27019            of the deflation-adjusted updating row vector.
27020 
27021     K      (output) INTEGER
27022            Contains the dimension of the non-deflated matrix,
27023            This is the order of the related secular equation. 1 <= K <=N.
27024 
27025     C      (output) DOUBLE PRECISION
27026            C contains garbage if SQRE =0 and the C-value of a Givens
27027            rotation related to the right null space if SQRE = 1.
27028 
27029     S      (output) DOUBLE PRECISION
27030            S contains garbage if SQRE =0 and the S-value of a Givens
27031            rotation related to the right null space if SQRE = 1.
27032 
27033     WORK   (workspace) DOUBLE PRECISION array, dimension ( 4 * M )
27034 
27035     IWORK  (workspace) INTEGER array, dimension ( 3 * N )
27036 
27037     INFO   (output) INTEGER
27038             = 0:  successful exit.
27039             < 0:  if INFO = -i, the i-th argument had an illegal value.
27040             > 0:  if INFO = 1, a singular value did not converge
27041 
27042     Further Details
27043     ===============
27044 
27045     Based on contributions by
27046        Ming Gu and Huan Ren, Computer Science Division, University of
27047        California at Berkeley, USA
27048 
27049     =====================================================================
27050 
27051 
27052        Test the input parameters.
27053 */
27054 
27055     /* Parameter adjustments */
27056     --d__;
27057     --vf;
27058     --vl;
27059     --idxq;
27060     --perm;
27061     givcol_dim1 = *ldgcol;
27062     givcol_offset = 1 + givcol_dim1;
27063     givcol -= givcol_offset;
27064     poles_dim1 = *ldgnum;
27065     poles_offset = 1 + poles_dim1;
27066     poles -= poles_offset;
27067     givnum_dim1 = *ldgnum;
27068     givnum_offset = 1 + givnum_dim1;
27069     givnum -= givnum_offset;
27070     --difl;
27071     --difr;
27072     --z__;
27073     --work;
27074     --iwork;
27075 
27076     /* Function Body */
27077     *info = 0;
27078     n = *nl + *nr + 1;
27079     m = n + *sqre;
27080 
27081     if (*icompq < 0 || *icompq > 1) {
27082 	*info = -1;
27083     } else if (*nl < 1) {
27084 	*info = -2;
27085     } else if (*nr < 1) {
27086 	*info = -3;
27087     } else if (*sqre < 0 || *sqre > 1) {
27088 	*info = -4;
27089     } else if (*ldgcol < n) {
27090 	*info = -14;
27091     } else if (*ldgnum < n) {
27092 	*info = -16;
27093     }
27094     if (*info != 0) {
27095 	i__1 = -(*info);
27096 	xerbla_("DLASD6", &i__1);
27097 	return 0;
27098     }
27099 
27100 /*
27101        The following values are for bookkeeping purposes only.  They are
27102        integer pointers which indicate the portion of the workspace
27103        used by a particular array in DLASD7 and DLASD8.
27104 */
27105 
27106     isigma = 1;
27107     iw = isigma + n;
27108     ivfw = iw + m;
27109     ivlw = ivfw + m;
27110 
27111     idx = 1;
27112     idxc = idx + n;
27113     idxp = idxc + n;
27114 
27115 /*
27116        Scale.
27117 
27118    Computing MAX
27119 */
27120     d__1 = abs(*alpha), d__2 = abs(*beta);
27121     orgnrm = max(d__1,d__2);
27122     d__[*nl + 1] = 0.;
27123     i__1 = n;
27124     for (i__ = 1; i__ <= i__1; ++i__) {
27125 	if ((d__1 = d__[i__], abs(d__1)) > orgnrm) {
27126 	    orgnrm = (d__1 = d__[i__], abs(d__1));
27127 	}
27128 /* L10: */
27129     }
27130     dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, &n, &c__1, &d__[1], &n, info);
27131     *alpha /= orgnrm;
27132     *beta /= orgnrm;
27133 
27134 /*     Sort and Deflate singular values. */
27135 
27136     dlasd7_(icompq, nl, nr, sqre, k, &d__[1], &z__[1], &work[iw], &vf[1], &
27137 	    work[ivfw], &vl[1], &work[ivlw], alpha, beta, &work[isigma], &
27138 	    iwork[idx], &iwork[idxp], &idxq[1], &perm[1], givptr, &givcol[
27139 	    givcol_offset], ldgcol, &givnum[givnum_offset], ldgnum, c__, s,
27140 	    info);
27141 
27142 /*     Solve Secular Equation, compute DIFL, DIFR, and update VF, VL. */
27143 
27144     dlasd8_(icompq, k, &d__[1], &z__[1], &vf[1], &vl[1], &difl[1], &difr[1],
27145 	    ldgnum, &work[isigma], &work[iw], info);
27146 
27147 /*     Save the poles if ICOMPQ = 1. */
27148 
27149     if (*icompq == 1) {
27150 	dcopy_(k, &d__[1], &c__1, &poles[poles_dim1 + 1], &c__1);
27151 	dcopy_(k, &work[isigma], &c__1, &poles[(poles_dim1 << 1) + 1], &c__1);
27152     }
27153 
27154 /*     Unscale. */
27155 
27156     dlascl_("G", &c__0, &c__0, &c_b15, &orgnrm, &n, &c__1, &d__[1], &n, info);
27157 
27158 /*     Prepare the IDXQ sorting permutation. */
27159 
27160     n1 = *k;
27161     n2 = n - *k;
27162     dlamrg_(&n1, &n2, &d__[1], &c__1, &c_n1, &idxq[1]);
27163 
27164     return 0;
27165 
27166 /*     End of DLASD6 */
27167 
27168 } /* dlasd6_ */
27169 
dlasd7_(integer * icompq,integer * nl,integer * nr,integer * sqre,integer * k,doublereal * d__,doublereal * z__,doublereal * zw,doublereal * vf,doublereal * vfw,doublereal * vl,doublereal * vlw,doublereal * alpha,doublereal * beta,doublereal * dsigma,integer * idx,integer * idxp,integer * idxq,integer * perm,integer * givptr,integer * givcol,integer * ldgcol,doublereal * givnum,integer * ldgnum,doublereal * c__,doublereal * s,integer * info)27170 /* Subroutine */ int dlasd7_(integer *icompq, integer *nl, integer *nr,
27171 	integer *sqre, integer *k, doublereal *d__, doublereal *z__,
27172 	doublereal *zw, doublereal *vf, doublereal *vfw, doublereal *vl,
27173 	doublereal *vlw, doublereal *alpha, doublereal *beta, doublereal *
27174 	dsigma, integer *idx, integer *idxp, integer *idxq, integer *perm,
27175 	integer *givptr, integer *givcol, integer *ldgcol, doublereal *givnum,
27176 	 integer *ldgnum, doublereal *c__, doublereal *s, integer *info)
27177 {
27178     /* System generated locals */
27179     integer givcol_dim1, givcol_offset, givnum_dim1, givnum_offset, i__1;
27180     doublereal d__1, d__2;
27181 
27182     /* Local variables */
27183     static integer i__, j, m, n, k2;
27184     static doublereal z1;
27185     static integer jp;
27186     static doublereal eps, tau, tol;
27187     static integer nlp1, nlp2, idxi, idxj;
27188     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
27189 	    doublereal *, integer *, doublereal *, doublereal *);
27190     static integer idxjp;
27191     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
27192 	    doublereal *, integer *);
27193     static integer jprev;
27194 
27195     extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *,
27196 	    integer *, integer *, integer *), xerbla_(char *, integer *);
27197     static doublereal hlftol;
27198 
27199 
27200 /*
27201     -- LAPACK auxiliary routine (version 3.2) --
27202     -- LAPACK is a software package provided by Univ. of Tennessee,    --
27203     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
27204        November 2006
27205 
27206 
27207     Purpose
27208     =======
27209 
27210     DLASD7 merges the two sets of singular values together into a single
27211     sorted set. Then it tries to deflate the size of the problem. There
27212     are two ways in which deflation can occur:  when two or more singular
27213     values are close together or if there is a tiny entry in the Z
27214     vector. For each such occurrence the order of the related
27215     secular equation problem is reduced by one.
27216 
27217     DLASD7 is called from DLASD6.
27218 
27219     Arguments
27220     =========
27221 
27222     ICOMPQ  (input) INTEGER
27223             Specifies whether singular vectors are to be computed
27224             in compact form, as follows:
27225             = 0: Compute singular values only.
27226             = 1: Compute singular vectors of upper
27227                  bidiagonal matrix in compact form.
27228 
27229     NL     (input) INTEGER
27230            The row dimension of the upper block. NL >= 1.
27231 
27232     NR     (input) INTEGER
27233            The row dimension of the lower block. NR >= 1.
27234 
27235     SQRE   (input) INTEGER
27236            = 0: the lower block is an NR-by-NR square matrix.
27237            = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
27238 
27239            The bidiagonal matrix has
27240            N = NL + NR + 1 rows and
27241            M = N + SQRE >= N columns.
27242 
27243     K      (output) INTEGER
27244            Contains the dimension of the non-deflated matrix, this is
27245            the order of the related secular equation. 1 <= K <=N.
27246 
27247     D      (input/output) DOUBLE PRECISION array, dimension ( N )
27248            On entry D contains the singular values of the two submatrices
27249            to be combined. On exit D contains the trailing (N-K) updated
27250            singular values (those which were deflated) sorted into
27251            increasing order.
27252 
27253     Z      (output) DOUBLE PRECISION array, dimension ( M )
27254            On exit Z contains the updating row vector in the secular
27255            equation.
27256 
27257     ZW     (workspace) DOUBLE PRECISION array, dimension ( M )
27258            Workspace for Z.
27259 
27260     VF     (input/output) DOUBLE PRECISION array, dimension ( M )
27261            On entry, VF(1:NL+1) contains the first components of all
27262            right singular vectors of the upper block; and VF(NL+2:M)
27263            contains the first components of all right singular vectors
27264            of the lower block. On exit, VF contains the first components
27265            of all right singular vectors of the bidiagonal matrix.
27266 
27267     VFW    (workspace) DOUBLE PRECISION array, dimension ( M )
27268            Workspace for VF.
27269 
27270     VL     (input/output) DOUBLE PRECISION array, dimension ( M )
27271            On entry, VL(1:NL+1) contains the  last components of all
27272            right singular vectors of the upper block; and VL(NL+2:M)
27273            contains the last components of all right singular vectors
27274            of the lower block. On exit, VL contains the last components
27275            of all right singular vectors of the bidiagonal matrix.
27276 
27277     VLW    (workspace) DOUBLE PRECISION array, dimension ( M )
27278            Workspace for VL.
27279 
27280     ALPHA  (input) DOUBLE PRECISION
27281            Contains the diagonal element associated with the added row.
27282 
27283     BETA   (input) DOUBLE PRECISION
27284            Contains the off-diagonal element associated with the added
27285            row.
27286 
27287     DSIGMA (output) DOUBLE PRECISION array, dimension ( N )
27288            Contains a copy of the diagonal elements (K-1 singular values
27289            and one zero) in the secular equation.
27290 
27291     IDX    (workspace) INTEGER array, dimension ( N )
27292            This will contain the permutation used to sort the contents of
27293            D into ascending order.
27294 
27295     IDXP   (workspace) INTEGER array, dimension ( N )
27296            This will contain the permutation used to place deflated
27297            values of D at the end of the array. On output IDXP(2:K)
27298            points to the nondeflated D-values and IDXP(K+1:N)
27299            points to the deflated singular values.
27300 
27301     IDXQ   (input) INTEGER array, dimension ( N )
27302            This contains the permutation which separately sorts the two
27303            sub-problems in D into ascending order.  Note that entries in
27304            the first half of this permutation must first be moved one
27305            position backward; and entries in the second half
27306            must first have NL+1 added to their values.
27307 
27308     PERM   (output) INTEGER array, dimension ( N )
27309            The permutations (from deflation and sorting) to be applied
27310            to each singular block. Not referenced if ICOMPQ = 0.
27311 
27312     GIVPTR (output) INTEGER
27313            The number of Givens rotations which took place in this
27314            subproblem. Not referenced if ICOMPQ = 0.
27315 
27316     GIVCOL (output) INTEGER array, dimension ( LDGCOL, 2 )
27317            Each pair of numbers indicates a pair of columns to take place
27318            in a Givens rotation. Not referenced if ICOMPQ = 0.
27319 
27320     LDGCOL (input) INTEGER
27321            The leading dimension of GIVCOL, must be at least N.
27322 
27323     GIVNUM (output) DOUBLE PRECISION array, dimension ( LDGNUM, 2 )
27324            Each number indicates the C or S value to be used in the
27325            corresponding Givens rotation. Not referenced if ICOMPQ = 0.
27326 
27327     LDGNUM (input) INTEGER
27328            The leading dimension of GIVNUM, must be at least N.
27329 
27330     C      (output) DOUBLE PRECISION
27331            C contains garbage if SQRE =0 and the C-value of a Givens
27332            rotation related to the right null space if SQRE = 1.
27333 
27334     S      (output) DOUBLE PRECISION
27335            S contains garbage if SQRE =0 and the S-value of a Givens
27336            rotation related to the right null space if SQRE = 1.
27337 
27338     INFO   (output) INTEGER
27339            = 0:  successful exit.
27340            < 0:  if INFO = -i, the i-th argument had an illegal value.
27341 
27342     Further Details
27343     ===============
27344 
27345     Based on contributions by
27346        Ming Gu and Huan Ren, Computer Science Division, University of
27347        California at Berkeley, USA
27348 
27349     =====================================================================
27350 
27351 
27352        Test the input parameters.
27353 */
27354 
27355     /* Parameter adjustments */
27356     --d__;
27357     --z__;
27358     --zw;
27359     --vf;
27360     --vfw;
27361     --vl;
27362     --vlw;
27363     --dsigma;
27364     --idx;
27365     --idxp;
27366     --idxq;
27367     --perm;
27368     givcol_dim1 = *ldgcol;
27369     givcol_offset = 1 + givcol_dim1;
27370     givcol -= givcol_offset;
27371     givnum_dim1 = *ldgnum;
27372     givnum_offset = 1 + givnum_dim1;
27373     givnum -= givnum_offset;
27374 
27375     /* Function Body */
27376     *info = 0;
27377     n = *nl + *nr + 1;
27378     m = n + *sqre;
27379 
27380     if (*icompq < 0 || *icompq > 1) {
27381 	*info = -1;
27382     } else if (*nl < 1) {
27383 	*info = -2;
27384     } else if (*nr < 1) {
27385 	*info = -3;
27386     } else if (*sqre < 0 || *sqre > 1) {
27387 	*info = -4;
27388     } else if (*ldgcol < n) {
27389 	*info = -22;
27390     } else if (*ldgnum < n) {
27391 	*info = -24;
27392     }
27393     if (*info != 0) {
27394 	i__1 = -(*info);
27395 	xerbla_("DLASD7", &i__1);
27396 	return 0;
27397     }
27398 
27399     nlp1 = *nl + 1;
27400     nlp2 = *nl + 2;
27401     if (*icompq == 1) {
27402 	*givptr = 0;
27403     }
27404 
27405 /*
27406        Generate the first part of the vector Z and move the singular
27407        values in the first part of D one position backward.
27408 */
27409 
27410     z1 = *alpha * vl[nlp1];
27411     vl[nlp1] = 0.;
27412     tau = vf[nlp1];
27413     for (i__ = *nl; i__ >= 1; --i__) {
27414 	z__[i__ + 1] = *alpha * vl[i__];
27415 	vl[i__] = 0.;
27416 	vf[i__ + 1] = vf[i__];
27417 	d__[i__ + 1] = d__[i__];
27418 	idxq[i__ + 1] = idxq[i__] + 1;
27419 /* L10: */
27420     }
27421     vf[1] = tau;
27422 
27423 /*     Generate the second part of the vector Z. */
27424 
27425     i__1 = m;
27426     for (i__ = nlp2; i__ <= i__1; ++i__) {
27427 	z__[i__] = *beta * vf[i__];
27428 	vf[i__] = 0.;
27429 /* L20: */
27430     }
27431 
27432 /*     Sort the singular values into increasing order */
27433 
27434     i__1 = n;
27435     for (i__ = nlp2; i__ <= i__1; ++i__) {
27436 	idxq[i__] += nlp1;
27437 /* L30: */
27438     }
27439 
27440 /*     DSIGMA, IDXC, IDXC, and ZW are used as storage space. */
27441 
27442     i__1 = n;
27443     for (i__ = 2; i__ <= i__1; ++i__) {
27444 	dsigma[i__] = d__[idxq[i__]];
27445 	zw[i__] = z__[idxq[i__]];
27446 	vfw[i__] = vf[idxq[i__]];
27447 	vlw[i__] = vl[idxq[i__]];
27448 /* L40: */
27449     }
27450 
27451     dlamrg_(nl, nr, &dsigma[2], &c__1, &c__1, &idx[2]);
27452 
27453     i__1 = n;
27454     for (i__ = 2; i__ <= i__1; ++i__) {
27455 	idxi = idx[i__] + 1;
27456 	d__[i__] = dsigma[idxi];
27457 	z__[i__] = zw[idxi];
27458 	vf[i__] = vfw[idxi];
27459 	vl[i__] = vlw[idxi];
27460 /* L50: */
27461     }
27462 
27463 /*     Calculate the allowable deflation tolerence */
27464 
27465     eps = EPSILON;
27466 /* Computing MAX */
27467     d__1 = abs(*alpha), d__2 = abs(*beta);
27468     tol = max(d__1,d__2);
27469 /* Computing MAX */
27470     d__2 = (d__1 = d__[n], abs(d__1));
27471     tol = eps * 64. * max(d__2,tol);
27472 
27473 /*
27474        There are 2 kinds of deflation -- first a value in the z-vector
27475        is small, second two (or more) singular values are very close
27476        together (their difference is small).
27477 
27478        If the value in the z-vector is small, we simply permute the
27479        array so that the corresponding singular value is moved to the
27480        end.
27481 
27482        If two values in the D-vector are close, we perform a two-sided
27483        rotation designed to make one of the corresponding z-vector
27484        entries zero, and then permute the array so that the deflated
27485        singular value is moved to the end.
27486 
27487        If there are multiple singular values then the problem deflates.
27488        Here the number of equal singular values are found.  As each equal
27489        singular value is found, an elementary reflector is computed to
27490        rotate the corresponding singular subspace so that the
27491        corresponding components of Z are zero in this new basis.
27492 */
27493 
27494     *k = 1;
27495     k2 = n + 1;
27496     i__1 = n;
27497     for (j = 2; j <= i__1; ++j) {
27498 	if ((d__1 = z__[j], abs(d__1)) <= tol) {
27499 
27500 /*           Deflate due to small z component. */
27501 
27502 	    --k2;
27503 	    idxp[k2] = j;
27504 	    if (j == n) {
27505 		goto L100;
27506 	    }
27507 	} else {
27508 	    jprev = j;
27509 	    goto L70;
27510 	}
27511 /* L60: */
27512     }
27513 L70:
27514     j = jprev;
27515 L80:
27516     ++j;
27517     if (j > n) {
27518 	goto L90;
27519     }
27520     if ((d__1 = z__[j], abs(d__1)) <= tol) {
27521 
27522 /*        Deflate due to small z component. */
27523 
27524 	--k2;
27525 	idxp[k2] = j;
27526     } else {
27527 
27528 /*        Check if singular values are close enough to allow deflation. */
27529 
27530 	if ((d__1 = d__[j] - d__[jprev], abs(d__1)) <= tol) {
27531 
27532 /*           Deflation is possible. */
27533 
27534 	    *s = z__[jprev];
27535 	    *c__ = z__[j];
27536 
27537 /*
27538              Find sqrt(a**2+b**2) without overflow or
27539              destructive underflow.
27540 */
27541 
27542 	    tau = dlapy2_(c__, s);
27543 	    z__[j] = tau;
27544 	    z__[jprev] = 0.;
27545 	    *c__ /= tau;
27546 	    *s = -(*s) / tau;
27547 
27548 /*           Record the appropriate Givens rotation */
27549 
27550 	    if (*icompq == 1) {
27551 		++(*givptr);
27552 		idxjp = idxq[idx[jprev] + 1];
27553 		idxj = idxq[idx[j] + 1];
27554 		if (idxjp <= nlp1) {
27555 		    --idxjp;
27556 		}
27557 		if (idxj <= nlp1) {
27558 		    --idxj;
27559 		}
27560 		givcol[*givptr + (givcol_dim1 << 1)] = idxjp;
27561 		givcol[*givptr + givcol_dim1] = idxj;
27562 		givnum[*givptr + (givnum_dim1 << 1)] = *c__;
27563 		givnum[*givptr + givnum_dim1] = *s;
27564 	    }
27565 	    drot_(&c__1, &vf[jprev], &c__1, &vf[j], &c__1, c__, s);
27566 	    drot_(&c__1, &vl[jprev], &c__1, &vl[j], &c__1, c__, s);
27567 	    --k2;
27568 	    idxp[k2] = jprev;
27569 	    jprev = j;
27570 	} else {
27571 	    ++(*k);
27572 	    zw[*k] = z__[jprev];
27573 	    dsigma[*k] = d__[jprev];
27574 	    idxp[*k] = jprev;
27575 	    jprev = j;
27576 	}
27577     }
27578     goto L80;
27579 L90:
27580 
27581 /*     Record the last singular value. */
27582 
27583     ++(*k);
27584     zw[*k] = z__[jprev];
27585     dsigma[*k] = d__[jprev];
27586     idxp[*k] = jprev;
27587 
27588 L100:
27589 
27590 /*
27591        Sort the singular values into DSIGMA. The singular values which
27592        were not deflated go into the first K slots of DSIGMA, except
27593        that DSIGMA(1) is treated separately.
27594 */
27595 
27596     i__1 = n;
27597     for (j = 2; j <= i__1; ++j) {
27598 	jp = idxp[j];
27599 	dsigma[j] = d__[jp];
27600 	vfw[j] = vf[jp];
27601 	vlw[j] = vl[jp];
27602 /* L110: */
27603     }
27604     if (*icompq == 1) {
27605 	i__1 = n;
27606 	for (j = 2; j <= i__1; ++j) {
27607 	    jp = idxp[j];
27608 	    perm[j] = idxq[idx[jp] + 1];
27609 	    if (perm[j] <= nlp1) {
27610 		--perm[j];
27611 	    }
27612 /* L120: */
27613 	}
27614     }
27615 
27616 /*
27617        The deflated singular values go back into the last N - K slots of
27618        D.
27619 */
27620 
27621     i__1 = n - *k;
27622     dcopy_(&i__1, &dsigma[*k + 1], &c__1, &d__[*k + 1], &c__1);
27623 
27624 /*
27625        Determine DSIGMA(1), DSIGMA(2), Z(1), VF(1), VL(1), VF(M), and
27626        VL(M).
27627 */
27628 
27629     dsigma[1] = 0.;
27630     hlftol = tol / 2.;
27631     if (abs(dsigma[2]) <= hlftol) {
27632 	dsigma[2] = hlftol;
27633     }
27634     if (m > n) {
27635 	z__[1] = dlapy2_(&z1, &z__[m]);
27636 	if (z__[1] <= tol) {
27637 	    *c__ = 1.;
27638 	    *s = 0.;
27639 	    z__[1] = tol;
27640 	} else {
27641 	    *c__ = z1 / z__[1];
27642 	    *s = -z__[m] / z__[1];
27643 	}
27644 	drot_(&c__1, &vf[m], &c__1, &vf[1], &c__1, c__, s);
27645 	drot_(&c__1, &vl[m], &c__1, &vl[1], &c__1, c__, s);
27646     } else {
27647 	if (abs(z1) <= tol) {
27648 	    z__[1] = tol;
27649 	} else {
27650 	    z__[1] = z1;
27651 	}
27652     }
27653 
27654 /*     Restore Z, VF, and VL. */
27655 
27656     i__1 = *k - 1;
27657     dcopy_(&i__1, &zw[2], &c__1, &z__[2], &c__1);
27658     i__1 = n - 1;
27659     dcopy_(&i__1, &vfw[2], &c__1, &vf[2], &c__1);
27660     i__1 = n - 1;
27661     dcopy_(&i__1, &vlw[2], &c__1, &vl[2], &c__1);
27662 
27663     return 0;
27664 
27665 /*     End of DLASD7 */
27666 
27667 } /* dlasd7_ */
27668 
dlasd8_(integer * icompq,integer * k,doublereal * d__,doublereal * z__,doublereal * vf,doublereal * vl,doublereal * difl,doublereal * difr,integer * lddifr,doublereal * dsigma,doublereal * work,integer * info)27669 /* Subroutine */ int dlasd8_(integer *icompq, integer *k, doublereal *d__,
27670 	doublereal *z__, doublereal *vf, doublereal *vl, doublereal *difl,
27671 	doublereal *difr, integer *lddifr, doublereal *dsigma, doublereal *
27672 	work, integer *info)
27673 {
27674     /* System generated locals */
27675     integer difr_dim1, difr_offset, i__1, i__2;
27676     doublereal d__1, d__2;
27677 
27678     /* Local variables */
27679     static integer i__, j;
27680     static doublereal dj, rho;
27681     static integer iwk1, iwk2, iwk3;
27682     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
27683 	    integer *);
27684     static doublereal temp;
27685     extern doublereal dnrm2_(integer *, doublereal *, integer *);
27686     static integer iwk2i, iwk3i;
27687     static doublereal diflj, difrj, dsigj;
27688     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
27689 	    doublereal *, integer *);
27690     extern doublereal dlamc3_(doublereal *, doublereal *);
27691     extern /* Subroutine */ int dlasd4_(integer *, integer *, doublereal *,
27692 	    doublereal *, doublereal *, doublereal *, doublereal *,
27693 	    doublereal *, integer *), dlascl_(char *, integer *, integer *,
27694 	    doublereal *, doublereal *, integer *, integer *, doublereal *,
27695 	    integer *, integer *), dlaset_(char *, integer *, integer
27696 	    *, doublereal *, doublereal *, doublereal *, integer *),
27697 	    xerbla_(char *, integer *);
27698     static doublereal dsigjp;
27699 
27700 
27701 /*
27702     -- LAPACK auxiliary routine (version 3.2.2) --
27703     -- LAPACK is a software package provided by Univ. of Tennessee,    --
27704     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
27705        June 2010
27706 
27707 
27708     Purpose
27709     =======
27710 
27711     DLASD8 finds the square roots of the roots of the secular equation,
27712     as defined by the values in DSIGMA and Z. It makes the appropriate
27713     calls to DLASD4, and stores, for each  element in D, the distance
27714     to its two nearest poles (elements in DSIGMA). It also updates
27715     the arrays VF and VL, the first and last components of all the
27716     right singular vectors of the original bidiagonal matrix.
27717 
27718     DLASD8 is called from DLASD6.
27719 
27720     Arguments
27721     =========
27722 
27723     ICOMPQ  (input) INTEGER
27724             Specifies whether singular vectors are to be computed in
27725             factored form in the calling routine:
27726             = 0: Compute singular values only.
27727             = 1: Compute singular vectors in factored form as well.
27728 
27729     K       (input) INTEGER
27730             The number of terms in the rational function to be solved
27731             by DLASD4.  K >= 1.
27732 
27733     D       (output) DOUBLE PRECISION array, dimension ( K )
27734             On output, D contains the updated singular values.
27735 
27736     Z       (input/output) DOUBLE PRECISION array, dimension ( K )
27737             On entry, the first K elements of this array contain the
27738             components of the deflation-adjusted updating row vector.
27739             On exit, Z is updated.
27740 
27741     VF      (input/output) DOUBLE PRECISION array, dimension ( K )
27742             On entry, VF contains  information passed through DBEDE8.
27743             On exit, VF contains the first K components of the first
27744             components of all right singular vectors of the bidiagonal
27745             matrix.
27746 
27747     VL      (input/output) DOUBLE PRECISION array, dimension ( K )
27748             On entry, VL contains  information passed through DBEDE8.
27749             On exit, VL contains the first K components of the last
27750             components of all right singular vectors of the bidiagonal
27751             matrix.
27752 
27753     DIFL    (output) DOUBLE PRECISION array, dimension ( K )
27754             On exit, DIFL(I) = D(I) - DSIGMA(I).
27755 
27756     DIFR    (output) DOUBLE PRECISION array,
27757                      dimension ( LDDIFR, 2 ) if ICOMPQ = 1 and
27758                      dimension ( K ) if ICOMPQ = 0.
27759             On exit, DIFR(I,1) = D(I) - DSIGMA(I+1), DIFR(K,1) is not
27760             defined and will not be referenced.
27761 
27762             If ICOMPQ = 1, DIFR(1:K,2) is an array containing the
27763             normalizing factors for the right singular vector matrix.
27764 
27765     LDDIFR  (input) INTEGER
27766             The leading dimension of DIFR, must be at least K.
27767 
27768     DSIGMA  (input/output) DOUBLE PRECISION array, dimension ( K )
27769             On entry, the first K elements of this array contain the old
27770             roots of the deflated updating problem.  These are the poles
27771             of the secular equation.
27772             On exit, the elements of DSIGMA may be very slightly altered
27773             in value.
27774 
27775     WORK    (workspace) DOUBLE PRECISION array, dimension at least 3 * K
27776 
27777     INFO    (output) INTEGER
27778             = 0:  successful exit.
27779             < 0:  if INFO = -i, the i-th argument had an illegal value.
27780             > 0:  if INFO = 1, a singular value did not converge
27781 
27782     Further Details
27783     ===============
27784 
27785     Based on contributions by
27786        Ming Gu and Huan Ren, Computer Science Division, University of
27787        California at Berkeley, USA
27788 
27789     =====================================================================
27790 
27791 
27792        Test the input parameters.
27793 */
27794 
27795     /* Parameter adjustments */
27796     --d__;
27797     --z__;
27798     --vf;
27799     --vl;
27800     --difl;
27801     difr_dim1 = *lddifr;
27802     difr_offset = 1 + difr_dim1;
27803     difr -= difr_offset;
27804     --dsigma;
27805     --work;
27806 
27807     /* Function Body */
27808     *info = 0;
27809 
27810     if (*icompq < 0 || *icompq > 1) {
27811 	*info = -1;
27812     } else if (*k < 1) {
27813 	*info = -2;
27814     } else if (*lddifr < *k) {
27815 	*info = -9;
27816     }
27817     if (*info != 0) {
27818 	i__1 = -(*info);
27819 	xerbla_("DLASD8", &i__1);
27820 	return 0;
27821     }
27822 
27823 /*     Quick return if possible */
27824 
27825     if (*k == 1) {
27826 	d__[1] = abs(z__[1]);
27827 	difl[1] = d__[1];
27828 	if (*icompq == 1) {
27829 	    difl[2] = 1.;
27830 	    difr[(difr_dim1 << 1) + 1] = 1.;
27831 	}
27832 	return 0;
27833     }
27834 
27835 /*
27836        Modify values DSIGMA(i) to make sure all DSIGMA(i)-DSIGMA(j) can
27837        be computed with high relative accuracy (barring over/underflow).
27838        This is a problem on machines without a guard digit in
27839        add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2).
27840        The following code replaces DSIGMA(I) by 2*DSIGMA(I)-DSIGMA(I),
27841        which on any of these machines zeros out the bottommost
27842        bit of DSIGMA(I) if it is 1; this makes the subsequent
27843        subtractions DSIGMA(I)-DSIGMA(J) unproblematic when cancellation
27844        occurs. On binary machines with a guard digit (almost all
27845        machines) it does not change DSIGMA(I) at all. On hexadecimal
27846        and decimal machines with a guard digit, it slightly
27847        changes the bottommost bits of DSIGMA(I). It does not account
27848        for hexadecimal or decimal machines without guard digits
27849        (we know of none). We use a subroutine call to compute
27850        2*DLAMBDA(I) to prevent optimizing compilers from eliminating
27851        this code.
27852 */
27853 
27854     i__1 = *k;
27855     for (i__ = 1; i__ <= i__1; ++i__) {
27856 	dsigma[i__] = dlamc3_(&dsigma[i__], &dsigma[i__]) - dsigma[i__];
27857 /* L10: */
27858     }
27859 
27860 /*     Book keeping. */
27861 
27862     iwk1 = 1;
27863     iwk2 = iwk1 + *k;
27864     iwk3 = iwk2 + *k;
27865     iwk2i = iwk2 - 1;
27866     iwk3i = iwk3 - 1;
27867 
27868 /*     Normalize Z. */
27869 
27870     rho = dnrm2_(k, &z__[1], &c__1);
27871     dlascl_("G", &c__0, &c__0, &rho, &c_b15, k, &c__1, &z__[1], k, info);
27872     rho *= rho;
27873 
27874 /*     Initialize WORK(IWK3). */
27875 
27876     dlaset_("A", k, &c__1, &c_b15, &c_b15, &work[iwk3], k);
27877 
27878 /*
27879        Compute the updated singular values, the arrays DIFL, DIFR,
27880        and the updated Z.
27881 */
27882 
27883     i__1 = *k;
27884     for (j = 1; j <= i__1; ++j) {
27885 	dlasd4_(k, &j, &dsigma[1], &z__[1], &work[iwk1], &rho, &d__[j], &work[
27886 		iwk2], info);
27887 
27888 /*        If the root finder fails, the computation is terminated. */
27889 
27890 	if (*info != 0) {
27891 	    return 0;
27892 	}
27893 	work[iwk3i + j] = work[iwk3i + j] * work[j] * work[iwk2i + j];
27894 	difl[j] = -work[j];
27895 	difr[j + difr_dim1] = -work[j + 1];
27896 	i__2 = j - 1;
27897 	for (i__ = 1; i__ <= i__2; ++i__) {
27898 	    work[iwk3i + i__] = work[iwk3i + i__] * work[i__] * work[iwk2i +
27899 		    i__] / (dsigma[i__] - dsigma[j]) / (dsigma[i__] + dsigma[
27900 		    j]);
27901 /* L20: */
27902 	}
27903 	i__2 = *k;
27904 	for (i__ = j + 1; i__ <= i__2; ++i__) {
27905 	    work[iwk3i + i__] = work[iwk3i + i__] * work[i__] * work[iwk2i +
27906 		    i__] / (dsigma[i__] - dsigma[j]) / (dsigma[i__] + dsigma[
27907 		    j]);
27908 /* L30: */
27909 	}
27910 /* L40: */
27911     }
27912 
27913 /*     Compute updated Z. */
27914 
27915     i__1 = *k;
27916     for (i__ = 1; i__ <= i__1; ++i__) {
27917 	d__2 = sqrt((d__1 = work[iwk3i + i__], abs(d__1)));
27918 	z__[i__] = d_sign(&d__2, &z__[i__]);
27919 /* L50: */
27920     }
27921 
27922 /*     Update VF and VL. */
27923 
27924     i__1 = *k;
27925     for (j = 1; j <= i__1; ++j) {
27926 	diflj = difl[j];
27927 	dj = d__[j];
27928 	dsigj = -dsigma[j];
27929 	if (j < *k) {
27930 	    difrj = -difr[j + difr_dim1];
27931 	    dsigjp = -dsigma[j + 1];
27932 	}
27933 	work[j] = -z__[j] / diflj / (dsigma[j] + dj);
27934 	i__2 = j - 1;
27935 	for (i__ = 1; i__ <= i__2; ++i__) {
27936 	    work[i__] = z__[i__] / (dlamc3_(&dsigma[i__], &dsigj) - diflj) / (
27937 		    dsigma[i__] + dj);
27938 /* L60: */
27939 	}
27940 	i__2 = *k;
27941 	for (i__ = j + 1; i__ <= i__2; ++i__) {
27942 	    work[i__] = z__[i__] / (dlamc3_(&dsigma[i__], &dsigjp) + difrj) /
27943 		    (dsigma[i__] + dj);
27944 /* L70: */
27945 	}
27946 	temp = dnrm2_(k, &work[1], &c__1);
27947 	work[iwk2i + j] = ddot_(k, &work[1], &c__1, &vf[1], &c__1) / temp;
27948 	work[iwk3i + j] = ddot_(k, &work[1], &c__1, &vl[1], &c__1) / temp;
27949 	if (*icompq == 1) {
27950 	    difr[j + (difr_dim1 << 1)] = temp;
27951 	}
27952 /* L80: */
27953     }
27954 
27955     dcopy_(k, &work[iwk2], &c__1, &vf[1], &c__1);
27956     dcopy_(k, &work[iwk3], &c__1, &vl[1], &c__1);
27957 
27958     return 0;
27959 
27960 /*     End of DLASD8 */
27961 
27962 } /* dlasd8_ */
27963 
dlasda_(integer * icompq,integer * smlsiz,integer * n,integer * sqre,doublereal * d__,doublereal * e,doublereal * u,integer * ldu,doublereal * vt,integer * k,doublereal * difl,doublereal * difr,doublereal * z__,doublereal * poles,integer * givptr,integer * givcol,integer * ldgcol,integer * perm,doublereal * givnum,doublereal * c__,doublereal * s,doublereal * work,integer * iwork,integer * info)27964 /* Subroutine */ int dlasda_(integer *icompq, integer *smlsiz, integer *n,
27965 	integer *sqre, doublereal *d__, doublereal *e, doublereal *u, integer
27966 	*ldu, doublereal *vt, integer *k, doublereal *difl, doublereal *difr,
27967 	doublereal *z__, doublereal *poles, integer *givptr, integer *givcol,
27968 	integer *ldgcol, integer *perm, doublereal *givnum, doublereal *c__,
27969 	doublereal *s, doublereal *work, integer *iwork, integer *info)
27970 {
27971     /* System generated locals */
27972     integer givcol_dim1, givcol_offset, perm_dim1, perm_offset, difl_dim1,
27973 	    difl_offset, difr_dim1, difr_offset, givnum_dim1, givnum_offset,
27974 	    poles_dim1, poles_offset, u_dim1, u_offset, vt_dim1, vt_offset,
27975 	    z_dim1, z_offset, i__1, i__2;
27976 
27977     /* Local variables */
27978     static integer i__, j, m, i1, ic, lf, nd, ll, nl, vf, nr, vl, im1, ncc,
27979 	    nlf, nrf, vfi, iwk, vli, lvl, nru, ndb1, nlp1, lvl2, nrp1;
27980     static doublereal beta;
27981     static integer idxq, nlvl;
27982     static doublereal alpha;
27983     static integer inode, ndiml, ndimr, idxqi, itemp;
27984     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
27985 	    doublereal *, integer *);
27986     static integer sqrei;
27987     extern /* Subroutine */ int dlasd6_(integer *, integer *, integer *,
27988 	    integer *, doublereal *, doublereal *, doublereal *, doublereal *,
27989 	     doublereal *, integer *, integer *, integer *, integer *,
27990 	    integer *, doublereal *, integer *, doublereal *, doublereal *,
27991 	    doublereal *, doublereal *, integer *, doublereal *, doublereal *,
27992 	     doublereal *, integer *, integer *);
27993     static integer nwork1, nwork2;
27994     extern /* Subroutine */ int dlasdq_(char *, integer *, integer *, integer
27995 	    *, integer *, integer *, doublereal *, doublereal *, doublereal *,
27996 	     integer *, doublereal *, integer *, doublereal *, integer *,
27997 	    doublereal *, integer *), dlasdt_(integer *, integer *,
27998 	    integer *, integer *, integer *, integer *, integer *), dlaset_(
27999 	    char *, integer *, integer *, doublereal *, doublereal *,
28000 	    doublereal *, integer *), xerbla_(char *, integer *);
28001     static integer smlszp;
28002 
28003 
28004 /*
28005     -- LAPACK auxiliary routine (version 3.2.2) --
28006     -- LAPACK is a software package provided by Univ. of Tennessee,    --
28007     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
28008        June 2010
28009 
28010 
28011     Purpose
28012     =======
28013 
28014     Using a divide and conquer approach, DLASDA computes the singular
28015     value decomposition (SVD) of a real upper bidiagonal N-by-M matrix
28016     B with diagonal D and offdiagonal E, where M = N + SQRE. The
28017     algorithm computes the singular values in the SVD B = U * S * VT.
28018     The orthogonal matrices U and VT are optionally computed in
28019     compact form.
28020 
28021     A related subroutine, DLASD0, computes the singular values and
28022     the singular vectors in explicit form.
28023 
28024     Arguments
28025     =========
28026 
28027     ICOMPQ (input) INTEGER
28028            Specifies whether singular vectors are to be computed
28029            in compact form, as follows
28030            = 0: Compute singular values only.
28031            = 1: Compute singular vectors of upper bidiagonal
28032                 matrix in compact form.
28033 
28034     SMLSIZ (input) INTEGER
28035            The maximum size of the subproblems at the bottom of the
28036            computation tree.
28037 
28038     N      (input) INTEGER
28039            The row dimension of the upper bidiagonal matrix. This is
28040            also the dimension of the main diagonal array D.
28041 
28042     SQRE   (input) INTEGER
28043            Specifies the column dimension of the bidiagonal matrix.
28044            = 0: The bidiagonal matrix has column dimension M = N;
28045            = 1: The bidiagonal matrix has column dimension M = N + 1.
28046 
28047     D      (input/output) DOUBLE PRECISION array, dimension ( N )
28048            On entry D contains the main diagonal of the bidiagonal
28049            matrix. On exit D, if INFO = 0, contains its singular values.
28050 
28051     E      (input) DOUBLE PRECISION array, dimension ( M-1 )
28052            Contains the subdiagonal entries of the bidiagonal matrix.
28053            On exit, E has been destroyed.
28054 
28055     U      (output) DOUBLE PRECISION array,
28056            dimension ( LDU, SMLSIZ ) if ICOMPQ = 1, and not referenced
28057            if ICOMPQ = 0. If ICOMPQ = 1, on exit, U contains the left
28058            singular vector matrices of all subproblems at the bottom
28059            level.
28060 
28061     LDU    (input) INTEGER, LDU = > N.
28062            The leading dimension of arrays U, VT, DIFL, DIFR, POLES,
28063            GIVNUM, and Z.
28064 
28065     VT     (output) DOUBLE PRECISION array,
28066            dimension ( LDU, SMLSIZ+1 ) if ICOMPQ = 1, and not referenced
28067            if ICOMPQ = 0. If ICOMPQ = 1, on exit, VT' contains the right
28068            singular vector matrices of all subproblems at the bottom
28069            level.
28070 
28071     K      (output) INTEGER array,
28072            dimension ( N ) if ICOMPQ = 1 and dimension 1 if ICOMPQ = 0.
28073            If ICOMPQ = 1, on exit, K(I) is the dimension of the I-th
28074            secular equation on the computation tree.
28075 
28076     DIFL   (output) DOUBLE PRECISION array, dimension ( LDU, NLVL ),
28077            where NLVL = floor(log_2 (N/SMLSIZ))).
28078 
28079     DIFR   (output) DOUBLE PRECISION array,
28080                     dimension ( LDU, 2 * NLVL ) if ICOMPQ = 1 and
28081                     dimension ( N ) if ICOMPQ = 0.
28082            If ICOMPQ = 1, on exit, DIFL(1:N, I) and DIFR(1:N, 2 * I - 1)
28083            record distances between singular values on the I-th
28084            level and singular values on the (I -1)-th level, and
28085            DIFR(1:N, 2 * I ) contains the normalizing factors for
28086            the right singular vector matrix. See DLASD8 for details.
28087 
28088     Z      (output) DOUBLE PRECISION array,
28089                     dimension ( LDU, NLVL ) if ICOMPQ = 1 and
28090                     dimension ( N ) if ICOMPQ = 0.
28091            The first K elements of Z(1, I) contain the components of
28092            the deflation-adjusted updating row vector for subproblems
28093            on the I-th level.
28094 
28095     POLES  (output) DOUBLE PRECISION array,
28096            dimension ( LDU, 2 * NLVL ) if ICOMPQ = 1, and not referenced
28097            if ICOMPQ = 0. If ICOMPQ = 1, on exit, POLES(1, 2*I - 1) and
28098            POLES(1, 2*I) contain  the new and old singular values
28099            involved in the secular equations on the I-th level.
28100 
28101     GIVPTR (output) INTEGER array,
28102            dimension ( N ) if ICOMPQ = 1, and not referenced if
28103            ICOMPQ = 0. If ICOMPQ = 1, on exit, GIVPTR( I ) records
28104            the number of Givens rotations performed on the I-th
28105            problem on the computation tree.
28106 
28107     GIVCOL (output) INTEGER array,
28108            dimension ( LDGCOL, 2 * NLVL ) if ICOMPQ = 1, and not
28109            referenced if ICOMPQ = 0. If ICOMPQ = 1, on exit, for each I,
28110            GIVCOL(1, 2 *I - 1) and GIVCOL(1, 2 *I) record the locations
28111            of Givens rotations performed on the I-th level on the
28112            computation tree.
28113 
28114     LDGCOL (input) INTEGER, LDGCOL = > N.
28115            The leading dimension of arrays GIVCOL and PERM.
28116 
28117     PERM   (output) INTEGER array,
28118            dimension ( LDGCOL, NLVL ) if ICOMPQ = 1, and not referenced
28119            if ICOMPQ = 0. If ICOMPQ = 1, on exit, PERM(1, I) records
28120            permutations done on the I-th level of the computation tree.
28121 
28122     GIVNUM (output) DOUBLE PRECISION array,
28123            dimension ( LDU,  2 * NLVL ) if ICOMPQ = 1, and not
28124            referenced if ICOMPQ = 0. If ICOMPQ = 1, on exit, for each I,
28125            GIVNUM(1, 2 *I - 1) and GIVNUM(1, 2 *I) record the C- and S-
28126            values of Givens rotations performed on the I-th level on
28127            the computation tree.
28128 
28129     C      (output) DOUBLE PRECISION array,
28130            dimension ( N ) if ICOMPQ = 1, and dimension 1 if ICOMPQ = 0.
28131            If ICOMPQ = 1 and the I-th subproblem is not square, on exit,
28132            C( I ) contains the C-value of a Givens rotation related to
28133            the right null space of the I-th subproblem.
28134 
28135     S      (output) DOUBLE PRECISION array, dimension ( N ) if
28136            ICOMPQ = 1, and dimension 1 if ICOMPQ = 0. If ICOMPQ = 1
28137            and the I-th subproblem is not square, on exit, S( I )
28138            contains the S-value of a Givens rotation related to
28139            the right null space of the I-th subproblem.
28140 
28141     WORK   (workspace) DOUBLE PRECISION array, dimension
28142            (6 * N + (SMLSIZ + 1)*(SMLSIZ + 1)).
28143 
28144     IWORK  (workspace) INTEGER array.
28145            Dimension must be at least (7 * N).
28146 
28147     INFO   (output) INTEGER
28148             = 0:  successful exit.
28149             < 0:  if INFO = -i, the i-th argument had an illegal value.
28150             > 0:  if INFO = 1, a singular value did not converge
28151 
28152     Further Details
28153     ===============
28154 
28155     Based on contributions by
28156        Ming Gu and Huan Ren, Computer Science Division, University of
28157        California at Berkeley, USA
28158 
28159     =====================================================================
28160 
28161 
28162        Test the input parameters.
28163 */
28164 
28165     /* Parameter adjustments */
28166     --d__;
28167     --e;
28168     givnum_dim1 = *ldu;
28169     givnum_offset = 1 + givnum_dim1;
28170     givnum -= givnum_offset;
28171     poles_dim1 = *ldu;
28172     poles_offset = 1 + poles_dim1;
28173     poles -= poles_offset;
28174     z_dim1 = *ldu;
28175     z_offset = 1 + z_dim1;
28176     z__ -= z_offset;
28177     difr_dim1 = *ldu;
28178     difr_offset = 1 + difr_dim1;
28179     difr -= difr_offset;
28180     difl_dim1 = *ldu;
28181     difl_offset = 1 + difl_dim1;
28182     difl -= difl_offset;
28183     vt_dim1 = *ldu;
28184     vt_offset = 1 + vt_dim1;
28185     vt -= vt_offset;
28186     u_dim1 = *ldu;
28187     u_offset = 1 + u_dim1;
28188     u -= u_offset;
28189     --k;
28190     --givptr;
28191     perm_dim1 = *ldgcol;
28192     perm_offset = 1 + perm_dim1;
28193     perm -= perm_offset;
28194     givcol_dim1 = *ldgcol;
28195     givcol_offset = 1 + givcol_dim1;
28196     givcol -= givcol_offset;
28197     --c__;
28198     --s;
28199     --work;
28200     --iwork;
28201 
28202     /* Function Body */
28203     *info = 0;
28204 
28205     if (*icompq < 0 || *icompq > 1) {
28206 	*info = -1;
28207     } else if (*smlsiz < 3) {
28208 	*info = -2;
28209     } else if (*n < 0) {
28210 	*info = -3;
28211     } else if (*sqre < 0 || *sqre > 1) {
28212 	*info = -4;
28213     } else if (*ldu < *n + *sqre) {
28214 	*info = -8;
28215     } else if (*ldgcol < *n) {
28216 	*info = -17;
28217     }
28218     if (*info != 0) {
28219 	i__1 = -(*info);
28220 	xerbla_("DLASDA", &i__1);
28221 	return 0;
28222     }
28223 
28224     m = *n + *sqre;
28225 
28226 /*     If the input matrix is too small, call DLASDQ to find the SVD. */
28227 
28228     if (*n <= *smlsiz) {
28229 	if (*icompq == 0) {
28230 	    dlasdq_("U", sqre, n, &c__0, &c__0, &c__0, &d__[1], &e[1], &vt[
28231 		    vt_offset], ldu, &u[u_offset], ldu, &u[u_offset], ldu, &
28232 		    work[1], info);
28233 	} else {
28234 	    dlasdq_("U", sqre, n, &m, n, &c__0, &d__[1], &e[1], &vt[vt_offset]
28235 		    , ldu, &u[u_offset], ldu, &u[u_offset], ldu, &work[1],
28236 		    info);
28237 	}
28238 	return 0;
28239     }
28240 
28241 /*     Book-keeping and  set up the computation tree. */
28242 
28243     inode = 1;
28244     ndiml = inode + *n;
28245     ndimr = ndiml + *n;
28246     idxq = ndimr + *n;
28247     iwk = idxq + *n;
28248 
28249     ncc = 0;
28250     nru = 0;
28251 
28252     smlszp = *smlsiz + 1;
28253     vf = 1;
28254     vl = vf + m;
28255     nwork1 = vl + m;
28256     nwork2 = nwork1 + smlszp * smlszp;
28257 
28258     dlasdt_(n, &nlvl, &nd, &iwork[inode], &iwork[ndiml], &iwork[ndimr],
28259 	    smlsiz);
28260 
28261 /*
28262        for the nodes on bottom level of the tree, solve
28263        their subproblems by DLASDQ.
28264 */
28265 
28266     ndb1 = (nd + 1) / 2;
28267     i__1 = nd;
28268     for (i__ = ndb1; i__ <= i__1; ++i__) {
28269 
28270 /*
28271           IC : center row of each node
28272           NL : number of rows of left  subproblem
28273           NR : number of rows of right subproblem
28274           NLF: starting row of the left   subproblem
28275           NRF: starting row of the right  subproblem
28276 */
28277 
28278 	i1 = i__ - 1;
28279 	ic = iwork[inode + i1];
28280 	nl = iwork[ndiml + i1];
28281 	nlp1 = nl + 1;
28282 	nr = iwork[ndimr + i1];
28283 	nlf = ic - nl;
28284 	nrf = ic + 1;
28285 	idxqi = idxq + nlf - 2;
28286 	vfi = vf + nlf - 1;
28287 	vli = vl + nlf - 1;
28288 	sqrei = 1;
28289 	if (*icompq == 0) {
28290 	    dlaset_("A", &nlp1, &nlp1, &c_b29, &c_b15, &work[nwork1], &smlszp);
28291 	    dlasdq_("U", &sqrei, &nl, &nlp1, &nru, &ncc, &d__[nlf], &e[nlf], &
28292 		    work[nwork1], &smlszp, &work[nwork2], &nl, &work[nwork2],
28293 		    &nl, &work[nwork2], info);
28294 	    itemp = nwork1 + nl * smlszp;
28295 	    dcopy_(&nlp1, &work[nwork1], &c__1, &work[vfi], &c__1);
28296 	    dcopy_(&nlp1, &work[itemp], &c__1, &work[vli], &c__1);
28297 	} else {
28298 	    dlaset_("A", &nl, &nl, &c_b29, &c_b15, &u[nlf + u_dim1], ldu);
28299 	    dlaset_("A", &nlp1, &nlp1, &c_b29, &c_b15, &vt[nlf + vt_dim1],
28300 		    ldu);
28301 	    dlasdq_("U", &sqrei, &nl, &nlp1, &nl, &ncc, &d__[nlf], &e[nlf], &
28302 		    vt[nlf + vt_dim1], ldu, &u[nlf + u_dim1], ldu, &u[nlf +
28303 		    u_dim1], ldu, &work[nwork1], info);
28304 	    dcopy_(&nlp1, &vt[nlf + vt_dim1], &c__1, &work[vfi], &c__1);
28305 	    dcopy_(&nlp1, &vt[nlf + nlp1 * vt_dim1], &c__1, &work[vli], &c__1)
28306 		    ;
28307 	}
28308 	if (*info != 0) {
28309 	    return 0;
28310 	}
28311 	i__2 = nl;
28312 	for (j = 1; j <= i__2; ++j) {
28313 	    iwork[idxqi + j] = j;
28314 /* L10: */
28315 	}
28316 	if (i__ == nd && *sqre == 0) {
28317 	    sqrei = 0;
28318 	} else {
28319 	    sqrei = 1;
28320 	}
28321 	idxqi += nlp1;
28322 	vfi += nlp1;
28323 	vli += nlp1;
28324 	nrp1 = nr + sqrei;
28325 	if (*icompq == 0) {
28326 	    dlaset_("A", &nrp1, &nrp1, &c_b29, &c_b15, &work[nwork1], &smlszp);
28327 	    dlasdq_("U", &sqrei, &nr, &nrp1, &nru, &ncc, &d__[nrf], &e[nrf], &
28328 		    work[nwork1], &smlszp, &work[nwork2], &nr, &work[nwork2],
28329 		    &nr, &work[nwork2], info);
28330 	    itemp = nwork1 + (nrp1 - 1) * smlszp;
28331 	    dcopy_(&nrp1, &work[nwork1], &c__1, &work[vfi], &c__1);
28332 	    dcopy_(&nrp1, &work[itemp], &c__1, &work[vli], &c__1);
28333 	} else {
28334 	    dlaset_("A", &nr, &nr, &c_b29, &c_b15, &u[nrf + u_dim1], ldu);
28335 	    dlaset_("A", &nrp1, &nrp1, &c_b29, &c_b15, &vt[nrf + vt_dim1],
28336 		    ldu);
28337 	    dlasdq_("U", &sqrei, &nr, &nrp1, &nr, &ncc, &d__[nrf], &e[nrf], &
28338 		    vt[nrf + vt_dim1], ldu, &u[nrf + u_dim1], ldu, &u[nrf +
28339 		    u_dim1], ldu, &work[nwork1], info);
28340 	    dcopy_(&nrp1, &vt[nrf + vt_dim1], &c__1, &work[vfi], &c__1);
28341 	    dcopy_(&nrp1, &vt[nrf + nrp1 * vt_dim1], &c__1, &work[vli], &c__1)
28342 		    ;
28343 	}
28344 	if (*info != 0) {
28345 	    return 0;
28346 	}
28347 	i__2 = nr;
28348 	for (j = 1; j <= i__2; ++j) {
28349 	    iwork[idxqi + j] = j;
28350 /* L20: */
28351 	}
28352 /* L30: */
28353     }
28354 
28355 /*     Now conquer each subproblem bottom-up. */
28356 
28357     j = pow_ii(&c__2, &nlvl);
28358     for (lvl = nlvl; lvl >= 1; --lvl) {
28359 	lvl2 = (lvl << 1) - 1;
28360 
28361 /*
28362           Find the first node LF and last node LL on
28363           the current level LVL.
28364 */
28365 
28366 	if (lvl == 1) {
28367 	    lf = 1;
28368 	    ll = 1;
28369 	} else {
28370 	    i__1 = lvl - 1;
28371 	    lf = pow_ii(&c__2, &i__1);
28372 	    ll = (lf << 1) - 1;
28373 	}
28374 	i__1 = ll;
28375 	for (i__ = lf; i__ <= i__1; ++i__) {
28376 	    im1 = i__ - 1;
28377 	    ic = iwork[inode + im1];
28378 	    nl = iwork[ndiml + im1];
28379 	    nr = iwork[ndimr + im1];
28380 	    nlf = ic - nl;
28381 	    nrf = ic + 1;
28382 	    if (i__ == ll) {
28383 		sqrei = *sqre;
28384 	    } else {
28385 		sqrei = 1;
28386 	    }
28387 	    vfi = vf + nlf - 1;
28388 	    vli = vl + nlf - 1;
28389 	    idxqi = idxq + nlf - 1;
28390 	    alpha = d__[ic];
28391 	    beta = e[ic];
28392 	    if (*icompq == 0) {
28393 		dlasd6_(icompq, &nl, &nr, &sqrei, &d__[nlf], &work[vfi], &
28394 			work[vli], &alpha, &beta, &iwork[idxqi], &perm[
28395 			perm_offset], &givptr[1], &givcol[givcol_offset],
28396 			ldgcol, &givnum[givnum_offset], ldu, &poles[
28397 			poles_offset], &difl[difl_offset], &difr[difr_offset],
28398 			 &z__[z_offset], &k[1], &c__[1], &s[1], &work[nwork1],
28399 			 &iwork[iwk], info);
28400 	    } else {
28401 		--j;
28402 		dlasd6_(icompq, &nl, &nr, &sqrei, &d__[nlf], &work[vfi], &
28403 			work[vli], &alpha, &beta, &iwork[idxqi], &perm[nlf +
28404 			lvl * perm_dim1], &givptr[j], &givcol[nlf + lvl2 *
28405 			givcol_dim1], ldgcol, &givnum[nlf + lvl2 *
28406 			givnum_dim1], ldu, &poles[nlf + lvl2 * poles_dim1], &
28407 			difl[nlf + lvl * difl_dim1], &difr[nlf + lvl2 *
28408 			difr_dim1], &z__[nlf + lvl * z_dim1], &k[j], &c__[j],
28409 			&s[j], &work[nwork1], &iwork[iwk], info);
28410 	    }
28411 	    if (*info != 0) {
28412 		return 0;
28413 	    }
28414 /* L40: */
28415 	}
28416 /* L50: */
28417     }
28418 
28419     return 0;
28420 
28421 /*     End of DLASDA */
28422 
28423 } /* dlasda_ */
28424 
dlasdq_(char * uplo,integer * sqre,integer * n,integer * ncvt,integer * nru,integer * ncc,doublereal * d__,doublereal * e,doublereal * vt,integer * ldvt,doublereal * u,integer * ldu,doublereal * c__,integer * ldc,doublereal * work,integer * info)28425 /* Subroutine */ int dlasdq_(char *uplo, integer *sqre, integer *n, integer *
28426 	ncvt, integer *nru, integer *ncc, doublereal *d__, doublereal *e,
28427 	doublereal *vt, integer *ldvt, doublereal *u, integer *ldu,
28428 	doublereal *c__, integer *ldc, doublereal *work, integer *info)
28429 {
28430     /* System generated locals */
28431     integer c_dim1, c_offset, u_dim1, u_offset, vt_dim1, vt_offset, i__1,
28432 	    i__2;
28433 
28434     /* Local variables */
28435     static integer i__, j;
28436     static doublereal r__, cs, sn;
28437     static integer np1, isub;
28438     static doublereal smin;
28439     static integer sqre1;
28440     extern logical lsame_(char *, char *);
28441     extern /* Subroutine */ int dlasr_(char *, char *, char *, integer *,
28442 	    integer *, doublereal *, doublereal *, doublereal *, integer *), dswap_(integer *, doublereal *, integer *
28443 	    , doublereal *, integer *);
28444     static integer iuplo;
28445     extern /* Subroutine */ int dlartg_(doublereal *, doublereal *,
28446 	    doublereal *, doublereal *, doublereal *), xerbla_(char *,
28447 	    integer *), dbdsqr_(char *, integer *, integer *, integer
28448 	    *, integer *, doublereal *, doublereal *, doublereal *, integer *,
28449 	     doublereal *, integer *, doublereal *, integer *, doublereal *,
28450 	    integer *);
28451     static logical rotate;
28452 
28453 
28454 /*
28455     -- LAPACK auxiliary routine (version 3.2) --
28456     -- LAPACK is a software package provided by Univ. of Tennessee,    --
28457     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
28458        November 2006
28459 
28460 
28461     Purpose
28462     =======
28463 
28464     DLASDQ computes the singular value decomposition (SVD) of a real
28465     (upper or lower) bidiagonal matrix with diagonal D and offdiagonal
28466     E, accumulating the transformations if desired. Letting B denote
28467     the input bidiagonal matrix, the algorithm computes orthogonal
28468     matrices Q and P such that B = Q * S * P' (P' denotes the transpose
28469     of P). The singular values S are overwritten on D.
28470 
28471     The input matrix U  is changed to U  * Q  if desired.
28472     The input matrix VT is changed to P' * VT if desired.
28473     The input matrix C  is changed to Q' * C  if desired.
28474 
28475     See "Computing  Small Singular Values of Bidiagonal Matrices With
28476     Guaranteed High Relative Accuracy," by J. Demmel and W. Kahan,
28477     LAPACK Working Note #3, for a detailed description of the algorithm.
28478 
28479     Arguments
28480     =========
28481 
28482     UPLO  (input) CHARACTER*1
28483           On entry, UPLO specifies whether the input bidiagonal matrix
28484           is upper or lower bidiagonal, and wether it is square are
28485           not.
28486              UPLO = 'U' or 'u'   B is upper bidiagonal.
28487              UPLO = 'L' or 'l'   B is lower bidiagonal.
28488 
28489     SQRE  (input) INTEGER
28490           = 0: then the input matrix is N-by-N.
28491           = 1: then the input matrix is N-by-(N+1) if UPLU = 'U' and
28492                (N+1)-by-N if UPLU = 'L'.
28493 
28494           The bidiagonal matrix has
28495           N = NL + NR + 1 rows and
28496           M = N + SQRE >= N columns.
28497 
28498     N     (input) INTEGER
28499           On entry, N specifies the number of rows and columns
28500           in the matrix. N must be at least 0.
28501 
28502     NCVT  (input) INTEGER
28503           On entry, NCVT specifies the number of columns of
28504           the matrix VT. NCVT must be at least 0.
28505 
28506     NRU   (input) INTEGER
28507           On entry, NRU specifies the number of rows of
28508           the matrix U. NRU must be at least 0.
28509 
28510     NCC   (input) INTEGER
28511           On entry, NCC specifies the number of columns of
28512           the matrix C. NCC must be at least 0.
28513 
28514     D     (input/output) DOUBLE PRECISION array, dimension (N)
28515           On entry, D contains the diagonal entries of the
28516           bidiagonal matrix whose SVD is desired. On normal exit,
28517           D contains the singular values in ascending order.
28518 
28519     E     (input/output) DOUBLE PRECISION array.
28520           dimension is (N-1) if SQRE = 0 and N if SQRE = 1.
28521           On entry, the entries of E contain the offdiagonal entries
28522           of the bidiagonal matrix whose SVD is desired. On normal
28523           exit, E will contain 0. If the algorithm does not converge,
28524           D and E will contain the diagonal and superdiagonal entries
28525           of a bidiagonal matrix orthogonally equivalent to the one
28526           given as input.
28527 
28528     VT    (input/output) DOUBLE PRECISION array, dimension (LDVT, NCVT)
28529           On entry, contains a matrix which on exit has been
28530           premultiplied by P', dimension N-by-NCVT if SQRE = 0
28531           and (N+1)-by-NCVT if SQRE = 1 (not referenced if NCVT=0).
28532 
28533     LDVT  (input) INTEGER
28534           On entry, LDVT specifies the leading dimension of VT as
28535           declared in the calling (sub) program. LDVT must be at
28536           least 1. If NCVT is nonzero LDVT must also be at least N.
28537 
28538     U     (input/output) DOUBLE PRECISION array, dimension (LDU, N)
28539           On entry, contains a  matrix which on exit has been
28540           postmultiplied by Q, dimension NRU-by-N if SQRE = 0
28541           and NRU-by-(N+1) if SQRE = 1 (not referenced if NRU=0).
28542 
28543     LDU   (input) INTEGER
28544           On entry, LDU  specifies the leading dimension of U as
28545           declared in the calling (sub) program. LDU must be at
28546           least max( 1, NRU ) .
28547 
28548     C     (input/output) DOUBLE PRECISION array, dimension (LDC, NCC)
28549           On entry, contains an N-by-NCC matrix which on exit
28550           has been premultiplied by Q'  dimension N-by-NCC if SQRE = 0
28551           and (N+1)-by-NCC if SQRE = 1 (not referenced if NCC=0).
28552 
28553     LDC   (input) INTEGER
28554           On entry, LDC  specifies the leading dimension of C as
28555           declared in the calling (sub) program. LDC must be at
28556           least 1. If NCC is nonzero, LDC must also be at least N.
28557 
28558     WORK  (workspace) DOUBLE PRECISION array, dimension (4*N)
28559           Workspace. Only referenced if one of NCVT, NRU, or NCC is
28560           nonzero, and if N is at least 2.
28561 
28562     INFO  (output) INTEGER
28563           On exit, a value of 0 indicates a successful exit.
28564           If INFO < 0, argument number -INFO is illegal.
28565           If INFO > 0, the algorithm did not converge, and INFO
28566           specifies how many superdiagonals did not converge.
28567 
28568     Further Details
28569     ===============
28570 
28571     Based on contributions by
28572        Ming Gu and Huan Ren, Computer Science Division, University of
28573        California at Berkeley, USA
28574 
28575     =====================================================================
28576 
28577 
28578        Test the input parameters.
28579 */
28580 
28581     /* Parameter adjustments */
28582     --d__;
28583     --e;
28584     vt_dim1 = *ldvt;
28585     vt_offset = 1 + vt_dim1;
28586     vt -= vt_offset;
28587     u_dim1 = *ldu;
28588     u_offset = 1 + u_dim1;
28589     u -= u_offset;
28590     c_dim1 = *ldc;
28591     c_offset = 1 + c_dim1;
28592     c__ -= c_offset;
28593     --work;
28594 
28595     /* Function Body */
28596     *info = 0;
28597     iuplo = 0;
28598     if (lsame_(uplo, "U")) {
28599 	iuplo = 1;
28600     }
28601     if (lsame_(uplo, "L")) {
28602 	iuplo = 2;
28603     }
28604     if (iuplo == 0) {
28605 	*info = -1;
28606     } else if (*sqre < 0 || *sqre > 1) {
28607 	*info = -2;
28608     } else if (*n < 0) {
28609 	*info = -3;
28610     } else if (*ncvt < 0) {
28611 	*info = -4;
28612     } else if (*nru < 0) {
28613 	*info = -5;
28614     } else if (*ncc < 0) {
28615 	*info = -6;
28616     } else if (*ncvt == 0 && *ldvt < 1 || *ncvt > 0 && *ldvt < max(1,*n)) {
28617 	*info = -10;
28618     } else if (*ldu < max(1,*nru)) {
28619 	*info = -12;
28620     } else if (*ncc == 0 && *ldc < 1 || *ncc > 0 && *ldc < max(1,*n)) {
28621 	*info = -14;
28622     }
28623     if (*info != 0) {
28624 	i__1 = -(*info);
28625 	xerbla_("DLASDQ", &i__1);
28626 	return 0;
28627     }
28628     if (*n == 0) {
28629 	return 0;
28630     }
28631 
28632 /*     ROTATE is true if any singular vectors desired, false otherwise */
28633 
28634     rotate = *ncvt > 0 || *nru > 0 || *ncc > 0;
28635     np1 = *n + 1;
28636     sqre1 = *sqre;
28637 
28638 /*
28639        If matrix non-square upper bidiagonal, rotate to be lower
28640        bidiagonal.  The rotations are on the right.
28641 */
28642 
28643     if (iuplo == 1 && sqre1 == 1) {
28644 	i__1 = *n - 1;
28645 	for (i__ = 1; i__ <= i__1; ++i__) {
28646 	    dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
28647 	    d__[i__] = r__;
28648 	    e[i__] = sn * d__[i__ + 1];
28649 	    d__[i__ + 1] = cs * d__[i__ + 1];
28650 	    if (rotate) {
28651 		work[i__] = cs;
28652 		work[*n + i__] = sn;
28653 	    }
28654 /* L10: */
28655 	}
28656 	dlartg_(&d__[*n], &e[*n], &cs, &sn, &r__);
28657 	d__[*n] = r__;
28658 	e[*n] = 0.;
28659 	if (rotate) {
28660 	    work[*n] = cs;
28661 	    work[*n + *n] = sn;
28662 	}
28663 	iuplo = 2;
28664 	sqre1 = 0;
28665 
28666 /*        Update singular vectors if desired. */
28667 
28668 	if (*ncvt > 0) {
28669 	    dlasr_("L", "V", "F", &np1, ncvt, &work[1], &work[np1], &vt[
28670 		    vt_offset], ldvt);
28671 	}
28672     }
28673 
28674 /*
28675        If matrix lower bidiagonal, rotate to be upper bidiagonal
28676        by applying Givens rotations on the left.
28677 */
28678 
28679     if (iuplo == 2) {
28680 	i__1 = *n - 1;
28681 	for (i__ = 1; i__ <= i__1; ++i__) {
28682 	    dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
28683 	    d__[i__] = r__;
28684 	    e[i__] = sn * d__[i__ + 1];
28685 	    d__[i__ + 1] = cs * d__[i__ + 1];
28686 	    if (rotate) {
28687 		work[i__] = cs;
28688 		work[*n + i__] = sn;
28689 	    }
28690 /* L20: */
28691 	}
28692 
28693 /*
28694           If matrix (N+1)-by-N lower bidiagonal, one additional
28695           rotation is needed.
28696 */
28697 
28698 	if (sqre1 == 1) {
28699 	    dlartg_(&d__[*n], &e[*n], &cs, &sn, &r__);
28700 	    d__[*n] = r__;
28701 	    if (rotate) {
28702 		work[*n] = cs;
28703 		work[*n + *n] = sn;
28704 	    }
28705 	}
28706 
28707 /*        Update singular vectors if desired. */
28708 
28709 	if (*nru > 0) {
28710 	    if (sqre1 == 0) {
28711 		dlasr_("R", "V", "F", nru, n, &work[1], &work[np1], &u[
28712 			u_offset], ldu);
28713 	    } else {
28714 		dlasr_("R", "V", "F", nru, &np1, &work[1], &work[np1], &u[
28715 			u_offset], ldu);
28716 	    }
28717 	}
28718 	if (*ncc > 0) {
28719 	    if (sqre1 == 0) {
28720 		dlasr_("L", "V", "F", n, ncc, &work[1], &work[np1], &c__[
28721 			c_offset], ldc);
28722 	    } else {
28723 		dlasr_("L", "V", "F", &np1, ncc, &work[1], &work[np1], &c__[
28724 			c_offset], ldc);
28725 	    }
28726 	}
28727     }
28728 
28729 /*
28730        Call DBDSQR to compute the SVD of the reduced real
28731        N-by-N upper bidiagonal matrix.
28732 */
28733 
28734     dbdsqr_("U", n, ncvt, nru, ncc, &d__[1], &e[1], &vt[vt_offset], ldvt, &u[
28735 	    u_offset], ldu, &c__[c_offset], ldc, &work[1], info);
28736 
28737 /*
28738        Sort the singular values into ascending order (insertion sort on
28739        singular values, but only one transposition per singular vector)
28740 */
28741 
28742     i__1 = *n;
28743     for (i__ = 1; i__ <= i__1; ++i__) {
28744 
28745 /*        Scan for smallest D(I). */
28746 
28747 	isub = i__;
28748 	smin = d__[i__];
28749 	i__2 = *n;
28750 	for (j = i__ + 1; j <= i__2; ++j) {
28751 	    if (d__[j] < smin) {
28752 		isub = j;
28753 		smin = d__[j];
28754 	    }
28755 /* L30: */
28756 	}
28757 	if (isub != i__) {
28758 
28759 /*           Swap singular values and vectors. */
28760 
28761 	    d__[isub] = d__[i__];
28762 	    d__[i__] = smin;
28763 	    if (*ncvt > 0) {
28764 		dswap_(ncvt, &vt[isub + vt_dim1], ldvt, &vt[i__ + vt_dim1],
28765 			ldvt);
28766 	    }
28767 	    if (*nru > 0) {
28768 		dswap_(nru, &u[isub * u_dim1 + 1], &c__1, &u[i__ * u_dim1 + 1]
28769 			, &c__1);
28770 	    }
28771 	    if (*ncc > 0) {
28772 		dswap_(ncc, &c__[isub + c_dim1], ldc, &c__[i__ + c_dim1], ldc)
28773 			;
28774 	    }
28775 	}
28776 /* L40: */
28777     }
28778 
28779     return 0;
28780 
28781 /*     End of DLASDQ */
28782 
28783 } /* dlasdq_ */
28784 
dlasdt_(integer * n,integer * lvl,integer * nd,integer * inode,integer * ndiml,integer * ndimr,integer * msub)28785 /* Subroutine */ int dlasdt_(integer *n, integer *lvl, integer *nd, integer *
28786 	inode, integer *ndiml, integer *ndimr, integer *msub)
28787 {
28788     /* System generated locals */
28789     integer i__1, i__2;
28790 
28791     /* Local variables */
28792     static integer i__, il, ir, maxn;
28793     static doublereal temp;
28794     static integer nlvl, llst, ncrnt;
28795 
28796 
28797 /*
28798     -- LAPACK auxiliary routine (version 3.2.2) --
28799     -- LAPACK is a software package provided by Univ. of Tennessee,    --
28800     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
28801        June 2010
28802 
28803 
28804     Purpose
28805     =======
28806 
28807     DLASDT creates a tree of subproblems for bidiagonal divide and
28808     conquer.
28809 
28810     Arguments
28811     =========
28812 
28813      N      (input) INTEGER
28814             On entry, the number of diagonal elements of the
28815             bidiagonal matrix.
28816 
28817      LVL    (output) INTEGER
28818             On exit, the number of levels on the computation tree.
28819 
28820      ND     (output) INTEGER
28821             On exit, the number of nodes on the tree.
28822 
28823      INODE  (output) INTEGER array, dimension ( N )
28824             On exit, centers of subproblems.
28825 
28826      NDIML  (output) INTEGER array, dimension ( N )
28827             On exit, row dimensions of left children.
28828 
28829      NDIMR  (output) INTEGER array, dimension ( N )
28830             On exit, row dimensions of right children.
28831 
28832      MSUB   (input) INTEGER
28833             On entry, the maximum row dimension each subproblem at the
28834             bottom of the tree can be of.
28835 
28836     Further Details
28837     ===============
28838 
28839     Based on contributions by
28840        Ming Gu and Huan Ren, Computer Science Division, University of
28841        California at Berkeley, USA
28842 
28843     =====================================================================
28844 
28845 
28846        Find the number of levels on the tree.
28847 */
28848 
28849     /* Parameter adjustments */
28850     --ndimr;
28851     --ndiml;
28852     --inode;
28853 
28854     /* Function Body */
28855     maxn = max(1,*n);
28856     temp = log((doublereal) maxn / (doublereal) (*msub + 1)) / log(2.);
28857     *lvl = (integer) temp + 1;
28858 
28859     i__ = *n / 2;
28860     inode[1] = i__ + 1;
28861     ndiml[1] = i__;
28862     ndimr[1] = *n - i__ - 1;
28863     il = 0;
28864     ir = 1;
28865     llst = 1;
28866     i__1 = *lvl - 1;
28867     for (nlvl = 1; nlvl <= i__1; ++nlvl) {
28868 
28869 /*
28870           Constructing the tree at (NLVL+1)-st level. The number of
28871           nodes created on this level is LLST * 2.
28872 */
28873 
28874 	i__2 = llst - 1;
28875 	for (i__ = 0; i__ <= i__2; ++i__) {
28876 	    il += 2;
28877 	    ir += 2;
28878 	    ncrnt = llst + i__;
28879 	    ndiml[il] = ndiml[ncrnt] / 2;
28880 	    ndimr[il] = ndiml[ncrnt] - ndiml[il] - 1;
28881 	    inode[il] = inode[ncrnt] - ndimr[il] - 1;
28882 	    ndiml[ir] = ndimr[ncrnt] / 2;
28883 	    ndimr[ir] = ndimr[ncrnt] - ndiml[ir] - 1;
28884 	    inode[ir] = inode[ncrnt] + ndiml[ir] + 1;
28885 /* L10: */
28886 	}
28887 	llst <<= 1;
28888 /* L20: */
28889     }
28890     *nd = (llst << 1) - 1;
28891 
28892     return 0;
28893 
28894 /*     End of DLASDT */
28895 
28896 } /* dlasdt_ */
28897 
dlaset_(char * uplo,integer * m,integer * n,doublereal * alpha,doublereal * beta,doublereal * a,integer * lda)28898 /* Subroutine */ int dlaset_(char *uplo, integer *m, integer *n, doublereal *
28899 	alpha, doublereal *beta, doublereal *a, integer *lda)
28900 {
28901     /* System generated locals */
28902     integer a_dim1, a_offset, i__1, i__2, i__3;
28903 
28904     /* Local variables */
28905     static integer i__, j;
28906     extern logical lsame_(char *, char *);
28907 
28908 
28909 /*
28910     -- LAPACK auxiliary routine (version 3.2) --
28911     -- LAPACK is a software package provided by Univ. of Tennessee,    --
28912     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
28913        November 2006
28914 
28915 
28916     Purpose
28917     =======
28918 
28919     DLASET initializes an m-by-n matrix A to BETA on the diagonal and
28920     ALPHA on the offdiagonals.
28921 
28922     Arguments
28923     =========
28924 
28925     UPLO    (input) CHARACTER*1
28926             Specifies the part of the matrix A to be set.
28927             = 'U':      Upper triangular part is set; the strictly lower
28928                         triangular part of A is not changed.
28929             = 'L':      Lower triangular part is set; the strictly upper
28930                         triangular part of A is not changed.
28931             Otherwise:  All of the matrix A is set.
28932 
28933     M       (input) INTEGER
28934             The number of rows of the matrix A.  M >= 0.
28935 
28936     N       (input) INTEGER
28937             The number of columns of the matrix A.  N >= 0.
28938 
28939     ALPHA   (input) DOUBLE PRECISION
28940             The constant to which the offdiagonal elements are to be set.
28941 
28942     BETA    (input) DOUBLE PRECISION
28943             The constant to which the diagonal elements are to be set.
28944 
28945     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
28946             On exit, the leading m-by-n submatrix of A is set as follows:
28947 
28948             if UPLO = 'U', A(i,j) = ALPHA, 1<=i<=j-1, 1<=j<=n,
28949             if UPLO = 'L', A(i,j) = ALPHA, j+1<=i<=m, 1<=j<=n,
28950             otherwise,     A(i,j) = ALPHA, 1<=i<=m, 1<=j<=n, i.ne.j,
28951 
28952             and, for all UPLO, A(i,i) = BETA, 1<=i<=min(m,n).
28953 
28954     LDA     (input) INTEGER
28955             The leading dimension of the array A.  LDA >= max(1,M).
28956 
28957    =====================================================================
28958 */
28959 
28960 
28961     /* Parameter adjustments */
28962     a_dim1 = *lda;
28963     a_offset = 1 + a_dim1;
28964     a -= a_offset;
28965 
28966     /* Function Body */
28967     if (lsame_(uplo, "U")) {
28968 
28969 /*
28970           Set the strictly upper triangular or trapezoidal part of the
28971           array to ALPHA.
28972 */
28973 
28974 	i__1 = *n;
28975 	for (j = 2; j <= i__1; ++j) {
28976 /* Computing MIN */
28977 	    i__3 = j - 1;
28978 	    i__2 = min(i__3,*m);
28979 	    for (i__ = 1; i__ <= i__2; ++i__) {
28980 		a[i__ + j * a_dim1] = *alpha;
28981 /* L10: */
28982 	    }
28983 /* L20: */
28984 	}
28985 
28986     } else if (lsame_(uplo, "L")) {
28987 
28988 /*
28989           Set the strictly lower triangular or trapezoidal part of the
28990           array to ALPHA.
28991 */
28992 
28993 	i__1 = min(*m,*n);
28994 	for (j = 1; j <= i__1; ++j) {
28995 	    i__2 = *m;
28996 	    for (i__ = j + 1; i__ <= i__2; ++i__) {
28997 		a[i__ + j * a_dim1] = *alpha;
28998 /* L30: */
28999 	    }
29000 /* L40: */
29001 	}
29002 
29003     } else {
29004 
29005 /*        Set the leading m-by-n submatrix to ALPHA. */
29006 
29007 	i__1 = *n;
29008 	for (j = 1; j <= i__1; ++j) {
29009 	    i__2 = *m;
29010 	    for (i__ = 1; i__ <= i__2; ++i__) {
29011 		a[i__ + j * a_dim1] = *alpha;
29012 /* L50: */
29013 	    }
29014 /* L60: */
29015 	}
29016     }
29017 
29018 /*     Set the first min(M,N) diagonal elements to BETA. */
29019 
29020     i__1 = min(*m,*n);
29021     for (i__ = 1; i__ <= i__1; ++i__) {
29022 	a[i__ + i__ * a_dim1] = *beta;
29023 /* L70: */
29024     }
29025 
29026     return 0;
29027 
29028 /*     End of DLASET */
29029 
29030 } /* dlaset_ */
29031 
dlasq1_(integer * n,doublereal * d__,doublereal * e,doublereal * work,integer * info)29032 /* Subroutine */ int dlasq1_(integer *n, doublereal *d__, doublereal *e,
29033 	doublereal *work, integer *info)
29034 {
29035     /* System generated locals */
29036     integer i__1, i__2;
29037     doublereal d__1, d__2, d__3;
29038 
29039     /* Local variables */
29040     static integer i__;
29041     static doublereal eps;
29042     extern /* Subroutine */ int dlas2_(doublereal *, doublereal *, doublereal
29043 	    *, doublereal *, doublereal *);
29044     static doublereal scale;
29045     static integer iinfo;
29046     static doublereal sigmn;
29047     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
29048 	    doublereal *, integer *);
29049     static doublereal sigmx;
29050     extern /* Subroutine */ int dlasq2_(integer *, doublereal *, integer *);
29051 
29052     extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
29053 	    doublereal *, doublereal *, integer *, integer *, doublereal *,
29054 	    integer *, integer *);
29055     static doublereal safmin;
29056     extern /* Subroutine */ int xerbla_(char *, integer *), dlasrt_(
29057 	    char *, integer *, doublereal *, integer *);
29058 
29059 
29060 /*
29061     -- LAPACK routine (version 3.2)                                    --
29062 
29063     -- Contributed by Osni Marques of the Lawrence Berkeley National   --
29064     -- Laboratory and Beresford Parlett of the Univ. of California at  --
29065     -- Berkeley                                                        --
29066     -- November 2008                                                   --
29067 
29068     -- LAPACK is a software package provided by Univ. of Tennessee,    --
29069     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
29070 
29071 
29072     Purpose
29073     =======
29074 
29075     DLASQ1 computes the singular values of a real N-by-N bidiagonal
29076     matrix with diagonal D and off-diagonal E. The singular values
29077     are computed to high relative accuracy, in the absence of
29078     denormalization, underflow and overflow. The algorithm was first
29079     presented in
29080 
29081     "Accurate singular values and differential qd algorithms" by K. V.
29082     Fernando and B. N. Parlett, Numer. Math., Vol-67, No. 2, pp. 191-230,
29083     1994,
29084 
29085     and the present implementation is described in "An implementation of
29086     the dqds Algorithm (Positive Case)", LAPACK Working Note.
29087 
29088     Arguments
29089     =========
29090 
29091     N     (input) INTEGER
29092           The number of rows and columns in the matrix. N >= 0.
29093 
29094     D     (input/output) DOUBLE PRECISION array, dimension (N)
29095           On entry, D contains the diagonal elements of the
29096           bidiagonal matrix whose SVD is desired. On normal exit,
29097           D contains the singular values in decreasing order.
29098 
29099     E     (input/output) DOUBLE PRECISION array, dimension (N)
29100           On entry, elements E(1:N-1) contain the off-diagonal elements
29101           of the bidiagonal matrix whose SVD is desired.
29102           On exit, E is overwritten.
29103 
29104     WORK  (workspace) DOUBLE PRECISION array, dimension (4*N)
29105 
29106     INFO  (output) INTEGER
29107           = 0: successful exit
29108           < 0: if INFO = -i, the i-th argument had an illegal value
29109           > 0: the algorithm failed
29110                = 1, a split was marked by a positive value in E
29111                = 2, current block of Z not diagonalized after 30*N
29112                     iterations (in inner while loop)
29113                = 3, termination criterion of outer while loop not met
29114                     (program created more than N unreduced blocks)
29115 
29116     =====================================================================
29117 */
29118 
29119 
29120     /* Parameter adjustments */
29121     --work;
29122     --e;
29123     --d__;
29124 
29125     /* Function Body */
29126     *info = 0;
29127     if (*n < 0) {
29128 	*info = -2;
29129 	i__1 = -(*info);
29130 	xerbla_("DLASQ1", &i__1);
29131 	return 0;
29132     } else if (*n == 0) {
29133 	return 0;
29134     } else if (*n == 1) {
29135 	d__[1] = abs(d__[1]);
29136 	return 0;
29137     } else if (*n == 2) {
29138 	dlas2_(&d__[1], &e[1], &d__[2], &sigmn, &sigmx);
29139 	d__[1] = sigmx;
29140 	d__[2] = sigmn;
29141 	return 0;
29142     }
29143 
29144 /*     Estimate the largest singular value. */
29145 
29146     sigmx = 0.;
29147     i__1 = *n - 1;
29148     for (i__ = 1; i__ <= i__1; ++i__) {
29149 	d__[i__] = (d__1 = d__[i__], abs(d__1));
29150 /* Computing MAX */
29151 	d__2 = sigmx, d__3 = (d__1 = e[i__], abs(d__1));
29152 	sigmx = max(d__2,d__3);
29153 /* L10: */
29154     }
29155     d__[*n] = (d__1 = d__[*n], abs(d__1));
29156 
29157 /*     Early return if SIGMX is zero (matrix is already diagonal). */
29158 
29159     if (sigmx == 0.) {
29160 	dlasrt_("D", n, &d__[1], &iinfo);
29161 	return 0;
29162     }
29163 
29164     i__1 = *n;
29165     for (i__ = 1; i__ <= i__1; ++i__) {
29166 /* Computing MAX */
29167 	d__1 = sigmx, d__2 = d__[i__];
29168 	sigmx = max(d__1,d__2);
29169 /* L20: */
29170     }
29171 
29172 /*
29173        Copy D and E into WORK (in the Z format) and scale (squaring the
29174        input data makes scaling by a power of the radix pointless).
29175 */
29176 
29177     eps = PRECISION;
29178     safmin = SAFEMINIMUM;
29179     scale = sqrt(eps / safmin);
29180     dcopy_(n, &d__[1], &c__1, &work[1], &c__2);
29181     i__1 = *n - 1;
29182     dcopy_(&i__1, &e[1], &c__1, &work[2], &c__2);
29183     i__1 = (*n << 1) - 1;
29184     i__2 = (*n << 1) - 1;
29185     dlascl_("G", &c__0, &c__0, &sigmx, &scale, &i__1, &c__1, &work[1], &i__2,
29186 	    &iinfo);
29187 
29188 /*     Compute the q's and e's. */
29189 
29190     i__1 = (*n << 1) - 1;
29191     for (i__ = 1; i__ <= i__1; ++i__) {
29192 /* Computing 2nd power */
29193 	d__1 = work[i__];
29194 	work[i__] = d__1 * d__1;
29195 /* L30: */
29196     }
29197     work[*n * 2] = 0.;
29198 
29199     dlasq2_(n, &work[1], info);
29200 
29201     if (*info == 0) {
29202 	i__1 = *n;
29203 	for (i__ = 1; i__ <= i__1; ++i__) {
29204 	    d__[i__] = sqrt(work[i__]);
29205 /* L40: */
29206 	}
29207 	dlascl_("G", &c__0, &c__0, &scale, &sigmx, n, &c__1, &d__[1], n, &
29208 		iinfo);
29209     }
29210 
29211     return 0;
29212 
29213 /*     End of DLASQ1 */
29214 
29215 } /* dlasq1_ */
29216 
dlasq2_(integer * n,doublereal * z__,integer * info)29217 /* Subroutine */ int dlasq2_(integer *n, doublereal *z__, integer *info)
29218 {
29219     /* System generated locals */
29220     integer i__1, i__2, i__3;
29221     doublereal d__1, d__2;
29222 
29223     /* Local variables */
29224     static doublereal d__, e, g;
29225     static integer k;
29226     static doublereal s, t;
29227     static integer i0, i4, n0;
29228     static doublereal dn;
29229     static integer pp;
29230     static doublereal dn1, dn2, dee, eps, tau, tol;
29231     static integer ipn4;
29232     static doublereal tol2;
29233     static logical ieee;
29234     static integer nbig;
29235     static doublereal dmin__, emin, emax;
29236     static integer kmin, ndiv, iter;
29237     static doublereal qmin, temp, qmax, zmax;
29238     static integer splt;
29239     static doublereal dmin1, dmin2;
29240     static integer nfail;
29241     static doublereal desig, trace, sigma;
29242     static integer iinfo, ttype;
29243     extern /* Subroutine */ int dlasq3_(integer *, integer *, doublereal *,
29244 	    integer *, doublereal *, doublereal *, doublereal *, doublereal *,
29245 	     integer *, integer *, integer *, logical *, integer *,
29246 	    doublereal *, doublereal *, doublereal *, doublereal *,
29247 	    doublereal *, doublereal *, doublereal *);
29248 
29249     static doublereal deemin;
29250     static integer iwhila, iwhilb;
29251     static doublereal oldemn, safmin;
29252     extern /* Subroutine */ int xerbla_(char *, integer *);
29253     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
29254 	    integer *, integer *, ftnlen, ftnlen);
29255     extern /* Subroutine */ int dlasrt_(char *, integer *, doublereal *,
29256 	    integer *);
29257 
29258 
29259 /*
29260     -- LAPACK routine (version 3.2)                                    --
29261 
29262     -- Contributed by Osni Marques of the Lawrence Berkeley National   --
29263     -- Laboratory and Beresford Parlett of the Univ. of California at  --
29264     -- Berkeley                                                        --
29265     -- November 2008                                                   --
29266 
29267     -- LAPACK is a software package provided by Univ. of Tennessee,    --
29268     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
29269 
29270 
29271     Purpose
29272     =======
29273 
29274     DLASQ2 computes all the eigenvalues of the symmetric positive
29275     definite tridiagonal matrix associated with the qd array Z to high
29276     relative accuracy are computed to high relative accuracy, in the
29277     absence of denormalization, underflow and overflow.
29278 
29279     To see the relation of Z to the tridiagonal matrix, let L be a
29280     unit lower bidiagonal matrix with subdiagonals Z(2,4,6,,..) and
29281     let U be an upper bidiagonal matrix with 1's above and diagonal
29282     Z(1,3,5,,..). The tridiagonal is L*U or, if you prefer, the
29283     symmetric tridiagonal to which it is similar.
29284 
29285     Note : DLASQ2 defines a logical variable, IEEE, which is true
29286     on machines which follow ieee-754 floating-point standard in their
29287     handling of infinities and NaNs, and false otherwise. This variable
29288     is passed to DLASQ3.
29289 
29290     Arguments
29291     =========
29292 
29293     N     (input) INTEGER
29294           The number of rows and columns in the matrix. N >= 0.
29295 
29296     Z     (input/output) DOUBLE PRECISION array, dimension ( 4*N )
29297           On entry Z holds the qd array. On exit, entries 1 to N hold
29298           the eigenvalues in decreasing order, Z( 2*N+1 ) holds the
29299           trace, and Z( 2*N+2 ) holds the sum of the eigenvalues. If
29300           N > 2, then Z( 2*N+3 ) holds the iteration count, Z( 2*N+4 )
29301           holds NDIVS/NIN^2, and Z( 2*N+5 ) holds the percentage of
29302           shifts that failed.
29303 
29304     INFO  (output) INTEGER
29305           = 0: successful exit
29306           < 0: if the i-th argument is a scalar and had an illegal
29307                value, then INFO = -i, if the i-th argument is an
29308                array and the j-entry had an illegal value, then
29309                INFO = -(i*100+j)
29310           > 0: the algorithm failed
29311                 = 1, a split was marked by a positive value in E
29312                 = 2, current block of Z not diagonalized after 30*N
29313                      iterations (in inner while loop)
29314                 = 3, termination criterion of outer while loop not met
29315                      (program created more than N unreduced blocks)
29316 
29317     Further Details
29318     ===============
29319     Local Variables: I0:N0 defines a current unreduced segment of Z.
29320     The shifts are accumulated in SIGMA. Iteration count is in ITER.
29321     Ping-pong is controlled by PP (alternates between 0 and 1).
29322 
29323     =====================================================================
29324 
29325 
29326        Test the input arguments.
29327        (in case DLASQ2 is not called by DLASQ1)
29328 */
29329 
29330     /* Parameter adjustments */
29331     --z__;
29332 
29333     /* Function Body */
29334     *info = 0;
29335     eps = PRECISION;
29336     safmin = SAFEMINIMUM;
29337     tol = eps * 100.;
29338 /* Computing 2nd power */
29339     d__1 = tol;
29340     tol2 = d__1 * d__1;
29341 
29342     if (*n < 0) {
29343 	*info = -1;
29344 	xerbla_("DLASQ2", &c__1);
29345 	return 0;
29346     } else if (*n == 0) {
29347 	return 0;
29348     } else if (*n == 1) {
29349 
29350 /*        1-by-1 case. */
29351 
29352 	if (z__[1] < 0.) {
29353 	    *info = -201;
29354 	    xerbla_("DLASQ2", &c__2);
29355 	}
29356 	return 0;
29357     } else if (*n == 2) {
29358 
29359 /*        2-by-2 case. */
29360 
29361 	if (z__[2] < 0. || z__[3] < 0.) {
29362 	    *info = -2;
29363 	    xerbla_("DLASQ2", &c__2);
29364 	    return 0;
29365 	} else if (z__[3] > z__[1]) {
29366 	    d__ = z__[3];
29367 	    z__[3] = z__[1];
29368 	    z__[1] = d__;
29369 	}
29370 	z__[5] = z__[1] + z__[2] + z__[3];
29371 	if (z__[2] > z__[3] * tol2) {
29372 	    t = (z__[1] - z__[3] + z__[2]) * .5;
29373 	    s = z__[3] * (z__[2] / t);
29374 	    if (s <= t) {
29375 		s = z__[3] * (z__[2] / (t * (sqrt(s / t + 1.) + 1.)));
29376 	    } else {
29377 		s = z__[3] * (z__[2] / (t + sqrt(t) * sqrt(t + s)));
29378 	    }
29379 	    t = z__[1] + (s + z__[2]);
29380 	    z__[3] *= z__[1] / t;
29381 	    z__[1] = t;
29382 	}
29383 	z__[2] = z__[3];
29384 	z__[6] = z__[2] + z__[1];
29385 	return 0;
29386     }
29387 
29388 /*     Check for negative data and compute sums of q's and e's. */
29389 
29390     z__[*n * 2] = 0.;
29391     emin = z__[2];
29392     qmax = 0.;
29393     zmax = 0.;
29394     d__ = 0.;
29395     e = 0.;
29396 
29397     i__1 = *n - 1 << 1;
29398     for (k = 1; k <= i__1; k += 2) {
29399 	if (z__[k] < 0.) {
29400 	    *info = -(k + 200);
29401 	    xerbla_("DLASQ2", &c__2);
29402 	    return 0;
29403 	} else if (z__[k + 1] < 0.) {
29404 	    *info = -(k + 201);
29405 	    xerbla_("DLASQ2", &c__2);
29406 	    return 0;
29407 	}
29408 	d__ += z__[k];
29409 	e += z__[k + 1];
29410 /* Computing MAX */
29411 	d__1 = qmax, d__2 = z__[k];
29412 	qmax = max(d__1,d__2);
29413 /* Computing MIN */
29414 	d__1 = emin, d__2 = z__[k + 1];
29415 	emin = min(d__1,d__2);
29416 /* Computing MAX */
29417 	d__1 = max(qmax,zmax), d__2 = z__[k + 1];
29418 	zmax = max(d__1,d__2);
29419 /* L10: */
29420     }
29421     if (z__[(*n << 1) - 1] < 0.) {
29422 	*info = -((*n << 1) + 199);
29423 	xerbla_("DLASQ2", &c__2);
29424 	return 0;
29425     }
29426     d__ += z__[(*n << 1) - 1];
29427 /* Computing MAX */
29428     d__1 = qmax, d__2 = z__[(*n << 1) - 1];
29429     qmax = max(d__1,d__2);
29430     zmax = max(qmax,zmax);
29431 
29432 /*     Check for diagonality. */
29433 
29434     if (e == 0.) {
29435 	i__1 = *n;
29436 	for (k = 2; k <= i__1; ++k) {
29437 	    z__[k] = z__[(k << 1) - 1];
29438 /* L20: */
29439 	}
29440 	dlasrt_("D", n, &z__[1], &iinfo);
29441 	z__[(*n << 1) - 1] = d__;
29442 	return 0;
29443     }
29444 
29445     trace = d__ + e;
29446 
29447 /*     Check for zero data. */
29448 
29449     if (trace == 0.) {
29450 	z__[(*n << 1) - 1] = 0.;
29451 	return 0;
29452     }
29453 
29454 /*     Check whether the machine is IEEE conformable. */
29455 
29456     ieee = ilaenv_(&c__10, "DLASQ2", "N", &c__1, &c__2, &c__3, &c__4, (ftnlen)
29457 	    6, (ftnlen)1) == 1 && ilaenv_(&c__11, "DLASQ2", "N", &c__1, &c__2,
29458 	     &c__3, &c__4, (ftnlen)6, (ftnlen)1) == 1;
29459 
29460 /*     Rearrange data for locality: Z=(q1,qq1,e1,ee1,q2,qq2,e2,ee2,...). */
29461 
29462     for (k = *n << 1; k >= 2; k += -2) {
29463 	z__[k * 2] = 0.;
29464 	z__[(k << 1) - 1] = z__[k];
29465 	z__[(k << 1) - 2] = 0.;
29466 	z__[(k << 1) - 3] = z__[k - 1];
29467 /* L30: */
29468     }
29469 
29470     i0 = 1;
29471     n0 = *n;
29472 
29473 /*     Reverse the qd-array, if warranted. */
29474 
29475     if (z__[(i0 << 2) - 3] * 1.5 < z__[(n0 << 2) - 3]) {
29476 	ipn4 = i0 + n0 << 2;
29477 	i__1 = i0 + n0 - 1 << 1;
29478 	for (i4 = i0 << 2; i4 <= i__1; i4 += 4) {
29479 	    temp = z__[i4 - 3];
29480 	    z__[i4 - 3] = z__[ipn4 - i4 - 3];
29481 	    z__[ipn4 - i4 - 3] = temp;
29482 	    temp = z__[i4 - 1];
29483 	    z__[i4 - 1] = z__[ipn4 - i4 - 5];
29484 	    z__[ipn4 - i4 - 5] = temp;
29485 /* L40: */
29486 	}
29487     }
29488 
29489 /*     Initial split checking via dqd and Li's test. */
29490 
29491     pp = 0;
29492 
29493     for (k = 1; k <= 2; ++k) {
29494 
29495 	d__ = z__[(n0 << 2) + pp - 3];
29496 	i__1 = (i0 << 2) + pp;
29497 	for (i4 = (n0 - 1 << 2) + pp; i4 >= i__1; i4 += -4) {
29498 	    if (z__[i4 - 1] <= tol2 * d__) {
29499 		z__[i4 - 1] = -0.;
29500 		d__ = z__[i4 - 3];
29501 	    } else {
29502 		d__ = z__[i4 - 3] * (d__ / (d__ + z__[i4 - 1]));
29503 	    }
29504 /* L50: */
29505 	}
29506 
29507 /*        dqd maps Z to ZZ plus Li's test. */
29508 
29509 	emin = z__[(i0 << 2) + pp + 1];
29510 	d__ = z__[(i0 << 2) + pp - 3];
29511 	i__1 = (n0 - 1 << 2) + pp;
29512 	for (i4 = (i0 << 2) + pp; i4 <= i__1; i4 += 4) {
29513 	    z__[i4 - (pp << 1) - 2] = d__ + z__[i4 - 1];
29514 	    if (z__[i4 - 1] <= tol2 * d__) {
29515 		z__[i4 - 1] = -0.;
29516 		z__[i4 - (pp << 1) - 2] = d__;
29517 		z__[i4 - (pp << 1)] = 0.;
29518 		d__ = z__[i4 + 1];
29519 	    } else if (safmin * z__[i4 + 1] < z__[i4 - (pp << 1) - 2] &&
29520 		    safmin * z__[i4 - (pp << 1) - 2] < z__[i4 + 1]) {
29521 		temp = z__[i4 + 1] / z__[i4 - (pp << 1) - 2];
29522 		z__[i4 - (pp << 1)] = z__[i4 - 1] * temp;
29523 		d__ *= temp;
29524 	    } else {
29525 		z__[i4 - (pp << 1)] = z__[i4 + 1] * (z__[i4 - 1] / z__[i4 - (
29526 			pp << 1) - 2]);
29527 		d__ = z__[i4 + 1] * (d__ / z__[i4 - (pp << 1) - 2]);
29528 	    }
29529 /* Computing MIN */
29530 	    d__1 = emin, d__2 = z__[i4 - (pp << 1)];
29531 	    emin = min(d__1,d__2);
29532 /* L60: */
29533 	}
29534 	z__[(n0 << 2) - pp - 2] = d__;
29535 
29536 /*        Now find qmax. */
29537 
29538 	qmax = z__[(i0 << 2) - pp - 2];
29539 	i__1 = (n0 << 2) - pp - 2;
29540 	for (i4 = (i0 << 2) - pp + 2; i4 <= i__1; i4 += 4) {
29541 /* Computing MAX */
29542 	    d__1 = qmax, d__2 = z__[i4];
29543 	    qmax = max(d__1,d__2);
29544 /* L70: */
29545 	}
29546 
29547 /*        Prepare for the next iteration on K. */
29548 
29549 	pp = 1 - pp;
29550 /* L80: */
29551     }
29552 
29553 /*     Initialise variables to pass to DLASQ3. */
29554 
29555     ttype = 0;
29556     dmin1 = 0.;
29557     dmin2 = 0.;
29558     dn = 0.;
29559     dn1 = 0.;
29560     dn2 = 0.;
29561     g = 0.;
29562     tau = 0.;
29563 
29564     iter = 2;
29565     nfail = 0;
29566     ndiv = n0 - i0 << 1;
29567 
29568     i__1 = *n + 1;
29569     for (iwhila = 1; iwhila <= i__1; ++iwhila) {
29570 	if (n0 < 1) {
29571 	    goto L170;
29572 	}
29573 
29574 /*
29575           While array unfinished do
29576 
29577           E(N0) holds the value of SIGMA when submatrix in I0:N0
29578           splits from the rest of the array, but is negated.
29579 */
29580 
29581 	desig = 0.;
29582 	if (n0 == *n) {
29583 	    sigma = 0.;
29584 	} else {
29585 	    sigma = -z__[(n0 << 2) - 1];
29586 	}
29587 	if (sigma < 0.) {
29588 	    *info = 1;
29589 	    return 0;
29590 	}
29591 
29592 /*
29593           Find last unreduced submatrix's top index I0, find QMAX and
29594           EMIN. Find Gershgorin-type bound if Q's much greater than E's.
29595 */
29596 
29597 	emax = 0.;
29598 	if (n0 > i0) {
29599 	    emin = (d__1 = z__[(n0 << 2) - 5], abs(d__1));
29600 	} else {
29601 	    emin = 0.;
29602 	}
29603 	qmin = z__[(n0 << 2) - 3];
29604 	qmax = qmin;
29605 	for (i4 = n0 << 2; i4 >= 8; i4 += -4) {
29606 	    if (z__[i4 - 5] <= 0.) {
29607 		goto L100;
29608 	    }
29609 	    if (qmin >= emax * 4.) {
29610 /* Computing MIN */
29611 		d__1 = qmin, d__2 = z__[i4 - 3];
29612 		qmin = min(d__1,d__2);
29613 /* Computing MAX */
29614 		d__1 = emax, d__2 = z__[i4 - 5];
29615 		emax = max(d__1,d__2);
29616 	    }
29617 /* Computing MAX */
29618 	    d__1 = qmax, d__2 = z__[i4 - 7] + z__[i4 - 5];
29619 	    qmax = max(d__1,d__2);
29620 /* Computing MIN */
29621 	    d__1 = emin, d__2 = z__[i4 - 5];
29622 	    emin = min(d__1,d__2);
29623 /* L90: */
29624 	}
29625 	i4 = 4;
29626 
29627 L100:
29628 	i0 = i4 / 4;
29629 	pp = 0;
29630 
29631 	if (n0 - i0 > 1) {
29632 	    dee = z__[(i0 << 2) - 3];
29633 	    deemin = dee;
29634 	    kmin = i0;
29635 	    i__2 = (n0 << 2) - 3;
29636 	    for (i4 = (i0 << 2) + 1; i4 <= i__2; i4 += 4) {
29637 		dee = z__[i4] * (dee / (dee + z__[i4 - 2]));
29638 		if (dee <= deemin) {
29639 		    deemin = dee;
29640 		    kmin = (i4 + 3) / 4;
29641 		}
29642 /* L110: */
29643 	    }
29644 	    if (kmin - i0 << 1 < n0 - kmin && deemin <= z__[(n0 << 2) - 3] *
29645 		    .5) {
29646 		ipn4 = i0 + n0 << 2;
29647 		pp = 2;
29648 		i__2 = i0 + n0 - 1 << 1;
29649 		for (i4 = i0 << 2; i4 <= i__2; i4 += 4) {
29650 		    temp = z__[i4 - 3];
29651 		    z__[i4 - 3] = z__[ipn4 - i4 - 3];
29652 		    z__[ipn4 - i4 - 3] = temp;
29653 		    temp = z__[i4 - 2];
29654 		    z__[i4 - 2] = z__[ipn4 - i4 - 2];
29655 		    z__[ipn4 - i4 - 2] = temp;
29656 		    temp = z__[i4 - 1];
29657 		    z__[i4 - 1] = z__[ipn4 - i4 - 5];
29658 		    z__[ipn4 - i4 - 5] = temp;
29659 		    temp = z__[i4];
29660 		    z__[i4] = z__[ipn4 - i4 - 4];
29661 		    z__[ipn4 - i4 - 4] = temp;
29662 /* L120: */
29663 		}
29664 	    }
29665 	}
29666 
29667 /*
29668           Put -(initial shift) into DMIN.
29669 
29670    Computing MAX
29671 */
29672 	d__1 = 0., d__2 = qmin - sqrt(qmin) * 2. * sqrt(emax);
29673 	dmin__ = -max(d__1,d__2);
29674 
29675 /*
29676           Now I0:N0 is unreduced.
29677           PP = 0 for ping, PP = 1 for pong.
29678           PP = 2 indicates that flipping was applied to the Z array and
29679                  and that the tests for deflation upon entry in DLASQ3
29680                  should not be performed.
29681 */
29682 
29683 	nbig = (n0 - i0 + 1) * 30;
29684 	i__2 = nbig;
29685 	for (iwhilb = 1; iwhilb <= i__2; ++iwhilb) {
29686 	    if (i0 > n0) {
29687 		goto L150;
29688 	    }
29689 
29690 /*           While submatrix unfinished take a good dqds step. */
29691 
29692 	    dlasq3_(&i0, &n0, &z__[1], &pp, &dmin__, &sigma, &desig, &qmax, &
29693 		    nfail, &iter, &ndiv, &ieee, &ttype, &dmin1, &dmin2, &dn, &
29694 		    dn1, &dn2, &g, &tau);
29695 
29696 	    pp = 1 - pp;
29697 
29698 /*           When EMIN is very small check for splits. */
29699 
29700 	    if (pp == 0 && n0 - i0 >= 3) {
29701 		if (z__[n0 * 4] <= tol2 * qmax || z__[(n0 << 2) - 1] <= tol2 *
29702 			 sigma) {
29703 		    splt = i0 - 1;
29704 		    qmax = z__[(i0 << 2) - 3];
29705 		    emin = z__[(i0 << 2) - 1];
29706 		    oldemn = z__[i0 * 4];
29707 		    i__3 = n0 - 3 << 2;
29708 		    for (i4 = i0 << 2; i4 <= i__3; i4 += 4) {
29709 			if (z__[i4] <= tol2 * z__[i4 - 3] || z__[i4 - 1] <=
29710 				tol2 * sigma) {
29711 			    z__[i4 - 1] = -sigma;
29712 			    splt = i4 / 4;
29713 			    qmax = 0.;
29714 			    emin = z__[i4 + 3];
29715 			    oldemn = z__[i4 + 4];
29716 			} else {
29717 /* Computing MAX */
29718 			    d__1 = qmax, d__2 = z__[i4 + 1];
29719 			    qmax = max(d__1,d__2);
29720 /* Computing MIN */
29721 			    d__1 = emin, d__2 = z__[i4 - 1];
29722 			    emin = min(d__1,d__2);
29723 /* Computing MIN */
29724 			    d__1 = oldemn, d__2 = z__[i4];
29725 			    oldemn = min(d__1,d__2);
29726 			}
29727 /* L130: */
29728 		    }
29729 		    z__[(n0 << 2) - 1] = emin;
29730 		    z__[n0 * 4] = oldemn;
29731 		    i0 = splt + 1;
29732 		}
29733 	    }
29734 
29735 /* L140: */
29736 	}
29737 
29738 	*info = 2;
29739 	return 0;
29740 
29741 /*        end IWHILB */
29742 
29743 L150:
29744 
29745 /* L160: */
29746 	;
29747     }
29748 
29749     *info = 3;
29750     return 0;
29751 
29752 /*     end IWHILA */
29753 
29754 L170:
29755 
29756 /*     Move q's to the front. */
29757 
29758     i__1 = *n;
29759     for (k = 2; k <= i__1; ++k) {
29760 	z__[k] = z__[(k << 2) - 3];
29761 /* L180: */
29762     }
29763 
29764 /*     Sort and compute sum of eigenvalues. */
29765 
29766     dlasrt_("D", n, &z__[1], &iinfo);
29767 
29768     e = 0.;
29769     for (k = *n; k >= 1; --k) {
29770 	e += z__[k];
29771 /* L190: */
29772     }
29773 
29774 /*     Store trace, sum(eigenvalues) and information on performance. */
29775 
29776     z__[(*n << 1) + 1] = trace;
29777     z__[(*n << 1) + 2] = e;
29778     z__[(*n << 1) + 3] = (doublereal) iter;
29779 /* Computing 2nd power */
29780     i__1 = *n;
29781     z__[(*n << 1) + 4] = (doublereal) ndiv / (doublereal) (i__1 * i__1);
29782     z__[(*n << 1) + 5] = nfail * 100. / (doublereal) iter;
29783     return 0;
29784 
29785 /*     End of DLASQ2 */
29786 
29787 } /* dlasq2_ */
29788 
dlasq3_(integer * i0,integer * n0,doublereal * z__,integer * pp,doublereal * dmin__,doublereal * sigma,doublereal * desig,doublereal * qmax,integer * nfail,integer * iter,integer * ndiv,logical * ieee,integer * ttype,doublereal * dmin1,doublereal * dmin2,doublereal * dn,doublereal * dn1,doublereal * dn2,doublereal * g,doublereal * tau)29789 /* Subroutine */ int dlasq3_(integer *i0, integer *n0, doublereal *z__,
29790 	integer *pp, doublereal *dmin__, doublereal *sigma, doublereal *desig,
29791 	 doublereal *qmax, integer *nfail, integer *iter, integer *ndiv,
29792 	logical *ieee, integer *ttype, doublereal *dmin1, doublereal *dmin2,
29793 	doublereal *dn, doublereal *dn1, doublereal *dn2, doublereal *g,
29794 	doublereal *tau)
29795 {
29796     /* System generated locals */
29797     integer i__1;
29798     doublereal d__1, d__2;
29799 
29800     /* Local variables */
29801     static doublereal s, t;
29802     static integer j4, nn;
29803     static doublereal eps, tol;
29804     static integer n0in, ipn4;
29805     static doublereal tol2, temp;
29806     extern /* Subroutine */ int dlasq4_(integer *, integer *, doublereal *,
29807 	    integer *, integer *, doublereal *, doublereal *, doublereal *,
29808 	    doublereal *, doublereal *, doublereal *, doublereal *, integer *,
29809 	     doublereal *), dlasq5_(integer *, integer *, doublereal *,
29810 	    integer *, doublereal *, doublereal *, doublereal *, doublereal *,
29811 	     doublereal *, doublereal *, doublereal *, logical *), dlasq6_(
29812 	    integer *, integer *, doublereal *, integer *, doublereal *,
29813 	    doublereal *, doublereal *, doublereal *, doublereal *,
29814 	    doublereal *);
29815 
29816     extern logical disnan_(doublereal *);
29817 
29818 
29819 /*
29820     -- LAPACK routine (version 3.2.2)                                    --
29821 
29822     -- Contributed by Osni Marques of the Lawrence Berkeley National   --
29823     -- Laboratory and Beresford Parlett of the Univ. of California at  --
29824     -- Berkeley                                                        --
29825     -- June 2010                                                       --
29826 
29827     -- LAPACK is a software package provided by Univ. of Tennessee,    --
29828     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
29829 
29830 
29831     Purpose
29832     =======
29833 
29834     DLASQ3 checks for deflation, computes a shift (TAU) and calls dqds.
29835     In case of failure it changes shifts, and tries again until output
29836     is positive.
29837 
29838     Arguments
29839     =========
29840 
29841     I0     (input) INTEGER
29842            First index.
29843 
29844     N0     (input/output) INTEGER
29845            Last index.
29846 
29847     Z      (input) DOUBLE PRECISION array, dimension ( 4*N )
29848            Z holds the qd array.
29849 
29850     PP     (input/output) INTEGER
29851            PP=0 for ping, PP=1 for pong.
29852            PP=2 indicates that flipping was applied to the Z array
29853            and that the initial tests for deflation should not be
29854            performed.
29855 
29856     DMIN   (output) DOUBLE PRECISION
29857            Minimum value of d.
29858 
29859     SIGMA  (output) DOUBLE PRECISION
29860            Sum of shifts used in current segment.
29861 
29862     DESIG  (input/output) DOUBLE PRECISION
29863            Lower order part of SIGMA
29864 
29865     QMAX   (input) DOUBLE PRECISION
29866            Maximum value of q.
29867 
29868     NFAIL  (output) INTEGER
29869            Number of times shift was too big.
29870 
29871     ITER   (output) INTEGER
29872            Number of iterations.
29873 
29874     NDIV   (output) INTEGER
29875            Number of divisions.
29876 
29877     IEEE   (input) LOGICAL
29878            Flag for IEEE or non IEEE arithmetic (passed to DLASQ5).
29879 
29880     TTYPE  (input/output) INTEGER
29881            Shift type.
29882 
29883     DMIN1  (input/output) DOUBLE PRECISION
29884 
29885     DMIN2  (input/output) DOUBLE PRECISION
29886 
29887     DN     (input/output) DOUBLE PRECISION
29888 
29889     DN1    (input/output) DOUBLE PRECISION
29890 
29891     DN2    (input/output) DOUBLE PRECISION
29892 
29893     G      (input/output) DOUBLE PRECISION
29894 
29895     TAU    (input/output) DOUBLE PRECISION
29896 
29897            These are passed as arguments in order to save their values
29898            between calls to DLASQ3.
29899 
29900     =====================================================================
29901 */
29902 
29903 
29904     /* Parameter adjustments */
29905     --z__;
29906 
29907     /* Function Body */
29908     n0in = *n0;
29909     eps = PRECISION;
29910     tol = eps * 100.;
29911 /* Computing 2nd power */
29912     d__1 = tol;
29913     tol2 = d__1 * d__1;
29914 
29915 /*     Check for deflation. */
29916 
29917 L10:
29918 
29919     if (*n0 < *i0) {
29920 	return 0;
29921     }
29922     if (*n0 == *i0) {
29923 	goto L20;
29924     }
29925     nn = (*n0 << 2) + *pp;
29926     if (*n0 == *i0 + 1) {
29927 	goto L40;
29928     }
29929 
29930 /*     Check whether E(N0-1) is negligible, 1 eigenvalue. */
29931 
29932     if (z__[nn - 5] > tol2 * (*sigma + z__[nn - 3]) && z__[nn - (*pp << 1) -
29933 	    4] > tol2 * z__[nn - 7]) {
29934 	goto L30;
29935     }
29936 
29937 L20:
29938 
29939     z__[(*n0 << 2) - 3] = z__[(*n0 << 2) + *pp - 3] + *sigma;
29940     --(*n0);
29941     goto L10;
29942 
29943 /*     Check  whether E(N0-2) is negligible, 2 eigenvalues. */
29944 
29945 L30:
29946 
29947     if (z__[nn - 9] > tol2 * *sigma && z__[nn - (*pp << 1) - 8] > tol2 * z__[
29948 	    nn - 11]) {
29949 	goto L50;
29950     }
29951 
29952 L40:
29953 
29954     if (z__[nn - 3] > z__[nn - 7]) {
29955 	s = z__[nn - 3];
29956 	z__[nn - 3] = z__[nn - 7];
29957 	z__[nn - 7] = s;
29958     }
29959     if (z__[nn - 5] > z__[nn - 3] * tol2) {
29960 	t = (z__[nn - 7] - z__[nn - 3] + z__[nn - 5]) * .5;
29961 	s = z__[nn - 3] * (z__[nn - 5] / t);
29962 	if (s <= t) {
29963 	    s = z__[nn - 3] * (z__[nn - 5] / (t * (sqrt(s / t + 1.) + 1.)));
29964 	} else {
29965 	    s = z__[nn - 3] * (z__[nn - 5] / (t + sqrt(t) * sqrt(t + s)));
29966 	}
29967 	t = z__[nn - 7] + (s + z__[nn - 5]);
29968 	z__[nn - 3] *= z__[nn - 7] / t;
29969 	z__[nn - 7] = t;
29970     }
29971     z__[(*n0 << 2) - 7] = z__[nn - 7] + *sigma;
29972     z__[(*n0 << 2) - 3] = z__[nn - 3] + *sigma;
29973     *n0 += -2;
29974     goto L10;
29975 
29976 L50:
29977     if (*pp == 2) {
29978 	*pp = 0;
29979     }
29980 
29981 /*     Reverse the qd-array, if warranted. */
29982 
29983     if (*dmin__ <= 0. || *n0 < n0in) {
29984 	if (z__[(*i0 << 2) + *pp - 3] * 1.5 < z__[(*n0 << 2) + *pp - 3]) {
29985 	    ipn4 = *i0 + *n0 << 2;
29986 	    i__1 = *i0 + *n0 - 1 << 1;
29987 	    for (j4 = *i0 << 2; j4 <= i__1; j4 += 4) {
29988 		temp = z__[j4 - 3];
29989 		z__[j4 - 3] = z__[ipn4 - j4 - 3];
29990 		z__[ipn4 - j4 - 3] = temp;
29991 		temp = z__[j4 - 2];
29992 		z__[j4 - 2] = z__[ipn4 - j4 - 2];
29993 		z__[ipn4 - j4 - 2] = temp;
29994 		temp = z__[j4 - 1];
29995 		z__[j4 - 1] = z__[ipn4 - j4 - 5];
29996 		z__[ipn4 - j4 - 5] = temp;
29997 		temp = z__[j4];
29998 		z__[j4] = z__[ipn4 - j4 - 4];
29999 		z__[ipn4 - j4 - 4] = temp;
30000 /* L60: */
30001 	    }
30002 	    if (*n0 - *i0 <= 4) {
30003 		z__[(*n0 << 2) + *pp - 1] = z__[(*i0 << 2) + *pp - 1];
30004 		z__[(*n0 << 2) - *pp] = z__[(*i0 << 2) - *pp];
30005 	    }
30006 /* Computing MIN */
30007 	    d__1 = *dmin2, d__2 = z__[(*n0 << 2) + *pp - 1];
30008 	    *dmin2 = min(d__1,d__2);
30009 /* Computing MIN */
30010 	    d__1 = z__[(*n0 << 2) + *pp - 1], d__2 = z__[(*i0 << 2) + *pp - 1]
30011 		    , d__1 = min(d__1,d__2), d__2 = z__[(*i0 << 2) + *pp + 3];
30012 	    z__[(*n0 << 2) + *pp - 1] = min(d__1,d__2);
30013 /* Computing MIN */
30014 	    d__1 = z__[(*n0 << 2) - *pp], d__2 = z__[(*i0 << 2) - *pp], d__1 =
30015 		     min(d__1,d__2), d__2 = z__[(*i0 << 2) - *pp + 4];
30016 	    z__[(*n0 << 2) - *pp] = min(d__1,d__2);
30017 /* Computing MAX */
30018 	    d__1 = *qmax, d__2 = z__[(*i0 << 2) + *pp - 3], d__1 = max(d__1,
30019 		    d__2), d__2 = z__[(*i0 << 2) + *pp + 1];
30020 	    *qmax = max(d__1,d__2);
30021 	    *dmin__ = -0.;
30022 	}
30023     }
30024 
30025 /*     Choose a shift. */
30026 
30027     dlasq4_(i0, n0, &z__[1], pp, &n0in, dmin__, dmin1, dmin2, dn, dn1, dn2,
30028 	    tau, ttype, g);
30029 
30030 /*     Call dqds until DMIN > 0. */
30031 
30032 L70:
30033 
30034     dlasq5_(i0, n0, &z__[1], pp, tau, dmin__, dmin1, dmin2, dn, dn1, dn2,
30035 	    ieee);
30036 
30037     *ndiv += *n0 - *i0 + 2;
30038     ++(*iter);
30039 
30040 /*     Check status. */
30041 
30042     if (*dmin__ >= 0. && *dmin1 > 0.) {
30043 
30044 /*        Success. */
30045 
30046 	goto L90;
30047 
30048     } else if (*dmin__ < 0. && *dmin1 > 0. && z__[(*n0 - 1 << 2) - *pp] < tol
30049 	    * (*sigma + *dn1) && abs(*dn) < tol * *sigma) {
30050 
30051 /*        Convergence hidden by negative DN. */
30052 
30053 	z__[(*n0 - 1 << 2) - *pp + 2] = 0.;
30054 	*dmin__ = 0.;
30055 	goto L90;
30056     } else if (*dmin__ < 0.) {
30057 
30058 /*        TAU too big. Select new TAU and try again. */
30059 
30060 	++(*nfail);
30061 	if (*ttype < -22) {
30062 
30063 /*           Failed twice. Play it safe. */
30064 
30065 	    *tau = 0.;
30066 	} else if (*dmin1 > 0.) {
30067 
30068 /*           Late failure. Gives excellent shift. */
30069 
30070 	    *tau = (*tau + *dmin__) * (1. - eps * 2.);
30071 	    *ttype += -11;
30072 	} else {
30073 
30074 /*           Early failure. Divide by 4. */
30075 
30076 	    *tau *= .25;
30077 	    *ttype += -12;
30078 	}
30079 	goto L70;
30080     } else if (disnan_(dmin__)) {
30081 
30082 /*        NaN. */
30083 
30084 	if (*tau == 0.) {
30085 	    goto L80;
30086 	} else {
30087 	    *tau = 0.;
30088 	    goto L70;
30089 	}
30090     } else {
30091 
30092 /*        Possible underflow. Play it safe. */
30093 
30094 	goto L80;
30095     }
30096 
30097 /*     Risk of underflow. */
30098 
30099 L80:
30100     dlasq6_(i0, n0, &z__[1], pp, dmin__, dmin1, dmin2, dn, dn1, dn2);
30101     *ndiv += *n0 - *i0 + 2;
30102     ++(*iter);
30103     *tau = 0.;
30104 
30105 L90:
30106     if (*tau < *sigma) {
30107 	*desig += *tau;
30108 	t = *sigma + *desig;
30109 	*desig -= t - *sigma;
30110     } else {
30111 	t = *sigma + *tau;
30112 	*desig = *sigma - (t - *tau) + *desig;
30113     }
30114     *sigma = t;
30115 
30116     return 0;
30117 
30118 /*     End of DLASQ3 */
30119 
30120 } /* dlasq3_ */
30121 
dlasq4_(integer * i0,integer * n0,doublereal * z__,integer * pp,integer * n0in,doublereal * dmin__,doublereal * dmin1,doublereal * dmin2,doublereal * dn,doublereal * dn1,doublereal * dn2,doublereal * tau,integer * ttype,doublereal * g)30122 /* Subroutine */ int dlasq4_(integer *i0, integer *n0, doublereal *z__,
30123 	integer *pp, integer *n0in, doublereal *dmin__, doublereal *dmin1,
30124 	doublereal *dmin2, doublereal *dn, doublereal *dn1, doublereal *dn2,
30125 	doublereal *tau, integer *ttype, doublereal *g)
30126 {
30127     /* System generated locals */
30128     integer i__1;
30129     doublereal d__1, d__2;
30130 
30131     /* Local variables */
30132     static doublereal s, a2, b1, b2;
30133     static integer i4, nn, np;
30134     static doublereal gam, gap1, gap2;
30135 
30136 
30137 /*
30138     -- LAPACK routine (version 3.2)                                    --
30139 
30140     -- Contributed by Osni Marques of the Lawrence Berkeley National   --
30141     -- Laboratory and Beresford Parlett of the Univ. of California at  --
30142     -- Berkeley                                                        --
30143     -- November 2008                                                   --
30144 
30145     -- LAPACK is a software package provided by Univ. of Tennessee,    --
30146     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
30147 
30148 
30149     Purpose
30150     =======
30151 
30152     DLASQ4 computes an approximation TAU to the smallest eigenvalue
30153     using values of d from the previous transform.
30154 
30155     I0    (input) INTEGER
30156           First index.
30157 
30158     N0    (input) INTEGER
30159           Last index.
30160 
30161     Z     (input) DOUBLE PRECISION array, dimension ( 4*N )
30162           Z holds the qd array.
30163 
30164     PP    (input) INTEGER
30165           PP=0 for ping, PP=1 for pong.
30166 
30167     NOIN  (input) INTEGER
30168           The value of N0 at start of EIGTEST.
30169 
30170     DMIN  (input) DOUBLE PRECISION
30171           Minimum value of d.
30172 
30173     DMIN1 (input) DOUBLE PRECISION
30174           Minimum value of d, excluding D( N0 ).
30175 
30176     DMIN2 (input) DOUBLE PRECISION
30177           Minimum value of d, excluding D( N0 ) and D( N0-1 ).
30178 
30179     DN    (input) DOUBLE PRECISION
30180           d(N)
30181 
30182     DN1   (input) DOUBLE PRECISION
30183           d(N-1)
30184 
30185     DN2   (input) DOUBLE PRECISION
30186           d(N-2)
30187 
30188     TAU   (output) DOUBLE PRECISION
30189           This is the shift.
30190 
30191     TTYPE (output) INTEGER
30192           Shift type.
30193 
30194     G     (input/output) REAL
30195           G is passed as an argument in order to save its value between
30196           calls to DLASQ4.
30197 
30198     Further Details
30199     ===============
30200     CNST1 = 9/16
30201 
30202     =====================================================================
30203 
30204 
30205        A negative DMIN forces the shift to take that absolute value
30206        TTYPE records the type of shift.
30207 */
30208 
30209     /* Parameter adjustments */
30210     --z__;
30211 
30212     /* Function Body */
30213     if (*dmin__ <= 0.) {
30214 	*tau = -(*dmin__);
30215 	*ttype = -1;
30216 	return 0;
30217     }
30218 
30219     nn = (*n0 << 2) + *pp;
30220     if (*n0in == *n0) {
30221 
30222 /*        No eigenvalues deflated. */
30223 
30224 	if (*dmin__ == *dn || *dmin__ == *dn1) {
30225 
30226 	    b1 = sqrt(z__[nn - 3]) * sqrt(z__[nn - 5]);
30227 	    b2 = sqrt(z__[nn - 7]) * sqrt(z__[nn - 9]);
30228 	    a2 = z__[nn - 7] + z__[nn - 5];
30229 
30230 /*           Cases 2 and 3. */
30231 
30232 	    if (*dmin__ == *dn && *dmin1 == *dn1) {
30233 		gap2 = *dmin2 - a2 - *dmin2 * .25;
30234 		if (gap2 > 0. && gap2 > b2) {
30235 		    gap1 = a2 - *dn - b2 / gap2 * b2;
30236 		} else {
30237 		    gap1 = a2 - *dn - (b1 + b2);
30238 		}
30239 		if (gap1 > 0. && gap1 > b1) {
30240 /* Computing MAX */
30241 		    d__1 = *dn - b1 / gap1 * b1, d__2 = *dmin__ * .5;
30242 		    s = max(d__1,d__2);
30243 		    *ttype = -2;
30244 		} else {
30245 		    s = 0.;
30246 		    if (*dn > b1) {
30247 			s = *dn - b1;
30248 		    }
30249 		    if (a2 > b1 + b2) {
30250 /* Computing MIN */
30251 			d__1 = s, d__2 = a2 - (b1 + b2);
30252 			s = min(d__1,d__2);
30253 		    }
30254 /* Computing MAX */
30255 		    d__1 = s, d__2 = *dmin__ * .333;
30256 		    s = max(d__1,d__2);
30257 		    *ttype = -3;
30258 		}
30259 	    } else {
30260 
30261 /*              Case 4. */
30262 
30263 		*ttype = -4;
30264 		s = *dmin__ * .25;
30265 		if (*dmin__ == *dn) {
30266 		    gam = *dn;
30267 		    a2 = 0.;
30268 		    if (z__[nn - 5] > z__[nn - 7]) {
30269 			return 0;
30270 		    }
30271 		    b2 = z__[nn - 5] / z__[nn - 7];
30272 		    np = nn - 9;
30273 		} else {
30274 		    np = nn - (*pp << 1);
30275 		    b2 = z__[np - 2];
30276 		    gam = *dn1;
30277 		    if (z__[np - 4] > z__[np - 2]) {
30278 			return 0;
30279 		    }
30280 		    a2 = z__[np - 4] / z__[np - 2];
30281 		    if (z__[nn - 9] > z__[nn - 11]) {
30282 			return 0;
30283 		    }
30284 		    b2 = z__[nn - 9] / z__[nn - 11];
30285 		    np = nn - 13;
30286 		}
30287 
30288 /*              Approximate contribution to norm squared from I < NN-1. */
30289 
30290 		a2 += b2;
30291 		i__1 = (*i0 << 2) - 1 + *pp;
30292 		for (i4 = np; i4 >= i__1; i4 += -4) {
30293 		    if (b2 == 0.) {
30294 			goto L20;
30295 		    }
30296 		    b1 = b2;
30297 		    if (z__[i4] > z__[i4 - 2]) {
30298 			return 0;
30299 		    }
30300 		    b2 *= z__[i4] / z__[i4 - 2];
30301 		    a2 += b2;
30302 		    if (max(b2,b1) * 100. < a2 || .563 < a2) {
30303 			goto L20;
30304 		    }
30305 /* L10: */
30306 		}
30307 L20:
30308 		a2 *= 1.05;
30309 
30310 /*              Rayleigh quotient residual bound. */
30311 
30312 		if (a2 < .563) {
30313 		    s = gam * (1. - sqrt(a2)) / (a2 + 1.);
30314 		}
30315 	    }
30316 	} else if (*dmin__ == *dn2) {
30317 
30318 /*           Case 5. */
30319 
30320 	    *ttype = -5;
30321 	    s = *dmin__ * .25;
30322 
30323 /*           Compute contribution to norm squared from I > NN-2. */
30324 
30325 	    np = nn - (*pp << 1);
30326 	    b1 = z__[np - 2];
30327 	    b2 = z__[np - 6];
30328 	    gam = *dn2;
30329 	    if (z__[np - 8] > b2 || z__[np - 4] > b1) {
30330 		return 0;
30331 	    }
30332 	    a2 = z__[np - 8] / b2 * (z__[np - 4] / b1 + 1.);
30333 
30334 /*           Approximate contribution to norm squared from I < NN-2. */
30335 
30336 	    if (*n0 - *i0 > 2) {
30337 		b2 = z__[nn - 13] / z__[nn - 15];
30338 		a2 += b2;
30339 		i__1 = (*i0 << 2) - 1 + *pp;
30340 		for (i4 = nn - 17; i4 >= i__1; i4 += -4) {
30341 		    if (b2 == 0.) {
30342 			goto L40;
30343 		    }
30344 		    b1 = b2;
30345 		    if (z__[i4] > z__[i4 - 2]) {
30346 			return 0;
30347 		    }
30348 		    b2 *= z__[i4] / z__[i4 - 2];
30349 		    a2 += b2;
30350 		    if (max(b2,b1) * 100. < a2 || .563 < a2) {
30351 			goto L40;
30352 		    }
30353 /* L30: */
30354 		}
30355 L40:
30356 		a2 *= 1.05;
30357 	    }
30358 
30359 	    if (a2 < .563) {
30360 		s = gam * (1. - sqrt(a2)) / (a2 + 1.);
30361 	    }
30362 	} else {
30363 
30364 /*           Case 6, no information to guide us. */
30365 
30366 	    if (*ttype == -6) {
30367 		*g += (1. - *g) * .333;
30368 	    } else if (*ttype == -18) {
30369 		*g = .083250000000000005;
30370 	    } else {
30371 		*g = .25;
30372 	    }
30373 	    s = *g * *dmin__;
30374 	    *ttype = -6;
30375 	}
30376 
30377     } else if (*n0in == *n0 + 1) {
30378 
30379 /*        One eigenvalue just deflated. Use DMIN1, DN1 for DMIN and DN. */
30380 
30381 	if (*dmin1 == *dn1 && *dmin2 == *dn2) {
30382 
30383 /*           Cases 7 and 8. */
30384 
30385 	    *ttype = -7;
30386 	    s = *dmin1 * .333;
30387 	    if (z__[nn - 5] > z__[nn - 7]) {
30388 		return 0;
30389 	    }
30390 	    b1 = z__[nn - 5] / z__[nn - 7];
30391 	    b2 = b1;
30392 	    if (b2 == 0.) {
30393 		goto L60;
30394 	    }
30395 	    i__1 = (*i0 << 2) - 1 + *pp;
30396 	    for (i4 = (*n0 << 2) - 9 + *pp; i4 >= i__1; i4 += -4) {
30397 		a2 = b1;
30398 		if (z__[i4] > z__[i4 - 2]) {
30399 		    return 0;
30400 		}
30401 		b1 *= z__[i4] / z__[i4 - 2];
30402 		b2 += b1;
30403 		if (max(b1,a2) * 100. < b2) {
30404 		    goto L60;
30405 		}
30406 /* L50: */
30407 	    }
30408 L60:
30409 	    b2 = sqrt(b2 * 1.05);
30410 /* Computing 2nd power */
30411 	    d__1 = b2;
30412 	    a2 = *dmin1 / (d__1 * d__1 + 1.);
30413 	    gap2 = *dmin2 * .5 - a2;
30414 	    if (gap2 > 0. && gap2 > b2 * a2) {
30415 /* Computing MAX */
30416 		d__1 = s, d__2 = a2 * (1. - a2 * 1.01 * (b2 / gap2) * b2);
30417 		s = max(d__1,d__2);
30418 	    } else {
30419 /* Computing MAX */
30420 		d__1 = s, d__2 = a2 * (1. - b2 * 1.01);
30421 		s = max(d__1,d__2);
30422 		*ttype = -8;
30423 	    }
30424 	} else {
30425 
30426 /*           Case 9. */
30427 
30428 	    s = *dmin1 * .25;
30429 	    if (*dmin1 == *dn1) {
30430 		s = *dmin1 * .5;
30431 	    }
30432 	    *ttype = -9;
30433 	}
30434 
30435     } else if (*n0in == *n0 + 2) {
30436 
30437 /*
30438           Two eigenvalues deflated. Use DMIN2, DN2 for DMIN and DN.
30439 
30440           Cases 10 and 11.
30441 */
30442 
30443 	if (*dmin2 == *dn2 && z__[nn - 5] * 2. < z__[nn - 7]) {
30444 	    *ttype = -10;
30445 	    s = *dmin2 * .333;
30446 	    if (z__[nn - 5] > z__[nn - 7]) {
30447 		return 0;
30448 	    }
30449 	    b1 = z__[nn - 5] / z__[nn - 7];
30450 	    b2 = b1;
30451 	    if (b2 == 0.) {
30452 		goto L80;
30453 	    }
30454 	    i__1 = (*i0 << 2) - 1 + *pp;
30455 	    for (i4 = (*n0 << 2) - 9 + *pp; i4 >= i__1; i4 += -4) {
30456 		if (z__[i4] > z__[i4 - 2]) {
30457 		    return 0;
30458 		}
30459 		b1 *= z__[i4] / z__[i4 - 2];
30460 		b2 += b1;
30461 		if (b1 * 100. < b2) {
30462 		    goto L80;
30463 		}
30464 /* L70: */
30465 	    }
30466 L80:
30467 	    b2 = sqrt(b2 * 1.05);
30468 /* Computing 2nd power */
30469 	    d__1 = b2;
30470 	    a2 = *dmin2 / (d__1 * d__1 + 1.);
30471 	    gap2 = z__[nn - 7] + z__[nn - 9] - sqrt(z__[nn - 11]) * sqrt(z__[
30472 		    nn - 9]) - a2;
30473 	    if (gap2 > 0. && gap2 > b2 * a2) {
30474 /* Computing MAX */
30475 		d__1 = s, d__2 = a2 * (1. - a2 * 1.01 * (b2 / gap2) * b2);
30476 		s = max(d__1,d__2);
30477 	    } else {
30478 /* Computing MAX */
30479 		d__1 = s, d__2 = a2 * (1. - b2 * 1.01);
30480 		s = max(d__1,d__2);
30481 	    }
30482 	} else {
30483 	    s = *dmin2 * .25;
30484 	    *ttype = -11;
30485 	}
30486     } else if (*n0in > *n0 + 2) {
30487 
30488 /*        Case 12, more than two eigenvalues deflated. No information. */
30489 
30490 	s = 0.;
30491 	*ttype = -12;
30492     }
30493 
30494     *tau = s;
30495     return 0;
30496 
30497 /*     End of DLASQ4 */
30498 
30499 } /* dlasq4_ */
30500 
dlasq5_(integer * i0,integer * n0,doublereal * z__,integer * pp,doublereal * tau,doublereal * dmin__,doublereal * dmin1,doublereal * dmin2,doublereal * dn,doublereal * dnm1,doublereal * dnm2,logical * ieee)30501 /* Subroutine */ int dlasq5_(integer *i0, integer *n0, doublereal *z__,
30502 	integer *pp, doublereal *tau, doublereal *dmin__, doublereal *dmin1,
30503 	doublereal *dmin2, doublereal *dn, doublereal *dnm1, doublereal *dnm2,
30504 	 logical *ieee)
30505 {
30506     /* System generated locals */
30507     integer i__1;
30508     doublereal d__1, d__2;
30509 
30510     /* Local variables */
30511     static doublereal d__;
30512     static integer j4, j4p2;
30513     static doublereal emin, temp;
30514 
30515 
30516 /*
30517     -- LAPACK routine (version 3.2)                                    --
30518 
30519     -- Contributed by Osni Marques of the Lawrence Berkeley National   --
30520     -- Laboratory and Beresford Parlett of the Univ. of California at  --
30521     -- Berkeley                                                        --
30522     -- November 2008                                                   --
30523 
30524     -- LAPACK is a software package provided by Univ. of Tennessee,    --
30525     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
30526 
30527 
30528     Purpose
30529     =======
30530 
30531     DLASQ5 computes one dqds transform in ping-pong form, one
30532     version for IEEE machines another for non IEEE machines.
30533 
30534     Arguments
30535     =========
30536 
30537     I0    (input) INTEGER
30538           First index.
30539 
30540     N0    (input) INTEGER
30541           Last index.
30542 
30543     Z     (input) DOUBLE PRECISION array, dimension ( 4*N )
30544           Z holds the qd array. EMIN is stored in Z(4*N0) to avoid
30545           an extra argument.
30546 
30547     PP    (input) INTEGER
30548           PP=0 for ping, PP=1 for pong.
30549 
30550     TAU   (input) DOUBLE PRECISION
30551           This is the shift.
30552 
30553     DMIN  (output) DOUBLE PRECISION
30554           Minimum value of d.
30555 
30556     DMIN1 (output) DOUBLE PRECISION
30557           Minimum value of d, excluding D( N0 ).
30558 
30559     DMIN2 (output) DOUBLE PRECISION
30560           Minimum value of d, excluding D( N0 ) and D( N0-1 ).
30561 
30562     DN    (output) DOUBLE PRECISION
30563           d(N0), the last value of d.
30564 
30565     DNM1  (output) DOUBLE PRECISION
30566           d(N0-1).
30567 
30568     DNM2  (output) DOUBLE PRECISION
30569           d(N0-2).
30570 
30571     IEEE  (input) LOGICAL
30572           Flag for IEEE or non IEEE arithmetic.
30573 
30574     =====================================================================
30575 */
30576 
30577 
30578     /* Parameter adjustments */
30579     --z__;
30580 
30581     /* Function Body */
30582     if (*n0 - *i0 - 1 <= 0) {
30583 	return 0;
30584     }
30585 
30586     j4 = (*i0 << 2) + *pp - 3;
30587     emin = z__[j4 + 4];
30588     d__ = z__[j4] - *tau;
30589     *dmin__ = d__;
30590     *dmin1 = -z__[j4];
30591 
30592     if (*ieee) {
30593 
30594 /*        Code for IEEE arithmetic. */
30595 
30596 	if (*pp == 0) {
30597 	    i__1 = *n0 - 3 << 2;
30598 	    for (j4 = *i0 << 2; j4 <= i__1; j4 += 4) {
30599 		z__[j4 - 2] = d__ + z__[j4 - 1];
30600 		temp = z__[j4 + 1] / z__[j4 - 2];
30601 		d__ = d__ * temp - *tau;
30602 		*dmin__ = min(*dmin__,d__);
30603 		z__[j4] = z__[j4 - 1] * temp;
30604 /* Computing MIN */
30605 		d__1 = z__[j4];
30606 		emin = min(d__1,emin);
30607 /* L10: */
30608 	    }
30609 	} else {
30610 	    i__1 = *n0 - 3 << 2;
30611 	    for (j4 = *i0 << 2; j4 <= i__1; j4 += 4) {
30612 		z__[j4 - 3] = d__ + z__[j4];
30613 		temp = z__[j4 + 2] / z__[j4 - 3];
30614 		d__ = d__ * temp - *tau;
30615 		*dmin__ = min(*dmin__,d__);
30616 		z__[j4 - 1] = z__[j4] * temp;
30617 /* Computing MIN */
30618 		d__1 = z__[j4 - 1];
30619 		emin = min(d__1,emin);
30620 /* L20: */
30621 	    }
30622 	}
30623 
30624 /*        Unroll last two steps. */
30625 
30626 	*dnm2 = d__;
30627 	*dmin2 = *dmin__;
30628 	j4 = (*n0 - 2 << 2) - *pp;
30629 	j4p2 = j4 + (*pp << 1) - 1;
30630 	z__[j4 - 2] = *dnm2 + z__[j4p2];
30631 	z__[j4] = z__[j4p2 + 2] * (z__[j4p2] / z__[j4 - 2]);
30632 	*dnm1 = z__[j4p2 + 2] * (*dnm2 / z__[j4 - 2]) - *tau;
30633 	*dmin__ = min(*dmin__,*dnm1);
30634 
30635 	*dmin1 = *dmin__;
30636 	j4 += 4;
30637 	j4p2 = j4 + (*pp << 1) - 1;
30638 	z__[j4 - 2] = *dnm1 + z__[j4p2];
30639 	z__[j4] = z__[j4p2 + 2] * (z__[j4p2] / z__[j4 - 2]);
30640 	*dn = z__[j4p2 + 2] * (*dnm1 / z__[j4 - 2]) - *tau;
30641 	*dmin__ = min(*dmin__,*dn);
30642 
30643     } else {
30644 
30645 /*        Code for non IEEE arithmetic. */
30646 
30647 	if (*pp == 0) {
30648 	    i__1 = *n0 - 3 << 2;
30649 	    for (j4 = *i0 << 2; j4 <= i__1; j4 += 4) {
30650 		z__[j4 - 2] = d__ + z__[j4 - 1];
30651 		if (d__ < 0.) {
30652 		    return 0;
30653 		} else {
30654 		    z__[j4] = z__[j4 + 1] * (z__[j4 - 1] / z__[j4 - 2]);
30655 		    d__ = z__[j4 + 1] * (d__ / z__[j4 - 2]) - *tau;
30656 		}
30657 		*dmin__ = min(*dmin__,d__);
30658 /* Computing MIN */
30659 		d__1 = emin, d__2 = z__[j4];
30660 		emin = min(d__1,d__2);
30661 /* L30: */
30662 	    }
30663 	} else {
30664 	    i__1 = *n0 - 3 << 2;
30665 	    for (j4 = *i0 << 2; j4 <= i__1; j4 += 4) {
30666 		z__[j4 - 3] = d__ + z__[j4];
30667 		if (d__ < 0.) {
30668 		    return 0;
30669 		} else {
30670 		    z__[j4 - 1] = z__[j4 + 2] * (z__[j4] / z__[j4 - 3]);
30671 		    d__ = z__[j4 + 2] * (d__ / z__[j4 - 3]) - *tau;
30672 		}
30673 		*dmin__ = min(*dmin__,d__);
30674 /* Computing MIN */
30675 		d__1 = emin, d__2 = z__[j4 - 1];
30676 		emin = min(d__1,d__2);
30677 /* L40: */
30678 	    }
30679 	}
30680 
30681 /*        Unroll last two steps. */
30682 
30683 	*dnm2 = d__;
30684 	*dmin2 = *dmin__;
30685 	j4 = (*n0 - 2 << 2) - *pp;
30686 	j4p2 = j4 + (*pp << 1) - 1;
30687 	z__[j4 - 2] = *dnm2 + z__[j4p2];
30688 	if (*dnm2 < 0.) {
30689 	    return 0;
30690 	} else {
30691 	    z__[j4] = z__[j4p2 + 2] * (z__[j4p2] / z__[j4 - 2]);
30692 	    *dnm1 = z__[j4p2 + 2] * (*dnm2 / z__[j4 - 2]) - *tau;
30693 	}
30694 	*dmin__ = min(*dmin__,*dnm1);
30695 
30696 	*dmin1 = *dmin__;
30697 	j4 += 4;
30698 	j4p2 = j4 + (*pp << 1) - 1;
30699 	z__[j4 - 2] = *dnm1 + z__[j4p2];
30700 	if (*dnm1 < 0.) {
30701 	    return 0;
30702 	} else {
30703 	    z__[j4] = z__[j4p2 + 2] * (z__[j4p2] / z__[j4 - 2]);
30704 	    *dn = z__[j4p2 + 2] * (*dnm1 / z__[j4 - 2]) - *tau;
30705 	}
30706 	*dmin__ = min(*dmin__,*dn);
30707 
30708     }
30709 
30710     z__[j4 + 2] = *dn;
30711     z__[(*n0 << 2) - *pp] = emin;
30712     return 0;
30713 
30714 /*     End of DLASQ5 */
30715 
30716 } /* dlasq5_ */
30717 
dlasq6_(integer * i0,integer * n0,doublereal * z__,integer * pp,doublereal * dmin__,doublereal * dmin1,doublereal * dmin2,doublereal * dn,doublereal * dnm1,doublereal * dnm2)30718 /* Subroutine */ int dlasq6_(integer *i0, integer *n0, doublereal *z__,
30719 	integer *pp, doublereal *dmin__, doublereal *dmin1, doublereal *dmin2,
30720 	 doublereal *dn, doublereal *dnm1, doublereal *dnm2)
30721 {
30722     /* System generated locals */
30723     integer i__1;
30724     doublereal d__1, d__2;
30725 
30726     /* Local variables */
30727     static doublereal d__;
30728     static integer j4, j4p2;
30729     static doublereal emin, temp;
30730 
30731     static doublereal safmin;
30732 
30733 
30734 /*
30735     -- LAPACK routine (version 3.2)                                    --
30736 
30737     -- Contributed by Osni Marques of the Lawrence Berkeley National   --
30738     -- Laboratory and Beresford Parlett of the Univ. of California at  --
30739     -- Berkeley                                                        --
30740     -- November 2008                                                   --
30741 
30742     -- LAPACK is a software package provided by Univ. of Tennessee,    --
30743     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
30744 
30745 
30746     Purpose
30747     =======
30748 
30749     DLASQ6 computes one dqd (shift equal to zero) transform in
30750     ping-pong form, with protection against underflow and overflow.
30751 
30752     Arguments
30753     =========
30754 
30755     I0    (input) INTEGER
30756           First index.
30757 
30758     N0    (input) INTEGER
30759           Last index.
30760 
30761     Z     (input) DOUBLE PRECISION array, dimension ( 4*N )
30762           Z holds the qd array. EMIN is stored in Z(4*N0) to avoid
30763           an extra argument.
30764 
30765     PP    (input) INTEGER
30766           PP=0 for ping, PP=1 for pong.
30767 
30768     DMIN  (output) DOUBLE PRECISION
30769           Minimum value of d.
30770 
30771     DMIN1 (output) DOUBLE PRECISION
30772           Minimum value of d, excluding D( N0 ).
30773 
30774     DMIN2 (output) DOUBLE PRECISION
30775           Minimum value of d, excluding D( N0 ) and D( N0-1 ).
30776 
30777     DN    (output) DOUBLE PRECISION
30778           d(N0), the last value of d.
30779 
30780     DNM1  (output) DOUBLE PRECISION
30781           d(N0-1).
30782 
30783     DNM2  (output) DOUBLE PRECISION
30784           d(N0-2).
30785 
30786     =====================================================================
30787 */
30788 
30789 
30790     /* Parameter adjustments */
30791     --z__;
30792 
30793     /* Function Body */
30794     if (*n0 - *i0 - 1 <= 0) {
30795 	return 0;
30796     }
30797 
30798     safmin = SAFEMINIMUM;
30799     j4 = (*i0 << 2) + *pp - 3;
30800     emin = z__[j4 + 4];
30801     d__ = z__[j4];
30802     *dmin__ = d__;
30803 
30804     if (*pp == 0) {
30805 	i__1 = *n0 - 3 << 2;
30806 	for (j4 = *i0 << 2; j4 <= i__1; j4 += 4) {
30807 	    z__[j4 - 2] = d__ + z__[j4 - 1];
30808 	    if (z__[j4 - 2] == 0.) {
30809 		z__[j4] = 0.;
30810 		d__ = z__[j4 + 1];
30811 		*dmin__ = d__;
30812 		emin = 0.;
30813 	    } else if (safmin * z__[j4 + 1] < z__[j4 - 2] && safmin * z__[j4
30814 		    - 2] < z__[j4 + 1]) {
30815 		temp = z__[j4 + 1] / z__[j4 - 2];
30816 		z__[j4] = z__[j4 - 1] * temp;
30817 		d__ *= temp;
30818 	    } else {
30819 		z__[j4] = z__[j4 + 1] * (z__[j4 - 1] / z__[j4 - 2]);
30820 		d__ = z__[j4 + 1] * (d__ / z__[j4 - 2]);
30821 	    }
30822 	    *dmin__ = min(*dmin__,d__);
30823 /* Computing MIN */
30824 	    d__1 = emin, d__2 = z__[j4];
30825 	    emin = min(d__1,d__2);
30826 /* L10: */
30827 	}
30828     } else {
30829 	i__1 = *n0 - 3 << 2;
30830 	for (j4 = *i0 << 2; j4 <= i__1; j4 += 4) {
30831 	    z__[j4 - 3] = d__ + z__[j4];
30832 	    if (z__[j4 - 3] == 0.) {
30833 		z__[j4 - 1] = 0.;
30834 		d__ = z__[j4 + 2];
30835 		*dmin__ = d__;
30836 		emin = 0.;
30837 	    } else if (safmin * z__[j4 + 2] < z__[j4 - 3] && safmin * z__[j4
30838 		    - 3] < z__[j4 + 2]) {
30839 		temp = z__[j4 + 2] / z__[j4 - 3];
30840 		z__[j4 - 1] = z__[j4] * temp;
30841 		d__ *= temp;
30842 	    } else {
30843 		z__[j4 - 1] = z__[j4 + 2] * (z__[j4] / z__[j4 - 3]);
30844 		d__ = z__[j4 + 2] * (d__ / z__[j4 - 3]);
30845 	    }
30846 	    *dmin__ = min(*dmin__,d__);
30847 /* Computing MIN */
30848 	    d__1 = emin, d__2 = z__[j4 - 1];
30849 	    emin = min(d__1,d__2);
30850 /* L20: */
30851 	}
30852     }
30853 
30854 /*     Unroll last two steps. */
30855 
30856     *dnm2 = d__;
30857     *dmin2 = *dmin__;
30858     j4 = (*n0 - 2 << 2) - *pp;
30859     j4p2 = j4 + (*pp << 1) - 1;
30860     z__[j4 - 2] = *dnm2 + z__[j4p2];
30861     if (z__[j4 - 2] == 0.) {
30862 	z__[j4] = 0.;
30863 	*dnm1 = z__[j4p2 + 2];
30864 	*dmin__ = *dnm1;
30865 	emin = 0.;
30866     } else if (safmin * z__[j4p2 + 2] < z__[j4 - 2] && safmin * z__[j4 - 2] <
30867 	    z__[j4p2 + 2]) {
30868 	temp = z__[j4p2 + 2] / z__[j4 - 2];
30869 	z__[j4] = z__[j4p2] * temp;
30870 	*dnm1 = *dnm2 * temp;
30871     } else {
30872 	z__[j4] = z__[j4p2 + 2] * (z__[j4p2] / z__[j4 - 2]);
30873 	*dnm1 = z__[j4p2 + 2] * (*dnm2 / z__[j4 - 2]);
30874     }
30875     *dmin__ = min(*dmin__,*dnm1);
30876 
30877     *dmin1 = *dmin__;
30878     j4 += 4;
30879     j4p2 = j4 + (*pp << 1) - 1;
30880     z__[j4 - 2] = *dnm1 + z__[j4p2];
30881     if (z__[j4 - 2] == 0.) {
30882 	z__[j4] = 0.;
30883 	*dn = z__[j4p2 + 2];
30884 	*dmin__ = *dn;
30885 	emin = 0.;
30886     } else if (safmin * z__[j4p2 + 2] < z__[j4 - 2] && safmin * z__[j4 - 2] <
30887 	    z__[j4p2 + 2]) {
30888 	temp = z__[j4p2 + 2] / z__[j4 - 2];
30889 	z__[j4] = z__[j4p2] * temp;
30890 	*dn = *dnm1 * temp;
30891     } else {
30892 	z__[j4] = z__[j4p2 + 2] * (z__[j4p2] / z__[j4 - 2]);
30893 	*dn = z__[j4p2 + 2] * (*dnm1 / z__[j4 - 2]);
30894     }
30895     *dmin__ = min(*dmin__,*dn);
30896 
30897     z__[j4 + 2] = *dn;
30898     z__[(*n0 << 2) - *pp] = emin;
30899     return 0;
30900 
30901 /*     End of DLASQ6 */
30902 
30903 } /* dlasq6_ */
30904 
dlasr_(char * side,char * pivot,char * direct,integer * m,integer * n,doublereal * c__,doublereal * s,doublereal * a,integer * lda)30905 /* Subroutine */ int dlasr_(char *side, char *pivot, char *direct, integer *m,
30906 	 integer *n, doublereal *c__, doublereal *s, doublereal *a, integer *
30907 	lda)
30908 {
30909     /* System generated locals */
30910     integer a_dim1, a_offset, i__1, i__2;
30911 
30912     /* Local variables */
30913     static integer i__, j, info;
30914     static doublereal temp;
30915     extern logical lsame_(char *, char *);
30916     static doublereal ctemp, stemp;
30917     extern /* Subroutine */ int xerbla_(char *, integer *);
30918 
30919 
30920 /*
30921     -- LAPACK auxiliary routine (version 3.2) --
30922     -- LAPACK is a software package provided by Univ. of Tennessee,    --
30923     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
30924        November 2006
30925 
30926 
30927     Purpose
30928     =======
30929 
30930     DLASR applies a sequence of plane rotations to a real matrix A,
30931     from either the left or the right.
30932 
30933     When SIDE = 'L', the transformation takes the form
30934 
30935        A := P*A
30936 
30937     and when SIDE = 'R', the transformation takes the form
30938 
30939        A := A*P**T
30940 
30941     where P is an orthogonal matrix consisting of a sequence of z plane
30942     rotations, with z = M when SIDE = 'L' and z = N when SIDE = 'R',
30943     and P**T is the transpose of P.
30944 
30945     When DIRECT = 'F' (Forward sequence), then
30946 
30947        P = P(z-1) * ... * P(2) * P(1)
30948 
30949     and when DIRECT = 'B' (Backward sequence), then
30950 
30951        P = P(1) * P(2) * ... * P(z-1)
30952 
30953     where P(k) is a plane rotation matrix defined by the 2-by-2 rotation
30954 
30955        R(k) = (  c(k)  s(k) )
30956             = ( -s(k)  c(k) ).
30957 
30958     When PIVOT = 'V' (Variable pivot), the rotation is performed
30959     for the plane (k,k+1), i.e., P(k) has the form
30960 
30961        P(k) = (  1                                            )
30962               (       ...                                     )
30963               (              1                                )
30964               (                   c(k)  s(k)                  )
30965               (                  -s(k)  c(k)                  )
30966               (                                1              )
30967               (                                     ...       )
30968               (                                            1  )
30969 
30970     where R(k) appears as a rank-2 modification to the identity matrix in
30971     rows and columns k and k+1.
30972 
30973     When PIVOT = 'T' (Top pivot), the rotation is performed for the
30974     plane (1,k+1), so P(k) has the form
30975 
30976        P(k) = (  c(k)                    s(k)                 )
30977               (         1                                     )
30978               (              ...                              )
30979               (                     1                         )
30980               ( -s(k)                    c(k)                 )
30981               (                                 1             )
30982               (                                      ...      )
30983               (                                             1 )
30984 
30985     where R(k) appears in rows and columns 1 and k+1.
30986 
30987     Similarly, when PIVOT = 'B' (Bottom pivot), the rotation is
30988     performed for the plane (k,z), giving P(k) the form
30989 
30990        P(k) = ( 1                                             )
30991               (      ...                                      )
30992               (             1                                 )
30993               (                  c(k)                    s(k) )
30994               (                         1                     )
30995               (                              ...              )
30996               (                                     1         )
30997               (                 -s(k)                    c(k) )
30998 
30999     where R(k) appears in rows and columns k and z.  The rotations are
31000     performed without ever forming P(k) explicitly.
31001 
31002     Arguments
31003     =========
31004 
31005     SIDE    (input) CHARACTER*1
31006             Specifies whether the plane rotation matrix P is applied to
31007             A on the left or the right.
31008             = 'L':  Left, compute A := P*A
31009             = 'R':  Right, compute A:= A*P**T
31010 
31011     PIVOT   (input) CHARACTER*1
31012             Specifies the plane for which P(k) is a plane rotation
31013             matrix.
31014             = 'V':  Variable pivot, the plane (k,k+1)
31015             = 'T':  Top pivot, the plane (1,k+1)
31016             = 'B':  Bottom pivot, the plane (k,z)
31017 
31018     DIRECT  (input) CHARACTER*1
31019             Specifies whether P is a forward or backward sequence of
31020             plane rotations.
31021             = 'F':  Forward, P = P(z-1)*...*P(2)*P(1)
31022             = 'B':  Backward, P = P(1)*P(2)*...*P(z-1)
31023 
31024     M       (input) INTEGER
31025             The number of rows of the matrix A.  If m <= 1, an immediate
31026             return is effected.
31027 
31028     N       (input) INTEGER
31029             The number of columns of the matrix A.  If n <= 1, an
31030             immediate return is effected.
31031 
31032     C       (input) DOUBLE PRECISION array, dimension
31033                     (M-1) if SIDE = 'L'
31034                     (N-1) if SIDE = 'R'
31035             The cosines c(k) of the plane rotations.
31036 
31037     S       (input) DOUBLE PRECISION array, dimension
31038                     (M-1) if SIDE = 'L'
31039                     (N-1) if SIDE = 'R'
31040             The sines s(k) of the plane rotations.  The 2-by-2 plane
31041             rotation part of the matrix P(k), R(k), has the form
31042             R(k) = (  c(k)  s(k) )
31043                    ( -s(k)  c(k) ).
31044 
31045     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
31046             The M-by-N matrix A.  On exit, A is overwritten by P*A if
31047             SIDE = 'R' or by A*P**T if SIDE = 'L'.
31048 
31049     LDA     (input) INTEGER
31050             The leading dimension of the array A.  LDA >= max(1,M).
31051 
31052     =====================================================================
31053 
31054 
31055        Test the input parameters
31056 */
31057 
31058     /* Parameter adjustments */
31059     --c__;
31060     --s;
31061     a_dim1 = *lda;
31062     a_offset = 1 + a_dim1;
31063     a -= a_offset;
31064 
31065     /* Function Body */
31066     info = 0;
31067     if (! (lsame_(side, "L") || lsame_(side, "R"))) {
31068 	info = 1;
31069     } else if (! (lsame_(pivot, "V") || lsame_(pivot,
31070 	    "T") || lsame_(pivot, "B"))) {
31071 	info = 2;
31072     } else if (! (lsame_(direct, "F") || lsame_(direct,
31073 	    "B"))) {
31074 	info = 3;
31075     } else if (*m < 0) {
31076 	info = 4;
31077     } else if (*n < 0) {
31078 	info = 5;
31079     } else if (*lda < max(1,*m)) {
31080 	info = 9;
31081     }
31082     if (info != 0) {
31083 	xerbla_("DLASR ", &info);
31084 	return 0;
31085     }
31086 
31087 /*     Quick return if possible */
31088 
31089     if (*m == 0 || *n == 0) {
31090 	return 0;
31091     }
31092     if (lsame_(side, "L")) {
31093 
31094 /*        Form  P * A */
31095 
31096 	if (lsame_(pivot, "V")) {
31097 	    if (lsame_(direct, "F")) {
31098 		i__1 = *m - 1;
31099 		for (j = 1; j <= i__1; ++j) {
31100 		    ctemp = c__[j];
31101 		    stemp = s[j];
31102 		    if (ctemp != 1. || stemp != 0.) {
31103 			i__2 = *n;
31104 			for (i__ = 1; i__ <= i__2; ++i__) {
31105 			    temp = a[j + 1 + i__ * a_dim1];
31106 			    a[j + 1 + i__ * a_dim1] = ctemp * temp - stemp *
31107 				    a[j + i__ * a_dim1];
31108 			    a[j + i__ * a_dim1] = stemp * temp + ctemp * a[j
31109 				    + i__ * a_dim1];
31110 /* L10: */
31111 			}
31112 		    }
31113 /* L20: */
31114 		}
31115 	    } else if (lsame_(direct, "B")) {
31116 		for (j = *m - 1; j >= 1; --j) {
31117 		    ctemp = c__[j];
31118 		    stemp = s[j];
31119 		    if (ctemp != 1. || stemp != 0.) {
31120 			i__1 = *n;
31121 			for (i__ = 1; i__ <= i__1; ++i__) {
31122 			    temp = a[j + 1 + i__ * a_dim1];
31123 			    a[j + 1 + i__ * a_dim1] = ctemp * temp - stemp *
31124 				    a[j + i__ * a_dim1];
31125 			    a[j + i__ * a_dim1] = stemp * temp + ctemp * a[j
31126 				    + i__ * a_dim1];
31127 /* L30: */
31128 			}
31129 		    }
31130 /* L40: */
31131 		}
31132 	    }
31133 	} else if (lsame_(pivot, "T")) {
31134 	    if (lsame_(direct, "F")) {
31135 		i__1 = *m;
31136 		for (j = 2; j <= i__1; ++j) {
31137 		    ctemp = c__[j - 1];
31138 		    stemp = s[j - 1];
31139 		    if (ctemp != 1. || stemp != 0.) {
31140 			i__2 = *n;
31141 			for (i__ = 1; i__ <= i__2; ++i__) {
31142 			    temp = a[j + i__ * a_dim1];
31143 			    a[j + i__ * a_dim1] = ctemp * temp - stemp * a[
31144 				    i__ * a_dim1 + 1];
31145 			    a[i__ * a_dim1 + 1] = stemp * temp + ctemp * a[
31146 				    i__ * a_dim1 + 1];
31147 /* L50: */
31148 			}
31149 		    }
31150 /* L60: */
31151 		}
31152 	    } else if (lsame_(direct, "B")) {
31153 		for (j = *m; j >= 2; --j) {
31154 		    ctemp = c__[j - 1];
31155 		    stemp = s[j - 1];
31156 		    if (ctemp != 1. || stemp != 0.) {
31157 			i__1 = *n;
31158 			for (i__ = 1; i__ <= i__1; ++i__) {
31159 			    temp = a[j + i__ * a_dim1];
31160 			    a[j + i__ * a_dim1] = ctemp * temp - stemp * a[
31161 				    i__ * a_dim1 + 1];
31162 			    a[i__ * a_dim1 + 1] = stemp * temp + ctemp * a[
31163 				    i__ * a_dim1 + 1];
31164 /* L70: */
31165 			}
31166 		    }
31167 /* L80: */
31168 		}
31169 	    }
31170 	} else if (lsame_(pivot, "B")) {
31171 	    if (lsame_(direct, "F")) {
31172 		i__1 = *m - 1;
31173 		for (j = 1; j <= i__1; ++j) {
31174 		    ctemp = c__[j];
31175 		    stemp = s[j];
31176 		    if (ctemp != 1. || stemp != 0.) {
31177 			i__2 = *n;
31178 			for (i__ = 1; i__ <= i__2; ++i__) {
31179 			    temp = a[j + i__ * a_dim1];
31180 			    a[j + i__ * a_dim1] = stemp * a[*m + i__ * a_dim1]
31181 				     + ctemp * temp;
31182 			    a[*m + i__ * a_dim1] = ctemp * a[*m + i__ *
31183 				    a_dim1] - stemp * temp;
31184 /* L90: */
31185 			}
31186 		    }
31187 /* L100: */
31188 		}
31189 	    } else if (lsame_(direct, "B")) {
31190 		for (j = *m - 1; j >= 1; --j) {
31191 		    ctemp = c__[j];
31192 		    stemp = s[j];
31193 		    if (ctemp != 1. || stemp != 0.) {
31194 			i__1 = *n;
31195 			for (i__ = 1; i__ <= i__1; ++i__) {
31196 			    temp = a[j + i__ * a_dim1];
31197 			    a[j + i__ * a_dim1] = stemp * a[*m + i__ * a_dim1]
31198 				     + ctemp * temp;
31199 			    a[*m + i__ * a_dim1] = ctemp * a[*m + i__ *
31200 				    a_dim1] - stemp * temp;
31201 /* L110: */
31202 			}
31203 		    }
31204 /* L120: */
31205 		}
31206 	    }
31207 	}
31208     } else if (lsame_(side, "R")) {
31209 
31210 /*        Form A * P' */
31211 
31212 	if (lsame_(pivot, "V")) {
31213 	    if (lsame_(direct, "F")) {
31214 		i__1 = *n - 1;
31215 		for (j = 1; j <= i__1; ++j) {
31216 		    ctemp = c__[j];
31217 		    stemp = s[j];
31218 		    if (ctemp != 1. || stemp != 0.) {
31219 			i__2 = *m;
31220 			for (i__ = 1; i__ <= i__2; ++i__) {
31221 			    temp = a[i__ + (j + 1) * a_dim1];
31222 			    a[i__ + (j + 1) * a_dim1] = ctemp * temp - stemp *
31223 				     a[i__ + j * a_dim1];
31224 			    a[i__ + j * a_dim1] = stemp * temp + ctemp * a[
31225 				    i__ + j * a_dim1];
31226 /* L130: */
31227 			}
31228 		    }
31229 /* L140: */
31230 		}
31231 	    } else if (lsame_(direct, "B")) {
31232 		for (j = *n - 1; j >= 1; --j) {
31233 		    ctemp = c__[j];
31234 		    stemp = s[j];
31235 		    if (ctemp != 1. || stemp != 0.) {
31236 			i__1 = *m;
31237 			for (i__ = 1; i__ <= i__1; ++i__) {
31238 			    temp = a[i__ + (j + 1) * a_dim1];
31239 			    a[i__ + (j + 1) * a_dim1] = ctemp * temp - stemp *
31240 				     a[i__ + j * a_dim1];
31241 			    a[i__ + j * a_dim1] = stemp * temp + ctemp * a[
31242 				    i__ + j * a_dim1];
31243 /* L150: */
31244 			}
31245 		    }
31246 /* L160: */
31247 		}
31248 	    }
31249 	} else if (lsame_(pivot, "T")) {
31250 	    if (lsame_(direct, "F")) {
31251 		i__1 = *n;
31252 		for (j = 2; j <= i__1; ++j) {
31253 		    ctemp = c__[j - 1];
31254 		    stemp = s[j - 1];
31255 		    if (ctemp != 1. || stemp != 0.) {
31256 			i__2 = *m;
31257 			for (i__ = 1; i__ <= i__2; ++i__) {
31258 			    temp = a[i__ + j * a_dim1];
31259 			    a[i__ + j * a_dim1] = ctemp * temp - stemp * a[
31260 				    i__ + a_dim1];
31261 			    a[i__ + a_dim1] = stemp * temp + ctemp * a[i__ +
31262 				    a_dim1];
31263 /* L170: */
31264 			}
31265 		    }
31266 /* L180: */
31267 		}
31268 	    } else if (lsame_(direct, "B")) {
31269 		for (j = *n; j >= 2; --j) {
31270 		    ctemp = c__[j - 1];
31271 		    stemp = s[j - 1];
31272 		    if (ctemp != 1. || stemp != 0.) {
31273 			i__1 = *m;
31274 			for (i__ = 1; i__ <= i__1; ++i__) {
31275 			    temp = a[i__ + j * a_dim1];
31276 			    a[i__ + j * a_dim1] = ctemp * temp - stemp * a[
31277 				    i__ + a_dim1];
31278 			    a[i__ + a_dim1] = stemp * temp + ctemp * a[i__ +
31279 				    a_dim1];
31280 /* L190: */
31281 			}
31282 		    }
31283 /* L200: */
31284 		}
31285 	    }
31286 	} else if (lsame_(pivot, "B")) {
31287 	    if (lsame_(direct, "F")) {
31288 		i__1 = *n - 1;
31289 		for (j = 1; j <= i__1; ++j) {
31290 		    ctemp = c__[j];
31291 		    stemp = s[j];
31292 		    if (ctemp != 1. || stemp != 0.) {
31293 			i__2 = *m;
31294 			for (i__ = 1; i__ <= i__2; ++i__) {
31295 			    temp = a[i__ + j * a_dim1];
31296 			    a[i__ + j * a_dim1] = stemp * a[i__ + *n * a_dim1]
31297 				     + ctemp * temp;
31298 			    a[i__ + *n * a_dim1] = ctemp * a[i__ + *n *
31299 				    a_dim1] - stemp * temp;
31300 /* L210: */
31301 			}
31302 		    }
31303 /* L220: */
31304 		}
31305 	    } else if (lsame_(direct, "B")) {
31306 		for (j = *n - 1; j >= 1; --j) {
31307 		    ctemp = c__[j];
31308 		    stemp = s[j];
31309 		    if (ctemp != 1. || stemp != 0.) {
31310 			i__1 = *m;
31311 			for (i__ = 1; i__ <= i__1; ++i__) {
31312 			    temp = a[i__ + j * a_dim1];
31313 			    a[i__ + j * a_dim1] = stemp * a[i__ + *n * a_dim1]
31314 				     + ctemp * temp;
31315 			    a[i__ + *n * a_dim1] = ctemp * a[i__ + *n *
31316 				    a_dim1] - stemp * temp;
31317 /* L230: */
31318 			}
31319 		    }
31320 /* L240: */
31321 		}
31322 	    }
31323 	}
31324     }
31325 
31326     return 0;
31327 
31328 /*     End of DLASR */
31329 
31330 } /* dlasr_ */
31331 
dlasrt_(char * id,integer * n,doublereal * d__,integer * info)31332 /* Subroutine */ int dlasrt_(char *id, integer *n, doublereal *d__, integer *
31333 	info)
31334 {
31335     /* System generated locals */
31336     integer i__1, i__2;
31337 
31338     /* Local variables */
31339     static integer i__, j;
31340     static doublereal d1, d2, d3;
31341     static integer dir;
31342     static doublereal tmp;
31343     static integer endd;
31344     extern logical lsame_(char *, char *);
31345     static integer stack[64]	/* was [2][32] */;
31346     static doublereal dmnmx;
31347     static integer start;
31348     extern /* Subroutine */ int xerbla_(char *, integer *);
31349     static integer stkpnt;
31350 
31351 
31352 /*
31353     -- LAPACK routine (version 3.2) --
31354     -- LAPACK is a software package provided by Univ. of Tennessee,    --
31355     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
31356        November 2006
31357 
31358 
31359     Purpose
31360     =======
31361 
31362     Sort the numbers in D in increasing order (if ID = 'I') or
31363     in decreasing order (if ID = 'D' ).
31364 
31365     Use Quick Sort, reverting to Insertion sort on arrays of
31366     size <= 20. Dimension of STACK limits N to about 2**32.
31367 
31368     Arguments
31369     =========
31370 
31371     ID      (input) CHARACTER*1
31372             = 'I': sort D in increasing order;
31373             = 'D': sort D in decreasing order.
31374 
31375     N       (input) INTEGER
31376             The length of the array D.
31377 
31378     D       (input/output) DOUBLE PRECISION array, dimension (N)
31379             On entry, the array to be sorted.
31380             On exit, D has been sorted into increasing order
31381             (D(1) <= ... <= D(N) ) or into decreasing order
31382             (D(1) >= ... >= D(N) ), depending on ID.
31383 
31384     INFO    (output) INTEGER
31385             = 0:  successful exit
31386             < 0:  if INFO = -i, the i-th argument had an illegal value
31387 
31388     =====================================================================
31389 
31390 
31391        Test the input paramters.
31392 */
31393 
31394     /* Parameter adjustments */
31395     --d__;
31396 
31397     /* Function Body */
31398     *info = 0;
31399     dir = -1;
31400     if (lsame_(id, "D")) {
31401 	dir = 0;
31402     } else if (lsame_(id, "I")) {
31403 	dir = 1;
31404     }
31405     if (dir == -1) {
31406 	*info = -1;
31407     } else if (*n < 0) {
31408 	*info = -2;
31409     }
31410     if (*info != 0) {
31411 	i__1 = -(*info);
31412 	xerbla_("DLASRT", &i__1);
31413 	return 0;
31414     }
31415 
31416 /*     Quick return if possible */
31417 
31418     if (*n <= 1) {
31419 	return 0;
31420     }
31421 
31422     stkpnt = 1;
31423     stack[0] = 1;
31424     stack[1] = *n;
31425 L10:
31426     start = stack[(stkpnt << 1) - 2];
31427     endd = stack[(stkpnt << 1) - 1];
31428     --stkpnt;
31429     if (endd - start <= 20 && endd - start > 0) {
31430 
31431 /*        Do Insertion sort on D( START:ENDD ) */
31432 
31433 	if (dir == 0) {
31434 
31435 /*           Sort into decreasing order */
31436 
31437 	    i__1 = endd;
31438 	    for (i__ = start + 1; i__ <= i__1; ++i__) {
31439 		i__2 = start + 1;
31440 		for (j = i__; j >= i__2; --j) {
31441 		    if (d__[j] > d__[j - 1]) {
31442 			dmnmx = d__[j];
31443 			d__[j] = d__[j - 1];
31444 			d__[j - 1] = dmnmx;
31445 		    } else {
31446 			goto L30;
31447 		    }
31448 /* L20: */
31449 		}
31450 L30:
31451 		;
31452 	    }
31453 
31454 	} else {
31455 
31456 /*           Sort into increasing order */
31457 
31458 	    i__1 = endd;
31459 	    for (i__ = start + 1; i__ <= i__1; ++i__) {
31460 		i__2 = start + 1;
31461 		for (j = i__; j >= i__2; --j) {
31462 		    if (d__[j] < d__[j - 1]) {
31463 			dmnmx = d__[j];
31464 			d__[j] = d__[j - 1];
31465 			d__[j - 1] = dmnmx;
31466 		    } else {
31467 			goto L50;
31468 		    }
31469 /* L40: */
31470 		}
31471 L50:
31472 		;
31473 	    }
31474 
31475 	}
31476 
31477     } else if (endd - start > 20) {
31478 
31479 /*
31480           Partition D( START:ENDD ) and stack parts, largest one first
31481 
31482           Choose partition entry as median of 3
31483 */
31484 
31485 	d1 = d__[start];
31486 	d2 = d__[endd];
31487 	i__ = (start + endd) / 2;
31488 	d3 = d__[i__];
31489 	if (d1 < d2) {
31490 	    if (d3 < d1) {
31491 		dmnmx = d1;
31492 	    } else if (d3 < d2) {
31493 		dmnmx = d3;
31494 	    } else {
31495 		dmnmx = d2;
31496 	    }
31497 	} else {
31498 	    if (d3 < d2) {
31499 		dmnmx = d2;
31500 	    } else if (d3 < d1) {
31501 		dmnmx = d3;
31502 	    } else {
31503 		dmnmx = d1;
31504 	    }
31505 	}
31506 
31507 	if (dir == 0) {
31508 
31509 /*           Sort into decreasing order */
31510 
31511 	    i__ = start - 1;
31512 	    j = endd + 1;
31513 L60:
31514 L70:
31515 	    --j;
31516 	    if (d__[j] < dmnmx) {
31517 		goto L70;
31518 	    }
31519 L80:
31520 	    ++i__;
31521 	    if (d__[i__] > dmnmx) {
31522 		goto L80;
31523 	    }
31524 	    if (i__ < j) {
31525 		tmp = d__[i__];
31526 		d__[i__] = d__[j];
31527 		d__[j] = tmp;
31528 		goto L60;
31529 	    }
31530 	    if (j - start > endd - j - 1) {
31531 		++stkpnt;
31532 		stack[(stkpnt << 1) - 2] = start;
31533 		stack[(stkpnt << 1) - 1] = j;
31534 		++stkpnt;
31535 		stack[(stkpnt << 1) - 2] = j + 1;
31536 		stack[(stkpnt << 1) - 1] = endd;
31537 	    } else {
31538 		++stkpnt;
31539 		stack[(stkpnt << 1) - 2] = j + 1;
31540 		stack[(stkpnt << 1) - 1] = endd;
31541 		++stkpnt;
31542 		stack[(stkpnt << 1) - 2] = start;
31543 		stack[(stkpnt << 1) - 1] = j;
31544 	    }
31545 	} else {
31546 
31547 /*           Sort into increasing order */
31548 
31549 	    i__ = start - 1;
31550 	    j = endd + 1;
31551 L90:
31552 L100:
31553 	    --j;
31554 	    if (d__[j] > dmnmx) {
31555 		goto L100;
31556 	    }
31557 L110:
31558 	    ++i__;
31559 	    if (d__[i__] < dmnmx) {
31560 		goto L110;
31561 	    }
31562 	    if (i__ < j) {
31563 		tmp = d__[i__];
31564 		d__[i__] = d__[j];
31565 		d__[j] = tmp;
31566 		goto L90;
31567 	    }
31568 	    if (j - start > endd - j - 1) {
31569 		++stkpnt;
31570 		stack[(stkpnt << 1) - 2] = start;
31571 		stack[(stkpnt << 1) - 1] = j;
31572 		++stkpnt;
31573 		stack[(stkpnt << 1) - 2] = j + 1;
31574 		stack[(stkpnt << 1) - 1] = endd;
31575 	    } else {
31576 		++stkpnt;
31577 		stack[(stkpnt << 1) - 2] = j + 1;
31578 		stack[(stkpnt << 1) - 1] = endd;
31579 		++stkpnt;
31580 		stack[(stkpnt << 1) - 2] = start;
31581 		stack[(stkpnt << 1) - 1] = j;
31582 	    }
31583 	}
31584     }
31585     if (stkpnt > 0) {
31586 	goto L10;
31587     }
31588     return 0;
31589 
31590 /*     End of DLASRT */
31591 
31592 } /* dlasrt_ */
31593 
dlassq_(integer * n,doublereal * x,integer * incx,doublereal * scale,doublereal * sumsq)31594 /* Subroutine */ int dlassq_(integer *n, doublereal *x, integer *incx,
31595 	doublereal *scale, doublereal *sumsq)
31596 {
31597     /* System generated locals */
31598     integer i__1, i__2;
31599     doublereal d__1;
31600 
31601     /* Local variables */
31602     static integer ix;
31603     static doublereal absxi;
31604 
31605 
31606 /*
31607     -- LAPACK auxiliary routine (version 3.2) --
31608     -- LAPACK is a software package provided by Univ. of Tennessee,    --
31609     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
31610        November 2006
31611 
31612 
31613     Purpose
31614     =======
31615 
31616     DLASSQ  returns the values  scl  and  smsq  such that
31617 
31618        ( scl**2 )*smsq = x( 1 )**2 +...+ x( n )**2 + ( scale**2 )*sumsq,
31619 
31620     where  x( i ) = X( 1 + ( i - 1 )*INCX ). The value of  sumsq  is
31621     assumed to be non-negative and  scl  returns the value
31622 
31623        scl = max( scale, abs( x( i ) ) ).
31624 
31625     scale and sumsq must be supplied in SCALE and SUMSQ and
31626     scl and smsq are overwritten on SCALE and SUMSQ respectively.
31627 
31628     The routine makes only one pass through the vector x.
31629 
31630     Arguments
31631     =========
31632 
31633     N       (input) INTEGER
31634             The number of elements to be used from the vector X.
31635 
31636     X       (input) DOUBLE PRECISION array, dimension (N)
31637             The vector for which a scaled sum of squares is computed.
31638                x( i )  = X( 1 + ( i - 1 )*INCX ), 1 <= i <= n.
31639 
31640     INCX    (input) INTEGER
31641             The increment between successive values of the vector X.
31642             INCX > 0.
31643 
31644     SCALE   (input/output) DOUBLE PRECISION
31645             On entry, the value  scale  in the equation above.
31646             On exit, SCALE is overwritten with  scl , the scaling factor
31647             for the sum of squares.
31648 
31649     SUMSQ   (input/output) DOUBLE PRECISION
31650             On entry, the value  sumsq  in the equation above.
31651             On exit, SUMSQ is overwritten with  smsq , the basic sum of
31652             squares from which  scl  has been factored out.
31653 
31654    =====================================================================
31655 */
31656 
31657 
31658     /* Parameter adjustments */
31659     --x;
31660 
31661     /* Function Body */
31662     if (*n > 0) {
31663 	i__1 = (*n - 1) * *incx + 1;
31664 	i__2 = *incx;
31665 	for (ix = 1; i__2 < 0 ? ix >= i__1 : ix <= i__1; ix += i__2) {
31666 	    if (x[ix] != 0.) {
31667 		absxi = (d__1 = x[ix], abs(d__1));
31668 		if (*scale < absxi) {
31669 /* Computing 2nd power */
31670 		    d__1 = *scale / absxi;
31671 		    *sumsq = *sumsq * (d__1 * d__1) + 1;
31672 		    *scale = absxi;
31673 		} else {
31674 /* Computing 2nd power */
31675 		    d__1 = absxi / *scale;
31676 		    *sumsq += d__1 * d__1;
31677 		}
31678 	    }
31679 /* L10: */
31680 	}
31681     }
31682     return 0;
31683 
31684 /*     End of DLASSQ */
31685 
31686 } /* dlassq_ */
31687 
dlasv2_(doublereal * f,doublereal * g,doublereal * h__,doublereal * ssmin,doublereal * ssmax,doublereal * snr,doublereal * csr,doublereal * snl,doublereal * csl)31688 /* Subroutine */ int dlasv2_(doublereal *f, doublereal *g, doublereal *h__,
31689 	doublereal *ssmin, doublereal *ssmax, doublereal *snr, doublereal *
31690 	csr, doublereal *snl, doublereal *csl)
31691 {
31692     /* System generated locals */
31693     doublereal d__1;
31694 
31695     /* Local variables */
31696     static doublereal a, d__, l, m, r__, s, t, fa, ga, ha, ft, gt, ht, mm, tt,
31697 	     clt, crt, slt, srt;
31698     static integer pmax;
31699     static doublereal temp;
31700     static logical swap;
31701     static doublereal tsign;
31702 
31703     static logical gasmal;
31704 
31705 
31706 /*
31707     -- LAPACK auxiliary routine (version 3.2) --
31708     -- LAPACK is a software package provided by Univ. of Tennessee,    --
31709     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
31710        November 2006
31711 
31712 
31713     Purpose
31714     =======
31715 
31716     DLASV2 computes the singular value decomposition of a 2-by-2
31717     triangular matrix
31718        [  F   G  ]
31719        [  0   H  ].
31720     On return, abs(SSMAX) is the larger singular value, abs(SSMIN) is the
31721     smaller singular value, and (CSL,SNL) and (CSR,SNR) are the left and
31722     right singular vectors for abs(SSMAX), giving the decomposition
31723 
31724        [ CSL  SNL ] [  F   G  ] [ CSR -SNR ]  =  [ SSMAX   0   ]
31725        [-SNL  CSL ] [  0   H  ] [ SNR  CSR ]     [  0    SSMIN ].
31726 
31727     Arguments
31728     =========
31729 
31730     F       (input) DOUBLE PRECISION
31731             The (1,1) element of the 2-by-2 matrix.
31732 
31733     G       (input) DOUBLE PRECISION
31734             The (1,2) element of the 2-by-2 matrix.
31735 
31736     H       (input) DOUBLE PRECISION
31737             The (2,2) element of the 2-by-2 matrix.
31738 
31739     SSMIN   (output) DOUBLE PRECISION
31740             abs(SSMIN) is the smaller singular value.
31741 
31742     SSMAX   (output) DOUBLE PRECISION
31743             abs(SSMAX) is the larger singular value.
31744 
31745     SNL     (output) DOUBLE PRECISION
31746     CSL     (output) DOUBLE PRECISION
31747             The vector (CSL, SNL) is a unit left singular vector for the
31748             singular value abs(SSMAX).
31749 
31750     SNR     (output) DOUBLE PRECISION
31751     CSR     (output) DOUBLE PRECISION
31752             The vector (CSR, SNR) is a unit right singular vector for the
31753             singular value abs(SSMAX).
31754 
31755     Further Details
31756     ===============
31757 
31758     Any input parameter may be aliased with any output parameter.
31759 
31760     Barring over/underflow and assuming a guard digit in subtraction, all
31761     output quantities are correct to within a few units in the last
31762     place (ulps).
31763 
31764     In IEEE arithmetic, the code works correctly if one matrix element is
31765     infinite.
31766 
31767     Overflow will not occur unless the largest singular value itself
31768     overflows or is within a few ulps of overflow. (On machines with
31769     partial overflow, like the Cray, overflow may occur if the largest
31770     singular value is within a factor of 2 of overflow.)
31771 
31772     Underflow is harmless if underflow is gradual. Otherwise, results
31773     may correspond to a matrix modified by perturbations of size near
31774     the underflow threshold.
31775 
31776    =====================================================================
31777 */
31778 
31779 
31780     ft = *f;
31781     fa = abs(ft);
31782     ht = *h__;
31783     ha = abs(*h__);
31784 
31785 /*
31786        PMAX points to the maximum absolute element of matrix
31787          PMAX = 1 if F largest in absolute values
31788          PMAX = 2 if G largest in absolute values
31789          PMAX = 3 if H largest in absolute values
31790 */
31791 
31792     pmax = 1;
31793     swap = ha > fa;
31794     if (swap) {
31795 	pmax = 3;
31796 	temp = ft;
31797 	ft = ht;
31798 	ht = temp;
31799 	temp = fa;
31800 	fa = ha;
31801 	ha = temp;
31802 
31803 /*        Now FA .ge. HA */
31804 
31805     }
31806     gt = *g;
31807     ga = abs(gt);
31808     if (ga == 0.) {
31809 
31810 /*        Diagonal matrix */
31811 
31812 	*ssmin = ha;
31813 	*ssmax = fa;
31814 	clt = 1.;
31815 	crt = 1.;
31816 	slt = 0.;
31817 	srt = 0.;
31818     } else {
31819 	gasmal = TRUE_;
31820 	if (ga > fa) {
31821 	    pmax = 2;
31822 	    if (fa / ga < EPSILON) {
31823 
31824 /*              Case of very large GA */
31825 
31826 		gasmal = FALSE_;
31827 		*ssmax = ga;
31828 		if (ha > 1.) {
31829 		    *ssmin = fa / (ga / ha);
31830 		} else {
31831 		    *ssmin = fa / ga * ha;
31832 		}
31833 		clt = 1.;
31834 		slt = ht / gt;
31835 		srt = 1.;
31836 		crt = ft / gt;
31837 	    }
31838 	}
31839 	if (gasmal) {
31840 
31841 /*           Normal case */
31842 
31843 	    d__ = fa - ha;
31844 	    if (d__ == fa) {
31845 
31846 /*              Copes with infinite F or H */
31847 
31848 		l = 1.;
31849 	    } else {
31850 		l = d__ / fa;
31851 	    }
31852 
31853 /*           Note that 0 .le. L .le. 1 */
31854 
31855 	    m = gt / ft;
31856 
31857 /*           Note that abs(M) .le. 1/macheps */
31858 
31859 	    t = 2. - l;
31860 
31861 /*           Note that T .ge. 1 */
31862 
31863 	    mm = m * m;
31864 	    tt = t * t;
31865 	    s = sqrt(tt + mm);
31866 
31867 /*           Note that 1 .le. S .le. 1 + 1/macheps */
31868 
31869 	    if (l == 0.) {
31870 		r__ = abs(m);
31871 	    } else {
31872 		r__ = sqrt(l * l + mm);
31873 	    }
31874 
31875 /*           Note that 0 .le. R .le. 1 + 1/macheps */
31876 
31877 	    a = (s + r__) * .5;
31878 
31879 /*           Note that 1 .le. A .le. 1 + abs(M) */
31880 
31881 	    *ssmin = ha / a;
31882 	    *ssmax = fa * a;
31883 	    if (mm == 0.) {
31884 
31885 /*              Note that M is very tiny */
31886 
31887 		if (l == 0.) {
31888 		    t = d_sign(&c_b3192, &ft) * d_sign(&c_b15, &gt);
31889 		} else {
31890 		    t = gt / d_sign(&d__, &ft) + m / t;
31891 		}
31892 	    } else {
31893 		t = (m / (s + t) + m / (r__ + l)) * (a + 1.);
31894 	    }
31895 	    l = sqrt(t * t + 4.);
31896 	    crt = 2. / l;
31897 	    srt = t / l;
31898 	    clt = (crt + srt * m) / a;
31899 	    slt = ht / ft * srt / a;
31900 	}
31901     }
31902     if (swap) {
31903 	*csl = srt;
31904 	*snl = crt;
31905 	*csr = slt;
31906 	*snr = clt;
31907     } else {
31908 	*csl = clt;
31909 	*snl = slt;
31910 	*csr = crt;
31911 	*snr = srt;
31912     }
31913 
31914 /*     Correct signs of SSMAX and SSMIN */
31915 
31916     if (pmax == 1) {
31917 	tsign = d_sign(&c_b15, csr) * d_sign(&c_b15, csl) * d_sign(&c_b15, f);
31918     }
31919     if (pmax == 2) {
31920 	tsign = d_sign(&c_b15, snr) * d_sign(&c_b15, csl) * d_sign(&c_b15, g);
31921     }
31922     if (pmax == 3) {
31923 	tsign = d_sign(&c_b15, snr) * d_sign(&c_b15, snl) * d_sign(&c_b15,
31924 		h__);
31925     }
31926     *ssmax = d_sign(ssmax, &tsign);
31927     d__1 = tsign * d_sign(&c_b15, f) * d_sign(&c_b15, h__);
31928     *ssmin = d_sign(ssmin, &d__1);
31929     return 0;
31930 
31931 /*     End of DLASV2 */
31932 
31933 } /* dlasv2_ */
31934 
dlaswp_(integer * n,doublereal * a,integer * lda,integer * k1,integer * k2,integer * ipiv,integer * incx)31935 /* Subroutine */ int dlaswp_(integer *n, doublereal *a, integer *lda, integer
31936 	*k1, integer *k2, integer *ipiv, integer *incx)
31937 {
31938     /* System generated locals */
31939     integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
31940 
31941     /* Local variables */
31942     static integer i__, j, k, i1, i2, n32, ip, ix, ix0, inc;
31943     static doublereal temp;
31944 
31945 
31946 /*
31947     -- LAPACK auxiliary routine (version 3.2) --
31948     -- LAPACK is a software package provided by Univ. of Tennessee,    --
31949     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
31950        November 2006
31951 
31952 
31953     Purpose
31954     =======
31955 
31956     DLASWP performs a series of row interchanges on the matrix A.
31957     One row interchange is initiated for each of rows K1 through K2 of A.
31958 
31959     Arguments
31960     =========
31961 
31962     N       (input) INTEGER
31963             The number of columns of the matrix A.
31964 
31965     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
31966             On entry, the matrix of column dimension N to which the row
31967             interchanges will be applied.
31968             On exit, the permuted matrix.
31969 
31970     LDA     (input) INTEGER
31971             The leading dimension of the array A.
31972 
31973     K1      (input) INTEGER
31974             The first element of IPIV for which a row interchange will
31975             be done.
31976 
31977     K2      (input) INTEGER
31978             The last element of IPIV for which a row interchange will
31979             be done.
31980 
31981     IPIV    (input) INTEGER array, dimension (K2*abs(INCX))
31982             The vector of pivot indices.  Only the elements in positions
31983             K1 through K2 of IPIV are accessed.
31984             IPIV(K) = L implies rows K and L are to be interchanged.
31985 
31986     INCX    (input) INTEGER
31987             The increment between successive values of IPIV.  If IPIV
31988             is negative, the pivots are applied in reverse order.
31989 
31990     Further Details
31991     ===============
31992 
31993     Modified by
31994      R. C. Whaley, Computer Science Dept., Univ. of Tenn., Knoxville, USA
31995 
31996    =====================================================================
31997 
31998 
31999        Interchange row I with row IPIV(I) for each of rows K1 through K2.
32000 */
32001 
32002     /* Parameter adjustments */
32003     a_dim1 = *lda;
32004     a_offset = 1 + a_dim1;
32005     a -= a_offset;
32006     --ipiv;
32007 
32008     /* Function Body */
32009     if (*incx > 0) {
32010 	ix0 = *k1;
32011 	i1 = *k1;
32012 	i2 = *k2;
32013 	inc = 1;
32014     } else if (*incx < 0) {
32015 	ix0 = (1 - *k2) * *incx + 1;
32016 	i1 = *k2;
32017 	i2 = *k1;
32018 	inc = -1;
32019     } else {
32020 	return 0;
32021     }
32022 
32023     n32 = *n / 32 << 5;
32024     if (n32 != 0) {
32025 	i__1 = n32;
32026 	for (j = 1; j <= i__1; j += 32) {
32027 	    ix = ix0;
32028 	    i__2 = i2;
32029 	    i__3 = inc;
32030 	    for (i__ = i1; i__3 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__3)
32031 		    {
32032 		ip = ipiv[ix];
32033 		if (ip != i__) {
32034 		    i__4 = j + 31;
32035 		    for (k = j; k <= i__4; ++k) {
32036 			temp = a[i__ + k * a_dim1];
32037 			a[i__ + k * a_dim1] = a[ip + k * a_dim1];
32038 			a[ip + k * a_dim1] = temp;
32039 /* L10: */
32040 		    }
32041 		}
32042 		ix += *incx;
32043 /* L20: */
32044 	    }
32045 /* L30: */
32046 	}
32047     }
32048     if (n32 != *n) {
32049 	++n32;
32050 	ix = ix0;
32051 	i__1 = i2;
32052 	i__3 = inc;
32053 	for (i__ = i1; i__3 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__3) {
32054 	    ip = ipiv[ix];
32055 	    if (ip != i__) {
32056 		i__2 = *n;
32057 		for (k = n32; k <= i__2; ++k) {
32058 		    temp = a[i__ + k * a_dim1];
32059 		    a[i__ + k * a_dim1] = a[ip + k * a_dim1];
32060 		    a[ip + k * a_dim1] = temp;
32061 /* L40: */
32062 		}
32063 	    }
32064 	    ix += *incx;
32065 /* L50: */
32066 	}
32067     }
32068 
32069     return 0;
32070 
32071 /*     End of DLASWP */
32072 
32073 } /* dlaswp_ */
32074 
dlasy2_(logical * ltranl,logical * ltranr,integer * isgn,integer * n1,integer * n2,doublereal * tl,integer * ldtl,doublereal * tr,integer * ldtr,doublereal * b,integer * ldb,doublereal * scale,doublereal * x,integer * ldx,doublereal * xnorm,integer * info)32075 /* Subroutine */ int dlasy2_(logical *ltranl, logical *ltranr, integer *isgn,
32076 	integer *n1, integer *n2, doublereal *tl, integer *ldtl, doublereal *
32077 	tr, integer *ldtr, doublereal *b, integer *ldb, doublereal *scale,
32078 	doublereal *x, integer *ldx, doublereal *xnorm, integer *info)
32079 {
32080     /* Initialized data */
32081 
32082     static integer locu12[4] = { 3,4,1,2 };
32083     static integer locl21[4] = { 2,1,4,3 };
32084     static integer locu22[4] = { 4,3,2,1 };
32085     static logical xswpiv[4] = { FALSE_,FALSE_,TRUE_,TRUE_ };
32086     static logical bswpiv[4] = { FALSE_,TRUE_,FALSE_,TRUE_ };
32087 
32088     /* System generated locals */
32089     integer b_dim1, b_offset, tl_dim1, tl_offset, tr_dim1, tr_offset, x_dim1,
32090 	    x_offset;
32091     doublereal d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8;
32092 
32093     /* Local variables */
32094     static integer i__, j, k;
32095     static doublereal x2[2], l21, u11, u12;
32096     static integer ip, jp;
32097     static doublereal u22, t16[16]	/* was [4][4] */, gam, bet, eps, sgn,
32098 	    tmp[4], tau1, btmp[4], smin;
32099     static integer ipiv;
32100     static doublereal temp;
32101     static integer jpiv[4];
32102     static doublereal xmax;
32103     static integer ipsv, jpsv;
32104     static logical bswap;
32105     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
32106 	    doublereal *, integer *), dswap_(integer *, doublereal *, integer
32107 	    *, doublereal *, integer *);
32108     static logical xswap;
32109 
32110     extern integer idamax_(integer *, doublereal *, integer *);
32111     static doublereal smlnum;
32112 
32113 
32114 /*
32115     -- LAPACK auxiliary routine (version 3.2) --
32116     -- LAPACK is a software package provided by Univ. of Tennessee,    --
32117     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
32118        November 2006
32119 
32120 
32121     Purpose
32122     =======
32123 
32124     DLASY2 solves for the N1 by N2 matrix X, 1 <= N1,N2 <= 2, in
32125 
32126            op(TL)*X + ISGN*X*op(TR) = SCALE*B,
32127 
32128     where TL is N1 by N1, TR is N2 by N2, B is N1 by N2, and ISGN = 1 or
32129     -1.  op(T) = T or T', where T' denotes the transpose of T.
32130 
32131     Arguments
32132     =========
32133 
32134     LTRANL  (input) LOGICAL
32135             On entry, LTRANL specifies the op(TL):
32136                = .FALSE., op(TL) = TL,
32137                = .TRUE., op(TL) = TL'.
32138 
32139     LTRANR  (input) LOGICAL
32140             On entry, LTRANR specifies the op(TR):
32141               = .FALSE., op(TR) = TR,
32142               = .TRUE., op(TR) = TR'.
32143 
32144     ISGN    (input) INTEGER
32145             On entry, ISGN specifies the sign of the equation
32146             as described before. ISGN may only be 1 or -1.
32147 
32148     N1      (input) INTEGER
32149             On entry, N1 specifies the order of matrix TL.
32150             N1 may only be 0, 1 or 2.
32151 
32152     N2      (input) INTEGER
32153             On entry, N2 specifies the order of matrix TR.
32154             N2 may only be 0, 1 or 2.
32155 
32156     TL      (input) DOUBLE PRECISION array, dimension (LDTL,2)
32157             On entry, TL contains an N1 by N1 matrix.
32158 
32159     LDTL    (input) INTEGER
32160             The leading dimension of the matrix TL. LDTL >= max(1,N1).
32161 
32162     TR      (input) DOUBLE PRECISION array, dimension (LDTR,2)
32163             On entry, TR contains an N2 by N2 matrix.
32164 
32165     LDTR    (input) INTEGER
32166             The leading dimension of the matrix TR. LDTR >= max(1,N2).
32167 
32168     B       (input) DOUBLE PRECISION array, dimension (LDB,2)
32169             On entry, the N1 by N2 matrix B contains the right-hand
32170             side of the equation.
32171 
32172     LDB     (input) INTEGER
32173             The leading dimension of the matrix B. LDB >= max(1,N1).
32174 
32175     SCALE   (output) DOUBLE PRECISION
32176             On exit, SCALE contains the scale factor. SCALE is chosen
32177             less than or equal to 1 to prevent the solution overflowing.
32178 
32179     X       (output) DOUBLE PRECISION array, dimension (LDX,2)
32180             On exit, X contains the N1 by N2 solution.
32181 
32182     LDX     (input) INTEGER
32183             The leading dimension of the matrix X. LDX >= max(1,N1).
32184 
32185     XNORM   (output) DOUBLE PRECISION
32186             On exit, XNORM is the infinity-norm of the solution.
32187 
32188     INFO    (output) INTEGER
32189             On exit, INFO is set to
32190                0: successful exit.
32191                1: TL and TR have too close eigenvalues, so TL or
32192                   TR is perturbed to get a nonsingular equation.
32193             NOTE: In the interests of speed, this routine does not
32194                   check the inputs for errors.
32195 
32196    =====================================================================
32197 */
32198 
32199     /* Parameter adjustments */
32200     tl_dim1 = *ldtl;
32201     tl_offset = 1 + tl_dim1;
32202     tl -= tl_offset;
32203     tr_dim1 = *ldtr;
32204     tr_offset = 1 + tr_dim1;
32205     tr -= tr_offset;
32206     b_dim1 = *ldb;
32207     b_offset = 1 + b_dim1;
32208     b -= b_offset;
32209     x_dim1 = *ldx;
32210     x_offset = 1 + x_dim1;
32211     x -= x_offset;
32212 
32213     /* Function Body */
32214 
32215 /*     Do not check the input parameters for errors */
32216 
32217     *info = 0;
32218 
32219 /*     Quick return if possible */
32220 
32221     if (*n1 == 0 || *n2 == 0) {
32222 	return 0;
32223     }
32224 
32225 /*     Set constants to control overflow */
32226 
32227     eps = PRECISION;
32228     smlnum = SAFEMINIMUM / eps;
32229     sgn = (doublereal) (*isgn);
32230 
32231     k = *n1 + *n1 + *n2 - 2;
32232     switch (k) {
32233 	case 1:  goto L10;
32234 	case 2:  goto L20;
32235 	case 3:  goto L30;
32236 	case 4:  goto L50;
32237     }
32238 
32239 /*     1 by 1: TL11*X + SGN*X*TR11 = B11 */
32240 
32241 L10:
32242     tau1 = tl[tl_dim1 + 1] + sgn * tr[tr_dim1 + 1];
32243     bet = abs(tau1);
32244     if (bet <= smlnum) {
32245 	tau1 = smlnum;
32246 	bet = smlnum;
32247 	*info = 1;
32248     }
32249 
32250     *scale = 1.;
32251     gam = (d__1 = b[b_dim1 + 1], abs(d__1));
32252     if (smlnum * gam > bet) {
32253 	*scale = 1. / gam;
32254     }
32255 
32256     x[x_dim1 + 1] = b[b_dim1 + 1] * *scale / tau1;
32257     *xnorm = (d__1 = x[x_dim1 + 1], abs(d__1));
32258     return 0;
32259 
32260 /*
32261        1 by 2:
32262        TL11*[X11 X12] + ISGN*[X11 X12]*op[TR11 TR12]  = [B11 B12]
32263                                          [TR21 TR22]
32264 */
32265 
32266 L20:
32267 
32268 /*
32269    Computing MAX
32270    Computing MAX
32271 */
32272     d__7 = (d__1 = tl[tl_dim1 + 1], abs(d__1)), d__8 = (d__2 = tr[tr_dim1 + 1]
32273 	    , abs(d__2)), d__7 = max(d__7,d__8), d__8 = (d__3 = tr[(tr_dim1 <<
32274 	     1) + 1], abs(d__3)), d__7 = max(d__7,d__8), d__8 = (d__4 = tr[
32275 	    tr_dim1 + 2], abs(d__4)), d__7 = max(d__7,d__8), d__8 = (d__5 =
32276 	    tr[(tr_dim1 << 1) + 2], abs(d__5));
32277     d__6 = eps * max(d__7,d__8);
32278     smin = max(d__6,smlnum);
32279     tmp[0] = tl[tl_dim1 + 1] + sgn * tr[tr_dim1 + 1];
32280     tmp[3] = tl[tl_dim1 + 1] + sgn * tr[(tr_dim1 << 1) + 2];
32281     if (*ltranr) {
32282 	tmp[1] = sgn * tr[tr_dim1 + 2];
32283 	tmp[2] = sgn * tr[(tr_dim1 << 1) + 1];
32284     } else {
32285 	tmp[1] = sgn * tr[(tr_dim1 << 1) + 1];
32286 	tmp[2] = sgn * tr[tr_dim1 + 2];
32287     }
32288     btmp[0] = b[b_dim1 + 1];
32289     btmp[1] = b[(b_dim1 << 1) + 1];
32290     goto L40;
32291 
32292 /*
32293        2 by 1:
32294             op[TL11 TL12]*[X11] + ISGN* [X11]*TR11  = [B11]
32295               [TL21 TL22] [X21]         [X21]         [B21]
32296 */
32297 
32298 L30:
32299 /*
32300    Computing MAX
32301    Computing MAX
32302 */
32303     d__7 = (d__1 = tr[tr_dim1 + 1], abs(d__1)), d__8 = (d__2 = tl[tl_dim1 + 1]
32304 	    , abs(d__2)), d__7 = max(d__7,d__8), d__8 = (d__3 = tl[(tl_dim1 <<
32305 	     1) + 1], abs(d__3)), d__7 = max(d__7,d__8), d__8 = (d__4 = tl[
32306 	    tl_dim1 + 2], abs(d__4)), d__7 = max(d__7,d__8), d__8 = (d__5 =
32307 	    tl[(tl_dim1 << 1) + 2], abs(d__5));
32308     d__6 = eps * max(d__7,d__8);
32309     smin = max(d__6,smlnum);
32310     tmp[0] = tl[tl_dim1 + 1] + sgn * tr[tr_dim1 + 1];
32311     tmp[3] = tl[(tl_dim1 << 1) + 2] + sgn * tr[tr_dim1 + 1];
32312     if (*ltranl) {
32313 	tmp[1] = tl[(tl_dim1 << 1) + 1];
32314 	tmp[2] = tl[tl_dim1 + 2];
32315     } else {
32316 	tmp[1] = tl[tl_dim1 + 2];
32317 	tmp[2] = tl[(tl_dim1 << 1) + 1];
32318     }
32319     btmp[0] = b[b_dim1 + 1];
32320     btmp[1] = b[b_dim1 + 2];
32321 L40:
32322 
32323 /*
32324        Solve 2 by 2 system using complete pivoting.
32325        Set pivots less than SMIN to SMIN.
32326 */
32327 
32328     ipiv = idamax_(&c__4, tmp, &c__1);
32329     u11 = tmp[ipiv - 1];
32330     if (abs(u11) <= smin) {
32331 	*info = 1;
32332 	u11 = smin;
32333     }
32334     u12 = tmp[locu12[ipiv - 1] - 1];
32335     l21 = tmp[locl21[ipiv - 1] - 1] / u11;
32336     u22 = tmp[locu22[ipiv - 1] - 1] - u12 * l21;
32337     xswap = xswpiv[ipiv - 1];
32338     bswap = bswpiv[ipiv - 1];
32339     if (abs(u22) <= smin) {
32340 	*info = 1;
32341 	u22 = smin;
32342     }
32343     if (bswap) {
32344 	temp = btmp[1];
32345 	btmp[1] = btmp[0] - l21 * temp;
32346 	btmp[0] = temp;
32347     } else {
32348 	btmp[1] -= l21 * btmp[0];
32349     }
32350     *scale = 1.;
32351     if (smlnum * 2. * abs(btmp[1]) > abs(u22) || smlnum * 2. * abs(btmp[0]) >
32352 	    abs(u11)) {
32353 /* Computing MAX */
32354 	d__1 = abs(btmp[0]), d__2 = abs(btmp[1]);
32355 	*scale = .5 / max(d__1,d__2);
32356 	btmp[0] *= *scale;
32357 	btmp[1] *= *scale;
32358     }
32359     x2[1] = btmp[1] / u22;
32360     x2[0] = btmp[0] / u11 - u12 / u11 * x2[1];
32361     if (xswap) {
32362 	temp = x2[1];
32363 	x2[1] = x2[0];
32364 	x2[0] = temp;
32365     }
32366     x[x_dim1 + 1] = x2[0];
32367     if (*n1 == 1) {
32368 	x[(x_dim1 << 1) + 1] = x2[1];
32369 	*xnorm = (d__1 = x[x_dim1 + 1], abs(d__1)) + (d__2 = x[(x_dim1 << 1)
32370 		+ 1], abs(d__2));
32371     } else {
32372 	x[x_dim1 + 2] = x2[1];
32373 /* Computing MAX */
32374 	d__3 = (d__1 = x[x_dim1 + 1], abs(d__1)), d__4 = (d__2 = x[x_dim1 + 2]
32375 		, abs(d__2));
32376 	*xnorm = max(d__3,d__4);
32377     }
32378     return 0;
32379 
32380 /*
32381        2 by 2:
32382        op[TL11 TL12]*[X11 X12] +ISGN* [X11 X12]*op[TR11 TR12] = [B11 B12]
32383          [TL21 TL22] [X21 X22]        [X21 X22]   [TR21 TR22]   [B21 B22]
32384 
32385        Solve equivalent 4 by 4 system using complete pivoting.
32386        Set pivots less than SMIN to SMIN.
32387 */
32388 
32389 L50:
32390 /* Computing MAX */
32391     d__5 = (d__1 = tr[tr_dim1 + 1], abs(d__1)), d__6 = (d__2 = tr[(tr_dim1 <<
32392 	    1) + 1], abs(d__2)), d__5 = max(d__5,d__6), d__6 = (d__3 = tr[
32393 	    tr_dim1 + 2], abs(d__3)), d__5 = max(d__5,d__6), d__6 = (d__4 =
32394 	    tr[(tr_dim1 << 1) + 2], abs(d__4));
32395     smin = max(d__5,d__6);
32396 /* Computing MAX */
32397     d__5 = smin, d__6 = (d__1 = tl[tl_dim1 + 1], abs(d__1)), d__5 = max(d__5,
32398 	    d__6), d__6 = (d__2 = tl[(tl_dim1 << 1) + 1], abs(d__2)), d__5 =
32399 	    max(d__5,d__6), d__6 = (d__3 = tl[tl_dim1 + 2], abs(d__3)), d__5 =
32400 	     max(d__5,d__6), d__6 = (d__4 = tl[(tl_dim1 << 1) + 2], abs(d__4))
32401 	    ;
32402     smin = max(d__5,d__6);
32403 /* Computing MAX */
32404     d__1 = eps * smin;
32405     smin = max(d__1,smlnum);
32406     btmp[0] = 0.;
32407     dcopy_(&c__16, btmp, &c__0, t16, &c__1);
32408     t16[0] = tl[tl_dim1 + 1] + sgn * tr[tr_dim1 + 1];
32409     t16[5] = tl[(tl_dim1 << 1) + 2] + sgn * tr[tr_dim1 + 1];
32410     t16[10] = tl[tl_dim1 + 1] + sgn * tr[(tr_dim1 << 1) + 2];
32411     t16[15] = tl[(tl_dim1 << 1) + 2] + sgn * tr[(tr_dim1 << 1) + 2];
32412     if (*ltranl) {
32413 	t16[4] = tl[tl_dim1 + 2];
32414 	t16[1] = tl[(tl_dim1 << 1) + 1];
32415 	t16[14] = tl[tl_dim1 + 2];
32416 	t16[11] = tl[(tl_dim1 << 1) + 1];
32417     } else {
32418 	t16[4] = tl[(tl_dim1 << 1) + 1];
32419 	t16[1] = tl[tl_dim1 + 2];
32420 	t16[14] = tl[(tl_dim1 << 1) + 1];
32421 	t16[11] = tl[tl_dim1 + 2];
32422     }
32423     if (*ltranr) {
32424 	t16[8] = sgn * tr[(tr_dim1 << 1) + 1];
32425 	t16[13] = sgn * tr[(tr_dim1 << 1) + 1];
32426 	t16[2] = sgn * tr[tr_dim1 + 2];
32427 	t16[7] = sgn * tr[tr_dim1 + 2];
32428     } else {
32429 	t16[8] = sgn * tr[tr_dim1 + 2];
32430 	t16[13] = sgn * tr[tr_dim1 + 2];
32431 	t16[2] = sgn * tr[(tr_dim1 << 1) + 1];
32432 	t16[7] = sgn * tr[(tr_dim1 << 1) + 1];
32433     }
32434     btmp[0] = b[b_dim1 + 1];
32435     btmp[1] = b[b_dim1 + 2];
32436     btmp[2] = b[(b_dim1 << 1) + 1];
32437     btmp[3] = b[(b_dim1 << 1) + 2];
32438 
32439 /*     Perform elimination */
32440 
32441     for (i__ = 1; i__ <= 3; ++i__) {
32442 	xmax = 0.;
32443 	for (ip = i__; ip <= 4; ++ip) {
32444 	    for (jp = i__; jp <= 4; ++jp) {
32445 		if ((d__1 = t16[ip + (jp << 2) - 5], abs(d__1)) >= xmax) {
32446 		    xmax = (d__1 = t16[ip + (jp << 2) - 5], abs(d__1));
32447 		    ipsv = ip;
32448 		    jpsv = jp;
32449 		}
32450 /* L60: */
32451 	    }
32452 /* L70: */
32453 	}
32454 	if (ipsv != i__) {
32455 	    dswap_(&c__4, &t16[ipsv - 1], &c__4, &t16[i__ - 1], &c__4);
32456 	    temp = btmp[i__ - 1];
32457 	    btmp[i__ - 1] = btmp[ipsv - 1];
32458 	    btmp[ipsv - 1] = temp;
32459 	}
32460 	if (jpsv != i__) {
32461 	    dswap_(&c__4, &t16[(jpsv << 2) - 4], &c__1, &t16[(i__ << 2) - 4],
32462 		    &c__1);
32463 	}
32464 	jpiv[i__ - 1] = jpsv;
32465 	if ((d__1 = t16[i__ + (i__ << 2) - 5], abs(d__1)) < smin) {
32466 	    *info = 1;
32467 	    t16[i__ + (i__ << 2) - 5] = smin;
32468 	}
32469 	for (j = i__ + 1; j <= 4; ++j) {
32470 	    t16[j + (i__ << 2) - 5] /= t16[i__ + (i__ << 2) - 5];
32471 	    btmp[j - 1] -= t16[j + (i__ << 2) - 5] * btmp[i__ - 1];
32472 	    for (k = i__ + 1; k <= 4; ++k) {
32473 		t16[j + (k << 2) - 5] -= t16[j + (i__ << 2) - 5] * t16[i__ + (
32474 			k << 2) - 5];
32475 /* L80: */
32476 	    }
32477 /* L90: */
32478 	}
32479 /* L100: */
32480     }
32481     if (abs(t16[15]) < smin) {
32482 	t16[15] = smin;
32483     }
32484     *scale = 1.;
32485     if (smlnum * 8. * abs(btmp[0]) > abs(t16[0]) || smlnum * 8. * abs(btmp[1])
32486 	     > abs(t16[5]) || smlnum * 8. * abs(btmp[2]) > abs(t16[10]) ||
32487 	    smlnum * 8. * abs(btmp[3]) > abs(t16[15])) {
32488 /* Computing MAX */
32489 	d__1 = abs(btmp[0]), d__2 = abs(btmp[1]), d__1 = max(d__1,d__2), d__2
32490 		= abs(btmp[2]), d__1 = max(d__1,d__2), d__2 = abs(btmp[3]);
32491 	*scale = .125 / max(d__1,d__2);
32492 	btmp[0] *= *scale;
32493 	btmp[1] *= *scale;
32494 	btmp[2] *= *scale;
32495 	btmp[3] *= *scale;
32496     }
32497     for (i__ = 1; i__ <= 4; ++i__) {
32498 	k = 5 - i__;
32499 	temp = 1. / t16[k + (k << 2) - 5];
32500 	tmp[k - 1] = btmp[k - 1] * temp;
32501 	for (j = k + 1; j <= 4; ++j) {
32502 	    tmp[k - 1] -= temp * t16[k + (j << 2) - 5] * tmp[j - 1];
32503 /* L110: */
32504 	}
32505 /* L120: */
32506     }
32507     for (i__ = 1; i__ <= 3; ++i__) {
32508 	if (jpiv[4 - i__ - 1] != 4 - i__) {
32509 	    temp = tmp[4 - i__ - 1];
32510 	    tmp[4 - i__ - 1] = tmp[jpiv[4 - i__ - 1] - 1];
32511 	    tmp[jpiv[4 - i__ - 1] - 1] = temp;
32512 	}
32513 /* L130: */
32514     }
32515     x[x_dim1 + 1] = tmp[0];
32516     x[x_dim1 + 2] = tmp[1];
32517     x[(x_dim1 << 1) + 1] = tmp[2];
32518     x[(x_dim1 << 1) + 2] = tmp[3];
32519 /* Computing MAX */
32520     d__1 = abs(tmp[0]) + abs(tmp[2]), d__2 = abs(tmp[1]) + abs(tmp[3]);
32521     *xnorm = max(d__1,d__2);
32522     return 0;
32523 
32524 /*     End of DLASY2 */
32525 
32526 } /* dlasy2_ */
32527 
dlatrd_(char * uplo,integer * n,integer * nb,doublereal * a,integer * lda,doublereal * e,doublereal * tau,doublereal * w,integer * ldw)32528 /* Subroutine */ int dlatrd_(char *uplo, integer *n, integer *nb, doublereal *
32529 	a, integer *lda, doublereal *e, doublereal *tau, doublereal *w,
32530 	integer *ldw)
32531 {
32532     /* System generated locals */
32533     integer a_dim1, a_offset, w_dim1, w_offset, i__1, i__2, i__3;
32534 
32535     /* Local variables */
32536     static integer i__, iw;
32537     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
32538 	    integer *);
32539     static doublereal alpha;
32540     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
32541 	    integer *);
32542     extern logical lsame_(char *, char *);
32543     extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
32544 	    doublereal *, doublereal *, integer *, doublereal *, integer *,
32545 	    doublereal *, doublereal *, integer *), daxpy_(integer *,
32546 	    doublereal *, doublereal *, integer *, doublereal *, integer *),
32547 	    dsymv_(char *, integer *, doublereal *, doublereal *, integer *,
32548 	    doublereal *, integer *, doublereal *, doublereal *, integer *), dlarfg_(integer *, doublereal *, doublereal *, integer *,
32549 	     doublereal *);
32550 
32551 
32552 /*
32553     -- LAPACK auxiliary routine (version 3.2) --
32554     -- LAPACK is a software package provided by Univ. of Tennessee,    --
32555     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
32556        November 2006
32557 
32558 
32559     Purpose
32560     =======
32561 
32562     DLATRD reduces NB rows and columns of a real symmetric matrix A to
32563     symmetric tridiagonal form by an orthogonal similarity
32564     transformation Q' * A * Q, and returns the matrices V and W which are
32565     needed to apply the transformation to the unreduced part of A.
32566 
32567     If UPLO = 'U', DLATRD reduces the last NB rows and columns of a
32568     matrix, of which the upper triangle is supplied;
32569     if UPLO = 'L', DLATRD reduces the first NB rows and columns of a
32570     matrix, of which the lower triangle is supplied.
32571 
32572     This is an auxiliary routine called by DSYTRD.
32573 
32574     Arguments
32575     =========
32576 
32577     UPLO    (input) CHARACTER*1
32578             Specifies whether the upper or lower triangular part of the
32579             symmetric matrix A is stored:
32580             = 'U': Upper triangular
32581             = 'L': Lower triangular
32582 
32583     N       (input) INTEGER
32584             The order of the matrix A.
32585 
32586     NB      (input) INTEGER
32587             The number of rows and columns to be reduced.
32588 
32589     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
32590             On entry, the symmetric matrix A.  If UPLO = 'U', the leading
32591             n-by-n upper triangular part of A contains the upper
32592             triangular part of the matrix A, and the strictly lower
32593             triangular part of A is not referenced.  If UPLO = 'L', the
32594             leading n-by-n lower triangular part of A contains the lower
32595             triangular part of the matrix A, and the strictly upper
32596             triangular part of A is not referenced.
32597             On exit:
32598             if UPLO = 'U', the last NB columns have been reduced to
32599               tridiagonal form, with the diagonal elements overwriting
32600               the diagonal elements of A; the elements above the diagonal
32601               with the array TAU, represent the orthogonal matrix Q as a
32602               product of elementary reflectors;
32603             if UPLO = 'L', the first NB columns have been reduced to
32604               tridiagonal form, with the diagonal elements overwriting
32605               the diagonal elements of A; the elements below the diagonal
32606               with the array TAU, represent the  orthogonal matrix Q as a
32607               product of elementary reflectors.
32608             See Further Details.
32609 
32610     LDA     (input) INTEGER
32611             The leading dimension of the array A.  LDA >= (1,N).
32612 
32613     E       (output) DOUBLE PRECISION array, dimension (N-1)
32614             If UPLO = 'U', E(n-nb:n-1) contains the superdiagonal
32615             elements of the last NB columns of the reduced matrix;
32616             if UPLO = 'L', E(1:nb) contains the subdiagonal elements of
32617             the first NB columns of the reduced matrix.
32618 
32619     TAU     (output) DOUBLE PRECISION array, dimension (N-1)
32620             The scalar factors of the elementary reflectors, stored in
32621             TAU(n-nb:n-1) if UPLO = 'U', and in TAU(1:nb) if UPLO = 'L'.
32622             See Further Details.
32623 
32624     W       (output) DOUBLE PRECISION array, dimension (LDW,NB)
32625             The n-by-nb matrix W required to update the unreduced part
32626             of A.
32627 
32628     LDW     (input) INTEGER
32629             The leading dimension of the array W. LDW >= max(1,N).
32630 
32631     Further Details
32632     ===============
32633 
32634     If UPLO = 'U', the matrix Q is represented as a product of elementary
32635     reflectors
32636 
32637        Q = H(n) H(n-1) . . . H(n-nb+1).
32638 
32639     Each H(i) has the form
32640 
32641        H(i) = I - tau * v * v'
32642 
32643     where tau is a real scalar, and v is a real vector with
32644     v(i:n) = 0 and v(i-1) = 1; v(1:i-1) is stored on exit in A(1:i-1,i),
32645     and tau in TAU(i-1).
32646 
32647     If UPLO = 'L', the matrix Q is represented as a product of elementary
32648     reflectors
32649 
32650        Q = H(1) H(2) . . . H(nb).
32651 
32652     Each H(i) has the form
32653 
32654        H(i) = I - tau * v * v'
32655 
32656     where tau is a real scalar, and v is a real vector with
32657     v(1:i) = 0 and v(i+1) = 1; v(i+1:n) is stored on exit in A(i+1:n,i),
32658     and tau in TAU(i).
32659 
32660     The elements of the vectors v together form the n-by-nb matrix V
32661     which is needed, with W, to apply the transformation to the unreduced
32662     part of the matrix, using a symmetric rank-2k update of the form:
32663     A := A - V*W' - W*V'.
32664 
32665     The contents of A on exit are illustrated by the following examples
32666     with n = 5 and nb = 2:
32667 
32668     if UPLO = 'U':                       if UPLO = 'L':
32669 
32670       (  a   a   a   v4  v5 )              (  d                  )
32671       (      a   a   v4  v5 )              (  1   d              )
32672       (          a   1   v5 )              (  v1  1   a          )
32673       (              d   1  )              (  v1  v2  a   a      )
32674       (                  d  )              (  v1  v2  a   a   a  )
32675 
32676     where d denotes a diagonal element of the reduced matrix, a denotes
32677     an element of the original matrix that is unchanged, and vi denotes
32678     an element of the vector defining H(i).
32679 
32680     =====================================================================
32681 
32682 
32683        Quick return if possible
32684 */
32685 
32686     /* Parameter adjustments */
32687     a_dim1 = *lda;
32688     a_offset = 1 + a_dim1;
32689     a -= a_offset;
32690     --e;
32691     --tau;
32692     w_dim1 = *ldw;
32693     w_offset = 1 + w_dim1;
32694     w -= w_offset;
32695 
32696     /* Function Body */
32697     if (*n <= 0) {
32698 	return 0;
32699     }
32700 
32701     if (lsame_(uplo, "U")) {
32702 
32703 /*        Reduce last NB columns of upper triangle */
32704 
32705 	i__1 = *n - *nb + 1;
32706 	for (i__ = *n; i__ >= i__1; --i__) {
32707 	    iw = i__ - *n + *nb;
32708 	    if (i__ < *n) {
32709 
32710 /*              Update A(1:i,i) */
32711 
32712 		i__2 = *n - i__;
32713 		dgemv_("No transpose", &i__, &i__2, &c_b151, &a[(i__ + 1) *
32714 			a_dim1 + 1], lda, &w[i__ + (iw + 1) * w_dim1], ldw, &
32715 			c_b15, &a[i__ * a_dim1 + 1], &c__1);
32716 		i__2 = *n - i__;
32717 		dgemv_("No transpose", &i__, &i__2, &c_b151, &w[(iw + 1) *
32718 			w_dim1 + 1], ldw, &a[i__ + (i__ + 1) * a_dim1], lda, &
32719 			c_b15, &a[i__ * a_dim1 + 1], &c__1);
32720 	    }
32721 	    if (i__ > 1) {
32722 
32723 /*
32724                 Generate elementary reflector H(i) to annihilate
32725                 A(1:i-2,i)
32726 */
32727 
32728 		i__2 = i__ - 1;
32729 		dlarfg_(&i__2, &a[i__ - 1 + i__ * a_dim1], &a[i__ * a_dim1 +
32730 			1], &c__1, &tau[i__ - 1]);
32731 		e[i__ - 1] = a[i__ - 1 + i__ * a_dim1];
32732 		a[i__ - 1 + i__ * a_dim1] = 1.;
32733 
32734 /*              Compute W(1:i-1,i) */
32735 
32736 		i__2 = i__ - 1;
32737 		dsymv_("Upper", &i__2, &c_b15, &a[a_offset], lda, &a[i__ *
32738 			a_dim1 + 1], &c__1, &c_b29, &w[iw * w_dim1 + 1], &
32739 			c__1);
32740 		if (i__ < *n) {
32741 		    i__2 = i__ - 1;
32742 		    i__3 = *n - i__;
32743 		    dgemv_("Transpose", &i__2, &i__3, &c_b15, &w[(iw + 1) *
32744 			    w_dim1 + 1], ldw, &a[i__ * a_dim1 + 1], &c__1, &
32745 			    c_b29, &w[i__ + 1 + iw * w_dim1], &c__1);
32746 		    i__2 = i__ - 1;
32747 		    i__3 = *n - i__;
32748 		    dgemv_("No transpose", &i__2, &i__3, &c_b151, &a[(i__ + 1)
32749 			     * a_dim1 + 1], lda, &w[i__ + 1 + iw * w_dim1], &
32750 			    c__1, &c_b15, &w[iw * w_dim1 + 1], &c__1);
32751 		    i__2 = i__ - 1;
32752 		    i__3 = *n - i__;
32753 		    dgemv_("Transpose", &i__2, &i__3, &c_b15, &a[(i__ + 1) *
32754 			    a_dim1 + 1], lda, &a[i__ * a_dim1 + 1], &c__1, &
32755 			    c_b29, &w[i__ + 1 + iw * w_dim1], &c__1);
32756 		    i__2 = i__ - 1;
32757 		    i__3 = *n - i__;
32758 		    dgemv_("No transpose", &i__2, &i__3, &c_b151, &w[(iw + 1)
32759 			    * w_dim1 + 1], ldw, &w[i__ + 1 + iw * w_dim1], &
32760 			    c__1, &c_b15, &w[iw * w_dim1 + 1], &c__1);
32761 		}
32762 		i__2 = i__ - 1;
32763 		dscal_(&i__2, &tau[i__ - 1], &w[iw * w_dim1 + 1], &c__1);
32764 		i__2 = i__ - 1;
32765 		alpha = tau[i__ - 1] * -.5 * ddot_(&i__2, &w[iw * w_dim1 + 1],
32766 			 &c__1, &a[i__ * a_dim1 + 1], &c__1);
32767 		i__2 = i__ - 1;
32768 		daxpy_(&i__2, &alpha, &a[i__ * a_dim1 + 1], &c__1, &w[iw *
32769 			w_dim1 + 1], &c__1);
32770 	    }
32771 
32772 /* L10: */
32773 	}
32774     } else {
32775 
32776 /*        Reduce first NB columns of lower triangle */
32777 
32778 	i__1 = *nb;
32779 	for (i__ = 1; i__ <= i__1; ++i__) {
32780 
32781 /*           Update A(i:n,i) */
32782 
32783 	    i__2 = *n - i__ + 1;
32784 	    i__3 = i__ - 1;
32785 	    dgemv_("No transpose", &i__2, &i__3, &c_b151, &a[i__ + a_dim1],
32786 		    lda, &w[i__ + w_dim1], ldw, &c_b15, &a[i__ + i__ * a_dim1]
32787 		    , &c__1);
32788 	    i__2 = *n - i__ + 1;
32789 	    i__3 = i__ - 1;
32790 	    dgemv_("No transpose", &i__2, &i__3, &c_b151, &w[i__ + w_dim1],
32791 		    ldw, &a[i__ + a_dim1], lda, &c_b15, &a[i__ + i__ * a_dim1]
32792 		    , &c__1);
32793 	    if (i__ < *n) {
32794 
32795 /*
32796                 Generate elementary reflector H(i) to annihilate
32797                 A(i+2:n,i)
32798 */
32799 
32800 		i__2 = *n - i__;
32801 /* Computing MIN */
32802 		i__3 = i__ + 2;
32803 		dlarfg_(&i__2, &a[i__ + 1 + i__ * a_dim1], &a[min(i__3,*n) +
32804 			i__ * a_dim1], &c__1, &tau[i__]);
32805 		e[i__] = a[i__ + 1 + i__ * a_dim1];
32806 		a[i__ + 1 + i__ * a_dim1] = 1.;
32807 
32808 /*              Compute W(i+1:n,i) */
32809 
32810 		i__2 = *n - i__;
32811 		dsymv_("Lower", &i__2, &c_b15, &a[i__ + 1 + (i__ + 1) *
32812 			a_dim1], lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &
32813 			c_b29, &w[i__ + 1 + i__ * w_dim1], &c__1);
32814 		i__2 = *n - i__;
32815 		i__3 = i__ - 1;
32816 		dgemv_("Transpose", &i__2, &i__3, &c_b15, &w[i__ + 1 + w_dim1]
32817 			, ldw, &a[i__ + 1 + i__ * a_dim1], &c__1, &c_b29, &w[
32818 			i__ * w_dim1 + 1], &c__1);
32819 		i__2 = *n - i__;
32820 		i__3 = i__ - 1;
32821 		dgemv_("No transpose", &i__2, &i__3, &c_b151, &a[i__ + 1 +
32822 			a_dim1], lda, &w[i__ * w_dim1 + 1], &c__1, &c_b15, &w[
32823 			i__ + 1 + i__ * w_dim1], &c__1);
32824 		i__2 = *n - i__;
32825 		i__3 = i__ - 1;
32826 		dgemv_("Transpose", &i__2, &i__3, &c_b15, &a[i__ + 1 + a_dim1]
32827 			, lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &c_b29, &w[
32828 			i__ * w_dim1 + 1], &c__1);
32829 		i__2 = *n - i__;
32830 		i__3 = i__ - 1;
32831 		dgemv_("No transpose", &i__2, &i__3, &c_b151, &w[i__ + 1 +
32832 			w_dim1], ldw, &w[i__ * w_dim1 + 1], &c__1, &c_b15, &w[
32833 			i__ + 1 + i__ * w_dim1], &c__1);
32834 		i__2 = *n - i__;
32835 		dscal_(&i__2, &tau[i__], &w[i__ + 1 + i__ * w_dim1], &c__1);
32836 		i__2 = *n - i__;
32837 		alpha = tau[i__] * -.5 * ddot_(&i__2, &w[i__ + 1 + i__ *
32838 			w_dim1], &c__1, &a[i__ + 1 + i__ * a_dim1], &c__1);
32839 		i__2 = *n - i__;
32840 		daxpy_(&i__2, &alpha, &a[i__ + 1 + i__ * a_dim1], &c__1, &w[
32841 			i__ + 1 + i__ * w_dim1], &c__1);
32842 	    }
32843 
32844 /* L20: */
32845 	}
32846     }
32847 
32848     return 0;
32849 
32850 /*     End of DLATRD */
32851 
32852 } /* dlatrd_ */
32853 
dlauu2_(char * uplo,integer * n,doublereal * a,integer * lda,integer * info)32854 /* Subroutine */ int dlauu2_(char *uplo, integer *n, doublereal *a, integer *
32855 	lda, integer *info)
32856 {
32857     /* System generated locals */
32858     integer a_dim1, a_offset, i__1, i__2, i__3;
32859 
32860     /* Local variables */
32861     static integer i__;
32862     static doublereal aii;
32863     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
32864 	    integer *);
32865     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
32866 	    integer *);
32867     extern logical lsame_(char *, char *);
32868     extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
32869 	    doublereal *, doublereal *, integer *, doublereal *, integer *,
32870 	    doublereal *, doublereal *, integer *);
32871     static logical upper;
32872     extern /* Subroutine */ int xerbla_(char *, integer *);
32873 
32874 
32875 /*
32876     -- LAPACK auxiliary routine (version 3.2) --
32877     -- LAPACK is a software package provided by Univ. of Tennessee,    --
32878     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
32879        November 2006
32880 
32881 
32882     Purpose
32883     =======
32884 
32885     DLAUU2 computes the product U * U' or L' * L, where the triangular
32886     factor U or L is stored in the upper or lower triangular part of
32887     the array A.
32888 
32889     If UPLO = 'U' or 'u' then the upper triangle of the result is stored,
32890     overwriting the factor U in A.
32891     If UPLO = 'L' or 'l' then the lower triangle of the result is stored,
32892     overwriting the factor L in A.
32893 
32894     This is the unblocked form of the algorithm, calling Level 2 BLAS.
32895 
32896     Arguments
32897     =========
32898 
32899     UPLO    (input) CHARACTER*1
32900             Specifies whether the triangular factor stored in the array A
32901             is upper or lower triangular:
32902             = 'U':  Upper triangular
32903             = 'L':  Lower triangular
32904 
32905     N       (input) INTEGER
32906             The order of the triangular factor U or L.  N >= 0.
32907 
32908     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
32909             On entry, the triangular factor U or L.
32910             On exit, if UPLO = 'U', the upper triangle of A is
32911             overwritten with the upper triangle of the product U * U';
32912             if UPLO = 'L', the lower triangle of A is overwritten with
32913             the lower triangle of the product L' * L.
32914 
32915     LDA     (input) INTEGER
32916             The leading dimension of the array A.  LDA >= max(1,N).
32917 
32918     INFO    (output) INTEGER
32919             = 0: successful exit
32920             < 0: if INFO = -k, the k-th argument had an illegal value
32921 
32922     =====================================================================
32923 
32924 
32925        Test the input parameters.
32926 */
32927 
32928     /* Parameter adjustments */
32929     a_dim1 = *lda;
32930     a_offset = 1 + a_dim1;
32931     a -= a_offset;
32932 
32933     /* Function Body */
32934     *info = 0;
32935     upper = lsame_(uplo, "U");
32936     if (! upper && ! lsame_(uplo, "L")) {
32937 	*info = -1;
32938     } else if (*n < 0) {
32939 	*info = -2;
32940     } else if (*lda < max(1,*n)) {
32941 	*info = -4;
32942     }
32943     if (*info != 0) {
32944 	i__1 = -(*info);
32945 	xerbla_("DLAUU2", &i__1);
32946 	return 0;
32947     }
32948 
32949 /*     Quick return if possible */
32950 
32951     if (*n == 0) {
32952 	return 0;
32953     }
32954 
32955     if (upper) {
32956 
32957 /*        Compute the product U * U'. */
32958 
32959 	i__1 = *n;
32960 	for (i__ = 1; i__ <= i__1; ++i__) {
32961 	    aii = a[i__ + i__ * a_dim1];
32962 	    if (i__ < *n) {
32963 		i__2 = *n - i__ + 1;
32964 		a[i__ + i__ * a_dim1] = ddot_(&i__2, &a[i__ + i__ * a_dim1],
32965 			lda, &a[i__ + i__ * a_dim1], lda);
32966 		i__2 = i__ - 1;
32967 		i__3 = *n - i__;
32968 		dgemv_("No transpose", &i__2, &i__3, &c_b15, &a[(i__ + 1) *
32969 			a_dim1 + 1], lda, &a[i__ + (i__ + 1) * a_dim1], lda, &
32970 			aii, &a[i__ * a_dim1 + 1], &c__1);
32971 	    } else {
32972 		dscal_(&i__, &aii, &a[i__ * a_dim1 + 1], &c__1);
32973 	    }
32974 /* L10: */
32975 	}
32976 
32977     } else {
32978 
32979 /*        Compute the product L' * L. */
32980 
32981 	i__1 = *n;
32982 	for (i__ = 1; i__ <= i__1; ++i__) {
32983 	    aii = a[i__ + i__ * a_dim1];
32984 	    if (i__ < *n) {
32985 		i__2 = *n - i__ + 1;
32986 		a[i__ + i__ * a_dim1] = ddot_(&i__2, &a[i__ + i__ * a_dim1], &
32987 			c__1, &a[i__ + i__ * a_dim1], &c__1);
32988 		i__2 = *n - i__;
32989 		i__3 = i__ - 1;
32990 		dgemv_("Transpose", &i__2, &i__3, &c_b15, &a[i__ + 1 + a_dim1]
32991 			, lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &aii, &a[
32992 			i__ + a_dim1], lda);
32993 	    } else {
32994 		dscal_(&i__, &aii, &a[i__ + a_dim1], lda);
32995 	    }
32996 /* L20: */
32997 	}
32998     }
32999 
33000     return 0;
33001 
33002 /*     End of DLAUU2 */
33003 
33004 } /* dlauu2_ */
33005 
dlauum_(char * uplo,integer * n,doublereal * a,integer * lda,integer * info)33006 /* Subroutine */ int dlauum_(char *uplo, integer *n, doublereal *a, integer *
33007 	lda, integer *info)
33008 {
33009     /* System generated locals */
33010     integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
33011 
33012     /* Local variables */
33013     static integer i__, ib, nb;
33014     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
33015 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
33016 	    integer *, doublereal *, doublereal *, integer *);
33017     extern logical lsame_(char *, char *);
33018     extern /* Subroutine */ int dtrmm_(char *, char *, char *, char *,
33019 	    integer *, integer *, doublereal *, doublereal *, integer *,
33020 	    doublereal *, integer *);
33021     static logical upper;
33022     extern /* Subroutine */ int dsyrk_(char *, char *, integer *, integer *,
33023 	    doublereal *, doublereal *, integer *, doublereal *, doublereal *,
33024 	     integer *), dlauu2_(char *, integer *,
33025 	    doublereal *, integer *, integer *), xerbla_(char *,
33026 	    integer *);
33027     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
33028 	    integer *, integer *, ftnlen, ftnlen);
33029 
33030 
33031 /*
33032     -- LAPACK auxiliary routine (version 3.2) --
33033     -- LAPACK is a software package provided by Univ. of Tennessee,    --
33034     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
33035        November 2006
33036 
33037 
33038     Purpose
33039     =======
33040 
33041     DLAUUM computes the product U * U' or L' * L, where the triangular
33042     factor U or L is stored in the upper or lower triangular part of
33043     the array A.
33044 
33045     If UPLO = 'U' or 'u' then the upper triangle of the result is stored,
33046     overwriting the factor U in A.
33047     If UPLO = 'L' or 'l' then the lower triangle of the result is stored,
33048     overwriting the factor L in A.
33049 
33050     This is the blocked form of the algorithm, calling Level 3 BLAS.
33051 
33052     Arguments
33053     =========
33054 
33055     UPLO    (input) CHARACTER*1
33056             Specifies whether the triangular factor stored in the array A
33057             is upper or lower triangular:
33058             = 'U':  Upper triangular
33059             = 'L':  Lower triangular
33060 
33061     N       (input) INTEGER
33062             The order of the triangular factor U or L.  N >= 0.
33063 
33064     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
33065             On entry, the triangular factor U or L.
33066             On exit, if UPLO = 'U', the upper triangle of A is
33067             overwritten with the upper triangle of the product U * U';
33068             if UPLO = 'L', the lower triangle of A is overwritten with
33069             the lower triangle of the product L' * L.
33070 
33071     LDA     (input) INTEGER
33072             The leading dimension of the array A.  LDA >= max(1,N).
33073 
33074     INFO    (output) INTEGER
33075             = 0: successful exit
33076             < 0: if INFO = -k, the k-th argument had an illegal value
33077 
33078     =====================================================================
33079 
33080 
33081        Test the input parameters.
33082 */
33083 
33084     /* Parameter adjustments */
33085     a_dim1 = *lda;
33086     a_offset = 1 + a_dim1;
33087     a -= a_offset;
33088 
33089     /* Function Body */
33090     *info = 0;
33091     upper = lsame_(uplo, "U");
33092     if (! upper && ! lsame_(uplo, "L")) {
33093 	*info = -1;
33094     } else if (*n < 0) {
33095 	*info = -2;
33096     } else if (*lda < max(1,*n)) {
33097 	*info = -4;
33098     }
33099     if (*info != 0) {
33100 	i__1 = -(*info);
33101 	xerbla_("DLAUUM", &i__1);
33102 	return 0;
33103     }
33104 
33105 /*     Quick return if possible */
33106 
33107     if (*n == 0) {
33108 	return 0;
33109     }
33110 
33111 /*     Determine the block size for this environment. */
33112 
33113     nb = ilaenv_(&c__1, "DLAUUM", uplo, n, &c_n1, &c_n1, &c_n1, (ftnlen)6, (
33114 	    ftnlen)1);
33115 
33116     if (nb <= 1 || nb >= *n) {
33117 
33118 /*        Use unblocked code */
33119 
33120 	dlauu2_(uplo, n, &a[a_offset], lda, info);
33121     } else {
33122 
33123 /*        Use blocked code */
33124 
33125 	if (upper) {
33126 
33127 /*           Compute the product U * U'. */
33128 
33129 	    i__1 = *n;
33130 	    i__2 = nb;
33131 	    for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
33132 /* Computing MIN */
33133 		i__3 = nb, i__4 = *n - i__ + 1;
33134 		ib = min(i__3,i__4);
33135 		i__3 = i__ - 1;
33136 		dtrmm_("Right", "Upper", "Transpose", "Non-unit", &i__3, &ib,
33137 			&c_b15, &a[i__ + i__ * a_dim1], lda, &a[i__ * a_dim1
33138 			+ 1], lda)
33139 			;
33140 		dlauu2_("Upper", &ib, &a[i__ + i__ * a_dim1], lda, info);
33141 		if (i__ + ib <= *n) {
33142 		    i__3 = i__ - 1;
33143 		    i__4 = *n - i__ - ib + 1;
33144 		    dgemm_("No transpose", "Transpose", &i__3, &ib, &i__4, &
33145 			    c_b15, &a[(i__ + ib) * a_dim1 + 1], lda, &a[i__ +
33146 			    (i__ + ib) * a_dim1], lda, &c_b15, &a[i__ *
33147 			    a_dim1 + 1], lda);
33148 		    i__3 = *n - i__ - ib + 1;
33149 		    dsyrk_("Upper", "No transpose", &ib, &i__3, &c_b15, &a[
33150 			    i__ + (i__ + ib) * a_dim1], lda, &c_b15, &a[i__ +
33151 			    i__ * a_dim1], lda);
33152 		}
33153 /* L10: */
33154 	    }
33155 	} else {
33156 
33157 /*           Compute the product L' * L. */
33158 
33159 	    i__2 = *n;
33160 	    i__1 = nb;
33161 	    for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__1) {
33162 /* Computing MIN */
33163 		i__3 = nb, i__4 = *n - i__ + 1;
33164 		ib = min(i__3,i__4);
33165 		i__3 = i__ - 1;
33166 		dtrmm_("Left", "Lower", "Transpose", "Non-unit", &ib, &i__3, &
33167 			c_b15, &a[i__ + i__ * a_dim1], lda, &a[i__ + a_dim1],
33168 			lda);
33169 		dlauu2_("Lower", &ib, &a[i__ + i__ * a_dim1], lda, info);
33170 		if (i__ + ib <= *n) {
33171 		    i__3 = i__ - 1;
33172 		    i__4 = *n - i__ - ib + 1;
33173 		    dgemm_("Transpose", "No transpose", &ib, &i__3, &i__4, &
33174 			    c_b15, &a[i__ + ib + i__ * a_dim1], lda, &a[i__ +
33175 			    ib + a_dim1], lda, &c_b15, &a[i__ + a_dim1], lda);
33176 		    i__3 = *n - i__ - ib + 1;
33177 		    dsyrk_("Lower", "Transpose", &ib, &i__3, &c_b15, &a[i__ +
33178 			    ib + i__ * a_dim1], lda, &c_b15, &a[i__ + i__ *
33179 			    a_dim1], lda);
33180 		}
33181 /* L20: */
33182 	    }
33183 	}
33184     }
33185 
33186     return 0;
33187 
33188 /*     End of DLAUUM */
33189 
33190 } /* dlauum_ */
33191 
dorg2r_(integer * m,integer * n,integer * k,doublereal * a,integer * lda,doublereal * tau,doublereal * work,integer * info)33192 /* Subroutine */ int dorg2r_(integer *m, integer *n, integer *k, doublereal *
33193 	a, integer *lda, doublereal *tau, doublereal *work, integer *info)
33194 {
33195     /* System generated locals */
33196     integer a_dim1, a_offset, i__1, i__2;
33197     doublereal d__1;
33198 
33199     /* Local variables */
33200     static integer i__, j, l;
33201     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
33202 	    integer *), dlarf_(char *, integer *, integer *, doublereal *,
33203 	    integer *, doublereal *, doublereal *, integer *, doublereal *), xerbla_(char *, integer *);
33204 
33205 
33206 /*
33207     -- LAPACK routine (version 3.2) --
33208     -- LAPACK is a software package provided by Univ. of Tennessee,    --
33209     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
33210        November 2006
33211 
33212 
33213     Purpose
33214     =======
33215 
33216     DORG2R generates an m by n real matrix Q with orthonormal columns,
33217     which is defined as the first n columns of a product of k elementary
33218     reflectors of order m
33219 
33220           Q  =  H(1) H(2) . . . H(k)
33221 
33222     as returned by DGEQRF.
33223 
33224     Arguments
33225     =========
33226 
33227     M       (input) INTEGER
33228             The number of rows of the matrix Q. M >= 0.
33229 
33230     N       (input) INTEGER
33231             The number of columns of the matrix Q. M >= N >= 0.
33232 
33233     K       (input) INTEGER
33234             The number of elementary reflectors whose product defines the
33235             matrix Q. N >= K >= 0.
33236 
33237     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
33238             On entry, the i-th column must contain the vector which
33239             defines the elementary reflector H(i), for i = 1,2,...,k, as
33240             returned by DGEQRF in the first k columns of its array
33241             argument A.
33242             On exit, the m-by-n matrix Q.
33243 
33244     LDA     (input) INTEGER
33245             The first dimension of the array A. LDA >= max(1,M).
33246 
33247     TAU     (input) DOUBLE PRECISION array, dimension (K)
33248             TAU(i) must contain the scalar factor of the elementary
33249             reflector H(i), as returned by DGEQRF.
33250 
33251     WORK    (workspace) DOUBLE PRECISION array, dimension (N)
33252 
33253     INFO    (output) INTEGER
33254             = 0: successful exit
33255             < 0: if INFO = -i, the i-th argument has an illegal value
33256 
33257     =====================================================================
33258 
33259 
33260        Test the input arguments
33261 */
33262 
33263     /* Parameter adjustments */
33264     a_dim1 = *lda;
33265     a_offset = 1 + a_dim1;
33266     a -= a_offset;
33267     --tau;
33268     --work;
33269 
33270     /* Function Body */
33271     *info = 0;
33272     if (*m < 0) {
33273 	*info = -1;
33274     } else if (*n < 0 || *n > *m) {
33275 	*info = -2;
33276     } else if (*k < 0 || *k > *n) {
33277 	*info = -3;
33278     } else if (*lda < max(1,*m)) {
33279 	*info = -5;
33280     }
33281     if (*info != 0) {
33282 	i__1 = -(*info);
33283 	xerbla_("DORG2R", &i__1);
33284 	return 0;
33285     }
33286 
33287 /*     Quick return if possible */
33288 
33289     if (*n <= 0) {
33290 	return 0;
33291     }
33292 
33293 /*     Initialise columns k+1:n to columns of the unit matrix */
33294 
33295     i__1 = *n;
33296     for (j = *k + 1; j <= i__1; ++j) {
33297 	i__2 = *m;
33298 	for (l = 1; l <= i__2; ++l) {
33299 	    a[l + j * a_dim1] = 0.;
33300 /* L10: */
33301 	}
33302 	a[j + j * a_dim1] = 1.;
33303 /* L20: */
33304     }
33305 
33306     for (i__ = *k; i__ >= 1; --i__) {
33307 
33308 /*        Apply H(i) to A(i:m,i:n) from the left */
33309 
33310 	if (i__ < *n) {
33311 	    a[i__ + i__ * a_dim1] = 1.;
33312 	    i__1 = *m - i__ + 1;
33313 	    i__2 = *n - i__;
33314 	    dlarf_("Left", &i__1, &i__2, &a[i__ + i__ * a_dim1], &c__1, &tau[
33315 		    i__], &a[i__ + (i__ + 1) * a_dim1], lda, &work[1]);
33316 	}
33317 	if (i__ < *m) {
33318 	    i__1 = *m - i__;
33319 	    d__1 = -tau[i__];
33320 	    dscal_(&i__1, &d__1, &a[i__ + 1 + i__ * a_dim1], &c__1);
33321 	}
33322 	a[i__ + i__ * a_dim1] = 1. - tau[i__];
33323 
33324 /*        Set A(1:i-1,i) to zero */
33325 
33326 	i__1 = i__ - 1;
33327 	for (l = 1; l <= i__1; ++l) {
33328 	    a[l + i__ * a_dim1] = 0.;
33329 /* L30: */
33330 	}
33331 /* L40: */
33332     }
33333     return 0;
33334 
33335 /*     End of DORG2R */
33336 
33337 } /* dorg2r_ */
33338 
dorgbr_(char * vect,integer * m,integer * n,integer * k,doublereal * a,integer * lda,doublereal * tau,doublereal * work,integer * lwork,integer * info)33339 /* Subroutine */ int dorgbr_(char *vect, integer *m, integer *n, integer *k,
33340 	doublereal *a, integer *lda, doublereal *tau, doublereal *work,
33341 	integer *lwork, integer *info)
33342 {
33343     /* System generated locals */
33344     integer a_dim1, a_offset, i__1, i__2, i__3;
33345 
33346     /* Local variables */
33347     static integer i__, j, nb, mn;
33348     extern logical lsame_(char *, char *);
33349     static integer iinfo;
33350     static logical wantq;
33351     extern /* Subroutine */ int xerbla_(char *, integer *);
33352     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
33353 	    integer *, integer *, ftnlen, ftnlen);
33354     extern /* Subroutine */ int dorglq_(integer *, integer *, integer *,
33355 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
33356 	    integer *), dorgqr_(integer *, integer *, integer *, doublereal *,
33357 	     integer *, doublereal *, doublereal *, integer *, integer *);
33358     static integer lwkopt;
33359     static logical lquery;
33360 
33361 
33362 /*
33363     -- LAPACK routine (version 3.2) --
33364     -- LAPACK is a software package provided by Univ. of Tennessee,    --
33365     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
33366        November 2006
33367 
33368 
33369     Purpose
33370     =======
33371 
33372     DORGBR generates one of the real orthogonal matrices Q or P**T
33373     determined by DGEBRD when reducing a real matrix A to bidiagonal
33374     form: A = Q * B * P**T.  Q and P**T are defined as products of
33375     elementary reflectors H(i) or G(i) respectively.
33376 
33377     If VECT = 'Q', A is assumed to have been an M-by-K matrix, and Q
33378     is of order M:
33379     if m >= k, Q = H(1) H(2) . . . H(k) and DORGBR returns the first n
33380     columns of Q, where m >= n >= k;
33381     if m < k, Q = H(1) H(2) . . . H(m-1) and DORGBR returns Q as an
33382     M-by-M matrix.
33383 
33384     If VECT = 'P', A is assumed to have been a K-by-N matrix, and P**T
33385     is of order N:
33386     if k < n, P**T = G(k) . . . G(2) G(1) and DORGBR returns the first m
33387     rows of P**T, where n >= m >= k;
33388     if k >= n, P**T = G(n-1) . . . G(2) G(1) and DORGBR returns P**T as
33389     an N-by-N matrix.
33390 
33391     Arguments
33392     =========
33393 
33394     VECT    (input) CHARACTER*1
33395             Specifies whether the matrix Q or the matrix P**T is
33396             required, as defined in the transformation applied by DGEBRD:
33397             = 'Q':  generate Q;
33398             = 'P':  generate P**T.
33399 
33400     M       (input) INTEGER
33401             The number of rows of the matrix Q or P**T to be returned.
33402             M >= 0.
33403 
33404     N       (input) INTEGER
33405             The number of columns of the matrix Q or P**T to be returned.
33406             N >= 0.
33407             If VECT = 'Q', M >= N >= min(M,K);
33408             if VECT = 'P', N >= M >= min(N,K).
33409 
33410     K       (input) INTEGER
33411             If VECT = 'Q', the number of columns in the original M-by-K
33412             matrix reduced by DGEBRD.
33413             If VECT = 'P', the number of rows in the original K-by-N
33414             matrix reduced by DGEBRD.
33415             K >= 0.
33416 
33417     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
33418             On entry, the vectors which define the elementary reflectors,
33419             as returned by DGEBRD.
33420             On exit, the M-by-N matrix Q or P**T.
33421 
33422     LDA     (input) INTEGER
33423             The leading dimension of the array A. LDA >= max(1,M).
33424 
33425     TAU     (input) DOUBLE PRECISION array, dimension
33426                                   (min(M,K)) if VECT = 'Q'
33427                                   (min(N,K)) if VECT = 'P'
33428             TAU(i) must contain the scalar factor of the elementary
33429             reflector H(i) or G(i), which determines Q or P**T, as
33430             returned by DGEBRD in its array argument TAUQ or TAUP.
33431 
33432     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
33433             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
33434 
33435     LWORK   (input) INTEGER
33436             The dimension of the array WORK. LWORK >= max(1,min(M,N)).
33437             For optimum performance LWORK >= min(M,N)*NB, where NB
33438             is the optimal blocksize.
33439 
33440             If LWORK = -1, then a workspace query is assumed; the routine
33441             only calculates the optimal size of the WORK array, returns
33442             this value as the first entry of the WORK array, and no error
33443             message related to LWORK is issued by XERBLA.
33444 
33445     INFO    (output) INTEGER
33446             = 0:  successful exit
33447             < 0:  if INFO = -i, the i-th argument had an illegal value
33448 
33449     =====================================================================
33450 
33451 
33452        Test the input arguments
33453 */
33454 
33455     /* Parameter adjustments */
33456     a_dim1 = *lda;
33457     a_offset = 1 + a_dim1;
33458     a -= a_offset;
33459     --tau;
33460     --work;
33461 
33462     /* Function Body */
33463     *info = 0;
33464     wantq = lsame_(vect, "Q");
33465     mn = min(*m,*n);
33466     lquery = *lwork == -1;
33467     if (! wantq && ! lsame_(vect, "P")) {
33468 	*info = -1;
33469     } else if (*m < 0) {
33470 	*info = -2;
33471     } else if (*n < 0 || wantq && (*n > *m || *n < min(*m,*k)) || ! wantq && (
33472 	    *m > *n || *m < min(*n,*k))) {
33473 	*info = -3;
33474     } else if (*k < 0) {
33475 	*info = -4;
33476     } else if (*lda < max(1,*m)) {
33477 	*info = -6;
33478     } else if (*lwork < max(1,mn) && ! lquery) {
33479 	*info = -9;
33480     }
33481 
33482     if (*info == 0) {
33483 	if (wantq) {
33484 	    nb = ilaenv_(&c__1, "DORGQR", " ", m, n, k, &c_n1, (ftnlen)6, (
33485 		    ftnlen)1);
33486 	} else {
33487 	    nb = ilaenv_(&c__1, "DORGLQ", " ", m, n, k, &c_n1, (ftnlen)6, (
33488 		    ftnlen)1);
33489 	}
33490 	lwkopt = max(1,mn) * nb;
33491 	work[1] = (doublereal) lwkopt;
33492     }
33493 
33494     if (*info != 0) {
33495 	i__1 = -(*info);
33496 	xerbla_("DORGBR", &i__1);
33497 	return 0;
33498     } else if (lquery) {
33499 	return 0;
33500     }
33501 
33502 /*     Quick return if possible */
33503 
33504     if (*m == 0 || *n == 0) {
33505 	work[1] = 1.;
33506 	return 0;
33507     }
33508 
33509     if (wantq) {
33510 
33511 /*
33512           Form Q, determined by a call to DGEBRD to reduce an m-by-k
33513           matrix
33514 */
33515 
33516 	if (*m >= *k) {
33517 
33518 /*           If m >= k, assume m >= n >= k */
33519 
33520 	    dorgqr_(m, n, k, &a[a_offset], lda, &tau[1], &work[1], lwork, &
33521 		    iinfo);
33522 
33523 	} else {
33524 
33525 /*
33526              If m < k, assume m = n
33527 
33528              Shift the vectors which define the elementary reflectors one
33529              column to the right, and set the first row and column of Q
33530              to those of the unit matrix
33531 */
33532 
33533 	    for (j = *m; j >= 2; --j) {
33534 		a[j * a_dim1 + 1] = 0.;
33535 		i__1 = *m;
33536 		for (i__ = j + 1; i__ <= i__1; ++i__) {
33537 		    a[i__ + j * a_dim1] = a[i__ + (j - 1) * a_dim1];
33538 /* L10: */
33539 		}
33540 /* L20: */
33541 	    }
33542 	    a[a_dim1 + 1] = 1.;
33543 	    i__1 = *m;
33544 	    for (i__ = 2; i__ <= i__1; ++i__) {
33545 		a[i__ + a_dim1] = 0.;
33546 /* L30: */
33547 	    }
33548 	    if (*m > 1) {
33549 
33550 /*              Form Q(2:m,2:m) */
33551 
33552 		i__1 = *m - 1;
33553 		i__2 = *m - 1;
33554 		i__3 = *m - 1;
33555 		dorgqr_(&i__1, &i__2, &i__3, &a[(a_dim1 << 1) + 2], lda, &tau[
33556 			1], &work[1], lwork, &iinfo);
33557 	    }
33558 	}
33559     } else {
33560 
33561 /*
33562           Form P', determined by a call to DGEBRD to reduce a k-by-n
33563           matrix
33564 */
33565 
33566 	if (*k < *n) {
33567 
33568 /*           If k < n, assume k <= m <= n */
33569 
33570 	    dorglq_(m, n, k, &a[a_offset], lda, &tau[1], &work[1], lwork, &
33571 		    iinfo);
33572 
33573 	} else {
33574 
33575 /*
33576              If k >= n, assume m = n
33577 
33578              Shift the vectors which define the elementary reflectors one
33579              row downward, and set the first row and column of P' to
33580              those of the unit matrix
33581 */
33582 
33583 	    a[a_dim1 + 1] = 1.;
33584 	    i__1 = *n;
33585 	    for (i__ = 2; i__ <= i__1; ++i__) {
33586 		a[i__ + a_dim1] = 0.;
33587 /* L40: */
33588 	    }
33589 	    i__1 = *n;
33590 	    for (j = 2; j <= i__1; ++j) {
33591 		for (i__ = j - 1; i__ >= 2; --i__) {
33592 		    a[i__ + j * a_dim1] = a[i__ - 1 + j * a_dim1];
33593 /* L50: */
33594 		}
33595 		a[j * a_dim1 + 1] = 0.;
33596 /* L60: */
33597 	    }
33598 	    if (*n > 1) {
33599 
33600 /*              Form P'(2:n,2:n) */
33601 
33602 		i__1 = *n - 1;
33603 		i__2 = *n - 1;
33604 		i__3 = *n - 1;
33605 		dorglq_(&i__1, &i__2, &i__3, &a[(a_dim1 << 1) + 2], lda, &tau[
33606 			1], &work[1], lwork, &iinfo);
33607 	    }
33608 	}
33609     }
33610     work[1] = (doublereal) lwkopt;
33611     return 0;
33612 
33613 /*     End of DORGBR */
33614 
33615 } /* dorgbr_ */
33616 
dorghr_(integer * n,integer * ilo,integer * ihi,doublereal * a,integer * lda,doublereal * tau,doublereal * work,integer * lwork,integer * info)33617 /* Subroutine */ int dorghr_(integer *n, integer *ilo, integer *ihi,
33618 	doublereal *a, integer *lda, doublereal *tau, doublereal *work,
33619 	integer *lwork, integer *info)
33620 {
33621     /* System generated locals */
33622     integer a_dim1, a_offset, i__1, i__2;
33623 
33624     /* Local variables */
33625     static integer i__, j, nb, nh, iinfo;
33626     extern /* Subroutine */ int xerbla_(char *, integer *);
33627     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
33628 	    integer *, integer *, ftnlen, ftnlen);
33629     extern /* Subroutine */ int dorgqr_(integer *, integer *, integer *,
33630 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
33631 	    integer *);
33632     static integer lwkopt;
33633     static logical lquery;
33634 
33635 
33636 /*
33637     -- LAPACK routine (version 3.2) --
33638     -- LAPACK is a software package provided by Univ. of Tennessee,    --
33639     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
33640        November 2006
33641 
33642 
33643     Purpose
33644     =======
33645 
33646     DORGHR generates a real orthogonal matrix Q which is defined as the
33647     product of IHI-ILO elementary reflectors of order N, as returned by
33648     DGEHRD:
33649 
33650     Q = H(ilo) H(ilo+1) . . . H(ihi-1).
33651 
33652     Arguments
33653     =========
33654 
33655     N       (input) INTEGER
33656             The order of the matrix Q. N >= 0.
33657 
33658     ILO     (input) INTEGER
33659     IHI     (input) INTEGER
33660             ILO and IHI must have the same values as in the previous call
33661             of DGEHRD. Q is equal to the unit matrix except in the
33662             submatrix Q(ilo+1:ihi,ilo+1:ihi).
33663             1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
33664 
33665     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
33666             On entry, the vectors which define the elementary reflectors,
33667             as returned by DGEHRD.
33668             On exit, the N-by-N orthogonal matrix Q.
33669 
33670     LDA     (input) INTEGER
33671             The leading dimension of the array A. LDA >= max(1,N).
33672 
33673     TAU     (input) DOUBLE PRECISION array, dimension (N-1)
33674             TAU(i) must contain the scalar factor of the elementary
33675             reflector H(i), as returned by DGEHRD.
33676 
33677     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
33678             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
33679 
33680     LWORK   (input) INTEGER
33681             The dimension of the array WORK. LWORK >= IHI-ILO.
33682             For optimum performance LWORK >= (IHI-ILO)*NB, where NB is
33683             the optimal blocksize.
33684 
33685             If LWORK = -1, then a workspace query is assumed; the routine
33686             only calculates the optimal size of the WORK array, returns
33687             this value as the first entry of the WORK array, and no error
33688             message related to LWORK is issued by XERBLA.
33689 
33690     INFO    (output) INTEGER
33691             = 0:  successful exit
33692             < 0:  if INFO = -i, the i-th argument had an illegal value
33693 
33694     =====================================================================
33695 
33696 
33697        Test the input arguments
33698 */
33699 
33700     /* Parameter adjustments */
33701     a_dim1 = *lda;
33702     a_offset = 1 + a_dim1;
33703     a -= a_offset;
33704     --tau;
33705     --work;
33706 
33707     /* Function Body */
33708     *info = 0;
33709     nh = *ihi - *ilo;
33710     lquery = *lwork == -1;
33711     if (*n < 0) {
33712 	*info = -1;
33713     } else if (*ilo < 1 || *ilo > max(1,*n)) {
33714 	*info = -2;
33715     } else if (*ihi < min(*ilo,*n) || *ihi > *n) {
33716 	*info = -3;
33717     } else if (*lda < max(1,*n)) {
33718 	*info = -5;
33719     } else if (*lwork < max(1,nh) && ! lquery) {
33720 	*info = -8;
33721     }
33722 
33723     if (*info == 0) {
33724 	nb = ilaenv_(&c__1, "DORGQR", " ", &nh, &nh, &nh, &c_n1, (ftnlen)6, (
33725 		ftnlen)1);
33726 	lwkopt = max(1,nh) * nb;
33727 	work[1] = (doublereal) lwkopt;
33728     }
33729 
33730     if (*info != 0) {
33731 	i__1 = -(*info);
33732 	xerbla_("DORGHR", &i__1);
33733 	return 0;
33734     } else if (lquery) {
33735 	return 0;
33736     }
33737 
33738 /*     Quick return if possible */
33739 
33740     if (*n == 0) {
33741 	work[1] = 1.;
33742 	return 0;
33743     }
33744 
33745 /*
33746        Shift the vectors which define the elementary reflectors one
33747        column to the right, and set the first ilo and the last n-ihi
33748        rows and columns to those of the unit matrix
33749 */
33750 
33751     i__1 = *ilo + 1;
33752     for (j = *ihi; j >= i__1; --j) {
33753 	i__2 = j - 1;
33754 	for (i__ = 1; i__ <= i__2; ++i__) {
33755 	    a[i__ + j * a_dim1] = 0.;
33756 /* L10: */
33757 	}
33758 	i__2 = *ihi;
33759 	for (i__ = j + 1; i__ <= i__2; ++i__) {
33760 	    a[i__ + j * a_dim1] = a[i__ + (j - 1) * a_dim1];
33761 /* L20: */
33762 	}
33763 	i__2 = *n;
33764 	for (i__ = *ihi + 1; i__ <= i__2; ++i__) {
33765 	    a[i__ + j * a_dim1] = 0.;
33766 /* L30: */
33767 	}
33768 /* L40: */
33769     }
33770     i__1 = *ilo;
33771     for (j = 1; j <= i__1; ++j) {
33772 	i__2 = *n;
33773 	for (i__ = 1; i__ <= i__2; ++i__) {
33774 	    a[i__ + j * a_dim1] = 0.;
33775 /* L50: */
33776 	}
33777 	a[j + j * a_dim1] = 1.;
33778 /* L60: */
33779     }
33780     i__1 = *n;
33781     for (j = *ihi + 1; j <= i__1; ++j) {
33782 	i__2 = *n;
33783 	for (i__ = 1; i__ <= i__2; ++i__) {
33784 	    a[i__ + j * a_dim1] = 0.;
33785 /* L70: */
33786 	}
33787 	a[j + j * a_dim1] = 1.;
33788 /* L80: */
33789     }
33790 
33791     if (nh > 0) {
33792 
33793 /*        Generate Q(ilo+1:ihi,ilo+1:ihi) */
33794 
33795 	dorgqr_(&nh, &nh, &nh, &a[*ilo + 1 + (*ilo + 1) * a_dim1], lda, &tau[*
33796 		ilo], &work[1], lwork, &iinfo);
33797     }
33798     work[1] = (doublereal) lwkopt;
33799     return 0;
33800 
33801 /*     End of DORGHR */
33802 
33803 } /* dorghr_ */
33804 
dorgl2_(integer * m,integer * n,integer * k,doublereal * a,integer * lda,doublereal * tau,doublereal * work,integer * info)33805 /* Subroutine */ int dorgl2_(integer *m, integer *n, integer *k, doublereal *
33806 	a, integer *lda, doublereal *tau, doublereal *work, integer *info)
33807 {
33808     /* System generated locals */
33809     integer a_dim1, a_offset, i__1, i__2;
33810     doublereal d__1;
33811 
33812     /* Local variables */
33813     static integer i__, j, l;
33814     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
33815 	    integer *), dlarf_(char *, integer *, integer *, doublereal *,
33816 	    integer *, doublereal *, doublereal *, integer *, doublereal *), xerbla_(char *, integer *);
33817 
33818 
33819 /*
33820     -- LAPACK routine (version 3.2) --
33821     -- LAPACK is a software package provided by Univ. of Tennessee,    --
33822     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
33823        November 2006
33824 
33825 
33826     Purpose
33827     =======
33828 
33829     DORGL2 generates an m by n real matrix Q with orthonormal rows,
33830     which is defined as the first m rows of a product of k elementary
33831     reflectors of order n
33832 
33833           Q  =  H(k) . . . H(2) H(1)
33834 
33835     as returned by DGELQF.
33836 
33837     Arguments
33838     =========
33839 
33840     M       (input) INTEGER
33841             The number of rows of the matrix Q. M >= 0.
33842 
33843     N       (input) INTEGER
33844             The number of columns of the matrix Q. N >= M.
33845 
33846     K       (input) INTEGER
33847             The number of elementary reflectors whose product defines the
33848             matrix Q. M >= K >= 0.
33849 
33850     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
33851             On entry, the i-th row must contain the vector which defines
33852             the elementary reflector H(i), for i = 1,2,...,k, as returned
33853             by DGELQF in the first k rows of its array argument A.
33854             On exit, the m-by-n matrix Q.
33855 
33856     LDA     (input) INTEGER
33857             The first dimension of the array A. LDA >= max(1,M).
33858 
33859     TAU     (input) DOUBLE PRECISION array, dimension (K)
33860             TAU(i) must contain the scalar factor of the elementary
33861             reflector H(i), as returned by DGELQF.
33862 
33863     WORK    (workspace) DOUBLE PRECISION array, dimension (M)
33864 
33865     INFO    (output) INTEGER
33866             = 0: successful exit
33867             < 0: if INFO = -i, the i-th argument has an illegal value
33868 
33869     =====================================================================
33870 
33871 
33872        Test the input arguments
33873 */
33874 
33875     /* Parameter adjustments */
33876     a_dim1 = *lda;
33877     a_offset = 1 + a_dim1;
33878     a -= a_offset;
33879     --tau;
33880     --work;
33881 
33882     /* Function Body */
33883     *info = 0;
33884     if (*m < 0) {
33885 	*info = -1;
33886     } else if (*n < *m) {
33887 	*info = -2;
33888     } else if (*k < 0 || *k > *m) {
33889 	*info = -3;
33890     } else if (*lda < max(1,*m)) {
33891 	*info = -5;
33892     }
33893     if (*info != 0) {
33894 	i__1 = -(*info);
33895 	xerbla_("DORGL2", &i__1);
33896 	return 0;
33897     }
33898 
33899 /*     Quick return if possible */
33900 
33901     if (*m <= 0) {
33902 	return 0;
33903     }
33904 
33905     if (*k < *m) {
33906 
33907 /*        Initialise rows k+1:m to rows of the unit matrix */
33908 
33909 	i__1 = *n;
33910 	for (j = 1; j <= i__1; ++j) {
33911 	    i__2 = *m;
33912 	    for (l = *k + 1; l <= i__2; ++l) {
33913 		a[l + j * a_dim1] = 0.;
33914 /* L10: */
33915 	    }
33916 	    if (j > *k && j <= *m) {
33917 		a[j + j * a_dim1] = 1.;
33918 	    }
33919 /* L20: */
33920 	}
33921     }
33922 
33923     for (i__ = *k; i__ >= 1; --i__) {
33924 
33925 /*        Apply H(i) to A(i:m,i:n) from the right */
33926 
33927 	if (i__ < *n) {
33928 	    if (i__ < *m) {
33929 		a[i__ + i__ * a_dim1] = 1.;
33930 		i__1 = *m - i__;
33931 		i__2 = *n - i__ + 1;
33932 		dlarf_("Right", &i__1, &i__2, &a[i__ + i__ * a_dim1], lda, &
33933 			tau[i__], &a[i__ + 1 + i__ * a_dim1], lda, &work[1]);
33934 	    }
33935 	    i__1 = *n - i__;
33936 	    d__1 = -tau[i__];
33937 	    dscal_(&i__1, &d__1, &a[i__ + (i__ + 1) * a_dim1], lda);
33938 	}
33939 	a[i__ + i__ * a_dim1] = 1. - tau[i__];
33940 
33941 /*        Set A(i,1:i-1) to zero */
33942 
33943 	i__1 = i__ - 1;
33944 	for (l = 1; l <= i__1; ++l) {
33945 	    a[i__ + l * a_dim1] = 0.;
33946 /* L30: */
33947 	}
33948 /* L40: */
33949     }
33950     return 0;
33951 
33952 /*     End of DORGL2 */
33953 
33954 } /* dorgl2_ */
33955 
dorglq_(integer * m,integer * n,integer * k,doublereal * a,integer * lda,doublereal * tau,doublereal * work,integer * lwork,integer * info)33956 /* Subroutine */ int dorglq_(integer *m, integer *n, integer *k, doublereal *
33957 	a, integer *lda, doublereal *tau, doublereal *work, integer *lwork,
33958 	integer *info)
33959 {
33960     /* System generated locals */
33961     integer a_dim1, a_offset, i__1, i__2, i__3;
33962 
33963     /* Local variables */
33964     static integer i__, j, l, ib, nb, ki, kk, nx, iws, nbmin, iinfo;
33965     extern /* Subroutine */ int dorgl2_(integer *, integer *, integer *,
33966 	    doublereal *, integer *, doublereal *, doublereal *, integer *),
33967 	    dlarfb_(char *, char *, char *, char *, integer *, integer *,
33968 	    integer *, doublereal *, integer *, doublereal *, integer *,
33969 	    doublereal *, integer *, doublereal *, integer *), dlarft_(char *, char *, integer *, integer *,
33970 	    doublereal *, integer *, doublereal *, doublereal *, integer *), xerbla_(char *, integer *);
33971     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
33972 	    integer *, integer *, ftnlen, ftnlen);
33973     static integer ldwork, lwkopt;
33974     static logical lquery;
33975 
33976 
33977 /*
33978     -- LAPACK routine (version 3.2) --
33979     -- LAPACK is a software package provided by Univ. of Tennessee,    --
33980     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
33981        November 2006
33982 
33983 
33984     Purpose
33985     =======
33986 
33987     DORGLQ generates an M-by-N real matrix Q with orthonormal rows,
33988     which is defined as the first M rows of a product of K elementary
33989     reflectors of order N
33990 
33991           Q  =  H(k) . . . H(2) H(1)
33992 
33993     as returned by DGELQF.
33994 
33995     Arguments
33996     =========
33997 
33998     M       (input) INTEGER
33999             The number of rows of the matrix Q. M >= 0.
34000 
34001     N       (input) INTEGER
34002             The number of columns of the matrix Q. N >= M.
34003 
34004     K       (input) INTEGER
34005             The number of elementary reflectors whose product defines the
34006             matrix Q. M >= K >= 0.
34007 
34008     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
34009             On entry, the i-th row must contain the vector which defines
34010             the elementary reflector H(i), for i = 1,2,...,k, as returned
34011             by DGELQF in the first k rows of its array argument A.
34012             On exit, the M-by-N matrix Q.
34013 
34014     LDA     (input) INTEGER
34015             The first dimension of the array A. LDA >= max(1,M).
34016 
34017     TAU     (input) DOUBLE PRECISION array, dimension (K)
34018             TAU(i) must contain the scalar factor of the elementary
34019             reflector H(i), as returned by DGELQF.
34020 
34021     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
34022             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
34023 
34024     LWORK   (input) INTEGER
34025             The dimension of the array WORK. LWORK >= max(1,M).
34026             For optimum performance LWORK >= M*NB, where NB is
34027             the optimal blocksize.
34028 
34029             If LWORK = -1, then a workspace query is assumed; the routine
34030             only calculates the optimal size of the WORK array, returns
34031             this value as the first entry of the WORK array, and no error
34032             message related to LWORK is issued by XERBLA.
34033 
34034     INFO    (output) INTEGER
34035             = 0:  successful exit
34036             < 0:  if INFO = -i, the i-th argument has an illegal value
34037 
34038     =====================================================================
34039 
34040 
34041        Test the input arguments
34042 */
34043 
34044     /* Parameter adjustments */
34045     a_dim1 = *lda;
34046     a_offset = 1 + a_dim1;
34047     a -= a_offset;
34048     --tau;
34049     --work;
34050 
34051     /* Function Body */
34052     *info = 0;
34053     nb = ilaenv_(&c__1, "DORGLQ", " ", m, n, k, &c_n1, (ftnlen)6, (ftnlen)1);
34054     lwkopt = max(1,*m) * nb;
34055     work[1] = (doublereal) lwkopt;
34056     lquery = *lwork == -1;
34057     if (*m < 0) {
34058 	*info = -1;
34059     } else if (*n < *m) {
34060 	*info = -2;
34061     } else if (*k < 0 || *k > *m) {
34062 	*info = -3;
34063     } else if (*lda < max(1,*m)) {
34064 	*info = -5;
34065     } else if (*lwork < max(1,*m) && ! lquery) {
34066 	*info = -8;
34067     }
34068     if (*info != 0) {
34069 	i__1 = -(*info);
34070 	xerbla_("DORGLQ", &i__1);
34071 	return 0;
34072     } else if (lquery) {
34073 	return 0;
34074     }
34075 
34076 /*     Quick return if possible */
34077 
34078     if (*m <= 0) {
34079 	work[1] = 1.;
34080 	return 0;
34081     }
34082 
34083     nbmin = 2;
34084     nx = 0;
34085     iws = *m;
34086     if (nb > 1 && nb < *k) {
34087 
34088 /*
34089           Determine when to cross over from blocked to unblocked code.
34090 
34091    Computing MAX
34092 */
34093 	i__1 = 0, i__2 = ilaenv_(&c__3, "DORGLQ", " ", m, n, k, &c_n1, (
34094 		ftnlen)6, (ftnlen)1);
34095 	nx = max(i__1,i__2);
34096 	if (nx < *k) {
34097 
34098 /*           Determine if workspace is large enough for blocked code. */
34099 
34100 	    ldwork = *m;
34101 	    iws = ldwork * nb;
34102 	    if (*lwork < iws) {
34103 
34104 /*
34105                 Not enough workspace to use optimal NB:  reduce NB and
34106                 determine the minimum value of NB.
34107 */
34108 
34109 		nb = *lwork / ldwork;
34110 /* Computing MAX */
34111 		i__1 = 2, i__2 = ilaenv_(&c__2, "DORGLQ", " ", m, n, k, &c_n1,
34112 			 (ftnlen)6, (ftnlen)1);
34113 		nbmin = max(i__1,i__2);
34114 	    }
34115 	}
34116     }
34117 
34118     if (nb >= nbmin && nb < *k && nx < *k) {
34119 
34120 /*
34121           Use blocked code after the last block.
34122           The first kk rows are handled by the block method.
34123 */
34124 
34125 	ki = (*k - nx - 1) / nb * nb;
34126 /* Computing MIN */
34127 	i__1 = *k, i__2 = ki + nb;
34128 	kk = min(i__1,i__2);
34129 
34130 /*        Set A(kk+1:m,1:kk) to zero. */
34131 
34132 	i__1 = kk;
34133 	for (j = 1; j <= i__1; ++j) {
34134 	    i__2 = *m;
34135 	    for (i__ = kk + 1; i__ <= i__2; ++i__) {
34136 		a[i__ + j * a_dim1] = 0.;
34137 /* L10: */
34138 	    }
34139 /* L20: */
34140 	}
34141     } else {
34142 	kk = 0;
34143     }
34144 
34145 /*     Use unblocked code for the last or only block. */
34146 
34147     if (kk < *m) {
34148 	i__1 = *m - kk;
34149 	i__2 = *n - kk;
34150 	i__3 = *k - kk;
34151 	dorgl2_(&i__1, &i__2, &i__3, &a[kk + 1 + (kk + 1) * a_dim1], lda, &
34152 		tau[kk + 1], &work[1], &iinfo);
34153     }
34154 
34155     if (kk > 0) {
34156 
34157 /*        Use blocked code */
34158 
34159 	i__1 = -nb;
34160 	for (i__ = ki + 1; i__1 < 0 ? i__ >= 1 : i__ <= 1; i__ += i__1) {
34161 /* Computing MIN */
34162 	    i__2 = nb, i__3 = *k - i__ + 1;
34163 	    ib = min(i__2,i__3);
34164 	    if (i__ + ib <= *m) {
34165 
34166 /*
34167                 Form the triangular factor of the block reflector
34168                 H = H(i) H(i+1) . . . H(i+ib-1)
34169 */
34170 
34171 		i__2 = *n - i__ + 1;
34172 		dlarft_("Forward", "Rowwise", &i__2, &ib, &a[i__ + i__ *
34173 			a_dim1], lda, &tau[i__], &work[1], &ldwork);
34174 
34175 /*              Apply H' to A(i+ib:m,i:n) from the right */
34176 
34177 		i__2 = *m - i__ - ib + 1;
34178 		i__3 = *n - i__ + 1;
34179 		dlarfb_("Right", "Transpose", "Forward", "Rowwise", &i__2, &
34180 			i__3, &ib, &a[i__ + i__ * a_dim1], lda, &work[1], &
34181 			ldwork, &a[i__ + ib + i__ * a_dim1], lda, &work[ib +
34182 			1], &ldwork);
34183 	    }
34184 
34185 /*           Apply H' to columns i:n of current block */
34186 
34187 	    i__2 = *n - i__ + 1;
34188 	    dorgl2_(&ib, &i__2, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
34189 		    work[1], &iinfo);
34190 
34191 /*           Set columns 1:i-1 of current block to zero */
34192 
34193 	    i__2 = i__ - 1;
34194 	    for (j = 1; j <= i__2; ++j) {
34195 		i__3 = i__ + ib - 1;
34196 		for (l = i__; l <= i__3; ++l) {
34197 		    a[l + j * a_dim1] = 0.;
34198 /* L30: */
34199 		}
34200 /* L40: */
34201 	    }
34202 /* L50: */
34203 	}
34204     }
34205 
34206     work[1] = (doublereal) iws;
34207     return 0;
34208 
34209 /*     End of DORGLQ */
34210 
34211 } /* dorglq_ */
34212 
dorgqr_(integer * m,integer * n,integer * k,doublereal * a,integer * lda,doublereal * tau,doublereal * work,integer * lwork,integer * info)34213 /* Subroutine */ int dorgqr_(integer *m, integer *n, integer *k, doublereal *
34214 	a, integer *lda, doublereal *tau, doublereal *work, integer *lwork,
34215 	integer *info)
34216 {
34217     /* System generated locals */
34218     integer a_dim1, a_offset, i__1, i__2, i__3;
34219 
34220     /* Local variables */
34221     static integer i__, j, l, ib, nb, ki, kk, nx, iws, nbmin, iinfo;
34222     extern /* Subroutine */ int dorg2r_(integer *, integer *, integer *,
34223 	    doublereal *, integer *, doublereal *, doublereal *, integer *),
34224 	    dlarfb_(char *, char *, char *, char *, integer *, integer *,
34225 	    integer *, doublereal *, integer *, doublereal *, integer *,
34226 	    doublereal *, integer *, doublereal *, integer *), dlarft_(char *, char *, integer *, integer *,
34227 	    doublereal *, integer *, doublereal *, doublereal *, integer *), xerbla_(char *, integer *);
34228     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
34229 	    integer *, integer *, ftnlen, ftnlen);
34230     static integer ldwork, lwkopt;
34231     static logical lquery;
34232 
34233 
34234 /*
34235     -- LAPACK routine (version 3.2) --
34236     -- LAPACK is a software package provided by Univ. of Tennessee,    --
34237     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
34238        November 2006
34239 
34240 
34241     Purpose
34242     =======
34243 
34244     DORGQR generates an M-by-N real matrix Q with orthonormal columns,
34245     which is defined as the first N columns of a product of K elementary
34246     reflectors of order M
34247 
34248           Q  =  H(1) H(2) . . . H(k)
34249 
34250     as returned by DGEQRF.
34251 
34252     Arguments
34253     =========
34254 
34255     M       (input) INTEGER
34256             The number of rows of the matrix Q. M >= 0.
34257 
34258     N       (input) INTEGER
34259             The number of columns of the matrix Q. M >= N >= 0.
34260 
34261     K       (input) INTEGER
34262             The number of elementary reflectors whose product defines the
34263             matrix Q. N >= K >= 0.
34264 
34265     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
34266             On entry, the i-th column must contain the vector which
34267             defines the elementary reflector H(i), for i = 1,2,...,k, as
34268             returned by DGEQRF in the first k columns of its array
34269             argument A.
34270             On exit, the M-by-N matrix Q.
34271 
34272     LDA     (input) INTEGER
34273             The first dimension of the array A. LDA >= max(1,M).
34274 
34275     TAU     (input) DOUBLE PRECISION array, dimension (K)
34276             TAU(i) must contain the scalar factor of the elementary
34277             reflector H(i), as returned by DGEQRF.
34278 
34279     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
34280             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
34281 
34282     LWORK   (input) INTEGER
34283             The dimension of the array WORK. LWORK >= max(1,N).
34284             For optimum performance LWORK >= N*NB, where NB is the
34285             optimal blocksize.
34286 
34287             If LWORK = -1, then a workspace query is assumed; the routine
34288             only calculates the optimal size of the WORK array, returns
34289             this value as the first entry of the WORK array, and no error
34290             message related to LWORK is issued by XERBLA.
34291 
34292     INFO    (output) INTEGER
34293             = 0:  successful exit
34294             < 0:  if INFO = -i, the i-th argument has an illegal value
34295 
34296     =====================================================================
34297 
34298 
34299        Test the input arguments
34300 */
34301 
34302     /* Parameter adjustments */
34303     a_dim1 = *lda;
34304     a_offset = 1 + a_dim1;
34305     a -= a_offset;
34306     --tau;
34307     --work;
34308 
34309     /* Function Body */
34310     *info = 0;
34311     nb = ilaenv_(&c__1, "DORGQR", " ", m, n, k, &c_n1, (ftnlen)6, (ftnlen)1);
34312     lwkopt = max(1,*n) * nb;
34313     work[1] = (doublereal) lwkopt;
34314     lquery = *lwork == -1;
34315     if (*m < 0) {
34316 	*info = -1;
34317     } else if (*n < 0 || *n > *m) {
34318 	*info = -2;
34319     } else if (*k < 0 || *k > *n) {
34320 	*info = -3;
34321     } else if (*lda < max(1,*m)) {
34322 	*info = -5;
34323     } else if (*lwork < max(1,*n) && ! lquery) {
34324 	*info = -8;
34325     }
34326     if (*info != 0) {
34327 	i__1 = -(*info);
34328 	xerbla_("DORGQR", &i__1);
34329 	return 0;
34330     } else if (lquery) {
34331 	return 0;
34332     }
34333 
34334 /*     Quick return if possible */
34335 
34336     if (*n <= 0) {
34337 	work[1] = 1.;
34338 	return 0;
34339     }
34340 
34341     nbmin = 2;
34342     nx = 0;
34343     iws = *n;
34344     if (nb > 1 && nb < *k) {
34345 
34346 /*
34347           Determine when to cross over from blocked to unblocked code.
34348 
34349    Computing MAX
34350 */
34351 	i__1 = 0, i__2 = ilaenv_(&c__3, "DORGQR", " ", m, n, k, &c_n1, (
34352 		ftnlen)6, (ftnlen)1);
34353 	nx = max(i__1,i__2);
34354 	if (nx < *k) {
34355 
34356 /*           Determine if workspace is large enough for blocked code. */
34357 
34358 	    ldwork = *n;
34359 	    iws = ldwork * nb;
34360 	    if (*lwork < iws) {
34361 
34362 /*
34363                 Not enough workspace to use optimal NB:  reduce NB and
34364                 determine the minimum value of NB.
34365 */
34366 
34367 		nb = *lwork / ldwork;
34368 /* Computing MAX */
34369 		i__1 = 2, i__2 = ilaenv_(&c__2, "DORGQR", " ", m, n, k, &c_n1,
34370 			 (ftnlen)6, (ftnlen)1);
34371 		nbmin = max(i__1,i__2);
34372 	    }
34373 	}
34374     }
34375 
34376     if (nb >= nbmin && nb < *k && nx < *k) {
34377 
34378 /*
34379           Use blocked code after the last block.
34380           The first kk columns are handled by the block method.
34381 */
34382 
34383 	ki = (*k - nx - 1) / nb * nb;
34384 /* Computing MIN */
34385 	i__1 = *k, i__2 = ki + nb;
34386 	kk = min(i__1,i__2);
34387 
34388 /*        Set A(1:kk,kk+1:n) to zero. */
34389 
34390 	i__1 = *n;
34391 	for (j = kk + 1; j <= i__1; ++j) {
34392 	    i__2 = kk;
34393 	    for (i__ = 1; i__ <= i__2; ++i__) {
34394 		a[i__ + j * a_dim1] = 0.;
34395 /* L10: */
34396 	    }
34397 /* L20: */
34398 	}
34399     } else {
34400 	kk = 0;
34401     }
34402 
34403 /*     Use unblocked code for the last or only block. */
34404 
34405     if (kk < *n) {
34406 	i__1 = *m - kk;
34407 	i__2 = *n - kk;
34408 	i__3 = *k - kk;
34409 	dorg2r_(&i__1, &i__2, &i__3, &a[kk + 1 + (kk + 1) * a_dim1], lda, &
34410 		tau[kk + 1], &work[1], &iinfo);
34411     }
34412 
34413     if (kk > 0) {
34414 
34415 /*        Use blocked code */
34416 
34417 	i__1 = -nb;
34418 	for (i__ = ki + 1; i__1 < 0 ? i__ >= 1 : i__ <= 1; i__ += i__1) {
34419 /* Computing MIN */
34420 	    i__2 = nb, i__3 = *k - i__ + 1;
34421 	    ib = min(i__2,i__3);
34422 	    if (i__ + ib <= *n) {
34423 
34424 /*
34425                 Form the triangular factor of the block reflector
34426                 H = H(i) H(i+1) . . . H(i+ib-1)
34427 */
34428 
34429 		i__2 = *m - i__ + 1;
34430 		dlarft_("Forward", "Columnwise", &i__2, &ib, &a[i__ + i__ *
34431 			a_dim1], lda, &tau[i__], &work[1], &ldwork);
34432 
34433 /*              Apply H to A(i:m,i+ib:n) from the left */
34434 
34435 		i__2 = *m - i__ + 1;
34436 		i__3 = *n - i__ - ib + 1;
34437 		dlarfb_("Left", "No transpose", "Forward", "Columnwise", &
34438 			i__2, &i__3, &ib, &a[i__ + i__ * a_dim1], lda, &work[
34439 			1], &ldwork, &a[i__ + (i__ + ib) * a_dim1], lda, &
34440 			work[ib + 1], &ldwork);
34441 	    }
34442 
34443 /*           Apply H to rows i:m of current block */
34444 
34445 	    i__2 = *m - i__ + 1;
34446 	    dorg2r_(&i__2, &ib, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
34447 		    work[1], &iinfo);
34448 
34449 /*           Set rows 1:i-1 of current block to zero */
34450 
34451 	    i__2 = i__ + ib - 1;
34452 	    for (j = i__; j <= i__2; ++j) {
34453 		i__3 = i__ - 1;
34454 		for (l = 1; l <= i__3; ++l) {
34455 		    a[l + j * a_dim1] = 0.;
34456 /* L30: */
34457 		}
34458 /* L40: */
34459 	    }
34460 /* L50: */
34461 	}
34462     }
34463 
34464     work[1] = (doublereal) iws;
34465     return 0;
34466 
34467 /*     End of DORGQR */
34468 
34469 } /* dorgqr_ */
34470 
dorm2l_(char * side,char * trans,integer * m,integer * n,integer * k,doublereal * a,integer * lda,doublereal * tau,doublereal * c__,integer * ldc,doublereal * work,integer * info)34471 /* Subroutine */ int dorm2l_(char *side, char *trans, integer *m, integer *n,
34472 	integer *k, doublereal *a, integer *lda, doublereal *tau, doublereal *
34473 	c__, integer *ldc, doublereal *work, integer *info)
34474 {
34475     /* System generated locals */
34476     integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2;
34477 
34478     /* Local variables */
34479     static integer i__, i1, i2, i3, mi, ni, nq;
34480     static doublereal aii;
34481     static logical left;
34482     extern /* Subroutine */ int dlarf_(char *, integer *, integer *,
34483 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
34484 	    doublereal *);
34485     extern logical lsame_(char *, char *);
34486     extern /* Subroutine */ int xerbla_(char *, integer *);
34487     static logical notran;
34488 
34489 
34490 /*
34491     -- LAPACK routine (version 3.2) --
34492     -- LAPACK is a software package provided by Univ. of Tennessee,    --
34493     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
34494        November 2006
34495 
34496 
34497     Purpose
34498     =======
34499 
34500     DORM2L overwrites the general real m by n matrix C with
34501 
34502           Q * C  if SIDE = 'L' and TRANS = 'N', or
34503 
34504           Q'* C  if SIDE = 'L' and TRANS = 'T', or
34505 
34506           C * Q  if SIDE = 'R' and TRANS = 'N', or
34507 
34508           C * Q' if SIDE = 'R' and TRANS = 'T',
34509 
34510     where Q is a real orthogonal matrix defined as the product of k
34511     elementary reflectors
34512 
34513           Q = H(k) . . . H(2) H(1)
34514 
34515     as returned by DGEQLF. Q is of order m if SIDE = 'L' and of order n
34516     if SIDE = 'R'.
34517 
34518     Arguments
34519     =========
34520 
34521     SIDE    (input) CHARACTER*1
34522             = 'L': apply Q or Q' from the Left
34523             = 'R': apply Q or Q' from the Right
34524 
34525     TRANS   (input) CHARACTER*1
34526             = 'N': apply Q  (No transpose)
34527             = 'T': apply Q' (Transpose)
34528 
34529     M       (input) INTEGER
34530             The number of rows of the matrix C. M >= 0.
34531 
34532     N       (input) INTEGER
34533             The number of columns of the matrix C. N >= 0.
34534 
34535     K       (input) INTEGER
34536             The number of elementary reflectors whose product defines
34537             the matrix Q.
34538             If SIDE = 'L', M >= K >= 0;
34539             if SIDE = 'R', N >= K >= 0.
34540 
34541     A       (input) DOUBLE PRECISION array, dimension (LDA,K)
34542             The i-th column must contain the vector which defines the
34543             elementary reflector H(i), for i = 1,2,...,k, as returned by
34544             DGEQLF in the last k columns of its array argument A.
34545             A is modified by the routine but restored on exit.
34546 
34547     LDA     (input) INTEGER
34548             The leading dimension of the array A.
34549             If SIDE = 'L', LDA >= max(1,M);
34550             if SIDE = 'R', LDA >= max(1,N).
34551 
34552     TAU     (input) DOUBLE PRECISION array, dimension (K)
34553             TAU(i) must contain the scalar factor of the elementary
34554             reflector H(i), as returned by DGEQLF.
34555 
34556     C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
34557             On entry, the m by n matrix C.
34558             On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q.
34559 
34560     LDC     (input) INTEGER
34561             The leading dimension of the array C. LDC >= max(1,M).
34562 
34563     WORK    (workspace) DOUBLE PRECISION array, dimension
34564                                      (N) if SIDE = 'L',
34565                                      (M) if SIDE = 'R'
34566 
34567     INFO    (output) INTEGER
34568             = 0: successful exit
34569             < 0: if INFO = -i, the i-th argument had an illegal value
34570 
34571     =====================================================================
34572 
34573 
34574        Test the input arguments
34575 */
34576 
34577     /* Parameter adjustments */
34578     a_dim1 = *lda;
34579     a_offset = 1 + a_dim1;
34580     a -= a_offset;
34581     --tau;
34582     c_dim1 = *ldc;
34583     c_offset = 1 + c_dim1;
34584     c__ -= c_offset;
34585     --work;
34586 
34587     /* Function Body */
34588     *info = 0;
34589     left = lsame_(side, "L");
34590     notran = lsame_(trans, "N");
34591 
34592 /*     NQ is the order of Q */
34593 
34594     if (left) {
34595 	nq = *m;
34596     } else {
34597 	nq = *n;
34598     }
34599     if (! left && ! lsame_(side, "R")) {
34600 	*info = -1;
34601     } else if (! notran && ! lsame_(trans, "T")) {
34602 	*info = -2;
34603     } else if (*m < 0) {
34604 	*info = -3;
34605     } else if (*n < 0) {
34606 	*info = -4;
34607     } else if (*k < 0 || *k > nq) {
34608 	*info = -5;
34609     } else if (*lda < max(1,nq)) {
34610 	*info = -7;
34611     } else if (*ldc < max(1,*m)) {
34612 	*info = -10;
34613     }
34614     if (*info != 0) {
34615 	i__1 = -(*info);
34616 	xerbla_("DORM2L", &i__1);
34617 	return 0;
34618     }
34619 
34620 /*     Quick return if possible */
34621 
34622     if (*m == 0 || *n == 0 || *k == 0) {
34623 	return 0;
34624     }
34625 
34626     if (left && notran || ! left && ! notran) {
34627 	i1 = 1;
34628 	i2 = *k;
34629 	i3 = 1;
34630     } else {
34631 	i1 = *k;
34632 	i2 = 1;
34633 	i3 = -1;
34634     }
34635 
34636     if (left) {
34637 	ni = *n;
34638     } else {
34639 	mi = *m;
34640     }
34641 
34642     i__1 = i2;
34643     i__2 = i3;
34644     for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
34645 	if (left) {
34646 
34647 /*           H(i) is applied to C(1:m-k+i,1:n) */
34648 
34649 	    mi = *m - *k + i__;
34650 	} else {
34651 
34652 /*           H(i) is applied to C(1:m,1:n-k+i) */
34653 
34654 	    ni = *n - *k + i__;
34655 	}
34656 
34657 /*        Apply H(i) */
34658 
34659 	aii = a[nq - *k + i__ + i__ * a_dim1];
34660 	a[nq - *k + i__ + i__ * a_dim1] = 1.;
34661 	dlarf_(side, &mi, &ni, &a[i__ * a_dim1 + 1], &c__1, &tau[i__], &c__[
34662 		c_offset], ldc, &work[1]);
34663 	a[nq - *k + i__ + i__ * a_dim1] = aii;
34664 /* L10: */
34665     }
34666     return 0;
34667 
34668 /*     End of DORM2L */
34669 
34670 } /* dorm2l_ */
34671 
dorm2r_(char * side,char * trans,integer * m,integer * n,integer * k,doublereal * a,integer * lda,doublereal * tau,doublereal * c__,integer * ldc,doublereal * work,integer * info)34672 /* Subroutine */ int dorm2r_(char *side, char *trans, integer *m, integer *n,
34673 	integer *k, doublereal *a, integer *lda, doublereal *tau, doublereal *
34674 	c__, integer *ldc, doublereal *work, integer *info)
34675 {
34676     /* System generated locals */
34677     integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2;
34678 
34679     /* Local variables */
34680     static integer i__, i1, i2, i3, ic, jc, mi, ni, nq;
34681     static doublereal aii;
34682     static logical left;
34683     extern /* Subroutine */ int dlarf_(char *, integer *, integer *,
34684 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
34685 	    doublereal *);
34686     extern logical lsame_(char *, char *);
34687     extern /* Subroutine */ int xerbla_(char *, integer *);
34688     static logical notran;
34689 
34690 
34691 /*
34692     -- LAPACK routine (version 3.2) --
34693     -- LAPACK is a software package provided by Univ. of Tennessee,    --
34694     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
34695        November 2006
34696 
34697 
34698     Purpose
34699     =======
34700 
34701     DORM2R overwrites the general real m by n matrix C with
34702 
34703           Q * C  if SIDE = 'L' and TRANS = 'N', or
34704 
34705           Q'* C  if SIDE = 'L' and TRANS = 'T', or
34706 
34707           C * Q  if SIDE = 'R' and TRANS = 'N', or
34708 
34709           C * Q' if SIDE = 'R' and TRANS = 'T',
34710 
34711     where Q is a real orthogonal matrix defined as the product of k
34712     elementary reflectors
34713 
34714           Q = H(1) H(2) . . . H(k)
34715 
34716     as returned by DGEQRF. Q is of order m if SIDE = 'L' and of order n
34717     if SIDE = 'R'.
34718 
34719     Arguments
34720     =========
34721 
34722     SIDE    (input) CHARACTER*1
34723             = 'L': apply Q or Q' from the Left
34724             = 'R': apply Q or Q' from the Right
34725 
34726     TRANS   (input) CHARACTER*1
34727             = 'N': apply Q  (No transpose)
34728             = 'T': apply Q' (Transpose)
34729 
34730     M       (input) INTEGER
34731             The number of rows of the matrix C. M >= 0.
34732 
34733     N       (input) INTEGER
34734             The number of columns of the matrix C. N >= 0.
34735 
34736     K       (input) INTEGER
34737             The number of elementary reflectors whose product defines
34738             the matrix Q.
34739             If SIDE = 'L', M >= K >= 0;
34740             if SIDE = 'R', N >= K >= 0.
34741 
34742     A       (input) DOUBLE PRECISION array, dimension (LDA,K)
34743             The i-th column must contain the vector which defines the
34744             elementary reflector H(i), for i = 1,2,...,k, as returned by
34745             DGEQRF in the first k columns of its array argument A.
34746             A is modified by the routine but restored on exit.
34747 
34748     LDA     (input) INTEGER
34749             The leading dimension of the array A.
34750             If SIDE = 'L', LDA >= max(1,M);
34751             if SIDE = 'R', LDA >= max(1,N).
34752 
34753     TAU     (input) DOUBLE PRECISION array, dimension (K)
34754             TAU(i) must contain the scalar factor of the elementary
34755             reflector H(i), as returned by DGEQRF.
34756 
34757     C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
34758             On entry, the m by n matrix C.
34759             On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q.
34760 
34761     LDC     (input) INTEGER
34762             The leading dimension of the array C. LDC >= max(1,M).
34763 
34764     WORK    (workspace) DOUBLE PRECISION array, dimension
34765                                      (N) if SIDE = 'L',
34766                                      (M) if SIDE = 'R'
34767 
34768     INFO    (output) INTEGER
34769             = 0: successful exit
34770             < 0: if INFO = -i, the i-th argument had an illegal value
34771 
34772     =====================================================================
34773 
34774 
34775        Test the input arguments
34776 */
34777 
34778     /* Parameter adjustments */
34779     a_dim1 = *lda;
34780     a_offset = 1 + a_dim1;
34781     a -= a_offset;
34782     --tau;
34783     c_dim1 = *ldc;
34784     c_offset = 1 + c_dim1;
34785     c__ -= c_offset;
34786     --work;
34787 
34788     /* Function Body */
34789     *info = 0;
34790     left = lsame_(side, "L");
34791     notran = lsame_(trans, "N");
34792 
34793 /*     NQ is the order of Q */
34794 
34795     if (left) {
34796 	nq = *m;
34797     } else {
34798 	nq = *n;
34799     }
34800     if (! left && ! lsame_(side, "R")) {
34801 	*info = -1;
34802     } else if (! notran && ! lsame_(trans, "T")) {
34803 	*info = -2;
34804     } else if (*m < 0) {
34805 	*info = -3;
34806     } else if (*n < 0) {
34807 	*info = -4;
34808     } else if (*k < 0 || *k > nq) {
34809 	*info = -5;
34810     } else if (*lda < max(1,nq)) {
34811 	*info = -7;
34812     } else if (*ldc < max(1,*m)) {
34813 	*info = -10;
34814     }
34815     if (*info != 0) {
34816 	i__1 = -(*info);
34817 	xerbla_("DORM2R", &i__1);
34818 	return 0;
34819     }
34820 
34821 /*     Quick return if possible */
34822 
34823     if (*m == 0 || *n == 0 || *k == 0) {
34824 	return 0;
34825     }
34826 
34827     if (left && ! notran || ! left && notran) {
34828 	i1 = 1;
34829 	i2 = *k;
34830 	i3 = 1;
34831     } else {
34832 	i1 = *k;
34833 	i2 = 1;
34834 	i3 = -1;
34835     }
34836 
34837     if (left) {
34838 	ni = *n;
34839 	jc = 1;
34840     } else {
34841 	mi = *m;
34842 	ic = 1;
34843     }
34844 
34845     i__1 = i2;
34846     i__2 = i3;
34847     for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
34848 	if (left) {
34849 
34850 /*           H(i) is applied to C(i:m,1:n) */
34851 
34852 	    mi = *m - i__ + 1;
34853 	    ic = i__;
34854 	} else {
34855 
34856 /*           H(i) is applied to C(1:m,i:n) */
34857 
34858 	    ni = *n - i__ + 1;
34859 	    jc = i__;
34860 	}
34861 
34862 /*        Apply H(i) */
34863 
34864 	aii = a[i__ + i__ * a_dim1];
34865 	a[i__ + i__ * a_dim1] = 1.;
34866 	dlarf_(side, &mi, &ni, &a[i__ + i__ * a_dim1], &c__1, &tau[i__], &c__[
34867 		ic + jc * c_dim1], ldc, &work[1]);
34868 	a[i__ + i__ * a_dim1] = aii;
34869 /* L10: */
34870     }
34871     return 0;
34872 
34873 /*     End of DORM2R */
34874 
34875 } /* dorm2r_ */
34876 
dormbr_(char * vect,char * side,char * trans,integer * m,integer * n,integer * k,doublereal * a,integer * lda,doublereal * tau,doublereal * c__,integer * ldc,doublereal * work,integer * lwork,integer * info)34877 /* Subroutine */ int dormbr_(char *vect, char *side, char *trans, integer *m,
34878 	integer *n, integer *k, doublereal *a, integer *lda, doublereal *tau,
34879 	doublereal *c__, integer *ldc, doublereal *work, integer *lwork,
34880 	integer *info)
34881 {
34882     /* System generated locals */
34883     address a__1[2];
34884     integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2];
34885     char ch__1[2];
34886 
34887     /* Local variables */
34888     static integer i1, i2, nb, mi, ni, nq, nw;
34889     static logical left;
34890     extern logical lsame_(char *, char *);
34891     static integer iinfo;
34892     extern /* Subroutine */ int xerbla_(char *, integer *);
34893     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
34894 	    integer *, integer *, ftnlen, ftnlen);
34895     extern /* Subroutine */ int dormlq_(char *, char *, integer *, integer *,
34896 	    integer *, doublereal *, integer *, doublereal *, doublereal *,
34897 	    integer *, doublereal *, integer *, integer *);
34898     static logical notran;
34899     extern /* Subroutine */ int dormqr_(char *, char *, integer *, integer *,
34900 	    integer *, doublereal *, integer *, doublereal *, doublereal *,
34901 	    integer *, doublereal *, integer *, integer *);
34902     static logical applyq;
34903     static char transt[1];
34904     static integer lwkopt;
34905     static logical lquery;
34906 
34907 
34908 /*
34909     -- LAPACK routine (version 3.2) --
34910     -- LAPACK is a software package provided by Univ. of Tennessee,    --
34911     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
34912        November 2006
34913 
34914 
34915     Purpose
34916     =======
34917 
34918     If VECT = 'Q', DORMBR overwrites the general real M-by-N matrix C
34919     with
34920                     SIDE = 'L'     SIDE = 'R'
34921     TRANS = 'N':      Q * C          C * Q
34922     TRANS = 'T':      Q**T * C       C * Q**T
34923 
34924     If VECT = 'P', DORMBR overwrites the general real M-by-N matrix C
34925     with
34926                     SIDE = 'L'     SIDE = 'R'
34927     TRANS = 'N':      P * C          C * P
34928     TRANS = 'T':      P**T * C       C * P**T
34929 
34930     Here Q and P**T are the orthogonal matrices determined by DGEBRD when
34931     reducing a real matrix A to bidiagonal form: A = Q * B * P**T. Q and
34932     P**T are defined as products of elementary reflectors H(i) and G(i)
34933     respectively.
34934 
34935     Let nq = m if SIDE = 'L' and nq = n if SIDE = 'R'. Thus nq is the
34936     order of the orthogonal matrix Q or P**T that is applied.
34937 
34938     If VECT = 'Q', A is assumed to have been an NQ-by-K matrix:
34939     if nq >= k, Q = H(1) H(2) . . . H(k);
34940     if nq < k, Q = H(1) H(2) . . . H(nq-1).
34941 
34942     If VECT = 'P', A is assumed to have been a K-by-NQ matrix:
34943     if k < nq, P = G(1) G(2) . . . G(k);
34944     if k >= nq, P = G(1) G(2) . . . G(nq-1).
34945 
34946     Arguments
34947     =========
34948 
34949     VECT    (input) CHARACTER*1
34950             = 'Q': apply Q or Q**T;
34951             = 'P': apply P or P**T.
34952 
34953     SIDE    (input) CHARACTER*1
34954             = 'L': apply Q, Q**T, P or P**T from the Left;
34955             = 'R': apply Q, Q**T, P or P**T from the Right.
34956 
34957     TRANS   (input) CHARACTER*1
34958             = 'N':  No transpose, apply Q  or P;
34959             = 'T':  Transpose, apply Q**T or P**T.
34960 
34961     M       (input) INTEGER
34962             The number of rows of the matrix C. M >= 0.
34963 
34964     N       (input) INTEGER
34965             The number of columns of the matrix C. N >= 0.
34966 
34967     K       (input) INTEGER
34968             If VECT = 'Q', the number of columns in the original
34969             matrix reduced by DGEBRD.
34970             If VECT = 'P', the number of rows in the original
34971             matrix reduced by DGEBRD.
34972             K >= 0.
34973 
34974     A       (input) DOUBLE PRECISION array, dimension
34975                                   (LDA,min(nq,K)) if VECT = 'Q'
34976                                   (LDA,nq)        if VECT = 'P'
34977             The vectors which define the elementary reflectors H(i) and
34978             G(i), whose products determine the matrices Q and P, as
34979             returned by DGEBRD.
34980 
34981     LDA     (input) INTEGER
34982             The leading dimension of the array A.
34983             If VECT = 'Q', LDA >= max(1,nq);
34984             if VECT = 'P', LDA >= max(1,min(nq,K)).
34985 
34986     TAU     (input) DOUBLE PRECISION array, dimension (min(nq,K))
34987             TAU(i) must contain the scalar factor of the elementary
34988             reflector H(i) or G(i) which determines Q or P, as returned
34989             by DGEBRD in the array argument TAUQ or TAUP.
34990 
34991     C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
34992             On entry, the M-by-N matrix C.
34993             On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q
34994             or P*C or P**T*C or C*P or C*P**T.
34995 
34996     LDC     (input) INTEGER
34997             The leading dimension of the array C. LDC >= max(1,M).
34998 
34999     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
35000             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
35001 
35002     LWORK   (input) INTEGER
35003             The dimension of the array WORK.
35004             If SIDE = 'L', LWORK >= max(1,N);
35005             if SIDE = 'R', LWORK >= max(1,M).
35006             For optimum performance LWORK >= N*NB if SIDE = 'L', and
35007             LWORK >= M*NB if SIDE = 'R', where NB is the optimal
35008             blocksize.
35009 
35010             If LWORK = -1, then a workspace query is assumed; the routine
35011             only calculates the optimal size of the WORK array, returns
35012             this value as the first entry of the WORK array, and no error
35013             message related to LWORK is issued by XERBLA.
35014 
35015     INFO    (output) INTEGER
35016             = 0:  successful exit
35017             < 0:  if INFO = -i, the i-th argument had an illegal value
35018 
35019     =====================================================================
35020 
35021 
35022        Test the input arguments
35023 */
35024 
35025     /* Parameter adjustments */
35026     a_dim1 = *lda;
35027     a_offset = 1 + a_dim1;
35028     a -= a_offset;
35029     --tau;
35030     c_dim1 = *ldc;
35031     c_offset = 1 + c_dim1;
35032     c__ -= c_offset;
35033     --work;
35034 
35035     /* Function Body */
35036     *info = 0;
35037     applyq = lsame_(vect, "Q");
35038     left = lsame_(side, "L");
35039     notran = lsame_(trans, "N");
35040     lquery = *lwork == -1;
35041 
35042 /*     NQ is the order of Q or P and NW is the minimum dimension of WORK */
35043 
35044     if (left) {
35045 	nq = *m;
35046 	nw = *n;
35047     } else {
35048 	nq = *n;
35049 	nw = *m;
35050     }
35051     if (! applyq && ! lsame_(vect, "P")) {
35052 	*info = -1;
35053     } else if (! left && ! lsame_(side, "R")) {
35054 	*info = -2;
35055     } else if (! notran && ! lsame_(trans, "T")) {
35056 	*info = -3;
35057     } else if (*m < 0) {
35058 	*info = -4;
35059     } else if (*n < 0) {
35060 	*info = -5;
35061     } else if (*k < 0) {
35062 	*info = -6;
35063     } else /* if(complicated condition) */ {
35064 /* Computing MAX */
35065 	i__1 = 1, i__2 = min(nq,*k);
35066 	if (applyq && *lda < max(1,nq) || ! applyq && *lda < max(i__1,i__2)) {
35067 	    *info = -8;
35068 	} else if (*ldc < max(1,*m)) {
35069 	    *info = -11;
35070 	} else if (*lwork < max(1,nw) && ! lquery) {
35071 	    *info = -13;
35072 	}
35073     }
35074 
35075     if (*info == 0) {
35076 	if (applyq) {
35077 	    if (left) {
35078 /* Writing concatenation */
35079 		i__3[0] = 1, a__1[0] = side;
35080 		i__3[1] = 1, a__1[1] = trans;
35081 		s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
35082 		i__1 = *m - 1;
35083 		i__2 = *m - 1;
35084 		nb = ilaenv_(&c__1, "DORMQR", ch__1, &i__1, n, &i__2, &c_n1, (
35085 			ftnlen)6, (ftnlen)2);
35086 	    } else {
35087 /* Writing concatenation */
35088 		i__3[0] = 1, a__1[0] = side;
35089 		i__3[1] = 1, a__1[1] = trans;
35090 		s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
35091 		i__1 = *n - 1;
35092 		i__2 = *n - 1;
35093 		nb = ilaenv_(&c__1, "DORMQR", ch__1, m, &i__1, &i__2, &c_n1, (
35094 			ftnlen)6, (ftnlen)2);
35095 	    }
35096 	} else {
35097 	    if (left) {
35098 /* Writing concatenation */
35099 		i__3[0] = 1, a__1[0] = side;
35100 		i__3[1] = 1, a__1[1] = trans;
35101 		s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
35102 		i__1 = *m - 1;
35103 		i__2 = *m - 1;
35104 		nb = ilaenv_(&c__1, "DORMLQ", ch__1, &i__1, n, &i__2, &c_n1, (
35105 			ftnlen)6, (ftnlen)2);
35106 	    } else {
35107 /* Writing concatenation */
35108 		i__3[0] = 1, a__1[0] = side;
35109 		i__3[1] = 1, a__1[1] = trans;
35110 		s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
35111 		i__1 = *n - 1;
35112 		i__2 = *n - 1;
35113 		nb = ilaenv_(&c__1, "DORMLQ", ch__1, m, &i__1, &i__2, &c_n1, (
35114 			ftnlen)6, (ftnlen)2);
35115 	    }
35116 	}
35117 	lwkopt = max(1,nw) * nb;
35118 	work[1] = (doublereal) lwkopt;
35119     }
35120 
35121     if (*info != 0) {
35122 	i__1 = -(*info);
35123 	xerbla_("DORMBR", &i__1);
35124 	return 0;
35125     } else if (lquery) {
35126 	return 0;
35127     }
35128 
35129 /*     Quick return if possible */
35130 
35131     work[1] = 1.;
35132     if (*m == 0 || *n == 0) {
35133 	return 0;
35134     }
35135 
35136     if (applyq) {
35137 
35138 /*        Apply Q */
35139 
35140 	if (nq >= *k) {
35141 
35142 /*           Q was determined by a call to DGEBRD with nq >= k */
35143 
35144 	    dormqr_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
35145 		    c_offset], ldc, &work[1], lwork, &iinfo);
35146 	} else if (nq > 1) {
35147 
35148 /*           Q was determined by a call to DGEBRD with nq < k */
35149 
35150 	    if (left) {
35151 		mi = *m - 1;
35152 		ni = *n;
35153 		i1 = 2;
35154 		i2 = 1;
35155 	    } else {
35156 		mi = *m;
35157 		ni = *n - 1;
35158 		i1 = 1;
35159 		i2 = 2;
35160 	    }
35161 	    i__1 = nq - 1;
35162 	    dormqr_(side, trans, &mi, &ni, &i__1, &a[a_dim1 + 2], lda, &tau[1]
35163 		    , &c__[i1 + i2 * c_dim1], ldc, &work[1], lwork, &iinfo);
35164 	}
35165     } else {
35166 
35167 /*        Apply P */
35168 
35169 	if (notran) {
35170 	    *(unsigned char *)transt = 'T';
35171 	} else {
35172 	    *(unsigned char *)transt = 'N';
35173 	}
35174 	if (nq > *k) {
35175 
35176 /*           P was determined by a call to DGEBRD with nq > k */
35177 
35178 	    dormlq_(side, transt, m, n, k, &a[a_offset], lda, &tau[1], &c__[
35179 		    c_offset], ldc, &work[1], lwork, &iinfo);
35180 	} else if (nq > 1) {
35181 
35182 /*           P was determined by a call to DGEBRD with nq <= k */
35183 
35184 	    if (left) {
35185 		mi = *m - 1;
35186 		ni = *n;
35187 		i1 = 2;
35188 		i2 = 1;
35189 	    } else {
35190 		mi = *m;
35191 		ni = *n - 1;
35192 		i1 = 1;
35193 		i2 = 2;
35194 	    }
35195 	    i__1 = nq - 1;
35196 	    dormlq_(side, transt, &mi, &ni, &i__1, &a[(a_dim1 << 1) + 1], lda,
35197 		     &tau[1], &c__[i1 + i2 * c_dim1], ldc, &work[1], lwork, &
35198 		    iinfo);
35199 	}
35200     }
35201     work[1] = (doublereal) lwkopt;
35202     return 0;
35203 
35204 /*     End of DORMBR */
35205 
35206 } /* dormbr_ */
35207 
dormhr_(char * side,char * trans,integer * m,integer * n,integer * ilo,integer * ihi,doublereal * a,integer * lda,doublereal * tau,doublereal * c__,integer * ldc,doublereal * work,integer * lwork,integer * info)35208 /* Subroutine */ int dormhr_(char *side, char *trans, integer *m, integer *n,
35209 	integer *ilo, integer *ihi, doublereal *a, integer *lda, doublereal *
35210 	tau, doublereal *c__, integer *ldc, doublereal *work, integer *lwork,
35211 	integer *info)
35212 {
35213     /* System generated locals */
35214     address a__1[2];
35215     integer a_dim1, a_offset, c_dim1, c_offset, i__1[2], i__2;
35216     char ch__1[2];
35217 
35218     /* Local variables */
35219     static integer i1, i2, nb, mi, nh, ni, nq, nw;
35220     static logical left;
35221     extern logical lsame_(char *, char *);
35222     static integer iinfo;
35223     extern /* Subroutine */ int xerbla_(char *, integer *);
35224     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
35225 	    integer *, integer *, ftnlen, ftnlen);
35226     extern /* Subroutine */ int dormqr_(char *, char *, integer *, integer *,
35227 	    integer *, doublereal *, integer *, doublereal *, doublereal *,
35228 	    integer *, doublereal *, integer *, integer *);
35229     static integer lwkopt;
35230     static logical lquery;
35231 
35232 
35233 /*
35234     -- LAPACK routine (version 3.2) --
35235     -- LAPACK is a software package provided by Univ. of Tennessee,    --
35236     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
35237        November 2006
35238 
35239 
35240     Purpose
35241     =======
35242 
35243     DORMHR overwrites the general real M-by-N matrix C with
35244 
35245                     SIDE = 'L'     SIDE = 'R'
35246     TRANS = 'N':      Q * C          C * Q
35247     TRANS = 'T':      Q**T * C       C * Q**T
35248 
35249     where Q is a real orthogonal matrix of order nq, with nq = m if
35250     SIDE = 'L' and nq = n if SIDE = 'R'. Q is defined as the product of
35251     IHI-ILO elementary reflectors, as returned by DGEHRD:
35252 
35253     Q = H(ilo) H(ilo+1) . . . H(ihi-1).
35254 
35255     Arguments
35256     =========
35257 
35258     SIDE    (input) CHARACTER*1
35259             = 'L': apply Q or Q**T from the Left;
35260             = 'R': apply Q or Q**T from the Right.
35261 
35262     TRANS   (input) CHARACTER*1
35263             = 'N':  No transpose, apply Q;
35264             = 'T':  Transpose, apply Q**T.
35265 
35266     M       (input) INTEGER
35267             The number of rows of the matrix C. M >= 0.
35268 
35269     N       (input) INTEGER
35270             The number of columns of the matrix C. N >= 0.
35271 
35272     ILO     (input) INTEGER
35273     IHI     (input) INTEGER
35274             ILO and IHI must have the same values as in the previous call
35275             of DGEHRD. Q is equal to the unit matrix except in the
35276             submatrix Q(ilo+1:ihi,ilo+1:ihi).
35277             If SIDE = 'L', then 1 <= ILO <= IHI <= M, if M > 0, and
35278             ILO = 1 and IHI = 0, if M = 0;
35279             if SIDE = 'R', then 1 <= ILO <= IHI <= N, if N > 0, and
35280             ILO = 1 and IHI = 0, if N = 0.
35281 
35282     A       (input) DOUBLE PRECISION array, dimension
35283                                  (LDA,M) if SIDE = 'L'
35284                                  (LDA,N) if SIDE = 'R'
35285             The vectors which define the elementary reflectors, as
35286             returned by DGEHRD.
35287 
35288     LDA     (input) INTEGER
35289             The leading dimension of the array A.
35290             LDA >= max(1,M) if SIDE = 'L'; LDA >= max(1,N) if SIDE = 'R'.
35291 
35292     TAU     (input) DOUBLE PRECISION array, dimension
35293                                  (M-1) if SIDE = 'L'
35294                                  (N-1) if SIDE = 'R'
35295             TAU(i) must contain the scalar factor of the elementary
35296             reflector H(i), as returned by DGEHRD.
35297 
35298     C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
35299             On entry, the M-by-N matrix C.
35300             On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.
35301 
35302     LDC     (input) INTEGER
35303             The leading dimension of the array C. LDC >= max(1,M).
35304 
35305     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
35306             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
35307 
35308     LWORK   (input) INTEGER
35309             The dimension of the array WORK.
35310             If SIDE = 'L', LWORK >= max(1,N);
35311             if SIDE = 'R', LWORK >= max(1,M).
35312             For optimum performance LWORK >= N*NB if SIDE = 'L', and
35313             LWORK >= M*NB if SIDE = 'R', where NB is the optimal
35314             blocksize.
35315 
35316             If LWORK = -1, then a workspace query is assumed; the routine
35317             only calculates the optimal size of the WORK array, returns
35318             this value as the first entry of the WORK array, and no error
35319             message related to LWORK is issued by XERBLA.
35320 
35321     INFO    (output) INTEGER
35322             = 0:  successful exit
35323             < 0:  if INFO = -i, the i-th argument had an illegal value
35324 
35325     =====================================================================
35326 
35327 
35328        Test the input arguments
35329 */
35330 
35331     /* Parameter adjustments */
35332     a_dim1 = *lda;
35333     a_offset = 1 + a_dim1;
35334     a -= a_offset;
35335     --tau;
35336     c_dim1 = *ldc;
35337     c_offset = 1 + c_dim1;
35338     c__ -= c_offset;
35339     --work;
35340 
35341     /* Function Body */
35342     *info = 0;
35343     nh = *ihi - *ilo;
35344     left = lsame_(side, "L");
35345     lquery = *lwork == -1;
35346 
35347 /*     NQ is the order of Q and NW is the minimum dimension of WORK */
35348 
35349     if (left) {
35350 	nq = *m;
35351 	nw = *n;
35352     } else {
35353 	nq = *n;
35354 	nw = *m;
35355     }
35356     if (! left && ! lsame_(side, "R")) {
35357 	*info = -1;
35358     } else if (! lsame_(trans, "N") && ! lsame_(trans,
35359 	    "T")) {
35360 	*info = -2;
35361     } else if (*m < 0) {
35362 	*info = -3;
35363     } else if (*n < 0) {
35364 	*info = -4;
35365     } else if (*ilo < 1 || *ilo > max(1,nq)) {
35366 	*info = -5;
35367     } else if (*ihi < min(*ilo,nq) || *ihi > nq) {
35368 	*info = -6;
35369     } else if (*lda < max(1,nq)) {
35370 	*info = -8;
35371     } else if (*ldc < max(1,*m)) {
35372 	*info = -11;
35373     } else if (*lwork < max(1,nw) && ! lquery) {
35374 	*info = -13;
35375     }
35376 
35377     if (*info == 0) {
35378 	if (left) {
35379 /* Writing concatenation */
35380 	    i__1[0] = 1, a__1[0] = side;
35381 	    i__1[1] = 1, a__1[1] = trans;
35382 	    s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
35383 	    nb = ilaenv_(&c__1, "DORMQR", ch__1, &nh, n, &nh, &c_n1, (ftnlen)
35384 		    6, (ftnlen)2);
35385 	} else {
35386 /* Writing concatenation */
35387 	    i__1[0] = 1, a__1[0] = side;
35388 	    i__1[1] = 1, a__1[1] = trans;
35389 	    s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
35390 	    nb = ilaenv_(&c__1, "DORMQR", ch__1, m, &nh, &nh, &c_n1, (ftnlen)
35391 		    6, (ftnlen)2);
35392 	}
35393 	lwkopt = max(1,nw) * nb;
35394 	work[1] = (doublereal) lwkopt;
35395     }
35396 
35397     if (*info != 0) {
35398 	i__2 = -(*info);
35399 	xerbla_("DORMHR", &i__2);
35400 	return 0;
35401     } else if (lquery) {
35402 	return 0;
35403     }
35404 
35405 /*     Quick return if possible */
35406 
35407     if (*m == 0 || *n == 0 || nh == 0) {
35408 	work[1] = 1.;
35409 	return 0;
35410     }
35411 
35412     if (left) {
35413 	mi = nh;
35414 	ni = *n;
35415 	i1 = *ilo + 1;
35416 	i2 = 1;
35417     } else {
35418 	mi = *m;
35419 	ni = nh;
35420 	i1 = 1;
35421 	i2 = *ilo + 1;
35422     }
35423 
35424     dormqr_(side, trans, &mi, &ni, &nh, &a[*ilo + 1 + *ilo * a_dim1], lda, &
35425 	    tau[*ilo], &c__[i1 + i2 * c_dim1], ldc, &work[1], lwork, &iinfo);
35426 
35427     work[1] = (doublereal) lwkopt;
35428     return 0;
35429 
35430 /*     End of DORMHR */
35431 
35432 } /* dormhr_ */
35433 
dorml2_(char * side,char * trans,integer * m,integer * n,integer * k,doublereal * a,integer * lda,doublereal * tau,doublereal * c__,integer * ldc,doublereal * work,integer * info)35434 /* Subroutine */ int dorml2_(char *side, char *trans, integer *m, integer *n,
35435 	integer *k, doublereal *a, integer *lda, doublereal *tau, doublereal *
35436 	c__, integer *ldc, doublereal *work, integer *info)
35437 {
35438     /* System generated locals */
35439     integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2;
35440 
35441     /* Local variables */
35442     static integer i__, i1, i2, i3, ic, jc, mi, ni, nq;
35443     static doublereal aii;
35444     static logical left;
35445     extern /* Subroutine */ int dlarf_(char *, integer *, integer *,
35446 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
35447 	    doublereal *);
35448     extern logical lsame_(char *, char *);
35449     extern /* Subroutine */ int xerbla_(char *, integer *);
35450     static logical notran;
35451 
35452 
35453 /*
35454     -- LAPACK routine (version 3.2) --
35455     -- LAPACK is a software package provided by Univ. of Tennessee,    --
35456     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
35457        November 2006
35458 
35459 
35460     Purpose
35461     =======
35462 
35463     DORML2 overwrites the general real m by n matrix C with
35464 
35465           Q * C  if SIDE = 'L' and TRANS = 'N', or
35466 
35467           Q'* C  if SIDE = 'L' and TRANS = 'T', or
35468 
35469           C * Q  if SIDE = 'R' and TRANS = 'N', or
35470 
35471           C * Q' if SIDE = 'R' and TRANS = 'T',
35472 
35473     where Q is a real orthogonal matrix defined as the product of k
35474     elementary reflectors
35475 
35476           Q = H(k) . . . H(2) H(1)
35477 
35478     as returned by DGELQF. Q is of order m if SIDE = 'L' and of order n
35479     if SIDE = 'R'.
35480 
35481     Arguments
35482     =========
35483 
35484     SIDE    (input) CHARACTER*1
35485             = 'L': apply Q or Q' from the Left
35486             = 'R': apply Q or Q' from the Right
35487 
35488     TRANS   (input) CHARACTER*1
35489             = 'N': apply Q  (No transpose)
35490             = 'T': apply Q' (Transpose)
35491 
35492     M       (input) INTEGER
35493             The number of rows of the matrix C. M >= 0.
35494 
35495     N       (input) INTEGER
35496             The number of columns of the matrix C. N >= 0.
35497 
35498     K       (input) INTEGER
35499             The number of elementary reflectors whose product defines
35500             the matrix Q.
35501             If SIDE = 'L', M >= K >= 0;
35502             if SIDE = 'R', N >= K >= 0.
35503 
35504     A       (input) DOUBLE PRECISION array, dimension
35505                                  (LDA,M) if SIDE = 'L',
35506                                  (LDA,N) if SIDE = 'R'
35507             The i-th row must contain the vector which defines the
35508             elementary reflector H(i), for i = 1,2,...,k, as returned by
35509             DGELQF in the first k rows of its array argument A.
35510             A is modified by the routine but restored on exit.
35511 
35512     LDA     (input) INTEGER
35513             The leading dimension of the array A. LDA >= max(1,K).
35514 
35515     TAU     (input) DOUBLE PRECISION array, dimension (K)
35516             TAU(i) must contain the scalar factor of the elementary
35517             reflector H(i), as returned by DGELQF.
35518 
35519     C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
35520             On entry, the m by n matrix C.
35521             On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q.
35522 
35523     LDC     (input) INTEGER
35524             The leading dimension of the array C. LDC >= max(1,M).
35525 
35526     WORK    (workspace) DOUBLE PRECISION array, dimension
35527                                      (N) if SIDE = 'L',
35528                                      (M) if SIDE = 'R'
35529 
35530     INFO    (output) INTEGER
35531             = 0: successful exit
35532             < 0: if INFO = -i, the i-th argument had an illegal value
35533 
35534     =====================================================================
35535 
35536 
35537        Test the input arguments
35538 */
35539 
35540     /* Parameter adjustments */
35541     a_dim1 = *lda;
35542     a_offset = 1 + a_dim1;
35543     a -= a_offset;
35544     --tau;
35545     c_dim1 = *ldc;
35546     c_offset = 1 + c_dim1;
35547     c__ -= c_offset;
35548     --work;
35549 
35550     /* Function Body */
35551     *info = 0;
35552     left = lsame_(side, "L");
35553     notran = lsame_(trans, "N");
35554 
35555 /*     NQ is the order of Q */
35556 
35557     if (left) {
35558 	nq = *m;
35559     } else {
35560 	nq = *n;
35561     }
35562     if (! left && ! lsame_(side, "R")) {
35563 	*info = -1;
35564     } else if (! notran && ! lsame_(trans, "T")) {
35565 	*info = -2;
35566     } else if (*m < 0) {
35567 	*info = -3;
35568     } else if (*n < 0) {
35569 	*info = -4;
35570     } else if (*k < 0 || *k > nq) {
35571 	*info = -5;
35572     } else if (*lda < max(1,*k)) {
35573 	*info = -7;
35574     } else if (*ldc < max(1,*m)) {
35575 	*info = -10;
35576     }
35577     if (*info != 0) {
35578 	i__1 = -(*info);
35579 	xerbla_("DORML2", &i__1);
35580 	return 0;
35581     }
35582 
35583 /*     Quick return if possible */
35584 
35585     if (*m == 0 || *n == 0 || *k == 0) {
35586 	return 0;
35587     }
35588 
35589     if (left && notran || ! left && ! notran) {
35590 	i1 = 1;
35591 	i2 = *k;
35592 	i3 = 1;
35593     } else {
35594 	i1 = *k;
35595 	i2 = 1;
35596 	i3 = -1;
35597     }
35598 
35599     if (left) {
35600 	ni = *n;
35601 	jc = 1;
35602     } else {
35603 	mi = *m;
35604 	ic = 1;
35605     }
35606 
35607     i__1 = i2;
35608     i__2 = i3;
35609     for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
35610 	if (left) {
35611 
35612 /*           H(i) is applied to C(i:m,1:n) */
35613 
35614 	    mi = *m - i__ + 1;
35615 	    ic = i__;
35616 	} else {
35617 
35618 /*           H(i) is applied to C(1:m,i:n) */
35619 
35620 	    ni = *n - i__ + 1;
35621 	    jc = i__;
35622 	}
35623 
35624 /*        Apply H(i) */
35625 
35626 	aii = a[i__ + i__ * a_dim1];
35627 	a[i__ + i__ * a_dim1] = 1.;
35628 	dlarf_(side, &mi, &ni, &a[i__ + i__ * a_dim1], lda, &tau[i__], &c__[
35629 		ic + jc * c_dim1], ldc, &work[1]);
35630 	a[i__ + i__ * a_dim1] = aii;
35631 /* L10: */
35632     }
35633     return 0;
35634 
35635 /*     End of DORML2 */
35636 
35637 } /* dorml2_ */
35638 
dormlq_(char * side,char * trans,integer * m,integer * n,integer * k,doublereal * a,integer * lda,doublereal * tau,doublereal * c__,integer * ldc,doublereal * work,integer * lwork,integer * info)35639 /* Subroutine */ int dormlq_(char *side, char *trans, integer *m, integer *n,
35640 	integer *k, doublereal *a, integer *lda, doublereal *tau, doublereal *
35641 	c__, integer *ldc, doublereal *work, integer *lwork, integer *info)
35642 {
35643     /* System generated locals */
35644     address a__1[2];
35645     integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2], i__4,
35646 	    i__5;
35647     char ch__1[2];
35648 
35649     /* Local variables */
35650     static integer i__;
35651     static doublereal t[4160]	/* was [65][64] */;
35652     static integer i1, i2, i3, ib, ic, jc, nb, mi, ni, nq, nw, iws;
35653     static logical left;
35654     extern logical lsame_(char *, char *);
35655     static integer nbmin, iinfo;
35656     extern /* Subroutine */ int dorml2_(char *, char *, integer *, integer *,
35657 	    integer *, doublereal *, integer *, doublereal *, doublereal *,
35658 	    integer *, doublereal *, integer *), dlarfb_(char
35659 	    *, char *, char *, char *, integer *, integer *, integer *,
35660 	    doublereal *, integer *, doublereal *, integer *, doublereal *,
35661 	    integer *, doublereal *, integer *), dlarft_(char *, char *, integer *, integer *, doublereal
35662 	    *, integer *, doublereal *, doublereal *, integer *), xerbla_(char *, integer *);
35663     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
35664 	    integer *, integer *, ftnlen, ftnlen);
35665     static logical notran;
35666     static integer ldwork;
35667     static char transt[1];
35668     static integer lwkopt;
35669     static logical lquery;
35670 
35671 
35672 /*
35673     -- LAPACK routine (version 3.2) --
35674     -- LAPACK is a software package provided by Univ. of Tennessee,    --
35675     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
35676        November 2006
35677 
35678 
35679     Purpose
35680     =======
35681 
35682     DORMLQ overwrites the general real M-by-N matrix C with
35683 
35684                     SIDE = 'L'     SIDE = 'R'
35685     TRANS = 'N':      Q * C          C * Q
35686     TRANS = 'T':      Q**T * C       C * Q**T
35687 
35688     where Q is a real orthogonal matrix defined as the product of k
35689     elementary reflectors
35690 
35691           Q = H(k) . . . H(2) H(1)
35692 
35693     as returned by DGELQF. Q is of order M if SIDE = 'L' and of order N
35694     if SIDE = 'R'.
35695 
35696     Arguments
35697     =========
35698 
35699     SIDE    (input) CHARACTER*1
35700             = 'L': apply Q or Q**T from the Left;
35701             = 'R': apply Q or Q**T from the Right.
35702 
35703     TRANS   (input) CHARACTER*1
35704             = 'N':  No transpose, apply Q;
35705             = 'T':  Transpose, apply Q**T.
35706 
35707     M       (input) INTEGER
35708             The number of rows of the matrix C. M >= 0.
35709 
35710     N       (input) INTEGER
35711             The number of columns of the matrix C. N >= 0.
35712 
35713     K       (input) INTEGER
35714             The number of elementary reflectors whose product defines
35715             the matrix Q.
35716             If SIDE = 'L', M >= K >= 0;
35717             if SIDE = 'R', N >= K >= 0.
35718 
35719     A       (input) DOUBLE PRECISION array, dimension
35720                                  (LDA,M) if SIDE = 'L',
35721                                  (LDA,N) if SIDE = 'R'
35722             The i-th row must contain the vector which defines the
35723             elementary reflector H(i), for i = 1,2,...,k, as returned by
35724             DGELQF in the first k rows of its array argument A.
35725             A is modified by the routine but restored on exit.
35726 
35727     LDA     (input) INTEGER
35728             The leading dimension of the array A. LDA >= max(1,K).
35729 
35730     TAU     (input) DOUBLE PRECISION array, dimension (K)
35731             TAU(i) must contain the scalar factor of the elementary
35732             reflector H(i), as returned by DGELQF.
35733 
35734     C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
35735             On entry, the M-by-N matrix C.
35736             On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.
35737 
35738     LDC     (input) INTEGER
35739             The leading dimension of the array C. LDC >= max(1,M).
35740 
35741     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
35742             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
35743 
35744     LWORK   (input) INTEGER
35745             The dimension of the array WORK.
35746             If SIDE = 'L', LWORK >= max(1,N);
35747             if SIDE = 'R', LWORK >= max(1,M).
35748             For optimum performance LWORK >= N*NB if SIDE = 'L', and
35749             LWORK >= M*NB if SIDE = 'R', where NB is the optimal
35750             blocksize.
35751 
35752             If LWORK = -1, then a workspace query is assumed; the routine
35753             only calculates the optimal size of the WORK array, returns
35754             this value as the first entry of the WORK array, and no error
35755             message related to LWORK is issued by XERBLA.
35756 
35757     INFO    (output) INTEGER
35758             = 0:  successful exit
35759             < 0:  if INFO = -i, the i-th argument had an illegal value
35760 
35761     =====================================================================
35762 
35763 
35764        Test the input arguments
35765 */
35766 
35767     /* Parameter adjustments */
35768     a_dim1 = *lda;
35769     a_offset = 1 + a_dim1;
35770     a -= a_offset;
35771     --tau;
35772     c_dim1 = *ldc;
35773     c_offset = 1 + c_dim1;
35774     c__ -= c_offset;
35775     --work;
35776 
35777     /* Function Body */
35778     *info = 0;
35779     left = lsame_(side, "L");
35780     notran = lsame_(trans, "N");
35781     lquery = *lwork == -1;
35782 
35783 /*     NQ is the order of Q and NW is the minimum dimension of WORK */
35784 
35785     if (left) {
35786 	nq = *m;
35787 	nw = *n;
35788     } else {
35789 	nq = *n;
35790 	nw = *m;
35791     }
35792     if (! left && ! lsame_(side, "R")) {
35793 	*info = -1;
35794     } else if (! notran && ! lsame_(trans, "T")) {
35795 	*info = -2;
35796     } else if (*m < 0) {
35797 	*info = -3;
35798     } else if (*n < 0) {
35799 	*info = -4;
35800     } else if (*k < 0 || *k > nq) {
35801 	*info = -5;
35802     } else if (*lda < max(1,*k)) {
35803 	*info = -7;
35804     } else if (*ldc < max(1,*m)) {
35805 	*info = -10;
35806     } else if (*lwork < max(1,nw) && ! lquery) {
35807 	*info = -12;
35808     }
35809 
35810     if (*info == 0) {
35811 
35812 /*
35813           Determine the block size.  NB may be at most NBMAX, where NBMAX
35814           is used to define the local array T.
35815 
35816    Computing MIN
35817    Writing concatenation
35818 */
35819 	i__3[0] = 1, a__1[0] = side;
35820 	i__3[1] = 1, a__1[1] = trans;
35821 	s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
35822 	i__1 = 64, i__2 = ilaenv_(&c__1, "DORMLQ", ch__1, m, n, k, &c_n1, (
35823 		ftnlen)6, (ftnlen)2);
35824 	nb = min(i__1,i__2);
35825 	lwkopt = max(1,nw) * nb;
35826 	work[1] = (doublereal) lwkopt;
35827     }
35828 
35829     if (*info != 0) {
35830 	i__1 = -(*info);
35831 	xerbla_("DORMLQ", &i__1);
35832 	return 0;
35833     } else if (lquery) {
35834 	return 0;
35835     }
35836 
35837 /*     Quick return if possible */
35838 
35839     if (*m == 0 || *n == 0 || *k == 0) {
35840 	work[1] = 1.;
35841 	return 0;
35842     }
35843 
35844     nbmin = 2;
35845     ldwork = nw;
35846     if (nb > 1 && nb < *k) {
35847 	iws = nw * nb;
35848 	if (*lwork < iws) {
35849 	    nb = *lwork / ldwork;
35850 /*
35851    Computing MAX
35852    Writing concatenation
35853 */
35854 	    i__3[0] = 1, a__1[0] = side;
35855 	    i__3[1] = 1, a__1[1] = trans;
35856 	    s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
35857 	    i__1 = 2, i__2 = ilaenv_(&c__2, "DORMLQ", ch__1, m, n, k, &c_n1, (
35858 		    ftnlen)6, (ftnlen)2);
35859 	    nbmin = max(i__1,i__2);
35860 	}
35861     } else {
35862 	iws = nw;
35863     }
35864 
35865     if (nb < nbmin || nb >= *k) {
35866 
35867 /*        Use unblocked code */
35868 
35869 	dorml2_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
35870 		c_offset], ldc, &work[1], &iinfo);
35871     } else {
35872 
35873 /*        Use blocked code */
35874 
35875 	if (left && notran || ! left && ! notran) {
35876 	    i1 = 1;
35877 	    i2 = *k;
35878 	    i3 = nb;
35879 	} else {
35880 	    i1 = (*k - 1) / nb * nb + 1;
35881 	    i2 = 1;
35882 	    i3 = -nb;
35883 	}
35884 
35885 	if (left) {
35886 	    ni = *n;
35887 	    jc = 1;
35888 	} else {
35889 	    mi = *m;
35890 	    ic = 1;
35891 	}
35892 
35893 	if (notran) {
35894 	    *(unsigned char *)transt = 'T';
35895 	} else {
35896 	    *(unsigned char *)transt = 'N';
35897 	}
35898 
35899 	i__1 = i2;
35900 	i__2 = i3;
35901 	for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
35902 /* Computing MIN */
35903 	    i__4 = nb, i__5 = *k - i__ + 1;
35904 	    ib = min(i__4,i__5);
35905 
35906 /*
35907              Form the triangular factor of the block reflector
35908              H = H(i) H(i+1) . . . H(i+ib-1)
35909 */
35910 
35911 	    i__4 = nq - i__ + 1;
35912 	    dlarft_("Forward", "Rowwise", &i__4, &ib, &a[i__ + i__ * a_dim1],
35913 		    lda, &tau[i__], t, &c__65);
35914 	    if (left) {
35915 
35916 /*              H or H' is applied to C(i:m,1:n) */
35917 
35918 		mi = *m - i__ + 1;
35919 		ic = i__;
35920 	    } else {
35921 
35922 /*              H or H' is applied to C(1:m,i:n) */
35923 
35924 		ni = *n - i__ + 1;
35925 		jc = i__;
35926 	    }
35927 
35928 /*           Apply H or H' */
35929 
35930 	    dlarfb_(side, transt, "Forward", "Rowwise", &mi, &ni, &ib, &a[i__
35931 		    + i__ * a_dim1], lda, t, &c__65, &c__[ic + jc * c_dim1],
35932 		    ldc, &work[1], &ldwork);
35933 /* L10: */
35934 	}
35935     }
35936     work[1] = (doublereal) lwkopt;
35937     return 0;
35938 
35939 /*     End of DORMLQ */
35940 
35941 } /* dormlq_ */
35942 
dormql_(char * side,char * trans,integer * m,integer * n,integer * k,doublereal * a,integer * lda,doublereal * tau,doublereal * c__,integer * ldc,doublereal * work,integer * lwork,integer * info)35943 /* Subroutine */ int dormql_(char *side, char *trans, integer *m, integer *n,
35944 	integer *k, doublereal *a, integer *lda, doublereal *tau, doublereal *
35945 	c__, integer *ldc, doublereal *work, integer *lwork, integer *info)
35946 {
35947     /* System generated locals */
35948     address a__1[2];
35949     integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2], i__4,
35950 	    i__5;
35951     char ch__1[2];
35952 
35953     /* Local variables */
35954     static integer i__;
35955     static doublereal t[4160]	/* was [65][64] */;
35956     static integer i1, i2, i3, ib, nb, mi, ni, nq, nw, iws;
35957     static logical left;
35958     extern logical lsame_(char *, char *);
35959     static integer nbmin, iinfo;
35960     extern /* Subroutine */ int dorm2l_(char *, char *, integer *, integer *,
35961 	    integer *, doublereal *, integer *, doublereal *, doublereal *,
35962 	    integer *, doublereal *, integer *), dlarfb_(char
35963 	    *, char *, char *, char *, integer *, integer *, integer *,
35964 	    doublereal *, integer *, doublereal *, integer *, doublereal *,
35965 	    integer *, doublereal *, integer *), dlarft_(char *, char *, integer *, integer *, doublereal
35966 	    *, integer *, doublereal *, doublereal *, integer *), xerbla_(char *, integer *);
35967     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
35968 	    integer *, integer *, ftnlen, ftnlen);
35969     static logical notran;
35970     static integer ldwork, lwkopt;
35971     static logical lquery;
35972 
35973 
35974 /*
35975     -- LAPACK routine (version 3.2) --
35976     -- LAPACK is a software package provided by Univ. of Tennessee,    --
35977     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
35978        November 2006
35979 
35980 
35981     Purpose
35982     =======
35983 
35984     DORMQL overwrites the general real M-by-N matrix C with
35985 
35986                     SIDE = 'L'     SIDE = 'R'
35987     TRANS = 'N':      Q * C          C * Q
35988     TRANS = 'T':      Q**T * C       C * Q**T
35989 
35990     where Q is a real orthogonal matrix defined as the product of k
35991     elementary reflectors
35992 
35993           Q = H(k) . . . H(2) H(1)
35994 
35995     as returned by DGEQLF. Q is of order M if SIDE = 'L' and of order N
35996     if SIDE = 'R'.
35997 
35998     Arguments
35999     =========
36000 
36001     SIDE    (input) CHARACTER*1
36002             = 'L': apply Q or Q**T from the Left;
36003             = 'R': apply Q or Q**T from the Right.
36004 
36005     TRANS   (input) CHARACTER*1
36006             = 'N':  No transpose, apply Q;
36007             = 'T':  Transpose, apply Q**T.
36008 
36009     M       (input) INTEGER
36010             The number of rows of the matrix C. M >= 0.
36011 
36012     N       (input) INTEGER
36013             The number of columns of the matrix C. N >= 0.
36014 
36015     K       (input) INTEGER
36016             The number of elementary reflectors whose product defines
36017             the matrix Q.
36018             If SIDE = 'L', M >= K >= 0;
36019             if SIDE = 'R', N >= K >= 0.
36020 
36021     A       (input) DOUBLE PRECISION array, dimension (LDA,K)
36022             The i-th column must contain the vector which defines the
36023             elementary reflector H(i), for i = 1,2,...,k, as returned by
36024             DGEQLF in the last k columns of its array argument A.
36025             A is modified by the routine but restored on exit.
36026 
36027     LDA     (input) INTEGER
36028             The leading dimension of the array A.
36029             If SIDE = 'L', LDA >= max(1,M);
36030             if SIDE = 'R', LDA >= max(1,N).
36031 
36032     TAU     (input) DOUBLE PRECISION array, dimension (K)
36033             TAU(i) must contain the scalar factor of the elementary
36034             reflector H(i), as returned by DGEQLF.
36035 
36036     C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
36037             On entry, the M-by-N matrix C.
36038             On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.
36039 
36040     LDC     (input) INTEGER
36041             The leading dimension of the array C. LDC >= max(1,M).
36042 
36043     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
36044             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
36045 
36046     LWORK   (input) INTEGER
36047             The dimension of the array WORK.
36048             If SIDE = 'L', LWORK >= max(1,N);
36049             if SIDE = 'R', LWORK >= max(1,M).
36050             For optimum performance LWORK >= N*NB if SIDE = 'L', and
36051             LWORK >= M*NB if SIDE = 'R', where NB is the optimal
36052             blocksize.
36053 
36054             If LWORK = -1, then a workspace query is assumed; the routine
36055             only calculates the optimal size of the WORK array, returns
36056             this value as the first entry of the WORK array, and no error
36057             message related to LWORK is issued by XERBLA.
36058 
36059     INFO    (output) INTEGER
36060             = 0:  successful exit
36061             < 0:  if INFO = -i, the i-th argument had an illegal value
36062 
36063     =====================================================================
36064 
36065 
36066        Test the input arguments
36067 */
36068 
36069     /* Parameter adjustments */
36070     a_dim1 = *lda;
36071     a_offset = 1 + a_dim1;
36072     a -= a_offset;
36073     --tau;
36074     c_dim1 = *ldc;
36075     c_offset = 1 + c_dim1;
36076     c__ -= c_offset;
36077     --work;
36078 
36079     /* Function Body */
36080     *info = 0;
36081     left = lsame_(side, "L");
36082     notran = lsame_(trans, "N");
36083     lquery = *lwork == -1;
36084 
36085 /*     NQ is the order of Q and NW is the minimum dimension of WORK */
36086 
36087     if (left) {
36088 	nq = *m;
36089 	nw = max(1,*n);
36090     } else {
36091 	nq = *n;
36092 	nw = max(1,*m);
36093     }
36094     if (! left && ! lsame_(side, "R")) {
36095 	*info = -1;
36096     } else if (! notran && ! lsame_(trans, "T")) {
36097 	*info = -2;
36098     } else if (*m < 0) {
36099 	*info = -3;
36100     } else if (*n < 0) {
36101 	*info = -4;
36102     } else if (*k < 0 || *k > nq) {
36103 	*info = -5;
36104     } else if (*lda < max(1,nq)) {
36105 	*info = -7;
36106     } else if (*ldc < max(1,*m)) {
36107 	*info = -10;
36108     }
36109 
36110     if (*info == 0) {
36111 	if (*m == 0 || *n == 0) {
36112 	    lwkopt = 1;
36113 	} else {
36114 
36115 /*
36116              Determine the block size.  NB may be at most NBMAX, where
36117              NBMAX is used to define the local array T.
36118 
36119    Computing MIN
36120    Writing concatenation
36121 */
36122 	    i__3[0] = 1, a__1[0] = side;
36123 	    i__3[1] = 1, a__1[1] = trans;
36124 	    s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
36125 	    i__1 = 64, i__2 = ilaenv_(&c__1, "DORMQL", ch__1, m, n, k, &c_n1,
36126 		    (ftnlen)6, (ftnlen)2);
36127 	    nb = min(i__1,i__2);
36128 	    lwkopt = nw * nb;
36129 	}
36130 	work[1] = (doublereal) lwkopt;
36131 
36132 	if (*lwork < nw && ! lquery) {
36133 	    *info = -12;
36134 	}
36135     }
36136 
36137     if (*info != 0) {
36138 	i__1 = -(*info);
36139 	xerbla_("DORMQL", &i__1);
36140 	return 0;
36141     } else if (lquery) {
36142 	return 0;
36143     }
36144 
36145 /*     Quick return if possible */
36146 
36147     if (*m == 0 || *n == 0) {
36148 	return 0;
36149     }
36150 
36151     nbmin = 2;
36152     ldwork = nw;
36153     if (nb > 1 && nb < *k) {
36154 	iws = nw * nb;
36155 	if (*lwork < iws) {
36156 	    nb = *lwork / ldwork;
36157 /*
36158    Computing MAX
36159    Writing concatenation
36160 */
36161 	    i__3[0] = 1, a__1[0] = side;
36162 	    i__3[1] = 1, a__1[1] = trans;
36163 	    s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
36164 	    i__1 = 2, i__2 = ilaenv_(&c__2, "DORMQL", ch__1, m, n, k, &c_n1, (
36165 		    ftnlen)6, (ftnlen)2);
36166 	    nbmin = max(i__1,i__2);
36167 	}
36168     } else {
36169 	iws = nw;
36170     }
36171 
36172     if (nb < nbmin || nb >= *k) {
36173 
36174 /*        Use unblocked code */
36175 
36176 	dorm2l_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
36177 		c_offset], ldc, &work[1], &iinfo);
36178     } else {
36179 
36180 /*        Use blocked code */
36181 
36182 	if (left && notran || ! left && ! notran) {
36183 	    i1 = 1;
36184 	    i2 = *k;
36185 	    i3 = nb;
36186 	} else {
36187 	    i1 = (*k - 1) / nb * nb + 1;
36188 	    i2 = 1;
36189 	    i3 = -nb;
36190 	}
36191 
36192 	if (left) {
36193 	    ni = *n;
36194 	} else {
36195 	    mi = *m;
36196 	}
36197 
36198 	i__1 = i2;
36199 	i__2 = i3;
36200 	for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
36201 /* Computing MIN */
36202 	    i__4 = nb, i__5 = *k - i__ + 1;
36203 	    ib = min(i__4,i__5);
36204 
36205 /*
36206              Form the triangular factor of the block reflector
36207              H = H(i+ib-1) . . . H(i+1) H(i)
36208 */
36209 
36210 	    i__4 = nq - *k + i__ + ib - 1;
36211 	    dlarft_("Backward", "Columnwise", &i__4, &ib, &a[i__ * a_dim1 + 1]
36212 		    , lda, &tau[i__], t, &c__65);
36213 	    if (left) {
36214 
36215 /*              H or H' is applied to C(1:m-k+i+ib-1,1:n) */
36216 
36217 		mi = *m - *k + i__ + ib - 1;
36218 	    } else {
36219 
36220 /*              H or H' is applied to C(1:m,1:n-k+i+ib-1) */
36221 
36222 		ni = *n - *k + i__ + ib - 1;
36223 	    }
36224 
36225 /*           Apply H or H' */
36226 
36227 	    dlarfb_(side, trans, "Backward", "Columnwise", &mi, &ni, &ib, &a[
36228 		    i__ * a_dim1 + 1], lda, t, &c__65, &c__[c_offset], ldc, &
36229 		    work[1], &ldwork);
36230 /* L10: */
36231 	}
36232     }
36233     work[1] = (doublereal) lwkopt;
36234     return 0;
36235 
36236 /*     End of DORMQL */
36237 
36238 } /* dormql_ */
36239 
dormqr_(char * side,char * trans,integer * m,integer * n,integer * k,doublereal * a,integer * lda,doublereal * tau,doublereal * c__,integer * ldc,doublereal * work,integer * lwork,integer * info)36240 /* Subroutine */ int dormqr_(char *side, char *trans, integer *m, integer *n,
36241 	integer *k, doublereal *a, integer *lda, doublereal *tau, doublereal *
36242 	c__, integer *ldc, doublereal *work, integer *lwork, integer *info)
36243 {
36244     /* System generated locals */
36245     address a__1[2];
36246     integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2], i__4,
36247 	    i__5;
36248     char ch__1[2];
36249 
36250     /* Local variables */
36251     static integer i__;
36252     static doublereal t[4160]	/* was [65][64] */;
36253     static integer i1, i2, i3, ib, ic, jc, nb, mi, ni, nq, nw, iws;
36254     static logical left;
36255     extern logical lsame_(char *, char *);
36256     static integer nbmin, iinfo;
36257     extern /* Subroutine */ int dorm2r_(char *, char *, integer *, integer *,
36258 	    integer *, doublereal *, integer *, doublereal *, doublereal *,
36259 	    integer *, doublereal *, integer *), dlarfb_(char
36260 	    *, char *, char *, char *, integer *, integer *, integer *,
36261 	    doublereal *, integer *, doublereal *, integer *, doublereal *,
36262 	    integer *, doublereal *, integer *), dlarft_(char *, char *, integer *, integer *, doublereal
36263 	    *, integer *, doublereal *, doublereal *, integer *), xerbla_(char *, integer *);
36264     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
36265 	    integer *, integer *, ftnlen, ftnlen);
36266     static logical notran;
36267     static integer ldwork, lwkopt;
36268     static logical lquery;
36269 
36270 
36271 /*
36272     -- LAPACK routine (version 3.2) --
36273     -- LAPACK is a software package provided by Univ. of Tennessee,    --
36274     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
36275        November 2006
36276 
36277 
36278     Purpose
36279     =======
36280 
36281     DORMQR overwrites the general real M-by-N matrix C with
36282 
36283                     SIDE = 'L'     SIDE = 'R'
36284     TRANS = 'N':      Q * C          C * Q
36285     TRANS = 'T':      Q**T * C       C * Q**T
36286 
36287     where Q is a real orthogonal matrix defined as the product of k
36288     elementary reflectors
36289 
36290           Q = H(1) H(2) . . . H(k)
36291 
36292     as returned by DGEQRF. Q is of order M if SIDE = 'L' and of order N
36293     if SIDE = 'R'.
36294 
36295     Arguments
36296     =========
36297 
36298     SIDE    (input) CHARACTER*1
36299             = 'L': apply Q or Q**T from the Left;
36300             = 'R': apply Q or Q**T from the Right.
36301 
36302     TRANS   (input) CHARACTER*1
36303             = 'N':  No transpose, apply Q;
36304             = 'T':  Transpose, apply Q**T.
36305 
36306     M       (input) INTEGER
36307             The number of rows of the matrix C. M >= 0.
36308 
36309     N       (input) INTEGER
36310             The number of columns of the matrix C. N >= 0.
36311 
36312     K       (input) INTEGER
36313             The number of elementary reflectors whose product defines
36314             the matrix Q.
36315             If SIDE = 'L', M >= K >= 0;
36316             if SIDE = 'R', N >= K >= 0.
36317 
36318     A       (input) DOUBLE PRECISION array, dimension (LDA,K)
36319             The i-th column must contain the vector which defines the
36320             elementary reflector H(i), for i = 1,2,...,k, as returned by
36321             DGEQRF in the first k columns of its array argument A.
36322             A is modified by the routine but restored on exit.
36323 
36324     LDA     (input) INTEGER
36325             The leading dimension of the array A.
36326             If SIDE = 'L', LDA >= max(1,M);
36327             if SIDE = 'R', LDA >= max(1,N).
36328 
36329     TAU     (input) DOUBLE PRECISION array, dimension (K)
36330             TAU(i) must contain the scalar factor of the elementary
36331             reflector H(i), as returned by DGEQRF.
36332 
36333     C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
36334             On entry, the M-by-N matrix C.
36335             On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.
36336 
36337     LDC     (input) INTEGER
36338             The leading dimension of the array C. LDC >= max(1,M).
36339 
36340     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
36341             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
36342 
36343     LWORK   (input) INTEGER
36344             The dimension of the array WORK.
36345             If SIDE = 'L', LWORK >= max(1,N);
36346             if SIDE = 'R', LWORK >= max(1,M).
36347             For optimum performance LWORK >= N*NB if SIDE = 'L', and
36348             LWORK >= M*NB if SIDE = 'R', where NB is the optimal
36349             blocksize.
36350 
36351             If LWORK = -1, then a workspace query is assumed; the routine
36352             only calculates the optimal size of the WORK array, returns
36353             this value as the first entry of the WORK array, and no error
36354             message related to LWORK is issued by XERBLA.
36355 
36356     INFO    (output) INTEGER
36357             = 0:  successful exit
36358             < 0:  if INFO = -i, the i-th argument had an illegal value
36359 
36360     =====================================================================
36361 
36362 
36363        Test the input arguments
36364 */
36365 
36366     /* Parameter adjustments */
36367     a_dim1 = *lda;
36368     a_offset = 1 + a_dim1;
36369     a -= a_offset;
36370     --tau;
36371     c_dim1 = *ldc;
36372     c_offset = 1 + c_dim1;
36373     c__ -= c_offset;
36374     --work;
36375 
36376     /* Function Body */
36377     *info = 0;
36378     left = lsame_(side, "L");
36379     notran = lsame_(trans, "N");
36380     lquery = *lwork == -1;
36381 
36382 /*     NQ is the order of Q and NW is the minimum dimension of WORK */
36383 
36384     if (left) {
36385 	nq = *m;
36386 	nw = *n;
36387     } else {
36388 	nq = *n;
36389 	nw = *m;
36390     }
36391     if (! left && ! lsame_(side, "R")) {
36392 	*info = -1;
36393     } else if (! notran && ! lsame_(trans, "T")) {
36394 	*info = -2;
36395     } else if (*m < 0) {
36396 	*info = -3;
36397     } else if (*n < 0) {
36398 	*info = -4;
36399     } else if (*k < 0 || *k > nq) {
36400 	*info = -5;
36401     } else if (*lda < max(1,nq)) {
36402 	*info = -7;
36403     } else if (*ldc < max(1,*m)) {
36404 	*info = -10;
36405     } else if (*lwork < max(1,nw) && ! lquery) {
36406 	*info = -12;
36407     }
36408 
36409     if (*info == 0) {
36410 
36411 /*
36412           Determine the block size.  NB may be at most NBMAX, where NBMAX
36413           is used to define the local array T.
36414 
36415    Computing MIN
36416    Writing concatenation
36417 */
36418 	i__3[0] = 1, a__1[0] = side;
36419 	i__3[1] = 1, a__1[1] = trans;
36420 	s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
36421 	i__1 = 64, i__2 = ilaenv_(&c__1, "DORMQR", ch__1, m, n, k, &c_n1, (
36422 		ftnlen)6, (ftnlen)2);
36423 	nb = min(i__1,i__2);
36424 	lwkopt = max(1,nw) * nb;
36425 	work[1] = (doublereal) lwkopt;
36426     }
36427 
36428     if (*info != 0) {
36429 	i__1 = -(*info);
36430 	xerbla_("DORMQR", &i__1);
36431 	return 0;
36432     } else if (lquery) {
36433 	return 0;
36434     }
36435 
36436 /*     Quick return if possible */
36437 
36438     if (*m == 0 || *n == 0 || *k == 0) {
36439 	work[1] = 1.;
36440 	return 0;
36441     }
36442 
36443     nbmin = 2;
36444     ldwork = nw;
36445     if (nb > 1 && nb < *k) {
36446 	iws = nw * nb;
36447 	if (*lwork < iws) {
36448 	    nb = *lwork / ldwork;
36449 /*
36450    Computing MAX
36451    Writing concatenation
36452 */
36453 	    i__3[0] = 1, a__1[0] = side;
36454 	    i__3[1] = 1, a__1[1] = trans;
36455 	    s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
36456 	    i__1 = 2, i__2 = ilaenv_(&c__2, "DORMQR", ch__1, m, n, k, &c_n1, (
36457 		    ftnlen)6, (ftnlen)2);
36458 	    nbmin = max(i__1,i__2);
36459 	}
36460     } else {
36461 	iws = nw;
36462     }
36463 
36464     if (nb < nbmin || nb >= *k) {
36465 
36466 /*        Use unblocked code */
36467 
36468 	dorm2r_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
36469 		c_offset], ldc, &work[1], &iinfo);
36470     } else {
36471 
36472 /*        Use blocked code */
36473 
36474 	if (left && ! notran || ! left && notran) {
36475 	    i1 = 1;
36476 	    i2 = *k;
36477 	    i3 = nb;
36478 	} else {
36479 	    i1 = (*k - 1) / nb * nb + 1;
36480 	    i2 = 1;
36481 	    i3 = -nb;
36482 	}
36483 
36484 	if (left) {
36485 	    ni = *n;
36486 	    jc = 1;
36487 	} else {
36488 	    mi = *m;
36489 	    ic = 1;
36490 	}
36491 
36492 	i__1 = i2;
36493 	i__2 = i3;
36494 	for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
36495 /* Computing MIN */
36496 	    i__4 = nb, i__5 = *k - i__ + 1;
36497 	    ib = min(i__4,i__5);
36498 
36499 /*
36500              Form the triangular factor of the block reflector
36501              H = H(i) H(i+1) . . . H(i+ib-1)
36502 */
36503 
36504 	    i__4 = nq - i__ + 1;
36505 	    dlarft_("Forward", "Columnwise", &i__4, &ib, &a[i__ + i__ *
36506 		    a_dim1], lda, &tau[i__], t, &c__65)
36507 		    ;
36508 	    if (left) {
36509 
36510 /*              H or H' is applied to C(i:m,1:n) */
36511 
36512 		mi = *m - i__ + 1;
36513 		ic = i__;
36514 	    } else {
36515 
36516 /*              H or H' is applied to C(1:m,i:n) */
36517 
36518 		ni = *n - i__ + 1;
36519 		jc = i__;
36520 	    }
36521 
36522 /*           Apply H or H' */
36523 
36524 	    dlarfb_(side, trans, "Forward", "Columnwise", &mi, &ni, &ib, &a[
36525 		    i__ + i__ * a_dim1], lda, t, &c__65, &c__[ic + jc *
36526 		    c_dim1], ldc, &work[1], &ldwork);
36527 /* L10: */
36528 	}
36529     }
36530     work[1] = (doublereal) lwkopt;
36531     return 0;
36532 
36533 /*     End of DORMQR */
36534 
36535 } /* dormqr_ */
36536 
dormtr_(char * side,char * uplo,char * trans,integer * m,integer * n,doublereal * a,integer * lda,doublereal * tau,doublereal * c__,integer * ldc,doublereal * work,integer * lwork,integer * info)36537 /* Subroutine */ int dormtr_(char *side, char *uplo, char *trans, integer *m,
36538 	integer *n, doublereal *a, integer *lda, doublereal *tau, doublereal *
36539 	c__, integer *ldc, doublereal *work, integer *lwork, integer *info)
36540 {
36541     /* System generated locals */
36542     address a__1[2];
36543     integer a_dim1, a_offset, c_dim1, c_offset, i__1[2], i__2, i__3;
36544     char ch__1[2];
36545 
36546     /* Local variables */
36547     static integer i1, i2, nb, mi, ni, nq, nw;
36548     static logical left;
36549     extern logical lsame_(char *, char *);
36550     static integer iinfo;
36551     static logical upper;
36552     extern /* Subroutine */ int xerbla_(char *, integer *);
36553     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
36554 	    integer *, integer *, ftnlen, ftnlen);
36555     extern /* Subroutine */ int dormql_(char *, char *, integer *, integer *,
36556 	    integer *, doublereal *, integer *, doublereal *, doublereal *,
36557 	    integer *, doublereal *, integer *, integer *),
36558 	    dormqr_(char *, char *, integer *, integer *, integer *,
36559 	    doublereal *, integer *, doublereal *, doublereal *, integer *,
36560 	    doublereal *, integer *, integer *);
36561     static integer lwkopt;
36562     static logical lquery;
36563 
36564 
36565 /*
36566     -- LAPACK routine (version 3.2) --
36567     -- LAPACK is a software package provided by Univ. of Tennessee,    --
36568     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
36569        November 2006
36570 
36571 
36572     Purpose
36573     =======
36574 
36575     DORMTR overwrites the general real M-by-N matrix C with
36576 
36577                     SIDE = 'L'     SIDE = 'R'
36578     TRANS = 'N':      Q * C          C * Q
36579     TRANS = 'T':      Q**T * C       C * Q**T
36580 
36581     where Q is a real orthogonal matrix of order nq, with nq = m if
36582     SIDE = 'L' and nq = n if SIDE = 'R'. Q is defined as the product of
36583     nq-1 elementary reflectors, as returned by DSYTRD:
36584 
36585     if UPLO = 'U', Q = H(nq-1) . . . H(2) H(1);
36586 
36587     if UPLO = 'L', Q = H(1) H(2) . . . H(nq-1).
36588 
36589     Arguments
36590     =========
36591 
36592     SIDE    (input) CHARACTER*1
36593             = 'L': apply Q or Q**T from the Left;
36594             = 'R': apply Q or Q**T from the Right.
36595 
36596     UPLO    (input) CHARACTER*1
36597             = 'U': Upper triangle of A contains elementary reflectors
36598                    from DSYTRD;
36599             = 'L': Lower triangle of A contains elementary reflectors
36600                    from DSYTRD.
36601 
36602     TRANS   (input) CHARACTER*1
36603             = 'N':  No transpose, apply Q;
36604             = 'T':  Transpose, apply Q**T.
36605 
36606     M       (input) INTEGER
36607             The number of rows of the matrix C. M >= 0.
36608 
36609     N       (input) INTEGER
36610             The number of columns of the matrix C. N >= 0.
36611 
36612     A       (input) DOUBLE PRECISION array, dimension
36613                                  (LDA,M) if SIDE = 'L'
36614                                  (LDA,N) if SIDE = 'R'
36615             The vectors which define the elementary reflectors, as
36616             returned by DSYTRD.
36617 
36618     LDA     (input) INTEGER
36619             The leading dimension of the array A.
36620             LDA >= max(1,M) if SIDE = 'L'; LDA >= max(1,N) if SIDE = 'R'.
36621 
36622     TAU     (input) DOUBLE PRECISION array, dimension
36623                                  (M-1) if SIDE = 'L'
36624                                  (N-1) if SIDE = 'R'
36625             TAU(i) must contain the scalar factor of the elementary
36626             reflector H(i), as returned by DSYTRD.
36627 
36628     C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
36629             On entry, the M-by-N matrix C.
36630             On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.
36631 
36632     LDC     (input) INTEGER
36633             The leading dimension of the array C. LDC >= max(1,M).
36634 
36635     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
36636             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
36637 
36638     LWORK   (input) INTEGER
36639             The dimension of the array WORK.
36640             If SIDE = 'L', LWORK >= max(1,N);
36641             if SIDE = 'R', LWORK >= max(1,M).
36642             For optimum performance LWORK >= N*NB if SIDE = 'L', and
36643             LWORK >= M*NB if SIDE = 'R', where NB is the optimal
36644             blocksize.
36645 
36646             If LWORK = -1, then a workspace query is assumed; the routine
36647             only calculates the optimal size of the WORK array, returns
36648             this value as the first entry of the WORK array, and no error
36649             message related to LWORK is issued by XERBLA.
36650 
36651     INFO    (output) INTEGER
36652             = 0:  successful exit
36653             < 0:  if INFO = -i, the i-th argument had an illegal value
36654 
36655     =====================================================================
36656 
36657 
36658        Test the input arguments
36659 */
36660 
36661     /* Parameter adjustments */
36662     a_dim1 = *lda;
36663     a_offset = 1 + a_dim1;
36664     a -= a_offset;
36665     --tau;
36666     c_dim1 = *ldc;
36667     c_offset = 1 + c_dim1;
36668     c__ -= c_offset;
36669     --work;
36670 
36671     /* Function Body */
36672     *info = 0;
36673     left = lsame_(side, "L");
36674     upper = lsame_(uplo, "U");
36675     lquery = *lwork == -1;
36676 
36677 /*     NQ is the order of Q and NW is the minimum dimension of WORK */
36678 
36679     if (left) {
36680 	nq = *m;
36681 	nw = *n;
36682     } else {
36683 	nq = *n;
36684 	nw = *m;
36685     }
36686     if (! left && ! lsame_(side, "R")) {
36687 	*info = -1;
36688     } else if (! upper && ! lsame_(uplo, "L")) {
36689 	*info = -2;
36690     } else if (! lsame_(trans, "N") && ! lsame_(trans,
36691 	    "T")) {
36692 	*info = -3;
36693     } else if (*m < 0) {
36694 	*info = -4;
36695     } else if (*n < 0) {
36696 	*info = -5;
36697     } else if (*lda < max(1,nq)) {
36698 	*info = -7;
36699     } else if (*ldc < max(1,*m)) {
36700 	*info = -10;
36701     } else if (*lwork < max(1,nw) && ! lquery) {
36702 	*info = -12;
36703     }
36704 
36705     if (*info == 0) {
36706 	if (upper) {
36707 	    if (left) {
36708 /* Writing concatenation */
36709 		i__1[0] = 1, a__1[0] = side;
36710 		i__1[1] = 1, a__1[1] = trans;
36711 		s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
36712 		i__2 = *m - 1;
36713 		i__3 = *m - 1;
36714 		nb = ilaenv_(&c__1, "DORMQL", ch__1, &i__2, n, &i__3, &c_n1, (
36715 			ftnlen)6, (ftnlen)2);
36716 	    } else {
36717 /* Writing concatenation */
36718 		i__1[0] = 1, a__1[0] = side;
36719 		i__1[1] = 1, a__1[1] = trans;
36720 		s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
36721 		i__2 = *n - 1;
36722 		i__3 = *n - 1;
36723 		nb = ilaenv_(&c__1, "DORMQL", ch__1, m, &i__2, &i__3, &c_n1, (
36724 			ftnlen)6, (ftnlen)2);
36725 	    }
36726 	} else {
36727 	    if (left) {
36728 /* Writing concatenation */
36729 		i__1[0] = 1, a__1[0] = side;
36730 		i__1[1] = 1, a__1[1] = trans;
36731 		s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
36732 		i__2 = *m - 1;
36733 		i__3 = *m - 1;
36734 		nb = ilaenv_(&c__1, "DORMQR", ch__1, &i__2, n, &i__3, &c_n1, (
36735 			ftnlen)6, (ftnlen)2);
36736 	    } else {
36737 /* Writing concatenation */
36738 		i__1[0] = 1, a__1[0] = side;
36739 		i__1[1] = 1, a__1[1] = trans;
36740 		s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
36741 		i__2 = *n - 1;
36742 		i__3 = *n - 1;
36743 		nb = ilaenv_(&c__1, "DORMQR", ch__1, m, &i__2, &i__3, &c_n1, (
36744 			ftnlen)6, (ftnlen)2);
36745 	    }
36746 	}
36747 	lwkopt = max(1,nw) * nb;
36748 	work[1] = (doublereal) lwkopt;
36749     }
36750 
36751     if (*info != 0) {
36752 	i__2 = -(*info);
36753 	xerbla_("DORMTR", &i__2);
36754 	return 0;
36755     } else if (lquery) {
36756 	return 0;
36757     }
36758 
36759 /*     Quick return if possible */
36760 
36761     if (*m == 0 || *n == 0 || nq == 1) {
36762 	work[1] = 1.;
36763 	return 0;
36764     }
36765 
36766     if (left) {
36767 	mi = *m - 1;
36768 	ni = *n;
36769     } else {
36770 	mi = *m;
36771 	ni = *n - 1;
36772     }
36773 
36774     if (upper) {
36775 
36776 /*        Q was determined by a call to DSYTRD with UPLO = 'U' */
36777 
36778 	i__2 = nq - 1;
36779 	dormql_(side, trans, &mi, &ni, &i__2, &a[(a_dim1 << 1) + 1], lda, &
36780 		tau[1], &c__[c_offset], ldc, &work[1], lwork, &iinfo);
36781     } else {
36782 
36783 /*        Q was determined by a call to DSYTRD with UPLO = 'L' */
36784 
36785 	if (left) {
36786 	    i1 = 2;
36787 	    i2 = 1;
36788 	} else {
36789 	    i1 = 1;
36790 	    i2 = 2;
36791 	}
36792 	i__2 = nq - 1;
36793 	dormqr_(side, trans, &mi, &ni, &i__2, &a[a_dim1 + 2], lda, &tau[1], &
36794 		c__[i1 + i2 * c_dim1], ldc, &work[1], lwork, &iinfo);
36795     }
36796     work[1] = (doublereal) lwkopt;
36797     return 0;
36798 
36799 /*     End of DORMTR */
36800 
36801 } /* dormtr_ */
36802 
dpotf2_(char * uplo,integer * n,doublereal * a,integer * lda,integer * info)36803 /* Subroutine */ int dpotf2_(char *uplo, integer *n, doublereal *a, integer *
36804 	lda, integer *info)
36805 {
36806     /* System generated locals */
36807     integer a_dim1, a_offset, i__1, i__2, i__3;
36808     doublereal d__1;
36809 
36810     /* Local variables */
36811     static integer j;
36812     static doublereal ajj;
36813     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
36814 	    integer *);
36815     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
36816 	    integer *);
36817     extern logical lsame_(char *, char *);
36818     extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
36819 	    doublereal *, doublereal *, integer *, doublereal *, integer *,
36820 	    doublereal *, doublereal *, integer *);
36821     static logical upper;
36822     extern logical disnan_(doublereal *);
36823     extern /* Subroutine */ int xerbla_(char *, integer *);
36824 
36825 
36826 /*
36827     -- LAPACK routine (version 3.2) --
36828     -- LAPACK is a software package provided by Univ. of Tennessee,    --
36829     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
36830        November 2006
36831 
36832 
36833     Purpose
36834     =======
36835 
36836     DPOTF2 computes the Cholesky factorization of a real symmetric
36837     positive definite matrix A.
36838 
36839     The factorization has the form
36840        A = U' * U ,  if UPLO = 'U', or
36841        A = L  * L',  if UPLO = 'L',
36842     where U is an upper triangular matrix and L is lower triangular.
36843 
36844     This is the unblocked version of the algorithm, calling Level 2 BLAS.
36845 
36846     Arguments
36847     =========
36848 
36849     UPLO    (input) CHARACTER*1
36850             Specifies whether the upper or lower triangular part of the
36851             symmetric matrix A is stored.
36852             = 'U':  Upper triangular
36853             = 'L':  Lower triangular
36854 
36855     N       (input) INTEGER
36856             The order of the matrix A.  N >= 0.
36857 
36858     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
36859             On entry, the symmetric matrix A.  If UPLO = 'U', the leading
36860             n by n upper triangular part of A contains the upper
36861             triangular part of the matrix A, and the strictly lower
36862             triangular part of A is not referenced.  If UPLO = 'L', the
36863             leading n by n lower triangular part of A contains the lower
36864             triangular part of the matrix A, and the strictly upper
36865             triangular part of A is not referenced.
36866 
36867             On exit, if INFO = 0, the factor U or L from the Cholesky
36868             factorization A = U'*U  or A = L*L'.
36869 
36870     LDA     (input) INTEGER
36871             The leading dimension of the array A.  LDA >= max(1,N).
36872 
36873     INFO    (output) INTEGER
36874             = 0: successful exit
36875             < 0: if INFO = -k, the k-th argument had an illegal value
36876             > 0: if INFO = k, the leading minor of order k is not
36877                  positive definite, and the factorization could not be
36878                  completed.
36879 
36880     =====================================================================
36881 
36882 
36883        Test the input parameters.
36884 */
36885 
36886     /* Parameter adjustments */
36887     a_dim1 = *lda;
36888     a_offset = 1 + a_dim1;
36889     a -= a_offset;
36890 
36891     /* Function Body */
36892     *info = 0;
36893     upper = lsame_(uplo, "U");
36894     if (! upper && ! lsame_(uplo, "L")) {
36895 	*info = -1;
36896     } else if (*n < 0) {
36897 	*info = -2;
36898     } else if (*lda < max(1,*n)) {
36899 	*info = -4;
36900     }
36901     if (*info != 0) {
36902 	i__1 = -(*info);
36903 	xerbla_("DPOTF2", &i__1);
36904 	return 0;
36905     }
36906 
36907 /*     Quick return if possible */
36908 
36909     if (*n == 0) {
36910 	return 0;
36911     }
36912 
36913     if (upper) {
36914 
36915 /*        Compute the Cholesky factorization A = U'*U. */
36916 
36917 	i__1 = *n;
36918 	for (j = 1; j <= i__1; ++j) {
36919 
36920 /*           Compute U(J,J) and test for non-positive-definiteness. */
36921 
36922 	    i__2 = j - 1;
36923 	    ajj = a[j + j * a_dim1] - ddot_(&i__2, &a[j * a_dim1 + 1], &c__1,
36924 		    &a[j * a_dim1 + 1], &c__1);
36925 	    if (ajj <= 0. || disnan_(&ajj)) {
36926 		a[j + j * a_dim1] = ajj;
36927 		goto L30;
36928 	    }
36929 	    ajj = sqrt(ajj);
36930 	    a[j + j * a_dim1] = ajj;
36931 
36932 /*           Compute elements J+1:N of row J. */
36933 
36934 	    if (j < *n) {
36935 		i__2 = j - 1;
36936 		i__3 = *n - j;
36937 		dgemv_("Transpose", &i__2, &i__3, &c_b151, &a[(j + 1) *
36938 			a_dim1 + 1], lda, &a[j * a_dim1 + 1], &c__1, &c_b15, &
36939 			a[j + (j + 1) * a_dim1], lda);
36940 		i__2 = *n - j;
36941 		d__1 = 1. / ajj;
36942 		dscal_(&i__2, &d__1, &a[j + (j + 1) * a_dim1], lda);
36943 	    }
36944 /* L10: */
36945 	}
36946     } else {
36947 
36948 /*        Compute the Cholesky factorization A = L*L'. */
36949 
36950 	i__1 = *n;
36951 	for (j = 1; j <= i__1; ++j) {
36952 
36953 /*           Compute L(J,J) and test for non-positive-definiteness. */
36954 
36955 	    i__2 = j - 1;
36956 	    ajj = a[j + j * a_dim1] - ddot_(&i__2, &a[j + a_dim1], lda, &a[j
36957 		    + a_dim1], lda);
36958 	    if (ajj <= 0. || disnan_(&ajj)) {
36959 		a[j + j * a_dim1] = ajj;
36960 		goto L30;
36961 	    }
36962 	    ajj = sqrt(ajj);
36963 	    a[j + j * a_dim1] = ajj;
36964 
36965 /*           Compute elements J+1:N of column J. */
36966 
36967 	    if (j < *n) {
36968 		i__2 = *n - j;
36969 		i__3 = j - 1;
36970 		dgemv_("No transpose", &i__2, &i__3, &c_b151, &a[j + 1 +
36971 			a_dim1], lda, &a[j + a_dim1], lda, &c_b15, &a[j + 1 +
36972 			j * a_dim1], &c__1);
36973 		i__2 = *n - j;
36974 		d__1 = 1. / ajj;
36975 		dscal_(&i__2, &d__1, &a[j + 1 + j * a_dim1], &c__1);
36976 	    }
36977 /* L20: */
36978 	}
36979     }
36980     goto L40;
36981 
36982 L30:
36983     *info = j;
36984 
36985 L40:
36986     return 0;
36987 
36988 /*     End of DPOTF2 */
36989 
36990 } /* dpotf2_ */
36991 
dpotrf_(char * uplo,integer * n,doublereal * a,integer * lda,integer * info)36992 /* Subroutine */ int dpotrf_(char *uplo, integer *n, doublereal *a, integer *
36993 	lda, integer *info)
36994 {
36995     /* System generated locals */
36996     integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
36997 
36998     /* Local variables */
36999     static integer j, jb, nb;
37000     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
37001 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
37002 	    integer *, doublereal *, doublereal *, integer *);
37003     extern logical lsame_(char *, char *);
37004     extern /* Subroutine */ int dtrsm_(char *, char *, char *, char *,
37005 	    integer *, integer *, doublereal *, doublereal *, integer *,
37006 	    doublereal *, integer *);
37007     static logical upper;
37008     extern /* Subroutine */ int dsyrk_(char *, char *, integer *, integer *,
37009 	    doublereal *, doublereal *, integer *, doublereal *, doublereal *,
37010 	     integer *), dpotf2_(char *, integer *,
37011 	    doublereal *, integer *, integer *), xerbla_(char *,
37012 	    integer *);
37013     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
37014 	    integer *, integer *, ftnlen, ftnlen);
37015 
37016 
37017 /*
37018     -- LAPACK routine (version 3.2) --
37019     -- LAPACK is a software package provided by Univ. of Tennessee,    --
37020     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
37021        November 2006
37022 
37023 
37024     Purpose
37025     =======
37026 
37027     DPOTRF computes the Cholesky factorization of a real symmetric
37028     positive definite matrix A.
37029 
37030     The factorization has the form
37031        A = U**T * U,  if UPLO = 'U', or
37032        A = L  * L**T,  if UPLO = 'L',
37033     where U is an upper triangular matrix and L is lower triangular.
37034 
37035     This is the block version of the algorithm, calling Level 3 BLAS.
37036 
37037     Arguments
37038     =========
37039 
37040     UPLO    (input) CHARACTER*1
37041             = 'U':  Upper triangle of A is stored;
37042             = 'L':  Lower triangle of A is stored.
37043 
37044     N       (input) INTEGER
37045             The order of the matrix A.  N >= 0.
37046 
37047     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
37048             On entry, the symmetric matrix A.  If UPLO = 'U', the leading
37049             N-by-N upper triangular part of A contains the upper
37050             triangular part of the matrix A, and the strictly lower
37051             triangular part of A is not referenced.  If UPLO = 'L', the
37052             leading N-by-N lower triangular part of A contains the lower
37053             triangular part of the matrix A, and the strictly upper
37054             triangular part of A is not referenced.
37055 
37056             On exit, if INFO = 0, the factor U or L from the Cholesky
37057             factorization A = U**T*U or A = L*L**T.
37058 
37059     LDA     (input) INTEGER
37060             The leading dimension of the array A.  LDA >= max(1,N).
37061 
37062     INFO    (output) INTEGER
37063             = 0:  successful exit
37064             < 0:  if INFO = -i, the i-th argument had an illegal value
37065             > 0:  if INFO = i, the leading minor of order i is not
37066                   positive definite, and the factorization could not be
37067                   completed.
37068 
37069     =====================================================================
37070 
37071 
37072        Test the input parameters.
37073 */
37074 
37075     /* Parameter adjustments */
37076     a_dim1 = *lda;
37077     a_offset = 1 + a_dim1;
37078     a -= a_offset;
37079 
37080     /* Function Body */
37081     *info = 0;
37082     upper = lsame_(uplo, "U");
37083     if (! upper && ! lsame_(uplo, "L")) {
37084 	*info = -1;
37085     } else if (*n < 0) {
37086 	*info = -2;
37087     } else if (*lda < max(1,*n)) {
37088 	*info = -4;
37089     }
37090     if (*info != 0) {
37091 	i__1 = -(*info);
37092 	xerbla_("DPOTRF", &i__1);
37093 	return 0;
37094     }
37095 
37096 /*     Quick return if possible */
37097 
37098     if (*n == 0) {
37099 	return 0;
37100     }
37101 
37102 /*     Determine the block size for this environment. */
37103 
37104     nb = ilaenv_(&c__1, "DPOTRF", uplo, n, &c_n1, &c_n1, &c_n1, (ftnlen)6, (
37105 	    ftnlen)1);
37106     if (nb <= 1 || nb >= *n) {
37107 
37108 /*        Use unblocked code. */
37109 
37110 	dpotf2_(uplo, n, &a[a_offset], lda, info);
37111     } else {
37112 
37113 /*        Use blocked code. */
37114 
37115 	if (upper) {
37116 
37117 /*           Compute the Cholesky factorization A = U'*U. */
37118 
37119 	    i__1 = *n;
37120 	    i__2 = nb;
37121 	    for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
37122 
37123 /*
37124                 Update and factorize the current diagonal block and test
37125                 for non-positive-definiteness.
37126 
37127    Computing MIN
37128 */
37129 		i__3 = nb, i__4 = *n - j + 1;
37130 		jb = min(i__3,i__4);
37131 		i__3 = j - 1;
37132 		dsyrk_("Upper", "Transpose", &jb, &i__3, &c_b151, &a[j *
37133 			a_dim1 + 1], lda, &c_b15, &a[j + j * a_dim1], lda);
37134 		dpotf2_("Upper", &jb, &a[j + j * a_dim1], lda, info);
37135 		if (*info != 0) {
37136 		    goto L30;
37137 		}
37138 		if (j + jb <= *n) {
37139 
37140 /*                 Compute the current block row. */
37141 
37142 		    i__3 = *n - j - jb + 1;
37143 		    i__4 = j - 1;
37144 		    dgemm_("Transpose", "No transpose", &jb, &i__3, &i__4, &
37145 			    c_b151, &a[j * a_dim1 + 1], lda, &a[(j + jb) *
37146 			    a_dim1 + 1], lda, &c_b15, &a[j + (j + jb) *
37147 			    a_dim1], lda);
37148 		    i__3 = *n - j - jb + 1;
37149 		    dtrsm_("Left", "Upper", "Transpose", "Non-unit", &jb, &
37150 			    i__3, &c_b15, &a[j + j * a_dim1], lda, &a[j + (j
37151 			    + jb) * a_dim1], lda);
37152 		}
37153 /* L10: */
37154 	    }
37155 
37156 	} else {
37157 
37158 /*           Compute the Cholesky factorization A = L*L'. */
37159 
37160 	    i__2 = *n;
37161 	    i__1 = nb;
37162 	    for (j = 1; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
37163 
37164 /*
37165                 Update and factorize the current diagonal block and test
37166                 for non-positive-definiteness.
37167 
37168    Computing MIN
37169 */
37170 		i__3 = nb, i__4 = *n - j + 1;
37171 		jb = min(i__3,i__4);
37172 		i__3 = j - 1;
37173 		dsyrk_("Lower", "No transpose", &jb, &i__3, &c_b151, &a[j +
37174 			a_dim1], lda, &c_b15, &a[j + j * a_dim1], lda);
37175 		dpotf2_("Lower", &jb, &a[j + j * a_dim1], lda, info);
37176 		if (*info != 0) {
37177 		    goto L30;
37178 		}
37179 		if (j + jb <= *n) {
37180 
37181 /*                 Compute the current block column. */
37182 
37183 		    i__3 = *n - j - jb + 1;
37184 		    i__4 = j - 1;
37185 		    dgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, &
37186 			    c_b151, &a[j + jb + a_dim1], lda, &a[j + a_dim1],
37187 			    lda, &c_b15, &a[j + jb + j * a_dim1], lda);
37188 		    i__3 = *n - j - jb + 1;
37189 		    dtrsm_("Right", "Lower", "Transpose", "Non-unit", &i__3, &
37190 			    jb, &c_b15, &a[j + j * a_dim1], lda, &a[j + jb +
37191 			    j * a_dim1], lda);
37192 		}
37193 /* L20: */
37194 	    }
37195 	}
37196     }
37197     goto L40;
37198 
37199 L30:
37200     *info = *info + j - 1;
37201 
37202 L40:
37203     return 0;
37204 
37205 /*     End of DPOTRF */
37206 
37207 } /* dpotrf_ */
37208 
dpotri_(char * uplo,integer * n,doublereal * a,integer * lda,integer * info)37209 /* Subroutine */ int dpotri_(char *uplo, integer *n, doublereal *a, integer *
37210 	lda, integer *info)
37211 {
37212     /* System generated locals */
37213     integer a_dim1, a_offset, i__1;
37214 
37215     /* Local variables */
37216     extern logical lsame_(char *, char *);
37217     extern /* Subroutine */ int xerbla_(char *, integer *), dlauum_(
37218 	    char *, integer *, doublereal *, integer *, integer *),
37219 	    dtrtri_(char *, char *, integer *, doublereal *, integer *,
37220 	    integer *);
37221 
37222 
37223 /*
37224     -- LAPACK routine (version 3.2) --
37225     -- LAPACK is a software package provided by Univ. of Tennessee,    --
37226     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
37227        November 2006
37228 
37229 
37230     Purpose
37231     =======
37232 
37233     DPOTRI computes the inverse of a real symmetric positive definite
37234     matrix A using the Cholesky factorization A = U**T*U or A = L*L**T
37235     computed by DPOTRF.
37236 
37237     Arguments
37238     =========
37239 
37240     UPLO    (input) CHARACTER*1
37241             = 'U':  Upper triangle of A is stored;
37242             = 'L':  Lower triangle of A is stored.
37243 
37244     N       (input) INTEGER
37245             The order of the matrix A.  N >= 0.
37246 
37247     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
37248             On entry, the triangular factor U or L from the Cholesky
37249             factorization A = U**T*U or A = L*L**T, as computed by
37250             DPOTRF.
37251             On exit, the upper or lower triangle of the (symmetric)
37252             inverse of A, overwriting the input factor U or L.
37253 
37254     LDA     (input) INTEGER
37255             The leading dimension of the array A.  LDA >= max(1,N).
37256 
37257     INFO    (output) INTEGER
37258             = 0:  successful exit
37259             < 0:  if INFO = -i, the i-th argument had an illegal value
37260             > 0:  if INFO = i, the (i,i) element of the factor U or L is
37261                   zero, and the inverse could not be computed.
37262 
37263     =====================================================================
37264 
37265 
37266        Test the input parameters.
37267 */
37268 
37269     /* Parameter adjustments */
37270     a_dim1 = *lda;
37271     a_offset = 1 + a_dim1;
37272     a -= a_offset;
37273 
37274     /* Function Body */
37275     *info = 0;
37276     if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
37277 	*info = -1;
37278     } else if (*n < 0) {
37279 	*info = -2;
37280     } else if (*lda < max(1,*n)) {
37281 	*info = -4;
37282     }
37283     if (*info != 0) {
37284 	i__1 = -(*info);
37285 	xerbla_("DPOTRI", &i__1);
37286 	return 0;
37287     }
37288 
37289 /*     Quick return if possible */
37290 
37291     if (*n == 0) {
37292 	return 0;
37293     }
37294 
37295 /*     Invert the triangular Cholesky factor U or L. */
37296 
37297     dtrtri_(uplo, "Non-unit", n, &a[a_offset], lda, info);
37298     if (*info > 0) {
37299 	return 0;
37300     }
37301 
37302 /*     Form inv(U)*inv(U)' or inv(L)'*inv(L). */
37303 
37304     dlauum_(uplo, n, &a[a_offset], lda, info);
37305 
37306     return 0;
37307 
37308 /*     End of DPOTRI */
37309 
37310 } /* dpotri_ */
37311 
dpotrs_(char * uplo,integer * n,integer * nrhs,doublereal * a,integer * lda,doublereal * b,integer * ldb,integer * info)37312 /* Subroutine */ int dpotrs_(char *uplo, integer *n, integer *nrhs,
37313 	doublereal *a, integer *lda, doublereal *b, integer *ldb, integer *
37314 	info)
37315 {
37316     /* System generated locals */
37317     integer a_dim1, a_offset, b_dim1, b_offset, i__1;
37318 
37319     /* Local variables */
37320     extern logical lsame_(char *, char *);
37321     extern /* Subroutine */ int dtrsm_(char *, char *, char *, char *,
37322 	    integer *, integer *, doublereal *, doublereal *, integer *,
37323 	    doublereal *, integer *);
37324     static logical upper;
37325     extern /* Subroutine */ int xerbla_(char *, integer *);
37326 
37327 
37328 /*
37329     -- LAPACK routine (version 3.2) --
37330     -- LAPACK is a software package provided by Univ. of Tennessee,    --
37331     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
37332        November 2006
37333 
37334 
37335     Purpose
37336     =======
37337 
37338     DPOTRS solves a system of linear equations A*X = B with a symmetric
37339     positive definite matrix A using the Cholesky factorization
37340     A = U**T*U or A = L*L**T computed by DPOTRF.
37341 
37342     Arguments
37343     =========
37344 
37345     UPLO    (input) CHARACTER*1
37346             = 'U':  Upper triangle of A is stored;
37347             = 'L':  Lower triangle of A is stored.
37348 
37349     N       (input) INTEGER
37350             The order of the matrix A.  N >= 0.
37351 
37352     NRHS    (input) INTEGER
37353             The number of right hand sides, i.e., the number of columns
37354             of the matrix B.  NRHS >= 0.
37355 
37356     A       (input) DOUBLE PRECISION array, dimension (LDA,N)
37357             The triangular factor U or L from the Cholesky factorization
37358             A = U**T*U or A = L*L**T, as computed by DPOTRF.
37359 
37360     LDA     (input) INTEGER
37361             The leading dimension of the array A.  LDA >= max(1,N).
37362 
37363     B       (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
37364             On entry, the right hand side matrix B.
37365             On exit, the solution matrix X.
37366 
37367     LDB     (input) INTEGER
37368             The leading dimension of the array B.  LDB >= max(1,N).
37369 
37370     INFO    (output) INTEGER
37371             = 0:  successful exit
37372             < 0:  if INFO = -i, the i-th argument had an illegal value
37373 
37374     =====================================================================
37375 
37376 
37377        Test the input parameters.
37378 */
37379 
37380     /* Parameter adjustments */
37381     a_dim1 = *lda;
37382     a_offset = 1 + a_dim1;
37383     a -= a_offset;
37384     b_dim1 = *ldb;
37385     b_offset = 1 + b_dim1;
37386     b -= b_offset;
37387 
37388     /* Function Body */
37389     *info = 0;
37390     upper = lsame_(uplo, "U");
37391     if (! upper && ! lsame_(uplo, "L")) {
37392 	*info = -1;
37393     } else if (*n < 0) {
37394 	*info = -2;
37395     } else if (*nrhs < 0) {
37396 	*info = -3;
37397     } else if (*lda < max(1,*n)) {
37398 	*info = -5;
37399     } else if (*ldb < max(1,*n)) {
37400 	*info = -7;
37401     }
37402     if (*info != 0) {
37403 	i__1 = -(*info);
37404 	xerbla_("DPOTRS", &i__1);
37405 	return 0;
37406     }
37407 
37408 /*     Quick return if possible */
37409 
37410     if (*n == 0 || *nrhs == 0) {
37411 	return 0;
37412     }
37413 
37414     if (upper) {
37415 
37416 /*
37417           Solve A*X = B where A = U'*U.
37418 
37419           Solve U'*X = B, overwriting B with X.
37420 */
37421 
37422 	dtrsm_("Left", "Upper", "Transpose", "Non-unit", n, nrhs, &c_b15, &a[
37423 		a_offset], lda, &b[b_offset], ldb);
37424 
37425 /*        Solve U*X = B, overwriting B with X. */
37426 
37427 	dtrsm_("Left", "Upper", "No transpose", "Non-unit", n, nrhs, &c_b15, &
37428 		a[a_offset], lda, &b[b_offset], ldb);
37429     } else {
37430 
37431 /*
37432           Solve A*X = B where A = L*L'.
37433 
37434           Solve L*X = B, overwriting B with X.
37435 */
37436 
37437 	dtrsm_("Left", "Lower", "No transpose", "Non-unit", n, nrhs, &c_b15, &
37438 		a[a_offset], lda, &b[b_offset], ldb);
37439 
37440 /*        Solve L'*X = B, overwriting B with X. */
37441 
37442 	dtrsm_("Left", "Lower", "Transpose", "Non-unit", n, nrhs, &c_b15, &a[
37443 		a_offset], lda, &b[b_offset], ldb);
37444     }
37445 
37446     return 0;
37447 
37448 /*     End of DPOTRS */
37449 
37450 } /* dpotrs_ */
37451 
dstedc_(char * compz,integer * n,doublereal * d__,doublereal * e,doublereal * z__,integer * ldz,doublereal * work,integer * lwork,integer * iwork,integer * liwork,integer * info)37452 /* Subroutine */ int dstedc_(char *compz, integer *n, doublereal *d__,
37453 	doublereal *e, doublereal *z__, integer *ldz, doublereal *work,
37454 	integer *lwork, integer *iwork, integer *liwork, integer *info)
37455 {
37456     /* System generated locals */
37457     integer z_dim1, z_offset, i__1, i__2;
37458     doublereal d__1, d__2;
37459 
37460     /* Local variables */
37461     static integer i__, j, k, m;
37462     static doublereal p;
37463     static integer ii, lgn;
37464     static doublereal eps, tiny;
37465     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
37466 	    integer *, doublereal *, doublereal *, integer *, doublereal *,
37467 	    integer *, doublereal *, doublereal *, integer *);
37468     extern logical lsame_(char *, char *);
37469     extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *,
37470 	    doublereal *, integer *);
37471     static integer lwmin;
37472     extern /* Subroutine */ int dlaed0_(integer *, integer *, integer *,
37473 	    doublereal *, doublereal *, doublereal *, integer *, doublereal *,
37474 	     integer *, doublereal *, integer *, integer *);
37475     static integer start;
37476 
37477     extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
37478 	    doublereal *, doublereal *, integer *, integer *, doublereal *,
37479 	    integer *, integer *), dlacpy_(char *, integer *, integer
37480 	    *, doublereal *, integer *, doublereal *, integer *),
37481 	    dlaset_(char *, integer *, integer *, doublereal *, doublereal *,
37482 	    doublereal *, integer *);
37483     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
37484 	    integer *, integer *, ftnlen, ftnlen);
37485     extern /* Subroutine */ int xerbla_(char *, integer *);
37486     static integer finish;
37487     extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
37488     extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *,
37489 	     integer *), dlasrt_(char *, integer *, doublereal *, integer *);
37490     static integer liwmin, icompz;
37491     extern /* Subroutine */ int dsteqr_(char *, integer *, doublereal *,
37492 	    doublereal *, doublereal *, integer *, doublereal *, integer *);
37493     static doublereal orgnrm;
37494     static logical lquery;
37495     static integer smlsiz, storez, strtrw;
37496 
37497 
37498 /*
37499     -- LAPACK driver routine (version 3.2) --
37500     -- LAPACK is a software package provided by Univ. of Tennessee,    --
37501     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
37502        November 2006
37503 
37504 
37505     Purpose
37506     =======
37507 
37508     DSTEDC computes all eigenvalues and, optionally, eigenvectors of a
37509     symmetric tridiagonal matrix using the divide and conquer method.
37510     The eigenvectors of a full or band real symmetric matrix can also be
37511     found if DSYTRD or DSPTRD or DSBTRD has been used to reduce this
37512     matrix to tridiagonal form.
37513 
37514     This code makes very mild assumptions about floating point
37515     arithmetic. It will work on machines with a guard digit in
37516     add/subtract, or on those binary machines without guard digits
37517     which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or Cray-2.
37518     It could conceivably fail on hexadecimal or decimal machines
37519     without guard digits, but we know of none.  See DLAED3 for details.
37520 
37521     Arguments
37522     =========
37523 
37524     COMPZ   (input) CHARACTER*1
37525             = 'N':  Compute eigenvalues only.
37526             = 'I':  Compute eigenvectors of tridiagonal matrix also.
37527             = 'V':  Compute eigenvectors of original dense symmetric
37528                     matrix also.  On entry, Z contains the orthogonal
37529                     matrix used to reduce the original matrix to
37530                     tridiagonal form.
37531 
37532     N       (input) INTEGER
37533             The dimension of the symmetric tridiagonal matrix.  N >= 0.
37534 
37535     D       (input/output) DOUBLE PRECISION array, dimension (N)
37536             On entry, the diagonal elements of the tridiagonal matrix.
37537             On exit, if INFO = 0, the eigenvalues in ascending order.
37538 
37539     E       (input/output) DOUBLE PRECISION array, dimension (N-1)
37540             On entry, the subdiagonal elements of the tridiagonal matrix.
37541             On exit, E has been destroyed.
37542 
37543     Z       (input/output) DOUBLE PRECISION array, dimension (LDZ,N)
37544             On entry, if COMPZ = 'V', then Z contains the orthogonal
37545             matrix used in the reduction to tridiagonal form.
37546             On exit, if INFO = 0, then if COMPZ = 'V', Z contains the
37547             orthonormal eigenvectors of the original symmetric matrix,
37548             and if COMPZ = 'I', Z contains the orthonormal eigenvectors
37549             of the symmetric tridiagonal matrix.
37550             If  COMPZ = 'N', then Z is not referenced.
37551 
37552     LDZ     (input) INTEGER
37553             The leading dimension of the array Z.  LDZ >= 1.
37554             If eigenvectors are desired, then LDZ >= max(1,N).
37555 
37556     WORK    (workspace/output) DOUBLE PRECISION array,
37557                                            dimension (LWORK)
37558             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
37559 
37560     LWORK   (input) INTEGER
37561             The dimension of the array WORK.
37562             If COMPZ = 'N' or N <= 1 then LWORK must be at least 1.
37563             If COMPZ = 'V' and N > 1 then LWORK must be at least
37564                            ( 1 + 3*N + 2*N*lg N + 3*N**2 ),
37565                            where lg( N ) = smallest integer k such
37566                            that 2**k >= N.
37567             If COMPZ = 'I' and N > 1 then LWORK must be at least
37568                            ( 1 + 4*N + N**2 ).
37569             Note that for COMPZ = 'I' or 'V', then if N is less than or
37570             equal to the minimum divide size, usually 25, then LWORK need
37571             only be max(1,2*(N-1)).
37572 
37573             If LWORK = -1, then a workspace query is assumed; the routine
37574             only calculates the optimal size of the WORK array, returns
37575             this value as the first entry of the WORK array, and no error
37576             message related to LWORK is issued by XERBLA.
37577 
37578     IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK))
37579             On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
37580 
37581     LIWORK  (input) INTEGER
37582             The dimension of the array IWORK.
37583             If COMPZ = 'N' or N <= 1 then LIWORK must be at least 1.
37584             If COMPZ = 'V' and N > 1 then LIWORK must be at least
37585                            ( 6 + 6*N + 5*N*lg N ).
37586             If COMPZ = 'I' and N > 1 then LIWORK must be at least
37587                            ( 3 + 5*N ).
37588             Note that for COMPZ = 'I' or 'V', then if N is less than or
37589             equal to the minimum divide size, usually 25, then LIWORK
37590             need only be 1.
37591 
37592             If LIWORK = -1, then a workspace query is assumed; the
37593             routine only calculates the optimal size of the IWORK array,
37594             returns this value as the first entry of the IWORK array, and
37595             no error message related to LIWORK is issued by XERBLA.
37596 
37597     INFO    (output) INTEGER
37598             = 0:  successful exit.
37599             < 0:  if INFO = -i, the i-th argument had an illegal value.
37600             > 0:  The algorithm failed to compute an eigenvalue while
37601                   working on the submatrix lying in rows and columns
37602                   INFO/(N+1) through mod(INFO,N+1).
37603 
37604     Further Details
37605     ===============
37606 
37607     Based on contributions by
37608        Jeff Rutter, Computer Science Division, University of California
37609        at Berkeley, USA
37610     Modified by Francoise Tisseur, University of Tennessee.
37611 
37612     =====================================================================
37613 
37614 
37615        Test the input parameters.
37616 */
37617 
37618     /* Parameter adjustments */
37619     --d__;
37620     --e;
37621     z_dim1 = *ldz;
37622     z_offset = 1 + z_dim1;
37623     z__ -= z_offset;
37624     --work;
37625     --iwork;
37626 
37627     /* Function Body */
37628     *info = 0;
37629     lquery = *lwork == -1 || *liwork == -1;
37630 
37631     if (lsame_(compz, "N")) {
37632 	icompz = 0;
37633     } else if (lsame_(compz, "V")) {
37634 	icompz = 1;
37635     } else if (lsame_(compz, "I")) {
37636 	icompz = 2;
37637     } else {
37638 	icompz = -1;
37639     }
37640     if (icompz < 0) {
37641 	*info = -1;
37642     } else if (*n < 0) {
37643 	*info = -2;
37644     } else if (*ldz < 1 || icompz > 0 && *ldz < max(1,*n)) {
37645 	*info = -6;
37646     }
37647 
37648     if (*info == 0) {
37649 
37650 /*        Compute the workspace requirements */
37651 
37652 	smlsiz = ilaenv_(&c__9, "DSTEDC", " ", &c__0, &c__0, &c__0, &c__0, (
37653 		ftnlen)6, (ftnlen)1);
37654 	if (*n <= 1 || icompz == 0) {
37655 	    liwmin = 1;
37656 	    lwmin = 1;
37657 	} else if (*n <= smlsiz) {
37658 	    liwmin = 1;
37659 	    lwmin = *n - 1 << 1;
37660 	} else {
37661 	    lgn = (integer) (log((doublereal) (*n)) / log(2.));
37662 	    if (pow_ii(&c__2, &lgn) < *n) {
37663 		++lgn;
37664 	    }
37665 	    if (pow_ii(&c__2, &lgn) < *n) {
37666 		++lgn;
37667 	    }
37668 	    if (icompz == 1) {
37669 /* Computing 2nd power */
37670 		i__1 = *n;
37671 		lwmin = *n * 3 + 1 + (*n << 1) * lgn + i__1 * i__1 * 3;
37672 		liwmin = *n * 6 + 6 + *n * 5 * lgn;
37673 	    } else if (icompz == 2) {
37674 /* Computing 2nd power */
37675 		i__1 = *n;
37676 		lwmin = (*n << 2) + 1 + i__1 * i__1;
37677 		liwmin = *n * 5 + 3;
37678 	    }
37679 	}
37680 	work[1] = (doublereal) lwmin;
37681 	iwork[1] = liwmin;
37682 
37683 	if (*lwork < lwmin && ! lquery) {
37684 	    *info = -8;
37685 	} else if (*liwork < liwmin && ! lquery) {
37686 	    *info = -10;
37687 	}
37688     }
37689 
37690     if (*info != 0) {
37691 	i__1 = -(*info);
37692 	xerbla_("DSTEDC", &i__1);
37693 	return 0;
37694     } else if (lquery) {
37695 	return 0;
37696     }
37697 
37698 /*     Quick return if possible */
37699 
37700     if (*n == 0) {
37701 	return 0;
37702     }
37703     if (*n == 1) {
37704 	if (icompz != 0) {
37705 	    z__[z_dim1 + 1] = 1.;
37706 	}
37707 	return 0;
37708     }
37709 
37710 /*
37711        If the following conditional clause is removed, then the routine
37712        will use the Divide and Conquer routine to compute only the
37713        eigenvalues, which requires (3N + 3N**2) real workspace and
37714        (2 + 5N + 2N lg(N)) integer workspace.
37715        Since on many architectures DSTERF is much faster than any other
37716        algorithm for finding eigenvalues only, it is used here
37717        as the default. If the conditional clause is removed, then
37718        information on the size of workspace needs to be changed.
37719 
37720        If COMPZ = 'N', use DSTERF to compute the eigenvalues.
37721 */
37722 
37723     if (icompz == 0) {
37724 	dsterf_(n, &d__[1], &e[1], info);
37725 	goto L50;
37726     }
37727 
37728 /*
37729        If N is smaller than the minimum divide size (SMLSIZ+1), then
37730        solve the problem with another solver.
37731 */
37732 
37733     if (*n <= smlsiz) {
37734 
37735 	dsteqr_(compz, n, &d__[1], &e[1], &z__[z_offset], ldz, &work[1], info);
37736 
37737     } else {
37738 
37739 /*
37740           If COMPZ = 'V', the Z matrix must be stored elsewhere for later
37741           use.
37742 */
37743 
37744 	if (icompz == 1) {
37745 	    storez = *n * *n + 1;
37746 	} else {
37747 	    storez = 1;
37748 	}
37749 
37750 	if (icompz == 2) {
37751 	    dlaset_("Full", n, n, &c_b29, &c_b15, &z__[z_offset], ldz);
37752 	}
37753 
37754 /*        Scale. */
37755 
37756 	orgnrm = dlanst_("M", n, &d__[1], &e[1]);
37757 	if (orgnrm == 0.) {
37758 	    goto L50;
37759 	}
37760 
37761 	eps = EPSILON;
37762 
37763 	start = 1;
37764 
37765 /*        while ( START <= N ) */
37766 
37767 L10:
37768 	if (start <= *n) {
37769 
37770 /*
37771              Let FINISH be the position of the next subdiagonal entry
37772              such that E( FINISH ) <= TINY or FINISH = N if no such
37773              subdiagonal exists.  The matrix identified by the elements
37774              between START and FINISH constitutes an independent
37775              sub-problem.
37776 */
37777 
37778 	    finish = start;
37779 L20:
37780 	    if (finish < *n) {
37781 		tiny = eps * sqrt((d__1 = d__[finish], abs(d__1))) * sqrt((
37782 			d__2 = d__[finish + 1], abs(d__2)));
37783 		if ((d__1 = e[finish], abs(d__1)) > tiny) {
37784 		    ++finish;
37785 		    goto L20;
37786 		}
37787 	    }
37788 
37789 /*           (Sub) Problem determined.  Compute its size and solve it. */
37790 
37791 	    m = finish - start + 1;
37792 	    if (m == 1) {
37793 		start = finish + 1;
37794 		goto L10;
37795 	    }
37796 	    if (m > smlsiz) {
37797 
37798 /*              Scale. */
37799 
37800 		orgnrm = dlanst_("M", &m, &d__[start], &e[start]);
37801 		dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, &m, &c__1, &d__[
37802 			start], &m, info);
37803 		i__1 = m - 1;
37804 		i__2 = m - 1;
37805 		dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, &i__1, &c__1, &e[
37806 			start], &i__2, info);
37807 
37808 		if (icompz == 1) {
37809 		    strtrw = 1;
37810 		} else {
37811 		    strtrw = start;
37812 		}
37813 		dlaed0_(&icompz, n, &m, &d__[start], &e[start], &z__[strtrw +
37814 			start * z_dim1], ldz, &work[1], n, &work[storez], &
37815 			iwork[1], info);
37816 		if (*info != 0) {
37817 		    *info = (*info / (m + 1) + start - 1) * (*n + 1) + *info %
37818 			     (m + 1) + start - 1;
37819 		    goto L50;
37820 		}
37821 
37822 /*              Scale back. */
37823 
37824 		dlascl_("G", &c__0, &c__0, &c_b15, &orgnrm, &m, &c__1, &d__[
37825 			start], &m, info);
37826 
37827 	    } else {
37828 		if (icompz == 1) {
37829 
37830 /*
37831                    Since QR won't update a Z matrix which is larger than
37832                    the length of D, we must solve the sub-problem in a
37833                    workspace and then multiply back into Z.
37834 */
37835 
37836 		    dsteqr_("I", &m, &d__[start], &e[start], &work[1], &m, &
37837 			    work[m * m + 1], info);
37838 		    dlacpy_("A", n, &m, &z__[start * z_dim1 + 1], ldz, &work[
37839 			    storez], n);
37840 		    dgemm_("N", "N", n, &m, &m, &c_b15, &work[storez], n, &
37841 			    work[1], &m, &c_b29, &z__[start * z_dim1 + 1],
37842 			    ldz);
37843 		} else if (icompz == 2) {
37844 		    dsteqr_("I", &m, &d__[start], &e[start], &z__[start +
37845 			    start * z_dim1], ldz, &work[1], info);
37846 		} else {
37847 		    dsterf_(&m, &d__[start], &e[start], info);
37848 		}
37849 		if (*info != 0) {
37850 		    *info = start * (*n + 1) + finish;
37851 		    goto L50;
37852 		}
37853 	    }
37854 
37855 	    start = finish + 1;
37856 	    goto L10;
37857 	}
37858 
37859 /*
37860           endwhile
37861 
37862           If the problem split any number of times, then the eigenvalues
37863           will not be properly ordered.  Here we permute the eigenvalues
37864           (and the associated eigenvectors) into ascending order.
37865 */
37866 
37867 	if (m != *n) {
37868 	    if (icompz == 0) {
37869 
37870 /*              Use Quick Sort */
37871 
37872 		dlasrt_("I", n, &d__[1], info);
37873 
37874 	    } else {
37875 
37876 /*              Use Selection Sort to minimize swaps of eigenvectors */
37877 
37878 		i__1 = *n;
37879 		for (ii = 2; ii <= i__1; ++ii) {
37880 		    i__ = ii - 1;
37881 		    k = i__;
37882 		    p = d__[i__];
37883 		    i__2 = *n;
37884 		    for (j = ii; j <= i__2; ++j) {
37885 			if (d__[j] < p) {
37886 			    k = j;
37887 			    p = d__[j];
37888 			}
37889 /* L30: */
37890 		    }
37891 		    if (k != i__) {
37892 			d__[k] = d__[i__];
37893 			d__[i__] = p;
37894 			dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[k *
37895 				z_dim1 + 1], &c__1);
37896 		    }
37897 /* L40: */
37898 		}
37899 	    }
37900 	}
37901     }
37902 
37903 L50:
37904     work[1] = (doublereal) lwmin;
37905     iwork[1] = liwmin;
37906 
37907     return 0;
37908 
37909 /*     End of DSTEDC */
37910 
37911 } /* dstedc_ */
37912 
dsteqr_(char * compz,integer * n,doublereal * d__,doublereal * e,doublereal * z__,integer * ldz,doublereal * work,integer * info)37913 /* Subroutine */ int dsteqr_(char *compz, integer *n, doublereal *d__,
37914 	doublereal *e, doublereal *z__, integer *ldz, doublereal *work,
37915 	integer *info)
37916 {
37917     /* System generated locals */
37918     integer z_dim1, z_offset, i__1, i__2;
37919     doublereal d__1, d__2;
37920 
37921     /* Local variables */
37922     static doublereal b, c__, f, g;
37923     static integer i__, j, k, l, m;
37924     static doublereal p, r__, s;
37925     static integer l1, ii, mm, lm1, mm1, nm1;
37926     static doublereal rt1, rt2, eps;
37927     static integer lsv;
37928     static doublereal tst, eps2;
37929     static integer lend, jtot;
37930     extern /* Subroutine */ int dlae2_(doublereal *, doublereal *, doublereal
37931 	    *, doublereal *, doublereal *);
37932     extern logical lsame_(char *, char *);
37933     extern /* Subroutine */ int dlasr_(char *, char *, char *, integer *,
37934 	    integer *, doublereal *, doublereal *, doublereal *, integer *);
37935     static doublereal anorm;
37936     extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *,
37937 	    doublereal *, integer *), dlaev2_(doublereal *, doublereal *,
37938 	    doublereal *, doublereal *, doublereal *, doublereal *,
37939 	    doublereal *);
37940     static integer lendm1, lendp1;
37941 
37942     static integer iscale;
37943     extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
37944 	    doublereal *, doublereal *, integer *, integer *, doublereal *,
37945 	    integer *, integer *), dlaset_(char *, integer *, integer
37946 	    *, doublereal *, doublereal *, doublereal *, integer *);
37947     static doublereal safmin;
37948     extern /* Subroutine */ int dlartg_(doublereal *, doublereal *,
37949 	    doublereal *, doublereal *, doublereal *);
37950     static doublereal safmax;
37951     extern /* Subroutine */ int xerbla_(char *, integer *);
37952     extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
37953     extern /* Subroutine */ int dlasrt_(char *, integer *, doublereal *,
37954 	    integer *);
37955     static integer lendsv;
37956     static doublereal ssfmin;
37957     static integer nmaxit, icompz;
37958     static doublereal ssfmax;
37959 
37960 
37961 /*
37962     -- LAPACK routine (version 3.2) --
37963     -- LAPACK is a software package provided by Univ. of Tennessee,    --
37964     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
37965        November 2006
37966 
37967 
37968     Purpose
37969     =======
37970 
37971     DSTEQR computes all eigenvalues and, optionally, eigenvectors of a
37972     symmetric tridiagonal matrix using the implicit QL or QR method.
37973     The eigenvectors of a full or band symmetric matrix can also be found
37974     if DSYTRD or DSPTRD or DSBTRD has been used to reduce this matrix to
37975     tridiagonal form.
37976 
37977     Arguments
37978     =========
37979 
37980     COMPZ   (input) CHARACTER*1
37981             = 'N':  Compute eigenvalues only.
37982             = 'V':  Compute eigenvalues and eigenvectors of the original
37983                     symmetric matrix.  On entry, Z must contain the
37984                     orthogonal matrix used to reduce the original matrix
37985                     to tridiagonal form.
37986             = 'I':  Compute eigenvalues and eigenvectors of the
37987                     tridiagonal matrix.  Z is initialized to the identity
37988                     matrix.
37989 
37990     N       (input) INTEGER
37991             The order of the matrix.  N >= 0.
37992 
37993     D       (input/output) DOUBLE PRECISION array, dimension (N)
37994             On entry, the diagonal elements of the tridiagonal matrix.
37995             On exit, if INFO = 0, the eigenvalues in ascending order.
37996 
37997     E       (input/output) DOUBLE PRECISION array, dimension (N-1)
37998             On entry, the (n-1) subdiagonal elements of the tridiagonal
37999             matrix.
38000             On exit, E has been destroyed.
38001 
38002     Z       (input/output) DOUBLE PRECISION array, dimension (LDZ, N)
38003             On entry, if  COMPZ = 'V', then Z contains the orthogonal
38004             matrix used in the reduction to tridiagonal form.
38005             On exit, if INFO = 0, then if  COMPZ = 'V', Z contains the
38006             orthonormal eigenvectors of the original symmetric matrix,
38007             and if COMPZ = 'I', Z contains the orthonormal eigenvectors
38008             of the symmetric tridiagonal matrix.
38009             If COMPZ = 'N', then Z is not referenced.
38010 
38011     LDZ     (input) INTEGER
38012             The leading dimension of the array Z.  LDZ >= 1, and if
38013             eigenvectors are desired, then  LDZ >= max(1,N).
38014 
38015     WORK    (workspace) DOUBLE PRECISION array, dimension (max(1,2*N-2))
38016             If COMPZ = 'N', then WORK is not referenced.
38017 
38018     INFO    (output) INTEGER
38019             = 0:  successful exit
38020             < 0:  if INFO = -i, the i-th argument had an illegal value
38021             > 0:  the algorithm has failed to find all the eigenvalues in
38022                   a total of 30*N iterations; if INFO = i, then i
38023                   elements of E have not converged to zero; on exit, D
38024                   and E contain the elements of a symmetric tridiagonal
38025                   matrix which is orthogonally similar to the original
38026                   matrix.
38027 
38028     =====================================================================
38029 
38030 
38031        Test the input parameters.
38032 */
38033 
38034     /* Parameter adjustments */
38035     --d__;
38036     --e;
38037     z_dim1 = *ldz;
38038     z_offset = 1 + z_dim1;
38039     z__ -= z_offset;
38040     --work;
38041 
38042     /* Function Body */
38043     *info = 0;
38044 
38045     if (lsame_(compz, "N")) {
38046 	icompz = 0;
38047     } else if (lsame_(compz, "V")) {
38048 	icompz = 1;
38049     } else if (lsame_(compz, "I")) {
38050 	icompz = 2;
38051     } else {
38052 	icompz = -1;
38053     }
38054     if (icompz < 0) {
38055 	*info = -1;
38056     } else if (*n < 0) {
38057 	*info = -2;
38058     } else if (*ldz < 1 || icompz > 0 && *ldz < max(1,*n)) {
38059 	*info = -6;
38060     }
38061     if (*info != 0) {
38062 	i__1 = -(*info);
38063 	xerbla_("DSTEQR", &i__1);
38064 	return 0;
38065     }
38066 
38067 /*     Quick return if possible */
38068 
38069     if (*n == 0) {
38070 	return 0;
38071     }
38072 
38073     if (*n == 1) {
38074 	if (icompz == 2) {
38075 	    z__[z_dim1 + 1] = 1.;
38076 	}
38077 	return 0;
38078     }
38079 
38080 /*     Determine the unit roundoff and over/underflow thresholds. */
38081 
38082     eps = EPSILON;
38083 /* Computing 2nd power */
38084     d__1 = eps;
38085     eps2 = d__1 * d__1;
38086     safmin = SAFEMINIMUM;
38087     safmax = 1. / safmin;
38088     ssfmax = sqrt(safmax) / 3.;
38089     ssfmin = sqrt(safmin) / eps2;
38090 
38091 /*
38092        Compute the eigenvalues and eigenvectors of the tridiagonal
38093        matrix.
38094 */
38095 
38096     if (icompz == 2) {
38097 	dlaset_("Full", n, n, &c_b29, &c_b15, &z__[z_offset], ldz);
38098     }
38099 
38100     nmaxit = *n * 30;
38101     jtot = 0;
38102 
38103 /*
38104        Determine where the matrix splits and choose QL or QR iteration
38105        for each block, according to whether top or bottom diagonal
38106        element is smaller.
38107 */
38108 
38109     l1 = 1;
38110     nm1 = *n - 1;
38111 
38112 L10:
38113     if (l1 > *n) {
38114 	goto L160;
38115     }
38116     if (l1 > 1) {
38117 	e[l1 - 1] = 0.;
38118     }
38119     if (l1 <= nm1) {
38120 	i__1 = nm1;
38121 	for (m = l1; m <= i__1; ++m) {
38122 	    tst = (d__1 = e[m], abs(d__1));
38123 	    if (tst == 0.) {
38124 		goto L30;
38125 	    }
38126 	    if (tst <= sqrt((d__1 = d__[m], abs(d__1))) * sqrt((d__2 = d__[m
38127 		    + 1], abs(d__2))) * eps) {
38128 		e[m] = 0.;
38129 		goto L30;
38130 	    }
38131 /* L20: */
38132 	}
38133     }
38134     m = *n;
38135 
38136 L30:
38137     l = l1;
38138     lsv = l;
38139     lend = m;
38140     lendsv = lend;
38141     l1 = m + 1;
38142     if (lend == l) {
38143 	goto L10;
38144     }
38145 
38146 /*     Scale submatrix in rows and columns L to LEND */
38147 
38148     i__1 = lend - l + 1;
38149     anorm = dlanst_("I", &i__1, &d__[l], &e[l]);
38150     iscale = 0;
38151     if (anorm == 0.) {
38152 	goto L10;
38153     }
38154     if (anorm > ssfmax) {
38155 	iscale = 1;
38156 	i__1 = lend - l + 1;
38157 	dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &d__[l], n,
38158 		info);
38159 	i__1 = lend - l;
38160 	dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &e[l], n,
38161 		info);
38162     } else if (anorm < ssfmin) {
38163 	iscale = 2;
38164 	i__1 = lend - l + 1;
38165 	dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &d__[l], n,
38166 		info);
38167 	i__1 = lend - l;
38168 	dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &e[l], n,
38169 		info);
38170     }
38171 
38172 /*     Choose between QL and QR iteration */
38173 
38174     if ((d__1 = d__[lend], abs(d__1)) < (d__2 = d__[l], abs(d__2))) {
38175 	lend = lsv;
38176 	l = lendsv;
38177     }
38178 
38179     if (lend > l) {
38180 
38181 /*
38182           QL Iteration
38183 
38184           Look for small subdiagonal element.
38185 */
38186 
38187 L40:
38188 	if (l != lend) {
38189 	    lendm1 = lend - 1;
38190 	    i__1 = lendm1;
38191 	    for (m = l; m <= i__1; ++m) {
38192 /* Computing 2nd power */
38193 		d__2 = (d__1 = e[m], abs(d__1));
38194 		tst = d__2 * d__2;
38195 		if (tst <= eps2 * (d__1 = d__[m], abs(d__1)) * (d__2 = d__[m
38196 			+ 1], abs(d__2)) + safmin) {
38197 		    goto L60;
38198 		}
38199 /* L50: */
38200 	    }
38201 	}
38202 
38203 	m = lend;
38204 
38205 L60:
38206 	if (m < lend) {
38207 	    e[m] = 0.;
38208 	}
38209 	p = d__[l];
38210 	if (m == l) {
38211 	    goto L80;
38212 	}
38213 
38214 /*
38215           If remaining matrix is 2-by-2, use DLAE2 or SLAEV2
38216           to compute its eigensystem.
38217 */
38218 
38219 	if (m == l + 1) {
38220 	    if (icompz > 0) {
38221 		dlaev2_(&d__[l], &e[l], &d__[l + 1], &rt1, &rt2, &c__, &s);
38222 		work[l] = c__;
38223 		work[*n - 1 + l] = s;
38224 		dlasr_("R", "V", "B", n, &c__2, &work[l], &work[*n - 1 + l], &
38225 			z__[l * z_dim1 + 1], ldz);
38226 	    } else {
38227 		dlae2_(&d__[l], &e[l], &d__[l + 1], &rt1, &rt2);
38228 	    }
38229 	    d__[l] = rt1;
38230 	    d__[l + 1] = rt2;
38231 	    e[l] = 0.;
38232 	    l += 2;
38233 	    if (l <= lend) {
38234 		goto L40;
38235 	    }
38236 	    goto L140;
38237 	}
38238 
38239 	if (jtot == nmaxit) {
38240 	    goto L140;
38241 	}
38242 	++jtot;
38243 
38244 /*        Form shift. */
38245 
38246 	g = (d__[l + 1] - p) / (e[l] * 2.);
38247 	r__ = dlapy2_(&g, &c_b15);
38248 	g = d__[m] - p + e[l] / (g + d_sign(&r__, &g));
38249 
38250 	s = 1.;
38251 	c__ = 1.;
38252 	p = 0.;
38253 
38254 /*        Inner loop */
38255 
38256 	mm1 = m - 1;
38257 	i__1 = l;
38258 	for (i__ = mm1; i__ >= i__1; --i__) {
38259 	    f = s * e[i__];
38260 	    b = c__ * e[i__];
38261 	    dlartg_(&g, &f, &c__, &s, &r__);
38262 	    if (i__ != m - 1) {
38263 		e[i__ + 1] = r__;
38264 	    }
38265 	    g = d__[i__ + 1] - p;
38266 	    r__ = (d__[i__] - g) * s + c__ * 2. * b;
38267 	    p = s * r__;
38268 	    d__[i__ + 1] = g + p;
38269 	    g = c__ * r__ - b;
38270 
38271 /*           If eigenvectors are desired, then save rotations. */
38272 
38273 	    if (icompz > 0) {
38274 		work[i__] = c__;
38275 		work[*n - 1 + i__] = -s;
38276 	    }
38277 
38278 /* L70: */
38279 	}
38280 
38281 /*        If eigenvectors are desired, then apply saved rotations. */
38282 
38283 	if (icompz > 0) {
38284 	    mm = m - l + 1;
38285 	    dlasr_("R", "V", "B", n, &mm, &work[l], &work[*n - 1 + l], &z__[l
38286 		    * z_dim1 + 1], ldz);
38287 	}
38288 
38289 	d__[l] -= p;
38290 	e[l] = g;
38291 	goto L40;
38292 
38293 /*        Eigenvalue found. */
38294 
38295 L80:
38296 	d__[l] = p;
38297 
38298 	++l;
38299 	if (l <= lend) {
38300 	    goto L40;
38301 	}
38302 	goto L140;
38303 
38304     } else {
38305 
38306 /*
38307           QR Iteration
38308 
38309           Look for small superdiagonal element.
38310 */
38311 
38312 L90:
38313 	if (l != lend) {
38314 	    lendp1 = lend + 1;
38315 	    i__1 = lendp1;
38316 	    for (m = l; m >= i__1; --m) {
38317 /* Computing 2nd power */
38318 		d__2 = (d__1 = e[m - 1], abs(d__1));
38319 		tst = d__2 * d__2;
38320 		if (tst <= eps2 * (d__1 = d__[m], abs(d__1)) * (d__2 = d__[m
38321 			- 1], abs(d__2)) + safmin) {
38322 		    goto L110;
38323 		}
38324 /* L100: */
38325 	    }
38326 	}
38327 
38328 	m = lend;
38329 
38330 L110:
38331 	if (m > lend) {
38332 	    e[m - 1] = 0.;
38333 	}
38334 	p = d__[l];
38335 	if (m == l) {
38336 	    goto L130;
38337 	}
38338 
38339 /*
38340           If remaining matrix is 2-by-2, use DLAE2 or SLAEV2
38341           to compute its eigensystem.
38342 */
38343 
38344 	if (m == l - 1) {
38345 	    if (icompz > 0) {
38346 		dlaev2_(&d__[l - 1], &e[l - 1], &d__[l], &rt1, &rt2, &c__, &s)
38347 			;
38348 		work[m] = c__;
38349 		work[*n - 1 + m] = s;
38350 		dlasr_("R", "V", "F", n, &c__2, &work[m], &work[*n - 1 + m], &
38351 			z__[(l - 1) * z_dim1 + 1], ldz);
38352 	    } else {
38353 		dlae2_(&d__[l - 1], &e[l - 1], &d__[l], &rt1, &rt2);
38354 	    }
38355 	    d__[l - 1] = rt1;
38356 	    d__[l] = rt2;
38357 	    e[l - 1] = 0.;
38358 	    l += -2;
38359 	    if (l >= lend) {
38360 		goto L90;
38361 	    }
38362 	    goto L140;
38363 	}
38364 
38365 	if (jtot == nmaxit) {
38366 	    goto L140;
38367 	}
38368 	++jtot;
38369 
38370 /*        Form shift. */
38371 
38372 	g = (d__[l - 1] - p) / (e[l - 1] * 2.);
38373 	r__ = dlapy2_(&g, &c_b15);
38374 	g = d__[m] - p + e[l - 1] / (g + d_sign(&r__, &g));
38375 
38376 	s = 1.;
38377 	c__ = 1.;
38378 	p = 0.;
38379 
38380 /*        Inner loop */
38381 
38382 	lm1 = l - 1;
38383 	i__1 = lm1;
38384 	for (i__ = m; i__ <= i__1; ++i__) {
38385 	    f = s * e[i__];
38386 	    b = c__ * e[i__];
38387 	    dlartg_(&g, &f, &c__, &s, &r__);
38388 	    if (i__ != m) {
38389 		e[i__ - 1] = r__;
38390 	    }
38391 	    g = d__[i__] - p;
38392 	    r__ = (d__[i__ + 1] - g) * s + c__ * 2. * b;
38393 	    p = s * r__;
38394 	    d__[i__] = g + p;
38395 	    g = c__ * r__ - b;
38396 
38397 /*           If eigenvectors are desired, then save rotations. */
38398 
38399 	    if (icompz > 0) {
38400 		work[i__] = c__;
38401 		work[*n - 1 + i__] = s;
38402 	    }
38403 
38404 /* L120: */
38405 	}
38406 
38407 /*        If eigenvectors are desired, then apply saved rotations. */
38408 
38409 	if (icompz > 0) {
38410 	    mm = l - m + 1;
38411 	    dlasr_("R", "V", "F", n, &mm, &work[m], &work[*n - 1 + m], &z__[m
38412 		    * z_dim1 + 1], ldz);
38413 	}
38414 
38415 	d__[l] -= p;
38416 	e[lm1] = g;
38417 	goto L90;
38418 
38419 /*        Eigenvalue found. */
38420 
38421 L130:
38422 	d__[l] = p;
38423 
38424 	--l;
38425 	if (l >= lend) {
38426 	    goto L90;
38427 	}
38428 	goto L140;
38429 
38430     }
38431 
38432 /*     Undo scaling if necessary */
38433 
38434 L140:
38435     if (iscale == 1) {
38436 	i__1 = lendsv - lsv + 1;
38437 	dlascl_("G", &c__0, &c__0, &ssfmax, &anorm, &i__1, &c__1, &d__[lsv],
38438 		n, info);
38439 	i__1 = lendsv - lsv;
38440 	dlascl_("G", &c__0, &c__0, &ssfmax, &anorm, &i__1, &c__1, &e[lsv], n,
38441 		info);
38442     } else if (iscale == 2) {
38443 	i__1 = lendsv - lsv + 1;
38444 	dlascl_("G", &c__0, &c__0, &ssfmin, &anorm, &i__1, &c__1, &d__[lsv],
38445 		n, info);
38446 	i__1 = lendsv - lsv;
38447 	dlascl_("G", &c__0, &c__0, &ssfmin, &anorm, &i__1, &c__1, &e[lsv], n,
38448 		info);
38449     }
38450 
38451 /*
38452        Check for no convergence to an eigenvalue after a total
38453        of N*MAXIT iterations.
38454 */
38455 
38456     if (jtot < nmaxit) {
38457 	goto L10;
38458     }
38459     i__1 = *n - 1;
38460     for (i__ = 1; i__ <= i__1; ++i__) {
38461 	if (e[i__] != 0.) {
38462 	    ++(*info);
38463 	}
38464 /* L150: */
38465     }
38466     goto L190;
38467 
38468 /*     Order eigenvalues and eigenvectors. */
38469 
38470 L160:
38471     if (icompz == 0) {
38472 
38473 /*        Use Quick Sort */
38474 
38475 	dlasrt_("I", n, &d__[1], info);
38476 
38477     } else {
38478 
38479 /*        Use Selection Sort to minimize swaps of eigenvectors */
38480 
38481 	i__1 = *n;
38482 	for (ii = 2; ii <= i__1; ++ii) {
38483 	    i__ = ii - 1;
38484 	    k = i__;
38485 	    p = d__[i__];
38486 	    i__2 = *n;
38487 	    for (j = ii; j <= i__2; ++j) {
38488 		if (d__[j] < p) {
38489 		    k = j;
38490 		    p = d__[j];
38491 		}
38492 /* L170: */
38493 	    }
38494 	    if (k != i__) {
38495 		d__[k] = d__[i__];
38496 		d__[i__] = p;
38497 		dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[k * z_dim1 + 1],
38498 			 &c__1);
38499 	    }
38500 /* L180: */
38501 	}
38502     }
38503 
38504 L190:
38505     return 0;
38506 
38507 /*     End of DSTEQR */
38508 
38509 } /* dsteqr_ */
38510 
dsterf_(integer * n,doublereal * d__,doublereal * e,integer * info)38511 /* Subroutine */ int dsterf_(integer *n, doublereal *d__, doublereal *e,
38512 	integer *info)
38513 {
38514     /* System generated locals */
38515     integer i__1;
38516     doublereal d__1, d__2, d__3;
38517 
38518     /* Local variables */
38519     static doublereal c__;
38520     static integer i__, l, m;
38521     static doublereal p, r__, s;
38522     static integer l1;
38523     static doublereal bb, rt1, rt2, eps, rte;
38524     static integer lsv;
38525     static doublereal eps2, oldc;
38526     static integer lend, jtot;
38527     extern /* Subroutine */ int dlae2_(doublereal *, doublereal *, doublereal
38528 	    *, doublereal *, doublereal *);
38529     static doublereal gamma, alpha, sigma, anorm;
38530 
38531     static integer iscale;
38532     extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
38533 	    doublereal *, doublereal *, integer *, integer *, doublereal *,
38534 	    integer *, integer *);
38535     static doublereal oldgam, safmin;
38536     extern /* Subroutine */ int xerbla_(char *, integer *);
38537     static doublereal safmax;
38538     extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
38539     extern /* Subroutine */ int dlasrt_(char *, integer *, doublereal *,
38540 	    integer *);
38541     static integer lendsv;
38542     static doublereal ssfmin;
38543     static integer nmaxit;
38544     static doublereal ssfmax;
38545 
38546 
38547 /*
38548     -- LAPACK routine (version 3.2) --
38549     -- LAPACK is a software package provided by Univ. of Tennessee,    --
38550     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
38551        November 2006
38552 
38553 
38554     Purpose
38555     =======
38556 
38557     DSTERF computes all eigenvalues of a symmetric tridiagonal matrix
38558     using the Pal-Walker-Kahan variant of the QL or QR algorithm.
38559 
38560     Arguments
38561     =========
38562 
38563     N       (input) INTEGER
38564             The order of the matrix.  N >= 0.
38565 
38566     D       (input/output) DOUBLE PRECISION array, dimension (N)
38567             On entry, the n diagonal elements of the tridiagonal matrix.
38568             On exit, if INFO = 0, the eigenvalues in ascending order.
38569 
38570     E       (input/output) DOUBLE PRECISION array, dimension (N-1)
38571             On entry, the (n-1) subdiagonal elements of the tridiagonal
38572             matrix.
38573             On exit, E has been destroyed.
38574 
38575     INFO    (output) INTEGER
38576             = 0:  successful exit
38577             < 0:  if INFO = -i, the i-th argument had an illegal value
38578             > 0:  the algorithm failed to find all of the eigenvalues in
38579                   a total of 30*N iterations; if INFO = i, then i
38580                   elements of E have not converged to zero.
38581 
38582     =====================================================================
38583 
38584 
38585        Test the input parameters.
38586 */
38587 
38588     /* Parameter adjustments */
38589     --e;
38590     --d__;
38591 
38592     /* Function Body */
38593     *info = 0;
38594 
38595 /*     Quick return if possible */
38596 
38597     if (*n < 0) {
38598 	*info = -1;
38599 	i__1 = -(*info);
38600 	xerbla_("DSTERF", &i__1);
38601 	return 0;
38602     }
38603     if (*n <= 1) {
38604 	return 0;
38605     }
38606 
38607 /*     Determine the unit roundoff for this environment. */
38608 
38609     eps = EPSILON;
38610 /* Computing 2nd power */
38611     d__1 = eps;
38612     eps2 = d__1 * d__1;
38613     safmin = SAFEMINIMUM;
38614     safmax = 1. / safmin;
38615     ssfmax = sqrt(safmax) / 3.;
38616     ssfmin = sqrt(safmin) / eps2;
38617 
38618 /*     Compute the eigenvalues of the tridiagonal matrix. */
38619 
38620     nmaxit = *n * 30;
38621     sigma = 0.;
38622     jtot = 0;
38623 
38624 /*
38625        Determine where the matrix splits and choose QL or QR iteration
38626        for each block, according to whether top or bottom diagonal
38627        element is smaller.
38628 */
38629 
38630     l1 = 1;
38631 
38632 L10:
38633     if (l1 > *n) {
38634 	goto L170;
38635     }
38636     if (l1 > 1) {
38637 	e[l1 - 1] = 0.;
38638     }
38639     i__1 = *n - 1;
38640     for (m = l1; m <= i__1; ++m) {
38641 	if ((d__3 = e[m], abs(d__3)) <= sqrt((d__1 = d__[m], abs(d__1))) *
38642 		sqrt((d__2 = d__[m + 1], abs(d__2))) * eps) {
38643 	    e[m] = 0.;
38644 	    goto L30;
38645 	}
38646 /* L20: */
38647     }
38648     m = *n;
38649 
38650 L30:
38651     l = l1;
38652     lsv = l;
38653     lend = m;
38654     lendsv = lend;
38655     l1 = m + 1;
38656     if (lend == l) {
38657 	goto L10;
38658     }
38659 
38660 /*     Scale submatrix in rows and columns L to LEND */
38661 
38662     i__1 = lend - l + 1;
38663     anorm = dlanst_("I", &i__1, &d__[l], &e[l]);
38664     iscale = 0;
38665     if (anorm > ssfmax) {
38666 	iscale = 1;
38667 	i__1 = lend - l + 1;
38668 	dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &d__[l], n,
38669 		info);
38670 	i__1 = lend - l;
38671 	dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &e[l], n,
38672 		info);
38673     } else if (anorm < ssfmin) {
38674 	iscale = 2;
38675 	i__1 = lend - l + 1;
38676 	dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &d__[l], n,
38677 		info);
38678 	i__1 = lend - l;
38679 	dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &e[l], n,
38680 		info);
38681     }
38682 
38683     i__1 = lend - 1;
38684     for (i__ = l; i__ <= i__1; ++i__) {
38685 /* Computing 2nd power */
38686 	d__1 = e[i__];
38687 	e[i__] = d__1 * d__1;
38688 /* L40: */
38689     }
38690 
38691 /*     Choose between QL and QR iteration */
38692 
38693     if ((d__1 = d__[lend], abs(d__1)) < (d__2 = d__[l], abs(d__2))) {
38694 	lend = lsv;
38695 	l = lendsv;
38696     }
38697 
38698     if (lend >= l) {
38699 
38700 /*
38701           QL Iteration
38702 
38703           Look for small subdiagonal element.
38704 */
38705 
38706 L50:
38707 	if (l != lend) {
38708 	    i__1 = lend - 1;
38709 	    for (m = l; m <= i__1; ++m) {
38710 		if ((d__2 = e[m], abs(d__2)) <= eps2 * (d__1 = d__[m] * d__[m
38711 			+ 1], abs(d__1))) {
38712 		    goto L70;
38713 		}
38714 /* L60: */
38715 	    }
38716 	}
38717 	m = lend;
38718 
38719 L70:
38720 	if (m < lend) {
38721 	    e[m] = 0.;
38722 	}
38723 	p = d__[l];
38724 	if (m == l) {
38725 	    goto L90;
38726 	}
38727 
38728 /*
38729           If remaining matrix is 2 by 2, use DLAE2 to compute its
38730           eigenvalues.
38731 */
38732 
38733 	if (m == l + 1) {
38734 	    rte = sqrt(e[l]);
38735 	    dlae2_(&d__[l], &rte, &d__[l + 1], &rt1, &rt2);
38736 	    d__[l] = rt1;
38737 	    d__[l + 1] = rt2;
38738 	    e[l] = 0.;
38739 	    l += 2;
38740 	    if (l <= lend) {
38741 		goto L50;
38742 	    }
38743 	    goto L150;
38744 	}
38745 
38746 	if (jtot == nmaxit) {
38747 	    goto L150;
38748 	}
38749 	++jtot;
38750 
38751 /*        Form shift. */
38752 
38753 	rte = sqrt(e[l]);
38754 	sigma = (d__[l + 1] - p) / (rte * 2.);
38755 	r__ = dlapy2_(&sigma, &c_b15);
38756 	sigma = p - rte / (sigma + d_sign(&r__, &sigma));
38757 
38758 	c__ = 1.;
38759 	s = 0.;
38760 	gamma = d__[m] - sigma;
38761 	p = gamma * gamma;
38762 
38763 /*        Inner loop */
38764 
38765 	i__1 = l;
38766 	for (i__ = m - 1; i__ >= i__1; --i__) {
38767 	    bb = e[i__];
38768 	    r__ = p + bb;
38769 	    if (i__ != m - 1) {
38770 		e[i__ + 1] = s * r__;
38771 	    }
38772 	    oldc = c__;
38773 	    c__ = p / r__;
38774 	    s = bb / r__;
38775 	    oldgam = gamma;
38776 	    alpha = d__[i__];
38777 	    gamma = c__ * (alpha - sigma) - s * oldgam;
38778 	    d__[i__ + 1] = oldgam + (alpha - gamma);
38779 	    if (c__ != 0.) {
38780 		p = gamma * gamma / c__;
38781 	    } else {
38782 		p = oldc * bb;
38783 	    }
38784 /* L80: */
38785 	}
38786 
38787 	e[l] = s * p;
38788 	d__[l] = sigma + gamma;
38789 	goto L50;
38790 
38791 /*        Eigenvalue found. */
38792 
38793 L90:
38794 	d__[l] = p;
38795 
38796 	++l;
38797 	if (l <= lend) {
38798 	    goto L50;
38799 	}
38800 	goto L150;
38801 
38802     } else {
38803 
38804 /*
38805           QR Iteration
38806 
38807           Look for small superdiagonal element.
38808 */
38809 
38810 L100:
38811 	i__1 = lend + 1;
38812 	for (m = l; m >= i__1; --m) {
38813 	    if ((d__2 = e[m - 1], abs(d__2)) <= eps2 * (d__1 = d__[m] * d__[m
38814 		    - 1], abs(d__1))) {
38815 		goto L120;
38816 	    }
38817 /* L110: */
38818 	}
38819 	m = lend;
38820 
38821 L120:
38822 	if (m > lend) {
38823 	    e[m - 1] = 0.;
38824 	}
38825 	p = d__[l];
38826 	if (m == l) {
38827 	    goto L140;
38828 	}
38829 
38830 /*
38831           If remaining matrix is 2 by 2, use DLAE2 to compute its
38832           eigenvalues.
38833 */
38834 
38835 	if (m == l - 1) {
38836 	    rte = sqrt(e[l - 1]);
38837 	    dlae2_(&d__[l], &rte, &d__[l - 1], &rt1, &rt2);
38838 	    d__[l] = rt1;
38839 	    d__[l - 1] = rt2;
38840 	    e[l - 1] = 0.;
38841 	    l += -2;
38842 	    if (l >= lend) {
38843 		goto L100;
38844 	    }
38845 	    goto L150;
38846 	}
38847 
38848 	if (jtot == nmaxit) {
38849 	    goto L150;
38850 	}
38851 	++jtot;
38852 
38853 /*        Form shift. */
38854 
38855 	rte = sqrt(e[l - 1]);
38856 	sigma = (d__[l - 1] - p) / (rte * 2.);
38857 	r__ = dlapy2_(&sigma, &c_b15);
38858 	sigma = p - rte / (sigma + d_sign(&r__, &sigma));
38859 
38860 	c__ = 1.;
38861 	s = 0.;
38862 	gamma = d__[m] - sigma;
38863 	p = gamma * gamma;
38864 
38865 /*        Inner loop */
38866 
38867 	i__1 = l - 1;
38868 	for (i__ = m; i__ <= i__1; ++i__) {
38869 	    bb = e[i__];
38870 	    r__ = p + bb;
38871 	    if (i__ != m) {
38872 		e[i__ - 1] = s * r__;
38873 	    }
38874 	    oldc = c__;
38875 	    c__ = p / r__;
38876 	    s = bb / r__;
38877 	    oldgam = gamma;
38878 	    alpha = d__[i__ + 1];
38879 	    gamma = c__ * (alpha - sigma) - s * oldgam;
38880 	    d__[i__] = oldgam + (alpha - gamma);
38881 	    if (c__ != 0.) {
38882 		p = gamma * gamma / c__;
38883 	    } else {
38884 		p = oldc * bb;
38885 	    }
38886 /* L130: */
38887 	}
38888 
38889 	e[l - 1] = s * p;
38890 	d__[l] = sigma + gamma;
38891 	goto L100;
38892 
38893 /*        Eigenvalue found. */
38894 
38895 L140:
38896 	d__[l] = p;
38897 
38898 	--l;
38899 	if (l >= lend) {
38900 	    goto L100;
38901 	}
38902 	goto L150;
38903 
38904     }
38905 
38906 /*     Undo scaling if necessary */
38907 
38908 L150:
38909     if (iscale == 1) {
38910 	i__1 = lendsv - lsv + 1;
38911 	dlascl_("G", &c__0, &c__0, &ssfmax, &anorm, &i__1, &c__1, &d__[lsv],
38912 		n, info);
38913     }
38914     if (iscale == 2) {
38915 	i__1 = lendsv - lsv + 1;
38916 	dlascl_("G", &c__0, &c__0, &ssfmin, &anorm, &i__1, &c__1, &d__[lsv],
38917 		n, info);
38918     }
38919 
38920 /*
38921        Check for no convergence to an eigenvalue after a total
38922        of N*MAXIT iterations.
38923 */
38924 
38925     if (jtot < nmaxit) {
38926 	goto L10;
38927     }
38928     i__1 = *n - 1;
38929     for (i__ = 1; i__ <= i__1; ++i__) {
38930 	if (e[i__] != 0.) {
38931 	    ++(*info);
38932 	}
38933 /* L160: */
38934     }
38935     goto L180;
38936 
38937 /*     Sort eigenvalues in increasing order. */
38938 
38939 L170:
38940     dlasrt_("I", n, &d__[1], info);
38941 
38942 L180:
38943     return 0;
38944 
38945 /*     End of DSTERF */
38946 
38947 } /* dsterf_ */
38948 
dsyevd_(char * jobz,char * uplo,integer * n,doublereal * a,integer * lda,doublereal * w,doublereal * work,integer * lwork,integer * iwork,integer * liwork,integer * info)38949 /* Subroutine */ int dsyevd_(char *jobz, char *uplo, integer *n, doublereal *
38950 	a, integer *lda, doublereal *w, doublereal *work, integer *lwork,
38951 	integer *iwork, integer *liwork, integer *info)
38952 {
38953     /* System generated locals */
38954     integer a_dim1, a_offset, i__1, i__2, i__3;
38955     doublereal d__1;
38956 
38957     /* Local variables */
38958     static doublereal eps;
38959     static integer inde;
38960     static doublereal anrm, rmin, rmax;
38961     static integer lopt;
38962     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
38963 	    integer *);
38964     static doublereal sigma;
38965     extern logical lsame_(char *, char *);
38966     static integer iinfo, lwmin, liopt;
38967     static logical lower, wantz;
38968     static integer indwk2, llwrk2;
38969 
38970     static integer iscale;
38971     extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
38972 	    doublereal *, doublereal *, integer *, integer *, doublereal *,
38973 	    integer *, integer *), dstedc_(char *, integer *,
38974 	    doublereal *, doublereal *, doublereal *, integer *, doublereal *,
38975 	     integer *, integer *, integer *, integer *), dlacpy_(
38976 	    char *, integer *, integer *, doublereal *, integer *, doublereal
38977 	    *, integer *);
38978     static doublereal safmin;
38979     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
38980 	    integer *, integer *, ftnlen, ftnlen);
38981     extern /* Subroutine */ int xerbla_(char *, integer *);
38982     static doublereal bignum;
38983     static integer indtau;
38984     extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *,
38985 	     integer *);
38986     extern doublereal dlansy_(char *, char *, integer *, doublereal *,
38987 	    integer *, doublereal *);
38988     static integer indwrk, liwmin;
38989     extern /* Subroutine */ int dormtr_(char *, char *, char *, integer *,
38990 	    integer *, doublereal *, integer *, doublereal *, doublereal *,
38991 	    integer *, doublereal *, integer *, integer *), dsytrd_(char *, integer *, doublereal *, integer *,
38992 	    doublereal *, doublereal *, doublereal *, doublereal *, integer *,
38993 	     integer *);
38994     static integer llwork;
38995     static doublereal smlnum;
38996     static logical lquery;
38997 
38998 
38999 /*
39000     -- LAPACK driver routine (version 3.2) --
39001     -- LAPACK is a software package provided by Univ. of Tennessee,    --
39002     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
39003        November 2006
39004 
39005 
39006     Purpose
39007     =======
39008 
39009     DSYEVD computes all eigenvalues and, optionally, eigenvectors of a
39010     real symmetric matrix A. If eigenvectors are desired, it uses a
39011     divide and conquer algorithm.
39012 
39013     The divide and conquer algorithm makes very mild assumptions about
39014     floating point arithmetic. It will work on machines with a guard
39015     digit in add/subtract, or on those binary machines without guard
39016     digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or
39017     Cray-2. It could conceivably fail on hexadecimal or decimal machines
39018     without guard digits, but we know of none.
39019 
39020     Because of large use of BLAS of level 3, DSYEVD needs N**2 more
39021     workspace than DSYEVX.
39022 
39023     Arguments
39024     =========
39025 
39026     JOBZ    (input) CHARACTER*1
39027             = 'N':  Compute eigenvalues only;
39028             = 'V':  Compute eigenvalues and eigenvectors.
39029 
39030     UPLO    (input) CHARACTER*1
39031             = 'U':  Upper triangle of A is stored;
39032             = 'L':  Lower triangle of A is stored.
39033 
39034     N       (input) INTEGER
39035             The order of the matrix A.  N >= 0.
39036 
39037     A       (input/output) DOUBLE PRECISION array, dimension (LDA, N)
39038             On entry, the symmetric matrix A.  If UPLO = 'U', the
39039             leading N-by-N upper triangular part of A contains the
39040             upper triangular part of the matrix A.  If UPLO = 'L',
39041             the leading N-by-N lower triangular part of A contains
39042             the lower triangular part of the matrix A.
39043             On exit, if JOBZ = 'V', then if INFO = 0, A contains the
39044             orthonormal eigenvectors of the matrix A.
39045             If JOBZ = 'N', then on exit the lower triangle (if UPLO='L')
39046             or the upper triangle (if UPLO='U') of A, including the
39047             diagonal, is destroyed.
39048 
39049     LDA     (input) INTEGER
39050             The leading dimension of the array A.  LDA >= max(1,N).
39051 
39052     W       (output) DOUBLE PRECISION array, dimension (N)
39053             If INFO = 0, the eigenvalues in ascending order.
39054 
39055     WORK    (workspace/output) DOUBLE PRECISION array,
39056                                            dimension (LWORK)
39057             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
39058 
39059     LWORK   (input) INTEGER
39060             The dimension of the array WORK.
39061             If N <= 1,               LWORK must be at least 1.
39062             If JOBZ = 'N' and N > 1, LWORK must be at least 2*N+1.
39063             If JOBZ = 'V' and N > 1, LWORK must be at least
39064                                                   1 + 6*N + 2*N**2.
39065 
39066             If LWORK = -1, then a workspace query is assumed; the routine
39067             only calculates the optimal sizes of the WORK and IWORK
39068             arrays, returns these values as the first entries of the WORK
39069             and IWORK arrays, and no error message related to LWORK or
39070             LIWORK is issued by XERBLA.
39071 
39072     IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK))
39073             On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
39074 
39075     LIWORK  (input) INTEGER
39076             The dimension of the array IWORK.
39077             If N <= 1,                LIWORK must be at least 1.
39078             If JOBZ  = 'N' and N > 1, LIWORK must be at least 1.
39079             If JOBZ  = 'V' and N > 1, LIWORK must be at least 3 + 5*N.
39080 
39081             If LIWORK = -1, then a workspace query is assumed; the
39082             routine only calculates the optimal sizes of the WORK and
39083             IWORK arrays, returns these values as the first entries of
39084             the WORK and IWORK arrays, and no error message related to
39085             LWORK or LIWORK is issued by XERBLA.
39086 
39087     INFO    (output) INTEGER
39088             = 0:  successful exit
39089             < 0:  if INFO = -i, the i-th argument had an illegal value
39090             > 0:  if INFO = i and JOBZ = 'N', then the algorithm failed
39091                   to converge; i off-diagonal elements of an intermediate
39092                   tridiagonal form did not converge to zero;
39093                   if INFO = i and JOBZ = 'V', then the algorithm failed
39094                   to compute an eigenvalue while working on the submatrix
39095                   lying in rows and columns INFO/(N+1) through
39096                   mod(INFO,N+1).
39097 
39098     Further Details
39099     ===============
39100 
39101     Based on contributions by
39102        Jeff Rutter, Computer Science Division, University of California
39103        at Berkeley, USA
39104     Modified by Francoise Tisseur, University of Tennessee.
39105 
39106     Modified description of INFO. Sven, 16 Feb 05.
39107     =====================================================================
39108 
39109 
39110        Test the input parameters.
39111 */
39112 
39113     /* Parameter adjustments */
39114     a_dim1 = *lda;
39115     a_offset = 1 + a_dim1;
39116     a -= a_offset;
39117     --w;
39118     --work;
39119     --iwork;
39120 
39121     /* Function Body */
39122     wantz = lsame_(jobz, "V");
39123     lower = lsame_(uplo, "L");
39124     lquery = *lwork == -1 || *liwork == -1;
39125 
39126     *info = 0;
39127     if (! (wantz || lsame_(jobz, "N"))) {
39128 	*info = -1;
39129     } else if (! (lower || lsame_(uplo, "U"))) {
39130 	*info = -2;
39131     } else if (*n < 0) {
39132 	*info = -3;
39133     } else if (*lda < max(1,*n)) {
39134 	*info = -5;
39135     }
39136 
39137     if (*info == 0) {
39138 	if (*n <= 1) {
39139 	    liwmin = 1;
39140 	    lwmin = 1;
39141 	    lopt = lwmin;
39142 	    liopt = liwmin;
39143 	} else {
39144 	    if (wantz) {
39145 		liwmin = *n * 5 + 3;
39146 /* Computing 2nd power */
39147 		i__1 = *n;
39148 		lwmin = *n * 6 + 1 + (i__1 * i__1 << 1);
39149 	    } else {
39150 		liwmin = 1;
39151 		lwmin = (*n << 1) + 1;
39152 	    }
39153 /* Computing MAX */
39154 	    i__1 = lwmin, i__2 = (*n << 1) + ilaenv_(&c__1, "DSYTRD", uplo, n,
39155 		     &c_n1, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
39156 	    lopt = max(i__1,i__2);
39157 	    liopt = liwmin;
39158 	}
39159 	work[1] = (doublereal) lopt;
39160 	iwork[1] = liopt;
39161 
39162 	if (*lwork < lwmin && ! lquery) {
39163 	    *info = -8;
39164 	} else if (*liwork < liwmin && ! lquery) {
39165 	    *info = -10;
39166 	}
39167     }
39168 
39169     if (*info != 0) {
39170 	i__1 = -(*info);
39171 	xerbla_("DSYEVD", &i__1);
39172 	return 0;
39173     } else if (lquery) {
39174 	return 0;
39175     }
39176 
39177 /*     Quick return if possible */
39178 
39179     if (*n == 0) {
39180 	return 0;
39181     }
39182 
39183     if (*n == 1) {
39184 	w[1] = a[a_dim1 + 1];
39185 	if (wantz) {
39186 	    a[a_dim1 + 1] = 1.;
39187 	}
39188 	return 0;
39189     }
39190 
39191 /*     Get machine constants. */
39192 
39193     safmin = SAFEMINIMUM;
39194     eps = PRECISION;
39195     smlnum = safmin / eps;
39196     bignum = 1. / smlnum;
39197     rmin = sqrt(smlnum);
39198     rmax = sqrt(bignum);
39199 
39200 /*     Scale matrix to allowable range, if necessary. */
39201 
39202     anrm = dlansy_("M", uplo, n, &a[a_offset], lda, &work[1]);
39203     iscale = 0;
39204     if (anrm > 0. && anrm < rmin) {
39205 	iscale = 1;
39206 	sigma = rmin / anrm;
39207     } else if (anrm > rmax) {
39208 	iscale = 1;
39209 	sigma = rmax / anrm;
39210     }
39211     if (iscale == 1) {
39212 	dlascl_(uplo, &c__0, &c__0, &c_b15, &sigma, n, n, &a[a_offset], lda,
39213 		info);
39214     }
39215 
39216 /*     Call DSYTRD to reduce symmetric matrix to tridiagonal form. */
39217 
39218     inde = 1;
39219     indtau = inde + *n;
39220     indwrk = indtau + *n;
39221     llwork = *lwork - indwrk + 1;
39222     indwk2 = indwrk + *n * *n;
39223     llwrk2 = *lwork - indwk2 + 1;
39224 
39225     dsytrd_(uplo, n, &a[a_offset], lda, &w[1], &work[inde], &work[indtau], &
39226 	    work[indwrk], &llwork, &iinfo);
39227     lopt = (integer) ((*n << 1) + work[indwrk]);
39228 
39229 /*
39230        For eigenvalues only, call DSTERF.  For eigenvectors, first call
39231        DSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the
39232        tridiagonal matrix, then call DORMTR to multiply it by the
39233        Householder transformations stored in A.
39234 */
39235 
39236     if (! wantz) {
39237 	dsterf_(n, &w[1], &work[inde], info);
39238     } else {
39239 	dstedc_("I", n, &w[1], &work[inde], &work[indwrk], n, &work[indwk2], &
39240 		llwrk2, &iwork[1], liwork, info);
39241 	dormtr_("L", uplo, "N", n, n, &a[a_offset], lda, &work[indtau], &work[
39242 		indwrk], n, &work[indwk2], &llwrk2, &iinfo);
39243 	dlacpy_("A", n, n, &work[indwrk], n, &a[a_offset], lda);
39244 /*
39245    Computing MAX
39246    Computing 2nd power
39247 */
39248 	i__3 = *n;
39249 	i__1 = lopt, i__2 = *n * 6 + 1 + (i__3 * i__3 << 1);
39250 	lopt = max(i__1,i__2);
39251     }
39252 
39253 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
39254 
39255     if (iscale == 1) {
39256 	d__1 = 1. / sigma;
39257 	dscal_(n, &d__1, &w[1], &c__1);
39258     }
39259 
39260     work[1] = (doublereal) lopt;
39261     iwork[1] = liopt;
39262 
39263     return 0;
39264 
39265 /*     End of DSYEVD */
39266 
39267 } /* dsyevd_ */
39268 
dsytd2_(char * uplo,integer * n,doublereal * a,integer * lda,doublereal * d__,doublereal * e,doublereal * tau,integer * info)39269 /* Subroutine */ int dsytd2_(char *uplo, integer *n, doublereal *a, integer *
39270 	lda, doublereal *d__, doublereal *e, doublereal *tau, integer *info)
39271 {
39272     /* System generated locals */
39273     integer a_dim1, a_offset, i__1, i__2, i__3;
39274 
39275     /* Local variables */
39276     static integer i__;
39277     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
39278 	    integer *);
39279     static doublereal taui;
39280     extern /* Subroutine */ int dsyr2_(char *, integer *, doublereal *,
39281 	    doublereal *, integer *, doublereal *, integer *, doublereal *,
39282 	    integer *);
39283     static doublereal alpha;
39284     extern logical lsame_(char *, char *);
39285     extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *,
39286 	    integer *, doublereal *, integer *);
39287     static logical upper;
39288     extern /* Subroutine */ int dsymv_(char *, integer *, doublereal *,
39289 	    doublereal *, integer *, doublereal *, integer *, doublereal *,
39290 	    doublereal *, integer *), dlarfg_(integer *, doublereal *,
39291 	     doublereal *, integer *, doublereal *), xerbla_(char *, integer *
39292 	    );
39293 
39294 
39295 /*
39296     -- LAPACK routine (version 3.2) --
39297     -- LAPACK is a software package provided by Univ. of Tennessee,    --
39298     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
39299        November 2006
39300 
39301 
39302     Purpose
39303     =======
39304 
39305     DSYTD2 reduces a real symmetric matrix A to symmetric tridiagonal
39306     form T by an orthogonal similarity transformation: Q' * A * Q = T.
39307 
39308     Arguments
39309     =========
39310 
39311     UPLO    (input) CHARACTER*1
39312             Specifies whether the upper or lower triangular part of the
39313             symmetric matrix A is stored:
39314             = 'U':  Upper triangular
39315             = 'L':  Lower triangular
39316 
39317     N       (input) INTEGER
39318             The order of the matrix A.  N >= 0.
39319 
39320     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
39321             On entry, the symmetric matrix A.  If UPLO = 'U', the leading
39322             n-by-n upper triangular part of A contains the upper
39323             triangular part of the matrix A, and the strictly lower
39324             triangular part of A is not referenced.  If UPLO = 'L', the
39325             leading n-by-n lower triangular part of A contains the lower
39326             triangular part of the matrix A, and the strictly upper
39327             triangular part of A is not referenced.
39328             On exit, if UPLO = 'U', the diagonal and first superdiagonal
39329             of A are overwritten by the corresponding elements of the
39330             tridiagonal matrix T, and the elements above the first
39331             superdiagonal, with the array TAU, represent the orthogonal
39332             matrix Q as a product of elementary reflectors; if UPLO
39333             = 'L', the diagonal and first subdiagonal of A are over-
39334             written by the corresponding elements of the tridiagonal
39335             matrix T, and the elements below the first subdiagonal, with
39336             the array TAU, represent the orthogonal matrix Q as a product
39337             of elementary reflectors. See Further Details.
39338 
39339     LDA     (input) INTEGER
39340             The leading dimension of the array A.  LDA >= max(1,N).
39341 
39342     D       (output) DOUBLE PRECISION array, dimension (N)
39343             The diagonal elements of the tridiagonal matrix T:
39344             D(i) = A(i,i).
39345 
39346     E       (output) DOUBLE PRECISION array, dimension (N-1)
39347             The off-diagonal elements of the tridiagonal matrix T:
39348             E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'.
39349 
39350     TAU     (output) DOUBLE PRECISION array, dimension (N-1)
39351             The scalar factors of the elementary reflectors (see Further
39352             Details).
39353 
39354     INFO    (output) INTEGER
39355             = 0:  successful exit
39356             < 0:  if INFO = -i, the i-th argument had an illegal value.
39357 
39358     Further Details
39359     ===============
39360 
39361     If UPLO = 'U', the matrix Q is represented as a product of elementary
39362     reflectors
39363 
39364        Q = H(n-1) . . . H(2) H(1).
39365 
39366     Each H(i) has the form
39367 
39368        H(i) = I - tau * v * v'
39369 
39370     where tau is a real scalar, and v is a real vector with
39371     v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in
39372     A(1:i-1,i+1), and tau in TAU(i).
39373 
39374     If UPLO = 'L', the matrix Q is represented as a product of elementary
39375     reflectors
39376 
39377        Q = H(1) H(2) . . . H(n-1).
39378 
39379     Each H(i) has the form
39380 
39381        H(i) = I - tau * v * v'
39382 
39383     where tau is a real scalar, and v is a real vector with
39384     v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in A(i+2:n,i),
39385     and tau in TAU(i).
39386 
39387     The contents of A on exit are illustrated by the following examples
39388     with n = 5:
39389 
39390     if UPLO = 'U':                       if UPLO = 'L':
39391 
39392       (  d   e   v2  v3  v4 )              (  d                  )
39393       (      d   e   v3  v4 )              (  e   d              )
39394       (          d   e   v4 )              (  v1  e   d          )
39395       (              d   e  )              (  v1  v2  e   d      )
39396       (                  d  )              (  v1  v2  v3  e   d  )
39397 
39398     where d and e denote diagonal and off-diagonal elements of T, and vi
39399     denotes an element of the vector defining H(i).
39400 
39401     =====================================================================
39402 
39403 
39404        Test the input parameters
39405 */
39406 
39407     /* Parameter adjustments */
39408     a_dim1 = *lda;
39409     a_offset = 1 + a_dim1;
39410     a -= a_offset;
39411     --d__;
39412     --e;
39413     --tau;
39414 
39415     /* Function Body */
39416     *info = 0;
39417     upper = lsame_(uplo, "U");
39418     if (! upper && ! lsame_(uplo, "L")) {
39419 	*info = -1;
39420     } else if (*n < 0) {
39421 	*info = -2;
39422     } else if (*lda < max(1,*n)) {
39423 	*info = -4;
39424     }
39425     if (*info != 0) {
39426 	i__1 = -(*info);
39427 	xerbla_("DSYTD2", &i__1);
39428 	return 0;
39429     }
39430 
39431 /*     Quick return if possible */
39432 
39433     if (*n <= 0) {
39434 	return 0;
39435     }
39436 
39437     if (upper) {
39438 
39439 /*        Reduce the upper triangle of A */
39440 
39441 	for (i__ = *n - 1; i__ >= 1; --i__) {
39442 
39443 /*
39444              Generate elementary reflector H(i) = I - tau * v * v'
39445              to annihilate A(1:i-1,i+1)
39446 */
39447 
39448 	    dlarfg_(&i__, &a[i__ + (i__ + 1) * a_dim1], &a[(i__ + 1) * a_dim1
39449 		    + 1], &c__1, &taui);
39450 	    e[i__] = a[i__ + (i__ + 1) * a_dim1];
39451 
39452 	    if (taui != 0.) {
39453 
39454 /*              Apply H(i) from both sides to A(1:i,1:i) */
39455 
39456 		a[i__ + (i__ + 1) * a_dim1] = 1.;
39457 
39458 /*              Compute  x := tau * A * v  storing x in TAU(1:i) */
39459 
39460 		dsymv_(uplo, &i__, &taui, &a[a_offset], lda, &a[(i__ + 1) *
39461 			a_dim1 + 1], &c__1, &c_b29, &tau[1], &c__1)
39462 			;
39463 
39464 /*              Compute  w := x - 1/2 * tau * (x'*v) * v */
39465 
39466 		alpha = taui * -.5 * ddot_(&i__, &tau[1], &c__1, &a[(i__ + 1)
39467 			* a_dim1 + 1], &c__1);
39468 		daxpy_(&i__, &alpha, &a[(i__ + 1) * a_dim1 + 1], &c__1, &tau[
39469 			1], &c__1);
39470 
39471 /*
39472                 Apply the transformation as a rank-2 update:
39473                    A := A - v * w' - w * v'
39474 */
39475 
39476 		dsyr2_(uplo, &i__, &c_b151, &a[(i__ + 1) * a_dim1 + 1], &c__1,
39477 			 &tau[1], &c__1, &a[a_offset], lda);
39478 
39479 		a[i__ + (i__ + 1) * a_dim1] = e[i__];
39480 	    }
39481 	    d__[i__ + 1] = a[i__ + 1 + (i__ + 1) * a_dim1];
39482 	    tau[i__] = taui;
39483 /* L10: */
39484 	}
39485 	d__[1] = a[a_dim1 + 1];
39486     } else {
39487 
39488 /*        Reduce the lower triangle of A */
39489 
39490 	i__1 = *n - 1;
39491 	for (i__ = 1; i__ <= i__1; ++i__) {
39492 
39493 /*
39494              Generate elementary reflector H(i) = I - tau * v * v'
39495              to annihilate A(i+2:n,i)
39496 */
39497 
39498 	    i__2 = *n - i__;
39499 /* Computing MIN */
39500 	    i__3 = i__ + 2;
39501 	    dlarfg_(&i__2, &a[i__ + 1 + i__ * a_dim1], &a[min(i__3,*n) + i__ *
39502 		     a_dim1], &c__1, &taui);
39503 	    e[i__] = a[i__ + 1 + i__ * a_dim1];
39504 
39505 	    if (taui != 0.) {
39506 
39507 /*              Apply H(i) from both sides to A(i+1:n,i+1:n) */
39508 
39509 		a[i__ + 1 + i__ * a_dim1] = 1.;
39510 
39511 /*              Compute  x := tau * A * v  storing y in TAU(i:n-1) */
39512 
39513 		i__2 = *n - i__;
39514 		dsymv_(uplo, &i__2, &taui, &a[i__ + 1 + (i__ + 1) * a_dim1],
39515 			lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &c_b29, &tau[
39516 			i__], &c__1);
39517 
39518 /*              Compute  w := x - 1/2 * tau * (x'*v) * v */
39519 
39520 		i__2 = *n - i__;
39521 		alpha = taui * -.5 * ddot_(&i__2, &tau[i__], &c__1, &a[i__ +
39522 			1 + i__ * a_dim1], &c__1);
39523 		i__2 = *n - i__;
39524 		daxpy_(&i__2, &alpha, &a[i__ + 1 + i__ * a_dim1], &c__1, &tau[
39525 			i__], &c__1);
39526 
39527 /*
39528                 Apply the transformation as a rank-2 update:
39529                    A := A - v * w' - w * v'
39530 */
39531 
39532 		i__2 = *n - i__;
39533 		dsyr2_(uplo, &i__2, &c_b151, &a[i__ + 1 + i__ * a_dim1], &
39534 			c__1, &tau[i__], &c__1, &a[i__ + 1 + (i__ + 1) *
39535 			a_dim1], lda);
39536 
39537 		a[i__ + 1 + i__ * a_dim1] = e[i__];
39538 	    }
39539 	    d__[i__] = a[i__ + i__ * a_dim1];
39540 	    tau[i__] = taui;
39541 /* L20: */
39542 	}
39543 	d__[*n] = a[*n + *n * a_dim1];
39544     }
39545 
39546     return 0;
39547 
39548 /*     End of DSYTD2 */
39549 
39550 } /* dsytd2_ */
39551 
dsytrd_(char * uplo,integer * n,doublereal * a,integer * lda,doublereal * d__,doublereal * e,doublereal * tau,doublereal * work,integer * lwork,integer * info)39552 /* Subroutine */ int dsytrd_(char *uplo, integer *n, doublereal *a, integer *
39553 	lda, doublereal *d__, doublereal *e, doublereal *tau, doublereal *
39554 	work, integer *lwork, integer *info)
39555 {
39556     /* System generated locals */
39557     integer a_dim1, a_offset, i__1, i__2, i__3;
39558 
39559     /* Local variables */
39560     static integer i__, j, nb, kk, nx, iws;
39561     extern logical lsame_(char *, char *);
39562     static integer nbmin, iinfo;
39563     static logical upper;
39564     extern /* Subroutine */ int dsytd2_(char *, integer *, doublereal *,
39565 	    integer *, doublereal *, doublereal *, doublereal *, integer *), dsyr2k_(char *, char *, integer *, integer *, doublereal
39566 	    *, doublereal *, integer *, doublereal *, integer *, doublereal *,
39567 	     doublereal *, integer *), dlatrd_(char *,
39568 	    integer *, integer *, doublereal *, integer *, doublereal *,
39569 	    doublereal *, doublereal *, integer *), xerbla_(char *,
39570 	    integer *);
39571     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
39572 	    integer *, integer *, ftnlen, ftnlen);
39573     static integer ldwork, lwkopt;
39574     static logical lquery;
39575 
39576 
39577 /*
39578     -- LAPACK routine (version 3.2) --
39579     -- LAPACK is a software package provided by Univ. of Tennessee,    --
39580     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
39581        November 2006
39582 
39583 
39584     Purpose
39585     =======
39586 
39587     DSYTRD reduces a real symmetric matrix A to real symmetric
39588     tridiagonal form T by an orthogonal similarity transformation:
39589     Q**T * A * Q = T.
39590 
39591     Arguments
39592     =========
39593 
39594     UPLO    (input) CHARACTER*1
39595             = 'U':  Upper triangle of A is stored;
39596             = 'L':  Lower triangle of A is stored.
39597 
39598     N       (input) INTEGER
39599             The order of the matrix A.  N >= 0.
39600 
39601     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
39602             On entry, the symmetric matrix A.  If UPLO = 'U', the leading
39603             N-by-N upper triangular part of A contains the upper
39604             triangular part of the matrix A, and the strictly lower
39605             triangular part of A is not referenced.  If UPLO = 'L', the
39606             leading N-by-N lower triangular part of A contains the lower
39607             triangular part of the matrix A, and the strictly upper
39608             triangular part of A is not referenced.
39609             On exit, if UPLO = 'U', the diagonal and first superdiagonal
39610             of A are overwritten by the corresponding elements of the
39611             tridiagonal matrix T, and the elements above the first
39612             superdiagonal, with the array TAU, represent the orthogonal
39613             matrix Q as a product of elementary reflectors; if UPLO
39614             = 'L', the diagonal and first subdiagonal of A are over-
39615             written by the corresponding elements of the tridiagonal
39616             matrix T, and the elements below the first subdiagonal, with
39617             the array TAU, represent the orthogonal matrix Q as a product
39618             of elementary reflectors. See Further Details.
39619 
39620     LDA     (input) INTEGER
39621             The leading dimension of the array A.  LDA >= max(1,N).
39622 
39623     D       (output) DOUBLE PRECISION array, dimension (N)
39624             The diagonal elements of the tridiagonal matrix T:
39625             D(i) = A(i,i).
39626 
39627     E       (output) DOUBLE PRECISION array, dimension (N-1)
39628             The off-diagonal elements of the tridiagonal matrix T:
39629             E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'.
39630 
39631     TAU     (output) DOUBLE PRECISION array, dimension (N-1)
39632             The scalar factors of the elementary reflectors (see Further
39633             Details).
39634 
39635     WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
39636             On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
39637 
39638     LWORK   (input) INTEGER
39639             The dimension of the array WORK.  LWORK >= 1.
39640             For optimum performance LWORK >= N*NB, where NB is the
39641             optimal blocksize.
39642 
39643             If LWORK = -1, then a workspace query is assumed; the routine
39644             only calculates the optimal size of the WORK array, returns
39645             this value as the first entry of the WORK array, and no error
39646             message related to LWORK is issued by XERBLA.
39647 
39648     INFO    (output) INTEGER
39649             = 0:  successful exit
39650             < 0:  if INFO = -i, the i-th argument had an illegal value
39651 
39652     Further Details
39653     ===============
39654 
39655     If UPLO = 'U', the matrix Q is represented as a product of elementary
39656     reflectors
39657 
39658        Q = H(n-1) . . . H(2) H(1).
39659 
39660     Each H(i) has the form
39661 
39662        H(i) = I - tau * v * v'
39663 
39664     where tau is a real scalar, and v is a real vector with
39665     v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in
39666     A(1:i-1,i+1), and tau in TAU(i).
39667 
39668     If UPLO = 'L', the matrix Q is represented as a product of elementary
39669     reflectors
39670 
39671        Q = H(1) H(2) . . . H(n-1).
39672 
39673     Each H(i) has the form
39674 
39675        H(i) = I - tau * v * v'
39676 
39677     where tau is a real scalar, and v is a real vector with
39678     v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in A(i+2:n,i),
39679     and tau in TAU(i).
39680 
39681     The contents of A on exit are illustrated by the following examples
39682     with n = 5:
39683 
39684     if UPLO = 'U':                       if UPLO = 'L':
39685 
39686       (  d   e   v2  v3  v4 )              (  d                  )
39687       (      d   e   v3  v4 )              (  e   d              )
39688       (          d   e   v4 )              (  v1  e   d          )
39689       (              d   e  )              (  v1  v2  e   d      )
39690       (                  d  )              (  v1  v2  v3  e   d  )
39691 
39692     where d and e denote diagonal and off-diagonal elements of T, and vi
39693     denotes an element of the vector defining H(i).
39694 
39695     =====================================================================
39696 
39697 
39698        Test the input parameters
39699 */
39700 
39701     /* Parameter adjustments */
39702     a_dim1 = *lda;
39703     a_offset = 1 + a_dim1;
39704     a -= a_offset;
39705     --d__;
39706     --e;
39707     --tau;
39708     --work;
39709 
39710     /* Function Body */
39711     *info = 0;
39712     upper = lsame_(uplo, "U");
39713     lquery = *lwork == -1;
39714     if (! upper && ! lsame_(uplo, "L")) {
39715 	*info = -1;
39716     } else if (*n < 0) {
39717 	*info = -2;
39718     } else if (*lda < max(1,*n)) {
39719 	*info = -4;
39720     } else if (*lwork < 1 && ! lquery) {
39721 	*info = -9;
39722     }
39723 
39724     if (*info == 0) {
39725 
39726 /*        Determine the block size. */
39727 
39728 	nb = ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1, (ftnlen)6,
39729 		 (ftnlen)1);
39730 	lwkopt = *n * nb;
39731 	work[1] = (doublereal) lwkopt;
39732     }
39733 
39734     if (*info != 0) {
39735 	i__1 = -(*info);
39736 	xerbla_("DSYTRD", &i__1);
39737 	return 0;
39738     } else if (lquery) {
39739 	return 0;
39740     }
39741 
39742 /*     Quick return if possible */
39743 
39744     if (*n == 0) {
39745 	work[1] = 1.;
39746 	return 0;
39747     }
39748 
39749     nx = *n;
39750     iws = 1;
39751     if (nb > 1 && nb < *n) {
39752 
39753 /*
39754           Determine when to cross over from blocked to unblocked code
39755           (last block is always handled by unblocked code).
39756 
39757    Computing MAX
39758 */
39759 	i__1 = nb, i__2 = ilaenv_(&c__3, "DSYTRD", uplo, n, &c_n1, &c_n1, &
39760 		c_n1, (ftnlen)6, (ftnlen)1);
39761 	nx = max(i__1,i__2);
39762 	if (nx < *n) {
39763 
39764 /*           Determine if workspace is large enough for blocked code. */
39765 
39766 	    ldwork = *n;
39767 	    iws = ldwork * nb;
39768 	    if (*lwork < iws) {
39769 
39770 /*
39771                 Not enough workspace to use optimal NB:  determine the
39772                 minimum value of NB, and reduce NB or force use of
39773                 unblocked code by setting NX = N.
39774 
39775    Computing MAX
39776 */
39777 		i__1 = *lwork / ldwork;
39778 		nb = max(i__1,1);
39779 		nbmin = ilaenv_(&c__2, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1,
39780 			 (ftnlen)6, (ftnlen)1);
39781 		if (nb < nbmin) {
39782 		    nx = *n;
39783 		}
39784 	    }
39785 	} else {
39786 	    nx = *n;
39787 	}
39788     } else {
39789 	nb = 1;
39790     }
39791 
39792     if (upper) {
39793 
39794 /*
39795           Reduce the upper triangle of A.
39796           Columns 1:kk are handled by the unblocked method.
39797 */
39798 
39799 	kk = *n - (*n - nx + nb - 1) / nb * nb;
39800 	i__1 = kk + 1;
39801 	i__2 = -nb;
39802 	for (i__ = *n - nb + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ +=
39803 		i__2) {
39804 
39805 /*
39806              Reduce columns i:i+nb-1 to tridiagonal form and form the
39807              matrix W which is needed to update the unreduced part of
39808              the matrix
39809 */
39810 
39811 	    i__3 = i__ + nb - 1;
39812 	    dlatrd_(uplo, &i__3, &nb, &a[a_offset], lda, &e[1], &tau[1], &
39813 		    work[1], &ldwork);
39814 
39815 /*
39816              Update the unreduced submatrix A(1:i-1,1:i-1), using an
39817              update of the form:  A := A - V*W' - W*V'
39818 */
39819 
39820 	    i__3 = i__ - 1;
39821 	    dsyr2k_(uplo, "No transpose", &i__3, &nb, &c_b151, &a[i__ *
39822 		    a_dim1 + 1], lda, &work[1], &ldwork, &c_b15, &a[a_offset],
39823 		     lda);
39824 
39825 /*
39826              Copy superdiagonal elements back into A, and diagonal
39827              elements into D
39828 */
39829 
39830 	    i__3 = i__ + nb - 1;
39831 	    for (j = i__; j <= i__3; ++j) {
39832 		a[j - 1 + j * a_dim1] = e[j - 1];
39833 		d__[j] = a[j + j * a_dim1];
39834 /* L10: */
39835 	    }
39836 /* L20: */
39837 	}
39838 
39839 /*        Use unblocked code to reduce the last or only block */
39840 
39841 	dsytd2_(uplo, &kk, &a[a_offset], lda, &d__[1], &e[1], &tau[1], &iinfo);
39842     } else {
39843 
39844 /*        Reduce the lower triangle of A */
39845 
39846 	i__2 = *n - nx;
39847 	i__1 = nb;
39848 	for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__1) {
39849 
39850 /*
39851              Reduce columns i:i+nb-1 to tridiagonal form and form the
39852              matrix W which is needed to update the unreduced part of
39853              the matrix
39854 */
39855 
39856 	    i__3 = *n - i__ + 1;
39857 	    dlatrd_(uplo, &i__3, &nb, &a[i__ + i__ * a_dim1], lda, &e[i__], &
39858 		    tau[i__], &work[1], &ldwork);
39859 
39860 /*
39861              Update the unreduced submatrix A(i+ib:n,i+ib:n), using
39862              an update of the form:  A := A - V*W' - W*V'
39863 */
39864 
39865 	    i__3 = *n - i__ - nb + 1;
39866 	    dsyr2k_(uplo, "No transpose", &i__3, &nb, &c_b151, &a[i__ + nb +
39867 		    i__ * a_dim1], lda, &work[nb + 1], &ldwork, &c_b15, &a[
39868 		    i__ + nb + (i__ + nb) * a_dim1], lda);
39869 
39870 /*
39871              Copy subdiagonal elements back into A, and diagonal
39872              elements into D
39873 */
39874 
39875 	    i__3 = i__ + nb - 1;
39876 	    for (j = i__; j <= i__3; ++j) {
39877 		a[j + 1 + j * a_dim1] = e[j];
39878 		d__[j] = a[j + j * a_dim1];
39879 /* L30: */
39880 	    }
39881 /* L40: */
39882 	}
39883 
39884 /*        Use unblocked code to reduce the last or only block */
39885 
39886 	i__1 = *n - i__ + 1;
39887 	dsytd2_(uplo, &i__1, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[i__],
39888 		&tau[i__], &iinfo);
39889     }
39890 
39891     work[1] = (doublereal) lwkopt;
39892     return 0;
39893 
39894 /*     End of DSYTRD */
39895 
39896 } /* dsytrd_ */
39897 
dtrevc_(char * side,char * howmny,logical * select,integer * n,doublereal * t,integer * ldt,doublereal * vl,integer * ldvl,doublereal * vr,integer * ldvr,integer * mm,integer * m,doublereal * work,integer * info)39898 /* Subroutine */ int dtrevc_(char *side, char *howmny, logical *select,
39899 	integer *n, doublereal *t, integer *ldt, doublereal *vl, integer *
39900 	ldvl, doublereal *vr, integer *ldvr, integer *mm, integer *m,
39901 	doublereal *work, integer *info)
39902 {
39903     /* System generated locals */
39904     integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
39905 	    i__2, i__3;
39906     doublereal d__1, d__2, d__3, d__4;
39907 
39908     /* Local variables */
39909     static integer i__, j, k;
39910     static doublereal x[4]	/* was [2][2] */;
39911     static integer j1, j2, n2, ii, ki, ip, is;
39912     static doublereal wi, wr, rec, ulp, beta, emax;
39913     static logical pair;
39914     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
39915 	    integer *);
39916     static logical allv;
39917     static integer ierr;
39918     static doublereal unfl, ovfl, smin;
39919     static logical over;
39920     static doublereal vmax;
39921     static integer jnxt;
39922     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
39923 	    integer *);
39924     static doublereal scale;
39925     extern logical lsame_(char *, char *);
39926     extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
39927 	    doublereal *, doublereal *, integer *, doublereal *, integer *,
39928 	    doublereal *, doublereal *, integer *);
39929     static doublereal remax;
39930     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
39931 	    doublereal *, integer *);
39932     static logical leftv, bothv;
39933     extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *,
39934 	    integer *, doublereal *, integer *);
39935     static doublereal vcrit;
39936     static logical somev;
39937     static doublereal xnorm;
39938     extern /* Subroutine */ int dlaln2_(logical *, integer *, integer *,
39939 	    doublereal *, doublereal *, doublereal *, integer *, doublereal *,
39940 	     doublereal *, doublereal *, integer *, doublereal *, doublereal *
39941 	    , doublereal *, integer *, doublereal *, doublereal *, integer *),
39942 	     dlabad_(doublereal *, doublereal *);
39943 
39944     extern integer idamax_(integer *, doublereal *, integer *);
39945     extern /* Subroutine */ int xerbla_(char *, integer *);
39946     static doublereal bignum;
39947     static logical rightv;
39948     static doublereal smlnum;
39949 
39950 
39951 /*
39952     -- LAPACK routine (version 3.2) --
39953     -- LAPACK is a software package provided by Univ. of Tennessee,    --
39954     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
39955        November 2006
39956 
39957 
39958     Purpose
39959     =======
39960 
39961     DTREVC computes some or all of the right and/or left eigenvectors of
39962     a real upper quasi-triangular matrix T.
39963     Matrices of this type are produced by the Schur factorization of
39964     a real general matrix:  A = Q*T*Q**T, as computed by DHSEQR.
39965 
39966     The right eigenvector x and the left eigenvector y of T corresponding
39967     to an eigenvalue w are defined by:
39968 
39969        T*x = w*x,     (y**H)*T = w*(y**H)
39970 
39971     where y**H denotes the conjugate transpose of y.
39972     The eigenvalues are not input to this routine, but are read directly
39973     from the diagonal blocks of T.
39974 
39975     This routine returns the matrices X and/or Y of right and left
39976     eigenvectors of T, or the products Q*X and/or Q*Y, where Q is an
39977     input matrix.  If Q is the orthogonal factor that reduces a matrix
39978     A to Schur form T, then Q*X and Q*Y are the matrices of right and
39979     left eigenvectors of A.
39980 
39981     Arguments
39982     =========
39983 
39984     SIDE    (input) CHARACTER*1
39985             = 'R':  compute right eigenvectors only;
39986             = 'L':  compute left eigenvectors only;
39987             = 'B':  compute both right and left eigenvectors.
39988 
39989     HOWMNY  (input) CHARACTER*1
39990             = 'A':  compute all right and/or left eigenvectors;
39991             = 'B':  compute all right and/or left eigenvectors,
39992                     backtransformed by the matrices in VR and/or VL;
39993             = 'S':  compute selected right and/or left eigenvectors,
39994                     as indicated by the logical array SELECT.
39995 
39996     SELECT  (input/output) LOGICAL array, dimension (N)
39997             If HOWMNY = 'S', SELECT specifies the eigenvectors to be
39998             computed.
39999             If w(j) is a real eigenvalue, the corresponding real
40000             eigenvector is computed if SELECT(j) is .TRUE..
40001             If w(j) and w(j+1) are the real and imaginary parts of a
40002             complex eigenvalue, the corresponding complex eigenvector is
40003             computed if either SELECT(j) or SELECT(j+1) is .TRUE., and
40004             on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is set to
40005             .FALSE..
40006             Not referenced if HOWMNY = 'A' or 'B'.
40007 
40008     N       (input) INTEGER
40009             The order of the matrix T. N >= 0.
40010 
40011     T       (input) DOUBLE PRECISION array, dimension (LDT,N)
40012             The upper quasi-triangular matrix T in Schur canonical form.
40013 
40014     LDT     (input) INTEGER
40015             The leading dimension of the array T. LDT >= max(1,N).
40016 
40017     VL      (input/output) DOUBLE PRECISION array, dimension (LDVL,MM)
40018             On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must
40019             contain an N-by-N matrix Q (usually the orthogonal matrix Q
40020             of Schur vectors returned by DHSEQR).
40021             On exit, if SIDE = 'L' or 'B', VL contains:
40022             if HOWMNY = 'A', the matrix Y of left eigenvectors of T;
40023             if HOWMNY = 'B', the matrix Q*Y;
40024             if HOWMNY = 'S', the left eigenvectors of T specified by
40025                              SELECT, stored consecutively in the columns
40026                              of VL, in the same order as their
40027                              eigenvalues.
40028             A complex eigenvector corresponding to a complex eigenvalue
40029             is stored in two consecutive columns, the first holding the
40030             real part, and the second the imaginary part.
40031             Not referenced if SIDE = 'R'.
40032 
40033     LDVL    (input) INTEGER
40034             The leading dimension of the array VL.  LDVL >= 1, and if
40035             SIDE = 'L' or 'B', LDVL >= N.
40036 
40037     VR      (input/output) DOUBLE PRECISION array, dimension (LDVR,MM)
40038             On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must
40039             contain an N-by-N matrix Q (usually the orthogonal matrix Q
40040             of Schur vectors returned by DHSEQR).
40041             On exit, if SIDE = 'R' or 'B', VR contains:
40042             if HOWMNY = 'A', the matrix X of right eigenvectors of T;
40043             if HOWMNY = 'B', the matrix Q*X;
40044             if HOWMNY = 'S', the right eigenvectors of T specified by
40045                              SELECT, stored consecutively in the columns
40046                              of VR, in the same order as their
40047                              eigenvalues.
40048             A complex eigenvector corresponding to a complex eigenvalue
40049             is stored in two consecutive columns, the first holding the
40050             real part and the second the imaginary part.
40051             Not referenced if SIDE = 'L'.
40052 
40053     LDVR    (input) INTEGER
40054             The leading dimension of the array VR.  LDVR >= 1, and if
40055             SIDE = 'R' or 'B', LDVR >= N.
40056 
40057     MM      (input) INTEGER
40058             The number of columns in the arrays VL and/or VR. MM >= M.
40059 
40060     M       (output) INTEGER
40061             The number of columns in the arrays VL and/or VR actually
40062             used to store the eigenvectors.
40063             If HOWMNY = 'A' or 'B', M is set to N.
40064             Each selected real eigenvector occupies one column and each
40065             selected complex eigenvector occupies two columns.
40066 
40067     WORK    (workspace) DOUBLE PRECISION array, dimension (3*N)
40068 
40069     INFO    (output) INTEGER
40070             = 0:  successful exit
40071             < 0:  if INFO = -i, the i-th argument had an illegal value
40072 
40073     Further Details
40074     ===============
40075 
40076     The algorithm used in this program is basically backward (forward)
40077     substitution, with scaling to make the the code robust against
40078     possible overflow.
40079 
40080     Each eigenvector is normalized so that the element of largest
40081     magnitude has magnitude 1; here the magnitude of a complex number
40082     (x,y) is taken to be |x| + |y|.
40083 
40084     =====================================================================
40085 
40086 
40087        Decode and test the input parameters
40088 */
40089 
40090     /* Parameter adjustments */
40091     --select;
40092     t_dim1 = *ldt;
40093     t_offset = 1 + t_dim1;
40094     t -= t_offset;
40095     vl_dim1 = *ldvl;
40096     vl_offset = 1 + vl_dim1;
40097     vl -= vl_offset;
40098     vr_dim1 = *ldvr;
40099     vr_offset = 1 + vr_dim1;
40100     vr -= vr_offset;
40101     --work;
40102 
40103     /* Function Body */
40104     bothv = lsame_(side, "B");
40105     rightv = lsame_(side, "R") || bothv;
40106     leftv = lsame_(side, "L") || bothv;
40107 
40108     allv = lsame_(howmny, "A");
40109     over = lsame_(howmny, "B");
40110     somev = lsame_(howmny, "S");
40111 
40112     *info = 0;
40113     if (! rightv && ! leftv) {
40114 	*info = -1;
40115     } else if (! allv && ! over && ! somev) {
40116 	*info = -2;
40117     } else if (*n < 0) {
40118 	*info = -4;
40119     } else if (*ldt < max(1,*n)) {
40120 	*info = -6;
40121     } else if (*ldvl < 1 || leftv && *ldvl < *n) {
40122 	*info = -8;
40123     } else if (*ldvr < 1 || rightv && *ldvr < *n) {
40124 	*info = -10;
40125     } else {
40126 
40127 /*
40128           Set M to the number of columns required to store the selected
40129           eigenvectors, standardize the array SELECT if necessary, and
40130           test MM.
40131 */
40132 
40133 	if (somev) {
40134 	    *m = 0;
40135 	    pair = FALSE_;
40136 	    i__1 = *n;
40137 	    for (j = 1; j <= i__1; ++j) {
40138 		if (pair) {
40139 		    pair = FALSE_;
40140 		    select[j] = FALSE_;
40141 		} else {
40142 		    if (j < *n) {
40143 			if (t[j + 1 + j * t_dim1] == 0.) {
40144 			    if (select[j]) {
40145 				++(*m);
40146 			    }
40147 			} else {
40148 			    pair = TRUE_;
40149 			    if (select[j] || select[j + 1]) {
40150 				select[j] = TRUE_;
40151 				*m += 2;
40152 			    }
40153 			}
40154 		    } else {
40155 			if (select[*n]) {
40156 			    ++(*m);
40157 			}
40158 		    }
40159 		}
40160 /* L10: */
40161 	    }
40162 	} else {
40163 	    *m = *n;
40164 	}
40165 
40166 	if (*mm < *m) {
40167 	    *info = -11;
40168 	}
40169     }
40170     if (*info != 0) {
40171 	i__1 = -(*info);
40172 	xerbla_("DTREVC", &i__1);
40173 	return 0;
40174     }
40175 
40176 /*     Quick return if possible. */
40177 
40178     if (*n == 0) {
40179 	return 0;
40180     }
40181 
40182 /*     Set the constants to control overflow. */
40183 
40184     unfl = SAFEMINIMUM;
40185     ovfl = 1. / unfl;
40186     dlabad_(&unfl, &ovfl);
40187     ulp = PRECISION;
40188     smlnum = unfl * (*n / ulp);
40189     bignum = (1. - ulp) / smlnum;
40190 
40191 /*
40192        Compute 1-norm of each column of strictly upper triangular
40193        part of T to control overflow in triangular solver.
40194 */
40195 
40196     work[1] = 0.;
40197     i__1 = *n;
40198     for (j = 2; j <= i__1; ++j) {
40199 	work[j] = 0.;
40200 	i__2 = j - 1;
40201 	for (i__ = 1; i__ <= i__2; ++i__) {
40202 	    work[j] += (d__1 = t[i__ + j * t_dim1], abs(d__1));
40203 /* L20: */
40204 	}
40205 /* L30: */
40206     }
40207 
40208 /*
40209        Index IP is used to specify the real or complex eigenvalue:
40210          IP = 0, real eigenvalue,
40211               1, first of conjugate complex pair: (wr,wi)
40212              -1, second of conjugate complex pair: (wr,wi)
40213 */
40214 
40215     n2 = *n << 1;
40216 
40217     if (rightv) {
40218 
40219 /*        Compute right eigenvectors. */
40220 
40221 	ip = 0;
40222 	is = *m;
40223 	for (ki = *n; ki >= 1; --ki) {
40224 
40225 	    if (ip == 1) {
40226 		goto L130;
40227 	    }
40228 	    if (ki == 1) {
40229 		goto L40;
40230 	    }
40231 	    if (t[ki + (ki - 1) * t_dim1] == 0.) {
40232 		goto L40;
40233 	    }
40234 	    ip = -1;
40235 
40236 L40:
40237 	    if (somev) {
40238 		if (ip == 0) {
40239 		    if (! select[ki]) {
40240 			goto L130;
40241 		    }
40242 		} else {
40243 		    if (! select[ki - 1]) {
40244 			goto L130;
40245 		    }
40246 		}
40247 	    }
40248 
40249 /*           Compute the KI-th eigenvalue (WR,WI). */
40250 
40251 	    wr = t[ki + ki * t_dim1];
40252 	    wi = 0.;
40253 	    if (ip != 0) {
40254 		wi = sqrt((d__1 = t[ki + (ki - 1) * t_dim1], abs(d__1))) *
40255 			sqrt((d__2 = t[ki - 1 + ki * t_dim1], abs(d__2)));
40256 	    }
40257 /* Computing MAX */
40258 	    d__1 = ulp * (abs(wr) + abs(wi));
40259 	    smin = max(d__1,smlnum);
40260 
40261 	    if (ip == 0) {
40262 
40263 /*              Real right eigenvector */
40264 
40265 		work[ki + *n] = 1.;
40266 
40267 /*              Form right-hand side */
40268 
40269 		i__1 = ki - 1;
40270 		for (k = 1; k <= i__1; ++k) {
40271 		    work[k + *n] = -t[k + ki * t_dim1];
40272 /* L50: */
40273 		}
40274 
40275 /*
40276                 Solve the upper quasi-triangular system:
40277                    (T(1:KI-1,1:KI-1) - WR)*X = SCALE*WORK.
40278 */
40279 
40280 		jnxt = ki - 1;
40281 		for (j = ki - 1; j >= 1; --j) {
40282 		    if (j > jnxt) {
40283 			goto L60;
40284 		    }
40285 		    j1 = j;
40286 		    j2 = j;
40287 		    jnxt = j - 1;
40288 		    if (j > 1) {
40289 			if (t[j + (j - 1) * t_dim1] != 0.) {
40290 			    j1 = j - 1;
40291 			    jnxt = j - 2;
40292 			}
40293 		    }
40294 
40295 		    if (j1 == j2) {
40296 
40297 /*                    1-by-1 diagonal block */
40298 
40299 			dlaln2_(&c_false, &c__1, &c__1, &smin, &c_b15, &t[j +
40300 				j * t_dim1], ldt, &c_b15, &c_b15, &work[j + *
40301 				n], n, &wr, &c_b29, x, &c__2, &scale, &xnorm,
40302 				&ierr);
40303 
40304 /*
40305                       Scale X(1,1) to avoid overflow when updating
40306                       the right-hand side.
40307 */
40308 
40309 			if (xnorm > 1.) {
40310 			    if (work[j] > bignum / xnorm) {
40311 				x[0] /= xnorm;
40312 				scale /= xnorm;
40313 			    }
40314 			}
40315 
40316 /*                    Scale if necessary */
40317 
40318 			if (scale != 1.) {
40319 			    dscal_(&ki, &scale, &work[*n + 1], &c__1);
40320 			}
40321 			work[j + *n] = x[0];
40322 
40323 /*                    Update right-hand side */
40324 
40325 			i__1 = j - 1;
40326 			d__1 = -x[0];
40327 			daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
40328 				*n + 1], &c__1);
40329 
40330 		    } else {
40331 
40332 /*                    2-by-2 diagonal block */
40333 
40334 			dlaln2_(&c_false, &c__2, &c__1, &smin, &c_b15, &t[j -
40335 				1 + (j - 1) * t_dim1], ldt, &c_b15, &c_b15, &
40336 				work[j - 1 + *n], n, &wr, &c_b29, x, &c__2, &
40337 				scale, &xnorm, &ierr);
40338 
40339 /*
40340                       Scale X(1,1) and X(2,1) to avoid overflow when
40341                       updating the right-hand side.
40342 */
40343 
40344 			if (xnorm > 1.) {
40345 /* Computing MAX */
40346 			    d__1 = work[j - 1], d__2 = work[j];
40347 			    beta = max(d__1,d__2);
40348 			    if (beta > bignum / xnorm) {
40349 				x[0] /= xnorm;
40350 				x[1] /= xnorm;
40351 				scale /= xnorm;
40352 			    }
40353 			}
40354 
40355 /*                    Scale if necessary */
40356 
40357 			if (scale != 1.) {
40358 			    dscal_(&ki, &scale, &work[*n + 1], &c__1);
40359 			}
40360 			work[j - 1 + *n] = x[0];
40361 			work[j + *n] = x[1];
40362 
40363 /*                    Update right-hand side */
40364 
40365 			i__1 = j - 2;
40366 			d__1 = -x[0];
40367 			daxpy_(&i__1, &d__1, &t[(j - 1) * t_dim1 + 1], &c__1,
40368 				&work[*n + 1], &c__1);
40369 			i__1 = j - 2;
40370 			d__1 = -x[1];
40371 			daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
40372 				*n + 1], &c__1);
40373 		    }
40374 L60:
40375 		    ;
40376 		}
40377 
40378 /*              Copy the vector x or Q*x to VR and normalize. */
40379 
40380 		if (! over) {
40381 		    dcopy_(&ki, &work[*n + 1], &c__1, &vr[is * vr_dim1 + 1], &
40382 			    c__1);
40383 
40384 		    ii = idamax_(&ki, &vr[is * vr_dim1 + 1], &c__1);
40385 		    remax = 1. / (d__1 = vr[ii + is * vr_dim1], abs(d__1));
40386 		    dscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
40387 
40388 		    i__1 = *n;
40389 		    for (k = ki + 1; k <= i__1; ++k) {
40390 			vr[k + is * vr_dim1] = 0.;
40391 /* L70: */
40392 		    }
40393 		} else {
40394 		    if (ki > 1) {
40395 			i__1 = ki - 1;
40396 			dgemv_("N", n, &i__1, &c_b15, &vr[vr_offset], ldvr, &
40397 				work[*n + 1], &c__1, &work[ki + *n], &vr[ki *
40398 				vr_dim1 + 1], &c__1);
40399 		    }
40400 
40401 		    ii = idamax_(n, &vr[ki * vr_dim1 + 1], &c__1);
40402 		    remax = 1. / (d__1 = vr[ii + ki * vr_dim1], abs(d__1));
40403 		    dscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
40404 		}
40405 
40406 	    } else {
40407 
40408 /*
40409                 Complex right eigenvector.
40410 
40411                 Initial solve
40412                   [ (T(KI-1,KI-1) T(KI-1,KI) ) - (WR + I* WI)]*X = 0.
40413                   [ (T(KI,KI-1)   T(KI,KI)   )               ]
40414 */
40415 
40416 		if ((d__1 = t[ki - 1 + ki * t_dim1], abs(d__1)) >= (d__2 = t[
40417 			ki + (ki - 1) * t_dim1], abs(d__2))) {
40418 		    work[ki - 1 + *n] = 1.;
40419 		    work[ki + n2] = wi / t[ki - 1 + ki * t_dim1];
40420 		} else {
40421 		    work[ki - 1 + *n] = -wi / t[ki + (ki - 1) * t_dim1];
40422 		    work[ki + n2] = 1.;
40423 		}
40424 		work[ki + *n] = 0.;
40425 		work[ki - 1 + n2] = 0.;
40426 
40427 /*              Form right-hand side */
40428 
40429 		i__1 = ki - 2;
40430 		for (k = 1; k <= i__1; ++k) {
40431 		    work[k + *n] = -work[ki - 1 + *n] * t[k + (ki - 1) *
40432 			    t_dim1];
40433 		    work[k + n2] = -work[ki + n2] * t[k + ki * t_dim1];
40434 /* L80: */
40435 		}
40436 
40437 /*
40438                 Solve upper quasi-triangular system:
40439                 (T(1:KI-2,1:KI-2) - (WR+i*WI))*X = SCALE*(WORK+i*WORK2)
40440 */
40441 
40442 		jnxt = ki - 2;
40443 		for (j = ki - 2; j >= 1; --j) {
40444 		    if (j > jnxt) {
40445 			goto L90;
40446 		    }
40447 		    j1 = j;
40448 		    j2 = j;
40449 		    jnxt = j - 1;
40450 		    if (j > 1) {
40451 			if (t[j + (j - 1) * t_dim1] != 0.) {
40452 			    j1 = j - 1;
40453 			    jnxt = j - 2;
40454 			}
40455 		    }
40456 
40457 		    if (j1 == j2) {
40458 
40459 /*                    1-by-1 diagonal block */
40460 
40461 			dlaln2_(&c_false, &c__1, &c__2, &smin, &c_b15, &t[j +
40462 				j * t_dim1], ldt, &c_b15, &c_b15, &work[j + *
40463 				n], n, &wr, &wi, x, &c__2, &scale, &xnorm, &
40464 				ierr);
40465 
40466 /*
40467                       Scale X(1,1) and X(1,2) to avoid overflow when
40468                       updating the right-hand side.
40469 */
40470 
40471 			if (xnorm > 1.) {
40472 			    if (work[j] > bignum / xnorm) {
40473 				x[0] /= xnorm;
40474 				x[2] /= xnorm;
40475 				scale /= xnorm;
40476 			    }
40477 			}
40478 
40479 /*                    Scale if necessary */
40480 
40481 			if (scale != 1.) {
40482 			    dscal_(&ki, &scale, &work[*n + 1], &c__1);
40483 			    dscal_(&ki, &scale, &work[n2 + 1], &c__1);
40484 			}
40485 			work[j + *n] = x[0];
40486 			work[j + n2] = x[2];
40487 
40488 /*                    Update the right-hand side */
40489 
40490 			i__1 = j - 1;
40491 			d__1 = -x[0];
40492 			daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
40493 				*n + 1], &c__1);
40494 			i__1 = j - 1;
40495 			d__1 = -x[2];
40496 			daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
40497 				n2 + 1], &c__1);
40498 
40499 		    } else {
40500 
40501 /*                    2-by-2 diagonal block */
40502 
40503 			dlaln2_(&c_false, &c__2, &c__2, &smin, &c_b15, &t[j -
40504 				1 + (j - 1) * t_dim1], ldt, &c_b15, &c_b15, &
40505 				work[j - 1 + *n], n, &wr, &wi, x, &c__2, &
40506 				scale, &xnorm, &ierr);
40507 
40508 /*
40509                       Scale X to avoid overflow when updating
40510                       the right-hand side.
40511 */
40512 
40513 			if (xnorm > 1.) {
40514 /* Computing MAX */
40515 			    d__1 = work[j - 1], d__2 = work[j];
40516 			    beta = max(d__1,d__2);
40517 			    if (beta > bignum / xnorm) {
40518 				rec = 1. / xnorm;
40519 				x[0] *= rec;
40520 				x[2] *= rec;
40521 				x[1] *= rec;
40522 				x[3] *= rec;
40523 				scale *= rec;
40524 			    }
40525 			}
40526 
40527 /*                    Scale if necessary */
40528 
40529 			if (scale != 1.) {
40530 			    dscal_(&ki, &scale, &work[*n + 1], &c__1);
40531 			    dscal_(&ki, &scale, &work[n2 + 1], &c__1);
40532 			}
40533 			work[j - 1 + *n] = x[0];
40534 			work[j + *n] = x[1];
40535 			work[j - 1 + n2] = x[2];
40536 			work[j + n2] = x[3];
40537 
40538 /*                    Update the right-hand side */
40539 
40540 			i__1 = j - 2;
40541 			d__1 = -x[0];
40542 			daxpy_(&i__1, &d__1, &t[(j - 1) * t_dim1 + 1], &c__1,
40543 				&work[*n + 1], &c__1);
40544 			i__1 = j - 2;
40545 			d__1 = -x[1];
40546 			daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
40547 				*n + 1], &c__1);
40548 			i__1 = j - 2;
40549 			d__1 = -x[2];
40550 			daxpy_(&i__1, &d__1, &t[(j - 1) * t_dim1 + 1], &c__1,
40551 				&work[n2 + 1], &c__1);
40552 			i__1 = j - 2;
40553 			d__1 = -x[3];
40554 			daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
40555 				n2 + 1], &c__1);
40556 		    }
40557 L90:
40558 		    ;
40559 		}
40560 
40561 /*              Copy the vector x or Q*x to VR and normalize. */
40562 
40563 		if (! over) {
40564 		    dcopy_(&ki, &work[*n + 1], &c__1, &vr[(is - 1) * vr_dim1
40565 			    + 1], &c__1);
40566 		    dcopy_(&ki, &work[n2 + 1], &c__1, &vr[is * vr_dim1 + 1], &
40567 			    c__1);
40568 
40569 		    emax = 0.;
40570 		    i__1 = ki;
40571 		    for (k = 1; k <= i__1; ++k) {
40572 /* Computing MAX */
40573 			d__3 = emax, d__4 = (d__1 = vr[k + (is - 1) * vr_dim1]
40574 				, abs(d__1)) + (d__2 = vr[k + is * vr_dim1],
40575 				abs(d__2));
40576 			emax = max(d__3,d__4);
40577 /* L100: */
40578 		    }
40579 
40580 		    remax = 1. / emax;
40581 		    dscal_(&ki, &remax, &vr[(is - 1) * vr_dim1 + 1], &c__1);
40582 		    dscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
40583 
40584 		    i__1 = *n;
40585 		    for (k = ki + 1; k <= i__1; ++k) {
40586 			vr[k + (is - 1) * vr_dim1] = 0.;
40587 			vr[k + is * vr_dim1] = 0.;
40588 /* L110: */
40589 		    }
40590 
40591 		} else {
40592 
40593 		    if (ki > 2) {
40594 			i__1 = ki - 2;
40595 			dgemv_("N", n, &i__1, &c_b15, &vr[vr_offset], ldvr, &
40596 				work[*n + 1], &c__1, &work[ki - 1 + *n], &vr[(
40597 				ki - 1) * vr_dim1 + 1], &c__1);
40598 			i__1 = ki - 2;
40599 			dgemv_("N", n, &i__1, &c_b15, &vr[vr_offset], ldvr, &
40600 				work[n2 + 1], &c__1, &work[ki + n2], &vr[ki *
40601 				vr_dim1 + 1], &c__1);
40602 		    } else {
40603 			dscal_(n, &work[ki - 1 + *n], &vr[(ki - 1) * vr_dim1
40604 				+ 1], &c__1);
40605 			dscal_(n, &work[ki + n2], &vr[ki * vr_dim1 + 1], &
40606 				c__1);
40607 		    }
40608 
40609 		    emax = 0.;
40610 		    i__1 = *n;
40611 		    for (k = 1; k <= i__1; ++k) {
40612 /* Computing MAX */
40613 			d__3 = emax, d__4 = (d__1 = vr[k + (ki - 1) * vr_dim1]
40614 				, abs(d__1)) + (d__2 = vr[k + ki * vr_dim1],
40615 				abs(d__2));
40616 			emax = max(d__3,d__4);
40617 /* L120: */
40618 		    }
40619 		    remax = 1. / emax;
40620 		    dscal_(n, &remax, &vr[(ki - 1) * vr_dim1 + 1], &c__1);
40621 		    dscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
40622 		}
40623 	    }
40624 
40625 	    --is;
40626 	    if (ip != 0) {
40627 		--is;
40628 	    }
40629 L130:
40630 	    if (ip == 1) {
40631 		ip = 0;
40632 	    }
40633 	    if (ip == -1) {
40634 		ip = 1;
40635 	    }
40636 /* L140: */
40637 	}
40638     }
40639 
40640     if (leftv) {
40641 
40642 /*        Compute left eigenvectors. */
40643 
40644 	ip = 0;
40645 	is = 1;
40646 	i__1 = *n;
40647 	for (ki = 1; ki <= i__1; ++ki) {
40648 
40649 	    if (ip == -1) {
40650 		goto L250;
40651 	    }
40652 	    if (ki == *n) {
40653 		goto L150;
40654 	    }
40655 	    if (t[ki + 1 + ki * t_dim1] == 0.) {
40656 		goto L150;
40657 	    }
40658 	    ip = 1;
40659 
40660 L150:
40661 	    if (somev) {
40662 		if (! select[ki]) {
40663 		    goto L250;
40664 		}
40665 	    }
40666 
40667 /*           Compute the KI-th eigenvalue (WR,WI). */
40668 
40669 	    wr = t[ki + ki * t_dim1];
40670 	    wi = 0.;
40671 	    if (ip != 0) {
40672 		wi = sqrt((d__1 = t[ki + (ki + 1) * t_dim1], abs(d__1))) *
40673 			sqrt((d__2 = t[ki + 1 + ki * t_dim1], abs(d__2)));
40674 	    }
40675 /* Computing MAX */
40676 	    d__1 = ulp * (abs(wr) + abs(wi));
40677 	    smin = max(d__1,smlnum);
40678 
40679 	    if (ip == 0) {
40680 
40681 /*              Real left eigenvector. */
40682 
40683 		work[ki + *n] = 1.;
40684 
40685 /*              Form right-hand side */
40686 
40687 		i__2 = *n;
40688 		for (k = ki + 1; k <= i__2; ++k) {
40689 		    work[k + *n] = -t[ki + k * t_dim1];
40690 /* L160: */
40691 		}
40692 
40693 /*
40694                 Solve the quasi-triangular system:
40695                    (T(KI+1:N,KI+1:N) - WR)'*X = SCALE*WORK
40696 */
40697 
40698 		vmax = 1.;
40699 		vcrit = bignum;
40700 
40701 		jnxt = ki + 1;
40702 		i__2 = *n;
40703 		for (j = ki + 1; j <= i__2; ++j) {
40704 		    if (j < jnxt) {
40705 			goto L170;
40706 		    }
40707 		    j1 = j;
40708 		    j2 = j;
40709 		    jnxt = j + 1;
40710 		    if (j < *n) {
40711 			if (t[j + 1 + j * t_dim1] != 0.) {
40712 			    j2 = j + 1;
40713 			    jnxt = j + 2;
40714 			}
40715 		    }
40716 
40717 		    if (j1 == j2) {
40718 
40719 /*
40720                       1-by-1 diagonal block
40721 
40722                       Scale if necessary to avoid overflow when forming
40723                       the right-hand side.
40724 */
40725 
40726 			if (work[j] > vcrit) {
40727 			    rec = 1. / vmax;
40728 			    i__3 = *n - ki + 1;
40729 			    dscal_(&i__3, &rec, &work[ki + *n], &c__1);
40730 			    vmax = 1.;
40731 			    vcrit = bignum;
40732 			}
40733 
40734 			i__3 = j - ki - 1;
40735 			work[j + *n] -= ddot_(&i__3, &t[ki + 1 + j * t_dim1],
40736 				&c__1, &work[ki + 1 + *n], &c__1);
40737 
40738 /*                    Solve (T(J,J)-WR)'*X = WORK */
40739 
40740 			dlaln2_(&c_false, &c__1, &c__1, &smin, &c_b15, &t[j +
40741 				j * t_dim1], ldt, &c_b15, &c_b15, &work[j + *
40742 				n], n, &wr, &c_b29, x, &c__2, &scale, &xnorm,
40743 				&ierr);
40744 
40745 /*                    Scale if necessary */
40746 
40747 			if (scale != 1.) {
40748 			    i__3 = *n - ki + 1;
40749 			    dscal_(&i__3, &scale, &work[ki + *n], &c__1);
40750 			}
40751 			work[j + *n] = x[0];
40752 /* Computing MAX */
40753 			d__2 = (d__1 = work[j + *n], abs(d__1));
40754 			vmax = max(d__2,vmax);
40755 			vcrit = bignum / vmax;
40756 
40757 		    } else {
40758 
40759 /*
40760                       2-by-2 diagonal block
40761 
40762                       Scale if necessary to avoid overflow when forming
40763                       the right-hand side.
40764 
40765    Computing MAX
40766 */
40767 			d__1 = work[j], d__2 = work[j + 1];
40768 			beta = max(d__1,d__2);
40769 			if (beta > vcrit) {
40770 			    rec = 1. / vmax;
40771 			    i__3 = *n - ki + 1;
40772 			    dscal_(&i__3, &rec, &work[ki + *n], &c__1);
40773 			    vmax = 1.;
40774 			    vcrit = bignum;
40775 			}
40776 
40777 			i__3 = j - ki - 1;
40778 			work[j + *n] -= ddot_(&i__3, &t[ki + 1 + j * t_dim1],
40779 				&c__1, &work[ki + 1 + *n], &c__1);
40780 
40781 			i__3 = j - ki - 1;
40782 			work[j + 1 + *n] -= ddot_(&i__3, &t[ki + 1 + (j + 1) *
40783 				 t_dim1], &c__1, &work[ki + 1 + *n], &c__1);
40784 
40785 /*
40786                       Solve
40787                         [T(J,J)-WR   T(J,J+1)     ]'* X = SCALE*( WORK1 )
40788                         [T(J+1,J)    T(J+1,J+1)-WR]             ( WORK2 )
40789 */
40790 
40791 			dlaln2_(&c_true, &c__2, &c__1, &smin, &c_b15, &t[j +
40792 				j * t_dim1], ldt, &c_b15, &c_b15, &work[j + *
40793 				n], n, &wr, &c_b29, x, &c__2, &scale, &xnorm,
40794 				&ierr);
40795 
40796 /*                    Scale if necessary */
40797 
40798 			if (scale != 1.) {
40799 			    i__3 = *n - ki + 1;
40800 			    dscal_(&i__3, &scale, &work[ki + *n], &c__1);
40801 			}
40802 			work[j + *n] = x[0];
40803 			work[j + 1 + *n] = x[1];
40804 
40805 /* Computing MAX */
40806 			d__3 = (d__1 = work[j + *n], abs(d__1)), d__4 = (d__2
40807 				= work[j + 1 + *n], abs(d__2)), d__3 = max(
40808 				d__3,d__4);
40809 			vmax = max(d__3,vmax);
40810 			vcrit = bignum / vmax;
40811 
40812 		    }
40813 L170:
40814 		    ;
40815 		}
40816 
40817 /*              Copy the vector x or Q*x to VL and normalize. */
40818 
40819 		if (! over) {
40820 		    i__2 = *n - ki + 1;
40821 		    dcopy_(&i__2, &work[ki + *n], &c__1, &vl[ki + is *
40822 			    vl_dim1], &c__1);
40823 
40824 		    i__2 = *n - ki + 1;
40825 		    ii = idamax_(&i__2, &vl[ki + is * vl_dim1], &c__1) + ki -
40826 			    1;
40827 		    remax = 1. / (d__1 = vl[ii + is * vl_dim1], abs(d__1));
40828 		    i__2 = *n - ki + 1;
40829 		    dscal_(&i__2, &remax, &vl[ki + is * vl_dim1], &c__1);
40830 
40831 		    i__2 = ki - 1;
40832 		    for (k = 1; k <= i__2; ++k) {
40833 			vl[k + is * vl_dim1] = 0.;
40834 /* L180: */
40835 		    }
40836 
40837 		} else {
40838 
40839 		    if (ki < *n) {
40840 			i__2 = *n - ki;
40841 			dgemv_("N", n, &i__2, &c_b15, &vl[(ki + 1) * vl_dim1
40842 				+ 1], ldvl, &work[ki + 1 + *n], &c__1, &work[
40843 				ki + *n], &vl[ki * vl_dim1 + 1], &c__1);
40844 		    }
40845 
40846 		    ii = idamax_(n, &vl[ki * vl_dim1 + 1], &c__1);
40847 		    remax = 1. / (d__1 = vl[ii + ki * vl_dim1], abs(d__1));
40848 		    dscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
40849 
40850 		}
40851 
40852 	    } else {
40853 
40854 /*
40855                 Complex left eigenvector.
40856 
40857                  Initial solve:
40858                    ((T(KI,KI)    T(KI,KI+1) )' - (WR - I* WI))*X = 0.
40859                    ((T(KI+1,KI) T(KI+1,KI+1))                )
40860 */
40861 
40862 		if ((d__1 = t[ki + (ki + 1) * t_dim1], abs(d__1)) >= (d__2 =
40863 			t[ki + 1 + ki * t_dim1], abs(d__2))) {
40864 		    work[ki + *n] = wi / t[ki + (ki + 1) * t_dim1];
40865 		    work[ki + 1 + n2] = 1.;
40866 		} else {
40867 		    work[ki + *n] = 1.;
40868 		    work[ki + 1 + n2] = -wi / t[ki + 1 + ki * t_dim1];
40869 		}
40870 		work[ki + 1 + *n] = 0.;
40871 		work[ki + n2] = 0.;
40872 
40873 /*              Form right-hand side */
40874 
40875 		i__2 = *n;
40876 		for (k = ki + 2; k <= i__2; ++k) {
40877 		    work[k + *n] = -work[ki + *n] * t[ki + k * t_dim1];
40878 		    work[k + n2] = -work[ki + 1 + n2] * t[ki + 1 + k * t_dim1]
40879 			    ;
40880 /* L190: */
40881 		}
40882 
40883 /*
40884                 Solve complex quasi-triangular system:
40885                 ( T(KI+2,N:KI+2,N) - (WR-i*WI) )*X = WORK1+i*WORK2
40886 */
40887 
40888 		vmax = 1.;
40889 		vcrit = bignum;
40890 
40891 		jnxt = ki + 2;
40892 		i__2 = *n;
40893 		for (j = ki + 2; j <= i__2; ++j) {
40894 		    if (j < jnxt) {
40895 			goto L200;
40896 		    }
40897 		    j1 = j;
40898 		    j2 = j;
40899 		    jnxt = j + 1;
40900 		    if (j < *n) {
40901 			if (t[j + 1 + j * t_dim1] != 0.) {
40902 			    j2 = j + 1;
40903 			    jnxt = j + 2;
40904 			}
40905 		    }
40906 
40907 		    if (j1 == j2) {
40908 
40909 /*
40910                       1-by-1 diagonal block
40911 
40912                       Scale if necessary to avoid overflow when
40913                       forming the right-hand side elements.
40914 */
40915 
40916 			if (work[j] > vcrit) {
40917 			    rec = 1. / vmax;
40918 			    i__3 = *n - ki + 1;
40919 			    dscal_(&i__3, &rec, &work[ki + *n], &c__1);
40920 			    i__3 = *n - ki + 1;
40921 			    dscal_(&i__3, &rec, &work[ki + n2], &c__1);
40922 			    vmax = 1.;
40923 			    vcrit = bignum;
40924 			}
40925 
40926 			i__3 = j - ki - 2;
40927 			work[j + *n] -= ddot_(&i__3, &t[ki + 2 + j * t_dim1],
40928 				&c__1, &work[ki + 2 + *n], &c__1);
40929 			i__3 = j - ki - 2;
40930 			work[j + n2] -= ddot_(&i__3, &t[ki + 2 + j * t_dim1],
40931 				&c__1, &work[ki + 2 + n2], &c__1);
40932 
40933 /*                    Solve (T(J,J)-(WR-i*WI))*(X11+i*X12)= WK+I*WK2 */
40934 
40935 			d__1 = -wi;
40936 			dlaln2_(&c_false, &c__1, &c__2, &smin, &c_b15, &t[j +
40937 				j * t_dim1], ldt, &c_b15, &c_b15, &work[j + *
40938 				n], n, &wr, &d__1, x, &c__2, &scale, &xnorm, &
40939 				ierr);
40940 
40941 /*                    Scale if necessary */
40942 
40943 			if (scale != 1.) {
40944 			    i__3 = *n - ki + 1;
40945 			    dscal_(&i__3, &scale, &work[ki + *n], &c__1);
40946 			    i__3 = *n - ki + 1;
40947 			    dscal_(&i__3, &scale, &work[ki + n2], &c__1);
40948 			}
40949 			work[j + *n] = x[0];
40950 			work[j + n2] = x[2];
40951 /* Computing MAX */
40952 			d__3 = (d__1 = work[j + *n], abs(d__1)), d__4 = (d__2
40953 				= work[j + n2], abs(d__2)), d__3 = max(d__3,
40954 				d__4);
40955 			vmax = max(d__3,vmax);
40956 			vcrit = bignum / vmax;
40957 
40958 		    } else {
40959 
40960 /*
40961                       2-by-2 diagonal block
40962 
40963                       Scale if necessary to avoid overflow when forming
40964                       the right-hand side elements.
40965 
40966    Computing MAX
40967 */
40968 			d__1 = work[j], d__2 = work[j + 1];
40969 			beta = max(d__1,d__2);
40970 			if (beta > vcrit) {
40971 			    rec = 1. / vmax;
40972 			    i__3 = *n - ki + 1;
40973 			    dscal_(&i__3, &rec, &work[ki + *n], &c__1);
40974 			    i__3 = *n - ki + 1;
40975 			    dscal_(&i__3, &rec, &work[ki + n2], &c__1);
40976 			    vmax = 1.;
40977 			    vcrit = bignum;
40978 			}
40979 
40980 			i__3 = j - ki - 2;
40981 			work[j + *n] -= ddot_(&i__3, &t[ki + 2 + j * t_dim1],
40982 				&c__1, &work[ki + 2 + *n], &c__1);
40983 
40984 			i__3 = j - ki - 2;
40985 			work[j + n2] -= ddot_(&i__3, &t[ki + 2 + j * t_dim1],
40986 				&c__1, &work[ki + 2 + n2], &c__1);
40987 
40988 			i__3 = j - ki - 2;
40989 			work[j + 1 + *n] -= ddot_(&i__3, &t[ki + 2 + (j + 1) *
40990 				 t_dim1], &c__1, &work[ki + 2 + *n], &c__1);
40991 
40992 			i__3 = j - ki - 2;
40993 			work[j + 1 + n2] -= ddot_(&i__3, &t[ki + 2 + (j + 1) *
40994 				 t_dim1], &c__1, &work[ki + 2 + n2], &c__1);
40995 
40996 /*
40997                       Solve 2-by-2 complex linear equation
40998                         ([T(j,j)   T(j,j+1)  ]'-(wr-i*wi)*I)*X = SCALE*B
40999                         ([T(j+1,j) T(j+1,j+1)]             )
41000 */
41001 
41002 			d__1 = -wi;
41003 			dlaln2_(&c_true, &c__2, &c__2, &smin, &c_b15, &t[j +
41004 				j * t_dim1], ldt, &c_b15, &c_b15, &work[j + *
41005 				n], n, &wr, &d__1, x, &c__2, &scale, &xnorm, &
41006 				ierr);
41007 
41008 /*                    Scale if necessary */
41009 
41010 			if (scale != 1.) {
41011 			    i__3 = *n - ki + 1;
41012 			    dscal_(&i__3, &scale, &work[ki + *n], &c__1);
41013 			    i__3 = *n - ki + 1;
41014 			    dscal_(&i__3, &scale, &work[ki + n2], &c__1);
41015 			}
41016 			work[j + *n] = x[0];
41017 			work[j + n2] = x[2];
41018 			work[j + 1 + *n] = x[1];
41019 			work[j + 1 + n2] = x[3];
41020 /* Computing MAX */
41021 			d__1 = abs(x[0]), d__2 = abs(x[2]), d__1 = max(d__1,
41022 				d__2), d__2 = abs(x[1]), d__1 = max(d__1,d__2)
41023 				, d__2 = abs(x[3]), d__1 = max(d__1,d__2);
41024 			vmax = max(d__1,vmax);
41025 			vcrit = bignum / vmax;
41026 
41027 		    }
41028 L200:
41029 		    ;
41030 		}
41031 
41032 /*              Copy the vector x or Q*x to VL and normalize. */
41033 
41034 		if (! over) {
41035 		    i__2 = *n - ki + 1;
41036 		    dcopy_(&i__2, &work[ki + *n], &c__1, &vl[ki + is *
41037 			    vl_dim1], &c__1);
41038 		    i__2 = *n - ki + 1;
41039 		    dcopy_(&i__2, &work[ki + n2], &c__1, &vl[ki + (is + 1) *
41040 			    vl_dim1], &c__1);
41041 
41042 		    emax = 0.;
41043 		    i__2 = *n;
41044 		    for (k = ki; k <= i__2; ++k) {
41045 /* Computing MAX */
41046 			d__3 = emax, d__4 = (d__1 = vl[k + is * vl_dim1], abs(
41047 				d__1)) + (d__2 = vl[k + (is + 1) * vl_dim1],
41048 				abs(d__2));
41049 			emax = max(d__3,d__4);
41050 /* L220: */
41051 		    }
41052 		    remax = 1. / emax;
41053 		    i__2 = *n - ki + 1;
41054 		    dscal_(&i__2, &remax, &vl[ki + is * vl_dim1], &c__1);
41055 		    i__2 = *n - ki + 1;
41056 		    dscal_(&i__2, &remax, &vl[ki + (is + 1) * vl_dim1], &c__1)
41057 			    ;
41058 
41059 		    i__2 = ki - 1;
41060 		    for (k = 1; k <= i__2; ++k) {
41061 			vl[k + is * vl_dim1] = 0.;
41062 			vl[k + (is + 1) * vl_dim1] = 0.;
41063 /* L230: */
41064 		    }
41065 		} else {
41066 		    if (ki < *n - 1) {
41067 			i__2 = *n - ki - 1;
41068 			dgemv_("N", n, &i__2, &c_b15, &vl[(ki + 2) * vl_dim1
41069 				+ 1], ldvl, &work[ki + 2 + *n], &c__1, &work[
41070 				ki + *n], &vl[ki * vl_dim1 + 1], &c__1);
41071 			i__2 = *n - ki - 1;
41072 			dgemv_("N", n, &i__2, &c_b15, &vl[(ki + 2) * vl_dim1
41073 				+ 1], ldvl, &work[ki + 2 + n2], &c__1, &work[
41074 				ki + 1 + n2], &vl[(ki + 1) * vl_dim1 + 1], &
41075 				c__1);
41076 		    } else {
41077 			dscal_(n, &work[ki + *n], &vl[ki * vl_dim1 + 1], &
41078 				c__1);
41079 			dscal_(n, &work[ki + 1 + n2], &vl[(ki + 1) * vl_dim1
41080 				+ 1], &c__1);
41081 		    }
41082 
41083 		    emax = 0.;
41084 		    i__2 = *n;
41085 		    for (k = 1; k <= i__2; ++k) {
41086 /* Computing MAX */
41087 			d__3 = emax, d__4 = (d__1 = vl[k + ki * vl_dim1], abs(
41088 				d__1)) + (d__2 = vl[k + (ki + 1) * vl_dim1],
41089 				abs(d__2));
41090 			emax = max(d__3,d__4);
41091 /* L240: */
41092 		    }
41093 		    remax = 1. / emax;
41094 		    dscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
41095 		    dscal_(n, &remax, &vl[(ki + 1) * vl_dim1 + 1], &c__1);
41096 
41097 		}
41098 
41099 	    }
41100 
41101 	    ++is;
41102 	    if (ip != 0) {
41103 		++is;
41104 	    }
41105 L250:
41106 	    if (ip == -1) {
41107 		ip = 0;
41108 	    }
41109 	    if (ip == 1) {
41110 		ip = -1;
41111 	    }
41112 
41113 /* L260: */
41114 	}
41115 
41116     }
41117 
41118     return 0;
41119 
41120 /*     End of DTREVC */
41121 
41122 } /* dtrevc_ */
41123 
dtrexc_(char * compq,integer * n,doublereal * t,integer * ldt,doublereal * q,integer * ldq,integer * ifst,integer * ilst,doublereal * work,integer * info)41124 /* Subroutine */ int dtrexc_(char *compq, integer *n, doublereal *t, integer *
41125 	ldt, doublereal *q, integer *ldq, integer *ifst, integer *ilst,
41126 	doublereal *work, integer *info)
41127 {
41128     /* System generated locals */
41129     integer q_dim1, q_offset, t_dim1, t_offset, i__1;
41130 
41131     /* Local variables */
41132     static integer nbf, nbl, here;
41133     extern logical lsame_(char *, char *);
41134     static logical wantq;
41135     extern /* Subroutine */ int dlaexc_(logical *, integer *, doublereal *,
41136 	    integer *, doublereal *, integer *, integer *, integer *, integer
41137 	    *, doublereal *, integer *), xerbla_(char *, integer *);
41138     static integer nbnext;
41139 
41140 
41141 /*
41142     -- LAPACK routine (version 3.2) --
41143     -- LAPACK is a software package provided by Univ. of Tennessee,    --
41144     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
41145        November 2006
41146 
41147 
41148     Purpose
41149     =======
41150 
41151     DTREXC reorders the real Schur factorization of a real matrix
41152     A = Q*T*Q**T, so that the diagonal block of T with row index IFST is
41153     moved to row ILST.
41154 
41155     The real Schur form T is reordered by an orthogonal similarity
41156     transformation Z**T*T*Z, and optionally the matrix Q of Schur vectors
41157     is updated by postmultiplying it with Z.
41158 
41159     T must be in Schur canonical form (as returned by DHSEQR), that is,
41160     block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; each
41161     2-by-2 diagonal block has its diagonal elements equal and its
41162     off-diagonal elements of opposite sign.
41163 
41164     Arguments
41165     =========
41166 
41167     COMPQ   (input) CHARACTER*1
41168             = 'V':  update the matrix Q of Schur vectors;
41169             = 'N':  do not update Q.
41170 
41171     N       (input) INTEGER
41172             The order of the matrix T. N >= 0.
41173 
41174     T       (input/output) DOUBLE PRECISION array, dimension (LDT,N)
41175             On entry, the upper quasi-triangular matrix T, in Schur
41176             Schur canonical form.
41177             On exit, the reordered upper quasi-triangular matrix, again
41178             in Schur canonical form.
41179 
41180     LDT     (input) INTEGER
41181             The leading dimension of the array T. LDT >= max(1,N).
41182 
41183     Q       (input/output) DOUBLE PRECISION array, dimension (LDQ,N)
41184             On entry, if COMPQ = 'V', the matrix Q of Schur vectors.
41185             On exit, if COMPQ = 'V', Q has been postmultiplied by the
41186             orthogonal transformation matrix Z which reorders T.
41187             If COMPQ = 'N', Q is not referenced.
41188 
41189     LDQ     (input) INTEGER
41190             The leading dimension of the array Q.  LDQ >= max(1,N).
41191 
41192     IFST    (input/output) INTEGER
41193     ILST    (input/output) INTEGER
41194             Specify the reordering of the diagonal blocks of T.
41195             The block with row index IFST is moved to row ILST, by a
41196             sequence of transpositions between adjacent blocks.
41197             On exit, if IFST pointed on entry to the second row of a
41198             2-by-2 block, it is changed to point to the first row; ILST
41199             always points to the first row of the block in its final
41200             position (which may differ from its input value by +1 or -1).
41201             1 <= IFST <= N; 1 <= ILST <= N.
41202 
41203     WORK    (workspace) DOUBLE PRECISION array, dimension (N)
41204 
41205     INFO    (output) INTEGER
41206             = 0:  successful exit
41207             < 0:  if INFO = -i, the i-th argument had an illegal value
41208             = 1:  two adjacent blocks were too close to swap (the problem
41209                   is very ill-conditioned); T may have been partially
41210                   reordered, and ILST points to the first row of the
41211                   current position of the block being moved.
41212 
41213     =====================================================================
41214 
41215 
41216        Decode and test the input arguments.
41217 */
41218 
41219     /* Parameter adjustments */
41220     t_dim1 = *ldt;
41221     t_offset = 1 + t_dim1;
41222     t -= t_offset;
41223     q_dim1 = *ldq;
41224     q_offset = 1 + q_dim1;
41225     q -= q_offset;
41226     --work;
41227 
41228     /* Function Body */
41229     *info = 0;
41230     wantq = lsame_(compq, "V");
41231     if (! wantq && ! lsame_(compq, "N")) {
41232 	*info = -1;
41233     } else if (*n < 0) {
41234 	*info = -2;
41235     } else if (*ldt < max(1,*n)) {
41236 	*info = -4;
41237     } else if (*ldq < 1 || wantq && *ldq < max(1,*n)) {
41238 	*info = -6;
41239     } else if (*ifst < 1 || *ifst > *n) {
41240 	*info = -7;
41241     } else if (*ilst < 1 || *ilst > *n) {
41242 	*info = -8;
41243     }
41244     if (*info != 0) {
41245 	i__1 = -(*info);
41246 	xerbla_("DTREXC", &i__1);
41247 	return 0;
41248     }
41249 
41250 /*     Quick return if possible */
41251 
41252     if (*n <= 1) {
41253 	return 0;
41254     }
41255 
41256 /*
41257        Determine the first row of specified block
41258        and find out it is 1 by 1 or 2 by 2.
41259 */
41260 
41261     if (*ifst > 1) {
41262 	if (t[*ifst + (*ifst - 1) * t_dim1] != 0.) {
41263 	    --(*ifst);
41264 	}
41265     }
41266     nbf = 1;
41267     if (*ifst < *n) {
41268 	if (t[*ifst + 1 + *ifst * t_dim1] != 0.) {
41269 	    nbf = 2;
41270 	}
41271     }
41272 
41273 /*
41274        Determine the first row of the final block
41275        and find out it is 1 by 1 or 2 by 2.
41276 */
41277 
41278     if (*ilst > 1) {
41279 	if (t[*ilst + (*ilst - 1) * t_dim1] != 0.) {
41280 	    --(*ilst);
41281 	}
41282     }
41283     nbl = 1;
41284     if (*ilst < *n) {
41285 	if (t[*ilst + 1 + *ilst * t_dim1] != 0.) {
41286 	    nbl = 2;
41287 	}
41288     }
41289 
41290     if (*ifst == *ilst) {
41291 	return 0;
41292     }
41293 
41294     if (*ifst < *ilst) {
41295 
41296 /*        Update ILST */
41297 
41298 	if (nbf == 2 && nbl == 1) {
41299 	    --(*ilst);
41300 	}
41301 	if (nbf == 1 && nbl == 2) {
41302 	    ++(*ilst);
41303 	}
41304 
41305 	here = *ifst;
41306 
41307 L10:
41308 
41309 /*        Swap block with next one below */
41310 
41311 	if (nbf == 1 || nbf == 2) {
41312 
41313 /*           Current block either 1 by 1 or 2 by 2 */
41314 
41315 	    nbnext = 1;
41316 	    if (here + nbf + 1 <= *n) {
41317 		if (t[here + nbf + 1 + (here + nbf) * t_dim1] != 0.) {
41318 		    nbnext = 2;
41319 		}
41320 	    }
41321 	    dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &here, &
41322 		    nbf, &nbnext, &work[1], info);
41323 	    if (*info != 0) {
41324 		*ilst = here;
41325 		return 0;
41326 	    }
41327 	    here += nbnext;
41328 
41329 /*           Test if 2 by 2 block breaks into two 1 by 1 blocks */
41330 
41331 	    if (nbf == 2) {
41332 		if (t[here + 1 + here * t_dim1] == 0.) {
41333 		    nbf = 3;
41334 		}
41335 	    }
41336 
41337 	} else {
41338 
41339 /*
41340              Current block consists of two 1 by 1 blocks each of which
41341              must be swapped individually
41342 */
41343 
41344 	    nbnext = 1;
41345 	    if (here + 3 <= *n) {
41346 		if (t[here + 3 + (here + 2) * t_dim1] != 0.) {
41347 		    nbnext = 2;
41348 		}
41349 	    }
41350 	    i__1 = here + 1;
41351 	    dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &i__1, &
41352 		    c__1, &nbnext, &work[1], info);
41353 	    if (*info != 0) {
41354 		*ilst = here;
41355 		return 0;
41356 	    }
41357 	    if (nbnext == 1) {
41358 
41359 /*              Swap two 1 by 1 blocks, no problems possible */
41360 
41361 		dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
41362 			here, &c__1, &nbnext, &work[1], info);
41363 		++here;
41364 	    } else {
41365 
41366 /*              Recompute NBNEXT in case 2 by 2 split */
41367 
41368 		if (t[here + 2 + (here + 1) * t_dim1] == 0.) {
41369 		    nbnext = 1;
41370 		}
41371 		if (nbnext == 2) {
41372 
41373 /*                 2 by 2 Block did not split */
41374 
41375 		    dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
41376 			    here, &c__1, &nbnext, &work[1], info);
41377 		    if (*info != 0) {
41378 			*ilst = here;
41379 			return 0;
41380 		    }
41381 		    here += 2;
41382 		} else {
41383 
41384 /*                 2 by 2 Block did split */
41385 
41386 		    dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
41387 			    here, &c__1, &c__1, &work[1], info);
41388 		    i__1 = here + 1;
41389 		    dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
41390 			    i__1, &c__1, &c__1, &work[1], info);
41391 		    here += 2;
41392 		}
41393 	    }
41394 	}
41395 	if (here < *ilst) {
41396 	    goto L10;
41397 	}
41398 
41399     } else {
41400 
41401 	here = *ifst;
41402 L20:
41403 
41404 /*        Swap block with next one above */
41405 
41406 	if (nbf == 1 || nbf == 2) {
41407 
41408 /*           Current block either 1 by 1 or 2 by 2 */
41409 
41410 	    nbnext = 1;
41411 	    if (here >= 3) {
41412 		if (t[here - 1 + (here - 2) * t_dim1] != 0.) {
41413 		    nbnext = 2;
41414 		}
41415 	    }
41416 	    i__1 = here - nbnext;
41417 	    dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &i__1, &
41418 		    nbnext, &nbf, &work[1], info);
41419 	    if (*info != 0) {
41420 		*ilst = here;
41421 		return 0;
41422 	    }
41423 	    here -= nbnext;
41424 
41425 /*           Test if 2 by 2 block breaks into two 1 by 1 blocks */
41426 
41427 	    if (nbf == 2) {
41428 		if (t[here + 1 + here * t_dim1] == 0.) {
41429 		    nbf = 3;
41430 		}
41431 	    }
41432 
41433 	} else {
41434 
41435 /*
41436              Current block consists of two 1 by 1 blocks each of which
41437              must be swapped individually
41438 */
41439 
41440 	    nbnext = 1;
41441 	    if (here >= 3) {
41442 		if (t[here - 1 + (here - 2) * t_dim1] != 0.) {
41443 		    nbnext = 2;
41444 		}
41445 	    }
41446 	    i__1 = here - nbnext;
41447 	    dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &i__1, &
41448 		    nbnext, &c__1, &work[1], info);
41449 	    if (*info != 0) {
41450 		*ilst = here;
41451 		return 0;
41452 	    }
41453 	    if (nbnext == 1) {
41454 
41455 /*              Swap two 1 by 1 blocks, no problems possible */
41456 
41457 		dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
41458 			here, &nbnext, &c__1, &work[1], info);
41459 		--here;
41460 	    } else {
41461 
41462 /*              Recompute NBNEXT in case 2 by 2 split */
41463 
41464 		if (t[here + (here - 1) * t_dim1] == 0.) {
41465 		    nbnext = 1;
41466 		}
41467 		if (nbnext == 2) {
41468 
41469 /*                 2 by 2 Block did not split */
41470 
41471 		    i__1 = here - 1;
41472 		    dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
41473 			    i__1, &c__2, &c__1, &work[1], info);
41474 		    if (*info != 0) {
41475 			*ilst = here;
41476 			return 0;
41477 		    }
41478 		    here += -2;
41479 		} else {
41480 
41481 /*                 2 by 2 Block did split */
41482 
41483 		    dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
41484 			    here, &c__1, &c__1, &work[1], info);
41485 		    i__1 = here - 1;
41486 		    dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
41487 			    i__1, &c__1, &c__1, &work[1], info);
41488 		    here += -2;
41489 		}
41490 	    }
41491 	}
41492 	if (here > *ilst) {
41493 	    goto L20;
41494 	}
41495     }
41496     *ilst = here;
41497 
41498     return 0;
41499 
41500 /*     End of DTREXC */
41501 
41502 } /* dtrexc_ */
41503 
dtrti2_(char * uplo,char * diag,integer * n,doublereal * a,integer * lda,integer * info)41504 /* Subroutine */ int dtrti2_(char *uplo, char *diag, integer *n, doublereal *
41505 	a, integer *lda, integer *info)
41506 {
41507     /* System generated locals */
41508     integer a_dim1, a_offset, i__1, i__2;
41509 
41510     /* Local variables */
41511     static integer j;
41512     static doublereal ajj;
41513     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
41514 	    integer *);
41515     extern logical lsame_(char *, char *);
41516     static logical upper;
41517     extern /* Subroutine */ int dtrmv_(char *, char *, char *, integer *,
41518 	    doublereal *, integer *, doublereal *, integer *), xerbla_(char *, integer *);
41519     static logical nounit;
41520 
41521 
41522 /*
41523     -- LAPACK routine (version 3.2) --
41524     -- LAPACK is a software package provided by Univ. of Tennessee,    --
41525     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
41526        November 2006
41527 
41528 
41529     Purpose
41530     =======
41531 
41532     DTRTI2 computes the inverse of a real upper or lower triangular
41533     matrix.
41534 
41535     This is the Level 2 BLAS version of the algorithm.
41536 
41537     Arguments
41538     =========
41539 
41540     UPLO    (input) CHARACTER*1
41541             Specifies whether the matrix A is upper or lower triangular.
41542             = 'U':  Upper triangular
41543             = 'L':  Lower triangular
41544 
41545     DIAG    (input) CHARACTER*1
41546             Specifies whether or not the matrix A is unit triangular.
41547             = 'N':  Non-unit triangular
41548             = 'U':  Unit triangular
41549 
41550     N       (input) INTEGER
41551             The order of the matrix A.  N >= 0.
41552 
41553     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
41554             On entry, the triangular matrix A.  If UPLO = 'U', the
41555             leading n by n upper triangular part of the array A contains
41556             the upper triangular matrix, and the strictly lower
41557             triangular part of A is not referenced.  If UPLO = 'L', the
41558             leading n by n lower triangular part of the array A contains
41559             the lower triangular matrix, and the strictly upper
41560             triangular part of A is not referenced.  If DIAG = 'U', the
41561             diagonal elements of A are also not referenced and are
41562             assumed to be 1.
41563 
41564             On exit, the (triangular) inverse of the original matrix, in
41565             the same storage format.
41566 
41567     LDA     (input) INTEGER
41568             The leading dimension of the array A.  LDA >= max(1,N).
41569 
41570     INFO    (output) INTEGER
41571             = 0: successful exit
41572             < 0: if INFO = -k, the k-th argument had an illegal value
41573 
41574     =====================================================================
41575 
41576 
41577        Test the input parameters.
41578 */
41579 
41580     /* Parameter adjustments */
41581     a_dim1 = *lda;
41582     a_offset = 1 + a_dim1;
41583     a -= a_offset;
41584 
41585     /* Function Body */
41586     *info = 0;
41587     upper = lsame_(uplo, "U");
41588     nounit = lsame_(diag, "N");
41589     if (! upper && ! lsame_(uplo, "L")) {
41590 	*info = -1;
41591     } else if (! nounit && ! lsame_(diag, "U")) {
41592 	*info = -2;
41593     } else if (*n < 0) {
41594 	*info = -3;
41595     } else if (*lda < max(1,*n)) {
41596 	*info = -5;
41597     }
41598     if (*info != 0) {
41599 	i__1 = -(*info);
41600 	xerbla_("DTRTI2", &i__1);
41601 	return 0;
41602     }
41603 
41604     if (upper) {
41605 
41606 /*        Compute inverse of upper triangular matrix. */
41607 
41608 	i__1 = *n;
41609 	for (j = 1; j <= i__1; ++j) {
41610 	    if (nounit) {
41611 		a[j + j * a_dim1] = 1. / a[j + j * a_dim1];
41612 		ajj = -a[j + j * a_dim1];
41613 	    } else {
41614 		ajj = -1.;
41615 	    }
41616 
41617 /*           Compute elements 1:j-1 of j-th column. */
41618 
41619 	    i__2 = j - 1;
41620 	    dtrmv_("Upper", "No transpose", diag, &i__2, &a[a_offset], lda, &
41621 		    a[j * a_dim1 + 1], &c__1);
41622 	    i__2 = j - 1;
41623 	    dscal_(&i__2, &ajj, &a[j * a_dim1 + 1], &c__1);
41624 /* L10: */
41625 	}
41626     } else {
41627 
41628 /*        Compute inverse of lower triangular matrix. */
41629 
41630 	for (j = *n; j >= 1; --j) {
41631 	    if (nounit) {
41632 		a[j + j * a_dim1] = 1. / a[j + j * a_dim1];
41633 		ajj = -a[j + j * a_dim1];
41634 	    } else {
41635 		ajj = -1.;
41636 	    }
41637 	    if (j < *n) {
41638 
41639 /*              Compute elements j+1:n of j-th column. */
41640 
41641 		i__1 = *n - j;
41642 		dtrmv_("Lower", "No transpose", diag, &i__1, &a[j + 1 + (j +
41643 			1) * a_dim1], lda, &a[j + 1 + j * a_dim1], &c__1);
41644 		i__1 = *n - j;
41645 		dscal_(&i__1, &ajj, &a[j + 1 + j * a_dim1], &c__1);
41646 	    }
41647 /* L20: */
41648 	}
41649     }
41650 
41651     return 0;
41652 
41653 /*     End of DTRTI2 */
41654 
41655 } /* dtrti2_ */
41656 
dtrtri_(char * uplo,char * diag,integer * n,doublereal * a,integer * lda,integer * info)41657 /* Subroutine */ int dtrtri_(char *uplo, char *diag, integer *n, doublereal *
41658 	a, integer *lda, integer *info)
41659 {
41660     /* System generated locals */
41661     address a__1[2];
41662     integer a_dim1, a_offset, i__1, i__2[2], i__3, i__4, i__5;
41663     char ch__1[2];
41664 
41665     /* Local variables */
41666     static integer j, jb, nb, nn;
41667     extern logical lsame_(char *, char *);
41668     extern /* Subroutine */ int dtrmm_(char *, char *, char *, char *,
41669 	    integer *, integer *, doublereal *, doublereal *, integer *,
41670 	    doublereal *, integer *), dtrsm_(
41671 	    char *, char *, char *, char *, integer *, integer *, doublereal *
41672 	    , doublereal *, integer *, doublereal *, integer *);
41673     static logical upper;
41674     extern /* Subroutine */ int dtrti2_(char *, char *, integer *, doublereal
41675 	    *, integer *, integer *), xerbla_(char *, integer
41676 	    *);
41677     extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
41678 	    integer *, integer *, ftnlen, ftnlen);
41679     static logical nounit;
41680 
41681 
41682 /*
41683     -- LAPACK routine (version 3.2) --
41684     -- LAPACK is a software package provided by Univ. of Tennessee,    --
41685     -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
41686        November 2006
41687 
41688 
41689     Purpose
41690     =======
41691 
41692     DTRTRI computes the inverse of a real upper or lower triangular
41693     matrix A.
41694 
41695     This is the Level 3 BLAS version of the algorithm.
41696 
41697     Arguments
41698     =========
41699 
41700     UPLO    (input) CHARACTER*1
41701             = 'U':  A is upper triangular;
41702             = 'L':  A is lower triangular.
41703 
41704     DIAG    (input) CHARACTER*1
41705             = 'N':  A is non-unit triangular;
41706             = 'U':  A is unit triangular.
41707 
41708     N       (input) INTEGER
41709             The order of the matrix A.  N >= 0.
41710 
41711     A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
41712             On entry, the triangular matrix A.  If UPLO = 'U', the
41713             leading N-by-N upper triangular part of the array A contains
41714             the upper triangular matrix, and the strictly lower
41715             triangular part of A is not referenced.  If UPLO = 'L', the
41716             leading N-by-N lower triangular part of the array A contains
41717             the lower triangular matrix, and the strictly upper
41718             triangular part of A is not referenced.  If DIAG = 'U', the
41719             diagonal elements of A are also not referenced and are
41720             assumed to be 1.
41721             On exit, the (triangular) inverse of the original matrix, in
41722             the same storage format.
41723 
41724     LDA     (input) INTEGER
41725             The leading dimension of the array A.  LDA >= max(1,N).
41726 
41727     INFO    (output) INTEGER
41728             = 0: successful exit
41729             < 0: if INFO = -i, the i-th argument had an illegal value
41730             > 0: if INFO = i, A(i,i) is exactly zero.  The triangular
41731                  matrix is singular and its inverse can not be computed.
41732 
41733     =====================================================================
41734 
41735 
41736        Test the input parameters.
41737 */
41738 
41739     /* Parameter adjustments */
41740     a_dim1 = *lda;
41741     a_offset = 1 + a_dim1;
41742     a -= a_offset;
41743 
41744     /* Function Body */
41745     *info = 0;
41746     upper = lsame_(uplo, "U");
41747     nounit = lsame_(diag, "N");
41748     if (! upper && ! lsame_(uplo, "L")) {
41749 	*info = -1;
41750     } else if (! nounit && ! lsame_(diag, "U")) {
41751 	*info = -2;
41752     } else if (*n < 0) {
41753 	*info = -3;
41754     } else if (*lda < max(1,*n)) {
41755 	*info = -5;
41756     }
41757     if (*info != 0) {
41758 	i__1 = -(*info);
41759 	xerbla_("DTRTRI", &i__1);
41760 	return 0;
41761     }
41762 
41763 /*     Quick return if possible */
41764 
41765     if (*n == 0) {
41766 	return 0;
41767     }
41768 
41769 /*     Check for singularity if non-unit. */
41770 
41771     if (nounit) {
41772 	i__1 = *n;
41773 	for (*info = 1; *info <= i__1; ++(*info)) {
41774 	    if (a[*info + *info * a_dim1] == 0.) {
41775 		return 0;
41776 	    }
41777 /* L10: */
41778 	}
41779 	*info = 0;
41780     }
41781 
41782 /*
41783        Determine the block size for this environment.
41784 
41785    Writing concatenation
41786 */
41787     i__2[0] = 1, a__1[0] = uplo;
41788     i__2[1] = 1, a__1[1] = diag;
41789     s_cat(ch__1, a__1, i__2, &c__2, (ftnlen)2);
41790     nb = ilaenv_(&c__1, "DTRTRI", ch__1, n, &c_n1, &c_n1, &c_n1, (ftnlen)6, (
41791 	    ftnlen)2);
41792     if (nb <= 1 || nb >= *n) {
41793 
41794 /*        Use unblocked code */
41795 
41796 	dtrti2_(uplo, diag, n, &a[a_offset], lda, info);
41797     } else {
41798 
41799 /*        Use blocked code */
41800 
41801 	if (upper) {
41802 
41803 /*           Compute inverse of upper triangular matrix */
41804 
41805 	    i__1 = *n;
41806 	    i__3 = nb;
41807 	    for (j = 1; i__3 < 0 ? j >= i__1 : j <= i__1; j += i__3) {
41808 /* Computing MIN */
41809 		i__4 = nb, i__5 = *n - j + 1;
41810 		jb = min(i__4,i__5);
41811 
41812 /*              Compute rows 1:j-1 of current block column */
41813 
41814 		i__4 = j - 1;
41815 		dtrmm_("Left", "Upper", "No transpose", diag, &i__4, &jb, &
41816 			c_b15, &a[a_offset], lda, &a[j * a_dim1 + 1], lda);
41817 		i__4 = j - 1;
41818 		dtrsm_("Right", "Upper", "No transpose", diag, &i__4, &jb, &
41819 			c_b151, &a[j + j * a_dim1], lda, &a[j * a_dim1 + 1],
41820 			lda);
41821 
41822 /*              Compute inverse of current diagonal block */
41823 
41824 		dtrti2_("Upper", diag, &jb, &a[j + j * a_dim1], lda, info);
41825 /* L20: */
41826 	    }
41827 	} else {
41828 
41829 /*           Compute inverse of lower triangular matrix */
41830 
41831 	    nn = (*n - 1) / nb * nb + 1;
41832 	    i__3 = -nb;
41833 	    for (j = nn; i__3 < 0 ? j >= 1 : j <= 1; j += i__3) {
41834 /* Computing MIN */
41835 		i__1 = nb, i__4 = *n - j + 1;
41836 		jb = min(i__1,i__4);
41837 		if (j + jb <= *n) {
41838 
41839 /*                 Compute rows j+jb:n of current block column */
41840 
41841 		    i__1 = *n - j - jb + 1;
41842 		    dtrmm_("Left", "Lower", "No transpose", diag, &i__1, &jb,
41843 			    &c_b15, &a[j + jb + (j + jb) * a_dim1], lda, &a[j
41844 			    + jb + j * a_dim1], lda);
41845 		    i__1 = *n - j - jb + 1;
41846 		    dtrsm_("Right", "Lower", "No transpose", diag, &i__1, &jb,
41847 			     &c_b151, &a[j + j * a_dim1], lda, &a[j + jb + j *
41848 			     a_dim1], lda);
41849 		}
41850 
41851 /*              Compute inverse of current diagonal block */
41852 
41853 		dtrti2_("Lower", diag, &jb, &a[j + j * a_dim1], lda, info);
41854 /* L30: */
41855 	    }
41856 	}
41857     }
41858 
41859     return 0;
41860 
41861 /*     End of DTRTRI */
41862 
41863 } /* dtrtri_ */
41864 
41865