Debian Codegraph @

07p/src/lapack.f

raw symbols SCIP
1 *
2 * This file contains the LAPACK 3.2.2 routines
3 *
4 * DGEEV (Eigenvalues & eigenvectors, used by several)
5 * DGESVJ (Singular value decomposition, used by floquet.f90)
6 * DGGEV (Generalized eigenvalues & eigenvectors, used by floquet.f90)
7 * DGEES (Schur decomposition, used by HomCont, homcont.f90)
8 * + DTRSEN (Order Schur decomposition, used by HomCont, homcont.f90)
9 * and all their dependencies
10 *
11 * DLAMCH was rewritten to use Fortran-90 intrinsics, to avoid
12 * over-optimization.
13 *
14 * DGESVJ was changed to not divide by zero for zero columns.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions are
18 * met:
19 *
20 * - Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 *
23 * - Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer listed
25 * in this license in the documentation and/or other materials
26 * provided with the distribution.
27 *
28 * - Neither the name of the copyright holders nor the names of its
29 * contributors may be used to endorse or promote products derived from
30 * this software without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
40 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
42 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 *
44 INTEGER FUNCTION ILAENV( ISPEC, NAME, OPTS, N1, N2, N3, N4 )
45 *
46 * -- LAPACK auxiliary routine (version 3.2.1) --
47 *
48 * -- April 2009 --
49 *
50 * -- LAPACK is a software package provided by Univ. of Tennessee, --
51 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
52 *
53 * .. Scalar Arguments ..
54 CHARACTER*( * ) NAME, OPTS
55 INTEGER ISPEC, N1, N2, N3, N4
56 * ..
57 *
58 * Purpose
59 * =======
60 *
61 * ILAENV is called from the LAPACK routines to choose problem-dependent
62 * parameters for the local environment. See ISPEC for a description of
63 * the parameters.
64 *
65 * ILAENV returns an INTEGER
66 * if ILAENV >= 0: ILAENV returns the value of the parameter specified by ISPEC
67 * if ILAENV < 0: if ILAENV = -k, the k-th argument had an illegal value.
68 *
69 * This version provides a set of parameters which should give good,
70 * but not optimal, performance on many of the currently available
71 * computers. Users are encouraged to modify this subroutine to set
72 * the tuning parameters for their particular machine using the option
73 * and problem size information in the arguments.
74 *
75 * This routine will not function correctly if it is converted to all
76 * lower case. Converting it to all upper case is allowed.
77 *
78 * Arguments
79 * =========
80 *
81 * ISPEC (input) INTEGER
82 * Specifies the parameter to be returned as the value of
83 * ILAENV.
84 * = 1: the optimal blocksize; if this value is 1, an unblocked
85 * algorithm will give the best performance.
86 * = 2: the minimum block size for which the block routine
87 * should be used; if the usable block size is less than
88 * this value, an unblocked routine should be used.
89 * = 3: the crossover point (in a block routine, for N less
90 * than this value, an unblocked routine should be used)
91 * = 4: the number of shifts, used in the nonsymmetric
92 * eigenvalue routines (DEPRECATED)
93 * = 5: the minimum column dimension for blocking to be used;
94 * rectangular blocks must have dimension at least k by m,
95 * where k is given by ILAENV(2,...) and m by ILAENV(5,...)
96 * = 6: the crossover point for the SVD (when reducing an m by n
97 * matrix to bidiagonal form, if max(m,n)/min(m,n) exceeds
98 * this value, a QR factorization is used first to reduce
99 * the matrix to a triangular form.)
100 * = 7: the number of processors
101 * = 8: the crossover point for the multishift QR method
102 * for nonsymmetric eigenvalue problems (DEPRECATED)
103 * = 9: maximum size of the subproblems at the bottom of the
104 * computation tree in the divide-and-conquer algorithm
105 * (used by xGELSD and xGESDD)
106 * =10: ieee NaN arithmetic can be trusted not to trap
107 * =11: infinity arithmetic can be trusted not to trap
108 * 12 <= ISPEC <= 16:
109 * xHSEQR or one of its subroutines,
110 * see IPARMQ for detailed explanation
111 *
112 * NAME (input) CHARACTER*(*)
113 * The name of the calling subroutine, in either upper case or
114 * lower case.
115 *
116 * OPTS (input) CHARACTER*(*)
117 * The character options to the subroutine NAME, concatenated
118 * into a single character string. For example, UPLO = 'U',
119 * TRANS = 'T', and DIAG = 'N' for a triangular routine would
120 * be specified as OPTS = 'UTN'.
121 *
122 * N1 (input) INTEGER
123 * N2 (input) INTEGER
124 * N3 (input) INTEGER
125 * N4 (input) INTEGER
126 * Problem dimensions for the subroutine NAME; these may not all
127 * be required.
128 *
129 * Further Details
130 * ===============
131 *
132 * The following conventions have been used when calling ILAENV from the
133 * LAPACK routines:
134 * 1) OPTS is a concatenation of all of the character options to
135 * subroutine NAME, in the same order that they appear in the
136 * argument list for NAME, even if they are not used in determining
137 * the value of the parameter specified by ISPEC.
138 * 2) The problem dimensions N1, N2, N3, N4 are specified in the order
139 * that they appear in the argument list for NAME. N1 is used
140 * first, N2 second, and so on, and unused problem dimensions are
141 * passed a value of -1.
142 * 3) The parameter value returned by ILAENV is checked for validity in
143 * the calling subroutine. For example, ILAENV is used to retrieve
144 * the optimal blocksize for STRTRI as follows:
145 *
146 * NB = ILAENV( 1, 'STRTRI', UPLO // DIAG, N, -1, -1, -1 )
147 * IF( NB.LE.1 ) NB = MAX( 1, N )
148 *
149 * =====================================================================
150 *
151 * .. Local Scalars ..
152 INTEGER I, IC, IZ, NB, NBMIN, NX
153 LOGICAL CNAME, SNAME
154 CHARACTER C1*1, C2*2, C4*2, C3*3, SUBNAM*6
155 * ..
156 * .. Intrinsic Functions ..
157 INTRINSIC CHAR, ICHAR, INT, MIN, REAL
158 * ..
159 * .. External Functions ..
160 INTEGER IEEECK, IPARMQ
161 EXTERNAL IEEECK, IPARMQ
162 * ..
163 * .. Executable Statements ..
164 *
165 GO TO ( 10, 10, 10, 80, 90, 100, 110, 120,
166 $ 130, 140, 150, 160, 160, 160, 160, 160 )ISPEC
167 *
168 * Invalid value for ISPEC
169 *
170 ILAENV = -1
171 RETURN
172 *
173 10 CONTINUE
174 *
175 * Convert NAME to upper case if the first character is lower case.
176 *
177 ILAENV = 1
178 SUBNAM = NAME
179 IC = ICHAR( SUBNAM( 1: 1 ) )
180 IZ = ICHAR( 'Z' )
181 IF( IZ.EQ.90 .OR. IZ.EQ.122 ) THEN
182 *
183 * ASCII character set
184 *
185 IF( IC.GE.97 .AND. IC.LE.122 ) THEN
186 SUBNAM( 1: 1 ) = CHAR( IC-32 )
187 DO 20 I = 2, 6
188 IC = ICHAR( SUBNAM( I: I ) )
189 IF( IC.GE.97 .AND. IC.LE.122 )
190 $ SUBNAM( I: I ) = CHAR( IC-32 )
191 20 CONTINUE
192 END IF
193 *
194 ELSE IF( IZ.EQ.233 .OR. IZ.EQ.169 ) THEN
195 *
196 * EBCDIC character set
197 *
198 IF( ( IC.GE.129 .AND. IC.LE.137 ) .OR.
199 $ ( IC.GE.145 .AND. IC.LE.153 ) .OR.
200 $ ( IC.GE.162 .AND. IC.LE.169 ) ) THEN
201 SUBNAM( 1: 1 ) = CHAR( IC+64 )
202 DO 30 I = 2, 6
203 IC = ICHAR( SUBNAM( I: I ) )
204 IF( ( IC.GE.129 .AND. IC.LE.137 ) .OR.
205 $ ( IC.GE.145 .AND. IC.LE.153 ) .OR.
206 $ ( IC.GE.162 .AND. IC.LE.169 ) )SUBNAM( I:
207 $ I ) = CHAR( IC+64 )
208 30 CONTINUE
209 END IF
210 *
211 ELSE IF( IZ.EQ.218 .OR. IZ.EQ.250 ) THEN
212 *
213 * Prime machines: ASCII+128
214 *
215 IF( IC.GE.225 .AND. IC.LE.250 ) THEN
216 SUBNAM( 1: 1 ) = CHAR( IC-32 )
217 DO 40 I = 2, 6
218 IC = ICHAR( SUBNAM( I: I ) )
219 IF( IC.GE.225 .AND. IC.LE.250 )
220 $ SUBNAM( I: I ) = CHAR( IC-32 )
221 40 CONTINUE
222 END IF
223 END IF
224 *
225 C1 = SUBNAM( 1: 1 )
226 SNAME = C1.EQ.'S' .OR. C1.EQ.'D'
227 CNAME = C1.EQ.'C' .OR. C1.EQ.'Z'
228 IF( .NOT.( CNAME .OR. SNAME ) )
229 $ RETURN
230 C2 = SUBNAM( 2: 3 )
231 C3 = SUBNAM( 4: 6 )
232 C4 = C3( 2: 3 )
233 *
234 GO TO ( 50, 60, 70 )ISPEC
235 *
236 50 CONTINUE
237 *
238 * ISPEC = 1: block size
239 *
240 * In these examples, separate code is provided for setting NB for
241 * real and complex. We assume that NB will take the same value in
242 * single or double precision.
243 *
244 NB = 1
245 *
246 IF( C2.EQ.'GE' ) THEN
247 IF( C3.EQ.'TRF' ) THEN
248 IF( SNAME ) THEN
249 NB = 64
250 ELSE
251 NB = 64
252 END IF
253 ELSE IF( C3.EQ.'QRF' .OR. C3.EQ.'RQF' .OR. C3.EQ.'LQF' .OR.
254 $ C3.EQ.'QLF' ) THEN
255 IF( SNAME ) THEN
256 NB = 32
257 ELSE
258 NB = 32
259 END IF
260 ELSE IF( C3.EQ.'HRD' ) THEN
261 IF( SNAME ) THEN
262 NB = 32
263 ELSE
264 NB = 32
265 END IF
266 ELSE IF( C3.EQ.'BRD' ) THEN
267 IF( SNAME ) THEN
268 NB = 32
269 ELSE
270 NB = 32
271 END IF
272 ELSE IF( C3.EQ.'TRI' ) THEN
273 IF( SNAME ) THEN
274 NB = 64
275 ELSE
276 NB = 64
277 END IF
278 END IF
279 ELSE IF( C2.EQ.'PO' ) THEN
280 IF( C3.EQ.'TRF' ) THEN
281 IF( SNAME ) THEN
282 NB = 64
283 ELSE
284 NB = 64
285 END IF
286 END IF
287 ELSE IF( C2.EQ.'SY' ) THEN
288 IF( C3.EQ.'TRF' ) THEN
289 IF( SNAME ) THEN
290 NB = 64
291 ELSE
292 NB = 64
293 END IF
294 ELSE IF( SNAME .AND. C3.EQ.'TRD' ) THEN
295 NB = 32
296 ELSE IF( SNAME .AND. C3.EQ.'GST' ) THEN
297 NB = 64
298 END IF
299 ELSE IF( CNAME .AND. C2.EQ.'HE' ) THEN
300 IF( C3.EQ.'TRF' ) THEN
301 NB = 64
302 ELSE IF( C3.EQ.'TRD' ) THEN
303 NB = 32
304 ELSE IF( C3.EQ.'GST' ) THEN
305 NB = 64
306 END IF
307 ELSE IF( SNAME .AND. C2.EQ.'OR' ) THEN
308 IF( C3( 1: 1 ).EQ.'G' ) THEN
309 IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ.
310 $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' )
311 $ THEN
312 NB = 32
313 END IF
314 ELSE IF( C3( 1: 1 ).EQ.'M' ) THEN
315 IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ.
316 $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' )
317 $ THEN
318 NB = 32
319 END IF
320 END IF
321 ELSE IF( CNAME .AND. C2.EQ.'UN' ) THEN
322 IF( C3( 1: 1 ).EQ.'G' ) THEN
323 IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ.
324 $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' )
325 $ THEN
326 NB = 32
327 END IF
328 ELSE IF( C3( 1: 1 ).EQ.'M' ) THEN
329 IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ.
330 $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' )
331 $ THEN
332 NB = 32
333 END IF
334 END IF
335 ELSE IF( C2.EQ.'GB' ) THEN
336 IF( C3.EQ.'TRF' ) THEN
337 IF( SNAME ) THEN
338 IF( N4.LE.64 ) THEN
339 NB = 1
340 ELSE
341 NB = 32
342 END IF
343 ELSE
344 IF( N4.LE.64 ) THEN
345 NB = 1
346 ELSE
347 NB = 32
348 END IF
349 END IF
350 END IF
351 ELSE IF( C2.EQ.'PB' ) THEN
352 IF( C3.EQ.'TRF' ) THEN
353 IF( SNAME ) THEN
354 IF( N2.LE.64 ) THEN
355 NB = 1
356 ELSE
357 NB = 32
358 END IF
359 ELSE
360 IF( N2.LE.64 ) THEN
361 NB = 1
362 ELSE
363 NB = 32
364 END IF
365 END IF
366 END IF
367 ELSE IF( C2.EQ.'TR' ) THEN
368 IF( C3.EQ.'TRI' ) THEN
369 IF( SNAME ) THEN
370 NB = 64
371 ELSE
372 NB = 64
373 END IF
374 END IF
375 ELSE IF( C2.EQ.'LA' ) THEN
376 IF( C3.EQ.'UUM' ) THEN
377 IF( SNAME ) THEN
378 NB = 64
379 ELSE
380 NB = 64
381 END IF
382 END IF
383 ELSE IF( SNAME .AND. C2.EQ.'ST' ) THEN
384 IF( C3.EQ.'EBZ' ) THEN
385 NB = 1
386 END IF
387 END IF
388 ILAENV = NB
389 RETURN
390 *
391 60 CONTINUE
392 *
393 * ISPEC = 2: minimum block size
394 *
395 NBMIN = 2
396 IF( C2.EQ.'GE' ) THEN
397 IF( C3.EQ.'QRF' .OR. C3.EQ.'RQF' .OR. C3.EQ.'LQF' .OR. C3.EQ.
398 $ 'QLF' ) THEN
399 IF( SNAME ) THEN
400 NBMIN = 2
401 ELSE
402 NBMIN = 2
403 END IF
404 ELSE IF( C3.EQ.'HRD' ) THEN
405 IF( SNAME ) THEN
406 NBMIN = 2
407 ELSE
408 NBMIN = 2
409 END IF
410 ELSE IF( C3.EQ.'BRD' ) THEN
411 IF( SNAME ) THEN
412 NBMIN = 2
413 ELSE
414 NBMIN = 2
415 END IF
416 ELSE IF( C3.EQ.'TRI' ) THEN
417 IF( SNAME ) THEN
418 NBMIN = 2
419 ELSE
420 NBMIN = 2
421 END IF
422 END IF
423 ELSE IF( C2.EQ.'SY' ) THEN
424 IF( C3.EQ.'TRF' ) THEN
425 IF( SNAME ) THEN
426 NBMIN = 8
427 ELSE
428 NBMIN = 8
429 END IF
430 ELSE IF( SNAME .AND. C3.EQ.'TRD' ) THEN
431 NBMIN = 2
432 END IF
433 ELSE IF( CNAME .AND. C2.EQ.'HE' ) THEN
434 IF( C3.EQ.'TRD' ) THEN
435 NBMIN = 2
436 END IF
437 ELSE IF( SNAME .AND. C2.EQ.'OR' ) THEN
438 IF( C3( 1: 1 ).EQ.'G' ) THEN
439 IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ.
440 $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' )
441 $ THEN
442 NBMIN = 2
443 END IF
444 ELSE IF( C3( 1: 1 ).EQ.'M' ) THEN
445 IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ.
446 $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' )
447 $ THEN
448 NBMIN = 2
449 END IF
450 END IF
451 ELSE IF( CNAME .AND. C2.EQ.'UN' ) THEN
452 IF( C3( 1: 1 ).EQ.'G' ) THEN
453 IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ.
454 $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' )
455 $ THEN
456 NBMIN = 2
457 END IF
458 ELSE IF( C3( 1: 1 ).EQ.'M' ) THEN
459 IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ.
460 $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' )
461 $ THEN
462 NBMIN = 2
463 END IF
464 END IF
465 END IF
466 ILAENV = NBMIN
467 RETURN
468 *
469 70 CONTINUE
470 *
471 * ISPEC = 3: crossover point
472 *
473 NX = 0
474 IF( C2.EQ.'GE' ) THEN
475 IF( C3.EQ.'QRF' .OR. C3.EQ.'RQF' .OR. C3.EQ.'LQF' .OR. C3.EQ.
476 $ 'QLF' ) THEN
477 IF( SNAME ) THEN
478 NX = 128
479 ELSE
480 NX = 128
481 END IF
482 ELSE IF( C3.EQ.'HRD' ) THEN
483 IF( SNAME ) THEN
484 NX = 128
485 ELSE
486 NX = 128
487 END IF
488 ELSE IF( C3.EQ.'BRD' ) THEN
489 IF( SNAME ) THEN
490 NX = 128
491 ELSE
492 NX = 128
493 END IF
494 END IF
495 ELSE IF( C2.EQ.'SY' ) THEN
496 IF( SNAME .AND. C3.EQ.'TRD' ) THEN
497 NX = 32
498 END IF
499 ELSE IF( CNAME .AND. C2.EQ.'HE' ) THEN
500 IF( C3.EQ.'TRD' ) THEN
501 NX = 32
502 END IF
503 ELSE IF( SNAME .AND. C2.EQ.'OR' ) THEN
504 IF( C3( 1: 1 ).EQ.'G' ) THEN
505 IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ.
506 $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' )
507 $ THEN
508 NX = 128
509 END IF
510 END IF
511 ELSE IF( CNAME .AND. C2.EQ.'UN' ) THEN
512 IF( C3( 1: 1 ).EQ.'G' ) THEN
513 IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ.
514 $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' )
515 $ THEN
516 NX = 128
517 END IF
518 END IF
519 END IF
520 ILAENV = NX
521 RETURN
522 *
523 80 CONTINUE
524 *
525 * ISPEC = 4: number of shifts (used by xHSEQR)
526 *
527 ILAENV = 6
528 RETURN
529 *
530 90 CONTINUE
531 *
532 * ISPEC = 5: minimum column dimension (not used)
533 *
534 ILAENV = 2
535 RETURN
536 *
537 100 CONTINUE
538 *
539 * ISPEC = 6: crossover point for SVD (used by xGELSS and xGESVD)
540 *
541 ILAENV = INT( REAL( MIN( N1, N2 ) )*1.6E0 )
542 RETURN
543 *
544 110 CONTINUE
545 *
546 * ISPEC = 7: number of processors (not used)
547 *
548 ILAENV = 1
549 RETURN
550 *
551 120 CONTINUE
552 *
553 * ISPEC = 8: crossover point for multishift (used by xHSEQR)
554 *
555 ILAENV = 50
556 RETURN
557 *
558 130 CONTINUE
559 *
560 * ISPEC = 9: maximum size of the subproblems at the bottom of the
561 * computation tree in the divide-and-conquer algorithm
562 * (used by xGELSD and xGESDD)
563 *
564 ILAENV = 25
565 RETURN
566 *
567 140 CONTINUE
568 *
569 * ISPEC = 10: ieee NaN arithmetic can be trusted not to trap
570 *
571 * ILAENV = 0
572 ILAENV = 1
573 IF( ILAENV.EQ.1 ) THEN
574 ILAENV = IEEECK( 1, 0.0, 1.0 )
575 END IF
576 RETURN
577 *
578 150 CONTINUE
579 *
580 * ISPEC = 11: infinity arithmetic can be trusted not to trap
581 *
582 * ILAENV = 0
583 ILAENV = 1
584 IF( ILAENV.EQ.1 ) THEN
585 ILAENV = IEEECK( 0, 0.0, 1.0 )
586 END IF
587 RETURN
588 *
589 160 CONTINUE
590 *
591 * 12 <= ISPEC <= 16: xHSEQR or one of its subroutines.
592 *
593 ILAENV = IPARMQ( ISPEC, NAME, OPTS, N1, N2, N3, N4 )
594 RETURN
595 *
596 * End of ILAENV
597 *
598 END
599 C
600 C-----------------------------------------------------------------------
601 C-----------------------------------------------------------------------
602 DOUBLE PRECISION FUNCTION DLAMCH( CMACH )
603 *
604 * -- LAPACK auxiliary routine (version 3.2) --
605 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
606 * November 2006
607 * NOTE (Bart Oldeman): routine changed to use Fortran90 intrinsics
608 *
609 IMPLICIT NONE
610 * .. Scalar Arguments ..
611 CHARACTER CMACH
612 * ..
613 *
614 * Purpose
615 * =======
616 *
617 * DLAMCH determines double precision machine parameters.
618 *
619 * Arguments
620 * =========
621 *
622 * CMACH (input) CHARACTER*1
623 * Specifies the value to be returned by DLAMCH:
624 * = 'E' or 'e', DLAMCH := eps
625 * = 'S' or 's , DLAMCH := sfmin
626 * = 'B' or 'b', DLAMCH := base
627 * = 'P' or 'p', DLAMCH := eps*base
628 * = 'N' or 'n', DLAMCH := t
629 * = 'R' or 'r', DLAMCH := rnd
630 * = 'M' or 'm', DLAMCH := emin
631 * = 'U' or 'u', DLAMCH := rmin
632 * = 'L' or 'l', DLAMCH := emax
633 * = 'O' or 'o', DLAMCH := rmax
634 *
635 * where
636 *
637 * eps = relative machine precision
638 * sfmin = safe minimum, such that 1/sfmin does not overflow
639 * base = base of the machine
640 * prec = eps*base
641 * t = number of (base) digits in the mantissa
642 * rnd = 1.0 when rounding occurs in addition, 0.0 otherwise
643 * emin = minimum exponent before (gradual) underflow
644 * rmin = underflow threshold - base**(emin-1)
645 * emax = largest exponent before overflow
646 * rmax = overflow threshold - (base**emax)*(1-eps)
647 *
648 * =====================================================================
649 *
650 * .. Parameters ..
651 DOUBLE PRECISION ONE, ZERO
652 PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
653 * ..
654 * .. Local Scalars ..
655 LOGICAL FIRST
656 DOUBLE PRECISION EPS, EPS2, PREC, RMACH, RND, SFMIN, SMALL, RMAX
657 * ..
658 * .. External Functions ..
659 LOGICAL LSAME
660 EXTERNAL LSAME
661 * ..
662 * .. Save statement ..
663 SAVE FIRST, EPS, SFMIN, RND, PREC
664 * ..
665 * .. Data statements ..
666 DATA FIRST / .TRUE. /
667 * ..
668 * .. Executable Statements ..
669 *
670 IF( FIRST ) THEN
671 *
672 * Determine whether rounding or chopping occurs, by adding a
673 * bit less than epsilon/2 and a bit more than epsilon/2 to 1.
674 *
675 EPS2 = EPSILON(ONE) / 2
676 ! use FRACTION to avoid extended precision bits
677 IF( FRACTION( ONE + (EPS2 - EPS2 / 50) ).EQ.FRACTION(ONE) .AND.
678 $ FRACTION( ONE + (EPS2 + EPS2 / 50) ).NE.FRACTION(ONE)) THEN
679 RND = ONE
680 EPS = EPSILON(ONE) / 2
681 ELSE
682 RND = ZERO
683 EPS = EPSILON(ONE)
684 END IF
685 PREC = EPS*RADIX(ONE)
686 RMAX = HUGE(ONE)
687 SMALL = ONE / RMAX
688 IF( SMALL.GE.TINY(ONE) ) THEN
689 *
690 * Use SMALL plus a bit, to avoid the possibility of rounding
691 * causing overflow when computing 1/sfmin.
692 *
693 SFMIN = SMALL*( ONE+EPS )
694 ELSE
695 SFMIN = TINY(ONE)
696 END IF
697 END IF
698 *
699 IF( LSAME( CMACH, 'E' ) ) THEN
700 RMACH = EPS
701 ELSE IF( LSAME( CMACH, 'S' ) ) THEN
702 RMACH = SFMIN
703 ELSE IF( LSAME( CMACH, 'B' ) ) THEN
704 RMACH = RADIX(ONE)
705 ELSE IF( LSAME( CMACH, 'P' ) ) THEN
706 RMACH = PREC
707 ELSE IF( LSAME( CMACH, 'N' ) ) THEN
708 RMACH = DIGITS(ONE)
709 ELSE IF( LSAME( CMACH, 'R' ) ) THEN
710 RMACH = RND
711 ELSE IF( LSAME( CMACH, 'M' ) ) THEN
712 RMACH = MINEXPONENT(ONE)
713 ELSE IF( LSAME( CMACH, 'U' ) ) THEN
714 RMACH = TINY(ONE)
715 ELSE IF( LSAME( CMACH, 'L' ) ) THEN
716 RMACH = MAXEXPONENT(ONE)
717 ELSE IF( LSAME( CMACH, 'O' ) ) THEN
718 RMACH = HUGE(ONE)
719 END IF
720 *
721 DLAMCH = RMACH
722 FIRST = .FALSE.
723 RETURN
724 *
725 * End of DLAMCH
726 *
727 END
728 C
729 C-----------------------------------------------------------------------
730 C-----------------------------------------------------------------------
731 SUBROUTINE DGEEV( JOBVL, JOBVR, N, A, LDA, WR, WI, VL, LDVL, VR,
732 $ LDVR, WORK, LWORK, INFO )
733 *
734 * -- LAPACK driver routine (version 3.2) --
735 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
736 * November 2006
737 *
738 * .. Scalar Arguments ..
739 CHARACTER JOBVL, JOBVR
740 INTEGER INFO, LDA, LDVL, LDVR, LWORK, N
741 * ..
742 * .. Array Arguments ..
743 DOUBLE PRECISION A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ),
744 $ WI( * ), WORK( * ), WR( * )
745 * ..
746 *
747 * Purpose
748 * =======
749 *
750 * DGEEV computes for an N-by-N real nonsymmetric matrix A, the
751 * eigenvalues and, optionally, the left and/or right eigenvectors.
752 *
753 * The right eigenvector v(j) of A satisfies
754 * A * v(j) = lambda(j) * v(j)
755 * where lambda(j) is its eigenvalue.
756 * The left eigenvector u(j) of A satisfies
757 * u(j)**H * A = lambda(j) * u(j)**H
758 * where u(j)**H denotes the conjugate transpose of u(j).
759 *
760 * The computed eigenvectors are normalized to have Euclidean norm
761 * equal to 1 and largest component real.
762 *
763 * Arguments
764 * =========
765 *
766 * JOBVL (input) CHARACTER*1
767 * = 'N': left eigenvectors of A are not computed;
768 * = 'V': left eigenvectors of A are computed.
769 *
770 * JOBVR (input) CHARACTER*1
771 * = 'N': right eigenvectors of A are not computed;
772 * = 'V': right eigenvectors of A are computed.
773 *
774 * N (input) INTEGER
775 * The order of the matrix A. N >= 0.
776 *
777 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
778 * On entry, the N-by-N matrix A.
779 * On exit, A has been overwritten.
780 *
781 * LDA (input) INTEGER
782 * The leading dimension of the array A. LDA >= max(1,N).
783 *
784 * WR (output) DOUBLE PRECISION array, dimension (N)
785 * WI (output) DOUBLE PRECISION array, dimension (N)
786 * WR and WI contain the real and imaginary parts,
787 * respectively, of the computed eigenvalues. Complex
788 * conjugate pairs of eigenvalues appear consecutively
789 * with the eigenvalue having the positive imaginary part
790 * first.
791 *
792 * VL (output) DOUBLE PRECISION array, dimension (LDVL,N)
793 * If JOBVL = 'V', the left eigenvectors u(j) are stored one
794 * after another in the columns of VL, in the same order
795 * as their eigenvalues.
796 * If JOBVL = 'N', VL is not referenced.
797 * If the j-th eigenvalue is real, then u(j) = VL(:,j),
798 * the j-th column of VL.
799 * If the j-th and (j+1)-st eigenvalues form a complex
800 * conjugate pair, then u(j) = VL(:,j) + i*VL(:,j+1) and
801 * u(j+1) = VL(:,j) - i*VL(:,j+1).
802 *
803 * LDVL (input) INTEGER
804 * The leading dimension of the array VL. LDVL >= 1; if
805 * JOBVL = 'V', LDVL >= N.
806 *
807 * VR (output) DOUBLE PRECISION array, dimension (LDVR,N)
808 * If JOBVR = 'V', the right eigenvectors v(j) are stored one
809 * after another in the columns of VR, in the same order
810 * as their eigenvalues.
811 * If JOBVR = 'N', VR is not referenced.
812 * If the j-th eigenvalue is real, then v(j) = VR(:,j),
813 * the j-th column of VR.
814 * If the j-th and (j+1)-st eigenvalues form a complex
815 * conjugate pair, then v(j) = VR(:,j) + i*VR(:,j+1) and
816 * v(j+1) = VR(:,j) - i*VR(:,j+1).
817 *
818 * LDVR (input) INTEGER
819 * The leading dimension of the array VR. LDVR >= 1; if
820 * JOBVR = 'V', LDVR >= N.
821 *
822 * WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
823 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
824 *
825 * LWORK (input) INTEGER
826 * The dimension of the array WORK. LWORK >= max(1,3*N), and
827 * if JOBVL = 'V' or JOBVR = 'V', LWORK >= 4*N. For good
828 * performance, LWORK must generally be larger.
829 *
830 * If LWORK = -1, then a workspace query is assumed; the routine
831 * only calculates the optimal size of the WORK array, returns
832 * this value as the first entry of the WORK array, and no error
833 * message related to LWORK is issued by XERBLA.
834 *
835 * INFO (output) INTEGER
836 * = 0: successful exit
837 * < 0: if INFO = -i, the i-th argument had an illegal value.
838 * > 0: if INFO = i, the QR algorithm failed to compute all the
839 * eigenvalues, and no eigenvectors have been computed;
840 * elements i+1:N of WR and WI contain eigenvalues which
841 * have converged.
842 *
843 * =====================================================================
844 *
845 * .. Parameters ..
846 DOUBLE PRECISION ZERO, ONE
847 PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
848 * ..
849 * .. Local Scalars ..
850 LOGICAL LQUERY, SCALEA, WANTVL, WANTVR
851 CHARACTER SIDE
852 INTEGER HSWORK, I, IBAL, IERR, IHI, ILO, ITAU, IWRK, K,
853 $ MAXWRK, MINWRK, NOUT
854 DOUBLE PRECISION ANRM, BIGNUM, CS, CSCALE, EPS, R, SCL, SMLNUM,
855 $ SN
856 * ..
857 * .. Local Arrays ..
858 LOGICAL SELECT( 1 )
859 DOUBLE PRECISION DUM( 1 )
860 * ..
861 * .. External Subroutines ..
862 EXTERNAL DGEBAK, DGEBAL, DGEHRD, DHSEQR, DLABAD, DLACPY,
863 $ DLARTG, DLASCL, DORGHR, DROT, DSCAL, DTREVC,
864 $ XERBLA
865 * ..
866 * .. External Functions ..
867 LOGICAL LSAME
868 INTEGER IDAMAX, ILAENV
869 DOUBLE PRECISION DLAMCH, DLANGE, DLAPY2, DNRM2
870 EXTERNAL LSAME, IDAMAX, ILAENV, DLAMCH, DLANGE, DLAPY2,
871 $ DNRM2
872 * ..
873 * .. Intrinsic Functions ..
874 INTRINSIC MAX, SQRT
875 * ..
876 * .. Executable Statements ..
877 *
878 * Test the input arguments
879 *
880 INFO = 0
881 LQUERY = ( LWORK.EQ.-1 )
882 WANTVL = LSAME( JOBVL, 'V' )
883 WANTVR = LSAME( JOBVR, 'V' )
884 IF( ( .NOT.WANTVL ) .AND. ( .NOT.LSAME( JOBVL, 'N' ) ) ) THEN
885 INFO = -1
886 ELSE IF( ( .NOT.WANTVR ) .AND. ( .NOT.LSAME( JOBVR, 'N' ) ) ) THEN
887 INFO = -2
888 ELSE IF( N.LT.0 ) THEN
889 INFO = -3
890 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
891 INFO = -5
892 ELSE IF( LDVL.LT.1 .OR. ( WANTVL .AND. LDVL.LT.N ) ) THEN
893 INFO = -9
894 ELSE IF( LDVR.LT.1 .OR. ( WANTVR .AND. LDVR.LT.N ) ) THEN
895 INFO = -11
896 END IF
897 *
898 * Compute workspace
899 * (Note: Comments in the code beginning "Workspace:" describe the
900 * minimal amount of workspace needed at that point in the code,
901 * as well as the preferred amount for good performance.
902 * NB refers to the optimal block size for the immediately
903 * following subroutine, as returned by ILAENV.
904 * HSWORK refers to the workspace preferred by DHSEQR, as
905 * calculated below. HSWORK is computed assuming ILO=1 and IHI=N,
906 * the worst case.)
907 *
908 IF( INFO.EQ.0 ) THEN
909 IF( N.EQ.0 ) THEN
910 MINWRK = 1
911 MAXWRK = 1
912 ELSE
913 MAXWRK = 2*N + N*ILAENV( 1, 'DGEHRD', ' ', N, 1, N, 0 )
914 IF( WANTVL ) THEN
915 MINWRK = 4*N
916 MAXWRK = MAX( MAXWRK, 2*N + ( N - 1 )*ILAENV( 1,
917 $ 'DORGHR', ' ', N, 1, N, -1 ) )
918 CALL DHSEQR( 'S', 'V', N, 1, N, A, LDA, WR, WI, VL, LDVL,
919 $ WORK, -1, INFO )
920 HSWORK = WORK( 1 )
921 MAXWRK = MAX( MAXWRK, N + 1, N + HSWORK )
922 MAXWRK = MAX( MAXWRK, 4*N )
923 ELSE IF( WANTVR ) THEN
924 MINWRK = 4*N
925 MAXWRK = MAX( MAXWRK, 2*N + ( N - 1 )*ILAENV( 1,
926 $ 'DORGHR', ' ', N, 1, N, -1 ) )
927 CALL DHSEQR( 'S', 'V', N, 1, N, A, LDA, WR, WI, VR, LDVR,
928 $ WORK, -1, INFO )
929 HSWORK = WORK( 1 )
930 MAXWRK = MAX( MAXWRK, N + 1, N + HSWORK )
931 MAXWRK = MAX( MAXWRK, 4*N )
932 ELSE
933 MINWRK = 3*N
934 CALL DHSEQR( 'E', 'N', N, 1, N, A, LDA, WR, WI, VR, LDVR,
935 $ WORK, -1, INFO )
936 HSWORK = WORK( 1 )
937 MAXWRK = MAX( MAXWRK, N + 1, N + HSWORK )
938 END IF
939 MAXWRK = MAX( MAXWRK, MINWRK )
940 END IF
941 WORK( 1 ) = MAXWRK
942 *
943 IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN
944 INFO = -13
945 END IF
946 END IF
947 *
948 IF( INFO.NE.0 ) THEN
949 CALL XERBLA( 'DGEEV ', -INFO )
950 RETURN
951 ELSE IF( LQUERY ) THEN
952 RETURN
953 END IF
954 *
955 * Quick return if possible
956 *
957 IF( N.EQ.0 )
958 $ RETURN
959 *
960 * Get machine constants
961 *
962 EPS = DLAMCH( 'P' )
963 SMLNUM = DLAMCH( 'S' )
964 BIGNUM = ONE / SMLNUM
965 CALL DLABAD( SMLNUM, BIGNUM )
966 SMLNUM = SQRT( SMLNUM ) / EPS
967 BIGNUM = ONE / SMLNUM
968 *
969 * Scale A if max element outside range [SMLNUM,BIGNUM]
970 *
971 ANRM = DLANGE( 'M', N, N, A, LDA, DUM )
972 SCALEA = .FALSE.
973 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
974 SCALEA = .TRUE.
975 CSCALE = SMLNUM
976 ELSE IF( ANRM.GT.BIGNUM ) THEN
977 SCALEA = .TRUE.
978 CSCALE = BIGNUM
979 END IF
980 IF( SCALEA )
981 $ CALL DLASCL( 'G', 0, 0, ANRM, CSCALE, N, N, A, LDA, IERR )
982 *
983 * Balance the matrix
984 * (Workspace: need N)
985 *
986 IBAL = 1
987 CALL DGEBAL( 'B', N, A, LDA, ILO, IHI, WORK( IBAL ), IERR )
988 *
989 * Reduce to upper Hessenberg form
990 * (Workspace: need 3*N, prefer 2*N+N*NB)
991 *
992 ITAU = IBAL + N
993 IWRK = ITAU + N
994 CALL DGEHRD( N, ILO, IHI, A, LDA, WORK( ITAU ), WORK( IWRK ),
995 $ LWORK-IWRK+1, IERR )
996 *
997 IF( WANTVL ) THEN
998 *
999 * Want left eigenvectors
1000 * Copy Householder vectors to VL
1001 *
1002 SIDE = 'L'
1003 CALL DLACPY( 'L', N, N, A, LDA, VL, LDVL )
1004 *
1005 * Generate orthogonal matrix in VL
1006 * (Workspace: need 3*N-1, prefer 2*N+(N-1)*NB)
1007 *
1008 CALL DORGHR( N, ILO, IHI, VL, LDVL, WORK( ITAU ), WORK( IWRK ),
1009 $ LWORK-IWRK+1, IERR )
1010 *
1011 * Perform QR iteration, accumulating Schur vectors in VL
1012 * (Workspace: need N+1, prefer N+HSWORK (see comments) )
1013 *
1014 IWRK = ITAU
1015 CALL DHSEQR( 'S', 'V', N, ILO, IHI, A, LDA, WR, WI, VL, LDVL,
1016 $ WORK( IWRK ), LWORK-IWRK+1, INFO )
1017 *
1018 IF( WANTVR ) THEN
1019 *
1020 * Want left and right eigenvectors
1021 * Copy Schur vectors to VR
1022 *
1023 SIDE = 'B'
1024 CALL DLACPY( 'F', N, N, VL, LDVL, VR, LDVR )
1025 END IF
1026 *
1027 ELSE IF( WANTVR ) THEN
1028 *
1029 * Want right eigenvectors
1030 * Copy Householder vectors to VR
1031 *
1032 SIDE = 'R'
1033 CALL DLACPY( 'L', N, N, A, LDA, VR, LDVR )
1034 *
1035 * Generate orthogonal matrix in VR
1036 * (Workspace: need 3*N-1, prefer 2*N+(N-1)*NB)
1037 *
1038 CALL DORGHR( N, ILO, IHI, VR, LDVR, WORK( ITAU ), WORK( IWRK ),
1039 $ LWORK-IWRK+1, IERR )
1040 *
1041 * Perform QR iteration, accumulating Schur vectors in VR
1042 * (Workspace: need N+1, prefer N+HSWORK (see comments) )
1043 *
1044 IWRK = ITAU
1045 CALL DHSEQR( 'S', 'V', N, ILO, IHI, A, LDA, WR, WI, VR, LDVR,
1046 $ WORK( IWRK ), LWORK-IWRK+1, INFO )
1047 *
1048 ELSE
1049 *
1050 * Compute eigenvalues only
1051 * (Workspace: need N+1, prefer N+HSWORK (see comments) )
1052 *
1053 IWRK = ITAU
1054 CALL DHSEQR( 'E', 'N', N, ILO, IHI, A, LDA, WR, WI, VR, LDVR,
1055 $ WORK( IWRK ), LWORK-IWRK+1, INFO )
1056 END IF
1057 *
1058 * If INFO > 0 from DHSEQR, then quit
1059 *
1060 IF( INFO.GT.0 )
1061 $ GO TO 50
1062 *
1063 IF( WANTVL .OR. WANTVR ) THEN
1064 *
1065 * Compute left and/or right eigenvectors
1066 * (Workspace: need 4*N)
1067 *
1068 CALL DTREVC( SIDE, 'B', SELECT, N, A, LDA, VL, LDVL, VR, LDVR,
1069 $ N, NOUT, WORK( IWRK ), IERR )
1070 END IF
1071 *
1072 IF( WANTVL ) THEN
1073 *
1074 * Undo balancing of left eigenvectors
1075 * (Workspace: need N)
1076 *
1077 CALL DGEBAK( 'B', 'L', N, ILO, IHI, WORK( IBAL ), N, VL, LDVL,
1078 $ IERR )
1079 *
1080 * Normalize left eigenvectors and make largest component real
1081 *
1082 DO 20 I = 1, N
1083 IF( WI( I ).EQ.ZERO ) THEN
1084 SCL = ONE / DNRM2( N, VL( 1, I ), 1 )
1085 CALL DSCAL( N, SCL, VL( 1, I ), 1 )
1086 ELSE IF( WI( I ).GT.ZERO ) THEN
1087 SCL = ONE / DLAPY2( DNRM2( N, VL( 1, I ), 1 ),
1088 $ DNRM2( N, VL( 1, I+1 ), 1 ) )
1089 CALL DSCAL( N, SCL, VL( 1, I ), 1 )
1090 CALL DSCAL( N, SCL, VL( 1, I+1 ), 1 )
1091 DO 10 K = 1, N
1092 WORK( IWRK+K-1 ) = VL( K, I )**2 + VL( K, I+1 )**2
1093 10 CONTINUE
1094 K = IDAMAX( N, WORK( IWRK ), 1 )
1095 CALL DLARTG( VL( K, I ), VL( K, I+1 ), CS, SN, R )
1096 CALL DROT( N, VL( 1, I ), 1, VL( 1, I+1 ), 1, CS, SN )
1097 VL( K, I+1 ) = ZERO
1098 END IF
1099 20 CONTINUE
1100 END IF
1101 *
1102 IF( WANTVR ) THEN
1103 *
1104 * Undo balancing of right eigenvectors
1105 * (Workspace: need N)
1106 *
1107 CALL DGEBAK( 'B', 'R', N, ILO, IHI, WORK( IBAL ), N, VR, LDVR,
1108 $ IERR )
1109 *
1110 * Normalize right eigenvectors and make largest component real
1111 *
1112 DO 40 I = 1, N
1113 IF( WI( I ).EQ.ZERO ) THEN
1114 SCL = ONE / DNRM2( N, VR( 1, I ), 1 )
1115 CALL DSCAL( N, SCL, VR( 1, I ), 1 )
1116 ELSE IF( WI( I ).GT.ZERO ) THEN
1117 SCL = ONE / DLAPY2( DNRM2( N, VR( 1, I ), 1 ),
1118 $ DNRM2( N, VR( 1, I+1 ), 1 ) )
1119 CALL DSCAL( N, SCL, VR( 1, I ), 1 )
1120 CALL DSCAL( N, SCL, VR( 1, I+1 ), 1 )
1121 DO 30 K = 1, N
1122 WORK( IWRK+K-1 ) = VR( K, I )**2 + VR( K, I+1 )**2
1123 30 CONTINUE
1124 K = IDAMAX( N, WORK( IWRK ), 1 )
1125 CALL DLARTG( VR( K, I ), VR( K, I+1 ), CS, SN, R )
1126 CALL DROT( N, VR( 1, I ), 1, VR( 1, I+1 ), 1, CS, SN )
1127 VR( K, I+1 ) = ZERO
1128 END IF
1129 40 CONTINUE
1130 END IF
1131 *
1132 * Undo scaling if necessary
1133 *
1134 50 CONTINUE
1135 IF( SCALEA ) THEN
1136 CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, N-INFO, 1, WR( INFO+1 ),
1137 $ MAX( N-INFO, 1 ), IERR )
1138 CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, N-INFO, 1, WI( INFO+1 ),
1139 $ MAX( N-INFO, 1 ), IERR )
1140 IF( INFO.GT.0 ) THEN
1141 CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, ILO-1, 1, WR, N,
1142 $ IERR )
1143 CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, ILO-1, 1, WI, N,
1144 $ IERR )
1145 END IF
1146 END IF
1147 *
1148 WORK( 1 ) = MAXWRK
1149 RETURN
1150 *
1151 * End of DGEEV
1152 *
1153 END
1154 C
1155 C-----------------------------------------------------------------------
1156 C-----------------------------------------------------------------------
1157 SUBROUTINE DGGEV( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR, ALPHAI,
1158 $ BETA, VL, LDVL, VR, LDVR, WORK, LWORK, INFO )
1159 *
1160 * -- LAPACK driver routine (version 3.2) --
1161 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
1162 * November 2006
1163 *
1164 * .. Scalar Arguments ..
1165 CHARACTER JOBVL, JOBVR
1166 INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N
1167 * ..
1168 * .. Array Arguments ..
1169 DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
1170 $ B( LDB, * ), BETA( * ), VL( LDVL, * ),
1171 $ VR( LDVR, * ), WORK( * )
1172 * ..
1173 *
1174 * Purpose
1175 * =======
1176 *
1177 * DGGEV computes for a pair of N-by-N real nonsymmetric matrices (A,B)
1178 * the generalized eigenvalues, and optionally, the left and/or right
1179 * generalized eigenvectors.
1180 *
1181 * A generalized eigenvalue for a pair of matrices (A,B) is a scalar
1182 * lambda or a ratio alpha/beta = lambda, such that A - lambda*B is
1183 * singular. It is usually represented as the pair (alpha,beta), as
1184 * there is a reasonable interpretation for beta=0, and even for both
1185 * being zero.
1186 *
1187 * The right eigenvector v(j) corresponding to the eigenvalue lambda(j)
1188 * of (A,B) satisfies
1189 *
1190 * A * v(j) = lambda(j) * B * v(j).
1191 *
1192 * The left eigenvector u(j) corresponding to the eigenvalue lambda(j)
1193 * of (A,B) satisfies
1194 *
1195 * u(j)**H * A = lambda(j) * u(j)**H * B .
1196 *
1197 * where u(j)**H is the conjugate-transpose of u(j).
1198 *
1199 *
1200 * Arguments
1201 * =========
1202 *
1203 * JOBVL (input) CHARACTER*1
1204 * = 'N': do not compute the left generalized eigenvectors;
1205 * = 'V': compute the left generalized eigenvectors.
1206 *
1207 * JOBVR (input) CHARACTER*1
1208 * = 'N': do not compute the right generalized eigenvectors;
1209 * = 'V': compute the right generalized eigenvectors.
1210 *
1211 * N (input) INTEGER
1212 * The order of the matrices A, B, VL, and VR. N >= 0.
1213 *
1214 * A (input/output) DOUBLE PRECISION array, dimension (LDA, N)
1215 * On entry, the matrix A in the pair (A,B).
1216 * On exit, A has been overwritten.
1217 *
1218 * LDA (input) INTEGER
1219 * The leading dimension of A. LDA >= max(1,N).
1220 *
1221 * B (input/output) DOUBLE PRECISION array, dimension (LDB, N)
1222 * On entry, the matrix B in the pair (A,B).
1223 * On exit, B has been overwritten.
1224 *
1225 * LDB (input) INTEGER
1226 * The leading dimension of B. LDB >= max(1,N).
1227 *
1228 * ALPHAR (output) DOUBLE PRECISION array, dimension (N)
1229 * ALPHAI (output) DOUBLE PRECISION array, dimension (N)
1230 * BETA (output) DOUBLE PRECISION array, dimension (N)
1231 * On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will
1232 * be the generalized eigenvalues. If ALPHAI(j) is zero, then
1233 * the j-th eigenvalue is real; if positive, then the j-th and
1234 * (j+1)-st eigenvalues are a complex conjugate pair, with
1235 * ALPHAI(j+1) negative.
1236 *
1237 * Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j)
1238 * may easily over- or underflow, and BETA(j) may even be zero.
1239 * Thus, the user should avoid naively computing the ratio
1240 * alpha/beta. However, ALPHAR and ALPHAI will be always less
1241 * than and usually comparable with norm(A) in magnitude, and
1242 * BETA always less than and usually comparable with norm(B).
1243 *
1244 * VL (output) DOUBLE PRECISION array, dimension (LDVL,N)
1245 * If JOBVL = 'V', the left eigenvectors u(j) are stored one
1246 * after another in the columns of VL, in the same order as
1247 * their eigenvalues. If the j-th eigenvalue is real, then
1248 * u(j) = VL(:,j), the j-th column of VL. If the j-th and
1249 * (j+1)-th eigenvalues form a complex conjugate pair, then
1250 * u(j) = VL(:,j)+i*VL(:,j+1) and u(j+1) = VL(:,j)-i*VL(:,j+1).
1251 * Each eigenvector is scaled so the largest component has
1252 * abs(real part)+abs(imag. part)=1.
1253 * Not referenced if JOBVL = 'N'.
1254 *
1255 * LDVL (input) INTEGER
1256 * The leading dimension of the matrix VL. LDVL >= 1, and
1257 * if JOBVL = 'V', LDVL >= N.
1258 *
1259 * VR (output) DOUBLE PRECISION array, dimension (LDVR,N)
1260 * If JOBVR = 'V', the right eigenvectors v(j) are stored one
1261 * after another in the columns of VR, in the same order as
1262 * their eigenvalues. If the j-th eigenvalue is real, then
1263 * v(j) = VR(:,j), the j-th column of VR. If the j-th and
1264 * (j+1)-th eigenvalues form a complex conjugate pair, then
1265 * v(j) = VR(:,j)+i*VR(:,j+1) and v(j+1) = VR(:,j)-i*VR(:,j+1).
1266 * Each eigenvector is scaled so the largest component has
1267 * abs(real part)+abs(imag. part)=1.
1268 * Not referenced if JOBVR = 'N'.
1269 *
1270 * LDVR (input) INTEGER
1271 * The leading dimension of the matrix VR. LDVR >= 1, and
1272 * if JOBVR = 'V', LDVR >= N.
1273 *
1274 * WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
1275 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
1276 *
1277 * LWORK (input) INTEGER
1278 * The dimension of the array WORK. LWORK >= max(1,8*N).
1279 * For good performance, LWORK must generally be larger.
1280 *
1281 * If LWORK = -1, then a workspace query is assumed; the routine
1282 * only calculates the optimal size of the WORK array, returns
1283 * this value as the first entry of the WORK array, and no error
1284 * message related to LWORK is issued by XERBLA.
1285 *
1286 * INFO (output) INTEGER
1287 * = 0: successful exit
1288 * < 0: if INFO = -i, the i-th argument had an illegal value.
1289 * = 1,...,N:
1290 * The QZ iteration failed. No eigenvectors have been
1291 * calculated, but ALPHAR(j), ALPHAI(j), and BETA(j)
1292 * should be correct for j=INFO+1,...,N.
1293 * > N: =N+1: other than QZ iteration failed in DHGEQZ.
1294 * =N+2: error return from DTGEVC.
1295 *
1296 * =====================================================================
1297 *
1298 * .. Parameters ..
1299 DOUBLE PRECISION ZERO, ONE
1300 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
1301 * ..
1302 * .. Local Scalars ..
1303 LOGICAL ILASCL, ILBSCL, ILV, ILVL, ILVR, LQUERY
1304 CHARACTER CHTEMP
1305 INTEGER ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT, ILO,
1306 $ IN, IRIGHT, IROWS, ITAU, IWRK, JC, JR, MAXWRK,
1307 $ MINWRK
1308 DOUBLE PRECISION ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
1309 $ SMLNUM, TEMP
1310 * ..
1311 * .. Local Arrays ..
1312 LOGICAL LDUMMA( 1 )
1313 * ..
1314 * .. External Subroutines ..
1315 EXTERNAL DGEQRF, DGGBAK, DGGBAL, DGGHRD, DHGEQZ, DLABAD,
1316 $ DLACPY,DLASCL, DLASET, DORGQR, DORMQR, DTGEVC,
1317 $ XERBLA
1318 * ..
1319 * .. External Functions ..
1320 LOGICAL LSAME
1321 INTEGER ILAENV
1322 DOUBLE PRECISION DLAMCH, DLANGE
1323 EXTERNAL LSAME, ILAENV, DLAMCH, DLANGE
1324 * ..
1325 * .. Intrinsic Functions ..
1326 INTRINSIC ABS, MAX, SQRT
1327 * ..
1328 * .. Executable Statements ..
1329 *
1330 * Decode the input arguments
1331 *
1332 IF( LSAME( JOBVL, 'N' ) ) THEN
1333 IJOBVL = 1
1334 ILVL = .FALSE.
1335 ELSE IF( LSAME( JOBVL, 'V' ) ) THEN
1336 IJOBVL = 2
1337 ILVL = .TRUE.
1338 ELSE
1339 IJOBVL = -1
1340 ILVL = .FALSE.
1341 END IF
1342 *
1343 IF( LSAME( JOBVR, 'N' ) ) THEN
1344 IJOBVR = 1
1345 ILVR = .FALSE.
1346 ELSE IF( LSAME( JOBVR, 'V' ) ) THEN
1347 IJOBVR = 2
1348 ILVR = .TRUE.
1349 ELSE
1350 IJOBVR = -1
1351 ILVR = .FALSE.
1352 END IF
1353 ILV = ILVL .OR. ILVR
1354 *
1355 * Test the input arguments
1356 *
1357 INFO = 0
1358 LQUERY = ( LWORK.EQ.-1 )
1359 IF( IJOBVL.LE.0 ) THEN
1360 INFO = -1
1361 ELSE IF( IJOBVR.LE.0 ) THEN
1362 INFO = -2
1363 ELSE IF( N.LT.0 ) THEN
1364 INFO = -3
1365 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
1366 INFO = -5
1367 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
1368 INFO = -7
1369 ELSE IF( LDVL.LT.1 .OR. ( ILVL .AND. LDVL.LT.N ) ) THEN
1370 INFO = -12
1371 ELSE IF( LDVR.LT.1 .OR. ( ILVR .AND. LDVR.LT.N ) ) THEN
1372 INFO = -14
1373 END IF
1374 *
1375 * Compute workspace
1376 * (Note: Comments in the code beginning "Workspace:" describe the
1377 * minimal amount of workspace needed at that point in the code,
1378 * as well as the preferred amount for good performance.
1379 * NB refers to the optimal block size for the immediately
1380 * following subroutine, as returned by ILAENV. The workspace is
1381 * computed assuming ILO = 1 and IHI = N, the worst case.)
1382 *
1383 IF( INFO.EQ.0 ) THEN
1384 MINWRK = MAX( 1, 8*N )
1385 MAXWRK = MAX( 1, N*( 7 +
1386 $ ILAENV( 1, 'DGEQRF', ' ', N, 1, N, 0 ) ) )
1387 MAXWRK = MAX( MAXWRK, N*( 7 +
1388 $ ILAENV( 1, 'DORMQR', ' ', N, 1, N, 0 ) ) )
1389 IF( ILVL ) THEN
1390 MAXWRK = MAX( MAXWRK, N*( 7 +
1391 $ ILAENV( 1, 'DORGQR', ' ', N, 1, N, -1 ) ) )
1392 END IF
1393 WORK( 1 ) = MAXWRK
1394 *
1395 IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY )
1396 $ INFO = -16
1397 END IF
1398 *
1399 IF( INFO.NE.0 ) THEN
1400 CALL XERBLA( 'DGGEV ', -INFO )
1401 RETURN
1402 ELSE IF( LQUERY ) THEN
1403 RETURN
1404 END IF
1405 *
1406 * Quick return if possible
1407 *
1408 IF( N.EQ.0 )
1409 $ RETURN
1410 *
1411 * Get machine constants
1412 *
1413 EPS = DLAMCH( 'P' )
1414 SMLNUM = DLAMCH( 'S' )
1415 BIGNUM = ONE / SMLNUM
1416 CALL DLABAD( SMLNUM, BIGNUM )
1417 SMLNUM = SQRT( SMLNUM ) / EPS
1418 BIGNUM = ONE / SMLNUM
1419 *
1420 * Scale A if max element outside range [SMLNUM,BIGNUM]
1421 *
1422 ANRM = DLANGE( 'M', N, N, A, LDA, WORK )
1423 ILASCL = .FALSE.
1424 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
1425 ANRMTO = SMLNUM
1426 ILASCL = .TRUE.
1427 ELSE IF( ANRM.GT.BIGNUM ) THEN
1428 ANRMTO = BIGNUM
1429 ILASCL = .TRUE.
1430 END IF
1431 IF( ILASCL )
1432 $ CALL DLASCL( 'G', 0, 0, ANRM, ANRMTO, N, N, A, LDA, IERR )
1433 *
1434 * Scale B if max element outside range [SMLNUM,BIGNUM]
1435 *
1436 BNRM = DLANGE( 'M', N, N, B, LDB, WORK )
1437 ILBSCL = .FALSE.
1438 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
1439 BNRMTO = SMLNUM
1440 ILBSCL = .TRUE.
1441 ELSE IF( BNRM.GT.BIGNUM ) THEN
1442 BNRMTO = BIGNUM
1443 ILBSCL = .TRUE.
1444 END IF
1445 IF( ILBSCL )
1446 $ CALL DLASCL( 'G', 0, 0, BNRM, BNRMTO, N, N, B, LDB, IERR )
1447 *
1448 * Permute the matrices A, B to isolate eigenvalues if possible
1449 * (Workspace: need 6*N)
1450 *
1451 ILEFT = 1
1452 IRIGHT = N + 1
1453 IWRK = IRIGHT + N
1454 CALL DGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, WORK( ILEFT ),
1455 $ WORK( IRIGHT ), WORK( IWRK ), IERR )
1456 *
1457 * Reduce B to triangular form (QR decomposition of B)
1458 * (Workspace: need N, prefer N*NB)
1459 *
1460 IROWS = IHI + 1 - ILO
1461 IF( ILV ) THEN
1462 ICOLS = N + 1 - ILO
1463 ELSE
1464 ICOLS = IROWS
1465 END IF
1466 ITAU = IWRK
1467 IWRK = ITAU + IROWS
1468 CALL DGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
1469 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
1470 *
1471 * Apply the orthogonal transformation to matrix A
1472 * (Workspace: need N, prefer N*NB)
1473 *
1474 CALL DORMQR( 'L', 'T', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
1475 $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWRK ),
1476 $ LWORK+1-IWRK, IERR )
1477 *
1478 * Initialize VL
1479 * (Workspace: need N, prefer N*NB)
1480 *
1481 IF( ILVL ) THEN
1482 CALL DLASET( 'Full', N, N, ZERO, ONE, VL, LDVL )
1483 IF( IROWS.GT.1 ) THEN
1484 CALL DLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
1485 $ VL( ILO+1, ILO ), LDVL )
1486 END IF
1487 CALL DORGQR( IROWS, IROWS, IROWS, VL( ILO, ILO ), LDVL,
1488 $ WORK( ITAU ), WORK( IWRK ), LWORK+1-IWRK, IERR )
1489 END IF
1490 *
1491 * Initialize VR
1492 *
1493 IF( ILVR )
1494 $ CALL DLASET( 'Full', N, N, ZERO, ONE, VR, LDVR )
1495 *
1496 * Reduce to generalized Hessenberg form
1497 * (Workspace: none needed)
1498 *
1499 IF( ILV ) THEN
1500 *
1501 * Eigenvectors requested -- work on whole matrix.
1502 *
1503 CALL DGGHRD( JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, VL,
1504 $ LDVL, VR, LDVR, IERR )
1505 ELSE
1506 CALL DGGHRD( 'N', 'N', IROWS, 1, IROWS, A( ILO, ILO ), LDA,
1507 $ B( ILO, ILO ), LDB, VL, LDVL, VR, LDVR, IERR )
1508 END IF
1509 *
1510 * Perform QZ algorithm (Compute eigenvalues, and optionally, the
1511 * Schur forms and Schur vectors)
1512 * (Workspace: need N)
1513 *
1514 IWRK = ITAU
1515 IF( ILV ) THEN
1516 CHTEMP = 'S'
1517 ELSE
1518 CHTEMP = 'E'
1519 END IF
1520 CALL DHGEQZ( CHTEMP, JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB,
1521 $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR,
1522 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
1523 IF( IERR.NE.0 ) THEN
1524 IF( IERR.GT.0 .AND. IERR.LE.N ) THEN
1525 INFO = IERR
1526 ELSE IF( IERR.GT.N .AND. IERR.LE.2*N ) THEN
1527 INFO = IERR - N
1528 ELSE
1529 INFO = N + 1
1530 END IF
1531 GO TO 110
1532 END IF
1533 *
1534 * Compute Eigenvectors
1535 * (Workspace: need 6*N)
1536 *
1537 IF( ILV ) THEN
1538 IF( ILVL ) THEN
1539 IF( ILVR ) THEN
1540 CHTEMP = 'B'
1541 ELSE
1542 CHTEMP = 'L'
1543 END IF
1544 ELSE
1545 CHTEMP = 'R'
1546 END IF
1547 CALL DTGEVC( CHTEMP, 'B', LDUMMA, N, A, LDA, B, LDB, VL, LDVL,
1548 $ VR, LDVR, N, IN, WORK( IWRK ), IERR )
1549 IF( IERR.NE.0 ) THEN
1550 INFO = N + 2
1551 GO TO 110
1552 END IF
1553 *
1554 * Undo balancing on VL and VR and normalization
1555 * (Workspace: none needed)
1556 *
1557 IF( ILVL ) THEN
1558 CALL DGGBAK( 'P', 'L', N, ILO, IHI, WORK( ILEFT ),
1559 $ WORK( IRIGHT ), N, VL, LDVL, IERR )
1560 DO 50 JC = 1, N
1561 IF( ALPHAI( JC ).LT.ZERO )
1562 $ GO TO 50
1563 TEMP = ZERO
1564 IF( ALPHAI( JC ).EQ.ZERO ) THEN
1565 DO 10 JR = 1, N
1566 TEMP = MAX( TEMP, ABS( VL( JR, JC ) ) )
1567 10 CONTINUE
1568 ELSE
1569 DO 20 JR = 1, N
1570 TEMP = MAX( TEMP, ABS( VL( JR, JC ) )+
1571 $ ABS( VL( JR, JC+1 ) ) )
1572 20 CONTINUE
1573 END IF
1574 IF( TEMP.LT.SMLNUM )
1575 $ GO TO 50
1576 TEMP = ONE / TEMP
1577 IF( ALPHAI( JC ).EQ.ZERO ) THEN
1578 DO 30 JR = 1, N
1579 VL( JR, JC ) = VL( JR, JC )*TEMP
1580 30 CONTINUE
1581 ELSE
1582 DO 40 JR = 1, N
1583 VL( JR, JC ) = VL( JR, JC )*TEMP
1584 VL( JR, JC+1 ) = VL( JR, JC+1 )*TEMP
1585 40 CONTINUE
1586 END IF
1587 50 CONTINUE
1588 END IF
1589 IF( ILVR ) THEN
1590 CALL DGGBAK( 'P', 'R', N, ILO, IHI, WORK( ILEFT ),
1591 $ WORK( IRIGHT ), N, VR, LDVR, IERR )
1592 DO 100 JC = 1, N
1593 IF( ALPHAI( JC ).LT.ZERO )
1594 $ GO TO 100
1595 TEMP = ZERO
1596 IF( ALPHAI( JC ).EQ.ZERO ) THEN
1597 DO 60 JR = 1, N
1598 TEMP = MAX( TEMP, ABS( VR( JR, JC ) ) )
1599 60 CONTINUE
1600 ELSE
1601 DO 70 JR = 1, N
1602 TEMP = MAX( TEMP, ABS( VR( JR, JC ) )+
1603 $ ABS( VR( JR, JC+1 ) ) )
1604 70 CONTINUE
1605 END IF
1606 IF( TEMP.LT.SMLNUM )
1607 $ GO TO 100
1608 TEMP = ONE / TEMP
1609 IF( ALPHAI( JC ).EQ.ZERO ) THEN
1610 DO 80 JR = 1, N
1611 VR( JR, JC ) = VR( JR, JC )*TEMP
1612 80 CONTINUE
1613 ELSE
1614 DO 90 JR = 1, N
1615 VR( JR, JC ) = VR( JR, JC )*TEMP
1616 VR( JR, JC+1 ) = VR( JR, JC+1 )*TEMP
1617 90 CONTINUE
1618 END IF
1619 100 CONTINUE
1620 END IF
1621 *
1622 * End of eigenvector calculation
1623 *
1624 END IF
1625 *
1626 * Undo scaling if necessary
1627 *
1628 IF( ILASCL ) THEN
1629 CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAR, N, IERR )
1630 CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAI, N, IERR )
1631 END IF
1632 *
1633 IF( ILBSCL ) THEN
1634 CALL DLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR )
1635 END IF
1636 *
1637 110 CONTINUE
1638 *
1639 WORK( 1 ) = MAXWRK
1640 *
1641 RETURN
1642 *
1643 * End of DGGEV
1644 *
1645 END
1646 C
1647 C-----------------------------------------------------------------------
1648 C-----------------------------------------------------------------------
1649 SUBROUTINE DGEES( JOBVS, SORT, SELECT, N, A, LDA, SDIM, WR, WI,
1650 $ VS, LDVS, WORK, LWORK, BWORK, INFO )
1651 *
1652 * -- LAPACK driver routine (version 3.2) --
1653 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
1654 * November 2006
1655 *
1656 * .. Scalar Arguments ..
1657 CHARACTER JOBVS, SORT
1658 INTEGER INFO, LDA, LDVS, LWORK, N, SDIM
1659 * ..
1660 * .. Array Arguments ..
1661 LOGICAL BWORK( * )
1662 DOUBLE PRECISION A( LDA, * ), VS( LDVS, * ), WI( * ), WORK( * ),
1663 $ WR( * )
1664 * ..
1665 * .. Function Arguments ..
1666 LOGICAL SELECT
1667 EXTERNAL SELECT
1668 * ..
1669 *
1670 * Purpose
1671 * =======
1672 *
1673 * DGEES computes for an N-by-N real nonsymmetric matrix A, the
1674 * eigenvalues, the real Schur form T, and, optionally, the matrix of
1675 * Schur vectors Z. This gives the Schur factorization A = Z*T*(Z**T).
1676 *
1677 * Optionally, it also orders the eigenvalues on the diagonal of the
1678 * real Schur form so that selected eigenvalues are at the top left.
1679 * The leading columns of Z then form an orthonormal basis for the
1680 * invariant subspace corresponding to the selected eigenvalues.
1681 *
1682 * A matrix is in real Schur form if it is upper quasi-triangular with
1683 * 1-by-1 and 2-by-2 blocks. 2-by-2 blocks will be standardized in the
1684 * form
1685 * [ a b ]
1686 * [ c a ]
1687 *
1688 * where b*c < 0. The eigenvalues of such a block are a +- sqrt(bc).
1689 *
1690 * Arguments
1691 * =========
1692 *
1693 * JOBVS (input) CHARACTER*1
1694 * = 'N': Schur vectors are not computed;
1695 * = 'V': Schur vectors are computed.
1696 *
1697 * SORT (input) CHARACTER*1
1698 * Specifies whether or not to order the eigenvalues on the
1699 * diagonal of the Schur form.
1700 * = 'N': Eigenvalues are not ordered;
1701 * = 'S': Eigenvalues are ordered (see SELECT).
1702 *
1703 * SELECT (external procedure) LOGICAL FUNCTION of two DOUBLE PRECISION arguments
1704 * SELECT must be declared EXTERNAL in the calling subroutine.
1705 * If SORT = 'S', SELECT is used to select eigenvalues to sort
1706 * to the top left of the Schur form.
1707 * If SORT = 'N', SELECT is not referenced.
1708 * An eigenvalue WR(j)+sqrt(-1)*WI(j) is selected if
1709 * SELECT(WR(j),WI(j)) is true; i.e., if either one of a complex
1710 * conjugate pair of eigenvalues is selected, then both complex
1711 * eigenvalues are selected.
1712 * Note that a selected complex eigenvalue may no longer
1713 * satisfy SELECT(WR(j),WI(j)) = .TRUE. after ordering, since
1714 * ordering may change the value of complex eigenvalues
1715 * (especially if the eigenvalue is ill-conditioned); in this
1716 * case INFO is set to N+2 (see INFO below).
1717 *
1718 * N (input) INTEGER
1719 * The order of the matrix A. N >= 0.
1720 *
1721 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
1722 * On entry, the N-by-N matrix A.
1723 * On exit, A has been overwritten by its real Schur form T.
1724 *
1725 * LDA (input) INTEGER
1726 * The leading dimension of the array A. LDA >= max(1,N).
1727 *
1728 * SDIM (output) INTEGER
1729 * If SORT = 'N', SDIM = 0.
1730 * If SORT = 'S', SDIM = number of eigenvalues (after sorting)
1731 * for which SELECT is true. (Complex conjugate
1732 * pairs for which SELECT is true for either
1733 * eigenvalue count as 2.)
1734 *
1735 * WR (output) DOUBLE PRECISION array, dimension (N)
1736 * WI (output) DOUBLE PRECISION array, dimension (N)
1737 * WR and WI contain the real and imaginary parts,
1738 * respectively, of the computed eigenvalues in the same order
1739 * that they appear on the diagonal of the output Schur form T.
1740 * Complex conjugate pairs of eigenvalues will appear
1741 * consecutively with the eigenvalue having the positive
1742 * imaginary part first.
1743 *
1744 * VS (output) DOUBLE PRECISION array, dimension (LDVS,N)
1745 * If JOBVS = 'V', VS contains the orthogonal matrix Z of Schur
1746 * vectors.
1747 * If JOBVS = 'N', VS is not referenced.
1748 *
1749 * LDVS (input) INTEGER
1750 * The leading dimension of the array VS. LDVS >= 1; if
1751 * JOBVS = 'V', LDVS >= N.
1752 *
1753 * WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
1754 * On exit, if INFO = 0, WORK(1) contains the optimal LWORK.
1755 *
1756 * LWORK (input) INTEGER
1757 * The dimension of the array WORK. LWORK >= max(1,3*N).
1758 * For good performance, LWORK must generally be larger.
1759 *
1760 * If LWORK = -1, then a workspace query is assumed; the routine
1761 * only calculates the optimal size of the WORK array, returns
1762 * this value as the first entry of the WORK array, and no error
1763 * message related to LWORK is issued by XERBLA.
1764 *
1765 * BWORK (workspace) LOGICAL array, dimension (N)
1766 * Not referenced if SORT = 'N'.
1767 *
1768 * INFO (output) INTEGER
1769 * = 0: successful exit
1770 * < 0: if INFO = -i, the i-th argument had an illegal value.
1771 * > 0: if INFO = i, and i is
1772 * <= N: the QR algorithm failed to compute all the
1773 * eigenvalues; elements 1:ILO-1 and i+1:N of WR and WI
1774 * contain those eigenvalues which have converged; if
1775 * JOBVS = 'V', VS contains the matrix which reduces A
1776 * to its partially converged Schur form.
1777 * = N+1: the eigenvalues could not be reordered because some
1778 * eigenvalues were too close to separate (the problem
1779 * is very ill-conditioned);
1780 * = N+2: after reordering, roundoff changed values of some
1781 * complex eigenvalues so that leading eigenvalues in
1782 * the Schur form no longer satisfy SELECT=.TRUE. This
1783 * could also be caused by underflow due to scaling.
1784 *
1785 * =====================================================================
1786 *
1787 * .. Parameters ..
1788 DOUBLE PRECISION ZERO, ONE
1789 PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
1790 * ..
1791 * .. Local Scalars ..
1792 LOGICAL CURSL, LASTSL, LQUERY, LST2SL, SCALEA, WANTST,
1793 $ WANTVS
1794 INTEGER HSWORK, I, I1, I2, IBAL, ICOND, IERR, IEVAL,
1795 $ IHI, ILO, INXT, IP, ITAU, IWRK, MAXWRK, MINWRK
1796 DOUBLE PRECISION ANRM, BIGNUM, CSCALE, EPS, S, SEP, SMLNUM
1797 * ..
1798 * .. Local Arrays ..
1799 INTEGER IDUM( 1 )
1800 DOUBLE PRECISION DUM( 1 )
1801 * ..
1802 * .. External Subroutines ..
1803 EXTERNAL DCOPY, DGEBAK, DGEBAL, DGEHRD, DHSEQR, DLACPY,
1804 $ DLABAD, DLASCL, DORGHR, DSWAP, DTRSEN, XERBLA
1805 * ..
1806 * .. External Functions ..
1807 LOGICAL LSAME
1808 INTEGER ILAENV
1809 DOUBLE PRECISION DLAMCH, DLANGE
1810 EXTERNAL LSAME, ILAENV, DLAMCH, DLANGE
1811 * ..
1812 * .. Intrinsic Functions ..
1813 INTRINSIC MAX, SQRT
1814 * ..
1815 * .. Executable Statements ..
1816 *
1817 * Test the input arguments
1818 *
1819 INFO = 0
1820 LQUERY = ( LWORK.EQ.-1 )
1821 WANTVS = LSAME( JOBVS, 'V' )
1822 WANTST = LSAME( SORT, 'S' )
1823 IF( ( .NOT.WANTVS ) .AND. ( .NOT.LSAME( JOBVS, 'N' ) ) ) THEN
1824 INFO = -1
1825 ELSE IF( ( .NOT.WANTST ) .AND. ( .NOT.LSAME( SORT, 'N' ) ) ) THEN
1826 INFO = -2
1827 ELSE IF( N.LT.0 ) THEN
1828 INFO = -4
1829 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
1830 INFO = -6
1831 ELSE IF( LDVS.LT.1 .OR. ( WANTVS .AND. LDVS.LT.N ) ) THEN
1832 INFO = -11
1833 END IF
1834 *
1835 * Compute workspace
1836 * (Note: Comments in the code beginning "Workspace:" describe the
1837 * minimal amount of workspace needed at that point in the code,
1838 * as well as the preferred amount for good performance.
1839 * NB refers to the optimal block size for the immediately
1840 * following subroutine, as returned by ILAENV.
1841 * HSWORK refers to the workspace preferred by DHSEQR, as
1842 * calculated below. HSWORK is computed assuming ILO=1 and IHI=N,
1843 * the worst case.)
1844 *
1845 IF( INFO.EQ.0 ) THEN
1846 IF( N.EQ.0 ) THEN
1847 MINWRK = 1
1848 MAXWRK = 1
1849 ELSE
1850 MAXWRK = 2*N + N*ILAENV( 1, 'DGEHRD', ' ', N, 1, N, 0 )
1851 MINWRK = 3*N
1852 *
1853 CALL DHSEQR( 'S', JOBVS, N, 1, N, A, LDA, WR, WI, VS, LDVS,
1854 $ WORK, -1, IEVAL )
1855 HSWORK = WORK( 1 )
1856 *
1857 IF( .NOT.WANTVS ) THEN
1858 MAXWRK = MAX( MAXWRK, N + HSWORK )
1859 ELSE
1860 MAXWRK = MAX( MAXWRK, 2*N + ( N - 1 )*ILAENV( 1,
1861 $ 'DORGHR', ' ', N, 1, N, -1 ) )
1862 MAXWRK = MAX( MAXWRK, N + HSWORK )
1863 END IF
1864 END IF
1865 WORK( 1 ) = MAXWRK
1866 *
1867 IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN
1868 INFO = -13
1869 END IF
1870 END IF
1871 *
1872 IF( INFO.NE.0 ) THEN
1873 CALL XERBLA( 'DGEES ', -INFO )
1874 RETURN
1875 ELSE IF( LQUERY ) THEN
1876 RETURN
1877 END IF
1878 *
1879 * Quick return if possible
1880 *
1881 IF( N.EQ.0 ) THEN
1882 SDIM = 0
1883 RETURN
1884 END IF
1885 *
1886 * Get machine constants
1887 *
1888 EPS = DLAMCH( 'P' )
1889 SMLNUM = DLAMCH( 'S' )
1890 BIGNUM = ONE / SMLNUM
1891 CALL DLABAD( SMLNUM, BIGNUM )
1892 SMLNUM = SQRT( SMLNUM ) / EPS
1893 BIGNUM = ONE / SMLNUM
1894 *
1895 * Scale A if max element outside range [SMLNUM,BIGNUM]
1896 *
1897 ANRM = DLANGE( 'M', N, N, A, LDA, DUM )
1898 SCALEA = .FALSE.
1899 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
1900 SCALEA = .TRUE.
1901 CSCALE = SMLNUM
1902 ELSE IF( ANRM.GT.BIGNUM ) THEN
1903 SCALEA = .TRUE.
1904 CSCALE = BIGNUM
1905 END IF
1906 IF( SCALEA )
1907 $ CALL DLASCL( 'G', 0, 0, ANRM, CSCALE, N, N, A, LDA, IERR )
1908 *
1909 * Permute the matrix to make it more nearly triangular
1910 * (Workspace: need N)
1911 *
1912 IBAL = 1
1913 CALL DGEBAL( 'P', N, A, LDA, ILO, IHI, WORK( IBAL ), IERR )
1914 *
1915 * Reduce to upper Hessenberg form
1916 * (Workspace: need 3*N, prefer 2*N+N*NB)
1917 *
1918 ITAU = N + IBAL
1919 IWRK = N + ITAU
1920 CALL DGEHRD( N, ILO, IHI, A, LDA, WORK( ITAU ), WORK( IWRK ),
1921 $ LWORK-IWRK+1, IERR )
1922 *
1923 IF( WANTVS ) THEN
1924 *
1925 * Copy Householder vectors to VS
1926 *
1927 CALL DLACPY( 'L', N, N, A, LDA, VS, LDVS )
1928 *
1929 * Generate orthogonal matrix in VS
1930 * (Workspace: need 3*N-1, prefer 2*N+(N-1)*NB)
1931 *
1932 CALL DORGHR( N, ILO, IHI, VS, LDVS, WORK( ITAU ), WORK( IWRK ),
1933 $ LWORK-IWRK+1, IERR )
1934 END IF
1935 *
1936 SDIM = 0
1937 *
1938 * Perform QR iteration, accumulating Schur vectors in VS if desired
1939 * (Workspace: need N+1, prefer N+HSWORK (see comments) )
1940 *
1941 IWRK = ITAU
1942 CALL DHSEQR( 'S', JOBVS, N, ILO, IHI, A, LDA, WR, WI, VS, LDVS,
1943 $ WORK( IWRK ), LWORK-IWRK+1, IEVAL )
1944 IF( IEVAL.GT.0 )
1945 $ INFO = IEVAL
1946 *
1947 * Sort eigenvalues if desired
1948 *
1949 IF( WANTST .AND. INFO.EQ.0 ) THEN
1950 IF( SCALEA ) THEN
1951 CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, N, 1, WR, N, IERR )
1952 CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, N, 1, WI, N, IERR )
1953 END IF
1954 DO 10 I = 1, N
1955 BWORK( I ) = SELECT( WR( I ), WI( I ) )
1956 10 CONTINUE
1957 *
1958 * Reorder eigenvalues and transform Schur vectors
1959 * (Workspace: none needed)
1960 *
1961 CALL DTRSEN( 'N', JOBVS, BWORK, N, A, LDA, VS, LDVS, WR, WI,
1962 $ SDIM, S, SEP, WORK( IWRK ), LWORK-IWRK+1, IDUM, 1,
1963 $ ICOND )
1964 IF( ICOND.GT.0 )
1965 $ INFO = N + ICOND
1966 END IF
1967 *
1968 IF( WANTVS ) THEN
1969 *
1970 * Undo balancing
1971 * (Workspace: need N)
1972 *
1973 CALL DGEBAK( 'P', 'R', N, ILO, IHI, WORK( IBAL ), N, VS, LDVS,
1974 $ IERR )
1975 END IF
1976 *
1977 IF( SCALEA ) THEN
1978 *
1979 * Undo scaling for the Schur form of A
1980 *
1981 CALL DLASCL( 'H', 0, 0, CSCALE, ANRM, N, N, A, LDA, IERR )
1982 CALL DCOPY( N, A, LDA+1, WR, 1 )
1983 IF( CSCALE.EQ.SMLNUM ) THEN
1984 *
1985 * If scaling back towards underflow, adjust WI if an
1986 * offdiagonal element of a 2-by-2 block in the Schur form
1987 * underflows.
1988 *
1989 IF( IEVAL.GT.0 ) THEN
1990 I1 = IEVAL + 1
1991 I2 = IHI - 1
1992 CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, ILO-1, 1, WI,
1993 $ MAX( ILO-1, 1 ), IERR )
1994 ELSE IF( WANTST ) THEN
1995 I1 = 1
1996 I2 = N - 1
1997 ELSE
1998 I1 = ILO
1999 I2 = IHI - 1
2000 END IF
2001 INXT = I1 - 1
2002 DO 20 I = I1, I2
2003 IF( I.LT.INXT )
2004 $ GO TO 20
2005 IF( WI( I ).EQ.ZERO ) THEN
2006 INXT = I + 1
2007 ELSE
2008 IF( A( I+1, I ).EQ.ZERO ) THEN
2009 WI( I ) = ZERO
2010 WI( I+1 ) = ZERO
2011 ELSE IF( A( I+1, I ).NE.ZERO .AND. A( I, I+1 ).EQ.
2012 $ ZERO ) THEN
2013 WI( I ) = ZERO
2014 WI( I+1 ) = ZERO
2015 IF( I.GT.1 )
2016 $ CALL DSWAP( I-1, A( 1, I ), 1, A( 1, I+1 ), 1 )
2017 IF( N.GT.I+1 )
2018 $ CALL DSWAP( N-I-1, A( I, I+2 ), LDA,
2019 $ A( I+1, I+2 ), LDA )
2020 IF( WANTVS ) THEN
2021 CALL DSWAP( N, VS( 1, I ), 1, VS( 1, I+1 ), 1 )
2022 END IF
2023 A( I, I+1 ) = A( I+1, I )
2024 A( I+1, I ) = ZERO
2025 END IF
2026 INXT = I + 2
2027 END IF
2028 20 CONTINUE
2029 END IF
2030 *
2031 * Undo scaling for the imaginary part of the eigenvalues
2032 *
2033 CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, N-IEVAL, 1,
2034 $ WI( IEVAL+1 ), MAX( N-IEVAL, 1 ), IERR )
2035 END IF
2036 *
2037 IF( WANTST .AND. INFO.EQ.0 ) THEN
2038 *
2039 * Check if reordering successful
2040 *
2041 LASTSL = .TRUE.
2042 LST2SL = .TRUE.
2043 SDIM = 0
2044 IP = 0
2045 DO 30 I = 1, N
2046 CURSL = SELECT( WR( I ), WI( I ) )
2047 IF( WI( I ).EQ.ZERO ) THEN
2048 IF( CURSL )
2049 $ SDIM = SDIM + 1
2050 IP = 0
2051 IF( CURSL .AND. .NOT.LASTSL )
2052 $ INFO = N + 2
2053 ELSE
2054 IF( IP.EQ.1 ) THEN
2055 *
2056 * Last eigenvalue of conjugate pair
2057 *
2058 CURSL = CURSL .OR. LASTSL
2059 LASTSL = CURSL
2060 IF( CURSL )
2061 $ SDIM = SDIM + 2
2062 IP = -1
2063 IF( CURSL .AND. .NOT.LST2SL )
2064 $ INFO = N + 2
2065 ELSE
2066 *
2067 * First eigenvalue of conjugate pair
2068 *
2069 IP = 1
2070 END IF
2071 END IF
2072 LST2SL = LASTSL
2073 LASTSL = CURSL
2074 30 CONTINUE
2075 END IF
2076 *
2077 WORK( 1 ) = MAXWRK
2078 RETURN
2079 *
2080 * End of DGEES
2081 *
2082 END
2083 C
2084 C-----------------------------------------------------------------------
2085 C-----------------------------------------------------------------------
2086 SUBROUTINE DGESVJ( JOBA, JOBU, JOBV, M, N, A, LDA, SVA, MV, V,
2087 + LDV, WORK, LWORK, INFO )
2088 *
2089 * -- LAPACK routine (version 3.2.2) --
2090 *
2091 * -- Contributed by Zlatko Drmac of the University of Zagreb and --
2092 * -- Kresimir Veselic of the Fernuniversitaet Hagen --
2093 * -- June 2010 --
2094 *
2095 * -- LAPACK is a software package provided by Univ. of Tennessee, --
2096 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
2097 *
2098 * This routine is also part of SIGMA (version 1.23, October 23. 2008.)
2099 * SIGMA is a library of algorithms for highly accurate algorithms for
2100 * computation of SVD, PSVD, QSVD, (H,K)-SVD, and for solution of the
2101 * eigenvalue problems Hx = lambda M x, H M x = lambda x with H, M > 0.
2102 *
2103 IMPLICIT NONE
2104 * ..
2105 * .. Scalar Arguments ..
2106 INTEGER INFO, LDA, LDV, LWORK, M, MV, N
2107 CHARACTER*1 JOBA, JOBU, JOBV
2108 * ..
2109 * .. Array Arguments ..
2110 DOUBLE PRECISION A( LDA, * ), SVA( N ), V( LDV, * ),
2111 + WORK( LWORK )
2112 * ..
2113 *
2114 * Purpose
2115 * =======
2116 *
2117 * DGESVJ computes the singular value decomposition (SVD) of a real
2118 * M-by-N matrix A, where M >= N. The SVD of A is written as
2119 * [++] [xx] [x0] [xx]
2120 * A = U * SIGMA * V^t, [++] = [xx] * [ox] * [xx]
2121 * [++] [xx]
2122 * where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal
2123 * matrix, and V is an N-by-N orthogonal matrix. The diagonal elements
2124 * of SIGMA are the singular values of A. The columns of U and V are the
2125 * left and the right singular vectors of A, respectively.
2126 *
2127 * Further Details
2128 * ~~~~~~~~~~~~~~~
2129 * The orthogonal N-by-N matrix V is obtained as a product of Jacobi plane
2130 * rotations. The rotations are implemented as fast scaled rotations of
2131 * Anda and Park [1]. In the case of underflow of the Jacobi angle, a
2132 * modified Jacobi transformation of Drmac [4] is used. Pivot strategy uses
2133 * column interchanges of de Rijk [2]. The relative accuracy of the computed
2134 * singular values and the accuracy of the computed singular vectors (in
2135 * angle metric) is as guaranteed by the theory of Demmel and Veselic [3].
2136 * The condition number that determines the accuracy in the full rank case
2137 * is essentially min_{D=diag} kappa(A*D), where kappa(.) is the
2138 * spectral condition number. The best performance of this Jacobi SVD
2139 * procedure is achieved if used in an accelerated version of Drmac and
2140 * Veselic [5,6], and it is the kernel routine in the SIGMA library [7].
2141 * Some tunning parameters (marked with [TP]) are available for the
2142 * implementer.
2143 * The computational range for the nonzero singular values is the machine
2144 * number interval ( UNDERFLOW , OVERFLOW ). In extreme cases, even
2145 * denormalized singular values can be computed with the corresponding
2146 * gradual loss of accurate digits.
2147 *
2148 * Contributors
2149 * ~~~~~~~~~~~~
2150 * Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany)
2151 *
2152 * References
2153 * ~~~~~~~~~~
2154 * [1] A. A. Anda and H. Park: Fast plane rotations with dynamic scaling.
2155 * SIAM J. matrix Anal. Appl., Vol. 15 (1994), pp. 162-174.
2156 * [2] P. P. M. De Rijk: A one-sided Jacobi algorithm for computing the
2157 * singular value decomposition on a vector computer.
2158 * SIAM J. Sci. Stat. Comp., Vol. 10 (1998), pp. 359-371.
2159 * [3] J. Demmel and K. Veselic: Jacobi method is more accurate than QR.
2160 * [4] Z. Drmac: Implementation of Jacobi rotations for accurate singular
2161 * value computation in floating point arithmetic.
2162 * SIAM J. Sci. Comp., Vol. 18 (1997), pp. 1200-1222.
2163 * [5] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm I.
2164 * SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1322-1342.
2165 * LAPACK Working note 169.
2166 * [6] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm II.
2167 * SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1343-1362.
2168 * LAPACK Working note 170.
2169 * [7] Z. Drmac: SIGMA - mathematical software library for accurate SVD, PSV,
2170 * QSVD, (H,K)-SVD computations.
2171 * Department of Mathematics, University of Zagreb, 2008.
2172 *
2173 * Bugs, Examples and Comments
2174 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
2175 * Please report all bugs and send interesting test examples and comments to
2176 * [email protected]. Thank you.
2177 *
2178 * Arguments
2179 * =========
2180 *
2181 * JOBA (input) CHARACTER* 1
2182 * Specifies the structure of A.
2183 * = 'L': The input matrix A is lower triangular;
2184 * = 'U': The input matrix A is upper triangular;
2185 * = 'G': The input matrix A is general M-by-N matrix, M >= N.
2186 *
2187 * JOBU (input) CHARACTER*1
2188 * Specifies whether to compute the left singular vectors
2189 * (columns of U):
2190 * = 'U': The left singular vectors corresponding to the nonzero
2191 * singular values are computed and returned in the leading
2192 * columns of A. See more details in the description of A.
2193 * The default numerical orthogonality threshold is set to
2194 * approximately TOL=CTOL*EPS, CTOL=DSQRT(M), EPS=DLAMCH('E').
2195 * = 'C': Analogous to JOBU='U', except that user can control the
2196 * level of numerical orthogonality of the computed left
2197 * singular vectors. TOL can be set to TOL = CTOL*EPS, where
2198 * CTOL is given on input in the array WORK.
2199 * No CTOL smaller than ONE is allowed. CTOL greater
2200 * than 1 / EPS is meaningless. The option 'C'
2201 * can be used if M*EPS is satisfactory orthogonality
2202 * of the computed left singular vectors, so CTOL=M could
2203 * save few sweeps of Jacobi rotations.
2204 * See the descriptions of A and WORK(1).
2205 * = 'N': The matrix U is not computed. However, see the
2206 * description of A.
2207 *
2208 * JOBV (input) CHARACTER*1
2209 * Specifies whether to compute the right singular vectors, that
2210 * is, the matrix V:
2211 * = 'V' : the matrix V is computed and returned in the array V
2212 * = 'A' : the Jacobi rotations are applied to the MV-by-N
2213 * array V. In other words, the right singular vector
2214 * matrix V is not computed explicitly, instead it is
2215 * applied to an MV-by-N matrix initially stored in the
2216 * first MV rows of V.
2217 * = 'N' : the matrix V is not computed and the array V is not
2218 * referenced
2219 *
2220 * M (input) INTEGER
2221 * The number of rows of the input matrix A. M >= 0.
2222 *
2223 * N (input) INTEGER
2224 * The number of columns of the input matrix A.
2225 * M >= N >= 0.
2226 *
2227 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
2228 * On entry, the M-by-N matrix A.
2229 * On exit :
2230 * If JOBU .EQ. 'U' .OR. JOBU .EQ. 'C' :
2231 * If INFO .EQ. 0 :
2232 * RANKA orthonormal columns of U are returned in the
2233 * leading RANKA columns of the array A. Here RANKA <= N
2234 * is the number of computed singular values of A that are
2235 * above the underflow threshold DLAMCH('S'). The singular
2236 * vectors corresponding to underflowed or zero singular
2237 * values are not computed. The value of RANKA is returned
2238 * in the array WORK as RANKA=NINT(WORK(2)). Also see the
2239 * descriptions of SVA and WORK. The computed columns of U
2240 * are mutually numerically orthogonal up to approximately
2241 * TOL=DSQRT(M)*EPS (default); or TOL=CTOL*EPS (JOBU.EQ.'C'),
2242 * see the description of JOBU.
2243 * If INFO .GT. 0 :
2244 * the procedure DGESVJ did not converge in the given number
2245 * of iterations (sweeps). In that case, the computed
2246 * columns of U may not be orthogonal up to TOL. The output
2247 * U (stored in A), SIGMA (given by the computed singular
2248 * values in SVA(1:N)) and V is still a decomposition of the
2249 * input matrix A in the sense that the residual
2250 * ||A-SCALE*U*SIGMA*V^T||_2 / ||A||_2 is small.
2251 *
2252 * If JOBU .EQ. 'N' :
2253 * If INFO .EQ. 0 :
2254 * Note that the left singular vectors are 'for free' in the
2255 * one-sided Jacobi SVD algorithm. However, if only the
2256 * singular values are needed, the level of numerical
2257 * orthogonality of U is not an issue and iterations are
2258 * stopped when the columns of the iterated matrix are
2259 * numerically orthogonal up to approximately M*EPS. Thus,
2260 * on exit, A contains the columns of U scaled with the
2261 * corresponding singular values.
2262 * If INFO .GT. 0 :
2263 * the procedure DGESVJ did not converge in the given number
2264 * of iterations (sweeps).
2265 *
2266 * LDA (input) INTEGER
2267 * The leading dimension of the array A. LDA >= max(1,M).
2268 *
2269 * SVA (workspace/output) DOUBLE PRECISION array, dimension (N)
2270 * On exit :
2271 * If INFO .EQ. 0 :
2272 * depending on the value SCALE = WORK(1), we have:
2273 * If SCALE .EQ. ONE :
2274 * SVA(1:N) contains the computed singular values of A.
2275 * During the computation SVA contains the Euclidean column
2276 * norms of the iterated matrices in the array A.
2277 * If SCALE .NE. ONE :
2278 * The singular values of A are SCALE*SVA(1:N), and this
2279 * factored representation is due to the fact that some of the
2280 * singular values of A might underflow or overflow.
2281 * If INFO .GT. 0 :
2282 * the procedure DGESVJ did not converge in the given number of
2283 * iterations (sweeps) and SCALE*SVA(1:N) may not be accurate.
2284 *
2285 * MV (input) INTEGER
2286 * If JOBV .EQ. 'A', then the product of Jacobi rotations in DGESVJ
2287 * is applied to the first MV rows of V. See the description of JOBV.
2288 *
2289 * V (input/output) DOUBLE PRECISION array, dimension (LDV,N)
2290 * If JOBV = 'V', then V contains on exit the N-by-N matrix of
2291 * the right singular vectors;
2292 * If JOBV = 'A', then V contains the product of the computed right
2293 * singular vector matrix and the initial matrix in
2294 * the array V.
2295 * If JOBV = 'N', then V is not referenced.
2296 *
2297 * LDV (input) INTEGER
2298 * The leading dimension of the array V, LDV .GE. 1.
2299 * If JOBV .EQ. 'V', then LDV .GE. max(1,N).
2300 * If JOBV .EQ. 'A', then LDV .GE. max(1,MV) .
2301 *
2302 * WORK (input/workspace/output) DOUBLE PRECISION array, dimension max(4,M+N).
2303 * On entry :
2304 * If JOBU .EQ. 'C' :
2305 * WORK(1) = CTOL, where CTOL defines the threshold for convergence.
2306 * The process stops if all columns of A are mutually
2307 * orthogonal up to CTOL*EPS, EPS=DLAMCH('E').
2308 * It is required that CTOL >= ONE, i.e. it is not
2309 * allowed to force the routine to obtain orthogonality
2310 * below EPSILON.
2311 * On exit :
2312 * WORK(1) = SCALE is the scaling factor such that SCALE*SVA(1:N)
2313 * are the computed singular values of A.
2314 * (See description of SVA().)
2315 * WORK(2) = NINT(WORK(2)) is the number of the computed nonzero
2316 * singular values.
2317 * WORK(3) = NINT(WORK(3)) is the number of the computed singular
2318 * values that are larger than the underflow threshold.
2319 * WORK(4) = NINT(WORK(4)) is the number of sweeps of Jacobi
2320 * rotations needed for numerical convergence.
2321 * WORK(5) = max_{i.NE.j} |COS(A(:,i),A(:,j))| in the last sweep.
2322 * This is useful information in cases when DGESVJ did
2323 * not converge, as it can be used to estimate whether
2324 * the output is stil useful and for post festum analysis.
2325 * WORK(6) = the largest absolute value over all sines of the
2326 * Jacobi rotation angles in the last sweep. It can be
2327 * useful for a post festum analysis.
2328 *
2329 * LWORK (input) INTEGER
2330 * length of WORK, WORK >= MAX(6,M+N)
2331 *
2332 * INFO (output) INTEGER
2333 * = 0 : successful exit.
2334 * < 0 : if INFO = -i, then the i-th argument had an illegal value
2335 * > 0 : DGESVJ did not converge in the maximal allowed number (30)
2336 * of sweeps. The output may still be useful. See the
2337 * description of WORK.
2338 *
2339 * =====================================================================
2340 *
2341 * .. Local Parameters ..
2342 DOUBLE PRECISION ZERO, HALF, ONE, TWO
2343 PARAMETER ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0,
2344 + TWO = 2.0D0 )
2345 INTEGER NSWEEP
2346 PARAMETER ( NSWEEP = 30 )
2347 * ..
2348 * .. Local Scalars ..
2349 DOUBLE PRECISION AAPP, AAPP0, AAPQ, AAQQ, APOAQ, AQOAP, BIG,
2350 + BIGTHETA, CS, CTOL, EPSILON, LARGE, MXAAPQ,
2351 + MXSINJ, ROOTBIG, ROOTEPS, ROOTSFMIN, ROOTTOL,
2352 + SCALE, SFMIN, SMALL, SN, T, TEMP1, THETA,
2353 + THSIGN, TOL
2354 INTEGER BLSKIP, EMPTSW, i, ibr, IERR, igl, IJBLSK, ir1,
2355 + ISWROT, jbc, jgl, KBL, LKAHEAD, MVL, N2, N34,
2356 + N4, NBL, NOTROT, p, PSKIPPED, q, ROWSKIP,
2357 + SWBAND
2358 LOGICAL APPLV, GOSCALE, LOWER, LSVEC, NOSCALE, ROTOK,
2359 + RSVEC, UCTOL, UPPER
2360 * ..
2361 * .. Local Arrays ..
2362 DOUBLE PRECISION FASTR( 5 )
2363 * ..
2364 * .. Intrinsic Functions ..
2365 INTRINSIC DABS, DMAX1, DMIN1, DBLE, MIN0, DSIGN, DSQRT
2366 * ..
2367 * .. External Functions ..
2368 * ..
2369 * from BLAS
2370 DOUBLE PRECISION DDOT, DNRM2
2371 EXTERNAL DDOT, DNRM2
2372 INTEGER IDAMAX
2373 EXTERNAL IDAMAX
2374 * from LAPACK
2375 DOUBLE PRECISION DLAMCH
2376 EXTERNAL DLAMCH
2377 LOGICAL LSAME
2378 EXTERNAL LSAME
2379 * ..
2380 * .. External Subroutines ..
2381 * ..
2382 * from BLAS
2383 EXTERNAL DAXPY, DCOPY, DROTM, DSCAL, DSWAP
2384 * from LAPACK
2385 EXTERNAL DLASCL, DLASET, DLASSQ, XERBLA
2386 *
2387 EXTERNAL DGSVJ0, DGSVJ1
2388 * ..
2389 * .. Executable Statements ..
2390 *
2391 * Test the input arguments
2392 *
2393 LSVEC = LSAME( JOBU, 'U' )
2394 UCTOL = LSAME( JOBU, 'C' )
2395 RSVEC = LSAME( JOBV, 'V' )
2396 APPLV = LSAME( JOBV, 'A' )
2397 UPPER = LSAME( JOBA, 'U' )
2398 LOWER = LSAME( JOBA, 'L' )
2399 *
2400 IF( .NOT.( UPPER .OR. LOWER .OR. LSAME( JOBA, 'G' ) ) ) THEN
2401 INFO = -1
2402 ELSE IF( .NOT.( LSVEC .OR. UCTOL .OR. LSAME( JOBU, 'N' ) ) ) THEN
2403 INFO = -2
2404 ELSE IF( .NOT.( RSVEC .OR. APPLV .OR. LSAME( JOBV, 'N' ) ) ) THEN
2405 INFO = -3
2406 ELSE IF( M.LT.0 ) THEN
2407 INFO = -4
2408 ELSE IF( ( N.LT.0 ) .OR. ( N.GT.M ) ) THEN
2409 INFO = -5
2410 ELSE IF( LDA.LT.M ) THEN
2411 INFO = -7
2412 ELSE IF( MV.LT.0 ) THEN
2413 INFO = -9
2414 ELSE IF( ( RSVEC .AND. ( LDV.LT.N ) ) .OR.
2415 + ( APPLV .AND. ( LDV.LT.MV ) ) ) THEN
2416 INFO = -11
2417 ELSE IF( UCTOL .AND. ( WORK( 1 ).LE.ONE ) ) THEN
2418 INFO = -12
2419 ELSE IF( LWORK.LT.MAX0( M+N, 6 ) ) THEN
2420 INFO = -13
2421 ELSE
2422 INFO = 0
2423 END IF
2424 *
2425 * #:(
2426 IF( INFO.NE.0 ) THEN
2427 CALL XERBLA( 'DGESVJ', -INFO )
2428 RETURN
2429 END IF
2430 *
2431 * #:) Quick return for void matrix
2432 *
2433 IF( ( M.EQ.0 ) .OR. ( N.EQ.0 ) )RETURN
2434 *
2435 * Set numerical parameters
2436 * The stopping criterion for Jacobi rotations is
2437 *
2438 * max_{i<>j}|A(:,i)^T * A(:,j)|/(||A(:,i)||*||A(:,j)||) < CTOL*EPS
2439 *
2440 * where EPS is the round-off and CTOL is defined as follows:
2441 *
2442 IF( UCTOL ) THEN
2443 * ... user controlled
2444 CTOL = WORK( 1 )
2445 ELSE
2446 * ... default
2447 IF( LSVEC .OR. RSVEC .OR. APPLV ) THEN
2448 CTOL = DSQRT( DBLE( M ) )
2449 ELSE
2450 CTOL = DBLE( M )
2451 END IF
2452 END IF
2453 * ... and the machine dependent parameters are
2454 *[!] (Make sure that DLAMCH() works properly on the target machine.)
2455 *
2456 EPSILON = DLAMCH( 'Epsilon' )
2457 ROOTEPS = DSQRT( EPSILON )
2458 SFMIN = DLAMCH( 'SafeMinimum' )
2459 ROOTSFMIN = DSQRT( SFMIN )
2460 SMALL = SFMIN / EPSILON
2461 BIG = DLAMCH( 'Overflow' )
2462 * BIG = ONE / SFMIN
2463 ROOTBIG = ONE / ROOTSFMIN
2464 LARGE = BIG / DSQRT( DBLE( M*N ) )
2465 BIGTHETA = ONE / ROOTEPS
2466 *
2467 TOL = CTOL*EPSILON
2468 ROOTTOL = DSQRT( TOL )
2469 *
2470 IF( DBLE( M )*EPSILON.GE.ONE ) THEN
2471 INFO = -5
2472 CALL XERBLA( 'DGESVJ', -INFO )
2473 RETURN
2474 END IF
2475 *
2476 * Initialize the right singular vector matrix.
2477 *
2478 IF( RSVEC ) THEN
2479 MVL = N
2480 CALL DLASET( 'A', MVL, N, ZERO, ONE, V, LDV )
2481 ELSE IF( APPLV ) THEN
2482 MVL = MV
2483 END IF
2484 RSVEC = RSVEC .OR. APPLV
2485 *
2486 * Initialize SVA( 1:N ) = ( ||A e_i||_2, i = 1:N )
2487 *(!) If necessary, scale A to protect the largest singular value
2488 * from overflow. It is possible that saving the largest singular
2489 * value destroys the information about the small ones.
2490 * This initial scaling is almost minimal in the sense that the
2491 * goal is to make sure that no column norm overflows, and that
2492 * DSQRT(N)*max_i SVA(i) does not overflow. If INFinite entries
2493 * in A are detected, the procedure returns with INFO=-6.
2494 *
2495 SCALE = ONE / DSQRT( DBLE( M )*DBLE( N ) )
2496 NOSCALE = .TRUE.
2497 GOSCALE = .TRUE.
2498 *
2499 IF( LOWER ) THEN
2500 * the input matrix is M-by-N lower triangular (trapezoidal)
2501 DO 1874 p = 1, N
2502 AAPP = ZERO
2503 AAQQ = ZERO
2504 CALL DLASSQ( M-p+1, A( p, p ), 1, AAPP, AAQQ )
2505 IF( AAPP.GT.BIG ) THEN
2506 INFO = -6
2507 CALL XERBLA( 'DGESVJ', -INFO )
2508 RETURN
2509 END IF
2510 AAQQ = DSQRT( AAQQ )
2511 IF( ( AAQQ.NE.ZERO ) .AND. NOSCALE ) THEN
2512 IF( AAPP.GE.( BIG / AAQQ ) ) THEN
2513 NOSCALE = .FALSE.
2514 END IF
2515 END IF
2516 IF( NOSCALE ) THEN
2517 SVA( p ) = AAPP*AAQQ
2518 ELSE
2519 SVA( p ) = AAPP*( AAQQ*SCALE )
2520 IF( GOSCALE ) THEN
2521 GOSCALE = .FALSE.
2522 DO 1873 q = 1, p - 1
2523 SVA( q ) = SVA( q )*SCALE
2524 1873 CONTINUE
2525 END IF
2526 END IF
2527 1874 CONTINUE
2528 ELSE IF( UPPER ) THEN
2529 * the input matrix is M-by-N upper triangular (trapezoidal)
2530 DO 2874 p = 1, N
2531 AAPP = ZERO
2532 AAQQ = ZERO
2533 CALL DLASSQ( p, A( 1, p ), 1, AAPP, AAQQ )
2534 IF( AAPP.GT.BIG ) THEN
2535 INFO = -6
2536 CALL XERBLA( 'DGESVJ', -INFO )
2537 RETURN
2538 END IF
2539 AAQQ = DSQRT( AAQQ )
2540 IF( ( AAQQ.NE.ZERO ) .AND. NOSCALE ) THEN
2541 IF( AAPP.GE.( BIG / AAQQ ) ) THEN
2542 NOSCALE = .FALSE.
2543 END IF
2544 END IF
2545 IF( NOSCALE ) THEN
2546 SVA( p ) = AAPP*AAQQ
2547 ELSE
2548 SVA( p ) = AAPP*( AAQQ*SCALE )
2549 IF( GOSCALE ) THEN
2550 GOSCALE = .FALSE.
2551 DO 2873 q = 1, p - 1
2552 SVA( q ) = SVA( q )*SCALE
2553 2873 CONTINUE
2554 END IF
2555 END IF
2556 2874 CONTINUE
2557 ELSE
2558 * the input matrix is M-by-N general dense
2559 DO 3874 p = 1, N
2560 AAPP = ZERO
2561 AAQQ = ZERO
2562 CALL DLASSQ( M, A( 1, p ), 1, AAPP, AAQQ )
2563 IF( AAPP.GT.BIG ) THEN
2564 INFO = -6
2565 CALL XERBLA( 'DGESVJ', -INFO )
2566 RETURN
2567 END IF
2568 AAQQ = DSQRT( AAQQ )
2569 IF( ( AAQQ.NE.ZERO ) .AND. NOSCALE ) THEN
2570 IF( AAPP.GE.( BIG / AAQQ ) ) THEN
2571 NOSCALE = .FALSE.
2572 END IF
2573 END IF
2574 IF( NOSCALE ) THEN
2575 SVA( p ) = AAPP*AAQQ
2576 ELSE
2577 SVA( p ) = AAPP*( AAQQ*SCALE )
2578 IF( GOSCALE ) THEN
2579 GOSCALE = .FALSE.
2580 DO 3873 q = 1, p - 1
2581 SVA( q ) = SVA( q )*SCALE
2582 3873 CONTINUE
2583 END IF
2584 END IF
2585 3874 CONTINUE
2586 END IF
2587 *
2588 IF( NOSCALE )SCALE = ONE
2589 *
2590 * Move the smaller part of the spectrum from the underflow threshold
2591 *(!) Start by determining the position of the nonzero entries of the
2592 * array SVA() relative to ( SFMIN, BIG ).
2593 *
2594 AAPP = ZERO
2595 AAQQ = BIG
2596 DO 4781 p = 1, N
2597 IF( SVA( p ).NE.ZERO )AAQQ = DMIN1( AAQQ, SVA( p ) )
2598 AAPP = DMAX1( AAPP, SVA( p ) )
2599 4781 CONTINUE
2600 *
2601 * #:) Quick return for zero matrix
2602 *
2603 IF( AAPP.EQ.ZERO ) THEN
2604 IF( LSVEC )CALL DLASET( 'G', M, N, ZERO, ONE, A, LDA )
2605 WORK( 1 ) = ONE
2606 WORK( 2 ) = ZERO
2607 WORK( 3 ) = ZERO
2608 WORK( 4 ) = ZERO
2609 WORK( 5 ) = ZERO
2610 WORK( 6 ) = ZERO
2611 RETURN
2612 END IF
2613 *
2614 * #:) Quick return for one-column matrix
2615 *
2616 IF( N.EQ.1 ) THEN
2617 IF( LSVEC )CALL DLASCL( 'G', 0, 0, SVA( 1 ), SCALE, M, 1,
2618 + A( 1, 1 ), LDA, IERR )
2619 WORK( 1 ) = ONE / SCALE
2620 IF( SVA( 1 ).GE.SFMIN ) THEN
2621 WORK( 2 ) = ONE
2622 ELSE
2623 WORK( 2 ) = ZERO
2624 END IF
2625 WORK( 3 ) = ZERO
2626 WORK( 4 ) = ZERO
2627 WORK( 5 ) = ZERO
2628 WORK( 6 ) = ZERO
2629 RETURN
2630 END IF
2631 *
2632 * Protect small singular values from underflow, and try to
2633 * avoid underflows/overflows in computing Jacobi rotations.
2634 *
2635 SN = DSQRT( SFMIN / EPSILON )
2636 TEMP1 = DSQRT( BIG / DBLE( N ) )
2637 IF( ( AAPP.LE.SN ) .OR. ( AAQQ.GE.TEMP1 ) .OR.
2638 + ( ( SN.LE.AAQQ ) .AND. ( AAPP.LE.TEMP1 ) ) ) THEN
2639 TEMP1 = DMIN1( BIG, TEMP1 / AAPP )
2640 * AAQQ = AAQQ*TEMP1
2641 * AAPP = AAPP*TEMP1
2642 ELSE IF( ( AAQQ.LE.SN ) .AND. ( AAPP.LE.TEMP1 ) ) THEN
2643 TEMP1 = DMIN1( SN / AAQQ, BIG / ( AAPP*DSQRT( DBLE( N ) ) ) )
2644 * AAQQ = AAQQ*TEMP1
2645 * AAPP = AAPP*TEMP1
2646 ELSE IF( ( AAQQ.GE.SN ) .AND. ( AAPP.GE.TEMP1 ) ) THEN
2647 TEMP1 = DMAX1( SN / AAQQ, TEMP1 / AAPP )
2648 * AAQQ = AAQQ*TEMP1
2649 * AAPP = AAPP*TEMP1
2650 ELSE IF( ( AAQQ.LE.SN ) .AND. ( AAPP.GE.TEMP1 ) ) THEN
2651 TEMP1 = DMIN1( SN / AAQQ, BIG / ( DSQRT( DBLE( N ) )*AAPP ) )
2652 * AAQQ = AAQQ*TEMP1
2653 * AAPP = AAPP*TEMP1
2654 ELSE
2655 TEMP1 = ONE
2656 END IF
2657 *
2658 * Scale, if necessary
2659 *
2660 IF( TEMP1.NE.ONE ) THEN
2661 CALL DLASCL( 'G', 0, 0, ONE, TEMP1, N, 1, SVA, N, IERR )
2662 END IF
2663 SCALE = TEMP1*SCALE
2664 IF( SCALE.NE.ONE ) THEN
2665 CALL DLASCL( JOBA, 0, 0, ONE, SCALE, M, N, A, LDA, IERR )
2666 SCALE = ONE / SCALE
2667 END IF
2668 *
2669 * Row-cyclic Jacobi SVD algorithm with column pivoting
2670 *
2671 EMPTSW = ( N*( N-1 ) ) / 2
2672 NOTROT = 0
2673 FASTR( 1 ) = ZERO
2674 *
2675 * A is represented in factored form A = A * diag(WORK), where diag(WORK)
2676 * is initialized to identity. WORK is updated during fast scaled
2677 * rotations.
2678 *
2679 DO 1868 q = 1, N
2680 WORK( q ) = ONE
2681 1868 CONTINUE
2682 *
2683 *
2684 SWBAND = 3
2685 *[TP] SWBAND is a tuning parameter [TP]. It is meaningful and effective
2686 * if DGESVJ is used as a computational routine in the preconditioned
2687 * Jacobi SVD algorithm DGESVJ. For sweeps i=1:SWBAND the procedure
2688 * works on pivots inside a band-like region around the diagonal.
2689 * The boundaries are determined dynamically, based on the number of
2690 * pivots above a threshold.
2691 *
2692 KBL = MIN0( 8, N )
2693 *[TP] KBL is a tuning parameter that defines the tile size in the
2694 * tiling of the p-q loops of pivot pairs. In general, an optimal
2695 * value of KBL depends on the matrix dimensions and on the
2696 * parameters of the computer's memory.
2697 *
2698 NBL = N / KBL
2699 IF( ( NBL*KBL ).NE.N )NBL = NBL + 1
2700 *
2701 BLSKIP = KBL**2
2702 *[TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL.
2703 *
2704 ROWSKIP = MIN0( 5, KBL )
2705 *[TP] ROWSKIP is a tuning parameter.
2706 *
2707 LKAHEAD = 1
2708 *[TP] LKAHEAD is a tuning parameter.
2709 *
2710 * Quasi block transformations, using the lower (upper) triangular
2711 * structure of the input matrix. The quasi-block-cycling usually
2712 * invokes cubic convergence. Big part of this cycle is done inside
2713 * canonical subspaces of dimensions less than M.
2714 *
2715 IF( ( LOWER .OR. UPPER ) .AND. ( N.GT.MAX0( 64, 4*KBL ) ) ) THEN
2716 *[TP] The number of partition levels and the actual partition are
2717 * tuning parameters.
2718 N4 = N / 4
2719 N2 = N / 2
2720 N34 = 3*N4
2721 IF( APPLV ) THEN
2722 q = 0
2723 ELSE
2724 q = 1
2725 END IF
2726 *
2727 IF( LOWER ) THEN
2728 *
2729 * This works very well on lower triangular matrices, in particular
2730 * in the framework of the preconditioned Jacobi SVD (xGEJSV).
2731 * The idea is simple:
2732 * [+ 0 0 0] Note that Jacobi transformations of [0 0]
2733 * [+ + 0 0] [0 0]
2734 * [+ + x 0] actually work on [x 0] [x 0]
2735 * [+ + x x] [x x]. [x x]
2736 *
2737 CALL DGSVJ0( JOBV, M-N34, N-N34, A( N34+1, N34+1 ), LDA,
2738 + WORK( N34+1 ), SVA( N34+1 ), MVL,
2739 + V( N34*q+1, N34+1 ), LDV, EPSILON, SFMIN, TOL,
2740 + 2, WORK( N+1 ), LWORK-N, IERR )
2741 *
2742 CALL DGSVJ0( JOBV, M-N2, N34-N2, A( N2+1, N2+1 ), LDA,
2743 + WORK( N2+1 ), SVA( N2+1 ), MVL,
2744 + V( N2*q+1, N2+1 ), LDV, EPSILON, SFMIN, TOL, 2,
2745 + WORK( N+1 ), LWORK-N, IERR )
2746 *
2747 CALL DGSVJ1( JOBV, M-N2, N-N2, N4, A( N2+1, N2+1 ), LDA,
2748 + WORK( N2+1 ), SVA( N2+1 ), MVL,
2749 + V( N2*q+1, N2+1 ), LDV, EPSILON, SFMIN, TOL, 1,
2750 + WORK( N+1 ), LWORK-N, IERR )
2751 *
2752 CALL DGSVJ0( JOBV, M-N4, N2-N4, A( N4+1, N4+1 ), LDA,
2753 + WORK( N4+1 ), SVA( N4+1 ), MVL,
2754 + V( N4*q+1, N4+1 ), LDV, EPSILON, SFMIN, TOL, 1,
2755 + WORK( N+1 ), LWORK-N, IERR )
2756 *
2757 CALL DGSVJ0( JOBV, M, N4, A, LDA, WORK, SVA, MVL, V, LDV,
2758 + EPSILON, SFMIN, TOL, 1, WORK( N+1 ), LWORK-N,
2759 + IERR )
2760 *
2761 CALL DGSVJ1( JOBV, M, N2, N4, A, LDA, WORK, SVA, MVL, V,
2762 + LDV, EPSILON, SFMIN, TOL, 1, WORK( N+1 ),
2763 + LWORK-N, IERR )
2764 *
2765 *
2766 ELSE IF( UPPER ) THEN
2767 *
2768 *
2769 CALL DGSVJ0( JOBV, N4, N4, A, LDA, WORK, SVA, MVL, V, LDV,
2770 + EPSILON, SFMIN, TOL, 2, WORK( N+1 ), LWORK-N,
2771 + IERR )
2772 *
2773 CALL DGSVJ0( JOBV, N2, N4, A( 1, N4+1 ), LDA, WORK( N4+1 ),
2774 + SVA( N4+1 ), MVL, V( N4*q+1, N4+1 ), LDV,
2775 + EPSILON, SFMIN, TOL, 1, WORK( N+1 ), LWORK-N,
2776 + IERR )
2777 *
2778 CALL DGSVJ1( JOBV, N2, N2, N4, A, LDA, WORK, SVA, MVL, V,
2779 + LDV, EPSILON, SFMIN, TOL, 1, WORK( N+1 ),
2780 + LWORK-N, IERR )
2781 *
2782 CALL DGSVJ0( JOBV, N2+N4, N4, A( 1, N2+1 ), LDA,
2783 + WORK( N2+1 ), SVA( N2+1 ), MVL,
2784 + V( N2*q+1, N2+1 ), LDV, EPSILON, SFMIN, TOL, 1,
2785 + WORK( N+1 ), LWORK-N, IERR )
2786
2787 END IF
2788 *
2789 END IF
2790 *
2791 * .. Row-cyclic pivot strategy with de Rijk's pivoting ..
2792 *
2793 DO 1993 i = 1, NSWEEP
2794 *
2795 * .. go go go ...
2796 *
2797 MXAAPQ = ZERO
2798 MXSINJ = ZERO
2799 ISWROT = 0
2800 *
2801 NOTROT = 0
2802 PSKIPPED = 0
2803 *
2804 * Each sweep is unrolled using KBL-by-KBL tiles over the pivot pairs
2805 * 1 <= p < q <= N. This is the first step toward a blocked implementation
2806 * of the rotations. New implementation, based on block transformations,
2807 * is under development.
2808 *
2809 DO 2000 ibr = 1, NBL
2810 *
2811 igl = ( ibr-1 )*KBL + 1
2812 *
2813 DO 1002 ir1 = 0, MIN0( LKAHEAD, NBL-ibr )
2814 *
2815 igl = igl + ir1*KBL
2816 *
2817 DO 2001 p = igl, MIN0( igl+KBL-1, N-1 )
2818 *
2819 * .. de Rijk's pivoting
2820 *
2821 q = IDAMAX( N-p+1, SVA( p ), 1 ) + p - 1
2822 IF( p.NE.q ) THEN
2823 CALL DSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
2824 IF( RSVEC )CALL DSWAP( MVL, V( 1, p ), 1,
2825 + V( 1, q ), 1 )
2826 TEMP1 = SVA( p )
2827 SVA( p ) = SVA( q )
2828 SVA( q ) = TEMP1
2829 TEMP1 = WORK( p )
2830 WORK( p ) = WORK( q )
2831 WORK( q ) = TEMP1
2832 END IF
2833 *
2834 IF( ir1.EQ.0 ) THEN
2835 *
2836 * Column norms are periodically updated by explicit
2837 * norm computation.
2838 * Caveat:
2839 * Unfortunately, some BLAS implementations compute DNRM2(M,A(1,p),1)
2840 * as DSQRT(DDOT(M,A(1,p),1,A(1,p),1)), which may cause the result to
2841 * overflow for ||A(:,p)||_2 > DSQRT(overflow_threshold), and to
2842 * underflow for ||A(:,p)||_2 < DSQRT(underflow_threshold).
2843 * Hence, DNRM2 cannot be trusted, not even in the case when
2844 * the true norm is far from the under(over)flow boundaries.
2845 * If properly implemented DNRM2 is available, the IF-THEN-ELSE
2846 * below should read "AAPP = DNRM2( M, A(1,p), 1 ) * WORK(p)".
2847 *
2848 IF( ( SVA( p ).LT.ROOTBIG ) .AND.
2849 + ( SVA( p ).GT.ROOTSFMIN ) ) THEN
2850 SVA( p ) = DNRM2( M, A( 1, p ), 1 )*WORK( p )
2851 ELSE
2852 TEMP1 = ZERO
2853 AAPP = ZERO
2854 CALL DLASSQ( M, A( 1, p ), 1, TEMP1, AAPP )
2855 SVA( p ) = TEMP1*DSQRT( AAPP )*WORK( p )
2856 END IF
2857 AAPP = SVA( p )
2858 ELSE
2859 AAPP = SVA( p )
2860 END IF
2861 *
2862 IF( AAPP.GT.ZERO ) THEN
2863 *
2864 PSKIPPED = 0
2865 *
2866 DO 2002 q = p + 1, MIN0( igl+KBL-1, N )
2867 *
2868 AAQQ = SVA( q )
2869 *
2870 IF( AAQQ.GT.ZERO ) THEN
2871 *
2872 AAPP0 = AAPP
2873 IF( AAQQ.GE.ONE ) THEN
2874 ROTOK = ( SMALL*AAPP ).LE.AAQQ
2875 IF( AAPP.LT.( BIG / AAQQ ) ) THEN
2876 AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
2877 + q ), 1 )*WORK( p )*WORK( q ) /
2878 + AAQQ ) / AAPP
2879 ELSE
2880 CALL DCOPY( M, A( 1, p ), 1,
2881 + WORK( N+1 ), 1 )
2882 CALL DLASCL( 'G', 0, 0, AAPP,
2883 + WORK( p ), M, 1,
2884 + WORK( N+1 ), LDA, IERR )
2885 AAPQ = DDOT( M, WORK( N+1 ), 1,
2886 + A( 1, q ), 1 )*WORK( q ) / AAQQ
2887 END IF
2888 ELSE
2889 ROTOK = AAPP.LE.( AAQQ / SMALL )
2890 IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
2891 AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
2892 + q ), 1 )*WORK( p )*WORK( q ) /
2893 + AAQQ ) / AAPP
2894 ELSE
2895 CALL DCOPY( M, A( 1, q ), 1,
2896 + WORK( N+1 ), 1 )
2897 CALL DLASCL( 'G', 0, 0, AAQQ,
2898 + WORK( q ), M, 1,
2899 + WORK( N+1 ), LDA, IERR )
2900 AAPQ = DDOT( M, WORK( N+1 ), 1,
2901 + A( 1, p ), 1 )*WORK( p ) / AAPP
2902 END IF
2903 END IF
2904 *
2905 MXAAPQ = DMAX1( MXAAPQ, DABS( AAPQ ) )
2906 *
2907 * TO rotate or NOT to rotate, THAT is the question ...
2908 *
2909 IF( DABS( AAPQ ).GT.TOL ) THEN
2910 *
2911 * .. rotate
2912 *[RTD] ROTATED = ROTATED + ONE
2913 *
2914 IF( ir1.EQ.0 ) THEN
2915 NOTROT = 0
2916 PSKIPPED = 0
2917 ISWROT = ISWROT + 1
2918 END IF
2919 *
2920 IF( ROTOK ) THEN
2921 *
2922 AQOAP = AAQQ / AAPP
2923 APOAQ = AAPP / AAQQ
2924 THETA = -HALF*DABS( AQOAP-APOAQ ) /
2925 + AAPQ
2926 *
2927 IF( DABS( THETA ).GT.BIGTHETA ) THEN
2928 *
2929 T = HALF / THETA
2930 FASTR( 3 ) = T*WORK( p ) / WORK( q )
2931 FASTR( 4 ) = -T*WORK( q ) /
2932 + WORK( p )
2933 CALL DROTM( M, A( 1, p ), 1,
2934 + A( 1, q ), 1, FASTR )
2935 IF( RSVEC )CALL DROTM( MVL,
2936 + V( 1, p ), 1,
2937 + V( 1, q ), 1,
2938 + FASTR )
2939 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
2940 + ONE+T*APOAQ*AAPQ ) )
2941 AAPP = AAPP*DSQRT( ONE-T*AQOAP*
2942 + AAPQ )
2943 MXSINJ = DMAX1( MXSINJ, DABS( T ) )
2944 *
2945 ELSE
2946 *
2947 * .. choose correct signum for THETA and rotate
2948 *
2949 THSIGN = -DSIGN( ONE, AAPQ )
2950 T = ONE / ( THETA+THSIGN*
2951 + DSQRT( ONE+THETA*THETA ) )
2952 CS = DSQRT( ONE / ( ONE+T*T ) )
2953 SN = T*CS
2954 *
2955 MXSINJ = DMAX1( MXSINJ, DABS( SN ) )
2956 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
2957 + ONE+T*APOAQ*AAPQ ) )
2958 AAPP = AAPP*DSQRT( DMAX1( ZERO,
2959 + ONE-T*AQOAP*AAPQ ) )
2960 *
2961 APOAQ = WORK( p ) / WORK( q )
2962 AQOAP = WORK( q ) / WORK( p )
2963 IF( WORK( p ).GE.ONE ) THEN
2964 IF( WORK( q ).GE.ONE ) THEN
2965 FASTR( 3 ) = T*APOAQ
2966 FASTR( 4 ) = -T*AQOAP
2967 WORK( p ) = WORK( p )*CS
2968 WORK( q ) = WORK( q )*CS
2969 CALL DROTM( M, A( 1, p ), 1,
2970 + A( 1, q ), 1,
2971 + FASTR )
2972 IF( RSVEC )CALL DROTM( MVL,
2973 + V( 1, p ), 1, V( 1, q ),
2974 + 1, FASTR )
2975 ELSE
2976 CALL DAXPY( M, -T*AQOAP,
2977 + A( 1, q ), 1,
2978 + A( 1, p ), 1 )
2979 CALL DAXPY( M, CS*SN*APOAQ,
2980 + A( 1, p ), 1,
2981 + A( 1, q ), 1 )
2982 WORK( p ) = WORK( p )*CS
2983 WORK( q ) = WORK( q ) / CS
2984 IF( RSVEC ) THEN
2985 CALL DAXPY( MVL, -T*AQOAP,
2986 + V( 1, q ), 1,
2987 + V( 1, p ), 1 )
2988 CALL DAXPY( MVL,
2989 + CS*SN*APOAQ,
2990 + V( 1, p ), 1,
2991 + V( 1, q ), 1 )
2992 END IF
2993 END IF
2994 ELSE
2995 IF( WORK( q ).GE.ONE ) THEN
2996 CALL DAXPY( M, T*APOAQ,
2997 + A( 1, p ), 1,
2998 + A( 1, q ), 1 )
2999 CALL DAXPY( M, -CS*SN*AQOAP,
3000 + A( 1, q ), 1,
3001 + A( 1, p ), 1 )
3002 WORK( p ) = WORK( p ) / CS
3003 WORK( q ) = WORK( q )*CS
3004 IF( RSVEC ) THEN
3005 CALL DAXPY( MVL, T*APOAQ,
3006 + V( 1, p ), 1,
3007 + V( 1, q ), 1 )
3008 CALL DAXPY( MVL,
3009 + -CS*SN*AQOAP,
3010 + V( 1, q ), 1,
3011 + V( 1, p ), 1 )
3012 END IF
3013 ELSE
3014 IF( WORK( p ).GE.WORK( q ) )
3015 + THEN
3016 CALL DAXPY( M, -T*AQOAP,
3017 + A( 1, q ), 1,
3018 + A( 1, p ), 1 )
3019 CALL DAXPY( M, CS*SN*APOAQ,
3020 + A( 1, p ), 1,
3021 + A( 1, q ), 1 )
3022 WORK( p ) = WORK( p )*CS
3023 WORK( q ) = WORK( q ) / CS
3024 IF( RSVEC ) THEN
3025 CALL DAXPY( MVL,
3026 + -T*AQOAP,
3027 + V( 1, q ), 1,
3028 + V( 1, p ), 1 )
3029 CALL DAXPY( MVL,
3030 + CS*SN*APOAQ,
3031 + V( 1, p ), 1,
3032 + V( 1, q ), 1 )
3033 END IF
3034 ELSE
3035 CALL DAXPY( M, T*APOAQ,
3036 + A( 1, p ), 1,
3037 + A( 1, q ), 1 )
3038 CALL DAXPY( M,
3039 + -CS*SN*AQOAP,
3040 + A( 1, q ), 1,
3041 + A( 1, p ), 1 )
3042 WORK( p ) = WORK( p ) / CS
3043 WORK( q ) = WORK( q )*CS
3044 IF( RSVEC ) THEN
3045 CALL DAXPY( MVL,
3046 + T*APOAQ, V( 1, p ),
3047 + 1, V( 1, q ), 1 )
3048 CALL DAXPY( MVL,
3049 + -CS*SN*AQOAP,
3050 + V( 1, q ), 1,
3051 + V( 1, p ), 1 )
3052 END IF
3053 END IF
3054 END IF
3055 END IF
3056 END IF
3057 *
3058 ELSE
3059 * .. have to use modified Gram-Schmidt like transformation
3060 CALL DCOPY( M, A( 1, p ), 1,
3061 + WORK( N+1 ), 1 )
3062 CALL DLASCL( 'G', 0, 0, AAPP, ONE, M,
3063 + 1, WORK( N+1 ), LDA,
3064 + IERR )
3065 CALL DLASCL( 'G', 0, 0, AAQQ, ONE, M,
3066 + 1, A( 1, q ), LDA, IERR )
3067 TEMP1 = -AAPQ*WORK( p ) / WORK( q )
3068 CALL DAXPY( M, TEMP1, WORK( N+1 ), 1,
3069 + A( 1, q ), 1 )
3070 CALL DLASCL( 'G', 0, 0, ONE, AAQQ, M,
3071 + 1, A( 1, q ), LDA, IERR )
3072 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
3073 + ONE-AAPQ*AAPQ ) )
3074 MXSINJ = DMAX1( MXSINJ, SFMIN )
3075 END IF
3076 * END IF ROTOK THEN ... ELSE
3077 *
3078 * In the case of cancellation in updating SVA(q), SVA(p)
3079 * recompute SVA(q), SVA(p).
3080 *
3081 IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
3082 + THEN
3083 IF( ( AAQQ.LT.ROOTBIG ) .AND.
3084 + ( AAQQ.GT.ROOTSFMIN ) ) THEN
3085 SVA( q ) = DNRM2( M, A( 1, q ), 1 )*
3086 + WORK( q )
3087 ELSE
3088 T = ZERO
3089 AAQQ = ZERO
3090 CALL DLASSQ( M, A( 1, q ), 1, T,
3091 + AAQQ )
3092 SVA( q ) = T*DSQRT( AAQQ )*WORK( q )
3093 END IF
3094 END IF
3095 IF( ( AAPP / AAPP0 ).LE.ROOTEPS ) THEN
3096 IF( ( AAPP.LT.ROOTBIG ) .AND.
3097 + ( AAPP.GT.ROOTSFMIN ) ) THEN
3098 AAPP = DNRM2( M, A( 1, p ), 1 )*
3099 + WORK( p )
3100 ELSE
3101 T = ZERO
3102 AAPP = ZERO
3103 CALL DLASSQ( M, A( 1, p ), 1, T,
3104 + AAPP )
3105 AAPP = T*DSQRT( AAPP )*WORK( p )
3106 END IF
3107 SVA( p ) = AAPP
3108 END IF
3109 *
3110 ELSE
3111 * A(:,p) and A(:,q) already numerically orthogonal
3112 IF( ir1.EQ.0 )NOTROT = NOTROT + 1
3113 *[RTD] SKIPPED = SKIPPED + 1
3114 PSKIPPED = PSKIPPED + 1
3115 END IF
3116 ELSE
3117 * A(:,q) is zero column
3118 IF( ir1.EQ.0 )NOTROT = NOTROT + 1
3119 PSKIPPED = PSKIPPED + 1
3120 END IF
3121 *
3122 IF( ( i.LE.SWBAND ) .AND.
3123 + ( PSKIPPED.GT.ROWSKIP ) ) THEN
3124 IF( ir1.EQ.0 )AAPP = -AAPP
3125 NOTROT = 0
3126 GO TO 2103
3127 END IF
3128 *
3129 2002 CONTINUE
3130 * END q-LOOP
3131 *
3132 2103 CONTINUE
3133 * bailed out of q-loop
3134 *
3135 SVA( p ) = AAPP
3136 *
3137 ELSE
3138 SVA( p ) = AAPP
3139 IF( ( ir1.EQ.0 ) .AND. ( AAPP.EQ.ZERO ) )
3140 + NOTROT = NOTROT + MIN0( igl+KBL-1, N ) - p
3141 END IF
3142 *
3143 2001 CONTINUE
3144 * end of the p-loop
3145 * end of doing the block ( ibr, ibr )
3146 1002 CONTINUE
3147 * end of ir1-loop
3148 *
3149 * ... go to the off diagonal blocks
3150 *
3151 igl = ( ibr-1 )*KBL + 1
3152 *
3153 DO 2010 jbc = ibr + 1, NBL
3154 *
3155 jgl = ( jbc-1 )*KBL + 1
3156 *
3157 * doing the block at ( ibr, jbc )
3158 *
3159 IJBLSK = 0
3160 DO 2100 p = igl, MIN0( igl+KBL-1, N )
3161 *
3162 AAPP = SVA( p )
3163 IF( AAPP.GT.ZERO ) THEN
3164 *
3165 PSKIPPED = 0
3166 *
3167 DO 2200 q = jgl, MIN0( jgl+KBL-1, N )
3168 *
3169 AAQQ = SVA( q )
3170 IF( AAQQ.GT.ZERO ) THEN
3171 AAPP0 = AAPP
3172 *
3173 * .. M x 2 Jacobi SVD ..
3174 *
3175 * Safe Gram matrix computation
3176 *
3177 IF( AAQQ.GE.ONE ) THEN
3178 IF( AAPP.GE.AAQQ ) THEN
3179 ROTOK = ( SMALL*AAPP ).LE.AAQQ
3180 ELSE
3181 ROTOK = ( SMALL*AAQQ ).LE.AAPP
3182 END IF
3183 IF( AAPP.LT.( BIG / AAQQ ) ) THEN
3184 AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
3185 + q ), 1 )*WORK( p )*WORK( q ) /
3186 + AAQQ ) / AAPP
3187 ELSE
3188 CALL DCOPY( M, A( 1, p ), 1,
3189 + WORK( N+1 ), 1 )
3190 CALL DLASCL( 'G', 0, 0, AAPP,
3191 + WORK( p ), M, 1,
3192 + WORK( N+1 ), LDA, IERR )
3193 AAPQ = DDOT( M, WORK( N+1 ), 1,
3194 + A( 1, q ), 1 )*WORK( q ) / AAQQ
3195 END IF
3196 ELSE
3197 IF( AAPP.GE.AAQQ ) THEN
3198 ROTOK = AAPP.LE.( AAQQ / SMALL )
3199 ELSE
3200 ROTOK = AAQQ.LE.( AAPP / SMALL )
3201 END IF
3202 IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
3203 AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
3204 + q ), 1 )*WORK( p )*WORK( q ) /
3205 + AAQQ ) / AAPP
3206 ELSE
3207 CALL DCOPY( M, A( 1, q ), 1,
3208 + WORK( N+1 ), 1 )
3209 CALL DLASCL( 'G', 0, 0, AAQQ,
3210 + WORK( q ), M, 1,
3211 + WORK( N+1 ), LDA, IERR )
3212 AAPQ = DDOT( M, WORK( N+1 ), 1,
3213 + A( 1, p ), 1 )*WORK( p ) / AAPP
3214 END IF
3215 END IF
3216 *
3217 MXAAPQ = DMAX1( MXAAPQ, DABS( AAPQ ) )
3218 *
3219 * TO rotate or NOT to rotate, THAT is the question ...
3220 *
3221 IF( DABS( AAPQ ).GT.TOL ) THEN
3222 NOTROT = 0
3223 *[RTD] ROTATED = ROTATED + 1
3224 PSKIPPED = 0
3225 ISWROT = ISWROT + 1
3226 *
3227 IF( ROTOK ) THEN
3228 *
3229 AQOAP = AAQQ / AAPP
3230 APOAQ = AAPP / AAQQ
3231 THETA = -HALF*DABS( AQOAP-APOAQ ) /
3232 + AAPQ
3233 IF( AAQQ.GT.AAPP0 )THETA = -THETA
3234 *
3235 IF( DABS( THETA ).GT.BIGTHETA ) THEN
3236 T = HALF / THETA
3237 FASTR( 3 ) = T*WORK( p ) / WORK( q )
3238 FASTR( 4 ) = -T*WORK( q ) /
3239 + WORK( p )
3240 CALL DROTM( M, A( 1, p ), 1,
3241 + A( 1, q ), 1, FASTR )
3242 IF( RSVEC )CALL DROTM( MVL,
3243 + V( 1, p ), 1,
3244 + V( 1, q ), 1,
3245 + FASTR )
3246 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
3247 + ONE+T*APOAQ*AAPQ ) )
3248 AAPP = AAPP*DSQRT( DMAX1( ZERO,
3249 + ONE-T*AQOAP*AAPQ ) )
3250 MXSINJ = DMAX1( MXSINJ, DABS( T ) )
3251 ELSE
3252 *
3253 * .. choose correct signum for THETA and rotate
3254 *
3255 THSIGN = -DSIGN( ONE, AAPQ )
3256 IF( AAQQ.GT.AAPP0 )THSIGN = -THSIGN
3257 T = ONE / ( THETA+THSIGN*
3258 + DSQRT( ONE+THETA*THETA ) )
3259 CS = DSQRT( ONE / ( ONE+T*T ) )
3260 SN = T*CS
3261 MXSINJ = DMAX1( MXSINJ, DABS( SN ) )
3262 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
3263 + ONE+T*APOAQ*AAPQ ) )
3264 AAPP = AAPP*DSQRT( ONE-T*AQOAP*
3265 + AAPQ )
3266 *
3267 APOAQ = WORK( p ) / WORK( q )
3268 AQOAP = WORK( q ) / WORK( p )
3269 IF( WORK( p ).GE.ONE ) THEN
3270 *
3271 IF( WORK( q ).GE.ONE ) THEN
3272 FASTR( 3 ) = T*APOAQ
3273 FASTR( 4 ) = -T*AQOAP
3274 WORK( p ) = WORK( p )*CS
3275 WORK( q ) = WORK( q )*CS
3276 CALL DROTM( M, A( 1, p ), 1,
3277 + A( 1, q ), 1,
3278 + FASTR )
3279 IF( RSVEC )CALL DROTM( MVL,
3280 + V( 1, p ), 1, V( 1, q ),
3281 + 1, FASTR )
3282 ELSE
3283 CALL DAXPY( M, -T*AQOAP,
3284 + A( 1, q ), 1,
3285 + A( 1, p ), 1 )
3286 CALL DAXPY( M, CS*SN*APOAQ,
3287 + A( 1, p ), 1,
3288 + A( 1, q ), 1 )
3289 IF( RSVEC ) THEN
3290 CALL DAXPY( MVL, -T*AQOAP,
3291 + V( 1, q ), 1,
3292 + V( 1, p ), 1 )
3293 CALL DAXPY( MVL,
3294 + CS*SN*APOAQ,
3295 + V( 1, p ), 1,
3296 + V( 1, q ), 1 )
3297 END IF
3298 WORK( p ) = WORK( p )*CS
3299 WORK( q ) = WORK( q ) / CS
3300 END IF
3301 ELSE
3302 IF( WORK( q ).GE.ONE ) THEN
3303 CALL DAXPY( M, T*APOAQ,
3304 + A( 1, p ), 1,
3305 + A( 1, q ), 1 )
3306 CALL DAXPY( M, -CS*SN*AQOAP,
3307 + A( 1, q ), 1,
3308 + A( 1, p ), 1 )
3309 IF( RSVEC ) THEN
3310 CALL DAXPY( MVL, T*APOAQ,
3311 + V( 1, p ), 1,
3312 + V( 1, q ), 1 )
3313 CALL DAXPY( MVL,
3314 + -CS*SN*AQOAP,
3315 + V( 1, q ), 1,
3316 + V( 1, p ), 1 )
3317 END IF
3318 WORK( p ) = WORK( p ) / CS
3319 WORK( q ) = WORK( q )*CS
3320 ELSE
3321 IF( WORK( p ).GE.WORK( q ) )
3322 + THEN
3323 CALL DAXPY( M, -T*AQOAP,
3324 + A( 1, q ), 1,
3325 + A( 1, p ), 1 )
3326 CALL DAXPY( M, CS*SN*APOAQ,
3327 + A( 1, p ), 1,
3328 + A( 1, q ), 1 )
3329 WORK( p ) = WORK( p )*CS
3330 WORK( q ) = WORK( q ) / CS
3331 IF( RSVEC ) THEN
3332 CALL DAXPY( MVL,
3333 + -T*AQOAP,
3334 + V( 1, q ), 1,
3335 + V( 1, p ), 1 )
3336 CALL DAXPY( MVL,
3337 + CS*SN*APOAQ,
3338 + V( 1, p ), 1,
3339 + V( 1, q ), 1 )
3340 END IF
3341 ELSE
3342 CALL DAXPY( M, T*APOAQ,
3343 + A( 1, p ), 1,
3344 + A( 1, q ), 1 )
3345 CALL DAXPY( M,
3346 + -CS*SN*AQOAP,
3347 + A( 1, q ), 1,
3348 + A( 1, p ), 1 )
3349 WORK( p ) = WORK( p ) / CS
3350 WORK( q ) = WORK( q )*CS
3351 IF( RSVEC ) THEN
3352 CALL DAXPY( MVL,
3353 + T*APOAQ, V( 1, p ),
3354 + 1, V( 1, q ), 1 )
3355 CALL DAXPY( MVL,
3356 + -CS*SN*AQOAP,
3357 + V( 1, q ), 1,
3358 + V( 1, p ), 1 )
3359 END IF
3360 END IF
3361 END IF
3362 END IF
3363 END IF
3364 *
3365 ELSE
3366 IF( AAPP.GT.AAQQ ) THEN
3367 CALL DCOPY( M, A( 1, p ), 1,
3368 + WORK( N+1 ), 1 )
3369 CALL DLASCL( 'G', 0, 0, AAPP, ONE,
3370 + M, 1, WORK( N+1 ), LDA,
3371 + IERR )
3372 CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
3373 + M, 1, A( 1, q ), LDA,
3374 + IERR )
3375 TEMP1 = -AAPQ*WORK( p ) / WORK( q )
3376 CALL DAXPY( M, TEMP1, WORK( N+1 ),
3377 + 1, A( 1, q ), 1 )
3378 CALL DLASCL( 'G', 0, 0, ONE, AAQQ,
3379 + M, 1, A( 1, q ), LDA,
3380 + IERR )
3381 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
3382 + ONE-AAPQ*AAPQ ) )
3383 MXSINJ = DMAX1( MXSINJ, SFMIN )
3384 ELSE
3385 CALL DCOPY( M, A( 1, q ), 1,
3386 + WORK( N+1 ), 1 )
3387 CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
3388 + M, 1, WORK( N+1 ), LDA,
3389 + IERR )
3390 CALL DLASCL( 'G', 0, 0, AAPP, ONE,
3391 + M, 1, A( 1, p ), LDA,
3392 + IERR )
3393 TEMP1 = -AAPQ*WORK( q ) / WORK( p )
3394 CALL DAXPY( M, TEMP1, WORK( N+1 ),
3395 + 1, A( 1, p ), 1 )
3396 CALL DLASCL( 'G', 0, 0, ONE, AAPP,
3397 + M, 1, A( 1, p ), LDA,
3398 + IERR )
3399 SVA( p ) = AAPP*DSQRT( DMAX1( ZERO,
3400 + ONE-AAPQ*AAPQ ) )
3401 MXSINJ = DMAX1( MXSINJ, SFMIN )
3402 END IF
3403 END IF
3404 * END IF ROTOK THEN ... ELSE
3405 *
3406 * In the case of cancellation in updating SVA(q)
3407 * .. recompute SVA(q)
3408 IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
3409 + THEN
3410 IF( ( AAQQ.LT.ROOTBIG ) .AND.
3411 + ( AAQQ.GT.ROOTSFMIN ) ) THEN
3412 SVA( q ) = DNRM2( M, A( 1, q ), 1 )*
3413 + WORK( q )
3414 ELSE
3415 T = ZERO
3416 AAQQ = ZERO
3417 CALL DLASSQ( M, A( 1, q ), 1, T,
3418 + AAQQ )
3419 SVA( q ) = T*DSQRT( AAQQ )*WORK( q )
3420 END IF
3421 END IF
3422 IF( ( AAPP / AAPP0 )**2.LE.ROOTEPS ) THEN
3423 IF( ( AAPP.LT.ROOTBIG ) .AND.
3424 + ( AAPP.GT.ROOTSFMIN ) ) THEN
3425 AAPP = DNRM2( M, A( 1, p ), 1 )*
3426 + WORK( p )
3427 ELSE
3428 T = ZERO
3429 AAPP = ZERO
3430 CALL DLASSQ( M, A( 1, p ), 1, T,
3431 + AAPP )
3432 AAPP = T*DSQRT( AAPP )*WORK( p )
3433 END IF
3434 SVA( p ) = AAPP
3435 END IF
3436 * end of OK rotation
3437 ELSE
3438 NOTROT = NOTROT + 1
3439 *[RTD] SKIPPED = SKIPPED + 1
3440 PSKIPPED = PSKIPPED + 1
3441 IJBLSK = IJBLSK + 1
3442 END IF
3443 ELSE
3444 NOTROT = NOTROT + 1
3445 PSKIPPED = PSKIPPED + 1
3446 IJBLSK = IJBLSK + 1
3447 END IF
3448 *
3449 IF( ( i.LE.SWBAND ) .AND. ( IJBLSK.GE.BLSKIP ) )
3450 + THEN
3451 SVA( p ) = AAPP
3452 NOTROT = 0
3453 GO TO 2011
3454 END IF
3455 IF( ( i.LE.SWBAND ) .AND.
3456 + ( PSKIPPED.GT.ROWSKIP ) ) THEN
3457 AAPP = -AAPP
3458 NOTROT = 0
3459 GO TO 2203
3460 END IF
3461 *
3462 2200 CONTINUE
3463 * end of the q-loop
3464 2203 CONTINUE
3465 *
3466 SVA( p ) = AAPP
3467 *
3468 ELSE
3469 *
3470 IF( AAPP.EQ.ZERO )NOTROT = NOTROT +
3471 + MIN0( jgl+KBL-1, N ) - jgl + 1
3472 IF( AAPP.LT.ZERO )NOTROT = 0
3473 *
3474 END IF
3475 *
3476 2100 CONTINUE
3477 * end of the p-loop
3478 2010 CONTINUE
3479 * end of the jbc-loop
3480 2011 CONTINUE
3481 *2011 bailed out of the jbc-loop
3482 DO 2012 p = igl, MIN0( igl+KBL-1, N )
3483 SVA( p ) = DABS( SVA( p ) )
3484 2012 CONTINUE
3485 ***
3486 2000 CONTINUE
3487 *2000 :: end of the ibr-loop
3488 *
3489 * .. update SVA(N)
3490 IF( ( SVA( N ).LT.ROOTBIG ) .AND. ( SVA( N ).GT.ROOTSFMIN ) )
3491 + THEN
3492 SVA( N ) = DNRM2( M, A( 1, N ), 1 )*WORK( N )
3493 ELSE
3494 T = ZERO
3495 AAPP = ZERO
3496 CALL DLASSQ( M, A( 1, N ), 1, T, AAPP )
3497 SVA( N ) = T*DSQRT( AAPP )*WORK( N )
3498 END IF
3499 *
3500 * Additional steering devices
3501 *
3502 IF( ( i.LT.SWBAND ) .AND. ( ( MXAAPQ.LE.ROOTTOL ) .OR.
3503 + ( ISWROT.LE.N ) ) )SWBAND = i
3504 *
3505 IF( ( i.GT.SWBAND+1 ) .AND. ( MXAAPQ.LT.DSQRT( DBLE( N ) )*
3506 + TOL ) .AND. ( DBLE( N )*MXAAPQ*MXSINJ.LT.TOL ) ) THEN
3507 GO TO 1994
3508 END IF
3509 *
3510 IF( NOTROT.GE.EMPTSW )GO TO 1994
3511 *
3512 1993 CONTINUE
3513 * end i=1:NSWEEP loop
3514 *
3515 * #:( Reaching this point means that the procedure has not converged.
3516 INFO = NSWEEP - 1
3517 GO TO 1995
3518 *
3519 1994 CONTINUE
3520 * #:) Reaching this point means numerical convergence after the i-th
3521 * sweep.
3522 *
3523 INFO = 0
3524 * #:) INFO = 0 confirms successful iterations.
3525 1995 CONTINUE
3526 *
3527 * Sort the singular values and find how many are above
3528 * the underflow threshold.
3529 *
3530 N2 = 0
3531 N4 = 0
3532 DO 5991 p = 1, N - 1
3533 q = IDAMAX( N-p+1, SVA( p ), 1 ) + p - 1
3534 IF( p.NE.q ) THEN
3535 TEMP1 = SVA( p )
3536 SVA( p ) = SVA( q )
3537 SVA( q ) = TEMP1
3538 TEMP1 = WORK( p )
3539 WORK( p ) = WORK( q )
3540 WORK( q ) = TEMP1
3541 CALL DSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
3542 IF( RSVEC )CALL DSWAP( MVL, V( 1, p ), 1, V( 1, q ), 1 )
3543 END IF
3544 IF( SVA( p ).NE.ZERO ) THEN
3545 N4 = N4 + 1
3546 IF( SVA( p )*SCALE.GT.SFMIN )N2 = N2 + 1
3547 END IF
3548 5991 CONTINUE
3549 IF( SVA( N ).NE.ZERO ) THEN
3550 N4 = N4 + 1
3551 IF( SVA( N )*SCALE.GT.SFMIN )N2 = N2 + 1
3552 END IF
3553 *
3554 * Normalize the left singular vectors.
3555 *
3556 IF( LSVEC .OR. UCTOL ) THEN
3557 DO 1998 p = 1, N2
3558 CALL DSCAL( M, WORK( p ) / SVA( p ), A( 1, p ), 1 )
3559 1998 CONTINUE
3560 END IF
3561 *
3562 * Scale the product of Jacobi rotations (assemble the fast rotations).
3563 *
3564 IF( RSVEC ) THEN
3565 IF( APPLV ) THEN
3566 DO 2398 p = 1, N
3567 CALL DSCAL( MVL, WORK( p ), V( 1, p ), 1 )
3568 2398 CONTINUE
3569 ELSE
3570 DO 2399 p = 1, N
3571 TEMP1 = ONE / DNRM2( MVL, V( 1, p ), 1 )
3572 CALL DSCAL( MVL, TEMP1, V( 1, p ), 1 )
3573 2399 CONTINUE
3574 END IF
3575 END IF
3576 *
3577 * Undo scaling, if necessary (and possible).
3578 IF( ( ( SCALE.GT.ONE ) .AND. ( SVA( 1 ).LT.( BIG /
3579 + SCALE ) ) ) .OR. ( ( SCALE.LT.ONE ) .AND. ( SVA( N2 ).GT.
3580 + ( SFMIN / SCALE ) ) ) ) THEN
3581 DO 2400 p = 1, N
3582 SVA( p ) = SCALE*SVA( p )
3583 2400 CONTINUE
3584 SCALE = ONE
3585 END IF
3586 *
3587 WORK( 1 ) = SCALE
3588 * The singular values of A are SCALE*SVA(1:N). If SCALE.NE.ONE
3589 * then some of the singular values may overflow or underflow and
3590 * the spectrum is given in this factored representation.
3591 *
3592 WORK( 2 ) = DBLE( N4 )
3593 * N4 is the number of computed nonzero singular values of A.
3594 *
3595 WORK( 3 ) = DBLE( N2 )
3596 * N2 is the number of singular values of A greater than SFMIN.
3597 * If N2<N, SVA(N2:N) contains ZEROS and/or denormalized numbers
3598 * that may carry some information.
3599 *
3600 WORK( 4 ) = DBLE( i )
3601 * i is the index of the last sweep before declaring convergence.
3602 *
3603 WORK( 5 ) = MXAAPQ
3604 * MXAAPQ is the largest absolute value of scaled pivots in the
3605 * last sweep
3606 *
3607 WORK( 6 ) = MXSINJ
3608 * MXSINJ is the largest absolute value of the sines of Jacobi angles
3609 * in the last sweep
3610 *
3611 RETURN
3612 * ..
3613 * .. END OF DGESVJ
3614 * ..
3615 END
3616 C
3617 C-----------------------------------------------------------------------
3618 C-----------------------------------------------------------------------
3619 SUBROUTINE DGSVJ0( JOBV, M, N, A, LDA, D, SVA, MV, V, LDV, EPS,
3620 + SFMIN, TOL, NSWEEP, WORK, LWORK, INFO )
3621 *
3622 * -- LAPACK routine (version 3.2.2) --
3623 *
3624 * -- Contributed by Zlatko Drmac of the University of Zagreb and --
3625 * -- Kresimir Veselic of the Fernuniversitaet Hagen --
3626 * -- June 2010 --
3627 *
3628 * -- LAPACK is a software package provided by Univ. of Tennessee, --
3629 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
3630 *
3631 * This routine is also part of SIGMA (version 1.23, October 23. 2008.)
3632 * SIGMA is a library of algorithms for highly accurate algorithms for
3633 * computation of SVD, PSVD, QSVD, (H,K)-SVD, and for solution of the
3634 * eigenvalue problems Hx = lambda M x, H M x = lambda x with H, M > 0.
3635 *
3636 IMPLICIT NONE
3637 * .. Scalar Arguments ..
3638 INTEGER INFO, LDA, LDV, LWORK, M, MV, N, NSWEEP
3639 DOUBLE PRECISION EPS, SFMIN, TOL
3640 CHARACTER*1 JOBV
3641 * ..
3642 * .. Array Arguments ..
3643 DOUBLE PRECISION A( LDA, * ), SVA( N ), D( N ), V( LDV, * ),
3644 + WORK( LWORK )
3645 * ..
3646 *
3647 * Purpose
3648 * =======
3649 *
3650 * DGSVJ0 is called from DGESVJ as a pre-processor and that is its main
3651 * purpose. It applies Jacobi rotations in the same way as DGESVJ does, but
3652 * it does not check convergence (stopping criterion). Few tuning
3653 * parameters (marked by [TP]) are available for the implementer.
3654 *
3655 * Further Details
3656 * ~~~~~~~~~~~~~~~
3657 * DGSVJ0 is used just to enable SGESVJ to call a simplified version of
3658 * itself to work on a submatrix of the original matrix.
3659 *
3660 * Contributors
3661 * ~~~~~~~~~~~~
3662 * Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany)
3663 *
3664 * Bugs, Examples and Comments
3665 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
3666 * Please report all bugs and send interesting test examples and comments to
3667 * [email protected]. Thank you.
3668 *
3669 * Arguments
3670 * =========
3671 *
3672 * JOBV (input) CHARACTER*1
3673 * Specifies whether the output from this procedure is used
3674 * to compute the matrix V:
3675 * = 'V': the product of the Jacobi rotations is accumulated
3676 * by postmulyiplying the N-by-N array V.
3677 * (See the description of V.)
3678 * = 'A': the product of the Jacobi rotations is accumulated
3679 * by postmulyiplying the MV-by-N array V.
3680 * (See the descriptions of MV and V.)
3681 * = 'N': the Jacobi rotations are not accumulated.
3682 *
3683 * M (input) INTEGER
3684 * The number of rows of the input matrix A. M >= 0.
3685 *
3686 * N (input) INTEGER
3687 * The number of columns of the input matrix A.
3688 * M >= N >= 0.
3689 *
3690 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
3691 * On entry, M-by-N matrix A, such that A*diag(D) represents
3692 * the input matrix.
3693 * On exit,
3694 * A_onexit * D_onexit represents the input matrix A*diag(D)
3695 * post-multiplied by a sequence of Jacobi rotations, where the
3696 * rotation threshold and the total number of sweeps are given in
3697 * TOL and NSWEEP, respectively.
3698 * (See the descriptions of D, TOL and NSWEEP.)
3699 *
3700 * LDA (input) INTEGER
3701 * The leading dimension of the array A. LDA >= max(1,M).
3702 *
3703 * D (input/workspace/output) DOUBLE PRECISION array, dimension (N)
3704 * The array D accumulates the scaling factors from the fast scaled
3705 * Jacobi rotations.
3706 * On entry, A*diag(D) represents the input matrix.
3707 * On exit, A_onexit*diag(D_onexit) represents the input matrix
3708 * post-multiplied by a sequence of Jacobi rotations, where the
3709 * rotation threshold and the total number of sweeps are given in
3710 * TOL and NSWEEP, respectively.
3711 * (See the descriptions of A, TOL and NSWEEP.)
3712 *
3713 * SVA (input/workspace/output) DOUBLE PRECISION array, dimension (N)
3714 * On entry, SVA contains the Euclidean norms of the columns of
3715 * the matrix A*diag(D).
3716 * On exit, SVA contains the Euclidean norms of the columns of
3717 * the matrix onexit*diag(D_onexit).
3718 *
3719 * MV (input) INTEGER
3720 * If JOBV .EQ. 'A', then MV rows of V are post-multipled by a
3721 * sequence of Jacobi rotations.
3722 * If JOBV = 'N', then MV is not referenced.
3723 *
3724 * V (input/output) DOUBLE PRECISION array, dimension (LDV,N)
3725 * If JOBV .EQ. 'V' then N rows of V are post-multipled by a
3726 * sequence of Jacobi rotations.
3727 * If JOBV .EQ. 'A' then MV rows of V are post-multipled by a
3728 * sequence of Jacobi rotations.
3729 * If JOBV = 'N', then V is not referenced.
3730 *
3731 * LDV (input) INTEGER
3732 * The leading dimension of the array V, LDV >= 1.
3733 * If JOBV = 'V', LDV .GE. N.
3734 * If JOBV = 'A', LDV .GE. MV.
3735 *
3736 * EPS (input) DOUBLE PRECISION
3737 * EPS = DLAMCH('Epsilon')
3738 *
3739 * SFMIN (input) DOUBLE PRECISION
3740 * SFMIN = DLAMCH('Safe Minimum')
3741 *
3742 * TOL (input) DOUBLE PRECISION
3743 * TOL is the threshold for Jacobi rotations. For a pair
3744 * A(:,p), A(:,q) of pivot columns, the Jacobi rotation is
3745 * applied only if DABS(COS(angle(A(:,p),A(:,q)))) .GT. TOL.
3746 *
3747 * NSWEEP (input) INTEGER
3748 * NSWEEP is the number of sweeps of Jacobi rotations to be
3749 * performed.
3750 *
3751 * WORK (workspace) DOUBLE PRECISION array, dimension (LWORK)
3752 *
3753 * LWORK (input) INTEGER
3754 * LWORK is the dimension of WORK. LWORK .GE. M.
3755 *
3756 * INFO (output) INTEGER
3757 * = 0 : successful exit.
3758 * < 0 : if INFO = -i, then the i-th argument had an illegal value
3759 *
3760 * =====================================================================
3761 *
3762 * .. Local Parameters ..
3763 DOUBLE PRECISION ZERO, HALF, ONE, TWO
3764 PARAMETER ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0,
3765 + TWO = 2.0D0 )
3766 * ..
3767 * .. Local Scalars ..
3768 DOUBLE PRECISION AAPP, AAPP0, AAPQ, AAQQ, APOAQ, AQOAP, BIG,
3769 + BIGTHETA, CS, MXAAPQ, MXSINJ, ROOTBIG, ROOTEPS,
3770 + ROOTSFMIN, ROOTTOL, SMALL, SN, T, TEMP1, THETA,
3771 + THSIGN
3772 INTEGER BLSKIP, EMPTSW, i, ibr, IERR, igl, IJBLSK, ir1,
3773 + ISWROT, jbc, jgl, KBL, LKAHEAD, MVL, NBL,
3774 + NOTROT, p, PSKIPPED, q, ROWSKIP, SWBAND
3775 LOGICAL APPLV, ROTOK, RSVEC
3776 * ..
3777 * .. Local Arrays ..
3778 DOUBLE PRECISION FASTR( 5 )
3779 * ..
3780 * .. Intrinsic Functions ..
3781 INTRINSIC DABS, DMAX1, DBLE, MIN0, DSIGN, DSQRT
3782 * ..
3783 * .. External Functions ..
3784 DOUBLE PRECISION DDOT, DNRM2
3785 INTEGER IDAMAX
3786 LOGICAL LSAME
3787 EXTERNAL IDAMAX, LSAME, DDOT, DNRM2
3788 * ..
3789 * .. External Subroutines ..
3790 EXTERNAL DAXPY, DCOPY, DLASCL, DLASSQ, DROTM, DSWAP
3791 * ..
3792 * .. Executable Statements ..
3793 *
3794 APPLV = LSAME( JOBV, 'A' )
3795 RSVEC = LSAME( JOBV, 'V' )
3796 IF( .NOT.( RSVEC .OR. APPLV .OR. LSAME( JOBV, 'N' ) ) ) THEN
3797 INFO = -1
3798 ELSE IF( M.LT.0 ) THEN
3799 INFO = -2
3800 ELSE IF( ( N.LT.0 ) .OR. ( N.GT.M ) ) THEN
3801 INFO = -3
3802 ELSE IF( LDA.LT.M ) THEN
3803 INFO = -5
3804 ELSE IF( MV.LT.0 ) THEN
3805 INFO = -8
3806 ELSE IF( LDV.LT.M ) THEN
3807 INFO = -10
3808 ELSE IF( TOL.LE.EPS ) THEN
3809 INFO = -13
3810 ELSE IF( NSWEEP.LT.0 ) THEN
3811 INFO = -14
3812 ELSE IF( LWORK.LT.M ) THEN
3813 INFO = -16
3814 ELSE
3815 INFO = 0
3816 END IF
3817 *
3818 * #:(
3819 IF( INFO.NE.0 ) THEN
3820 CALL XERBLA( 'DGSVJ0', -INFO )
3821 RETURN
3822 END IF
3823 *
3824 IF( RSVEC ) THEN
3825 MVL = N
3826 ELSE IF( APPLV ) THEN
3827 MVL = MV
3828 END IF
3829 RSVEC = RSVEC .OR. APPLV
3830
3831 ROOTEPS = DSQRT( EPS )
3832 ROOTSFMIN = DSQRT( SFMIN )
3833 SMALL = SFMIN / EPS
3834 BIG = ONE / SFMIN
3835 ROOTBIG = ONE / ROOTSFMIN
3836 BIGTHETA = ONE / ROOTEPS
3837 ROOTTOL = DSQRT( TOL )
3838 *
3839 *
3840 * -#- Row-cyclic Jacobi SVD algorithm with column pivoting -#-
3841 *
3842 EMPTSW = ( N*( N-1 ) ) / 2
3843 NOTROT = 0
3844 FASTR( 1 ) = ZERO
3845 *
3846 * -#- Row-cyclic pivot strategy with de Rijk's pivoting -#-
3847 *
3848
3849 SWBAND = 0
3850 *[TP] SWBAND is a tuning parameter. It is meaningful and effective
3851 * if SGESVJ is used as a computational routine in the preconditioned
3852 * Jacobi SVD algorithm SGESVJ. For sweeps i=1:SWBAND the procedure
3853 * ......
3854
3855 KBL = MIN0( 8, N )
3856 *[TP] KBL is a tuning parameter that defines the tile size in the
3857 * tiling of the p-q loops of pivot pairs. In general, an optimal
3858 * value of KBL depends on the matrix dimensions and on the
3859 * parameters of the computer's memory.
3860 *
3861 NBL = N / KBL
3862 IF( ( NBL*KBL ).NE.N )NBL = NBL + 1
3863
3864 BLSKIP = ( KBL**2 ) + 1
3865 *[TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL.
3866
3867 ROWSKIP = MIN0( 5, KBL )
3868 *[TP] ROWSKIP is a tuning parameter.
3869
3870 LKAHEAD = 1
3871 *[TP] LKAHEAD is a tuning parameter.
3872 SWBAND = 0
3873 PSKIPPED = 0
3874 *
3875 DO 1993 i = 1, NSWEEP
3876 * .. go go go ...
3877 *
3878 MXAAPQ = ZERO
3879 MXSINJ = ZERO
3880 ISWROT = 0
3881 *
3882 NOTROT = 0
3883 PSKIPPED = 0
3884 *
3885 DO 2000 ibr = 1, NBL
3886
3887 igl = ( ibr-1 )*KBL + 1
3888 *
3889 DO 1002 ir1 = 0, MIN0( LKAHEAD, NBL-ibr )
3890 *
3891 igl = igl + ir1*KBL
3892 *
3893 DO 2001 p = igl, MIN0( igl+KBL-1, N-1 )
3894
3895 * .. de Rijk's pivoting
3896 q = IDAMAX( N-p+1, SVA( p ), 1 ) + p - 1
3897 IF( p.NE.q ) THEN
3898 CALL DSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
3899 IF( RSVEC )CALL DSWAP( MVL, V( 1, p ), 1,
3900 + V( 1, q ), 1 )
3901 TEMP1 = SVA( p )
3902 SVA( p ) = SVA( q )
3903 SVA( q ) = TEMP1
3904 TEMP1 = D( p )
3905 D( p ) = D( q )
3906 D( q ) = TEMP1
3907 END IF
3908 *
3909 IF( ir1.EQ.0 ) THEN
3910 *
3911 * Column norms are periodically updated by explicit
3912 * norm computation.
3913 * Caveat:
3914 * Some BLAS implementations compute DNRM2(M,A(1,p),1)
3915 * as DSQRT(DDOT(M,A(1,p),1,A(1,p),1)), which may result in
3916 * overflow for ||A(:,p)||_2 > DSQRT(overflow_threshold), and
3917 * undeflow for ||A(:,p)||_2 < DSQRT(underflow_threshold).
3918 * Hence, DNRM2 cannot be trusted, not even in the case when
3919 * the true norm is far from the under(over)flow boundaries.
3920 * If properly implemented DNRM2 is available, the IF-THEN-ELSE
3921 * below should read "AAPP = DNRM2( M, A(1,p), 1 ) * D(p)".
3922 *
3923 IF( ( SVA( p ).LT.ROOTBIG ) .AND.
3924 + ( SVA( p ).GT.ROOTSFMIN ) ) THEN
3925 SVA( p ) = DNRM2( M, A( 1, p ), 1 )*D( p )
3926 ELSE
3927 TEMP1 = ZERO
3928 AAPP = ZERO
3929 CALL DLASSQ( M, A( 1, p ), 1, TEMP1, AAPP )
3930 SVA( p ) = TEMP1*DSQRT( AAPP )*D( p )
3931 END IF
3932 AAPP = SVA( p )
3933 ELSE
3934 AAPP = SVA( p )
3935 END IF
3936
3937 *
3938 IF( AAPP.GT.ZERO ) THEN
3939 *
3940 PSKIPPED = 0
3941 *
3942 DO 2002 q = p + 1, MIN0( igl+KBL-1, N )
3943 *
3944 AAQQ = SVA( q )
3945
3946 IF( AAQQ.GT.ZERO ) THEN
3947 *
3948 AAPP0 = AAPP
3949 IF( AAQQ.GE.ONE ) THEN
3950 ROTOK = ( SMALL*AAPP ).LE.AAQQ
3951 IF( AAPP.LT.( BIG / AAQQ ) ) THEN
3952 AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
3953 + q ), 1 )*D( p )*D( q ) / AAQQ )
3954 + / AAPP
3955 ELSE
3956 CALL DCOPY( M, A( 1, p ), 1, WORK, 1 )
3957 CALL DLASCL( 'G', 0, 0, AAPP, D( p ),
3958 + M, 1, WORK, LDA, IERR )
3959 AAPQ = DDOT( M, WORK, 1, A( 1, q ),
3960 + 1 )*D( q ) / AAQQ
3961 END IF
3962 ELSE
3963 ROTOK = AAPP.LE.( AAQQ / SMALL )
3964 IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
3965 AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
3966 + q ), 1 )*D( p )*D( q ) / AAQQ )
3967 + / AAPP
3968 ELSE
3969 CALL DCOPY( M, A( 1, q ), 1, WORK, 1 )
3970 CALL DLASCL( 'G', 0, 0, AAQQ, D( q ),
3971 + M, 1, WORK, LDA, IERR )
3972 AAPQ = DDOT( M, WORK, 1, A( 1, p ),
3973 + 1 )*D( p ) / AAPP
3974 END IF
3975 END IF
3976 *
3977 MXAAPQ = DMAX1( MXAAPQ, DABS( AAPQ ) )
3978 *
3979 * TO rotate or NOT to rotate, THAT is the question ...
3980 *
3981 IF( DABS( AAPQ ).GT.TOL ) THEN
3982 *
3983 * .. rotate
3984 * ROTATED = ROTATED + ONE
3985 *
3986 IF( ir1.EQ.0 ) THEN
3987 NOTROT = 0
3988 PSKIPPED = 0
3989 ISWROT = ISWROT + 1
3990 END IF
3991 *
3992 IF( ROTOK ) THEN
3993 *
3994 AQOAP = AAQQ / AAPP
3995 APOAQ = AAPP / AAQQ
3996 THETA = -HALF*DABS( AQOAP-APOAQ ) /
3997 + AAPQ
3998 *
3999 IF( DABS( THETA ).GT.BIGTHETA ) THEN
4000 *
4001 T = HALF / THETA
4002 FASTR( 3 ) = T*D( p ) / D( q )
4003 FASTR( 4 ) = -T*D( q ) / D( p )
4004 CALL DROTM( M, A( 1, p ), 1,
4005 + A( 1, q ), 1, FASTR )
4006 IF( RSVEC )CALL DROTM( MVL,
4007 + V( 1, p ), 1,
4008 + V( 1, q ), 1,
4009 + FASTR )
4010 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
4011 + ONE+T*APOAQ*AAPQ ) )
4012 AAPP = AAPP*DSQRT( ONE-T*AQOAP*
4013 + AAPQ )
4014 MXSINJ = DMAX1( MXSINJ, DABS( T ) )
4015 *
4016 ELSE
4017 *
4018 * .. choose correct signum for THETA and rotate
4019 *
4020 THSIGN = -DSIGN( ONE, AAPQ )
4021 T = ONE / ( THETA+THSIGN*
4022 + DSQRT( ONE+THETA*THETA ) )
4023 CS = DSQRT( ONE / ( ONE+T*T ) )
4024 SN = T*CS
4025 *
4026 MXSINJ = DMAX1( MXSINJ, DABS( SN ) )
4027 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
4028 + ONE+T*APOAQ*AAPQ ) )
4029 AAPP = AAPP*DSQRT( DMAX1( ZERO,
4030 + ONE-T*AQOAP*AAPQ ) )
4031 *
4032 APOAQ = D( p ) / D( q )
4033 AQOAP = D( q ) / D( p )
4034 IF( D( p ).GE.ONE ) THEN
4035 IF( D( q ).GE.ONE ) THEN
4036 FASTR( 3 ) = T*APOAQ
4037 FASTR( 4 ) = -T*AQOAP
4038 D( p ) = D( p )*CS
4039 D( q ) = D( q )*CS
4040 CALL DROTM( M, A( 1, p ), 1,
4041 + A( 1, q ), 1,
4042 + FASTR )
4043 IF( RSVEC )CALL DROTM( MVL,
4044 + V( 1, p ), 1, V( 1, q ),
4045 + 1, FASTR )
4046 ELSE
4047 CALL DAXPY( M, -T*AQOAP,
4048 + A( 1, q ), 1,
4049 + A( 1, p ), 1 )
4050 CALL DAXPY( M, CS*SN*APOAQ,
4051 + A( 1, p ), 1,
4052 + A( 1, q ), 1 )
4053 D( p ) = D( p )*CS
4054 D( q ) = D( q ) / CS
4055 IF( RSVEC ) THEN
4056 CALL DAXPY( MVL, -T*AQOAP,
4057 + V( 1, q ), 1,
4058 + V( 1, p ), 1 )
4059 CALL DAXPY( MVL,
4060 + CS*SN*APOAQ,
4061 + V( 1, p ), 1,
4062 + V( 1, q ), 1 )
4063 END IF
4064 END IF
4065 ELSE
4066 IF( D( q ).GE.ONE ) THEN
4067 CALL DAXPY( M, T*APOAQ,
4068 + A( 1, p ), 1,
4069 + A( 1, q ), 1 )
4070 CALL DAXPY( M, -CS*SN*AQOAP,
4071 + A( 1, q ), 1,
4072 + A( 1, p ), 1 )
4073 D( p ) = D( p ) / CS
4074 D( q ) = D( q )*CS
4075 IF( RSVEC ) THEN
4076 CALL DAXPY( MVL, T*APOAQ,
4077 + V( 1, p ), 1,
4078 + V( 1, q ), 1 )
4079 CALL DAXPY( MVL,
4080 + -CS*SN*AQOAP,
4081 + V( 1, q ), 1,
4082 + V( 1, p ), 1 )
4083 END IF
4084 ELSE
4085 IF( D( p ).GE.D( q ) ) THEN
4086 CALL DAXPY( M, -T*AQOAP,
4087 + A( 1, q ), 1,
4088 + A( 1, p ), 1 )
4089 CALL DAXPY( M, CS*SN*APOAQ,
4090 + A( 1, p ), 1,
4091 + A( 1, q ), 1 )
4092 D( p ) = D( p )*CS
4093 D( q ) = D( q ) / CS
4094 IF( RSVEC ) THEN
4095 CALL DAXPY( MVL,
4096 + -T*AQOAP,
4097 + V( 1, q ), 1,
4098 + V( 1, p ), 1 )
4099 CALL DAXPY( MVL,
4100 + CS*SN*APOAQ,
4101 + V( 1, p ), 1,
4102 + V( 1, q ), 1 )
4103 END IF
4104 ELSE
4105 CALL DAXPY( M, T*APOAQ,
4106 + A( 1, p ), 1,
4107 + A( 1, q ), 1 )
4108 CALL DAXPY( M,
4109 + -CS*SN*AQOAP,
4110 + A( 1, q ), 1,
4111 + A( 1, p ), 1 )
4112 D( p ) = D( p ) / CS
4113 D( q ) = D( q )*CS
4114 IF( RSVEC ) THEN
4115 CALL DAXPY( MVL,
4116 + T*APOAQ, V( 1, p ),
4117 + 1, V( 1, q ), 1 )
4118 CALL DAXPY( MVL,
4119 + -CS*SN*AQOAP,
4120 + V( 1, q ), 1,
4121 + V( 1, p ), 1 )
4122 END IF
4123 END IF
4124 END IF
4125 END IF
4126 END IF
4127 *
4128 ELSE
4129 * .. have to use modified Gram-Schmidt like transformation
4130 CALL DCOPY( M, A( 1, p ), 1, WORK, 1 )
4131 CALL DLASCL( 'G', 0, 0, AAPP, ONE, M,
4132 + 1, WORK, LDA, IERR )
4133 CALL DLASCL( 'G', 0, 0, AAQQ, ONE, M,
4134 + 1, A( 1, q ), LDA, IERR )
4135 TEMP1 = -AAPQ*D( p ) / D( q )
4136 CALL DAXPY( M, TEMP1, WORK, 1,
4137 + A( 1, q ), 1 )
4138 CALL DLASCL( 'G', 0, 0, ONE, AAQQ, M,
4139 + 1, A( 1, q ), LDA, IERR )
4140 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
4141 + ONE-AAPQ*AAPQ ) )
4142 MXSINJ = DMAX1( MXSINJ, SFMIN )
4143 END IF
4144 * END IF ROTOK THEN ... ELSE
4145 *
4146 * In the case of cancellation in updating SVA(q), SVA(p)
4147 * recompute SVA(q), SVA(p).
4148 IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
4149 + THEN
4150 IF( ( AAQQ.LT.ROOTBIG ) .AND.
4151 + ( AAQQ.GT.ROOTSFMIN ) ) THEN
4152 SVA( q ) = DNRM2( M, A( 1, q ), 1 )*
4153 + D( q )
4154 ELSE
4155 T = ZERO
4156 AAQQ = ZERO
4157 CALL DLASSQ( M, A( 1, q ), 1, T,
4158 + AAQQ )
4159 SVA( q ) = T*DSQRT( AAQQ )*D( q )
4160 END IF
4161 END IF
4162 IF( ( AAPP / AAPP0 ).LE.ROOTEPS ) THEN
4163 IF( ( AAPP.LT.ROOTBIG ) .AND.
4164 + ( AAPP.GT.ROOTSFMIN ) ) THEN
4165 AAPP = DNRM2( M, A( 1, p ), 1 )*
4166 + D( p )
4167 ELSE
4168 T = ZERO
4169 AAPP = ZERO
4170 CALL DLASSQ( M, A( 1, p ), 1, T,
4171 + AAPP )
4172 AAPP = T*DSQRT( AAPP )*D( p )
4173 END IF
4174 SVA( p ) = AAPP
4175 END IF
4176 *
4177 ELSE
4178 * A(:,p) and A(:,q) already numerically orthogonal
4179 IF( ir1.EQ.0 )NOTROT = NOTROT + 1
4180 PSKIPPED = PSKIPPED + 1
4181 END IF
4182 ELSE
4183 * A(:,q) is zero column
4184 IF( ir1.EQ.0 )NOTROT = NOTROT + 1
4185 PSKIPPED = PSKIPPED + 1
4186 END IF
4187 *
4188 IF( ( i.LE.SWBAND ) .AND.
4189 + ( PSKIPPED.GT.ROWSKIP ) ) THEN
4190 IF( ir1.EQ.0 )AAPP = -AAPP
4191 NOTROT = 0
4192 GO TO 2103
4193 END IF
4194 *
4195 2002 CONTINUE
4196 * END q-LOOP
4197 *
4198 2103 CONTINUE
4199 * bailed out of q-loop
4200
4201 SVA( p ) = AAPP
4202
4203 ELSE
4204 SVA( p ) = AAPP
4205 IF( ( ir1.EQ.0 ) .AND. ( AAPP.EQ.ZERO ) )
4206 + NOTROT = NOTROT + MIN0( igl+KBL-1, N ) - p
4207 END IF
4208 *
4209 2001 CONTINUE
4210 * end of the p-loop
4211 * end of doing the block ( ibr, ibr )
4212 1002 CONTINUE
4213 * end of ir1-loop
4214 *
4215 *........................................................
4216 * ... go to the off diagonal blocks
4217 *
4218 igl = ( ibr-1 )*KBL + 1
4219 *
4220 DO 2010 jbc = ibr + 1, NBL
4221 *
4222 jgl = ( jbc-1 )*KBL + 1
4223 *
4224 * doing the block at ( ibr, jbc )
4225 *
4226 IJBLSK = 0
4227 DO 2100 p = igl, MIN0( igl+KBL-1, N )
4228 *
4229 AAPP = SVA( p )
4230 *
4231 IF( AAPP.GT.ZERO ) THEN
4232 *
4233 PSKIPPED = 0
4234 *
4235 DO 2200 q = jgl, MIN0( jgl+KBL-1, N )
4236 *
4237 AAQQ = SVA( q )
4238 *
4239 IF( AAQQ.GT.ZERO ) THEN
4240 AAPP0 = AAPP
4241 *
4242 * -#- M x 2 Jacobi SVD -#-
4243 *
4244 * -#- Safe Gram matrix computation -#-
4245 *
4246 IF( AAQQ.GE.ONE ) THEN
4247 IF( AAPP.GE.AAQQ ) THEN
4248 ROTOK = ( SMALL*AAPP ).LE.AAQQ
4249 ELSE
4250 ROTOK = ( SMALL*AAQQ ).LE.AAPP
4251 END IF
4252 IF( AAPP.LT.( BIG / AAQQ ) ) THEN
4253 AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
4254 + q ), 1 )*D( p )*D( q ) / AAQQ )
4255 + / AAPP
4256 ELSE
4257 CALL DCOPY( M, A( 1, p ), 1, WORK, 1 )
4258 CALL DLASCL( 'G', 0, 0, AAPP, D( p ),
4259 + M, 1, WORK, LDA, IERR )
4260 AAPQ = DDOT( M, WORK, 1, A( 1, q ),
4261 + 1 )*D( q ) / AAQQ
4262 END IF
4263 ELSE
4264 IF( AAPP.GE.AAQQ ) THEN
4265 ROTOK = AAPP.LE.( AAQQ / SMALL )
4266 ELSE
4267 ROTOK = AAQQ.LE.( AAPP / SMALL )
4268 END IF
4269 IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
4270 AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
4271 + q ), 1 )*D( p )*D( q ) / AAQQ )
4272 + / AAPP
4273 ELSE
4274 CALL DCOPY( M, A( 1, q ), 1, WORK, 1 )
4275 CALL DLASCL( 'G', 0, 0, AAQQ, D( q ),
4276 + M, 1, WORK, LDA, IERR )
4277 AAPQ = DDOT( M, WORK, 1, A( 1, p ),
4278 + 1 )*D( p ) / AAPP
4279 END IF
4280 END IF
4281 *
4282 MXAAPQ = DMAX1( MXAAPQ, DABS( AAPQ ) )
4283 *
4284 * TO rotate or NOT to rotate, THAT is the question ...
4285 *
4286 IF( DABS( AAPQ ).GT.TOL ) THEN
4287 NOTROT = 0
4288 * ROTATED = ROTATED + 1
4289 PSKIPPED = 0
4290 ISWROT = ISWROT + 1
4291 *
4292 IF( ROTOK ) THEN
4293 *
4294 AQOAP = AAQQ / AAPP
4295 APOAQ = AAPP / AAQQ
4296 THETA = -HALF*DABS( AQOAP-APOAQ ) /
4297 + AAPQ
4298 IF( AAQQ.GT.AAPP0 )THETA = -THETA
4299 *
4300 IF( DABS( THETA ).GT.BIGTHETA ) THEN
4301 T = HALF / THETA
4302 FASTR( 3 ) = T*D( p ) / D( q )
4303 FASTR( 4 ) = -T*D( q ) / D( p )
4304 CALL DROTM( M, A( 1, p ), 1,
4305 + A( 1, q ), 1, FASTR )
4306 IF( RSVEC )CALL DROTM( MVL,
4307 + V( 1, p ), 1,
4308 + V( 1, q ), 1,
4309 + FASTR )
4310 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
4311 + ONE+T*APOAQ*AAPQ ) )
4312 AAPP = AAPP*DSQRT( DMAX1( ZERO,
4313 + ONE-T*AQOAP*AAPQ ) )
4314 MXSINJ = DMAX1( MXSINJ, DABS( T ) )
4315 ELSE
4316 *
4317 * .. choose correct signum for THETA and rotate
4318 *
4319 THSIGN = -DSIGN( ONE, AAPQ )
4320 IF( AAQQ.GT.AAPP0 )THSIGN = -THSIGN
4321 T = ONE / ( THETA+THSIGN*
4322 + DSQRT( ONE+THETA*THETA ) )
4323 CS = DSQRT( ONE / ( ONE+T*T ) )
4324 SN = T*CS
4325 MXSINJ = DMAX1( MXSINJ, DABS( SN ) )
4326 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
4327 + ONE+T*APOAQ*AAPQ ) )
4328 AAPP = AAPP*DSQRT( ONE-T*AQOAP*
4329 + AAPQ )
4330 *
4331 APOAQ = D( p ) / D( q )
4332 AQOAP = D( q ) / D( p )
4333 IF( D( p ).GE.ONE ) THEN
4334 *
4335 IF( D( q ).GE.ONE ) THEN
4336 FASTR( 3 ) = T*APOAQ
4337 FASTR( 4 ) = -T*AQOAP
4338 D( p ) = D( p )*CS
4339 D( q ) = D( q )*CS
4340 CALL DROTM( M, A( 1, p ), 1,
4341 + A( 1, q ), 1,
4342 + FASTR )
4343 IF( RSVEC )CALL DROTM( MVL,
4344 + V( 1, p ), 1, V( 1, q ),
4345 + 1, FASTR )
4346 ELSE
4347 CALL DAXPY( M, -T*AQOAP,
4348 + A( 1, q ), 1,
4349 + A( 1, p ), 1 )
4350 CALL DAXPY( M, CS*SN*APOAQ,
4351 + A( 1, p ), 1,
4352 + A( 1, q ), 1 )
4353 IF( RSVEC ) THEN
4354 CALL DAXPY( MVL, -T*AQOAP,
4355 + V( 1, q ), 1,
4356 + V( 1, p ), 1 )
4357 CALL DAXPY( MVL,
4358 + CS*SN*APOAQ,
4359 + V( 1, p ), 1,
4360 + V( 1, q ), 1 )
4361 END IF
4362 D( p ) = D( p )*CS
4363 D( q ) = D( q ) / CS
4364 END IF
4365 ELSE
4366 IF( D( q ).GE.ONE ) THEN
4367 CALL DAXPY( M, T*APOAQ,
4368 + A( 1, p ), 1,
4369 + A( 1, q ), 1 )
4370 CALL DAXPY( M, -CS*SN*AQOAP,
4371 + A( 1, q ), 1,
4372 + A( 1, p ), 1 )
4373 IF( RSVEC ) THEN
4374 CALL DAXPY( MVL, T*APOAQ,
4375 + V( 1, p ), 1,
4376 + V( 1, q ), 1 )
4377 CALL DAXPY( MVL,
4378 + -CS*SN*AQOAP,
4379 + V( 1, q ), 1,
4380 + V( 1, p ), 1 )
4381 END IF
4382 D( p ) = D( p ) / CS
4383 D( q ) = D( q )*CS
4384 ELSE
4385 IF( D( p ).GE.D( q ) ) THEN
4386 CALL DAXPY( M, -T*AQOAP,
4387 + A( 1, q ), 1,
4388 + A( 1, p ), 1 )
4389 CALL DAXPY( M, CS*SN*APOAQ,
4390 + A( 1, p ), 1,
4391 + A( 1, q ), 1 )
4392 D( p ) = D( p )*CS
4393 D( q ) = D( q ) / CS
4394 IF( RSVEC ) THEN
4395 CALL DAXPY( MVL,
4396 + -T*AQOAP,
4397 + V( 1, q ), 1,
4398 + V( 1, p ), 1 )
4399 CALL DAXPY( MVL,
4400 + CS*SN*APOAQ,
4401 + V( 1, p ), 1,
4402 + V( 1, q ), 1 )
4403 END IF
4404 ELSE
4405 CALL DAXPY( M, T*APOAQ,
4406 + A( 1, p ), 1,
4407 + A( 1, q ), 1 )
4408 CALL DAXPY( M,
4409 + -CS*SN*AQOAP,
4410 + A( 1, q ), 1,
4411 + A( 1, p ), 1 )
4412 D( p ) = D( p ) / CS
4413 D( q ) = D( q )*CS
4414 IF( RSVEC ) THEN
4415 CALL DAXPY( MVL,
4416 + T*APOAQ, V( 1, p ),
4417 + 1, V( 1, q ), 1 )
4418 CALL DAXPY( MVL,
4419 + -CS*SN*AQOAP,
4420 + V( 1, q ), 1,
4421 + V( 1, p ), 1 )
4422 END IF
4423 END IF
4424 END IF
4425 END IF
4426 END IF
4427 *
4428 ELSE
4429 IF( AAPP.GT.AAQQ ) THEN
4430 CALL DCOPY( M, A( 1, p ), 1, WORK,
4431 + 1 )
4432 CALL DLASCL( 'G', 0, 0, AAPP, ONE,
4433 + M, 1, WORK, LDA, IERR )
4434 CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
4435 + M, 1, A( 1, q ), LDA,
4436 + IERR )
4437 TEMP1 = -AAPQ*D( p ) / D( q )
4438 CALL DAXPY( M, TEMP1, WORK, 1,
4439 + A( 1, q ), 1 )
4440 CALL DLASCL( 'G', 0, 0, ONE, AAQQ,
4441 + M, 1, A( 1, q ), LDA,
4442 + IERR )
4443 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
4444 + ONE-AAPQ*AAPQ ) )
4445 MXSINJ = DMAX1( MXSINJ, SFMIN )
4446 ELSE
4447 CALL DCOPY( M, A( 1, q ), 1, WORK,
4448 + 1 )
4449 CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
4450 + M, 1, WORK, LDA, IERR )
4451 CALL DLASCL( 'G', 0, 0, AAPP, ONE,
4452 + M, 1, A( 1, p ), LDA,
4453 + IERR )
4454 TEMP1 = -AAPQ*D( q ) / D( p )
4455 CALL DAXPY( M, TEMP1, WORK, 1,
4456 + A( 1, p ), 1 )
4457 CALL DLASCL( 'G', 0, 0, ONE, AAPP,
4458 + M, 1, A( 1, p ), LDA,
4459 + IERR )
4460 SVA( p ) = AAPP*DSQRT( DMAX1( ZERO,
4461 + ONE-AAPQ*AAPQ ) )
4462 MXSINJ = DMAX1( MXSINJ, SFMIN )
4463 END IF
4464 END IF
4465 * END IF ROTOK THEN ... ELSE
4466 *
4467 * In the case of cancellation in updating SVA(q)
4468 * .. recompute SVA(q)
4469 IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
4470 + THEN
4471 IF( ( AAQQ.LT.ROOTBIG ) .AND.
4472 + ( AAQQ.GT.ROOTSFMIN ) ) THEN
4473 SVA( q ) = DNRM2( M, A( 1, q ), 1 )*
4474 + D( q )
4475 ELSE
4476 T = ZERO
4477 AAQQ = ZERO
4478 CALL DLASSQ( M, A( 1, q ), 1, T,
4479 + AAQQ )
4480 SVA( q ) = T*DSQRT( AAQQ )*D( q )
4481 END IF
4482 END IF
4483 IF( ( AAPP / AAPP0 )**2.LE.ROOTEPS ) THEN
4484 IF( ( AAPP.LT.ROOTBIG ) .AND.
4485 + ( AAPP.GT.ROOTSFMIN ) ) THEN
4486 AAPP = DNRM2( M, A( 1, p ), 1 )*
4487 + D( p )
4488 ELSE
4489 T = ZERO
4490 AAPP = ZERO
4491 CALL DLASSQ( M, A( 1, p ), 1, T,
4492 + AAPP )
4493 AAPP = T*DSQRT( AAPP )*D( p )
4494 END IF
4495 SVA( p ) = AAPP
4496 END IF
4497 * end of OK rotation
4498 ELSE
4499 NOTROT = NOTROT + 1
4500 PSKIPPED = PSKIPPED + 1
4501 IJBLSK = IJBLSK + 1
4502 END IF
4503 ELSE
4504 NOTROT = NOTROT + 1
4505 PSKIPPED = PSKIPPED + 1
4506 IJBLSK = IJBLSK + 1
4507 END IF
4508 *
4509 IF( ( i.LE.SWBAND ) .AND. ( IJBLSK.GE.BLSKIP ) )
4510 + THEN
4511 SVA( p ) = AAPP
4512 NOTROT = 0
4513 GO TO 2011
4514 END IF
4515 IF( ( i.LE.SWBAND ) .AND.
4516 + ( PSKIPPED.GT.ROWSKIP ) ) THEN
4517 AAPP = -AAPP
4518 NOTROT = 0
4519 GO TO 2203
4520 END IF
4521 *
4522 2200 CONTINUE
4523 * end of the q-loop
4524 2203 CONTINUE
4525 *
4526 SVA( p ) = AAPP
4527 *
4528 ELSE
4529 IF( AAPP.EQ.ZERO )NOTROT = NOTROT +
4530 + MIN0( jgl+KBL-1, N ) - jgl + 1
4531 IF( AAPP.LT.ZERO )NOTROT = 0
4532 END IF
4533
4534 2100 CONTINUE
4535 * end of the p-loop
4536 2010 CONTINUE
4537 * end of the jbc-loop
4538 2011 CONTINUE
4539 *2011 bailed out of the jbc-loop
4540 DO 2012 p = igl, MIN0( igl+KBL-1, N )
4541 SVA( p ) = DABS( SVA( p ) )
4542 2012 CONTINUE
4543 *
4544 2000 CONTINUE
4545 *2000 :: end of the ibr-loop
4546 *
4547 * .. update SVA(N)
4548 IF( ( SVA( N ).LT.ROOTBIG ) .AND. ( SVA( N ).GT.ROOTSFMIN ) )
4549 + THEN
4550 SVA( N ) = DNRM2( M, A( 1, N ), 1 )*D( N )
4551 ELSE
4552 T = ZERO
4553 AAPP = ZERO
4554 CALL DLASSQ( M, A( 1, N ), 1, T, AAPP )
4555 SVA( N ) = T*DSQRT( AAPP )*D( N )
4556 END IF
4557 *
4558 * Additional steering devices
4559 *
4560 IF( ( i.LT.SWBAND ) .AND. ( ( MXAAPQ.LE.ROOTTOL ) .OR.
4561 + ( ISWROT.LE.N ) ) )SWBAND = i
4562 *
4563 IF( ( i.GT.SWBAND+1 ) .AND. ( MXAAPQ.LT.DBLE( N )*TOL ) .AND.
4564 + ( DBLE( N )*MXAAPQ*MXSINJ.LT.TOL ) ) THEN
4565 GO TO 1994
4566 END IF
4567 *
4568 IF( NOTROT.GE.EMPTSW )GO TO 1994
4569
4570 1993 CONTINUE
4571 * end i=1:NSWEEP loop
4572 * #:) Reaching this point means that the procedure has comleted the given
4573 * number of iterations.
4574 INFO = NSWEEP - 1
4575 GO TO 1995
4576 1994 CONTINUE
4577 * #:) Reaching this point means that during the i-th sweep all pivots were
4578 * below the given tolerance, causing early exit.
4579 *
4580 INFO = 0
4581 * #:) INFO = 0 confirms successful iterations.
4582 1995 CONTINUE
4583 *
4584 * Sort the vector D.
4585 DO 5991 p = 1, N - 1
4586 q = IDAMAX( N-p+1, SVA( p ), 1 ) + p - 1
4587 IF( p.NE.q ) THEN
4588 TEMP1 = SVA( p )
4589 SVA( p ) = SVA( q )
4590 SVA( q ) = TEMP1
4591 TEMP1 = D( p )
4592 D( p ) = D( q )
4593 D( q ) = TEMP1
4594 CALL DSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
4595 IF( RSVEC )CALL DSWAP( MVL, V( 1, p ), 1, V( 1, q ), 1 )
4596 END IF
4597 5991 CONTINUE
4598 *
4599 RETURN
4600 * ..
4601 * .. END OF DGSVJ0
4602 * ..
4603 END
4604 C
4605 C-----------------------------------------------------------------------
4606 C-----------------------------------------------------------------------
4607 SUBROUTINE DGSVJ1( JOBV, M, N, N1, A, LDA, D, SVA, MV, V, LDV,
4608 + EPS, SFMIN, TOL, NSWEEP, WORK, LWORK, INFO )
4609 *
4610 * -- LAPACK routine (version 3.2.2) --
4611 *
4612 * -- Contributed by Zlatko Drmac of the University of Zagreb and --
4613 * -- Kresimir Veselic of the Fernuniversitaet Hagen --
4614 * -- June 2010 --
4615 *
4616 * -- LAPACK is a software package provided by Univ. of Tennessee, --
4617 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
4618 *
4619 * This routine is also part of SIGMA (version 1.23, October 23. 2008.)
4620 * SIGMA is a library of algorithms for highly accurate algorithms for
4621 * computation of SVD, PSVD, QSVD, (H,K)-SVD, and for solution of the
4622 * eigenvalue problems Hx = lambda M x, H M x = lambda x with H, M > 0.
4623 *
4624 IMPLICIT NONE
4625 * ..
4626 * .. Scalar Arguments ..
4627 DOUBLE PRECISION EPS, SFMIN, TOL
4628 INTEGER INFO, LDA, LDV, LWORK, M, MV, N, N1, NSWEEP
4629 CHARACTER*1 JOBV
4630 * ..
4631 * .. Array Arguments ..
4632 DOUBLE PRECISION A( LDA, * ), D( N ), SVA( N ), V( LDV, * ),
4633 + WORK( LWORK )
4634 * ..
4635 *
4636 * Purpose
4637 * =======
4638 *
4639 * DGSVJ1 is called from SGESVJ as a pre-processor and that is its main
4640 * purpose. It applies Jacobi rotations in the same way as SGESVJ does, but
4641 * it targets only particular pivots and it does not check convergence
4642 * (stopping criterion). Few tunning parameters (marked by [TP]) are
4643 * available for the implementer.
4644 *
4645 * Further Details
4646 * ~~~~~~~~~~~~~~~
4647 * DGSVJ1 applies few sweeps of Jacobi rotations in the column space of
4648 * the input M-by-N matrix A. The pivot pairs are taken from the (1,2)
4649 * off-diagonal block in the corresponding N-by-N Gram matrix A^T * A. The
4650 * block-entries (tiles) of the (1,2) off-diagonal block are marked by the
4651 * [x]'s in the following scheme:
4652 *
4653 * | * * * [x] [x] [x]|
4654 * | * * * [x] [x] [x]| Row-cycling in the nblr-by-nblc [x] blocks.
4655 * | * * * [x] [x] [x]| Row-cyclic pivoting inside each [x] block.
4656 * |[x] [x] [x] * * * |
4657 * |[x] [x] [x] * * * |
4658 * |[x] [x] [x] * * * |
4659 *
4660 * In terms of the columns of A, the first N1 columns are rotated 'against'
4661 * the remaining N-N1 columns, trying to increase the angle between the
4662 * corresponding subspaces. The off-diagonal block is N1-by(N-N1) and it is
4663 * tiled using quadratic tiles of side KBL. Here, KBL is a tunning parmeter.
4664 * The number of sweeps is given in NSWEEP and the orthogonality threshold
4665 * is given in TOL.
4666 *
4667 * Contributors
4668 * ~~~~~~~~~~~~
4669 * Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany)
4670 *
4671 * Arguments
4672 * =========
4673 *
4674 * JOBV (input) CHARACTER*1
4675 * Specifies whether the output from this procedure is used
4676 * to compute the matrix V:
4677 * = 'V': the product of the Jacobi rotations is accumulated
4678 * by postmulyiplying the N-by-N array V.
4679 * (See the description of V.)
4680 * = 'A': the product of the Jacobi rotations is accumulated
4681 * by postmulyiplying the MV-by-N array V.
4682 * (See the descriptions of MV and V.)
4683 * = 'N': the Jacobi rotations are not accumulated.
4684 *
4685 * M (input) INTEGER
4686 * The number of rows of the input matrix A. M >= 0.
4687 *
4688 * N (input) INTEGER
4689 * The number of columns of the input matrix A.
4690 * M >= N >= 0.
4691 *
4692 * N1 (input) INTEGER
4693 * N1 specifies the 2 x 2 block partition, the first N1 columns are
4694 * rotated 'against' the remaining N-N1 columns of A.
4695 *
4696 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
4697 * On entry, M-by-N matrix A, such that A*diag(D) represents
4698 * the input matrix.
4699 * On exit,
4700 * A_onexit * D_onexit represents the input matrix A*diag(D)
4701 * post-multiplied by a sequence of Jacobi rotations, where the
4702 * rotation threshold and the total number of sweeps are given in
4703 * TOL and NSWEEP, respectively.
4704 * (See the descriptions of N1, D, TOL and NSWEEP.)
4705 *
4706 * LDA (input) INTEGER
4707 * The leading dimension of the array A. LDA >= max(1,M).
4708 *
4709 * D (input/workspace/output) DOUBLE PRECISION array, dimension (N)
4710 * The array D accumulates the scaling factors from the fast scaled
4711 * Jacobi rotations.
4712 * On entry, A*diag(D) represents the input matrix.
4713 * On exit, A_onexit*diag(D_onexit) represents the input matrix
4714 * post-multiplied by a sequence of Jacobi rotations, where the
4715 * rotation threshold and the total number of sweeps are given in
4716 * TOL and NSWEEP, respectively.
4717 * (See the descriptions of N1, A, TOL and NSWEEP.)
4718 *
4719 * SVA (input/workspace/output) DOUBLE PRECISION array, dimension (N)
4720 * On entry, SVA contains the Euclidean norms of the columns of
4721 * the matrix A*diag(D).
4722 * On exit, SVA contains the Euclidean norms of the columns of
4723 * the matrix onexit*diag(D_onexit).
4724 *
4725 * MV (input) INTEGER
4726 * If JOBV .EQ. 'A', then MV rows of V are post-multipled by a
4727 * sequence of Jacobi rotations.
4728 * If JOBV = 'N', then MV is not referenced.
4729 *
4730 * V (input/output) DOUBLE PRECISION array, dimension (LDV,N)
4731 * If JOBV .EQ. 'V' then N rows of V are post-multipled by a
4732 * sequence of Jacobi rotations.
4733 * If JOBV .EQ. 'A' then MV rows of V are post-multipled by a
4734 * sequence of Jacobi rotations.
4735 * If JOBV = 'N', then V is not referenced.
4736 *
4737 * LDV (input) INTEGER
4738 * The leading dimension of the array V, LDV >= 1.
4739 * If JOBV = 'V', LDV .GE. N.
4740 * If JOBV = 'A', LDV .GE. MV.
4741 *
4742 * EPS (input) DOUBLE PRECISION
4743 * EPS = DLAMCH('Epsilon')
4744 *
4745 * SFMIN (input) DOUBLE PRECISION
4746 * SFMIN = DLAMCH('Safe Minimum')
4747 *
4748 * TOL (input) DOUBLE PRECISION
4749 * TOL is the threshold for Jacobi rotations. For a pair
4750 * A(:,p), A(:,q) of pivot columns, the Jacobi rotation is
4751 * applied only if DABS(COS(angle(A(:,p),A(:,q)))) .GT. TOL.
4752 *
4753 * NSWEEP (input) INTEGER
4754 * NSWEEP is the number of sweeps of Jacobi rotations to be
4755 * performed.
4756 *
4757 * WORK (workspace) DOUBLE PRECISION array, dimension (LWORK)
4758 *
4759 * LWORK (input) INTEGER
4760 * LWORK is the dimension of WORK. LWORK .GE. M.
4761 *
4762 * INFO (output) INTEGER
4763 * = 0 : successful exit.
4764 * < 0 : if INFO = -i, then the i-th argument had an illegal value
4765 *
4766 * =====================================================================
4767 *
4768 * .. Local Parameters ..
4769 DOUBLE PRECISION ZERO, HALF, ONE, TWO
4770 PARAMETER ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0,
4771 + TWO = 2.0D0 )
4772 * ..
4773 * .. Local Scalars ..
4774 DOUBLE PRECISION AAPP, AAPP0, AAPQ, AAQQ, APOAQ, AQOAP, BIG,
4775 + BIGTHETA, CS, LARGE, MXAAPQ, MXSINJ, ROOTBIG,
4776 + ROOTEPS, ROOTSFMIN, ROOTTOL, SMALL, SN, T,
4777 + TEMP1, THETA, THSIGN
4778 INTEGER BLSKIP, EMPTSW, i, ibr, igl, IERR, IJBLSK,
4779 + ISWROT, jbc, jgl, KBL, MVL, NOTROT, nblc, nblr,
4780 + p, PSKIPPED, q, ROWSKIP, SWBAND
4781 LOGICAL APPLV, ROTOK, RSVEC
4782 * ..
4783 * .. Local Arrays ..
4784 DOUBLE PRECISION FASTR( 5 )
4785 * ..
4786 * .. Intrinsic Functions ..
4787 INTRINSIC DABS, DMAX1, DBLE, MIN0, DSIGN, DSQRT
4788 * ..
4789 * .. External Functions ..
4790 DOUBLE PRECISION DDOT, DNRM2
4791 INTEGER IDAMAX
4792 LOGICAL LSAME
4793 EXTERNAL IDAMAX, LSAME, DDOT, DNRM2
4794 * ..
4795 * .. External Subroutines ..
4796 EXTERNAL DAXPY, DCOPY, DLASCL, DLASSQ, DROTM, DSWAP
4797 * ..
4798 * .. Executable Statements ..
4799 *
4800 * Test the input parameters.
4801 *
4802 APPLV = LSAME( JOBV, 'A' )
4803 RSVEC = LSAME( JOBV, 'V' )
4804 IF( .NOT.( RSVEC .OR. APPLV .OR. LSAME( JOBV, 'N' ) ) ) THEN
4805 INFO = -1
4806 ELSE IF( M.LT.0 ) THEN
4807 INFO = -2
4808 ELSE IF( ( N.LT.0 ) .OR. ( N.GT.M ) ) THEN
4809 INFO = -3
4810 ELSE IF( N1.LT.0 ) THEN
4811 INFO = -4
4812 ELSE IF( LDA.LT.M ) THEN
4813 INFO = -6
4814 ELSE IF( MV.LT.0 ) THEN
4815 INFO = -9
4816 ELSE IF( LDV.LT.M ) THEN
4817 INFO = -11
4818 ELSE IF( TOL.LE.EPS ) THEN
4819 INFO = -14
4820 ELSE IF( NSWEEP.LT.0 ) THEN
4821 INFO = -15
4822 ELSE IF( LWORK.LT.M ) THEN
4823 INFO = -17
4824 ELSE
4825 INFO = 0
4826 END IF
4827 *
4828 * #:(
4829 IF( INFO.NE.0 ) THEN
4830 CALL XERBLA( 'DGSVJ1', -INFO )
4831 RETURN
4832 END IF
4833 *
4834 IF( RSVEC ) THEN
4835 MVL = N
4836 ELSE IF( APPLV ) THEN
4837 MVL = MV
4838 END IF
4839 RSVEC = RSVEC .OR. APPLV
4840
4841 ROOTEPS = DSQRT( EPS )
4842 ROOTSFMIN = DSQRT( SFMIN )
4843 SMALL = SFMIN / EPS
4844 BIG = ONE / SFMIN
4845 ROOTBIG = ONE / ROOTSFMIN
4846 LARGE = BIG / DSQRT( DBLE( M*N ) )
4847 BIGTHETA = ONE / ROOTEPS
4848 ROOTTOL = DSQRT( TOL )
4849 *
4850 * .. Initialize the right singular vector matrix ..
4851 *
4852 * RSVEC = LSAME( JOBV, 'Y' )
4853 *
4854 EMPTSW = N1*( N-N1 )
4855 NOTROT = 0
4856 FASTR( 1 ) = ZERO
4857 *
4858 * .. Row-cyclic pivot strategy with de Rijk's pivoting ..
4859 *
4860 KBL = MIN0( 8, N )
4861 NBLR = N1 / KBL
4862 IF( ( NBLR*KBL ).NE.N1 )NBLR = NBLR + 1
4863
4864 * .. the tiling is nblr-by-nblc [tiles]
4865
4866 NBLC = ( N-N1 ) / KBL
4867 IF( ( NBLC*KBL ).NE.( N-N1 ) )NBLC = NBLC + 1
4868 BLSKIP = ( KBL**2 ) + 1
4869 *[TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL.
4870
4871 ROWSKIP = MIN0( 5, KBL )
4872 *[TP] ROWSKIP is a tuning parameter.
4873 SWBAND = 0
4874 *[TP] SWBAND is a tuning parameter. It is meaningful and effective
4875 * if SGESVJ is used as a computational routine in the preconditioned
4876 * Jacobi SVD algorithm SGESVJ.
4877 *
4878 *
4879 * | * * * [x] [x] [x]|
4880 * | * * * [x] [x] [x]| Row-cycling in the nblr-by-nblc [x] blocks.
4881 * | * * * [x] [x] [x]| Row-cyclic pivoting inside each [x] block.
4882 * |[x] [x] [x] * * * |
4883 * |[x] [x] [x] * * * |
4884 * |[x] [x] [x] * * * |
4885 *
4886 *
4887 DO 1993 i = 1, NSWEEP
4888 * .. go go go ...
4889 *
4890 MXAAPQ = ZERO
4891 MXSINJ = ZERO
4892 ISWROT = 0
4893 *
4894 NOTROT = 0
4895 PSKIPPED = 0
4896 *
4897 DO 2000 ibr = 1, NBLR
4898
4899 igl = ( ibr-1 )*KBL + 1
4900 *
4901 *
4902 *........................................................
4903 * ... go to the off diagonal blocks
4904
4905 igl = ( ibr-1 )*KBL + 1
4906
4907 DO 2010 jbc = 1, NBLC
4908
4909 jgl = N1 + ( jbc-1 )*KBL + 1
4910
4911 * doing the block at ( ibr, jbc )
4912
4913 IJBLSK = 0
4914 DO 2100 p = igl, MIN0( igl+KBL-1, N1 )
4915
4916 AAPP = SVA( p )
4917
4918 IF( AAPP.GT.ZERO ) THEN
4919
4920 PSKIPPED = 0
4921
4922 DO 2200 q = jgl, MIN0( jgl+KBL-1, N )
4923 *
4924 AAQQ = SVA( q )
4925
4926 IF( AAQQ.GT.ZERO ) THEN
4927 AAPP0 = AAPP
4928 *
4929 * .. M x 2 Jacobi SVD ..
4930 *
4931 * .. Safe Gram matrix computation ..
4932 *
4933 IF( AAQQ.GE.ONE ) THEN
4934 IF( AAPP.GE.AAQQ ) THEN
4935 ROTOK = ( SMALL*AAPP ).LE.AAQQ
4936 ELSE
4937 ROTOK = ( SMALL*AAQQ ).LE.AAPP
4938 END IF
4939 IF( AAPP.LT.( BIG / AAQQ ) ) THEN
4940 AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
4941 + q ), 1 )*D( p )*D( q ) / AAQQ )
4942 + / AAPP
4943 ELSE
4944 CALL DCOPY( M, A( 1, p ), 1, WORK, 1 )
4945 CALL DLASCL( 'G', 0, 0, AAPP, D( p ),
4946 + M, 1, WORK, LDA, IERR )
4947 AAPQ = DDOT( M, WORK, 1, A( 1, q ),
4948 + 1 )*D( q ) / AAQQ
4949 END IF
4950 ELSE
4951 IF( AAPP.GE.AAQQ ) THEN
4952 ROTOK = AAPP.LE.( AAQQ / SMALL )
4953 ELSE
4954 ROTOK = AAQQ.LE.( AAPP / SMALL )
4955 END IF
4956 IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
4957 AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
4958 + q ), 1 )*D( p )*D( q ) / AAQQ )
4959 + / AAPP
4960 ELSE
4961 CALL DCOPY( M, A( 1, q ), 1, WORK, 1 )
4962 CALL DLASCL( 'G', 0, 0, AAQQ, D( q ),
4963 + M, 1, WORK, LDA, IERR )
4964 AAPQ = DDOT( M, WORK, 1, A( 1, p ),
4965 + 1 )*D( p ) / AAPP
4966 END IF
4967 END IF
4968
4969 MXAAPQ = DMAX1( MXAAPQ, DABS( AAPQ ) )
4970
4971 * TO rotate or NOT to rotate, THAT is the question ...
4972 *
4973 IF( DABS( AAPQ ).GT.TOL ) THEN
4974 NOTROT = 0
4975 * ROTATED = ROTATED + 1
4976 PSKIPPED = 0
4977 ISWROT = ISWROT + 1
4978 *
4979 IF( ROTOK ) THEN
4980 *
4981 AQOAP = AAQQ / AAPP
4982 APOAQ = AAPP / AAQQ
4983 THETA = -HALF*DABS( AQOAP-APOAQ ) /
4984 + AAPQ
4985 IF( AAQQ.GT.AAPP0 )THETA = -THETA
4986
4987 IF( DABS( THETA ).GT.BIGTHETA ) THEN
4988 T = HALF / THETA
4989 FASTR( 3 ) = T*D( p ) / D( q )
4990 FASTR( 4 ) = -T*D( q ) / D( p )
4991 CALL DROTM( M, A( 1, p ), 1,
4992 + A( 1, q ), 1, FASTR )
4993 IF( RSVEC )CALL DROTM( MVL,
4994 + V( 1, p ), 1,
4995 + V( 1, q ), 1,
4996 + FASTR )
4997 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
4998 + ONE+T*APOAQ*AAPQ ) )
4999 AAPP = AAPP*DSQRT( DMAX1( ZERO,
5000 + ONE-T*AQOAP*AAPQ ) )
5001 MXSINJ = DMAX1( MXSINJ, DABS( T ) )
5002 ELSE
5003 *
5004 * .. choose correct signum for THETA and rotate
5005 *
5006 THSIGN = -DSIGN( ONE, AAPQ )
5007 IF( AAQQ.GT.AAPP0 )THSIGN = -THSIGN
5008 T = ONE / ( THETA+THSIGN*
5009 + DSQRT( ONE+THETA*THETA ) )
5010 CS = DSQRT( ONE / ( ONE+T*T ) )
5011 SN = T*CS
5012 MXSINJ = DMAX1( MXSINJ, DABS( SN ) )
5013 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
5014 + ONE+T*APOAQ*AAPQ ) )
5015 AAPP = AAPP*DSQRT( ONE-T*AQOAP*
5016 + AAPQ )
5017
5018 APOAQ = D( p ) / D( q )
5019 AQOAP = D( q ) / D( p )
5020 IF( D( p ).GE.ONE ) THEN
5021 *
5022 IF( D( q ).GE.ONE ) THEN
5023 FASTR( 3 ) = T*APOAQ
5024 FASTR( 4 ) = -T*AQOAP
5025 D( p ) = D( p )*CS
5026 D( q ) = D( q )*CS
5027 CALL DROTM( M, A( 1, p ), 1,
5028 + A( 1, q ), 1,
5029 + FASTR )
5030 IF( RSVEC )CALL DROTM( MVL,
5031 + V( 1, p ), 1, V( 1, q ),
5032 + 1, FASTR )
5033 ELSE
5034 CALL DAXPY( M, -T*AQOAP,
5035 + A( 1, q ), 1,
5036 + A( 1, p ), 1 )
5037 CALL DAXPY( M, CS*SN*APOAQ,
5038 + A( 1, p ), 1,
5039 + A( 1, q ), 1 )
5040 IF( RSVEC ) THEN
5041 CALL DAXPY( MVL, -T*AQOAP,
5042 + V( 1, q ), 1,
5043 + V( 1, p ), 1 )
5044 CALL DAXPY( MVL,
5045 + CS*SN*APOAQ,
5046 + V( 1, p ), 1,
5047 + V( 1, q ), 1 )
5048 END IF
5049 D( p ) = D( p )*CS
5050 D( q ) = D( q ) / CS
5051 END IF
5052 ELSE
5053 IF( D( q ).GE.ONE ) THEN
5054 CALL DAXPY( M, T*APOAQ,
5055 + A( 1, p ), 1,
5056 + A( 1, q ), 1 )
5057 CALL DAXPY( M, -CS*SN*AQOAP,
5058 + A( 1, q ), 1,
5059 + A( 1, p ), 1 )
5060 IF( RSVEC ) THEN
5061 CALL DAXPY( MVL, T*APOAQ,
5062 + V( 1, p ), 1,
5063 + V( 1, q ), 1 )
5064 CALL DAXPY( MVL,
5065 + -CS*SN*AQOAP,
5066 + V( 1, q ), 1,
5067 + V( 1, p ), 1 )
5068 END IF
5069 D( p ) = D( p ) / CS
5070 D( q ) = D( q )*CS
5071 ELSE
5072 IF( D( p ).GE.D( q ) ) THEN
5073 CALL DAXPY( M, -T*AQOAP,
5074 + A( 1, q ), 1,
5075 + A( 1, p ), 1 )
5076 CALL DAXPY( M, CS*SN*APOAQ,
5077 + A( 1, p ), 1,
5078 + A( 1, q ), 1 )
5079 D( p ) = D( p )*CS
5080 D( q ) = D( q ) / CS
5081 IF( RSVEC ) THEN
5082 CALL DAXPY( MVL,
5083 + -T*AQOAP,
5084 + V( 1, q ), 1,
5085 + V( 1, p ), 1 )
5086 CALL DAXPY( MVL,
5087 + CS*SN*APOAQ,
5088 + V( 1, p ), 1,
5089 + V( 1, q ), 1 )
5090 END IF
5091 ELSE
5092 CALL DAXPY( M, T*APOAQ,
5093 + A( 1, p ), 1,
5094 + A( 1, q ), 1 )
5095 CALL DAXPY( M,
5096 + -CS*SN*AQOAP,
5097 + A( 1, q ), 1,
5098 + A( 1, p ), 1 )
5099 D( p ) = D( p ) / CS
5100 D( q ) = D( q )*CS
5101 IF( RSVEC ) THEN
5102 CALL DAXPY( MVL,
5103 + T*APOAQ, V( 1, p ),
5104 + 1, V( 1, q ), 1 )
5105 CALL DAXPY( MVL,
5106 + -CS*SN*AQOAP,
5107 + V( 1, q ), 1,
5108 + V( 1, p ), 1 )
5109 END IF
5110 END IF
5111 END IF
5112 END IF
5113 END IF
5114
5115 ELSE
5116 IF( AAPP.GT.AAQQ ) THEN
5117 CALL DCOPY( M, A( 1, p ), 1, WORK,
5118 + 1 )
5119 CALL DLASCL( 'G', 0, 0, AAPP, ONE,
5120 + M, 1, WORK, LDA, IERR )
5121 CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
5122 + M, 1, A( 1, q ), LDA,
5123 + IERR )
5124 TEMP1 = -AAPQ*D( p ) / D( q )
5125 CALL DAXPY( M, TEMP1, WORK, 1,
5126 + A( 1, q ), 1 )
5127 CALL DLASCL( 'G', 0, 0, ONE, AAQQ,
5128 + M, 1, A( 1, q ), LDA,
5129 + IERR )
5130 SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
5131 + ONE-AAPQ*AAPQ ) )
5132 MXSINJ = DMAX1( MXSINJ, SFMIN )
5133 ELSE
5134 CALL DCOPY( M, A( 1, q ), 1, WORK,
5135 + 1 )
5136 CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
5137 + M, 1, WORK, LDA, IERR )
5138 CALL DLASCL( 'G', 0, 0, AAPP, ONE,
5139 + M, 1, A( 1, p ), LDA,
5140 + IERR )
5141 TEMP1 = -AAPQ*D( q ) / D( p )
5142 CALL DAXPY( M, TEMP1, WORK, 1,
5143 + A( 1, p ), 1 )
5144 CALL DLASCL( 'G', 0, 0, ONE, AAPP,
5145 + M, 1, A( 1, p ), LDA,
5146 + IERR )
5147 SVA( p ) = AAPP*DSQRT( DMAX1( ZERO,
5148 + ONE-AAPQ*AAPQ ) )
5149 MXSINJ = DMAX1( MXSINJ, SFMIN )
5150 END IF
5151 END IF
5152 * END IF ROTOK THEN ... ELSE
5153 *
5154 * In the case of cancellation in updating SVA(q)
5155 * .. recompute SVA(q)
5156 IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
5157 + THEN
5158 IF( ( AAQQ.LT.ROOTBIG ) .AND.
5159 + ( AAQQ.GT.ROOTSFMIN ) ) THEN
5160 SVA( q ) = DNRM2( M, A( 1, q ), 1 )*
5161 + D( q )
5162 ELSE
5163 T = ZERO
5164 AAQQ = ZERO
5165 CALL DLASSQ( M, A( 1, q ), 1, T,
5166 + AAQQ )
5167 SVA( q ) = T*DSQRT( AAQQ )*D( q )
5168 END IF
5169 END IF
5170 IF( ( AAPP / AAPP0 )**2.LE.ROOTEPS ) THEN
5171 IF( ( AAPP.LT.ROOTBIG ) .AND.
5172 + ( AAPP.GT.ROOTSFMIN ) ) THEN
5173 AAPP = DNRM2( M, A( 1, p ), 1 )*
5174 + D( p )
5175 ELSE
5176 T = ZERO
5177 AAPP = ZERO
5178 CALL DLASSQ( M, A( 1, p ), 1, T,
5179 + AAPP )
5180 AAPP = T*DSQRT( AAPP )*D( p )
5181 END IF
5182 SVA( p ) = AAPP
5183 END IF
5184 * end of OK rotation
5185 ELSE
5186 NOTROT = NOTROT + 1
5187 * SKIPPED = SKIPPED + 1
5188 PSKIPPED = PSKIPPED + 1
5189 IJBLSK = IJBLSK + 1
5190 END IF
5191 ELSE
5192 NOTROT = NOTROT + 1
5193 PSKIPPED = PSKIPPED + 1
5194 IJBLSK = IJBLSK + 1
5195 END IF
5196
5197 * IF ( NOTROT .GE. EMPTSW ) GO TO 2011
5198 IF( ( i.LE.SWBAND ) .AND. ( IJBLSK.GE.BLSKIP ) )
5199 + THEN
5200 SVA( p ) = AAPP
5201 NOTROT = 0
5202 GO TO 2011
5203 END IF
5204 IF( ( i.LE.SWBAND ) .AND.
5205 + ( PSKIPPED.GT.ROWSKIP ) ) THEN
5206 AAPP = -AAPP
5207 NOTROT = 0
5208 GO TO 2203
5209 END IF
5210
5211 *
5212 2200 CONTINUE
5213 * end of the q-loop
5214 2203 CONTINUE
5215
5216 SVA( p ) = AAPP
5217 *
5218 ELSE
5219 IF( AAPP.EQ.ZERO )NOTROT = NOTROT +
5220 + MIN0( jgl+KBL-1, N ) - jgl + 1
5221 IF( AAPP.LT.ZERO )NOTROT = 0
5222 *** IF ( NOTROT .GE. EMPTSW ) GO TO 2011
5223 END IF
5224
5225 2100 CONTINUE
5226 * end of the p-loop
5227 2010 CONTINUE
5228 * end of the jbc-loop
5229 2011 CONTINUE
5230 *2011 bailed out of the jbc-loop
5231 DO 2012 p = igl, MIN0( igl+KBL-1, N )
5232 SVA( p ) = DABS( SVA( p ) )
5233 2012 CONTINUE
5234 *** IF ( NOTROT .GE. EMPTSW ) GO TO 1994
5235 2000 CONTINUE
5236 *2000 :: end of the ibr-loop
5237 *
5238 * .. update SVA(N)
5239 IF( ( SVA( N ).LT.ROOTBIG ) .AND. ( SVA( N ).GT.ROOTSFMIN ) )
5240 + THEN
5241 SVA( N ) = DNRM2( M, A( 1, N ), 1 )*D( N )
5242 ELSE
5243 T = ZERO
5244 AAPP = ZERO
5245 CALL DLASSQ( M, A( 1, N ), 1, T, AAPP )
5246 SVA( N ) = T*DSQRT( AAPP )*D( N )
5247 END IF
5248 *
5249 * Additional steering devices
5250 *
5251 IF( ( i.LT.SWBAND ) .AND. ( ( MXAAPQ.LE.ROOTTOL ) .OR.
5252 + ( ISWROT.LE.N ) ) )SWBAND = i
5253
5254 IF( ( i.GT.SWBAND+1 ) .AND. ( MXAAPQ.LT.DBLE( N )*TOL ) .AND.
5255 + ( DBLE( N )*MXAAPQ*MXSINJ.LT.TOL ) ) THEN
5256 GO TO 1994
5257 END IF
5258
5259 *
5260 IF( NOTROT.GE.EMPTSW )GO TO 1994
5261
5262 1993 CONTINUE
5263 * end i=1:NSWEEP loop
5264 * #:) Reaching this point means that the procedure has completed the given
5265 * number of sweeps.
5266 INFO = NSWEEP - 1
5267 GO TO 1995
5268 1994 CONTINUE
5269 * #:) Reaching this point means that during the i-th sweep all pivots were
5270 * below the given threshold, causing early exit.
5271
5272 INFO = 0
5273 * #:) INFO = 0 confirms successful iterations.
5274 1995 CONTINUE
5275 *
5276 * Sort the vector D
5277 *
5278 DO 5991 p = 1, N - 1
5279 q = IDAMAX( N-p+1, SVA( p ), 1 ) + p - 1
5280 IF( p.NE.q ) THEN
5281 TEMP1 = SVA( p )
5282 SVA( p ) = SVA( q )
5283 SVA( q ) = TEMP1
5284 TEMP1 = D( p )
5285 D( p ) = D( q )
5286 D( q ) = TEMP1
5287 CALL DSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
5288 IF( RSVEC )CALL DSWAP( MVL, V( 1, p ), 1, V( 1, q ), 1 )
5289 END IF
5290 5991 CONTINUE
5291 *
5292 RETURN
5293 * ..
5294 * .. END OF DGSVJ1
5295 * ..
5296 END
5297 C
5298 C-----------------------------------------------------------------------
5299 C-----------------------------------------------------------------------
5300 SUBROUTINE DGGBAK( JOB, SIDE, N, ILO, IHI, LSCALE, RSCALE, M, V,
5301 $ LDV, INFO )
5302 *
5303 * -- LAPACK routine (version 3.2) --
5304 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
5305 * November 2006
5306 *
5307 * .. Scalar Arguments ..
5308 CHARACTER JOB, SIDE
5309 INTEGER IHI, ILO, INFO, LDV, M, N
5310 * ..
5311 * .. Array Arguments ..
5312 DOUBLE PRECISION LSCALE( * ), RSCALE( * ), V( LDV, * )
5313 * ..
5314 *
5315 * Purpose
5316 * =======
5317 *
5318 * DGGBAK forms the right or left eigenvectors of a real generalized
5319 * eigenvalue problem A*x = lambda*B*x, by backward transformation on
5320 * the computed eigenvectors of the balanced pair of matrices output by
5321 * DGGBAL.
5322 *
5323 * Arguments
5324 * =========
5325 *
5326 * JOB (input) CHARACTER*1
5327 * Specifies the type of backward transformation required:
5328 * = 'N': do nothing, return immediately;
5329 * = 'P': do backward transformation for permutation only;
5330 * = 'S': do backward transformation for scaling only;
5331 * = 'B': do backward transformations for both permutation and
5332 * scaling.
5333 * JOB must be the same as the argument JOB supplied to DGGBAL.
5334 *
5335 * SIDE (input) CHARACTER*1
5336 * = 'R': V contains right eigenvectors;
5337 * = 'L': V contains left eigenvectors.
5338 *
5339 * N (input) INTEGER
5340 * The number of rows of the matrix V. N >= 0.
5341 *
5342 * ILO (input) INTEGER
5343 * IHI (input) INTEGER
5344 * The integers ILO and IHI determined by DGGBAL.
5345 * 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
5346 *
5347 * LSCALE (input) DOUBLE PRECISION array, dimension (N)
5348 * Details of the permutations and/or scaling factors applied
5349 * to the left side of A and B, as returned by DGGBAL.
5350 *
5351 * RSCALE (input) DOUBLE PRECISION array, dimension (N)
5352 * Details of the permutations and/or scaling factors applied
5353 * to the right side of A and B, as returned by DGGBAL.
5354 *
5355 * M (input) INTEGER
5356 * The number of columns of the matrix V. M >= 0.
5357 *
5358 * V (input/output) DOUBLE PRECISION array, dimension (LDV,M)
5359 * On entry, the matrix of right or left eigenvectors to be
5360 * transformed, as returned by DTGEVC.
5361 * On exit, V is overwritten by the transformed eigenvectors.
5362 *
5363 * LDV (input) INTEGER
5364 * The leading dimension of the matrix V. LDV >= max(1,N).
5365 *
5366 * INFO (output) INTEGER
5367 * = 0: successful exit.
5368 * < 0: if INFO = -i, the i-th argument had an illegal value.
5369 *
5370 * Further Details
5371 * ===============
5372 *
5373 * See R.C. Ward, Balancing the generalized eigenvalue problem,
5374 * SIAM J. Sci. Stat. Comp. 2 (1981), 141-152.
5375 *
5376 * =====================================================================
5377 *
5378 * .. Local Scalars ..
5379 LOGICAL LEFTV, RIGHTV
5380 INTEGER I, K
5381 * ..
5382 * .. External Functions ..
5383 LOGICAL LSAME
5384 EXTERNAL LSAME
5385 * ..
5386 * .. External Subroutines ..
5387 EXTERNAL DSCAL, DSWAP, XERBLA
5388 * ..
5389 * .. Intrinsic Functions ..
5390 INTRINSIC MAX
5391 * ..
5392 * .. Executable Statements ..
5393 *
5394 * Test the input parameters
5395 *
5396 RIGHTV = LSAME( SIDE, 'R' )
5397 LEFTV = LSAME( SIDE, 'L' )
5398 *
5399 INFO = 0
5400 IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.LSAME( JOB, 'P' ) .AND.
5401 $ .NOT.LSAME( JOB, 'S' ) .AND. .NOT.LSAME( JOB, 'B' ) ) THEN
5402 INFO = -1
5403 ELSE IF( .NOT.RIGHTV .AND. .NOT.LEFTV ) THEN
5404 INFO = -2
5405 ELSE IF( N.LT.0 ) THEN
5406 INFO = -3
5407 ELSE IF( ILO.LT.1 ) THEN
5408 INFO = -4
5409 ELSE IF( N.EQ.0 .AND. IHI.EQ.0 .AND. ILO.NE.1 ) THEN
5410 INFO = -4
5411 ELSE IF( N.GT.0 .AND. ( IHI.LT.ILO .OR. IHI.GT.MAX( 1, N ) ) )
5412 $ THEN
5413 INFO = -5
5414 ELSE IF( N.EQ.0 .AND. ILO.EQ.1 .AND. IHI.NE.0 ) THEN
5415 INFO = -5
5416 ELSE IF( M.LT.0 ) THEN
5417 INFO = -8
5418 ELSE IF( LDV.LT.MAX( 1, N ) ) THEN
5419 INFO = -10
5420 END IF
5421 IF( INFO.NE.0 ) THEN
5422 CALL XERBLA( 'DGGBAK', -INFO )
5423 RETURN
5424 END IF
5425 *
5426 * Quick return if possible
5427 *
5428 IF( N.EQ.0 )
5429 $ RETURN
5430 IF( M.EQ.0 )
5431 $ RETURN
5432 IF( LSAME( JOB, 'N' ) )
5433 $ RETURN
5434 *
5435 IF( ILO.EQ.IHI )
5436 $ GO TO 30
5437 *
5438 * Backward balance
5439 *
5440 IF( LSAME( JOB, 'S' ) .OR. LSAME( JOB, 'B' ) ) THEN
5441 *
5442 * Backward transformation on right eigenvectors
5443 *
5444 IF( RIGHTV ) THEN
5445 DO 10 I = ILO, IHI
5446 CALL DSCAL( M, RSCALE( I ), V( I, 1 ), LDV )
5447 10 CONTINUE
5448 END IF
5449 *
5450 * Backward transformation on left eigenvectors
5451 *
5452 IF( LEFTV ) THEN
5453 DO 20 I = ILO, IHI
5454 CALL DSCAL( M, LSCALE( I ), V( I, 1 ), LDV )
5455 20 CONTINUE
5456 END IF
5457 END IF
5458 *
5459 * Backward permutation
5460 *
5461 30 CONTINUE
5462 IF( LSAME( JOB, 'P' ) .OR. LSAME( JOB, 'B' ) ) THEN
5463 *
5464 * Backward permutation on right eigenvectors
5465 *
5466 IF( RIGHTV ) THEN
5467 IF( ILO.EQ.1 )
5468 $ GO TO 50
5469 *
5470 DO 40 I = ILO - 1, 1, -1
5471 K = RSCALE( I )
5472 IF( K.EQ.I )
5473 $ GO TO 40
5474 CALL DSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV )
5475 40 CONTINUE
5476 *
5477 50 CONTINUE
5478 IF( IHI.EQ.N )
5479 $ GO TO 70
5480 DO 60 I = IHI + 1, N
5481 K = RSCALE( I )
5482 IF( K.EQ.I )
5483 $ GO TO 60
5484 CALL DSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV )
5485 60 CONTINUE
5486 END IF
5487 *
5488 * Backward permutation on left eigenvectors
5489 *
5490 70 CONTINUE
5491 IF( LEFTV ) THEN
5492 IF( ILO.EQ.1 )
5493 $ GO TO 90
5494 DO 80 I = ILO - 1, 1, -1
5495 K = LSCALE( I )
5496 IF( K.EQ.I )
5497 $ GO TO 80
5498 CALL DSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV )
5499 80 CONTINUE
5500 *
5501 90 CONTINUE
5502 IF( IHI.EQ.N )
5503 $ GO TO 110
5504 DO 100 I = IHI + 1, N
5505 K = LSCALE( I )
5506 IF( K.EQ.I )
5507 $ GO TO 100
5508 CALL DSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV )
5509 100 CONTINUE
5510 END IF
5511 END IF
5512 *
5513 110 CONTINUE
5514 *
5515 RETURN
5516 *
5517 * End of DGGBAK
5518 *
5519 END
5520 C
5521 C-----------------------------------------------------------------------
5522 C-----------------------------------------------------------------------
5523 SUBROUTINE DGEQRF( M, N, A, LDA, TAU, WORK, LWORK, INFO )
5524 *
5525 * -- LAPACK routine (version 3.2) --
5526 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
5527 * November 2006
5528 *
5529 * .. Scalar Arguments ..
5530 INTEGER INFO, LDA, LWORK, M, N
5531 * ..
5532 * .. Array Arguments ..
5533 DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
5534 * ..
5535 *
5536 * Purpose
5537 * =======
5538 *
5539 * DGEQRF computes a QR factorization of a real M-by-N matrix A:
5540 * A = Q * R.
5541 *
5542 * Arguments
5543 * =========
5544 *
5545 * M (input) INTEGER
5546 * The number of rows of the matrix A. M >= 0.
5547 *
5548 * N (input) INTEGER
5549 * The number of columns of the matrix A. N >= 0.
5550 *
5551 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
5552 * On entry, the M-by-N matrix A.
5553 * On exit, the elements on and above the diagonal of the array
5554 * contain the min(M,N)-by-N upper trapezoidal matrix R (R is
5555 * upper triangular if m >= n); the elements below the diagonal,
5556 * with the array TAU, represent the orthogonal matrix Q as a
5557 * product of min(m,n) elementary reflectors (see Further
5558 * Details).
5559 *
5560 * LDA (input) INTEGER
5561 * The leading dimension of the array A. LDA >= max(1,M).
5562 *
5563 * TAU (output) DOUBLE PRECISION array, dimension (min(M,N))
5564 * The scalar factors of the elementary reflectors (see Further
5565 * Details).
5566 *
5567 * WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
5568 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
5569 *
5570 * LWORK (input) INTEGER
5571 * The dimension of the array WORK. LWORK >= max(1,N).
5572 * For optimum performance LWORK >= N*NB, where NB is
5573 * the optimal blocksize.
5574 *
5575 * If LWORK = -1, then a workspace query is assumed; the routine
5576 * only calculates the optimal size of the WORK array, returns
5577 * this value as the first entry of the WORK array, and no error
5578 * message related to LWORK is issued by XERBLA.
5579 *
5580 * INFO (output) INTEGER
5581 * = 0: successful exit
5582 * < 0: if INFO = -i, the i-th argument had an illegal value
5583 *
5584 * Further Details
5585 * ===============
5586 *
5587 * The matrix Q is represented as a product of elementary reflectors
5588 *
5589 * Q = H(1) H(2) . . . H(k), where k = min(m,n).
5590 *
5591 * Each H(i) has the form
5592 *
5593 * H(i) = I - tau * v * v'
5594 *
5595 * where tau is a real scalar, and v is a real vector with
5596 * v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i),
5597 * and tau in TAU(i).
5598 *
5599 * =====================================================================
5600 *
5601 * .. Local Scalars ..
5602 LOGICAL LQUERY
5603 INTEGER I, IB, IINFO, IWS, K, LDWORK, LWKOPT, NB,
5604 $ NBMIN, NX
5605 * ..
5606 * .. External Subroutines ..
5607 EXTERNAL DGEQR2, DLARFB, DLARFT, XERBLA
5608 * ..
5609 * .. Intrinsic Functions ..
5610 INTRINSIC MAX, MIN
5611 * ..
5612 * .. External Functions ..
5613 INTEGER ILAENV
5614 EXTERNAL ILAENV
5615 * ..
5616 * .. Executable Statements ..
5617 *
5618 * Test the input arguments
5619 *
5620 INFO = 0
5621 NB = ILAENV( 1, 'DGEQRF', ' ', M, N, -1, -1 )
5622 LWKOPT = N*NB
5623 WORK( 1 ) = LWKOPT
5624 LQUERY = ( LWORK.EQ.-1 )
5625 IF( M.LT.0 ) THEN
5626 INFO = -1
5627 ELSE IF( N.LT.0 ) THEN
5628 INFO = -2
5629 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
5630 INFO = -4
5631 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
5632 INFO = -7
5633 END IF
5634 IF( INFO.NE.0 ) THEN
5635 CALL XERBLA( 'DGEQRF', -INFO )
5636 RETURN
5637 ELSE IF( LQUERY ) THEN
5638 RETURN
5639 END IF
5640 *
5641 * Quick return if possible
5642 *
5643 K = MIN( M, N )
5644 IF( K.EQ.0 ) THEN
5645 WORK( 1 ) = 1
5646 RETURN
5647 END IF
5648 *
5649 NBMIN = 2
5650 NX = 0
5651 IWS = N
5652 IF( NB.GT.1 .AND. NB.LT.K ) THEN
5653 *
5654 * Determine when to cross over from blocked to unblocked code.
5655 *
5656 NX = MAX( 0, ILAENV( 3, 'DGEQRF', ' ', M, N, -1, -1 ) )
5657 IF( NX.LT.K ) THEN
5658 *
5659 * Determine if workspace is large enough for blocked code.
5660 *
5661 LDWORK = N
5662 IWS = LDWORK*NB
5663 IF( LWORK.LT.IWS ) THEN
5664 *
5665 * Not enough workspace to use optimal NB: reduce NB and
5666 * determine the minimum value of NB.
5667 *
5668 NB = LWORK / LDWORK
5669 NBMIN = MAX( 2, ILAENV( 2, 'DGEQRF', ' ', M, N, -1,
5670 $ -1 ) )
5671 END IF
5672 END IF
5673 END IF
5674 *
5675 IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN
5676 *
5677 * Use blocked code initially
5678 *
5679 DO 10 I = 1, K - NX, NB
5680 IB = MIN( K-I+1, NB )
5681 *
5682 * Compute the QR factorization of the current block
5683 * A(i:m,i:i+ib-1)
5684 *
5685 CALL DGEQR2( M-I+1, IB, A( I, I ), LDA, TAU( I ), WORK,
5686 $ IINFO )
5687 IF( I+IB.LE.N ) THEN
5688 *
5689 * Form the triangular factor of the block reflector
5690 * H = H(i) H(i+1) . . . H(i+ib-1)
5691 *
5692 CALL DLARFT( 'Forward', 'Columnwise', M-I+1, IB,
5693 $ A( I, I ), LDA, TAU( I ), WORK, LDWORK )
5694 *
5695 * Apply H' to A(i:m,i+ib:n) from the left
5696 *
5697 CALL DLARFB( 'Left', 'Transpose', 'Forward',
5698 $ 'Columnwise', M-I+1, N-I-IB+1, IB,
5699 $ A( I, I ), LDA, WORK, LDWORK, A( I, I+IB ),
5700 $ LDA, WORK( IB+1 ), LDWORK )
5701 END IF
5702 10 CONTINUE
5703 ELSE
5704 I = 1
5705 END IF
5706 *
5707 * Use unblocked code to factor the last or only block.
5708 *
5709 IF( I.LE.K )
5710 $ CALL DGEQR2( M-I+1, N-I+1, A( I, I ), LDA, TAU( I ), WORK,
5711 $ IINFO )
5712 *
5713 WORK( 1 ) = IWS
5714 RETURN
5715 *
5716 * End of DGEQRF
5717 *
5718 END
5719 C
5720 C-----------------------------------------------------------------------
5721 C-----------------------------------------------------------------------
5722 SUBROUTINE DGGHRD( COMPQ, COMPZ, N, ILO, IHI, A, LDA, B, LDB, Q,
5723 $ LDQ, Z, LDZ, INFO )
5724 *
5725 * -- LAPACK routine (version 3.2) --
5726 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
5727 * November 2006
5728 *
5729 * .. Scalar Arguments ..
5730 CHARACTER COMPQ, COMPZ
5731 INTEGER IHI, ILO, INFO, LDA, LDB, LDQ, LDZ, N
5732 * ..
5733 * .. Array Arguments ..
5734 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
5735 $ Z( LDZ, * )
5736 * ..
5737 *
5738 * Purpose
5739 * =======
5740 *
5741 * DGGHRD reduces a pair of real matrices (A,B) to generalized upper
5742 * Hessenberg form using orthogonal transformations, where A is a
5743 * general matrix and B is upper triangular. The form of the
5744 * generalized eigenvalue problem is
5745 * A*x = lambda*B*x,
5746 * and B is typically made upper triangular by computing its QR
5747 * factorization and moving the orthogonal matrix Q to the left side
5748 * of the equation.
5749 *
5750 * This subroutine simultaneously reduces A to a Hessenberg matrix H:
5751 * Q**T*A*Z = H
5752 * and transforms B to another upper triangular matrix T:
5753 * Q**T*B*Z = T
5754 * in order to reduce the problem to its standard form
5755 * H*y = lambda*T*y
5756 * where y = Z**T*x.
5757 *
5758 * The orthogonal matrices Q and Z are determined as products of Givens
5759 * rotations. They may either be formed explicitly, or they may be
5760 * postmultiplied into input matrices Q1 and Z1, so that
5761 *
5762 * Q1 * A * Z1**T = (Q1*Q) * H * (Z1*Z)**T
5763 *
5764 * Q1 * B * Z1**T = (Q1*Q) * T * (Z1*Z)**T
5765 *
5766 * If Q1 is the orthogonal matrix from the QR factorization of B in the
5767 * original equation A*x = lambda*B*x, then DGGHRD reduces the original
5768 * problem to generalized Hessenberg form.
5769 *
5770 * Arguments
5771 * =========
5772 *
5773 * COMPQ (input) CHARACTER*1
5774 * = 'N': do not compute Q;
5775 * = 'I': Q is initialized to the unit matrix, and the
5776 * orthogonal matrix Q is returned;
5777 * = 'V': Q must contain an orthogonal matrix Q1 on entry,
5778 * and the product Q1*Q is returned.
5779 *
5780 * COMPZ (input) CHARACTER*1
5781 * = 'N': do not compute Z;
5782 * = 'I': Z is initialized to the unit matrix, and the
5783 * orthogonal matrix Z is returned;
5784 * = 'V': Z must contain an orthogonal matrix Z1 on entry,
5785 * and the product Z1*Z is returned.
5786 *
5787 * N (input) INTEGER
5788 * The order of the matrices A and B. N >= 0.
5789 *
5790 * ILO (input) INTEGER
5791 * IHI (input) INTEGER
5792 * ILO and IHI mark the rows and columns of A which are to be
5793 * reduced. It is assumed that A is already upper triangular
5794 * in rows and columns 1:ILO-1 and IHI+1:N. ILO and IHI are
5795 * normally set by a previous call to SGGBAL; otherwise they
5796 * should be set to 1 and N respectively.
5797 * 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
5798 *
5799 * A (input/output) DOUBLE PRECISION array, dimension (LDA, N)
5800 * On entry, the N-by-N general matrix to be reduced.
5801 * On exit, the upper triangle and the first subdiagonal of A
5802 * are overwritten with the upper Hessenberg matrix H, and the
5803 * rest is set to zero.
5804 *
5805 * LDA (input) INTEGER
5806 * The leading dimension of the array A. LDA >= max(1,N).
5807 *
5808 * B (input/output) DOUBLE PRECISION array, dimension (LDB, N)
5809 * On entry, the N-by-N upper triangular matrix B.
5810 * On exit, the upper triangular matrix T = Q**T B Z. The
5811 * elements below the diagonal are set to zero.
5812 *
5813 * LDB (input) INTEGER
5814 * The leading dimension of the array B. LDB >= max(1,N).
5815 *
5816 * Q (input/output) DOUBLE PRECISION array, dimension (LDQ, N)
5817 * On entry, if COMPQ = 'V', the orthogonal matrix Q1,
5818 * typically from the QR factorization of B.
5819 * On exit, if COMPQ='I', the orthogonal matrix Q, and if
5820 * COMPQ = 'V', the product Q1*Q.
5821 * Not referenced if COMPQ='N'.
5822 *
5823 * LDQ (input) INTEGER
5824 * The leading dimension of the array Q.
5825 * LDQ >= N if COMPQ='V' or 'I'; LDQ >= 1 otherwise.
5826 *
5827 * Z (input/output) DOUBLE PRECISION array, dimension (LDZ, N)
5828 * On entry, if COMPZ = 'V', the orthogonal matrix Z1.
5829 * On exit, if COMPZ='I', the orthogonal matrix Z, and if
5830 * COMPZ = 'V', the product Z1*Z.
5831 * Not referenced if COMPZ='N'.
5832 *
5833 * LDZ (input) INTEGER
5834 * The leading dimension of the array Z.
5835 * LDZ >= N if COMPZ='V' or 'I'; LDZ >= 1 otherwise.
5836 *
5837 * INFO (output) INTEGER
5838 * = 0: successful exit.
5839 * < 0: if INFO = -i, the i-th argument had an illegal value.
5840 *
5841 * Further Details
5842 * ===============
5843 *
5844 * This routine reduces A to Hessenberg and B to triangular form by
5845 * an unblocked reduction, as described in _Matrix_Computations_,
5846 * by Golub and Van Loan (Johns Hopkins Press.)
5847 *
5848 * =====================================================================
5849 *
5850 * .. Parameters ..
5851 DOUBLE PRECISION ONE, ZERO
5852 PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
5853 * ..
5854 * .. Local Scalars ..
5855 LOGICAL ILQ, ILZ
5856 INTEGER ICOMPQ, ICOMPZ, JCOL, JROW
5857 DOUBLE PRECISION C, S, TEMP
5858 * ..
5859 * .. External Functions ..
5860 LOGICAL LSAME
5861 EXTERNAL LSAME
5862 * ..
5863 * .. External Subroutines ..
5864 EXTERNAL DLARTG, DLASET, DROT, XERBLA
5865 * ..
5866 * .. Intrinsic Functions ..
5867 INTRINSIC MAX
5868 * ..
5869 * .. Executable Statements ..
5870 *
5871 * Decode COMPQ
5872 *
5873 IF( LSAME( COMPQ, 'N' ) ) THEN
5874 ILQ = .FALSE.
5875 ICOMPQ = 1
5876 ELSE IF( LSAME( COMPQ, 'V' ) ) THEN
5877 ILQ = .TRUE.
5878 ICOMPQ = 2
5879 ELSE IF( LSAME( COMPQ, 'I' ) ) THEN
5880 ILQ = .TRUE.
5881 ICOMPQ = 3
5882 ELSE
5883 ICOMPQ = 0
5884 END IF
5885 *
5886 * Decode COMPZ
5887 *
5888 IF( LSAME( COMPZ, 'N' ) ) THEN
5889 ILZ = .FALSE.
5890 ICOMPZ = 1
5891 ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
5892 ILZ = .TRUE.
5893 ICOMPZ = 2
5894 ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
5895 ILZ = .TRUE.
5896 ICOMPZ = 3
5897 ELSE
5898 ICOMPZ = 0
5899 END IF
5900 *
5901 * Test the input parameters.
5902 *
5903 INFO = 0
5904 IF( ICOMPQ.LE.0 ) THEN
5905 INFO = -1
5906 ELSE IF( ICOMPZ.LE.0 ) THEN
5907 INFO = -2
5908 ELSE IF( N.LT.0 ) THEN
5909 INFO = -3
5910 ELSE IF( ILO.LT.1 ) THEN
5911 INFO = -4
5912 ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
5913 INFO = -5
5914 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
5915 INFO = -7
5916 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
5917 INFO = -9
5918 ELSE IF( ( ILQ .AND. LDQ.LT.N ) .OR. LDQ.LT.1 ) THEN
5919 INFO = -11
5920 ELSE IF( ( ILZ .AND. LDZ.LT.N ) .OR. LDZ.LT.1 ) THEN
5921 INFO = -13
5922 END IF
5923 IF( INFO.NE.0 ) THEN
5924 CALL XERBLA( 'DGGHRD', -INFO )
5925 RETURN
5926 END IF
5927 *
5928 * Initialize Q and Z if desired.
5929 *
5930 IF( ICOMPQ.EQ.3 )
5931 $ CALL DLASET( 'Full', N, N, ZERO, ONE, Q, LDQ )
5932 IF( ICOMPZ.EQ.3 )
5933 $ CALL DLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )
5934 *
5935 * Quick return if possible
5936 *
5937 IF( N.LE.1 )
5938 $ RETURN
5939 *
5940 * Zero out lower triangle of B
5941 *
5942 DO 20 JCOL = 1, N - 1
5943 DO 10 JROW = JCOL + 1, N
5944 B( JROW, JCOL ) = ZERO
5945 10 CONTINUE
5946 20 CONTINUE
5947 *
5948 * Reduce A and B
5949 *
5950 DO 40 JCOL = ILO, IHI - 2
5951 *
5952 DO 30 JROW = IHI, JCOL + 2, -1
5953 *
5954 * Step 1: rotate rows JROW-1, JROW to kill A(JROW,JCOL)
5955 *
5956 TEMP = A( JROW-1, JCOL )
5957 CALL DLARTG( TEMP, A( JROW, JCOL ), C, S,
5958 $ A( JROW-1, JCOL ) )
5959 A( JROW, JCOL ) = ZERO
5960 CALL DROT( N-JCOL, A( JROW-1, JCOL+1 ), LDA,
5961 $ A( JROW, JCOL+1 ), LDA, C, S )
5962 CALL DROT( N+2-JROW, B( JROW-1, JROW-1 ), LDB,
5963 $ B( JROW, JROW-1 ), LDB, C, S )
5964 IF( ILQ )
5965 $ CALL DROT( N, Q( 1, JROW-1 ), 1, Q( 1, JROW ), 1, C, S )
5966 *
5967 * Step 2: rotate columns JROW, JROW-1 to kill B(JROW,JROW-1)
5968 *
5969 TEMP = B( JROW, JROW )
5970 CALL DLARTG( TEMP, B( JROW, JROW-1 ), C, S,
5971 $ B( JROW, JROW ) )
5972 B( JROW, JROW-1 ) = ZERO
5973 CALL DROT( IHI, A( 1, JROW ), 1, A( 1, JROW-1 ), 1, C, S )
5974 CALL DROT( JROW-1, B( 1, JROW ), 1, B( 1, JROW-1 ), 1, C,
5975 $ S )
5976 IF( ILZ )
5977 $ CALL DROT( N, Z( 1, JROW ), 1, Z( 1, JROW-1 ), 1, C, S )
5978 30 CONTINUE
5979 40 CONTINUE
5980 *
5981 RETURN
5982 *
5983 * End of DGGHRD
5984 *
5985 END
5986 C
5987 C-----------------------------------------------------------------------
5988 C-----------------------------------------------------------------------
5989 SUBROUTINE DGGBAL( JOB, N, A, LDA, B, LDB, ILO, IHI, LSCALE,
5990 $ RSCALE, WORK, INFO )
5991 *
5992 * -- LAPACK routine (version 3.2.2) --
5993 * -- LAPACK is a software package provided by Univ. of Tennessee, --
5994 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
5995 * June 2010
5996 *
5997 * .. Scalar Arguments ..
5998 CHARACTER JOB
5999 INTEGER IHI, ILO, INFO, LDA, LDB, N
6000 * ..
6001 * .. Array Arguments ..
6002 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), LSCALE( * ),
6003 $ RSCALE( * ), WORK( * )
6004 * ..
6005 *
6006 * Purpose
6007 * =======
6008 *
6009 * DGGBAL balances a pair of general real matrices (A,B). This
6010 * involves, first, permuting A and B by similarity transformations to
6011 * isolate eigenvalues in the first 1 to ILO$-$1 and last IHI+1 to N
6012 * elements on the diagonal; and second, applying a diagonal similarity
6013 * transformation to rows and columns ILO to IHI to make the rows
6014 * and columns as close in norm as possible. Both steps are optional.
6015 *
6016 * Balancing may reduce the 1-norm of the matrices, and improve the
6017 * accuracy of the computed eigenvalues and/or eigenvectors in the
6018 * generalized eigenvalue problem A*x = lambda*B*x.
6019 *
6020 * Arguments
6021 * =========
6022 *
6023 * JOB (input) CHARACTER*1
6024 * Specifies the operations to be performed on A and B:
6025 * = 'N': none: simply set ILO = 1, IHI = N, LSCALE(I) = 1.0
6026 * and RSCALE(I) = 1.0 for i = 1,...,N.
6027 * = 'P': permute only;
6028 * = 'S': scale only;
6029 * = 'B': both permute and scale.
6030 *
6031 * N (input) INTEGER
6032 * The order of the matrices A and B. N >= 0.
6033 *
6034 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
6035 * On entry, the input matrix A.
6036 * On exit, A is overwritten by the balanced matrix.
6037 * If JOB = 'N', A is not referenced.
6038 *
6039 * LDA (input) INTEGER
6040 * The leading dimension of the array A. LDA >= max(1,N).
6041 *
6042 * B (input/output) DOUBLE PRECISION array, dimension (LDB,N)
6043 * On entry, the input matrix B.
6044 * On exit, B is overwritten by the balanced matrix.
6045 * If JOB = 'N', B is not referenced.
6046 *
6047 * LDB (input) INTEGER
6048 * The leading dimension of the array B. LDB >= max(1,N).
6049 *
6050 * ILO (output) INTEGER
6051 * IHI (output) INTEGER
6052 * ILO and IHI are set to integers such that on exit
6053 * A(i,j) = 0 and B(i,j) = 0 if i > j and
6054 * j = 1,...,ILO-1 or i = IHI+1,...,N.
6055 * If JOB = 'N' or 'S', ILO = 1 and IHI = N.
6056 *
6057 * LSCALE (output) DOUBLE PRECISION array, dimension (N)
6058 * Details of the permutations and scaling factors applied
6059 * to the left side of A and B. If P(j) is the index of the
6060 * row interchanged with row j, and D(j)
6061 * is the scaling factor applied to row j, then
6062 * LSCALE(j) = P(j) for J = 1,...,ILO-1
6063 * = D(j) for J = ILO,...,IHI
6064 * = P(j) for J = IHI+1,...,N.
6065 * The order in which the interchanges are made is N to IHI+1,
6066 * then 1 to ILO-1.
6067 *
6068 * RSCALE (output) DOUBLE PRECISION array, dimension (N)
6069 * Details of the permutations and scaling factors applied
6070 * to the right side of A and B. If P(j) is the index of the
6071 * column interchanged with column j, and D(j)
6072 * is the scaling factor applied to column j, then
6073 * LSCALE(j) = P(j) for J = 1,...,ILO-1
6074 * = D(j) for J = ILO,...,IHI
6075 * = P(j) for J = IHI+1,...,N.
6076 * The order in which the interchanges are made is N to IHI+1,
6077 * then 1 to ILO-1.
6078 *
6079 * WORK (workspace) DOUBLE PRECISION array, dimension (lwork)
6080 * lwork must be at least max(1,6*N) when JOB = 'S' or 'B', and
6081 * at least 1 when JOB = 'N' or 'P'.
6082 *
6083 * INFO (output) INTEGER
6084 * = 0: successful exit
6085 * < 0: if INFO = -i, the i-th argument had an illegal value.
6086 *
6087 * Further Details
6088 * ===============
6089 *
6090 * See R.C. WARD, Balancing the generalized eigenvalue problem,
6091 * SIAM J. Sci. Stat. Comp. 2 (1981), 141-152.
6092 *
6093 * =====================================================================
6094 *
6095 * .. Parameters ..
6096 DOUBLE PRECISION ZERO, HALF, ONE
6097 PARAMETER ( ZERO = 0.0D+0, HALF = 0.5D+0, ONE = 1.0D+0 )
6098 DOUBLE PRECISION THREE, SCLFAC
6099 PARAMETER ( THREE = 3.0D+0, SCLFAC = 1.0D+1 )
6100 * ..
6101 * .. Local Scalars ..
6102 INTEGER I, ICAB, IFLOW, IP1, IR, IRAB, IT, J, JC, JP1,
6103 $ K, KOUNT, L, LCAB, LM1, LRAB, LSFMAX, LSFMIN,
6104 $ M, NR, NRP2
6105 DOUBLE PRECISION ALPHA, BASL, BETA, CAB, CMAX, COEF, COEF2,
6106 $ COEF5, COR, EW, EWC, GAMMA, PGAMMA, RAB, SFMAX,
6107 $ SFMIN, SUM, T, TA, TB, TC
6108 * ..
6109 * .. External Functions ..
6110 LOGICAL LSAME
6111 INTEGER IDAMAX
6112 DOUBLE PRECISION DDOT, DLAMCH
6113 EXTERNAL LSAME, IDAMAX, DDOT, DLAMCH
6114 * ..
6115 * .. External Subroutines ..
6116 EXTERNAL DAXPY, DSCAL, DSWAP, XERBLA
6117 * ..
6118 * .. Intrinsic Functions ..
6119 INTRINSIC ABS, DBLE, INT, LOG10, MAX, MIN, SIGN
6120 * ..
6121 * .. Executable Statements ..
6122 *
6123 * Test the input parameters
6124 *
6125 INFO = 0
6126 IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.LSAME( JOB, 'P' ) .AND.
6127 $ .NOT.LSAME( JOB, 'S' ) .AND. .NOT.LSAME( JOB, 'B' ) ) THEN
6128 INFO = -1
6129 ELSE IF( N.LT.0 ) THEN
6130 INFO = -2
6131 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
6132 INFO = -4
6133 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
6134 INFO = -6
6135 END IF
6136 IF( INFO.NE.0 ) THEN
6137 CALL XERBLA( 'DGGBAL', -INFO )
6138 RETURN
6139 END IF
6140 *
6141 * Quick return if possible
6142 *
6143 IF( N.EQ.0 ) THEN
6144 ILO = 1
6145 IHI = N
6146 RETURN
6147 END IF
6148 *
6149 IF( N.EQ.1 ) THEN
6150 ILO = 1
6151 IHI = N
6152 LSCALE( 1 ) = ONE
6153 RSCALE( 1 ) = ONE
6154 RETURN
6155 END IF
6156 *
6157 IF( LSAME( JOB, 'N' ) ) THEN
6158 ILO = 1
6159 IHI = N
6160 DO 10 I = 1, N
6161 LSCALE( I ) = ONE
6162 RSCALE( I ) = ONE
6163 10 CONTINUE
6164 RETURN
6165 END IF
6166 *
6167 K = 1
6168 L = N
6169 IF( LSAME( JOB, 'S' ) )
6170 $ GO TO 190
6171 *
6172 GO TO 30
6173 *
6174 * Permute the matrices A and B to isolate the eigenvalues.
6175 *
6176 * Find row with one nonzero in columns 1 through L
6177 *
6178 20 CONTINUE
6179 L = LM1
6180 IF( L.NE.1 )
6181 $ GO TO 30
6182 *
6183 RSCALE( 1 ) = ONE
6184 LSCALE( 1 ) = ONE
6185 GO TO 190
6186 *
6187 30 CONTINUE
6188 LM1 = L - 1
6189 DO 80 I = L, 1, -1
6190 DO 40 J = 1, LM1
6191 JP1 = J + 1
6192 IF( A( I, J ).NE.ZERO .OR. B( I, J ).NE.ZERO )
6193 $ GO TO 50
6194 40 CONTINUE
6195 J = L
6196 GO TO 70
6197 *
6198 50 CONTINUE
6199 DO 60 J = JP1, L
6200 IF( A( I, J ).NE.ZERO .OR. B( I, J ).NE.ZERO )
6201 $ GO TO 80
6202 60 CONTINUE
6203 J = JP1 - 1
6204 *
6205 70 CONTINUE
6206 M = L
6207 IFLOW = 1
6208 GO TO 160
6209 80 CONTINUE
6210 GO TO 100
6211 *
6212 * Find column with one nonzero in rows K through N
6213 *
6214 90 CONTINUE
6215 K = K + 1
6216 *
6217 100 CONTINUE
6218 DO 150 J = K, L
6219 DO 110 I = K, LM1
6220 IP1 = I + 1
6221 IF( A( I, J ).NE.ZERO .OR. B( I, J ).NE.ZERO )
6222 $ GO TO 120
6223 110 CONTINUE
6224 I = L
6225 GO TO 140
6226 120 CONTINUE
6227 DO 130 I = IP1, L
6228 IF( A( I, J ).NE.ZERO .OR. B( I, J ).NE.ZERO )
6229 $ GO TO 150
6230 130 CONTINUE
6231 I = IP1 - 1
6232 140 CONTINUE
6233 M = K
6234 IFLOW = 2
6235 GO TO 160
6236 150 CONTINUE
6237 GO TO 190
6238 *
6239 * Permute rows M and I
6240 *
6241 160 CONTINUE
6242 LSCALE( M ) = I
6243 IF( I.EQ.M )
6244 $ GO TO 170
6245 CALL DSWAP( N-K+1, A( I, K ), LDA, A( M, K ), LDA )
6246 CALL DSWAP( N-K+1, B( I, K ), LDB, B( M, K ), LDB )
6247 *
6248 * Permute columns M and J
6249 *
6250 170 CONTINUE
6251 RSCALE( M ) = J
6252 IF( J.EQ.M )
6253 $ GO TO 180
6254 CALL DSWAP( L, A( 1, J ), 1, A( 1, M ), 1 )
6255 CALL DSWAP( L, B( 1, J ), 1, B( 1, M ), 1 )
6256 *
6257 180 CONTINUE
6258 GO TO ( 20, 90 )IFLOW
6259 *
6260 190 CONTINUE
6261 ILO = K
6262 IHI = L
6263 *
6264 IF( LSAME( JOB, 'P' ) ) THEN
6265 DO 195 I = ILO, IHI
6266 LSCALE( I ) = ONE
6267 RSCALE( I ) = ONE
6268 195 CONTINUE
6269 RETURN
6270 END IF
6271 *
6272 IF( ILO.EQ.IHI )
6273 $ RETURN
6274 *
6275 * Balance the submatrix in rows ILO to IHI.
6276 *
6277 NR = IHI - ILO + 1
6278 DO 200 I = ILO, IHI
6279 RSCALE( I ) = ZERO
6280 LSCALE( I ) = ZERO
6281 *
6282 WORK( I ) = ZERO
6283 WORK( I+N ) = ZERO
6284 WORK( I+2*N ) = ZERO
6285 WORK( I+3*N ) = ZERO
6286 WORK( I+4*N ) = ZERO
6287 WORK( I+5*N ) = ZERO
6288 200 CONTINUE
6289 *
6290 * Compute right side vector in resulting linear equations
6291 *
6292 BASL = LOG10( SCLFAC )
6293 DO 240 I = ILO, IHI
6294 DO 230 J = ILO, IHI
6295 TB = B( I, J )
6296 TA = A( I, J )
6297 IF( TA.EQ.ZERO )
6298 $ GO TO 210
6299 TA = LOG10( ABS( TA ) ) / BASL
6300 210 CONTINUE
6301 IF( TB.EQ.ZERO )
6302 $ GO TO 220
6303 TB = LOG10( ABS( TB ) ) / BASL
6304 220 CONTINUE
6305 WORK( I+4*N ) = WORK( I+4*N ) - TA - TB
6306 WORK( J+5*N ) = WORK( J+5*N ) - TA - TB
6307 230 CONTINUE
6308 240 CONTINUE
6309 *
6310 COEF = ONE / DBLE( 2*NR )
6311 COEF2 = COEF*COEF
6312 COEF5 = HALF*COEF2
6313 NRP2 = NR + 2
6314 BETA = ZERO
6315 IT = 1
6316 *
6317 * Start generalized conjugate gradient iteration
6318 *
6319 250 CONTINUE
6320 *
6321 GAMMA = DDOT( NR, WORK( ILO+4*N ), 1, WORK( ILO+4*N ), 1 ) +
6322 $ DDOT( NR, WORK( ILO+5*N ), 1, WORK( ILO+5*N ), 1 )
6323 *
6324 EW = ZERO
6325 EWC = ZERO
6326 DO 260 I = ILO, IHI
6327 EW = EW + WORK( I+4*N )
6328 EWC = EWC + WORK( I+5*N )
6329 260 CONTINUE
6330 *
6331 GAMMA = COEF*GAMMA - COEF2*( EW**2+EWC**2 ) - COEF5*( EW-EWC )**2
6332 IF( GAMMA.EQ.ZERO )
6333 $ GO TO 350
6334 IF( IT.NE.1 )
6335 $ BETA = GAMMA / PGAMMA
6336 T = COEF5*( EWC-THREE*EW )
6337 TC = COEF5*( EW-THREE*EWC )
6338 *
6339 CALL DSCAL( NR, BETA, WORK( ILO ), 1 )
6340 CALL DSCAL( NR, BETA, WORK( ILO+N ), 1 )
6341 *
6342 CALL DAXPY( NR, COEF, WORK( ILO+4*N ), 1, WORK( ILO+N ), 1 )
6343 CALL DAXPY( NR, COEF, WORK( ILO+5*N ), 1, WORK( ILO ), 1 )
6344 *
6345 DO 270 I = ILO, IHI
6346 WORK( I ) = WORK( I ) + TC
6347 WORK( I+N ) = WORK( I+N ) + T
6348 270 CONTINUE
6349 *
6350 * Apply matrix to vector
6351 *
6352 DO 300 I = ILO, IHI
6353 KOUNT = 0
6354 SUM = ZERO
6355 DO 290 J = ILO, IHI
6356 IF( A( I, J ).EQ.ZERO )
6357 $ GO TO 280
6358 KOUNT = KOUNT + 1
6359 SUM = SUM + WORK( J )
6360 280 CONTINUE
6361 IF( B( I, J ).EQ.ZERO )
6362 $ GO TO 290
6363 KOUNT = KOUNT + 1
6364 SUM = SUM + WORK( J )
6365 290 CONTINUE
6366 WORK( I+2*N ) = DBLE( KOUNT )*WORK( I+N ) + SUM
6367 300 CONTINUE
6368 *
6369 DO 330 J = ILO, IHI
6370 KOUNT = 0
6371 SUM = ZERO
6372 DO 320 I = ILO, IHI
6373 IF( A( I, J ).EQ.ZERO )
6374 $ GO TO 310
6375 KOUNT = KOUNT + 1
6376 SUM = SUM + WORK( I+N )
6377 310 CONTINUE
6378 IF( B( I, J ).EQ.ZERO )
6379 $ GO TO 320
6380 KOUNT = KOUNT + 1
6381 SUM = SUM + WORK( I+N )
6382 320 CONTINUE
6383 WORK( J+3*N ) = DBLE( KOUNT )*WORK( J ) + SUM
6384 330 CONTINUE
6385 *
6386 SUM = DDOT( NR, WORK( ILO+N ), 1, WORK( ILO+2*N ), 1 ) +
6387 $ DDOT( NR, WORK( ILO ), 1, WORK( ILO+3*N ), 1 )
6388 ALPHA = GAMMA / SUM
6389 *
6390 * Determine correction to current iteration
6391 *
6392 CMAX = ZERO
6393 DO 340 I = ILO, IHI
6394 COR = ALPHA*WORK( I+N )
6395 IF( ABS( COR ).GT.CMAX )
6396 $ CMAX = ABS( COR )
6397 LSCALE( I ) = LSCALE( I ) + COR
6398 COR = ALPHA*WORK( I )
6399 IF( ABS( COR ).GT.CMAX )
6400 $ CMAX = ABS( COR )
6401 RSCALE( I ) = RSCALE( I ) + COR
6402 340 CONTINUE
6403 IF( CMAX.LT.HALF )
6404 $ GO TO 350
6405 *
6406 CALL DAXPY( NR, -ALPHA, WORK( ILO+2*N ), 1, WORK( ILO+4*N ), 1 )
6407 CALL DAXPY( NR, -ALPHA, WORK( ILO+3*N ), 1, WORK( ILO+5*N ), 1 )
6408 *
6409 PGAMMA = GAMMA
6410 IT = IT + 1
6411 IF( IT.LE.NRP2 )
6412 $ GO TO 250
6413 *
6414 * End generalized conjugate gradient iteration
6415 *
6416 350 CONTINUE
6417 SFMIN = DLAMCH( 'S' )
6418 SFMAX = ONE / SFMIN
6419 LSFMIN = INT( LOG10( SFMIN ) / BASL+ONE )
6420 LSFMAX = INT( LOG10( SFMAX ) / BASL )
6421 DO 360 I = ILO, IHI
6422 IRAB = IDAMAX( N-ILO+1, A( I, ILO ), LDA )
6423 RAB = ABS( A( I, IRAB+ILO-1 ) )
6424 IRAB = IDAMAX( N-ILO+1, B( I, ILO ), LDB )
6425 RAB = MAX( RAB, ABS( B( I, IRAB+ILO-1 ) ) )
6426 LRAB = INT( LOG10( RAB+SFMIN ) / BASL+ONE )
6427 IR = LSCALE( I ) + SIGN( HALF, LSCALE( I ) )
6428 IR = MIN( MAX( IR, LSFMIN ), LSFMAX, LSFMAX-LRAB )
6429 LSCALE( I ) = SCLFAC**IR
6430 ICAB = IDAMAX( IHI, A( 1, I ), 1 )
6431 CAB = ABS( A( ICAB, I ) )
6432 ICAB = IDAMAX( IHI, B( 1, I ), 1 )
6433 CAB = MAX( CAB, ABS( B( ICAB, I ) ) )
6434 LCAB = INT( LOG10( CAB+SFMIN ) / BASL+ONE )
6435 JC = RSCALE( I ) + SIGN( HALF, RSCALE( I ) )
6436 JC = MIN( MAX( JC, LSFMIN ), LSFMAX, LSFMAX-LCAB )
6437 RSCALE( I ) = SCLFAC**JC
6438 360 CONTINUE
6439 *
6440 * Row scaling of matrices A and B
6441 *
6442 DO 370 I = ILO, IHI
6443 CALL DSCAL( N-ILO+1, LSCALE( I ), A( I, ILO ), LDA )
6444 CALL DSCAL( N-ILO+1, LSCALE( I ), B( I, ILO ), LDB )
6445 370 CONTINUE
6446 *
6447 * Column scaling of matrices A and B
6448 *
6449 DO 380 J = ILO, IHI
6450 CALL DSCAL( IHI, RSCALE( J ), A( 1, J ), 1 )
6451 CALL DSCAL( IHI, RSCALE( J ), B( 1, J ), 1 )
6452 380 CONTINUE
6453 *
6454 RETURN
6455 *
6456 * End of DGGBAL
6457 *
6458 END
6459 C
6460 C-----------------------------------------------------------------------
6461 C-----------------------------------------------------------------------
6462 SUBROUTINE DHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT,
6463 $ ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, WORK,
6464 $ LWORK, INFO )
6465 *
6466 * -- LAPACK routine (version 3.2.1) --
6467 * -- LAPACK is a software package provided by Univ. of Tennessee, --
6468 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
6469 * -- April 2009 --
6470 *
6471 * .. Scalar Arguments ..
6472 CHARACTER COMPQ, COMPZ, JOB
6473 INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N
6474 * ..
6475 * .. Array Arguments ..
6476 DOUBLE PRECISION ALPHAI( * ), ALPHAR( * ), BETA( * ),
6477 $ H( LDH, * ), Q( LDQ, * ), T( LDT, * ),
6478 $ WORK( * ), Z( LDZ, * )
6479 * ..
6480 *
6481 * Purpose
6482 * =======
6483 *
6484 * DHGEQZ computes the eigenvalues of a real matrix pair (H,T),
6485 * where H is an upper Hessenberg matrix and T is upper triangular,
6486 * using the double-shift QZ method.
6487 * Matrix pairs of this type are produced by the reduction to
6488 * generalized upper Hessenberg form of a real matrix pair (A,B):
6489 *
6490 * A = Q1*H*Z1**T, B = Q1*T*Z1**T,
6491 *
6492 * as computed by DGGHRD.
6493 *
6494 * If JOB='S', then the Hessenberg-triangular pair (H,T) is
6495 * also reduced to generalized Schur form,
6496 *
6497 * H = Q*S*Z**T, T = Q*P*Z**T,
6498 *
6499 * where Q and Z are orthogonal matrices, P is an upper triangular
6500 * matrix, and S is a quasi-triangular matrix with 1-by-1 and 2-by-2
6501 * diagonal blocks.
6502 *
6503 * The 1-by-1 blocks correspond to real eigenvalues of the matrix pair
6504 * (H,T) and the 2-by-2 blocks correspond to complex conjugate pairs of
6505 * eigenvalues.
6506 *
6507 * Additionally, the 2-by-2 upper triangular diagonal blocks of P
6508 * corresponding to 2-by-2 blocks of S are reduced to positive diagonal
6509 * form, i.e., if S(j+1,j) is non-zero, then P(j+1,j) = P(j,j+1) = 0,
6510 * P(j,j) > 0, and P(j+1,j+1) > 0.
6511 *
6512 * Optionally, the orthogonal matrix Q from the generalized Schur
6513 * factorization may be postmultiplied into an input matrix Q1, and the
6514 * orthogonal matrix Z may be postmultiplied into an input matrix Z1.
6515 * If Q1 and Z1 are the orthogonal matrices from DGGHRD that reduced
6516 * the matrix pair (A,B) to generalized upper Hessenberg form, then the
6517 * output matrices Q1*Q and Z1*Z are the orthogonal factors from the
6518 * generalized Schur factorization of (A,B):
6519 *
6520 * A = (Q1*Q)*S*(Z1*Z)**T, B = (Q1*Q)*P*(Z1*Z)**T.
6521 *
6522 * To avoid overflow, eigenvalues of the matrix pair (H,T) (equivalently,
6523 * of (A,B)) are computed as a pair of values (alpha,beta), where alpha is
6524 * complex and beta real.
6525 * If beta is nonzero, lambda = alpha / beta is an eigenvalue of the
6526 * generalized nonsymmetric eigenvalue problem (GNEP)
6527 * A*x = lambda*B*x
6528 * and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the
6529 * alternate form of the GNEP
6530 * mu*A*y = B*y.
6531 * Real eigenvalues can be read directly from the generalized Schur
6532 * form:
6533 * alpha = S(i,i), beta = P(i,i).
6534 *
6535 * Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix
6536 * Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973),
6537 * pp. 241--256.
6538 *
6539 * Arguments
6540 * =========
6541 *
6542 * JOB (input) CHARACTER*1
6543 * = 'E': Compute eigenvalues only;
6544 * = 'S': Compute eigenvalues and the Schur form.
6545 *
6546 * COMPQ (input) CHARACTER*1
6547 * = 'N': Left Schur vectors (Q) are not computed;
6548 * = 'I': Q is initialized to the unit matrix and the matrix Q
6549 * of left Schur vectors of (H,T) is returned;
6550 * = 'V': Q must contain an orthogonal matrix Q1 on entry and
6551 * the product Q1*Q is returned.
6552 *
6553 * COMPZ (input) CHARACTER*1
6554 * = 'N': Right Schur vectors (Z) are not computed;
6555 * = 'I': Z is initialized to the unit matrix and the matrix Z
6556 * of right Schur vectors of (H,T) is returned;
6557 * = 'V': Z must contain an orthogonal matrix Z1 on entry and
6558 * the product Z1*Z is returned.
6559 *
6560 * N (input) INTEGER
6561 * The order of the matrices H, T, Q, and Z. N >= 0.
6562 *
6563 * ILO (input) INTEGER
6564 * IHI (input) INTEGER
6565 * ILO and IHI mark the rows and columns of H which are in
6566 * Hessenberg form. It is assumed that A is already upper
6567 * triangular in rows and columns 1:ILO-1 and IHI+1:N.
6568 * If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0.
6569 *
6570 * H (input/output) DOUBLE PRECISION array, dimension (LDH, N)
6571 * On entry, the N-by-N upper Hessenberg matrix H.
6572 * On exit, if JOB = 'S', H contains the upper quasi-triangular
6573 * matrix S from the generalized Schur factorization;
6574 * 2-by-2 diagonal blocks (corresponding to complex conjugate
6575 * pairs of eigenvalues) are returned in standard form, with
6576 * H(i,i) = H(i+1,i+1) and H(i+1,i)*H(i,i+1) < 0.
6577 * If JOB = 'E', the diagonal blocks of H match those of S, but
6578 * the rest of H is unspecified.
6579 *
6580 * LDH (input) INTEGER
6581 * The leading dimension of the array H. LDH >= max( 1, N ).
6582 *
6583 * T (input/output) DOUBLE PRECISION array, dimension (LDT, N)
6584 * On entry, the N-by-N upper triangular matrix T.
6585 * On exit, if JOB = 'S', T contains the upper triangular
6586 * matrix P from the generalized Schur factorization;
6587 * 2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks of S
6588 * are reduced to positive diagonal form, i.e., if H(j+1,j) is
6589 * non-zero, then T(j+1,j) = T(j,j+1) = 0, T(j,j) > 0, and
6590 * T(j+1,j+1) > 0.
6591 * If JOB = 'E', the diagonal blocks of T match those of P, but
6592 * the rest of T is unspecified.
6593 *
6594 * LDT (input) INTEGER
6595 * The leading dimension of the array T. LDT >= max( 1, N ).
6596 *
6597 * ALPHAR (output) DOUBLE PRECISION array, dimension (N)
6598 * The real parts of each scalar alpha defining an eigenvalue
6599 * of GNEP.
6600 *
6601 * ALPHAI (output) DOUBLE PRECISION array, dimension (N)
6602 * The imaginary parts of each scalar alpha defining an
6603 * eigenvalue of GNEP.
6604 * If ALPHAI(j) is zero, then the j-th eigenvalue is real; if
6605 * positive, then the j-th and (j+1)-st eigenvalues are a
6606 * complex conjugate pair, with ALPHAI(j+1) = -ALPHAI(j).
6607 *
6608 * BETA (output) DOUBLE PRECISION array, dimension (N)
6609 * The scalars beta that define the eigenvalues of GNEP.
6610 * Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and
6611 * beta = BETA(j) represent the j-th eigenvalue of the matrix
6612 * pair (A,B), in one of the forms lambda = alpha/beta or
6613 * mu = beta/alpha. Since either lambda or mu may overflow,
6614 * they should not, in general, be computed.
6615 *
6616 * Q (input/output) DOUBLE PRECISION array, dimension (LDQ, N)
6617 * On entry, if COMPZ = 'V', the orthogonal matrix Q1 used in
6618 * the reduction of (A,B) to generalized Hessenberg form.
6619 * On exit, if COMPZ = 'I', the orthogonal matrix of left Schur
6620 * vectors of (H,T), and if COMPZ = 'V', the orthogonal matrix
6621 * of left Schur vectors of (A,B).
6622 * Not referenced if COMPZ = 'N'.
6623 *
6624 * LDQ (input) INTEGER
6625 * The leading dimension of the array Q. LDQ >= 1.
6626 * If COMPQ='V' or 'I', then LDQ >= N.
6627 *
6628 * Z (input/output) DOUBLE PRECISION array, dimension (LDZ, N)
6629 * On entry, if COMPZ = 'V', the orthogonal matrix Z1 used in
6630 * the reduction of (A,B) to generalized Hessenberg form.
6631 * On exit, if COMPZ = 'I', the orthogonal matrix of
6632 * right Schur vectors of (H,T), and if COMPZ = 'V', the
6633 * orthogonal matrix of right Schur vectors of (A,B).
6634 * Not referenced if COMPZ = 'N'.
6635 *
6636 * LDZ (input) INTEGER
6637 * The leading dimension of the array Z. LDZ >= 1.
6638 * If COMPZ='V' or 'I', then LDZ >= N.
6639 *
6640 * WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
6641 * On exit, if INFO >= 0, WORK(1) returns the optimal LWORK.
6642 *
6643 * LWORK (input) INTEGER
6644 * The dimension of the array WORK. LWORK >= max(1,N).
6645 *
6646 * If LWORK = -1, then a workspace query is assumed; the routine
6647 * only calculates the optimal size of the WORK array, returns
6648 * this value as the first entry of the WORK array, and no error
6649 * message related to LWORK is issued by XERBLA.
6650 *
6651 * INFO (output) INTEGER
6652 * = 0: successful exit
6653 * < 0: if INFO = -i, the i-th argument had an illegal value
6654 * = 1,...,N: the QZ iteration did not converge. (H,T) is not
6655 * in Schur form, but ALPHAR(i), ALPHAI(i), and
6656 * BETA(i), i=INFO+1,...,N should be correct.
6657 * = N+1,...,2*N: the shift calculation failed. (H,T) is not
6658 * in Schur form, but ALPHAR(i), ALPHAI(i), and
6659 * BETA(i), i=INFO-N+1,...,N should be correct.
6660 *
6661 * Further Details
6662 * ===============
6663 *
6664 * Iteration counters:
6665 *
6666 * JITER -- counts iterations.
6667 * IITER -- counts iterations run since ILAST was last
6668 * changed. This is therefore reset only when a 1-by-1 or
6669 * 2-by-2 block deflates off the bottom.
6670 *
6671 * =====================================================================
6672 *
6673 * .. Parameters ..
6674 * $ SAFETY = 1.0E+0 )
6675 DOUBLE PRECISION HALF, ZERO, ONE, SAFETY
6676 PARAMETER ( HALF = 0.5D+0, ZERO = 0.0D+0, ONE = 1.0D+0,
6677 $ SAFETY = 1.0D+2 )
6678 * ..
6679 * .. Local Scalars ..
6680 LOGICAL ILAZR2, ILAZRO, ILPIVT, ILQ, ILSCHR, ILZ,
6681 $ LQUERY
6682 INTEGER ICOMPQ, ICOMPZ, IFIRST, IFRSTM, IITER, ILAST,
6683 $ ILASTM, IN, ISCHUR, ISTART, J, JC, JCH, JITER,
6684 $ JR, MAXIT
6685 DOUBLE PRECISION A11, A12, A1I, A1R, A21, A22, A2I, A2R, AD11,
6686 $ AD11L, AD12, AD12L, AD21, AD21L, AD22, AD22L,
6687 $ AD32L, AN, ANORM, ASCALE, ATOL, B11, B1A, B1I,
6688 $ B1R, B22, B2A, B2I, B2R, BN, BNORM, BSCALE,
6689 $ BTOL, C, C11I, C11R, C12, C21, C22I, C22R, CL,
6690 $ CQ, CR, CZ, ESHIFT, S, S1, S1INV, S2, SAFMAX,
6691 $ SAFMIN, SCALE, SL, SQI, SQR, SR, SZI, SZR, T1,
6692 $ TAU, TEMP, TEMP2, TEMPI, TEMPR, U1, U12, U12L,
6693 $ U2, ULP, VS, W11, W12, W21, W22, WABS, WI, WR,
6694 $ WR2
6695 * ..
6696 * .. Local Arrays ..
6697 DOUBLE PRECISION V( 3 )
6698 * ..
6699 * .. External Functions ..
6700 LOGICAL LSAME
6701 DOUBLE PRECISION DLAMCH, DLANHS, DLAPY2, DLAPY3
6702 EXTERNAL LSAME, DLAMCH, DLANHS, DLAPY2, DLAPY3
6703 * ..
6704 * .. External Subroutines ..
6705 EXTERNAL DLAG2, DLARFG, DLARTG, DLASET, DLASV2, DROT,
6706 $ XERBLA
6707 * ..
6708 * .. Intrinsic Functions ..
6709 INTRINSIC ABS, DBLE, MAX, MIN, SQRT
6710 * ..
6711 * .. Executable Statements ..
6712 *
6713 * Decode JOB, COMPQ, COMPZ
6714 *
6715 IF( LSAME( JOB, 'E' ) ) THEN
6716 ILSCHR = .FALSE.
6717 ISCHUR = 1
6718 ELSE IF( LSAME( JOB, 'S' ) ) THEN
6719 ILSCHR = .TRUE.
6720 ISCHUR = 2
6721 ELSE
6722 ISCHUR = 0
6723 END IF
6724 *
6725 IF( LSAME( COMPQ, 'N' ) ) THEN
6726 ILQ = .FALSE.
6727 ICOMPQ = 1
6728 ELSE IF( LSAME( COMPQ, 'V' ) ) THEN
6729 ILQ = .TRUE.
6730 ICOMPQ = 2
6731 ELSE IF( LSAME( COMPQ, 'I' ) ) THEN
6732 ILQ = .TRUE.
6733 ICOMPQ = 3
6734 ELSE
6735 ICOMPQ = 0
6736 END IF
6737 *
6738 IF( LSAME( COMPZ, 'N' ) ) THEN
6739 ILZ = .FALSE.
6740 ICOMPZ = 1
6741 ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
6742 ILZ = .TRUE.
6743 ICOMPZ = 2
6744 ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
6745 ILZ = .TRUE.
6746 ICOMPZ = 3
6747 ELSE
6748 ICOMPZ = 0
6749 END IF
6750 *
6751 * Check Argument Values
6752 *
6753 INFO = 0
6754 WORK( 1 ) = MAX( 1, N )
6755 LQUERY = ( LWORK.EQ.-1 )
6756 IF( ISCHUR.EQ.0 ) THEN
6757 INFO = -1
6758 ELSE IF( ICOMPQ.EQ.0 ) THEN
6759 INFO = -2
6760 ELSE IF( ICOMPZ.EQ.0 ) THEN
6761 INFO = -3
6762 ELSE IF( N.LT.0 ) THEN
6763 INFO = -4
6764 ELSE IF( ILO.LT.1 ) THEN
6765 INFO = -5
6766 ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
6767 INFO = -6
6768 ELSE IF( LDH.LT.N ) THEN
6769 INFO = -8
6770 ELSE IF( LDT.LT.N ) THEN
6771 INFO = -10
6772 ELSE IF( LDQ.LT.1 .OR. ( ILQ .AND. LDQ.LT.N ) ) THEN
6773 INFO = -15
6774 ELSE IF( LDZ.LT.1 .OR. ( ILZ .AND. LDZ.LT.N ) ) THEN
6775 INFO = -17
6776 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
6777 INFO = -19
6778 END IF
6779 IF( INFO.NE.0 ) THEN
6780 CALL XERBLA( 'DHGEQZ', -INFO )
6781 RETURN
6782 ELSE IF( LQUERY ) THEN
6783 RETURN
6784 END IF
6785 *
6786 * Quick return if possible
6787 *
6788 IF( N.LE.0 ) THEN
6789 WORK( 1 ) = DBLE( 1 )
6790 RETURN
6791 END IF
6792 *
6793 * Initialize Q and Z
6794 *
6795 IF( ICOMPQ.EQ.3 )
6796 $ CALL DLASET( 'Full', N, N, ZERO, ONE, Q, LDQ )
6797 IF( ICOMPZ.EQ.3 )
6798 $ CALL DLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )
6799 *
6800 * Machine Constants
6801 *
6802 IN = IHI + 1 - ILO
6803 SAFMIN = DLAMCH( 'S' )
6804 SAFMAX = ONE / SAFMIN
6805 ULP = DLAMCH( 'E' )*DLAMCH( 'B' )
6806 ANORM = DLANHS( 'F', IN, H( ILO, ILO ), LDH, WORK )
6807 BNORM = DLANHS( 'F', IN, T( ILO, ILO ), LDT, WORK )
6808 ATOL = MAX( SAFMIN, ULP*ANORM )
6809 BTOL = MAX( SAFMIN, ULP*BNORM )
6810 ASCALE = ONE / MAX( SAFMIN, ANORM )
6811 BSCALE = ONE / MAX( SAFMIN, BNORM )
6812 *
6813 * Set Eigenvalues IHI+1:N
6814 *
6815 DO 30 J = IHI + 1, N
6816 IF( T( J, J ).LT.ZERO ) THEN
6817 IF( ILSCHR ) THEN
6818 DO 10 JR = 1, J
6819 H( JR, J ) = -H( JR, J )
6820 T( JR, J ) = -T( JR, J )
6821 10 CONTINUE
6822 ELSE
6823 H( J, J ) = -H( J, J )
6824 T( J, J ) = -T( J, J )
6825 END IF
6826 IF( ILZ ) THEN
6827 DO 20 JR = 1, N
6828 Z( JR, J ) = -Z( JR, J )
6829 20 CONTINUE
6830 END IF
6831 END IF
6832 ALPHAR( J ) = H( J, J )
6833 ALPHAI( J ) = ZERO
6834 BETA( J ) = T( J, J )
6835 30 CONTINUE
6836 *
6837 * If IHI < ILO, skip QZ steps
6838 *
6839 IF( IHI.LT.ILO )
6840 $ GO TO 380
6841 *
6842 * MAIN QZ ITERATION LOOP
6843 *
6844 * Initialize dynamic indices
6845 *
6846 * Eigenvalues ILAST+1:N have been found.
6847 * Column operations modify rows IFRSTM:whatever.
6848 * Row operations modify columns whatever:ILASTM.
6849 *
6850 * If only eigenvalues are being computed, then
6851 * IFRSTM is the row of the last splitting row above row ILAST;
6852 * this is always at least ILO.
6853 * IITER counts iterations since the last eigenvalue was found,
6854 * to tell when to use an extraordinary shift.
6855 * MAXIT is the maximum number of QZ sweeps allowed.
6856 *
6857 ILAST = IHI
6858 IF( ILSCHR ) THEN
6859 IFRSTM = 1
6860 ILASTM = N
6861 ELSE
6862 IFRSTM = ILO
6863 ILASTM = IHI
6864 END IF
6865 IITER = 0
6866 ESHIFT = ZERO
6867 MAXIT = 30*( IHI-ILO+1 )
6868 *
6869 DO 360 JITER = 1, MAXIT
6870 *
6871 * Split the matrix if possible.
6872 *
6873 * Two tests:
6874 * 1: H(j,j-1)=0 or j=ILO
6875 * 2: T(j,j)=0
6876 *
6877 IF( ILAST.EQ.ILO ) THEN
6878 *
6879 * Special case: j=ILAST
6880 *
6881 GO TO 80
6882 ELSE
6883 IF( ABS( H( ILAST, ILAST-1 ) ).LE.ATOL ) THEN
6884 H( ILAST, ILAST-1 ) = ZERO
6885 GO TO 80
6886 END IF
6887 END IF
6888 *
6889 IF( ABS( T( ILAST, ILAST ) ).LE.BTOL ) THEN
6890 T( ILAST, ILAST ) = ZERO
6891 GO TO 70
6892 END IF
6893 *
6894 * General case: j<ILAST
6895 *
6896 DO 60 J = ILAST - 1, ILO, -1
6897 *
6898 * Test 1: for H(j,j-1)=0 or j=ILO
6899 *
6900 IF( J.EQ.ILO ) THEN
6901 ILAZRO = .TRUE.
6902 ELSE
6903 IF( ABS( H( J, J-1 ) ).LE.ATOL ) THEN
6904 H( J, J-1 ) = ZERO
6905 ILAZRO = .TRUE.
6906 ELSE
6907 ILAZRO = .FALSE.
6908 END IF
6909 END IF
6910 *
6911 * Test 2: for T(j,j)=0
6912 *
6913 IF( ABS( T( J, J ) ).LT.BTOL ) THEN
6914 T( J, J ) = ZERO
6915 *
6916 * Test 1a: Check for 2 consecutive small subdiagonals in A
6917 *
6918 ILAZR2 = .FALSE.
6919 IF( .NOT.ILAZRO ) THEN
6920 TEMP = ABS( H( J, J-1 ) )
6921 TEMP2 = ABS( H( J, J ) )
6922 TEMPR = MAX( TEMP, TEMP2 )
6923 IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
6924 TEMP = TEMP / TEMPR
6925 TEMP2 = TEMP2 / TEMPR
6926 END IF
6927 IF( TEMP*( ASCALE*ABS( H( J+1, J ) ) ).LE.TEMP2*
6928 $ ( ASCALE*ATOL ) )ILAZR2 = .TRUE.
6929 END IF
6930 *
6931 * If both tests pass (1 & 2), i.e., the leading diagonal
6932 * element of B in the block is zero, split a 1x1 block off
6933 * at the top. (I.e., at the J-th row/column) The leading
6934 * diagonal element of the remainder can also be zero, so
6935 * this may have to be done repeatedly.
6936 *
6937 IF( ILAZRO .OR. ILAZR2 ) THEN
6938 DO 40 JCH = J, ILAST - 1
6939 TEMP = H( JCH, JCH )
6940 CALL DLARTG( TEMP, H( JCH+1, JCH ), C, S,
6941 $ H( JCH, JCH ) )
6942 H( JCH+1, JCH ) = ZERO
6943 CALL DROT( ILASTM-JCH, H( JCH, JCH+1 ), LDH,
6944 $ H( JCH+1, JCH+1 ), LDH, C, S )
6945 CALL DROT( ILASTM-JCH, T( JCH, JCH+1 ), LDT,
6946 $ T( JCH+1, JCH+1 ), LDT, C, S )
6947 IF( ILQ )
6948 $ CALL DROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
6949 $ C, S )
6950 IF( ILAZR2 )
6951 $ H( JCH, JCH-1 ) = H( JCH, JCH-1 )*C
6952 ILAZR2 = .FALSE.
6953 IF( ABS( T( JCH+1, JCH+1 ) ).GE.BTOL ) THEN
6954 IF( JCH+1.GE.ILAST ) THEN
6955 GO TO 80
6956 ELSE
6957 IFIRST = JCH + 1
6958 GO TO 110
6959 END IF
6960 END IF
6961 T( JCH+1, JCH+1 ) = ZERO
6962 40 CONTINUE
6963 GO TO 70
6964 ELSE
6965 *
6966 * Only test 2 passed -- chase the zero to T(ILAST,ILAST)
6967 * Then process as in the case T(ILAST,ILAST)=0
6968 *
6969 DO 50 JCH = J, ILAST - 1
6970 TEMP = T( JCH, JCH+1 )
6971 CALL DLARTG( TEMP, T( JCH+1, JCH+1 ), C, S,
6972 $ T( JCH, JCH+1 ) )
6973 T( JCH+1, JCH+1 ) = ZERO
6974 IF( JCH.LT.ILASTM-1 )
6975 $ CALL DROT( ILASTM-JCH-1, T( JCH, JCH+2 ), LDT,
6976 $ T( JCH+1, JCH+2 ), LDT, C, S )
6977 CALL DROT( ILASTM-JCH+2, H( JCH, JCH-1 ), LDH,
6978 $ H( JCH+1, JCH-1 ), LDH, C, S )
6979 IF( ILQ )
6980 $ CALL DROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
6981 $ C, S )
6982 TEMP = H( JCH+1, JCH )
6983 CALL DLARTG( TEMP, H( JCH+1, JCH-1 ), C, S,
6984 $ H( JCH+1, JCH ) )
6985 H( JCH+1, JCH-1 ) = ZERO
6986 CALL DROT( JCH+1-IFRSTM, H( IFRSTM, JCH ), 1,
6987 $ H( IFRSTM, JCH-1 ), 1, C, S )
6988 CALL DROT( JCH-IFRSTM, T( IFRSTM, JCH ), 1,
6989 $ T( IFRSTM, JCH-1 ), 1, C, S )
6990 IF( ILZ )
6991 $ CALL DROT( N, Z( 1, JCH ), 1, Z( 1, JCH-1 ), 1,
6992 $ C, S )
6993 50 CONTINUE
6994 GO TO 70
6995 END IF
6996 ELSE IF( ILAZRO ) THEN
6997 *
6998 * Only test 1 passed -- work on J:ILAST
6999 *
7000 IFIRST = J
7001 GO TO 110
7002 END IF
7003 *
7004 * Neither test passed -- try next J
7005 *
7006 60 CONTINUE
7007 *
7008 * (Drop-through is "impossible")
7009 *
7010 INFO = N + 1
7011 GO TO 420
7012 *
7013 * T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a
7014 * 1x1 block.
7015 *
7016 70 CONTINUE
7017 TEMP = H( ILAST, ILAST )
7018 CALL DLARTG( TEMP, H( ILAST, ILAST-1 ), C, S,
7019 $ H( ILAST, ILAST ) )
7020 H( ILAST, ILAST-1 ) = ZERO
7021 CALL DROT( ILAST-IFRSTM, H( IFRSTM, ILAST ), 1,
7022 $ H( IFRSTM, ILAST-1 ), 1, C, S )
7023 CALL DROT( ILAST-IFRSTM, T( IFRSTM, ILAST ), 1,
7024 $ T( IFRSTM, ILAST-1 ), 1, C, S )
7025 IF( ILZ )
7026 $ CALL DROT( N, Z( 1, ILAST ), 1, Z( 1, ILAST-1 ), 1, C, S )
7027 *
7028 * H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHAR, ALPHAI,
7029 * and BETA
7030 *
7031 80 CONTINUE
7032 IF( T( ILAST, ILAST ).LT.ZERO ) THEN
7033 IF( ILSCHR ) THEN
7034 DO 90 J = IFRSTM, ILAST
7035 H( J, ILAST ) = -H( J, ILAST )
7036 T( J, ILAST ) = -T( J, ILAST )
7037 90 CONTINUE
7038 ELSE
7039 H( ILAST, ILAST ) = -H( ILAST, ILAST )
7040 T( ILAST, ILAST ) = -T( ILAST, ILAST )
7041 END IF
7042 IF( ILZ ) THEN
7043 DO 100 J = 1, N
7044 Z( J, ILAST ) = -Z( J, ILAST )
7045 100 CONTINUE
7046 END IF
7047 END IF
7048 ALPHAR( ILAST ) = H( ILAST, ILAST )
7049 ALPHAI( ILAST ) = ZERO
7050 BETA( ILAST ) = T( ILAST, ILAST )
7051 *
7052 * Go to next block -- exit if finished.
7053 *
7054 ILAST = ILAST - 1
7055 IF( ILAST.LT.ILO )
7056 $ GO TO 380
7057 *
7058 * Reset counters
7059 *
7060 IITER = 0
7061 ESHIFT = ZERO
7062 IF( .NOT.ILSCHR ) THEN
7063 ILASTM = ILAST
7064 IF( IFRSTM.GT.ILAST )
7065 $ IFRSTM = ILO
7066 END IF
7067 GO TO 350
7068 *
7069 * QZ step
7070 *
7071 * This iteration only involves rows/columns IFIRST:ILAST. We
7072 * assume IFIRST < ILAST, and that the diagonal of B is non-zero.
7073 *
7074 110 CONTINUE
7075 IITER = IITER + 1
7076 IF( .NOT.ILSCHR ) THEN
7077 IFRSTM = IFIRST
7078 END IF
7079 *
7080 * Compute single shifts.
7081 *
7082 * At this point, IFIRST < ILAST, and the diagonal elements of
7083 * T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in
7084 * magnitude)
7085 *
7086 IF( ( IITER / 10 )*10.EQ.IITER ) THEN
7087 *
7088 * Exceptional shift. Chosen for no particularly good reason.
7089 * (Single shift only.)
7090 *
7091 IF( ( DBLE( MAXIT )*SAFMIN )*ABS( H( ILAST-1, ILAST ) ).LT.
7092 $ ABS( T( ILAST-1, ILAST-1 ) ) ) THEN
7093 ESHIFT = ESHIFT + H( ILAST-1, ILAST ) /
7094 $ T( ILAST-1, ILAST-1 )
7095 ELSE
7096 ESHIFT = ESHIFT + ONE / ( SAFMIN*DBLE( MAXIT ) )
7097 END IF
7098 S1 = ONE
7099 WR = ESHIFT
7100 *
7101 ELSE
7102 *
7103 * Shifts based on the generalized eigenvalues of the
7104 * bottom-right 2x2 block of A and B. The first eigenvalue
7105 * returned by DLAG2 is the Wilkinson shift (AEP p.512),
7106 *
7107 CALL DLAG2( H( ILAST-1, ILAST-1 ), LDH,
7108 $ T( ILAST-1, ILAST-1 ), LDT, SAFMIN*SAFETY, S1,
7109 $ S2, WR, WR2, WI )
7110 *
7111 TEMP = MAX( S1, SAFMIN*MAX( ONE, ABS( WR ), ABS( WI ) ) )
7112 IF( WI.NE.ZERO )
7113 $ GO TO 200
7114 END IF
7115 *
7116 * Fiddle with shift to avoid overflow
7117 *
7118 TEMP = MIN( ASCALE, ONE )*( HALF*SAFMAX )
7119 IF( S1.GT.TEMP ) THEN
7120 SCALE = TEMP / S1
7121 ELSE
7122 SCALE = ONE
7123 END IF
7124 *
7125 TEMP = MIN( BSCALE, ONE )*( HALF*SAFMAX )
7126 IF( ABS( WR ).GT.TEMP )
7127 $ SCALE = MIN( SCALE, TEMP / ABS( WR ) )
7128 S1 = SCALE*S1
7129 WR = SCALE*WR
7130 *
7131 * Now check for two consecutive small subdiagonals.
7132 *
7133 DO 120 J = ILAST - 1, IFIRST + 1, -1
7134 ISTART = J
7135 TEMP = ABS( S1*H( J, J-1 ) )
7136 TEMP2 = ABS( S1*H( J, J )-WR*T( J, J ) )
7137 TEMPR = MAX( TEMP, TEMP2 )
7138 IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
7139 TEMP = TEMP / TEMPR
7140 TEMP2 = TEMP2 / TEMPR
7141 END IF
7142 IF( ABS( ( ASCALE*H( J+1, J ) )*TEMP ).LE.( ASCALE*ATOL )*
7143 $ TEMP2 )GO TO 130
7144 120 CONTINUE
7145 *
7146 ISTART = IFIRST
7147 130 CONTINUE
7148 *
7149 * Do an implicit single-shift QZ sweep.
7150 *
7151 * Initial Q
7152 *
7153 TEMP = S1*H( ISTART, ISTART ) - WR*T( ISTART, ISTART )
7154 TEMP2 = S1*H( ISTART+1, ISTART )
7155 CALL DLARTG( TEMP, TEMP2, C, S, TEMPR )
7156 *
7157 * Sweep
7158 *
7159 DO 190 J = ISTART, ILAST - 1
7160 IF( J.GT.ISTART ) THEN
7161 TEMP = H( J, J-1 )
7162 CALL DLARTG( TEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
7163 H( J+1, J-1 ) = ZERO
7164 END IF
7165 *
7166 DO 140 JC = J, ILASTM
7167 TEMP = C*H( J, JC ) + S*H( J+1, JC )
7168 H( J+1, JC ) = -S*H( J, JC ) + C*H( J+1, JC )
7169 H( J, JC ) = TEMP
7170 TEMP2 = C*T( J, JC ) + S*T( J+1, JC )
7171 T( J+1, JC ) = -S*T( J, JC ) + C*T( J+1, JC )
7172 T( J, JC ) = TEMP2
7173 140 CONTINUE
7174 IF( ILQ ) THEN
7175 DO 150 JR = 1, N
7176 TEMP = C*Q( JR, J ) + S*Q( JR, J+1 )
7177 Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
7178 Q( JR, J ) = TEMP
7179 150 CONTINUE
7180 END IF
7181 *
7182 TEMP = T( J+1, J+1 )
7183 CALL DLARTG( TEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
7184 T( J+1, J ) = ZERO
7185 *
7186 DO 160 JR = IFRSTM, MIN( J+2, ILAST )
7187 TEMP = C*H( JR, J+1 ) + S*H( JR, J )
7188 H( JR, J ) = -S*H( JR, J+1 ) + C*H( JR, J )
7189 H( JR, J+1 ) = TEMP
7190 160 CONTINUE
7191 DO 170 JR = IFRSTM, J
7192 TEMP = C*T( JR, J+1 ) + S*T( JR, J )
7193 T( JR, J ) = -S*T( JR, J+1 ) + C*T( JR, J )
7194 T( JR, J+1 ) = TEMP
7195 170 CONTINUE
7196 IF( ILZ ) THEN
7197 DO 180 JR = 1, N
7198 TEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
7199 Z( JR, J ) = -S*Z( JR, J+1 ) + C*Z( JR, J )
7200 Z( JR, J+1 ) = TEMP
7201 180 CONTINUE
7202 END IF
7203 190 CONTINUE
7204 *
7205 GO TO 350
7206 *
7207 * Use Francis double-shift
7208 *
7209 * Note: the Francis double-shift should work with real shifts,
7210 * but only if the block is at least 3x3.
7211 * This code may break if this point is reached with
7212 * a 2x2 block with real eigenvalues.
7213 *
7214 200 CONTINUE
7215 IF( IFIRST+1.EQ.ILAST ) THEN
7216 *
7217 * Special case -- 2x2 block with complex eigenvectors
7218 *
7219 * Step 1: Standardize, that is, rotate so that
7220 *
7221 * ( B11 0 )
7222 * B = ( ) with B11 non-negative.
7223 * ( 0 B22 )
7224 *
7225 CALL DLASV2( T( ILAST-1, ILAST-1 ), T( ILAST-1, ILAST ),
7226 $ T( ILAST, ILAST ), B22, B11, SR, CR, SL, CL )
7227 *
7228 IF( B11.LT.ZERO ) THEN
7229 CR = -CR
7230 SR = -SR
7231 B11 = -B11
7232 B22 = -B22
7233 END IF
7234 *
7235 CALL DROT( ILASTM+1-IFIRST, H( ILAST-1, ILAST-1 ), LDH,
7236 $ H( ILAST, ILAST-1 ), LDH, CL, SL )
7237 CALL DROT( ILAST+1-IFRSTM, H( IFRSTM, ILAST-1 ), 1,
7238 $ H( IFRSTM, ILAST ), 1, CR, SR )
7239 *
7240 IF( ILAST.LT.ILASTM )
7241 $ CALL DROT( ILASTM-ILAST, T( ILAST-1, ILAST+1 ), LDT,
7242 $ T( ILAST, ILAST+1 ), LDT, CL, SL )
7243 IF( IFRSTM.LT.ILAST-1 )
7244 $ CALL DROT( IFIRST-IFRSTM, T( IFRSTM, ILAST-1 ), 1,
7245 $ T( IFRSTM, ILAST ), 1, CR, SR )
7246 *
7247 IF( ILQ )
7248 $ CALL DROT( N, Q( 1, ILAST-1 ), 1, Q( 1, ILAST ), 1, CL,
7249 $ SL )
7250 IF( ILZ )
7251 $ CALL DROT( N, Z( 1, ILAST-1 ), 1, Z( 1, ILAST ), 1, CR,
7252 $ SR )
7253 *
7254 T( ILAST-1, ILAST-1 ) = B11
7255 T( ILAST-1, ILAST ) = ZERO
7256 T( ILAST, ILAST-1 ) = ZERO
7257 T( ILAST, ILAST ) = B22
7258 *
7259 * If B22 is negative, negate column ILAST
7260 *
7261 IF( B22.LT.ZERO ) THEN
7262 DO 210 J = IFRSTM, ILAST
7263 H( J, ILAST ) = -H( J, ILAST )
7264 T( J, ILAST ) = -T( J, ILAST )
7265 210 CONTINUE
7266 *
7267 IF( ILZ ) THEN
7268 DO 220 J = 1, N
7269 Z( J, ILAST ) = -Z( J, ILAST )
7270 220 CONTINUE
7271 END IF
7272 END IF
7273 *
7274 * Step 2: Compute ALPHAR, ALPHAI, and BETA (see refs.)
7275 *
7276 * Recompute shift
7277 *
7278 CALL DLAG2( H( ILAST-1, ILAST-1 ), LDH,
7279 $ T( ILAST-1, ILAST-1 ), LDT, SAFMIN*SAFETY, S1,
7280 $ TEMP, WR, TEMP2, WI )
7281 *
7282 * If standardization has perturbed the shift onto real line,
7283 * do another (real single-shift) QR step.
7284 *
7285 IF( WI.EQ.ZERO )
7286 $ GO TO 350
7287 S1INV = ONE / S1
7288 *
7289 * Do EISPACK (QZVAL) computation of alpha and beta
7290 *
7291 A11 = H( ILAST-1, ILAST-1 )
7292 A21 = H( ILAST, ILAST-1 )
7293 A12 = H( ILAST-1, ILAST )
7294 A22 = H( ILAST, ILAST )
7295 *
7296 * Compute complex Givens rotation on right
7297 * (Assume some element of C = (sA - wB) > unfl )
7298 * __
7299 * (sA - wB) ( CZ -SZ )
7300 * ( SZ CZ )
7301 *
7302 C11R = S1*A11 - WR*B11
7303 C11I = -WI*B11
7304 C12 = S1*A12
7305 C21 = S1*A21
7306 C22R = S1*A22 - WR*B22
7307 C22I = -WI*B22
7308 *
7309 IF( ABS( C11R )+ABS( C11I )+ABS( C12 ).GT.ABS( C21 )+
7310 $ ABS( C22R )+ABS( C22I ) ) THEN
7311 T1 = DLAPY3( C12, C11R, C11I )
7312 CZ = C12 / T1
7313 SZR = -C11R / T1
7314 SZI = -C11I / T1
7315 ELSE
7316 CZ = DLAPY2( C22R, C22I )
7317 IF( CZ.LE.SAFMIN ) THEN
7318 CZ = ZERO
7319 SZR = ONE
7320 SZI = ZERO
7321 ELSE
7322 TEMPR = C22R / CZ
7323 TEMPI = C22I / CZ
7324 T1 = DLAPY2( CZ, C21 )
7325 CZ = CZ / T1
7326 SZR = -C21*TEMPR / T1
7327 SZI = C21*TEMPI / T1
7328 END IF
7329 END IF
7330 *
7331 * Compute Givens rotation on left
7332 *
7333 * ( CQ SQ )
7334 * ( __ ) A or B
7335 * ( -SQ CQ )
7336 *
7337 AN = ABS( A11 ) + ABS( A12 ) + ABS( A21 ) + ABS( A22 )
7338 BN = ABS( B11 ) + ABS( B22 )
7339 WABS = ABS( WR ) + ABS( WI )
7340 IF( S1*AN.GT.WABS*BN ) THEN
7341 CQ = CZ*B11
7342 SQR = SZR*B22
7343 SQI = -SZI*B22
7344 ELSE
7345 A1R = CZ*A11 + SZR*A12
7346 A1I = SZI*A12
7347 A2R = CZ*A21 + SZR*A22
7348 A2I = SZI*A22
7349 CQ = DLAPY2( A1R, A1I )
7350 IF( CQ.LE.SAFMIN ) THEN
7351 CQ = ZERO
7352 SQR = ONE
7353 SQI = ZERO
7354 ELSE
7355 TEMPR = A1R / CQ
7356 TEMPI = A1I / CQ
7357 SQR = TEMPR*A2R + TEMPI*A2I
7358 SQI = TEMPI*A2R - TEMPR*A2I
7359 END IF
7360 END IF
7361 T1 = DLAPY3( CQ, SQR, SQI )
7362 CQ = CQ / T1
7363 SQR = SQR / T1
7364 SQI = SQI / T1
7365 *
7366 * Compute diagonal elements of QBZ
7367 *
7368 TEMPR = SQR*SZR - SQI*SZI
7369 TEMPI = SQR*SZI + SQI*SZR
7370 B1R = CQ*CZ*B11 + TEMPR*B22
7371 B1I = TEMPI*B22
7372 B1A = DLAPY2( B1R, B1I )
7373 B2R = CQ*CZ*B22 + TEMPR*B11
7374 B2I = -TEMPI*B11
7375 B2A = DLAPY2( B2R, B2I )
7376 *
7377 * Normalize so beta > 0, and Im( alpha1 ) > 0
7378 *
7379 BETA( ILAST-1 ) = B1A
7380 BETA( ILAST ) = B2A
7381 ALPHAR( ILAST-1 ) = ( WR*B1A )*S1INV
7382 ALPHAI( ILAST-1 ) = ( WI*B1A )*S1INV
7383 ALPHAR( ILAST ) = ( WR*B2A )*S1INV
7384 ALPHAI( ILAST ) = -( WI*B2A )*S1INV
7385 *
7386 * Step 3: Go to next block -- exit if finished.
7387 *
7388 ILAST = IFIRST - 1
7389 IF( ILAST.LT.ILO )
7390 $ GO TO 380
7391 *
7392 * Reset counters
7393 *
7394 IITER = 0
7395 ESHIFT = ZERO
7396 IF( .NOT.ILSCHR ) THEN
7397 ILASTM = ILAST
7398 IF( IFRSTM.GT.ILAST )
7399 $ IFRSTM = ILO
7400 END IF
7401 GO TO 350
7402 ELSE
7403 *
7404 * Usual case: 3x3 or larger block, using Francis implicit
7405 * double-shift
7406 *
7407 * 2
7408 * Eigenvalue equation is w - c w + d = 0,
7409 *
7410 * -1 2 -1
7411 * so compute 1st column of (A B ) - c A B + d
7412 * using the formula in QZIT (from EISPACK)
7413 *
7414 * We assume that the block is at least 3x3
7415 *
7416 AD11 = ( ASCALE*H( ILAST-1, ILAST-1 ) ) /
7417 $ ( BSCALE*T( ILAST-1, ILAST-1 ) )
7418 AD21 = ( ASCALE*H( ILAST, ILAST-1 ) ) /
7419 $ ( BSCALE*T( ILAST-1, ILAST-1 ) )
7420 AD12 = ( ASCALE*H( ILAST-1, ILAST ) ) /
7421 $ ( BSCALE*T( ILAST, ILAST ) )
7422 AD22 = ( ASCALE*H( ILAST, ILAST ) ) /
7423 $ ( BSCALE*T( ILAST, ILAST ) )
7424 U12 = T( ILAST-1, ILAST ) / T( ILAST, ILAST )
7425 AD11L = ( ASCALE*H( IFIRST, IFIRST ) ) /
7426 $ ( BSCALE*T( IFIRST, IFIRST ) )
7427 AD21L = ( ASCALE*H( IFIRST+1, IFIRST ) ) /
7428 $ ( BSCALE*T( IFIRST, IFIRST ) )
7429 AD12L = ( ASCALE*H( IFIRST, IFIRST+1 ) ) /
7430 $ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
7431 AD22L = ( ASCALE*H( IFIRST+1, IFIRST+1 ) ) /
7432 $ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
7433 AD32L = ( ASCALE*H( IFIRST+2, IFIRST+1 ) ) /
7434 $ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
7435 U12L = T( IFIRST, IFIRST+1 ) / T( IFIRST+1, IFIRST+1 )
7436 *
7437 V( 1 ) = ( AD11-AD11L )*( AD22-AD11L ) - AD12*AD21 +
7438 $ AD21*U12*AD11L + ( AD12L-AD11L*U12L )*AD21L
7439 V( 2 ) = ( ( AD22L-AD11L )-AD21L*U12L-( AD11-AD11L )-
7440 $ ( AD22-AD11L )+AD21*U12 )*AD21L
7441 V( 3 ) = AD32L*AD21L
7442 *
7443 ISTART = IFIRST
7444 *
7445 CALL DLARFG( 3, V( 1 ), V( 2 ), 1, TAU )
7446 V( 1 ) = ONE
7447 *
7448 * Sweep
7449 *
7450 DO 290 J = ISTART, ILAST - 2
7451 *
7452 * All but last elements: use 3x3 Householder transforms.
7453 *
7454 * Zero (j-1)st column of A
7455 *
7456 IF( J.GT.ISTART ) THEN
7457 V( 1 ) = H( J, J-1 )
7458 V( 2 ) = H( J+1, J-1 )
7459 V( 3 ) = H( J+2, J-1 )
7460 *
7461 CALL DLARFG( 3, H( J, J-1 ), V( 2 ), 1, TAU )
7462 V( 1 ) = ONE
7463 H( J+1, J-1 ) = ZERO
7464 H( J+2, J-1 ) = ZERO
7465 END IF
7466 *
7467 DO 230 JC = J, ILASTM
7468 TEMP = TAU*( H( J, JC )+V( 2 )*H( J+1, JC )+V( 3 )*
7469 $ H( J+2, JC ) )
7470 H( J, JC ) = H( J, JC ) - TEMP
7471 H( J+1, JC ) = H( J+1, JC ) - TEMP*V( 2 )
7472 H( J+2, JC ) = H( J+2, JC ) - TEMP*V( 3 )
7473 TEMP2 = TAU*( T( J, JC )+V( 2 )*T( J+1, JC )+V( 3 )*
7474 $ T( J+2, JC ) )
7475 T( J, JC ) = T( J, JC ) - TEMP2
7476 T( J+1, JC ) = T( J+1, JC ) - TEMP2*V( 2 )
7477 T( J+2, JC ) = T( J+2, JC ) - TEMP2*V( 3 )
7478 230 CONTINUE
7479 IF( ILQ ) THEN
7480 DO 240 JR = 1, N
7481 TEMP = TAU*( Q( JR, J )+V( 2 )*Q( JR, J+1 )+V( 3 )*
7482 $ Q( JR, J+2 ) )
7483 Q( JR, J ) = Q( JR, J ) - TEMP
7484 Q( JR, J+1 ) = Q( JR, J+1 ) - TEMP*V( 2 )
7485 Q( JR, J+2 ) = Q( JR, J+2 ) - TEMP*V( 3 )
7486 240 CONTINUE
7487 END IF
7488 *
7489 * Zero j-th column of B (see DLAGBC for details)
7490 *
7491 * Swap rows to pivot
7492 *
7493 ILPIVT = .FALSE.
7494 TEMP = MAX( ABS( T( J+1, J+1 ) ), ABS( T( J+1, J+2 ) ) )
7495 TEMP2 = MAX( ABS( T( J+2, J+1 ) ), ABS( T( J+2, J+2 ) ) )
7496 IF( MAX( TEMP, TEMP2 ).LT.SAFMIN ) THEN
7497 SCALE = ZERO
7498 U1 = ONE
7499 U2 = ZERO
7500 GO TO 250
7501 ELSE IF( TEMP.GE.TEMP2 ) THEN
7502 W11 = T( J+1, J+1 )
7503 W21 = T( J+2, J+1 )
7504 W12 = T( J+1, J+2 )
7505 W22 = T( J+2, J+2 )
7506 U1 = T( J+1, J )
7507 U2 = T( J+2, J )
7508 ELSE
7509 W21 = T( J+1, J+1 )
7510 W11 = T( J+2, J+1 )
7511 W22 = T( J+1, J+2 )
7512 W12 = T( J+2, J+2 )
7513 U2 = T( J+1, J )
7514 U1 = T( J+2, J )
7515 END IF
7516 *
7517 * Swap columns if nec.
7518 *
7519 IF( ABS( W12 ).GT.ABS( W11 ) ) THEN
7520 ILPIVT = .TRUE.
7521 TEMP = W12
7522 TEMP2 = W22
7523 W12 = W11
7524 W22 = W21
7525 W11 = TEMP
7526 W21 = TEMP2
7527 END IF
7528 *
7529 * LU-factor
7530 *
7531 TEMP = W21 / W11
7532 U2 = U2 - TEMP*U1
7533 W22 = W22 - TEMP*W12
7534 W21 = ZERO
7535 *
7536 * Compute SCALE
7537 *
7538 SCALE = ONE
7539 IF( ABS( W22 ).LT.SAFMIN ) THEN
7540 SCALE = ZERO
7541 U2 = ONE
7542 U1 = -W12 / W11
7543 GO TO 250
7544 END IF
7545 IF( ABS( W22 ).LT.ABS( U2 ) )
7546 $ SCALE = ABS( W22 / U2 )
7547 IF( ABS( W11 ).LT.ABS( U1 ) )
7548 $ SCALE = MIN( SCALE, ABS( W11 / U1 ) )
7549 *
7550 * Solve
7551 *
7552 U2 = ( SCALE*U2 ) / W22
7553 U1 = ( SCALE*U1-W12*U2 ) / W11
7554 *
7555 250 CONTINUE
7556 IF( ILPIVT ) THEN
7557 TEMP = U2
7558 U2 = U1
7559 U1 = TEMP
7560 END IF
7561 *
7562 * Compute Householder Vector
7563 *
7564 T1 = SQRT( SCALE**2+U1**2+U2**2 )
7565 TAU = ONE + SCALE / T1
7566 VS = -ONE / ( SCALE+T1 )
7567 V( 1 ) = ONE
7568 V( 2 ) = VS*U1
7569 V( 3 ) = VS*U2
7570 *
7571 * Apply transformations from the right.
7572 *
7573 DO 260 JR = IFRSTM, MIN( J+3, ILAST )
7574 TEMP = TAU*( H( JR, J )+V( 2 )*H( JR, J+1 )+V( 3 )*
7575 $ H( JR, J+2 ) )
7576 H( JR, J ) = H( JR, J ) - TEMP
7577 H( JR, J+1 ) = H( JR, J+1 ) - TEMP*V( 2 )
7578 H( JR, J+2 ) = H( JR, J+2 ) - TEMP*V( 3 )
7579 260 CONTINUE
7580 DO 270 JR = IFRSTM, J + 2
7581 TEMP = TAU*( T( JR, J )+V( 2 )*T( JR, J+1 )+V( 3 )*
7582 $ T( JR, J+2 ) )
7583 T( JR, J ) = T( JR, J ) - TEMP
7584 T( JR, J+1 ) = T( JR, J+1 ) - TEMP*V( 2 )
7585 T( JR, J+2 ) = T( JR, J+2 ) - TEMP*V( 3 )
7586 270 CONTINUE
7587 IF( ILZ ) THEN
7588 DO 280 JR = 1, N
7589 TEMP = TAU*( Z( JR, J )+V( 2 )*Z( JR, J+1 )+V( 3 )*
7590 $ Z( JR, J+2 ) )
7591 Z( JR, J ) = Z( JR, J ) - TEMP
7592 Z( JR, J+1 ) = Z( JR, J+1 ) - TEMP*V( 2 )
7593 Z( JR, J+2 ) = Z( JR, J+2 ) - TEMP*V( 3 )
7594 280 CONTINUE
7595 END IF
7596 T( J+1, J ) = ZERO
7597 T( J+2, J ) = ZERO
7598 290 CONTINUE
7599 *
7600 * Last elements: Use Givens rotations
7601 *
7602 * Rotations from the left
7603 *
7604 J = ILAST - 1
7605 TEMP = H( J, J-1 )
7606 CALL DLARTG( TEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
7607 H( J+1, J-1 ) = ZERO
7608 *
7609 DO 300 JC = J, ILASTM
7610 TEMP = C*H( J, JC ) + S*H( J+1, JC )
7611 H( J+1, JC ) = -S*H( J, JC ) + C*H( J+1, JC )
7612 H( J, JC ) = TEMP
7613 TEMP2 = C*T( J, JC ) + S*T( J+1, JC )
7614 T( J+1, JC ) = -S*T( J, JC ) + C*T( J+1, JC )
7615 T( J, JC ) = TEMP2
7616 300 CONTINUE
7617 IF( ILQ ) THEN
7618 DO 310 JR = 1, N
7619 TEMP = C*Q( JR, J ) + S*Q( JR, J+1 )
7620 Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
7621 Q( JR, J ) = TEMP
7622 310 CONTINUE
7623 END IF
7624 *
7625 * Rotations from the right.
7626 *
7627 TEMP = T( J+1, J+1 )
7628 CALL DLARTG( TEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
7629 T( J+1, J ) = ZERO
7630 *
7631 DO 320 JR = IFRSTM, ILAST
7632 TEMP = C*H( JR, J+1 ) + S*H( JR, J )
7633 H( JR, J ) = -S*H( JR, J+1 ) + C*H( JR, J )
7634 H( JR, J+1 ) = TEMP
7635 320 CONTINUE
7636 DO 330 JR = IFRSTM, ILAST - 1
7637 TEMP = C*T( JR, J+1 ) + S*T( JR, J )
7638 T( JR, J ) = -S*T( JR, J+1 ) + C*T( JR, J )
7639 T( JR, J+1 ) = TEMP
7640 330 CONTINUE
7641 IF( ILZ ) THEN
7642 DO 340 JR = 1, N
7643 TEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
7644 Z( JR, J ) = -S*Z( JR, J+1 ) + C*Z( JR, J )
7645 Z( JR, J+1 ) = TEMP
7646 340 CONTINUE
7647 END IF
7648 *
7649 * End of Double-Shift code
7650 *
7651 END IF
7652 *
7653 GO TO 350
7654 *
7655 * End of iteration loop
7656 *
7657 350 CONTINUE
7658 360 CONTINUE
7659 *
7660 * Drop-through = non-convergence
7661 *
7662 INFO = ILAST
7663 GO TO 420
7664 *
7665 * Successful completion of all QZ steps
7666 *
7667 380 CONTINUE
7668 *
7669 * Set Eigenvalues 1:ILO-1
7670 *
7671 DO 410 J = 1, ILO - 1
7672 IF( T( J, J ).LT.ZERO ) THEN
7673 IF( ILSCHR ) THEN
7674 DO 390 JR = 1, J
7675 H( JR, J ) = -H( JR, J )
7676 T( JR, J ) = -T( JR, J )
7677 390 CONTINUE
7678 ELSE
7679 H( J, J ) = -H( J, J )
7680 T( J, J ) = -T( J, J )
7681 END IF
7682 IF( ILZ ) THEN
7683 DO 400 JR = 1, N
7684 Z( JR, J ) = -Z( JR, J )
7685 400 CONTINUE
7686 END IF
7687 END IF
7688 ALPHAR( J ) = H( J, J )
7689 ALPHAI( J ) = ZERO
7690 BETA( J ) = T( J, J )
7691 410 CONTINUE
7692 *
7693 * Normal Termination
7694 *
7695 INFO = 0
7696 *
7697 * Exit (other than argument error) -- return optimal workspace size
7698 *
7699 420 CONTINUE
7700 WORK( 1 ) = DBLE( N )
7701 RETURN
7702 *
7703 * End of DHGEQZ
7704 *
7705 END
7706 C
7707 C-----------------------------------------------------------------------
7708 C-----------------------------------------------------------------------
7709 SUBROUTINE DTGEVC( SIDE, HOWMNY, SELECT, N, S, LDS, P, LDP, VL,
7710 $ LDVL, VR, LDVR, MM, M, WORK, INFO )
7711 *
7712 * -- LAPACK routine (version 3.2) --
7713 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
7714 * November 2006
7715 *
7716 * .. Scalar Arguments ..
7717 CHARACTER HOWMNY, SIDE
7718 INTEGER INFO, LDP, LDS, LDVL, LDVR, M, MM, N
7719 * ..
7720 * .. Array Arguments ..
7721 LOGICAL SELECT( * )
7722 DOUBLE PRECISION P( LDP, * ), S( LDS, * ), VL( LDVL, * ),
7723 $ VR( LDVR, * ), WORK( * )
7724 * ..
7725 *
7726 *
7727 * Purpose
7728 * =======
7729 *
7730 * DTGEVC computes some or all of the right and/or left eigenvectors of
7731 * a pair of real matrices (S,P), where S is a quasi-triangular matrix
7732 * and P is upper triangular. Matrix pairs of this type are produced by
7733 * the generalized Schur factorization of a matrix pair (A,B):
7734 *
7735 * A = Q*S*Z**T, B = Q*P*Z**T
7736 *
7737 * as computed by DGGHRD + DHGEQZ.
7738 *
7739 * The right eigenvector x and the left eigenvector y of (S,P)
7740 * corresponding to an eigenvalue w are defined by:
7741 *
7742 * S*x = w*P*x, (y**H)*S = w*(y**H)*P,
7743 *
7744 * where y**H denotes the conjugate tranpose of y.
7745 * The eigenvalues are not input to this routine, but are computed
7746 * directly from the diagonal blocks of S and P.
7747 *
7748 * This routine returns the matrices X and/or Y of right and left
7749 * eigenvectors of (S,P), or the products Z*X and/or Q*Y,
7750 * where Z and Q are input matrices.
7751 * If Q and Z are the orthogonal factors from the generalized Schur
7752 * factorization of a matrix pair (A,B), then Z*X and Q*Y
7753 * are the matrices of right and left eigenvectors of (A,B).
7754 *
7755 * Arguments
7756 * =========
7757 *
7758 * SIDE (input) CHARACTER*1
7759 * = 'R': compute right eigenvectors only;
7760 * = 'L': compute left eigenvectors only;
7761 * = 'B': compute both right and left eigenvectors.
7762 *
7763 * HOWMNY (input) CHARACTER*1
7764 * = 'A': compute all right and/or left eigenvectors;
7765 * = 'B': compute all right and/or left eigenvectors,
7766 * backtransformed by the matrices in VR and/or VL;
7767 * = 'S': compute selected right and/or left eigenvectors,
7768 * specified by the logical array SELECT.
7769 *
7770 * SELECT (input) LOGICAL array, dimension (N)
7771 * If HOWMNY='S', SELECT specifies the eigenvectors to be
7772 * computed. If w(j) is a real eigenvalue, the corresponding
7773 * real eigenvector is computed if SELECT(j) is .TRUE..
7774 * If w(j) and w(j+1) are the real and imaginary parts of a
7775 * complex eigenvalue, the corresponding complex eigenvector
7776 * is computed if either SELECT(j) or SELECT(j+1) is .TRUE.,
7777 * and on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is
7778 * set to .FALSE..
7779 * Not referenced if HOWMNY = 'A' or 'B'.
7780 *
7781 * N (input) INTEGER
7782 * The order of the matrices S and P. N >= 0.
7783 *
7784 * S (input) DOUBLE PRECISION array, dimension (LDS,N)
7785 * The upper quasi-triangular matrix S from a generalized Schur
7786 * factorization, as computed by DHGEQZ.
7787 *
7788 * LDS (input) INTEGER
7789 * The leading dimension of array S. LDS >= max(1,N).
7790 *
7791 * P (input) DOUBLE PRECISION array, dimension (LDP,N)
7792 * The upper triangular matrix P from a generalized Schur
7793 * factorization, as computed by DHGEQZ.
7794 * 2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks
7795 * of S must be in positive diagonal form.
7796 *
7797 * LDP (input) INTEGER
7798 * The leading dimension of array P. LDP >= max(1,N).
7799 *
7800 * VL (input/output) DOUBLE PRECISION array, dimension (LDVL,MM)
7801 * On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must
7802 * contain an N-by-N matrix Q (usually the orthogonal matrix Q
7803 * of left Schur vectors returned by DHGEQZ).
7804 * On exit, if SIDE = 'L' or 'B', VL contains:
7805 * if HOWMNY = 'A', the matrix Y of left eigenvectors of (S,P);
7806 * if HOWMNY = 'B', the matrix Q*Y;
7807 * if HOWMNY = 'S', the left eigenvectors of (S,P) specified by
7808 * SELECT, stored consecutively in the columns of
7809 * VL, in the same order as their eigenvalues.
7810 *
7811 * A complex eigenvector corresponding to a complex eigenvalue
7812 * is stored in two consecutive columns, the first holding the
7813 * real part, and the second the imaginary part.
7814 *
7815 * Not referenced if SIDE = 'R'.
7816 *
7817 * LDVL (input) INTEGER
7818 * The leading dimension of array VL. LDVL >= 1, and if
7819 * SIDE = 'L' or 'B', LDVL >= N.
7820 *
7821 * VR (input/output) DOUBLE PRECISION array, dimension (LDVR,MM)
7822 * On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must
7823 * contain an N-by-N matrix Z (usually the orthogonal matrix Z
7824 * of right Schur vectors returned by DHGEQZ).
7825 *
7826 * On exit, if SIDE = 'R' or 'B', VR contains:
7827 * if HOWMNY = 'A', the matrix X of right eigenvectors of (S,P);
7828 * if HOWMNY = 'B' or 'b', the matrix Z*X;
7829 * if HOWMNY = 'S' or 's', the right eigenvectors of (S,P)
7830 * specified by SELECT, stored consecutively in the
7831 * columns of VR, in the same order as their
7832 * eigenvalues.
7833 *
7834 * A complex eigenvector corresponding to a complex eigenvalue
7835 * is stored in two consecutive columns, the first holding the
7836 * real part and the second the imaginary part.
7837 *
7838 * Not referenced if SIDE = 'L'.
7839 *
7840 * LDVR (input) INTEGER
7841 * The leading dimension of the array VR. LDVR >= 1, and if
7842 * SIDE = 'R' or 'B', LDVR >= N.
7843 *
7844 * MM (input) INTEGER
7845 * The number of columns in the arrays VL and/or VR. MM >= M.
7846 *
7847 * M (output) INTEGER
7848 * The number of columns in the arrays VL and/or VR actually
7849 * used to store the eigenvectors. If HOWMNY = 'A' or 'B', M
7850 * is set to N. Each selected real eigenvector occupies one
7851 * column and each selected complex eigenvector occupies two
7852 * columns.
7853 *
7854 * WORK (workspace) DOUBLE PRECISION array, dimension (6*N)
7855 *
7856 * INFO (output) INTEGER
7857 * = 0: successful exit.
7858 * < 0: if INFO = -i, the i-th argument had an illegal value.
7859 * > 0: the 2-by-2 block (INFO:INFO+1) does not have a complex
7860 * eigenvalue.
7861 *
7862 * Further Details
7863 * ===============
7864 *
7865 * Allocation of workspace:
7866 * ---------- -- ---------
7867 *
7868 * WORK( j ) = 1-norm of j-th column of A, above the diagonal
7869 * WORK( N+j ) = 1-norm of j-th column of B, above the diagonal
7870 * WORK( 2*N+1:3*N ) = real part of eigenvector
7871 * WORK( 3*N+1:4*N ) = imaginary part of eigenvector
7872 * WORK( 4*N+1:5*N ) = real part of back-transformed eigenvector
7873 * WORK( 5*N+1:6*N ) = imaginary part of back-transformed eigenvector
7874 *
7875 * Rowwise vs. columnwise solution methods:
7876 * ------- -- ---------- -------- -------
7877 *
7878 * Finding a generalized eigenvector consists basically of solving the
7879 * singular triangular system
7880 *
7881 * (A - w B) x = 0 (for right) or: (A - w B)**H y = 0 (for left)
7882 *
7883 * Consider finding the i-th right eigenvector (assume all eigenvalues
7884 * are real). The equation to be solved is:
7885 * n i
7886 * 0 = sum C(j,k) v(k) = sum C(j,k) v(k) for j = i,. . .,1
7887 * k=j k=j
7888 *
7889 * where C = (A - w B) (The components v(i+1:n) are 0.)
7890 *
7891 * The "rowwise" method is:
7892 *
7893 * (1) v(i) := 1
7894 * for j = i-1,. . .,1:
7895 * i
7896 * (2) compute s = - sum C(j,k) v(k) and
7897 * k=j+1
7898 *
7899 * (3) v(j) := s / C(j,j)
7900 *
7901 * Step 2 is sometimes called the "dot product" step, since it is an
7902 * inner product between the j-th row and the portion of the eigenvector
7903 * that has been computed so far.
7904 *
7905 * The "columnwise" method consists basically in doing the sums
7906 * for all the rows in parallel. As each v(j) is computed, the
7907 * contribution of v(j) times the j-th column of C is added to the
7908 * partial sums. Since FORTRAN arrays are stored columnwise, this has
7909 * the advantage that at each step, the elements of C that are accessed
7910 * are adjacent to one another, whereas with the rowwise method, the
7911 * elements accessed at a step are spaced LDS (and LDP) words apart.
7912 *
7913 * When finding left eigenvectors, the matrix in question is the
7914 * transpose of the one in storage, so the rowwise method then
7915 * actually accesses columns of A and B at each step, and so is the
7916 * preferred method.
7917 *
7918 * =====================================================================
7919 *
7920 * .. Parameters ..
7921 DOUBLE PRECISION ZERO, ONE, SAFETY
7922 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0,
7923 $ SAFETY = 1.0D+2 )
7924 * ..
7925 * .. Local Scalars ..
7926 LOGICAL COMPL, COMPR, IL2BY2, ILABAD, ILALL, ILBACK,
7927 $ ILBBAD, ILCOMP, ILCPLX, LSA, LSB
7928 INTEGER I, IBEG, IEIG, IEND, IHWMNY, IINFO, IM, ISIDE,
7929 $ J, JA, JC, JE, JR, JW, NA, NW
7930 DOUBLE PRECISION ACOEF, ACOEFA, ANORM, ASCALE, BCOEFA, BCOEFI,
7931 $ BCOEFR, BIG, BIGNUM, BNORM, BSCALE, CIM2A,
7932 $ CIM2B, CIMAGA, CIMAGB, CRE2A, CRE2B, CREALA,
7933 $ CREALB, DMIN, SAFMIN, SALFAR, SBETA, SCALE,
7934 $ SMALL, TEMP, TEMP2, TEMP2I, TEMP2R, ULP, XMAX,
7935 $ XSCALE
7936 * ..
7937 * .. Local Arrays ..
7938 DOUBLE PRECISION BDIAG( 2 ), SUM( 2, 2 ), SUMS( 2, 2 ),
7939 $ SUMP( 2, 2 )
7940 * ..
7941 * .. External Functions ..
7942 LOGICAL LSAME
7943 DOUBLE PRECISION DLAMCH
7944 EXTERNAL LSAME, DLAMCH
7945 * ..
7946 * .. External Subroutines ..
7947 EXTERNAL DGEMV, DLABAD, DLACPY, DLAG2, DLALN2, XERBLA
7948 * ..
7949 * .. Intrinsic Functions ..
7950 INTRINSIC ABS, MAX, MIN
7951 * ..
7952 * .. Executable Statements ..
7953 *
7954 * Decode and Test the input parameters
7955 *
7956 IF( LSAME( HOWMNY, 'A' ) ) THEN
7957 IHWMNY = 1
7958 ILALL = .TRUE.
7959 ILBACK = .FALSE.
7960 ELSE IF( LSAME( HOWMNY, 'S' ) ) THEN
7961 IHWMNY = 2
7962 ILALL = .FALSE.
7963 ILBACK = .FALSE.
7964 ELSE IF( LSAME( HOWMNY, 'B' ) ) THEN
7965 IHWMNY = 3
7966 ILALL = .TRUE.
7967 ILBACK = .TRUE.
7968 ELSE
7969 IHWMNY = -1
7970 ILALL = .TRUE.
7971 END IF
7972 *
7973 IF( LSAME( SIDE, 'R' ) ) THEN
7974 ISIDE = 1
7975 COMPL = .FALSE.
7976 COMPR = .TRUE.
7977 ELSE IF( LSAME( SIDE, 'L' ) ) THEN
7978 ISIDE = 2
7979 COMPL = .TRUE.
7980 COMPR = .FALSE.
7981 ELSE IF( LSAME( SIDE, 'B' ) ) THEN
7982 ISIDE = 3
7983 COMPL = .TRUE.
7984 COMPR = .TRUE.
7985 ELSE
7986 ISIDE = -1
7987 END IF
7988 *
7989 INFO = 0
7990 IF( ISIDE.LT.0 ) THEN
7991 INFO = -1
7992 ELSE IF( IHWMNY.LT.0 ) THEN
7993 INFO = -2
7994 ELSE IF( N.LT.0 ) THEN
7995 INFO = -4
7996 ELSE IF( LDS.LT.MAX( 1, N ) ) THEN
7997 INFO = -6
7998 ELSE IF( LDP.LT.MAX( 1, N ) ) THEN
7999 INFO = -8
8000 END IF
8001 IF( INFO.NE.0 ) THEN
8002 CALL XERBLA( 'DTGEVC', -INFO )
8003 RETURN
8004 END IF
8005 *
8006 * Count the number of eigenvectors to be computed
8007 *
8008 IF( .NOT.ILALL ) THEN
8009 IM = 0
8010 ILCPLX = .FALSE.
8011 DO 10 J = 1, N
8012 IF( ILCPLX ) THEN
8013 ILCPLX = .FALSE.
8014 GO TO 10
8015 END IF
8016 IF( J.LT.N ) THEN
8017 IF( S( J+1, J ).NE.ZERO )
8018 $ ILCPLX = .TRUE.
8019 END IF
8020 IF( ILCPLX ) THEN
8021 IF( SELECT( J ) .OR. SELECT( J+1 ) )
8022 $ IM = IM + 2
8023 ELSE
8024 IF( SELECT( J ) )
8025 $ IM = IM + 1
8026 END IF
8027 10 CONTINUE
8028 ELSE
8029 IM = N
8030 END IF
8031 *
8032 * Check 2-by-2 diagonal blocks of A, B
8033 *
8034 ILABAD = .FALSE.
8035 ILBBAD = .FALSE.
8036 DO 20 J = 1, N - 1
8037 IF( S( J+1, J ).NE.ZERO ) THEN
8038 IF( P( J, J ).EQ.ZERO .OR. P( J+1, J+1 ).EQ.ZERO .OR.
8039 $ P( J, J+1 ).NE.ZERO )ILBBAD = .TRUE.
8040 IF( J.LT.N-1 ) THEN
8041 IF( S( J+2, J+1 ).NE.ZERO )
8042 $ ILABAD = .TRUE.
8043 END IF
8044 END IF
8045 20 CONTINUE
8046 *
8047 IF( ILABAD ) THEN
8048 INFO = -5
8049 ELSE IF( ILBBAD ) THEN
8050 INFO = -7
8051 ELSE IF( COMPL .AND. LDVL.LT.N .OR. LDVL.LT.1 ) THEN
8052 INFO = -10
8053 ELSE IF( COMPR .AND. LDVR.LT.N .OR. LDVR.LT.1 ) THEN
8054 INFO = -12
8055 ELSE IF( MM.LT.IM ) THEN
8056 INFO = -13
8057 END IF
8058 IF( INFO.NE.0 ) THEN
8059 CALL XERBLA( 'DTGEVC', -INFO )
8060 RETURN
8061 END IF
8062 *
8063 * Quick return if possible
8064 *
8065 M = IM
8066 IF( N.EQ.0 )
8067 $ RETURN
8068 *
8069 * Machine Constants
8070 *
8071 SAFMIN = DLAMCH( 'Safe minimum' )
8072 BIG = ONE / SAFMIN
8073 CALL DLABAD( SAFMIN, BIG )
8074 ULP = DLAMCH( 'Epsilon' )*DLAMCH( 'Base' )
8075 SMALL = SAFMIN*N / ULP
8076 BIG = ONE / SMALL
8077 BIGNUM = ONE / ( SAFMIN*N )
8078 *
8079 * Compute the 1-norm of each column of the strictly upper triangular
8080 * part (i.e., excluding all elements belonging to the diagonal
8081 * blocks) of A and B to check for possible overflow in the
8082 * triangular solver.
8083 *
8084 ANORM = ABS( S( 1, 1 ) )
8085 IF( N.GT.1 )
8086 $ ANORM = ANORM + ABS( S( 2, 1 ) )
8087 BNORM = ABS( P( 1, 1 ) )
8088 WORK( 1 ) = ZERO
8089 WORK( N+1 ) = ZERO
8090 *
8091 DO 50 J = 2, N
8092 TEMP = ZERO
8093 TEMP2 = ZERO
8094 IF( S( J, J-1 ).EQ.ZERO ) THEN
8095 IEND = J - 1
8096 ELSE
8097 IEND = J - 2
8098 END IF
8099 DO 30 I = 1, IEND
8100 TEMP = TEMP + ABS( S( I, J ) )
8101 TEMP2 = TEMP2 + ABS( P( I, J ) )
8102 30 CONTINUE
8103 WORK( J ) = TEMP
8104 WORK( N+J ) = TEMP2
8105 DO 40 I = IEND + 1, MIN( J+1, N )
8106 TEMP = TEMP + ABS( S( I, J ) )
8107 TEMP2 = TEMP2 + ABS( P( I, J ) )
8108 40 CONTINUE
8109 ANORM = MAX( ANORM, TEMP )
8110 BNORM = MAX( BNORM, TEMP2 )
8111 50 CONTINUE
8112 *
8113 ASCALE = ONE / MAX( ANORM, SAFMIN )
8114 BSCALE = ONE / MAX( BNORM, SAFMIN )
8115 *
8116 * Left eigenvectors
8117 *
8118 IF( COMPL ) THEN
8119 IEIG = 0
8120 *
8121 * Main loop over eigenvalues
8122 *
8123 ILCPLX = .FALSE.
8124 DO 220 JE = 1, N
8125 *
8126 * Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or
8127 * (b) this would be the second of a complex pair.
8128 * Check for complex eigenvalue, so as to be sure of which
8129 * entry(-ies) of SELECT to look at.
8130 *
8131 IF( ILCPLX ) THEN
8132 ILCPLX = .FALSE.
8133 GO TO 220
8134 END IF
8135 NW = 1
8136 IF( JE.LT.N ) THEN
8137 IF( S( JE+1, JE ).NE.ZERO ) THEN
8138 ILCPLX = .TRUE.
8139 NW = 2
8140 END IF
8141 END IF
8142 IF( ILALL ) THEN
8143 ILCOMP = .TRUE.
8144 ELSE IF( ILCPLX ) THEN
8145 ILCOMP = SELECT( JE ) .OR. SELECT( JE+1 )
8146 ELSE
8147 ILCOMP = SELECT( JE )
8148 END IF
8149 IF( .NOT.ILCOMP )
8150 $ GO TO 220
8151 *
8152 * Decide if (a) singular pencil, (b) real eigenvalue, or
8153 * (c) complex eigenvalue.
8154 *
8155 IF( .NOT.ILCPLX ) THEN
8156 IF( ABS( S( JE, JE ) ).LE.SAFMIN .AND.
8157 $ ABS( P( JE, JE ) ).LE.SAFMIN ) THEN
8158 *
8159 * Singular matrix pencil -- return unit eigenvector
8160 *
8161 IEIG = IEIG + 1
8162 DO 60 JR = 1, N
8163 VL( JR, IEIG ) = ZERO
8164 60 CONTINUE
8165 VL( IEIG, IEIG ) = ONE
8166 GO TO 220
8167 END IF
8168 END IF
8169 *
8170 * Clear vector
8171 *
8172 DO 70 JR = 1, NW*N
8173 WORK( 2*N+JR ) = ZERO
8174 70 CONTINUE
8175 * T
8176 * Compute coefficients in ( a A - b B ) y = 0
8177 * a is ACOEF
8178 * b is BCOEFR + i*BCOEFI
8179 *
8180 IF( .NOT.ILCPLX ) THEN
8181 *
8182 * Real eigenvalue
8183 *
8184 TEMP = ONE / MAX( ABS( S( JE, JE ) )*ASCALE,
8185 $ ABS( P( JE, JE ) )*BSCALE, SAFMIN )
8186 SALFAR = ( TEMP*S( JE, JE ) )*ASCALE
8187 SBETA = ( TEMP*P( JE, JE ) )*BSCALE
8188 ACOEF = SBETA*ASCALE
8189 BCOEFR = SALFAR*BSCALE
8190 BCOEFI = ZERO
8191 *
8192 * Scale to avoid underflow
8193 *
8194 SCALE = ONE
8195 LSA = ABS( SBETA ).GE.SAFMIN .AND. ABS( ACOEF ).LT.SMALL
8196 LSB = ABS( SALFAR ).GE.SAFMIN .AND. ABS( BCOEFR ).LT.
8197 $ SMALL
8198 IF( LSA )
8199 $ SCALE = ( SMALL / ABS( SBETA ) )*MIN( ANORM, BIG )
8200 IF( LSB )
8201 $ SCALE = MAX( SCALE, ( SMALL / ABS( SALFAR ) )*
8202 $ MIN( BNORM, BIG ) )
8203 IF( LSA .OR. LSB ) THEN
8204 SCALE = MIN( SCALE, ONE /
8205 $ ( SAFMIN*MAX( ONE, ABS( ACOEF ),
8206 $ ABS( BCOEFR ) ) ) )
8207 IF( LSA ) THEN
8208 ACOEF = ASCALE*( SCALE*SBETA )
8209 ELSE
8210 ACOEF = SCALE*ACOEF
8211 END IF
8212 IF( LSB ) THEN
8213 BCOEFR = BSCALE*( SCALE*SALFAR )
8214 ELSE
8215 BCOEFR = SCALE*BCOEFR
8216 END IF
8217 END IF
8218 ACOEFA = ABS( ACOEF )
8219 BCOEFA = ABS( BCOEFR )
8220 *
8221 * First component is 1
8222 *
8223 WORK( 2*N+JE ) = ONE
8224 XMAX = ONE
8225 ELSE
8226 *
8227 * Complex eigenvalue
8228 *
8229 CALL DLAG2( S( JE, JE ), LDS, P( JE, JE ), LDP,
8230 $ SAFMIN*SAFETY, ACOEF, TEMP, BCOEFR, TEMP2,
8231 $ BCOEFI )
8232 BCOEFI = -BCOEFI
8233 IF( BCOEFI.EQ.ZERO ) THEN
8234 INFO = JE
8235 RETURN
8236 END IF
8237 *
8238 * Scale to avoid over/underflow
8239 *
8240 ACOEFA = ABS( ACOEF )
8241 BCOEFA = ABS( BCOEFR ) + ABS( BCOEFI )
8242 SCALE = ONE
8243 IF( ACOEFA*ULP.LT.SAFMIN .AND. ACOEFA.GE.SAFMIN )
8244 $ SCALE = ( SAFMIN / ULP ) / ACOEFA
8245 IF( BCOEFA*ULP.LT.SAFMIN .AND. BCOEFA.GE.SAFMIN )
8246 $ SCALE = MAX( SCALE, ( SAFMIN / ULP ) / BCOEFA )
8247 IF( SAFMIN*ACOEFA.GT.ASCALE )
8248 $ SCALE = ASCALE / ( SAFMIN*ACOEFA )
8249 IF( SAFMIN*BCOEFA.GT.BSCALE )
8250 $ SCALE = MIN( SCALE, BSCALE / ( SAFMIN*BCOEFA ) )
8251 IF( SCALE.NE.ONE ) THEN
8252 ACOEF = SCALE*ACOEF
8253 ACOEFA = ABS( ACOEF )
8254 BCOEFR = SCALE*BCOEFR
8255 BCOEFI = SCALE*BCOEFI
8256 BCOEFA = ABS( BCOEFR ) + ABS( BCOEFI )
8257 END IF
8258 *
8259 * Compute first two components of eigenvector
8260 *
8261 TEMP = ACOEF*S( JE+1, JE )
8262 TEMP2R = ACOEF*S( JE, JE ) - BCOEFR*P( JE, JE )
8263 TEMP2I = -BCOEFI*P( JE, JE )
8264 IF( ABS( TEMP ).GT.ABS( TEMP2R )+ABS( TEMP2I ) ) THEN
8265 WORK( 2*N+JE ) = ONE
8266 WORK( 3*N+JE ) = ZERO
8267 WORK( 2*N+JE+1 ) = -TEMP2R / TEMP
8268 WORK( 3*N+JE+1 ) = -TEMP2I / TEMP
8269 ELSE
8270 WORK( 2*N+JE+1 ) = ONE
8271 WORK( 3*N+JE+1 ) = ZERO
8272 TEMP = ACOEF*S( JE, JE+1 )
8273 WORK( 2*N+JE ) = ( BCOEFR*P( JE+1, JE+1 )-ACOEF*
8274 $ S( JE+1, JE+1 ) ) / TEMP
8275 WORK( 3*N+JE ) = BCOEFI*P( JE+1, JE+1 ) / TEMP
8276 END IF
8277 XMAX = MAX( ABS( WORK( 2*N+JE ) )+ABS( WORK( 3*N+JE ) ),
8278 $ ABS( WORK( 2*N+JE+1 ) )+ABS( WORK( 3*N+JE+1 ) ) )
8279 END IF
8280 *
8281 DMIN = MAX( ULP*ACOEFA*ANORM, ULP*BCOEFA*BNORM, SAFMIN )
8282 *
8283 * T
8284 * Triangular solve of (a A - b B) y = 0
8285 *
8286 * T
8287 * (rowwise in (a A - b B) , or columnwise in (a A - b B) )
8288 *
8289 IL2BY2 = .FALSE.
8290 *
8291 DO 160 J = JE + NW, N
8292 IF( IL2BY2 ) THEN
8293 IL2BY2 = .FALSE.
8294 GO TO 160
8295 END IF
8296 *
8297 NA = 1
8298 BDIAG( 1 ) = P( J, J )
8299 IF( J.LT.N ) THEN
8300 IF( S( J+1, J ).NE.ZERO ) THEN
8301 IL2BY2 = .TRUE.
8302 BDIAG( 2 ) = P( J+1, J+1 )
8303 NA = 2
8304 END IF
8305 END IF
8306 *
8307 * Check whether scaling is necessary for dot products
8308 *
8309 XSCALE = ONE / MAX( ONE, XMAX )
8310 TEMP = MAX( WORK( J ), WORK( N+J ),
8311 $ ACOEFA*WORK( J )+BCOEFA*WORK( N+J ) )
8312 IF( IL2BY2 )
8313 $ TEMP = MAX( TEMP, WORK( J+1 ), WORK( N+J+1 ),
8314 $ ACOEFA*WORK( J+1 )+BCOEFA*WORK( N+J+1 ) )
8315 IF( TEMP.GT.BIGNUM*XSCALE ) THEN
8316 DO 90 JW = 0, NW - 1
8317 DO 80 JR = JE, J - 1
8318 WORK( ( JW+2 )*N+JR ) = XSCALE*
8319 $ WORK( ( JW+2 )*N+JR )
8320 80 CONTINUE
8321 90 CONTINUE
8322 XMAX = XMAX*XSCALE
8323 END IF
8324 *
8325 * Compute dot products
8326 *
8327 * j-1
8328 * SUM = sum conjg( a*S(k,j) - b*P(k,j) )*x(k)
8329 * k=je
8330 *
8331 * To reduce the op count, this is done as
8332 *
8333 * _ j-1 _ j-1
8334 * a*conjg( sum S(k,j)*x(k) ) - b*conjg( sum P(k,j)*x(k) )
8335 * k=je k=je
8336 *
8337 * which may cause underflow problems if A or B are close
8338 * to underflow. (E.g., less than SMALL.)
8339 *
8340 *
8341 * A series of compiler directives to defeat vectorization
8342 * for the next loop
8343 *
8344 *$PL$ CMCHAR=' '
8345 CDIR$ NEXTSCALAR
8346 C$DIR SCALAR
8347 CDIR$ NEXT SCALAR
8348 CVD$L NOVECTOR
8349 CDEC$ NOVECTOR
8350 CVD$ NOVECTOR
8351 *VDIR NOVECTOR
8352 *VOCL LOOP,SCALAR
8353 CIBM PREFER SCALAR
8354 *$PL$ CMCHAR='*'
8355 *
8356 DO 120 JW = 1, NW
8357 *
8358 *$PL$ CMCHAR=' '
8359 CDIR$ NEXTSCALAR
8360 C$DIR SCALAR
8361 CDIR$ NEXT SCALAR
8362 CVD$L NOVECTOR
8363 CDEC$ NOVECTOR
8364 CVD$ NOVECTOR
8365 *VDIR NOVECTOR
8366 *VOCL LOOP,SCALAR
8367 CIBM PREFER SCALAR
8368 *$PL$ CMCHAR='*'
8369 *
8370 DO 110 JA = 1, NA
8371 SUMS( JA, JW ) = ZERO
8372 SUMP( JA, JW ) = ZERO
8373 *
8374 DO 100 JR = JE, J - 1
8375 SUMS( JA, JW ) = SUMS( JA, JW ) +
8376 $ S( JR, J+JA-1 )*
8377 $ WORK( ( JW+1 )*N+JR )
8378 SUMP( JA, JW ) = SUMP( JA, JW ) +
8379 $ P( JR, J+JA-1 )*
8380 $ WORK( ( JW+1 )*N+JR )
8381 100 CONTINUE
8382 110 CONTINUE
8383 120 CONTINUE
8384 *
8385 *$PL$ CMCHAR=' '
8386 CDIR$ NEXTSCALAR
8387 C$DIR SCALAR
8388 CDIR$ NEXT SCALAR
8389 CVD$L NOVECTOR
8390 CDEC$ NOVECTOR
8391 CVD$ NOVECTOR
8392 *VDIR NOVECTOR
8393 *VOCL LOOP,SCALAR
8394 CIBM PREFER SCALAR
8395 *$PL$ CMCHAR='*'
8396 *
8397 DO 130 JA = 1, NA
8398 IF( ILCPLX ) THEN
8399 SUM( JA, 1 ) = -ACOEF*SUMS( JA, 1 ) +
8400 $ BCOEFR*SUMP( JA, 1 ) -
8401 $ BCOEFI*SUMP( JA, 2 )
8402 SUM( JA, 2 ) = -ACOEF*SUMS( JA, 2 ) +
8403 $ BCOEFR*SUMP( JA, 2 ) +
8404 $ BCOEFI*SUMP( JA, 1 )
8405 ELSE
8406 SUM( JA, 1 ) = -ACOEF*SUMS( JA, 1 ) +
8407 $ BCOEFR*SUMP( JA, 1 )
8408 END IF
8409 130 CONTINUE
8410 *
8411 * T
8412 * Solve ( a A - b B ) y = SUM(,)
8413 * with scaling and perturbation of the denominator
8414 *
8415 CALL DLALN2( .TRUE., NA, NW, DMIN, ACOEF, S( J, J ), LDS,
8416 $ BDIAG( 1 ), BDIAG( 2 ), SUM, 2, BCOEFR,
8417 $ BCOEFI, WORK( 2*N+J ), N, SCALE, TEMP,
8418 $ IINFO )
8419 IF( SCALE.LT.ONE ) THEN
8420 DO 150 JW = 0, NW - 1
8421 DO 140 JR = JE, J - 1
8422 WORK( ( JW+2 )*N+JR ) = SCALE*
8423 $ WORK( ( JW+2 )*N+JR )
8424 140 CONTINUE
8425 150 CONTINUE
8426 XMAX = SCALE*XMAX
8427 END IF
8428 XMAX = MAX( XMAX, TEMP )
8429 160 CONTINUE
8430 *
8431 * Copy eigenvector to VL, back transforming if
8432 * HOWMNY='B'.
8433 *
8434 IEIG = IEIG + 1
8435 IF( ILBACK ) THEN
8436 DO 170 JW = 0, NW - 1
8437 CALL DGEMV( 'N', N, N+1-JE, ONE, VL( 1, JE ), LDVL,
8438 $ WORK( ( JW+2 )*N+JE ), 1, ZERO,
8439 $ WORK( ( JW+4 )*N+1 ), 1 )
8440 170 CONTINUE
8441 CALL DLACPY( ' ', N, NW, WORK( 4*N+1 ), N, VL( 1, JE ),
8442 $ LDVL )
8443 IBEG = 1
8444 ELSE
8445 CALL DLACPY( ' ', N, NW, WORK( 2*N+1 ), N, VL( 1, IEIG ),
8446 $ LDVL )
8447 IBEG = JE
8448 END IF
8449 *
8450 * Scale eigenvector
8451 *
8452 XMAX = ZERO
8453 IF( ILCPLX ) THEN
8454 DO 180 J = IBEG, N
8455 XMAX = MAX( XMAX, ABS( VL( J, IEIG ) )+
8456 $ ABS( VL( J, IEIG+1 ) ) )
8457 180 CONTINUE
8458 ELSE
8459 DO 190 J = IBEG, N
8460 XMAX = MAX( XMAX, ABS( VL( J, IEIG ) ) )
8461 190 CONTINUE
8462 END IF
8463 *
8464 IF( XMAX.GT.SAFMIN ) THEN
8465 XSCALE = ONE / XMAX
8466 *
8467 DO 210 JW = 0, NW - 1
8468 DO 200 JR = IBEG, N
8469 VL( JR, IEIG+JW ) = XSCALE*VL( JR, IEIG+JW )
8470 200 CONTINUE
8471 210 CONTINUE
8472 END IF
8473 IEIG = IEIG + NW - 1
8474 *
8475 220 CONTINUE
8476 END IF
8477 *
8478 * Right eigenvectors
8479 *
8480 IF( COMPR ) THEN
8481 IEIG = IM + 1
8482 *
8483 * Main loop over eigenvalues
8484 *
8485 ILCPLX = .FALSE.
8486 DO 500 JE = N, 1, -1
8487 *
8488 * Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or
8489 * (b) this would be the second of a complex pair.
8490 * Check for complex eigenvalue, so as to be sure of which
8491 * entry(-ies) of SELECT to look at -- if complex, SELECT(JE)
8492 * or SELECT(JE-1).
8493 * If this is a complex pair, the 2-by-2 diagonal block
8494 * corresponding to the eigenvalue is in rows/columns JE-1:JE
8495 *
8496 IF( ILCPLX ) THEN
8497 ILCPLX = .FALSE.
8498 GO TO 500
8499 END IF
8500 NW = 1
8501 IF( JE.GT.1 ) THEN
8502 IF( S( JE, JE-1 ).NE.ZERO ) THEN
8503 ILCPLX = .TRUE.
8504 NW = 2
8505 END IF
8506 END IF
8507 IF( ILALL ) THEN
8508 ILCOMP = .TRUE.
8509 ELSE IF( ILCPLX ) THEN
8510 ILCOMP = SELECT( JE ) .OR. SELECT( JE-1 )
8511 ELSE
8512 ILCOMP = SELECT( JE )
8513 END IF
8514 IF( .NOT.ILCOMP )
8515 $ GO TO 500
8516 *
8517 * Decide if (a) singular pencil, (b) real eigenvalue, or
8518 * (c) complex eigenvalue.
8519 *
8520 IF( .NOT.ILCPLX ) THEN
8521 IF( ABS( S( JE, JE ) ).LE.SAFMIN .AND.
8522 $ ABS( P( JE, JE ) ).LE.SAFMIN ) THEN
8523 *
8524 * Singular matrix pencil -- unit eigenvector
8525 *
8526 IEIG = IEIG - 1
8527 DO 230 JR = 1, N
8528 VR( JR, IEIG ) = ZERO
8529 230 CONTINUE
8530 VR( IEIG, IEIG ) = ONE
8531 GO TO 500
8532 END IF
8533 END IF
8534 *
8535 * Clear vector
8536 *
8537 DO 250 JW = 0, NW - 1
8538 DO 240 JR = 1, N
8539 WORK( ( JW+2 )*N+JR ) = ZERO
8540 240 CONTINUE
8541 250 CONTINUE
8542 *
8543 * Compute coefficients in ( a A - b B ) x = 0
8544 * a is ACOEF
8545 * b is BCOEFR + i*BCOEFI
8546 *
8547 IF( .NOT.ILCPLX ) THEN
8548 *
8549 * Real eigenvalue
8550 *
8551 TEMP = ONE / MAX( ABS( S( JE, JE ) )*ASCALE,
8552 $ ABS( P( JE, JE ) )*BSCALE, SAFMIN )
8553 SALFAR = ( TEMP*S( JE, JE ) )*ASCALE
8554 SBETA = ( TEMP*P( JE, JE ) )*BSCALE
8555 ACOEF = SBETA*ASCALE
8556 BCOEFR = SALFAR*BSCALE
8557 BCOEFI = ZERO
8558 *
8559 * Scale to avoid underflow
8560 *
8561 SCALE = ONE
8562 LSA = ABS( SBETA ).GE.SAFMIN .AND. ABS( ACOEF ).LT.SMALL
8563 LSB = ABS( SALFAR ).GE.SAFMIN .AND. ABS( BCOEFR ).LT.
8564 $ SMALL
8565 IF( LSA )
8566 $ SCALE = ( SMALL / ABS( SBETA ) )*MIN( ANORM, BIG )
8567 IF( LSB )
8568 $ SCALE = MAX( SCALE, ( SMALL / ABS( SALFAR ) )*
8569 $ MIN( BNORM, BIG ) )
8570 IF( LSA .OR. LSB ) THEN
8571 SCALE = MIN( SCALE, ONE /
8572 $ ( SAFMIN*MAX( ONE, ABS( ACOEF ),
8573 $ ABS( BCOEFR ) ) ) )
8574 IF( LSA ) THEN
8575 ACOEF = ASCALE*( SCALE*SBETA )
8576 ELSE
8577 ACOEF = SCALE*ACOEF
8578 END IF
8579 IF( LSB ) THEN
8580 BCOEFR = BSCALE*( SCALE*SALFAR )
8581 ELSE
8582 BCOEFR = SCALE*BCOEFR
8583 END IF
8584 END IF
8585 ACOEFA = ABS( ACOEF )
8586 BCOEFA = ABS( BCOEFR )
8587 *
8588 * First component is 1
8589 *
8590 WORK( 2*N+JE ) = ONE
8591 XMAX = ONE
8592 *
8593 * Compute contribution from column JE of A and B to sum
8594 * (See "Further Details", above.)
8595 *
8596 DO 260 JR = 1, JE - 1
8597 WORK( 2*N+JR ) = BCOEFR*P( JR, JE ) -
8598 $ ACOEF*S( JR, JE )
8599 260 CONTINUE
8600 ELSE
8601 *
8602 * Complex eigenvalue
8603 *
8604 CALL DLAG2( S( JE-1, JE-1 ), LDS, P( JE-1, JE-1 ), LDP,
8605 $ SAFMIN*SAFETY, ACOEF, TEMP, BCOEFR, TEMP2,
8606 $ BCOEFI )
8607 IF( BCOEFI.EQ.ZERO ) THEN
8608 INFO = JE - 1
8609 RETURN
8610 END IF
8611 *
8612 * Scale to avoid over/underflow
8613 *
8614 ACOEFA = ABS( ACOEF )
8615 BCOEFA = ABS( BCOEFR ) + ABS( BCOEFI )
8616 SCALE = ONE
8617 IF( ACOEFA*ULP.LT.SAFMIN .AND. ACOEFA.GE.SAFMIN )
8618 $ SCALE = ( SAFMIN / ULP ) / ACOEFA
8619 IF( BCOEFA*ULP.LT.SAFMIN .AND. BCOEFA.GE.SAFMIN )
8620 $ SCALE = MAX( SCALE, ( SAFMIN / ULP ) / BCOEFA )
8621 IF( SAFMIN*ACOEFA.GT.ASCALE )
8622 $ SCALE = ASCALE / ( SAFMIN*ACOEFA )
8623 IF( SAFMIN*BCOEFA.GT.BSCALE )
8624 $ SCALE = MIN( SCALE, BSCALE / ( SAFMIN*BCOEFA ) )
8625 IF( SCALE.NE.ONE ) THEN
8626 ACOEF = SCALE*ACOEF
8627 ACOEFA = ABS( ACOEF )
8628 BCOEFR = SCALE*BCOEFR
8629 BCOEFI = SCALE*BCOEFI
8630 BCOEFA = ABS( BCOEFR ) + ABS( BCOEFI )
8631 END IF
8632 *
8633 * Compute first two components of eigenvector
8634 * and contribution to sums
8635 *
8636 TEMP = ACOEF*S( JE, JE-1 )
8637 TEMP2R = ACOEF*S( JE, JE ) - BCOEFR*P( JE, JE )
8638 TEMP2I = -BCOEFI*P( JE, JE )
8639 IF( ABS( TEMP ).GE.ABS( TEMP2R )+ABS( TEMP2I ) ) THEN
8640 WORK( 2*N+JE ) = ONE
8641 WORK( 3*N+JE ) = ZERO
8642 WORK( 2*N+JE-1 ) = -TEMP2R / TEMP
8643 WORK( 3*N+JE-1 ) = -TEMP2I / TEMP
8644 ELSE
8645 WORK( 2*N+JE-1 ) = ONE
8646 WORK( 3*N+JE-1 ) = ZERO
8647 TEMP = ACOEF*S( JE-1, JE )
8648 WORK( 2*N+JE ) = ( BCOEFR*P( JE-1, JE-1 )-ACOEF*
8649 $ S( JE-1, JE-1 ) ) / TEMP
8650 WORK( 3*N+JE ) = BCOEFI*P( JE-1, JE-1 ) / TEMP
8651 END IF
8652 *
8653 XMAX = MAX( ABS( WORK( 2*N+JE ) )+ABS( WORK( 3*N+JE ) ),
8654 $ ABS( WORK( 2*N+JE-1 ) )+ABS( WORK( 3*N+JE-1 ) ) )
8655 *
8656 * Compute contribution from columns JE and JE-1
8657 * of A and B to the sums.
8658 *
8659 CREALA = ACOEF*WORK( 2*N+JE-1 )
8660 CIMAGA = ACOEF*WORK( 3*N+JE-1 )
8661 CREALB = BCOEFR*WORK( 2*N+JE-1 ) -
8662 $ BCOEFI*WORK( 3*N+JE-1 )
8663 CIMAGB = BCOEFI*WORK( 2*N+JE-1 ) +
8664 $ BCOEFR*WORK( 3*N+JE-1 )
8665 CRE2A = ACOEF*WORK( 2*N+JE )
8666 CIM2A = ACOEF*WORK( 3*N+JE )
8667 CRE2B = BCOEFR*WORK( 2*N+JE ) - BCOEFI*WORK( 3*N+JE )
8668 CIM2B = BCOEFI*WORK( 2*N+JE ) + BCOEFR*WORK( 3*N+JE )
8669 DO 270 JR = 1, JE - 2
8670 WORK( 2*N+JR ) = -CREALA*S( JR, JE-1 ) +
8671 $ CREALB*P( JR, JE-1 ) -
8672 $ CRE2A*S( JR, JE ) + CRE2B*P( JR, JE )
8673 WORK( 3*N+JR ) = -CIMAGA*S( JR, JE-1 ) +
8674 $ CIMAGB*P( JR, JE-1 ) -
8675 $ CIM2A*S( JR, JE ) + CIM2B*P( JR, JE )
8676 270 CONTINUE
8677 END IF
8678 *
8679 DMIN = MAX( ULP*ACOEFA*ANORM, ULP*BCOEFA*BNORM, SAFMIN )
8680 *
8681 * Columnwise triangular solve of (a A - b B) x = 0
8682 *
8683 IL2BY2 = .FALSE.
8684 DO 370 J = JE - NW, 1, -1
8685 *
8686 * If a 2-by-2 block, is in position j-1:j, wait until
8687 * next iteration to process it (when it will be j:j+1)
8688 *
8689 IF( .NOT.IL2BY2 .AND. J.GT.1 ) THEN
8690 IF( S( J, J-1 ).NE.ZERO ) THEN
8691 IL2BY2 = .TRUE.
8692 GO TO 370
8693 END IF
8694 END IF
8695 BDIAG( 1 ) = P( J, J )
8696 IF( IL2BY2 ) THEN
8697 NA = 2
8698 BDIAG( 2 ) = P( J+1, J+1 )
8699 ELSE
8700 NA = 1
8701 END IF
8702 *
8703 * Compute x(j) (and x(j+1), if 2-by-2 block)
8704 *
8705 CALL DLALN2( .FALSE., NA, NW, DMIN, ACOEF, S( J, J ),
8706 $ LDS, BDIAG( 1 ), BDIAG( 2 ), WORK( 2*N+J ),
8707 $ N, BCOEFR, BCOEFI, SUM, 2, SCALE, TEMP,
8708 $ IINFO )
8709 IF( SCALE.LT.ONE ) THEN
8710 *
8711 DO 290 JW = 0, NW - 1
8712 DO 280 JR = 1, JE
8713 WORK( ( JW+2 )*N+JR ) = SCALE*
8714 $ WORK( ( JW+2 )*N+JR )
8715 280 CONTINUE
8716 290 CONTINUE
8717 END IF
8718 XMAX = MAX( SCALE*XMAX, TEMP )
8719 *
8720 DO 310 JW = 1, NW
8721 DO 300 JA = 1, NA
8722 WORK( ( JW+1 )*N+J+JA-1 ) = SUM( JA, JW )
8723 300 CONTINUE
8724 310 CONTINUE
8725 *
8726 * w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling
8727 *
8728 IF( J.GT.1 ) THEN
8729 *
8730 * Check whether scaling is necessary for sum.
8731 *
8732 XSCALE = ONE / MAX( ONE, XMAX )
8733 TEMP = ACOEFA*WORK( J ) + BCOEFA*WORK( N+J )
8734 IF( IL2BY2 )
8735 $ TEMP = MAX( TEMP, ACOEFA*WORK( J+1 )+BCOEFA*
8736 $ WORK( N+J+1 ) )
8737 TEMP = MAX( TEMP, ACOEFA, BCOEFA )
8738 IF( TEMP.GT.BIGNUM*XSCALE ) THEN
8739 *
8740 DO 330 JW = 0, NW - 1
8741 DO 320 JR = 1, JE
8742 WORK( ( JW+2 )*N+JR ) = XSCALE*
8743 $ WORK( ( JW+2 )*N+JR )
8744 320 CONTINUE
8745 330 CONTINUE
8746 XMAX = XMAX*XSCALE
8747 END IF
8748 *
8749 * Compute the contributions of the off-diagonals of
8750 * column j (and j+1, if 2-by-2 block) of A and B to the
8751 * sums.
8752 *
8753 *
8754 DO 360 JA = 1, NA
8755 IF( ILCPLX ) THEN
8756 CREALA = ACOEF*WORK( 2*N+J+JA-1 )
8757 CIMAGA = ACOEF*WORK( 3*N+J+JA-1 )
8758 CREALB = BCOEFR*WORK( 2*N+J+JA-1 ) -
8759 $ BCOEFI*WORK( 3*N+J+JA-1 )
8760 CIMAGB = BCOEFI*WORK( 2*N+J+JA-1 ) +
8761 $ BCOEFR*WORK( 3*N+J+JA-1 )
8762 DO 340 JR = 1, J - 1
8763 WORK( 2*N+JR ) = WORK( 2*N+JR ) -
8764 $ CREALA*S( JR, J+JA-1 ) +
8765 $ CREALB*P( JR, J+JA-1 )
8766 WORK( 3*N+JR ) = WORK( 3*N+JR ) -
8767 $ CIMAGA*S( JR, J+JA-1 ) +
8768 $ CIMAGB*P( JR, J+JA-1 )
8769 340 CONTINUE
8770 ELSE
8771 CREALA = ACOEF*WORK( 2*N+J+JA-1 )
8772 CREALB = BCOEFR*WORK( 2*N+J+JA-1 )
8773 DO 350 JR = 1, J - 1
8774 WORK( 2*N+JR ) = WORK( 2*N+JR ) -
8775 $ CREALA*S( JR, J+JA-1 ) +
8776 $ CREALB*P( JR, J+JA-1 )
8777 350 CONTINUE
8778 END IF
8779 360 CONTINUE
8780 END IF
8781 *
8782 IL2BY2 = .FALSE.
8783 370 CONTINUE
8784 *
8785 * Copy eigenvector to VR, back transforming if
8786 * HOWMNY='B'.
8787 *
8788 IEIG = IEIG - NW
8789 IF( ILBACK ) THEN
8790 *
8791 DO 410 JW = 0, NW - 1
8792 DO 380 JR = 1, N
8793 WORK( ( JW+4 )*N+JR ) = WORK( ( JW+2 )*N+1 )*
8794 $ VR( JR, 1 )
8795 380 CONTINUE
8796 *
8797 * A series of compiler directives to defeat
8798 * vectorization for the next loop
8799 *
8800 *
8801 DO 400 JC = 2, JE
8802 DO 390 JR = 1, N
8803 WORK( ( JW+4 )*N+JR ) = WORK( ( JW+4 )*N+JR ) +
8804 $ WORK( ( JW+2 )*N+JC )*VR( JR, JC )
8805 390 CONTINUE
8806 400 CONTINUE
8807 410 CONTINUE
8808 *
8809 DO 430 JW = 0, NW - 1
8810 DO 420 JR = 1, N
8811 VR( JR, IEIG+JW ) = WORK( ( JW+4 )*N+JR )
8812 420 CONTINUE
8813 430 CONTINUE
8814 *
8815 IEND = N
8816 ELSE
8817 DO 450 JW = 0, NW - 1
8818 DO 440 JR = 1, N
8819 VR( JR, IEIG+JW ) = WORK( ( JW+2 )*N+JR )
8820 440 CONTINUE
8821 450 CONTINUE
8822 *
8823 IEND = JE
8824 END IF
8825 *
8826 * Scale eigenvector
8827 *
8828 XMAX = ZERO
8829 IF( ILCPLX ) THEN
8830 DO 460 J = 1, IEND
8831 XMAX = MAX( XMAX, ABS( VR( J, IEIG ) )+
8832 $ ABS( VR( J, IEIG+1 ) ) )
8833 460 CONTINUE
8834 ELSE
8835 DO 470 J = 1, IEND
8836 XMAX = MAX( XMAX, ABS( VR( J, IEIG ) ) )
8837 470 CONTINUE
8838 END IF
8839 *
8840 IF( XMAX.GT.SAFMIN ) THEN
8841 XSCALE = ONE / XMAX
8842 DO 490 JW = 0, NW - 1
8843 DO 480 JR = 1, IEND
8844 VR( JR, IEIG+JW ) = XSCALE*VR( JR, IEIG+JW )
8845 480 CONTINUE
8846 490 CONTINUE
8847 END IF
8848 500 CONTINUE
8849 END IF
8850 *
8851 RETURN
8852 *
8853 * End of DTGEVC
8854 *
8855 END
8856 C
8857 C-----------------------------------------------------------------------
8858 C-----------------------------------------------------------------------
8859 SUBROUTINE DLAG2( A, LDA, B, LDB, SAFMIN, SCALE1, SCALE2, WR1,
8860 $ WR2, WI )
8861 *
8862 * -- LAPACK auxiliary routine (version 3.2) --
8863 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
8864 * November 2006
8865 *
8866 * .. Scalar Arguments ..
8867 INTEGER LDA, LDB
8868 DOUBLE PRECISION SAFMIN, SCALE1, SCALE2, WI, WR1, WR2
8869 * ..
8870 * .. Array Arguments ..
8871 DOUBLE PRECISION A( LDA, * ), B( LDB, * )
8872 * ..
8873 *
8874 * Purpose
8875 * =======
8876 *
8877 * DLAG2 computes the eigenvalues of a 2 x 2 generalized eigenvalue
8878 * problem A - w B, with scaling as necessary to avoid over-/underflow.
8879 *
8880 * The scaling factor "s" results in a modified eigenvalue equation
8881 *
8882 * s A - w B
8883 *
8884 * where s is a non-negative scaling factor chosen so that w, w B,
8885 * and s A do not overflow and, if possible, do not underflow, either.
8886 *
8887 * Arguments
8888 * =========
8889 *
8890 * A (input) DOUBLE PRECISION array, dimension (LDA, 2)
8891 * On entry, the 2 x 2 matrix A. It is assumed that its 1-norm
8892 * is less than 1/SAFMIN. Entries less than
8893 * sqrt(SAFMIN)*norm(A) are subject to being treated as zero.
8894 *
8895 * LDA (input) INTEGER
8896 * The leading dimension of the array A. LDA >= 2.
8897 *
8898 * B (input) DOUBLE PRECISION array, dimension (LDB, 2)
8899 * On entry, the 2 x 2 upper triangular matrix B. It is
8900 * assumed that the one-norm of B is less than 1/SAFMIN. The
8901 * diagonals should be at least sqrt(SAFMIN) times the largest
8902 * element of B (in absolute value); if a diagonal is smaller
8903 * than that, then +/- sqrt(SAFMIN) will be used instead of
8904 * that diagonal.
8905 *
8906 * LDB (input) INTEGER
8907 * The leading dimension of the array B. LDB >= 2.
8908 *
8909 * SAFMIN (input) DOUBLE PRECISION
8910 * The smallest positive number s.t. 1/SAFMIN does not
8911 * overflow. (This should always be DLAMCH('S') -- it is an
8912 * argument in order to avoid having to call DLAMCH frequently.)
8913 *
8914 * SCALE1 (output) DOUBLE PRECISION
8915 * A scaling factor used to avoid over-/underflow in the
8916 * eigenvalue equation which defines the first eigenvalue. If
8917 * the eigenvalues are complex, then the eigenvalues are
8918 * ( WR1 +/- WI i ) / SCALE1 (which may lie outside the
8919 * exponent range of the machine), SCALE1=SCALE2, and SCALE1
8920 * will always be positive. If the eigenvalues are real, then
8921 * the first (real) eigenvalue is WR1 / SCALE1 , but this may
8922 * overflow or underflow, and in fact, SCALE1 may be zero or
8923 * less than the underflow threshhold if the exact eigenvalue
8924 * is sufficiently large.
8925 *
8926 * SCALE2 (output) DOUBLE PRECISION
8927 * A scaling factor used to avoid over-/underflow in the
8928 * eigenvalue equation which defines the second eigenvalue. If
8929 * the eigenvalues are complex, then SCALE2=SCALE1. If the
8930 * eigenvalues are real, then the second (real) eigenvalue is
8931 * WR2 / SCALE2 , but this may overflow or underflow, and in
8932 * fact, SCALE2 may be zero or less than the underflow
8933 * threshhold if the exact eigenvalue is sufficiently large.
8934 *
8935 * WR1 (output) DOUBLE PRECISION
8936 * If the eigenvalue is real, then WR1 is SCALE1 times the
8937 * eigenvalue closest to the (2,2) element of A B**(-1). If the
8938 * eigenvalue is complex, then WR1=WR2 is SCALE1 times the real
8939 * part of the eigenvalues.
8940 *
8941 * WR2 (output) DOUBLE PRECISION
8942 * If the eigenvalue is real, then WR2 is SCALE2 times the
8943 * other eigenvalue. If the eigenvalue is complex, then
8944 * WR1=WR2 is SCALE1 times the real part of the eigenvalues.
8945 *
8946 * WI (output) DOUBLE PRECISION
8947 * If the eigenvalue is real, then WI is zero. If the
8948 * eigenvalue is complex, then WI is SCALE1 times the imaginary
8949 * part of the eigenvalues. WI will always be non-negative.
8950 *
8951 * =====================================================================
8952 *
8953 * .. Parameters ..
8954 DOUBLE PRECISION ZERO, ONE, TWO
8955 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TWO = 2.0D+0 )
8956 DOUBLE PRECISION HALF
8957 PARAMETER ( HALF = ONE / TWO )
8958 DOUBLE PRECISION FUZZY1
8959 PARAMETER ( FUZZY1 = ONE+1.0D-5 )
8960 * ..
8961 * .. Local Scalars ..
8962 DOUBLE PRECISION A11, A12, A21, A22, ABI22, ANORM, AS11, AS12,
8963 $ AS22, ASCALE, B11, B12, B22, BINV11, BINV22,
8964 $ BMIN, BNORM, BSCALE, BSIZE, C1, C2, C3, C4, C5,
8965 $ DIFF, DISCR, PP, QQ, R, RTMAX, RTMIN, S1, S2,
8966 $ SAFMAX, SHIFT, SS, SUM, WABS, WBIG, WDET,
8967 $ WSCALE, WSIZE, WSMALL
8968 * ..
8969 * .. Intrinsic Functions ..
8970 INTRINSIC ABS, MAX, MIN, SIGN, SQRT
8971 * ..
8972 * .. Executable Statements ..
8973 *
8974 RTMIN = SQRT( SAFMIN )
8975 RTMAX = ONE / RTMIN
8976 SAFMAX = ONE / SAFMIN
8977 *
8978 * Scale A
8979 *
8980 ANORM = MAX( ABS( A( 1, 1 ) )+ABS( A( 2, 1 ) ),
8981 $ ABS( A( 1, 2 ) )+ABS( A( 2, 2 ) ), SAFMIN )
8982 ASCALE = ONE / ANORM
8983 A11 = ASCALE*A( 1, 1 )
8984 A21 = ASCALE*A( 2, 1 )
8985 A12 = ASCALE*A( 1, 2 )
8986 A22 = ASCALE*A( 2, 2 )
8987 *
8988 * Perturb B if necessary to insure non-singularity
8989 *
8990 B11 = B( 1, 1 )
8991 B12 = B( 1, 2 )
8992 B22 = B( 2, 2 )
8993 BMIN = RTMIN*MAX( ABS( B11 ), ABS( B12 ), ABS( B22 ), RTMIN )
8994 IF( ABS( B11 ).LT.BMIN )
8995 $ B11 = SIGN( BMIN, B11 )
8996 IF( ABS( B22 ).LT.BMIN )
8997 $ B22 = SIGN( BMIN, B22 )
8998 *
8999 * Scale B
9000 *
9001 BNORM = MAX( ABS( B11 ), ABS( B12 )+ABS( B22 ), SAFMIN )
9002 BSIZE = MAX( ABS( B11 ), ABS( B22 ) )
9003 BSCALE = ONE / BSIZE
9004 B11 = B11*BSCALE
9005 B12 = B12*BSCALE
9006 B22 = B22*BSCALE
9007 *
9008 * Compute larger eigenvalue by method described by C. van Loan
9009 *
9010 * ( AS is A shifted by -SHIFT*B )
9011 *
9012 BINV11 = ONE / B11
9013 BINV22 = ONE / B22
9014 S1 = A11*BINV11
9015 S2 = A22*BINV22
9016 IF( ABS( S1 ).LE.ABS( S2 ) ) THEN
9017 AS12 = A12 - S1*B12
9018 AS22 = A22 - S1*B22
9019 SS = A21*( BINV11*BINV22 )
9020 ABI22 = AS22*BINV22 - SS*B12
9021 PP = HALF*ABI22
9022 SHIFT = S1
9023 ELSE
9024 AS12 = A12 - S2*B12
9025 AS11 = A11 - S2*B11
9026 SS = A21*( BINV11*BINV22 )
9027 ABI22 = -SS*B12
9028 PP = HALF*( AS11*BINV11+ABI22 )
9029 SHIFT = S2
9030 END IF
9031 QQ = SS*AS12
9032 IF( ABS( PP*RTMIN ).GE.ONE ) THEN
9033 DISCR = ( RTMIN*PP )**2 + QQ*SAFMIN
9034 R = SQRT( ABS( DISCR ) )*RTMAX
9035 ELSE
9036 IF( PP**2+ABS( QQ ).LE.SAFMIN ) THEN
9037 DISCR = ( RTMAX*PP )**2 + QQ*SAFMAX
9038 R = SQRT( ABS( DISCR ) )*RTMIN
9039 ELSE
9040 DISCR = PP**2 + QQ
9041 R = SQRT( ABS( DISCR ) )
9042 END IF
9043 END IF
9044 *
9045 * Note: the test of R in the following IF is to cover the case when
9046 * DISCR is small and negative and is flushed to zero during
9047 * the calculation of R. On machines which have a consistent
9048 * flush-to-zero threshhold and handle numbers above that
9049 * threshhold correctly, it would not be necessary.
9050 *
9051 IF( DISCR.GE.ZERO .OR. R.EQ.ZERO ) THEN
9052 SUM = PP + SIGN( R, PP )
9053 DIFF = PP - SIGN( R, PP )
9054 WBIG = SHIFT + SUM
9055 *
9056 * Compute smaller eigenvalue
9057 *
9058 WSMALL = SHIFT + DIFF
9059 IF( HALF*ABS( WBIG ).GT.MAX( ABS( WSMALL ), SAFMIN ) ) THEN
9060 WDET = ( A11*A22-A12*A21 )*( BINV11*BINV22 )
9061 WSMALL = WDET / WBIG
9062 END IF
9063 *
9064 * Choose (real) eigenvalue closest to 2,2 element of A*B**(-1)
9065 * for WR1.
9066 *
9067 IF( PP.GT.ABI22 ) THEN
9068 WR1 = MIN( WBIG, WSMALL )
9069 WR2 = MAX( WBIG, WSMALL )
9070 ELSE
9071 WR1 = MAX( WBIG, WSMALL )
9072 WR2 = MIN( WBIG, WSMALL )
9073 END IF
9074 WI = ZERO
9075 ELSE
9076 *
9077 * Complex eigenvalues
9078 *
9079 WR1 = SHIFT + PP
9080 WR2 = WR1
9081 WI = R
9082 END IF
9083 *
9084 * Further scaling to avoid underflow and overflow in computing
9085 * SCALE1 and overflow in computing w*B.
9086 *
9087 * This scale factor (WSCALE) is bounded from above using C1 and C2,
9088 * and from below using C3 and C4.
9089 * C1 implements the condition s A must never overflow.
9090 * C2 implements the condition w B must never overflow.
9091 * C3, with C2,
9092 * implement the condition that s A - w B must never overflow.
9093 * C4 implements the condition s should not underflow.
9094 * C5 implements the condition max(s,|w|) should be at least 2.
9095 *
9096 C1 = BSIZE*( SAFMIN*MAX( ONE, ASCALE ) )
9097 C2 = SAFMIN*MAX( ONE, BNORM )
9098 C3 = BSIZE*SAFMIN
9099 IF( ASCALE.LE.ONE .AND. BSIZE.LE.ONE ) THEN
9100 C4 = MIN( ONE, ( ASCALE / SAFMIN )*BSIZE )
9101 ELSE
9102 C4 = ONE
9103 END IF
9104 IF( ASCALE.LE.ONE .OR. BSIZE.LE.ONE ) THEN
9105 C5 = MIN( ONE, ASCALE*BSIZE )
9106 ELSE
9107 C5 = ONE
9108 END IF
9109 *
9110 * Scale first eigenvalue
9111 *
9112 WABS = ABS( WR1 ) + ABS( WI )
9113 WSIZE = MAX( SAFMIN, C1, FUZZY1*( WABS*C2+C3 ),
9114 $ MIN( C4, HALF*MAX( WABS, C5 ) ) )
9115 IF( WSIZE.NE.ONE ) THEN
9116 WSCALE = ONE / WSIZE
9117 IF( WSIZE.GT.ONE ) THEN
9118 SCALE1 = ( MAX( ASCALE, BSIZE )*WSCALE )*
9119 $ MIN( ASCALE, BSIZE )
9120 ELSE
9121 SCALE1 = ( MIN( ASCALE, BSIZE )*WSCALE )*
9122 $ MAX( ASCALE, BSIZE )
9123 END IF
9124 WR1 = WR1*WSCALE
9125 IF( WI.NE.ZERO ) THEN
9126 WI = WI*WSCALE
9127 WR2 = WR1
9128 SCALE2 = SCALE1
9129 END IF
9130 ELSE
9131 SCALE1 = ASCALE*BSIZE
9132 SCALE2 = SCALE1
9133 END IF
9134 *
9135 * Scale second eigenvalue (if real)
9136 *
9137 IF( WI.EQ.ZERO ) THEN
9138 WSIZE = MAX( SAFMIN, C1, FUZZY1*( ABS( WR2 )*C2+C3 ),
9139 $ MIN( C4, HALF*MAX( ABS( WR2 ), C5 ) ) )
9140 IF( WSIZE.NE.ONE ) THEN
9141 WSCALE = ONE / WSIZE
9142 IF( WSIZE.GT.ONE ) THEN
9143 SCALE2 = ( MAX( ASCALE, BSIZE )*WSCALE )*
9144 $ MIN( ASCALE, BSIZE )
9145 ELSE
9146 SCALE2 = ( MIN( ASCALE, BSIZE )*WSCALE )*
9147 $ MAX( ASCALE, BSIZE )
9148 END IF
9149 WR2 = WR2*WSCALE
9150 ELSE
9151 SCALE2 = ASCALE*BSIZE
9152 END IF
9153 END IF
9154 *
9155 * End of DLAG2
9156 *
9157 RETURN
9158 END
9159 C
9160 C-----------------------------------------------------------------------
9161 C-----------------------------------------------------------------------
9162 DOUBLE PRECISION FUNCTION DLANHS( NORM, N, A, LDA, WORK )
9163 *
9164 * -- LAPACK auxiliary routine (version 3.2) --
9165 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
9166 * November 2006
9167 *
9168 * .. Scalar Arguments ..
9169 CHARACTER NORM
9170 INTEGER LDA, N
9171 * ..
9172 * .. Array Arguments ..
9173 DOUBLE PRECISION A( LDA, * ), WORK( * )
9174 * ..
9175 *
9176 * Purpose
9177 * =======
9178 *
9179 * DLANHS returns the value of the one norm, or the Frobenius norm, or
9180 * the infinity norm, or the element of largest absolute value of a
9181 * Hessenberg matrix A.
9182 *
9183 * Description
9184 * ===========
9185 *
9186 * DLANHS returns the value
9187 *
9188 * DLANHS = ( max(abs(A(i,j))), NORM = 'M' or 'm'
9189 * (
9190 * ( norm1(A), NORM = '1', 'O' or 'o'
9191 * (
9192 * ( normI(A), NORM = 'I' or 'i'
9193 * (
9194 * ( normF(A), NORM = 'F', 'f', 'E' or 'e'
9195 *
9196 * where norm1 denotes the one norm of a matrix (maximum column sum),
9197 * normI denotes the infinity norm of a matrix (maximum row sum) and
9198 * normF denotes the Frobenius norm of a matrix (square root of sum of
9199 * squares). Note that max(abs(A(i,j))) is not a consistent matrix norm.
9200 *
9201 * Arguments
9202 * =========
9203 *
9204 * NORM (input) CHARACTER*1
9205 * Specifies the value to be returned in DLANHS as described
9206 * above.
9207 *
9208 * N (input) INTEGER
9209 * The order of the matrix A. N >= 0. When N = 0, DLANHS is
9210 * set to zero.
9211 *
9212 * A (input) DOUBLE PRECISION array, dimension (LDA,N)
9213 * The n by n upper Hessenberg matrix A; the part of A below the
9214 * first sub-diagonal is not referenced.
9215 *
9216 * LDA (input) INTEGER
9217 * The leading dimension of the array A. LDA >= max(N,1).
9218 *
9219 * WORK (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),
9220 * where LWORK >= N when NORM = 'I'; otherwise, WORK is not
9221 * referenced.
9222 *
9223 * =====================================================================
9224 *
9225 * .. Parameters ..
9226 DOUBLE PRECISION ONE, ZERO
9227 PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
9228 * ..
9229 * .. Local Scalars ..
9230 INTEGER I, J
9231 DOUBLE PRECISION SCALE, SUM, VALUE
9232 * ..
9233 * .. External Subroutines ..
9234 EXTERNAL DLASSQ
9235 * ..
9236 * .. External Functions ..
9237 LOGICAL LSAME
9238 EXTERNAL LSAME
9239 * ..
9240 * .. Intrinsic Functions ..
9241 INTRINSIC ABS, MAX, MIN, SQRT
9242 * ..
9243 * .. Executable Statements ..
9244 *
9245 IF( N.EQ.0 ) THEN
9246 VALUE = ZERO
9247 ELSE IF( LSAME( NORM, 'M' ) ) THEN
9248 *
9249 * Find max(abs(A(i,j))).
9250 *
9251 VALUE = ZERO
9252 DO 20 J = 1, N
9253 DO 10 I = 1, MIN( N, J+1 )
9254 VALUE = MAX( VALUE, ABS( A( I, J ) ) )
9255 10 CONTINUE
9256 20 CONTINUE
9257 ELSE IF( ( LSAME( NORM, 'O' ) ) .OR. ( NORM.EQ.'1' ) ) THEN
9258 *
9259 * Find norm1(A).
9260 *
9261 VALUE = ZERO
9262 DO 40 J = 1, N
9263 SUM = ZERO
9264 DO 30 I = 1, MIN( N, J+1 )
9265 SUM = SUM + ABS( A( I, J ) )
9266 30 CONTINUE
9267 VALUE = MAX( VALUE, SUM )
9268 40 CONTINUE
9269 ELSE IF( LSAME( NORM, 'I' ) ) THEN
9270 *
9271 * Find normI(A).
9272 *
9273 DO 50 I = 1, N
9274 WORK( I ) = ZERO
9275 50 CONTINUE
9276 DO 70 J = 1, N
9277 DO 60 I = 1, MIN( N, J+1 )
9278 WORK( I ) = WORK( I ) + ABS( A( I, J ) )
9279 60 CONTINUE
9280 70 CONTINUE
9281 VALUE = ZERO
9282 DO 80 I = 1, N
9283 VALUE = MAX( VALUE, WORK( I ) )
9284 80 CONTINUE
9285 ELSE IF( ( LSAME( NORM, 'F' ) ) .OR. ( LSAME( NORM, 'E' ) ) ) THEN
9286 *
9287 * Find normF(A).
9288 *
9289 SCALE = ZERO
9290 SUM = ONE
9291 DO 90 J = 1, N
9292 CALL DLASSQ( MIN( N, J+1 ), A( 1, J ), 1, SCALE, SUM )
9293 90 CONTINUE
9294 VALUE = SCALE*SQRT( SUM )
9295 END IF
9296 *
9297 DLANHS = VALUE
9298 RETURN
9299 *
9300 * End of DLANHS
9301 *
9302 END
9303 C
9304 C-----------------------------------------------------------------------
9305 C-----------------------------------------------------------------------
9306 SUBROUTINE DLASV2( F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL )
9307 *
9308 * -- LAPACK auxiliary routine (version 3.2) --
9309 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
9310 * November 2006
9311 *
9312 * .. Scalar Arguments ..
9313 DOUBLE PRECISION CSL, CSR, F, G, H, SNL, SNR, SSMAX, SSMIN
9314 * ..
9315 *
9316 * Purpose
9317 * =======
9318 *
9319 * DLASV2 computes the singular value decomposition of a 2-by-2
9320 * triangular matrix
9321 * [ F G ]
9322 * [ 0 H ].
9323 * On return, abs(SSMAX) is the larger singular value, abs(SSMIN) is the
9324 * smaller singular value, and (CSL,SNL) and (CSR,SNR) are the left and
9325 * right singular vectors for abs(SSMAX), giving the decomposition
9326 *
9327 * [ CSL SNL ] [ F G ] [ CSR -SNR ] = [ SSMAX 0 ]
9328 * [-SNL CSL ] [ 0 H ] [ SNR CSR ] [ 0 SSMIN ].
9329 *
9330 * Arguments
9331 * =========
9332 *
9333 * F (input) DOUBLE PRECISION
9334 * The (1,1) element of the 2-by-2 matrix.
9335 *
9336 * G (input) DOUBLE PRECISION
9337 * The (1,2) element of the 2-by-2 matrix.
9338 *
9339 * H (input) DOUBLE PRECISION
9340 * The (2,2) element of the 2-by-2 matrix.
9341 *
9342 * SSMIN (output) DOUBLE PRECISION
9343 * abs(SSMIN) is the smaller singular value.
9344 *
9345 * SSMAX (output) DOUBLE PRECISION
9346 * abs(SSMAX) is the larger singular value.
9347 *
9348 * SNL (output) DOUBLE PRECISION
9349 * CSL (output) DOUBLE PRECISION
9350 * The vector (CSL, SNL) is a unit left singular vector for the
9351 * singular value abs(SSMAX).
9352 *
9353 * SNR (output) DOUBLE PRECISION
9354 * CSR (output) DOUBLE PRECISION
9355 * The vector (CSR, SNR) is a unit right singular vector for the
9356 * singular value abs(SSMAX).
9357 *
9358 * Further Details
9359 * ===============
9360 *
9361 * Any input parameter may be aliased with any output parameter.
9362 *
9363 * Barring over/underflow and assuming a guard digit in subtraction, all
9364 * output quantities are correct to within a few units in the last
9365 * place (ulps).
9366 *
9367 * In IEEE arithmetic, the code works correctly if one matrix element is
9368 * infinite.
9369 *
9370 * Overflow will not occur unless the largest singular value itself
9371 * overflows or is within a few ulps of overflow. (On machines with
9372 * partial overflow, like the Cray, overflow may occur if the largest
9373 * singular value is within a factor of 2 of overflow.)
9374 *
9375 * Underflow is harmless if underflow is gradual. Otherwise, results
9376 * may correspond to a matrix modified by perturbations of size near
9377 * the underflow threshold.
9378 *
9379 * =====================================================================
9380 *
9381 * .. Parameters ..
9382 DOUBLE PRECISION ZERO
9383 PARAMETER ( ZERO = 0.0D0 )
9384 DOUBLE PRECISION HALF
9385 PARAMETER ( HALF = 0.5D0 )
9386 DOUBLE PRECISION ONE
9387 PARAMETER ( ONE = 1.0D0 )
9388 DOUBLE PRECISION TWO
9389 PARAMETER ( TWO = 2.0D0 )
9390 DOUBLE PRECISION FOUR
9391 PARAMETER ( FOUR = 4.0D0 )
9392 * ..
9393 * .. Local Scalars ..
9394 LOGICAL GASMAL, SWAP
9395 INTEGER PMAX
9396 DOUBLE PRECISION A, CLT, CRT, D, FA, FT, GA, GT, HA, HT, L, M,
9397 $ MM, R, S, SLT, SRT, T, TEMP, TSIGN, TT
9398 * ..
9399 * .. Intrinsic Functions ..
9400 INTRINSIC ABS, SIGN, SQRT
9401 * ..
9402 * .. External Functions ..
9403 DOUBLE PRECISION DLAMCH
9404 EXTERNAL DLAMCH
9405 * ..
9406 * .. Executable Statements ..
9407 *
9408 FT = F
9409 FA = ABS( FT )
9410 HT = H
9411 HA = ABS( H )
9412 *
9413 * PMAX points to the maximum absolute element of matrix
9414 * PMAX = 1 if F largest in absolute values
9415 * PMAX = 2 if G largest in absolute values
9416 * PMAX = 3 if H largest in absolute values
9417 *
9418 PMAX = 1
9419 SWAP = ( HA.GT.FA )
9420 IF( SWAP ) THEN
9421 PMAX = 3
9422 TEMP = FT
9423 FT = HT
9424 HT = TEMP
9425 TEMP = FA
9426 FA = HA
9427 HA = TEMP
9428 *
9429 * Now FA .ge. HA
9430 *
9431 END IF
9432 GT = G
9433 GA = ABS( GT )
9434 IF( GA.EQ.ZERO ) THEN
9435 *
9436 * Diagonal matrix
9437 *
9438 SSMIN = HA
9439 SSMAX = FA
9440 CLT = ONE
9441 CRT = ONE
9442 SLT = ZERO
9443 SRT = ZERO
9444 ELSE
9445 GASMAL = .TRUE.
9446 IF( GA.GT.FA ) THEN
9447 PMAX = 2
9448 IF( ( FA / GA ).LT.DLAMCH( 'EPS' ) ) THEN
9449 *
9450 * Case of very large GA
9451 *
9452 GASMAL = .FALSE.
9453 SSMAX = GA
9454 IF( HA.GT.ONE ) THEN
9455 SSMIN = FA / ( GA / HA )
9456 ELSE
9457 SSMIN = ( FA / GA )*HA
9458 END IF
9459 CLT = ONE
9460 SLT = HT / GT
9461 SRT = ONE
9462 CRT = FT / GT
9463 END IF
9464 END IF
9465 IF( GASMAL ) THEN
9466 *
9467 * Normal case
9468 *
9469 D = FA - HA
9470 IF( D.EQ.FA ) THEN
9471 *
9472 * Copes with infinite F or H
9473 *
9474 L = ONE
9475 ELSE
9476 L = D / FA
9477 END IF
9478 *
9479 * Note that 0 .le. L .le. 1
9480 *
9481 M = GT / FT
9482 *
9483 * Note that abs(M) .le. 1/macheps
9484 *
9485 T = TWO - L
9486 *
9487 * Note that T .ge. 1
9488 *
9489 MM = M*M
9490 TT = T*T
9491 S = SQRT( TT+MM )
9492 *
9493 * Note that 1 .le. S .le. 1 + 1/macheps
9494 *
9495 IF( L.EQ.ZERO ) THEN
9496 R = ABS( M )
9497 ELSE
9498 R = SQRT( L*L+MM )
9499 END IF
9500 *
9501 * Note that 0 .le. R .le. 1 + 1/macheps
9502 *
9503 A = HALF*( S+R )
9504 *
9505 * Note that 1 .le. A .le. 1 + abs(M)
9506 *
9507 SSMIN = HA / A
9508 SSMAX = FA*A
9509 IF( MM.EQ.ZERO ) THEN
9510 *
9511 * Note that M is very tiny
9512 *
9513 IF( L.EQ.ZERO ) THEN
9514 T = SIGN( TWO, FT )*SIGN( ONE, GT )
9515 ELSE
9516 T = GT / SIGN( D, FT ) + M / T
9517 END IF
9518 ELSE
9519 T = ( M / ( S+T )+M / ( R+L ) )*( ONE+A )
9520 END IF
9521 L = SQRT( T*T+FOUR )
9522 CRT = TWO / L
9523 SRT = T / L
9524 CLT = ( CRT+SRT*M ) / A
9525 SLT = ( HT / FT )*SRT / A
9526 END IF
9527 END IF
9528 IF( SWAP ) THEN
9529 CSL = SRT
9530 SNL = CRT
9531 CSR = SLT
9532 SNR = CLT
9533 ELSE
9534 CSL = CLT
9535 SNL = SLT
9536 CSR = CRT
9537 SNR = SRT
9538 END IF
9539 *
9540 * Correct signs of SSMAX and SSMIN
9541 *
9542 IF( PMAX.EQ.1 )
9543 $ TSIGN = SIGN( ONE, CSR )*SIGN( ONE, CSL )*SIGN( ONE, F )
9544 IF( PMAX.EQ.2 )
9545 $ TSIGN = SIGN( ONE, SNR )*SIGN( ONE, CSL )*SIGN( ONE, G )
9546 IF( PMAX.EQ.3 )
9547 $ TSIGN = SIGN( ONE, SNR )*SIGN( ONE, SNL )*SIGN( ONE, H )
9548 SSMAX = SIGN( SSMAX, TSIGN )
9549 SSMIN = SIGN( SSMIN, TSIGN*SIGN( ONE, F )*SIGN( ONE, H ) )
9550 RETURN
9551 *
9552 * End of DLASV2
9553 *
9554 END
9555 C
9556 C-----------------------------------------------------------------------
9557 C-----------------------------------------------------------------------
9558 DOUBLE PRECISION FUNCTION DLAPY3( X, Y, Z )
9559 *
9560 * -- LAPACK auxiliary routine (version 3.2) --
9561 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
9562 * November 2006
9563 *
9564 * .. Scalar Arguments ..
9565 DOUBLE PRECISION X, Y, Z
9566 * ..
9567 *
9568 * Purpose
9569 * =======
9570 *
9571 * DLAPY3 returns sqrt(x**2+y**2+z**2), taking care not to cause
9572 * unnecessary overflow.
9573 *
9574 * Arguments
9575 * =========
9576 *
9577 * X (input) DOUBLE PRECISION
9578 * Y (input) DOUBLE PRECISION
9579 * Z (input) DOUBLE PRECISION
9580 * X, Y and Z specify the values x, y and z.
9581 *
9582 * =====================================================================
9583 *
9584 * .. Parameters ..
9585 DOUBLE PRECISION ZERO
9586 PARAMETER ( ZERO = 0.0D0 )
9587 * ..
9588 * .. Local Scalars ..
9589 DOUBLE PRECISION W, XABS, YABS, ZABS
9590 * ..
9591 * .. Intrinsic Functions ..
9592 INTRINSIC ABS, MAX, SQRT
9593 * ..
9594 * .. Executable Statements ..
9595 *
9596 XABS = ABS( X )
9597 YABS = ABS( Y )
9598 ZABS = ABS( Z )
9599 W = MAX( XABS, YABS, ZABS )
9600 IF( W.EQ.ZERO ) THEN
9601 * W can be zero for max(0,nan,0)
9602 * adding all three entries together will make sure
9603 * NaN will not disappear.
9604 DLAPY3 = XABS + YABS + ZABS
9605 ELSE
9606 DLAPY3 = W*SQRT( ( XABS / W )**2+( YABS / W )**2+
9607 $ ( ZABS / W )**2 )
9608 END IF
9609 RETURN
9610 *
9611 * End of DLAPY3
9612 *
9613 END
9614 C
9615 C-----------------------------------------------------------------------
9616 C-----------------------------------------------------------------------
9617 SUBROUTINE DGEQR2( M, N, A, LDA, TAU, WORK, INFO )
9618 *
9619 * -- LAPACK routine (version 3.2.2) --
9620 * -- LAPACK is a software package provided by Univ. of Tennessee, --
9621 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
9622 * June 2010
9623 *
9624 * .. Scalar Arguments ..
9625 INTEGER INFO, LDA, M, N
9626 * ..
9627 * .. Array Arguments ..
9628 DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
9629 * ..
9630 *
9631 * Purpose
9632 * =======
9633 *
9634 * DGEQR2 computes a QR factorization of a real m by n matrix A:
9635 * A = Q * R.
9636 *
9637 * Arguments
9638 * =========
9639 *
9640 * M (input) INTEGER
9641 * The number of rows of the matrix A. M >= 0.
9642 *
9643 * N (input) INTEGER
9644 * The number of columns of the matrix A. N >= 0.
9645 *
9646 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
9647 * On entry, the m by n matrix A.
9648 * On exit, the elements on and above the diagonal of the array
9649 * contain the min(m,n) by n upper trapezoidal matrix R (R is
9650 * upper triangular if m >= n); the elements below the diagonal,
9651 * with the array TAU, represent the orthogonal matrix Q as a
9652 * product of elementary reflectors (see Further Details).
9653 *
9654 * LDA (input) INTEGER
9655 * The leading dimension of the array A. LDA >= max(1,M).
9656 *
9657 * TAU (output) DOUBLE PRECISION array, dimension (min(M,N))
9658 * The scalar factors of the elementary reflectors (see Further
9659 * Details).
9660 *
9661 * WORK (workspace) DOUBLE PRECISION array, dimension (N)
9662 *
9663 * INFO (output) INTEGER
9664 * = 0: successful exit
9665 * < 0: if INFO = -i, the i-th argument had an illegal value
9666 *
9667 * Further Details
9668 * ===============
9669 *
9670 * The matrix Q is represented as a product of elementary reflectors
9671 *
9672 * Q = H(1) H(2) . . . H(k), where k = min(m,n).
9673 *
9674 * Each H(i) has the form
9675 *
9676 * H(i) = I - tau * v * v'
9677 *
9678 * where tau is a real scalar, and v is a real vector with
9679 * v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i),
9680 * and tau in TAU(i).
9681 *
9682 * =====================================================================
9683 *
9684 * .. Parameters ..
9685 DOUBLE PRECISION ONE
9686 PARAMETER ( ONE = 1.0D+0 )
9687 * ..
9688 * .. Local Scalars ..
9689 INTEGER I, K
9690 DOUBLE PRECISION AII
9691 * ..
9692 * .. External Subroutines ..
9693 EXTERNAL DLARF, DLARFG, XERBLA
9694 * ..
9695 * .. Intrinsic Functions ..
9696 INTRINSIC MAX, MIN
9697 * ..
9698 * .. Executable Statements ..
9699 *
9700 * Test the input arguments
9701 *
9702 INFO = 0
9703 IF( M.LT.0 ) THEN
9704 INFO = -1
9705 ELSE IF( N.LT.0 ) THEN
9706 INFO = -2
9707 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
9708 INFO = -4
9709 END IF
9710 IF( INFO.NE.0 ) THEN
9711 CALL XERBLA( 'DGEQR2', -INFO )
9712 RETURN
9713 END IF
9714 *
9715 K = MIN( M, N )
9716 *
9717 DO 10 I = 1, K
9718 *
9719 * Generate elementary reflector H(i) to annihilate A(i+1:m,i)
9720 *
9721 CALL DLARFG( M-I+1, A( I, I ), A( MIN( I+1, M ), I ), 1,
9722 $ TAU( I ) )
9723 IF( I.LT.N ) THEN
9724 *
9725 * Apply H(i) to A(i:m,i+1:n) from the left
9726 *
9727 AII = A( I, I )
9728 A( I, I ) = ONE
9729 CALL DLARF( 'Left', M-I+1, N-I, A( I, I ), 1, TAU( I ),
9730 $ A( I, I+1 ), LDA, WORK )
9731 A( I, I ) = AII
9732 END IF
9733 10 CONTINUE
9734 RETURN
9735 *
9736 * End of DGEQR2
9737 *
9738 END
9739 C
9740 C-----------------------------------------------------------------------
9741 C-----------------------------------------------------------------------
9742 SUBROUTINE DGEBAK( JOB, SIDE, N, ILO, IHI, SCALE, M, V, LDV,
9743 $ INFO )
9744 *
9745 * -- LAPACK routine (version 3.2) --
9746 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
9747 * November 2006
9748 *
9749 * .. Scalar Arguments ..
9750 CHARACTER JOB, SIDE
9751 INTEGER IHI, ILO, INFO, LDV, M, N
9752 * ..
9753 * .. Array Arguments ..
9754 DOUBLE PRECISION SCALE( * ), V( LDV, * )
9755 * ..
9756 *
9757 * Purpose
9758 * =======
9759 *
9760 * DGEBAK forms the right or left eigenvectors of a real general matrix
9761 * by backward transformation on the computed eigenvectors of the
9762 * balanced matrix output by DGEBAL.
9763 *
9764 * Arguments
9765 * =========
9766 *
9767 * JOB (input) CHARACTER*1
9768 * Specifies the type of backward transformation required:
9769 * = 'N', do nothing, return immediately;
9770 * = 'P', do backward transformation for permutation only;
9771 * = 'S', do backward transformation for scaling only;
9772 * = 'B', do backward transformations for both permutation and
9773 * scaling.
9774 * JOB must be the same as the argument JOB supplied to DGEBAL.
9775 *
9776 * SIDE (input) CHARACTER*1
9777 * = 'R': V contains right eigenvectors;
9778 * = 'L': V contains left eigenvectors.
9779 *
9780 * N (input) INTEGER
9781 * The number of rows of the matrix V. N >= 0.
9782 *
9783 * ILO (input) INTEGER
9784 * IHI (input) INTEGER
9785 * The integers ILO and IHI determined by DGEBAL.
9786 * 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
9787 *
9788 * SCALE (input) DOUBLE PRECISION array, dimension (N)
9789 * Details of the permutation and scaling factors, as returned
9790 * by DGEBAL.
9791 *
9792 * M (input) INTEGER
9793 * The number of columns of the matrix V. M >= 0.
9794 *
9795 * V (input/output) DOUBLE PRECISION array, dimension (LDV,M)
9796 * On entry, the matrix of right or left eigenvectors to be
9797 * transformed, as returned by DHSEIN or DTREVC.
9798 * On exit, V is overwritten by the transformed eigenvectors.
9799 *
9800 * LDV (input) INTEGER
9801 * The leading dimension of the array V. LDV >= max(1,N).
9802 *
9803 * INFO (output) INTEGER
9804 * = 0: successful exit
9805 * < 0: if INFO = -i, the i-th argument had an illegal value.
9806 *
9807 * =====================================================================
9808 *
9809 * .. Parameters ..
9810 DOUBLE PRECISION ONE
9811 PARAMETER ( ONE = 1.0D+0 )
9812 * ..
9813 * .. Local Scalars ..
9814 LOGICAL LEFTV, RIGHTV
9815 INTEGER I, II, K
9816 DOUBLE PRECISION S
9817 * ..
9818 * .. External Functions ..
9819 LOGICAL LSAME
9820 EXTERNAL LSAME
9821 * ..
9822 * .. External Subroutines ..
9823 EXTERNAL DSCAL, DSWAP, XERBLA
9824 * ..
9825 * .. Intrinsic Functions ..
9826 INTRINSIC MAX, MIN
9827 * ..
9828 * .. Executable Statements ..
9829 *
9830 * Decode and Test the input parameters
9831 *
9832 RIGHTV = LSAME( SIDE, 'R' )
9833 LEFTV = LSAME( SIDE, 'L' )
9834 *
9835 INFO = 0
9836 IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.LSAME( JOB, 'P' ) .AND.
9837 $ .NOT.LSAME( JOB, 'S' ) .AND. .NOT.LSAME( JOB, 'B' ) ) THEN
9838 INFO = -1
9839 ELSE IF( .NOT.RIGHTV .AND. .NOT.LEFTV ) THEN
9840 INFO = -2
9841 ELSE IF( N.LT.0 ) THEN
9842 INFO = -3
9843 ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN
9844 INFO = -4
9845 ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN
9846 INFO = -5
9847 ELSE IF( M.LT.0 ) THEN
9848 INFO = -7
9849 ELSE IF( LDV.LT.MAX( 1, N ) ) THEN
9850 INFO = -9
9851 END IF
9852 IF( INFO.NE.0 ) THEN
9853 CALL XERBLA( 'DGEBAK', -INFO )
9854 RETURN
9855 END IF
9856 *
9857 * Quick return if possible
9858 *
9859 IF( N.EQ.0 )
9860 $ RETURN
9861 IF( M.EQ.0 )
9862 $ RETURN
9863 IF( LSAME( JOB, 'N' ) )
9864 $ RETURN
9865 *
9866 IF( ILO.EQ.IHI )
9867 $ GO TO 30
9868 *
9869 * Backward balance
9870 *
9871 IF( LSAME( JOB, 'S' ) .OR. LSAME( JOB, 'B' ) ) THEN
9872 *
9873 IF( RIGHTV ) THEN
9874 DO 10 I = ILO, IHI
9875 S = SCALE( I )
9876 CALL DSCAL( M, S, V( I, 1 ), LDV )
9877 10 CONTINUE
9878 END IF
9879 *
9880 IF( LEFTV ) THEN
9881 DO 20 I = ILO, IHI
9882 S = ONE / SCALE( I )
9883 CALL DSCAL( M, S, V( I, 1 ), LDV )
9884 20 CONTINUE
9885 END IF
9886 *
9887 END IF
9888 *
9889 * Backward permutation
9890 *
9891 * For I = ILO-1 step -1 until 1,
9892 * IHI+1 step 1 until N do --
9893 *
9894 30 CONTINUE
9895 IF( LSAME( JOB, 'P' ) .OR. LSAME( JOB, 'B' ) ) THEN
9896 IF( RIGHTV ) THEN
9897 DO 40 II = 1, N
9898 I = II
9899 IF( I.GE.ILO .AND. I.LE.IHI )
9900 $ GO TO 40
9901 IF( I.LT.ILO )
9902 $ I = ILO - II
9903 K = SCALE( I )
9904 IF( K.EQ.I )
9905 $ GO TO 40
9906 CALL DSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV )
9907 40 CONTINUE
9908 END IF
9909 *
9910 IF( LEFTV ) THEN
9911 DO 50 II = 1, N
9912 I = II
9913 IF( I.GE.ILO .AND. I.LE.IHI )
9914 $ GO TO 50
9915 IF( I.LT.ILO )
9916 $ I = ILO - II
9917 K = SCALE( I )
9918 IF( K.EQ.I )
9919 $ GO TO 50
9920 CALL DSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV )
9921 50 CONTINUE
9922 END IF
9923 END IF
9924 *
9925 RETURN
9926 *
9927 * End of DGEBAK
9928 *
9929 END
9930 C
9931 C-----------------------------------------------------------------------
9932 C-----------------------------------------------------------------------
9933 SUBROUTINE DGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
9934 *
9935 * -- LAPACK routine (version 3.2.2) --
9936 * -- LAPACK is a software package provided by Univ. of Tennessee, --
9937 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
9938 * June 2010
9939 *
9940 * .. Scalar Arguments ..
9941 CHARACTER JOB
9942 INTEGER IHI, ILO, INFO, LDA, N
9943 * ..
9944 * .. Array Arguments ..
9945 DOUBLE PRECISION A( LDA, * ), SCALE( * )
9946 * ..
9947 *
9948 * Purpose
9949 * =======
9950 *
9951 * DGEBAL balances a general real matrix A. This involves, first,
9952 * permuting A by a similarity transformation to isolate eigenvalues
9953 * in the first 1 to ILO-1 and last IHI+1 to N elements on the
9954 * diagonal; and second, applying a diagonal similarity transformation
9955 * to rows and columns ILO to IHI to make the rows and columns as
9956 * close in norm as possible. Both steps are optional.
9957 *
9958 * Balancing may reduce the 1-norm of the matrix, and improve the
9959 * accuracy of the computed eigenvalues and/or eigenvectors.
9960 *
9961 * Arguments
9962 * =========
9963 *
9964 * JOB (input) CHARACTER*1
9965 * Specifies the operations to be performed on A:
9966 * = 'N': none: simply set ILO = 1, IHI = N, SCALE(I) = 1.0
9967 * for i = 1,...,N;
9968 * = 'P': permute only;
9969 * = 'S': scale only;
9970 * = 'B': both permute and scale.
9971 *
9972 * N (input) INTEGER
9973 * The order of the matrix A. N >= 0.
9974 *
9975 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
9976 * On entry, the input matrix A.
9977 * On exit, A is overwritten by the balanced matrix.
9978 * If JOB = 'N', A is not referenced.
9979 * See Further Details.
9980 *
9981 * LDA (input) INTEGER
9982 * The leading dimension of the array A. LDA >= max(1,N).
9983 *
9984 * ILO (output) INTEGER
9985 * IHI (output) INTEGER
9986 * ILO and IHI are set to integers such that on exit
9987 * A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N.
9988 * If JOB = 'N' or 'S', ILO = 1 and IHI = N.
9989 *
9990 * SCALE (output) DOUBLE PRECISION array, dimension (N)
9991 * Details of the permutations and scaling factors applied to
9992 * A. If P(j) is the index of the row and column interchanged
9993 * with row and column j and D(j) is the scaling factor
9994 * applied to row and column j, then
9995 * SCALE(j) = P(j) for j = 1,...,ILO-1
9996 * = D(j) for j = ILO,...,IHI
9997 * = P(j) for j = IHI+1,...,N.
9998 * The order in which the interchanges are made is N to IHI+1,
9999 * then 1 to ILO-1.
10000 *
10001 * INFO (output) INTEGER
10002 * = 0: successful exit.
10003 * < 0: if INFO = -i, the i-th argument had an illegal value.
10004 *
10005 * Further Details
10006 * ===============
10007 *
10008 * The permutations consist of row and column interchanges which put
10009 * the matrix in the form
10010 *
10011 * ( T1 X Y )
10012 * P A P = ( 0 B Z )
10013 * ( 0 0 T2 )
10014 *
10015 * where T1 and T2 are upper triangular matrices whose eigenvalues lie
10016 * along the diagonal. The column indices ILO and IHI mark the starting
10017 * and ending columns of the submatrix B. Balancing consists of applying
10018 * a diagonal similarity transformation inv(D) * B * D to make the
10019 * 1-norms of each row of B and its corresponding column nearly equal.
10020 * The output matrix is
10021 *
10022 * ( T1 X*D Y )
10023 * ( 0 inv(D)*B*D inv(D)*Z ).
10024 * ( 0 0 T2 )
10025 *
10026 * Information about the permutations P and the diagonal matrix D is
10027 * returned in the vector SCALE.
10028 *
10029 * This subroutine is based on the EISPACK routine BALANC.
10030 *
10031 * Modified by Tzu-Yi Chen, Computer Science Division, University of
10032 * California at Berkeley, USA
10033 *
10034 * =====================================================================
10035 *
10036 * .. Parameters ..
10037 DOUBLE PRECISION ZERO, ONE
10038 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
10039 DOUBLE PRECISION SCLFAC
10040 PARAMETER ( SCLFAC = 2.0D+0 )
10041 DOUBLE PRECISION FACTOR
10042 PARAMETER ( FACTOR = 0.95D+0 )
10043 * ..
10044 * .. Local Scalars ..
10045 LOGICAL NOCONV
10046 INTEGER I, ICA, IEXC, IRA, J, K, L, M
10047 DOUBLE PRECISION C, CA, F, G, R, RA, S, SFMAX1, SFMAX2, SFMIN1,
10048 $ SFMIN2
10049 * ..
10050 * .. External Functions ..
10051 LOGICAL DISNAN, LSAME
10052 INTEGER IDAMAX
10053 DOUBLE PRECISION DLAMCH
10054 EXTERNAL DISNAN, LSAME, IDAMAX, DLAMCH
10055 * ..
10056 * .. External Subroutines ..
10057 EXTERNAL DSCAL, DSWAP, XERBLA
10058 * ..
10059 * .. Intrinsic Functions ..
10060 INTRINSIC ABS, MAX, MIN
10061 * ..
10062 * .. Executable Statements ..
10063 *
10064 * Test the input parameters
10065 *
10066 INFO = 0
10067 IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.LSAME( JOB, 'P' ) .AND.
10068 $ .NOT.LSAME( JOB, 'S' ) .AND. .NOT.LSAME( JOB, 'B' ) ) THEN
10069 INFO = -1
10070 ELSE IF( N.LT.0 ) THEN
10071 INFO = -2
10072 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
10073 INFO = -4
10074 END IF
10075 IF( INFO.NE.0 ) THEN
10076 CALL XERBLA( 'DGEBAL', -INFO )
10077 RETURN
10078 END IF
10079 *
10080 K = 1
10081 L = N
10082 *
10083 IF( N.EQ.0 )
10084 $ GO TO 210
10085 *
10086 IF( LSAME( JOB, 'N' ) ) THEN
10087 DO 10 I = 1, N
10088 SCALE( I ) = ONE
10089 10 CONTINUE
10090 GO TO 210
10091 END IF
10092 *
10093 IF( LSAME( JOB, 'S' ) )
10094 $ GO TO 120
10095 *
10096 * Permutation to isolate eigenvalues if possible
10097 *
10098 GO TO 50
10099 *
10100 * Row and column exchange.
10101 *
10102 20 CONTINUE
10103 SCALE( M ) = J
10104 IF( J.EQ.M )
10105 $ GO TO 30
10106 *
10107 CALL DSWAP( L, A( 1, J ), 1, A( 1, M ), 1 )
10108 CALL DSWAP( N-K+1, A( J, K ), LDA, A( M, K ), LDA )
10109 *
10110 30 CONTINUE
10111 GO TO ( 40, 80 )IEXC
10112 *
10113 * Search for rows isolating an eigenvalue and push them down.
10114 *
10115 40 CONTINUE
10116 IF( L.EQ.1 )
10117 $ GO TO 210
10118 L = L - 1
10119 *
10120 50 CONTINUE
10121 DO 70 J = L, 1, -1
10122 *
10123 DO 60 I = 1, L
10124 IF( I.EQ.J )
10125 $ GO TO 60
10126 IF( A( J, I ).NE.ZERO )
10127 $ GO TO 70
10128 60 CONTINUE
10129 *
10130 M = L
10131 IEXC = 1
10132 GO TO 20
10133 70 CONTINUE
10134 *
10135 GO TO 90
10136 *
10137 * Search for columns isolating an eigenvalue and push them left.
10138 *
10139 80 CONTINUE
10140 K = K + 1
10141 *
10142 90 CONTINUE
10143 DO 110 J = K, L
10144 *
10145 DO 100 I = K, L
10146 IF( I.EQ.J )
10147 $ GO TO 100
10148 IF( A( I, J ).NE.ZERO )
10149 $ GO TO 110
10150 100 CONTINUE
10151 *
10152 M = K
10153 IEXC = 2
10154 GO TO 20
10155 110 CONTINUE
10156 *
10157 120 CONTINUE
10158 DO 130 I = K, L
10159 SCALE( I ) = ONE
10160 130 CONTINUE
10161 *
10162 IF( LSAME( JOB, 'P' ) )
10163 $ GO TO 210
10164 *
10165 * Balance the submatrix in rows K to L.
10166 *
10167 * Iterative loop for norm reduction
10168 *
10169 SFMIN1 = DLAMCH( 'S' ) / DLAMCH( 'P' )
10170 SFMAX1 = ONE / SFMIN1
10171 SFMIN2 = SFMIN1*SCLFAC
10172 SFMAX2 = ONE / SFMIN2
10173 140 CONTINUE
10174 NOCONV = .FALSE.
10175 *
10176 DO 200 I = K, L
10177 C = ZERO
10178 R = ZERO
10179 *
10180 DO 150 J = K, L
10181 IF( J.EQ.I )
10182 $ GO TO 150
10183 C = C + ABS( A( J, I ) )
10184 R = R + ABS( A( I, J ) )
10185 150 CONTINUE
10186 ICA = IDAMAX( L, A( 1, I ), 1 )
10187 CA = ABS( A( ICA, I ) )
10188 IRA = IDAMAX( N-K+1, A( I, K ), LDA )
10189 RA = ABS( A( I, IRA+K-1 ) )
10190 *
10191 * Guard against zero C or R due to underflow.
10192 *
10193 IF( C.EQ.ZERO .OR. R.EQ.ZERO )
10194 $ GO TO 200
10195 G = R / SCLFAC
10196 F = ONE
10197 S = C + R
10198 160 CONTINUE
10199 IF( C.GE.G .OR. MAX( F, C, CA ).GE.SFMAX2 .OR.
10200 $ MIN( R, G, RA ).LE.SFMIN2 )GO TO 170
10201 IF( DISNAN( C+F+CA+R+G+RA ) ) THEN
10202 *
10203 * Exit if NaN to avoid infinite loop
10204 *
10205 INFO = -3
10206 CALL XERBLA( 'DGEBAL', -INFO )
10207 RETURN
10208 END IF
10209 F = F*SCLFAC
10210 C = C*SCLFAC
10211 CA = CA*SCLFAC
10212 R = R / SCLFAC
10213 G = G / SCLFAC
10214 RA = RA / SCLFAC
10215 GO TO 160
10216 *
10217 170 CONTINUE
10218 G = C / SCLFAC
10219 180 CONTINUE
10220 IF( G.LT.R .OR. MAX( R, RA ).GE.SFMAX2 .OR.
10221 $ MIN( F, C, G, CA ).LE.SFMIN2 )GO TO 190
10222 F = F / SCLFAC
10223 C = C / SCLFAC
10224 G = G / SCLFAC
10225 CA = CA / SCLFAC
10226 R = R*SCLFAC
10227 RA = RA*SCLFAC
10228 GO TO 180
10229 *
10230 * Now balance.
10231 *
10232 190 CONTINUE
10233 IF( ( C+R ).GE.FACTOR*S )
10234 $ GO TO 200
10235 IF( F.LT.ONE .AND. SCALE( I ).LT.ONE ) THEN
10236 IF( F*SCALE( I ).LE.SFMIN1 )
10237 $ GO TO 200
10238 END IF
10239 IF( F.GT.ONE .AND. SCALE( I ).GT.ONE ) THEN
10240 IF( SCALE( I ).GE.SFMAX1 / F )
10241 $ GO TO 200
10242 END IF
10243 G = ONE / F
10244 SCALE( I ) = SCALE( I )*F
10245 NOCONV = .TRUE.
10246 *
10247 CALL DSCAL( N-K+1, G, A( I, K ), LDA )
10248 CALL DSCAL( L, F, A( 1, I ), 1 )
10249 *
10250 200 CONTINUE
10251 *
10252 IF( NOCONV )
10253 $ GO TO 140
10254 *
10255 210 CONTINUE
10256 ILO = K
10257 IHI = L
10258 *
10259 RETURN
10260 *
10261 * End of DGEBAL
10262 *
10263 END
10264 C
10265 C-----------------------------------------------------------------------
10266 C-----------------------------------------------------------------------
10267 SUBROUTINE DGEHD2( N, ILO, IHI, A, LDA, TAU, WORK, INFO )
10268 *
10269 * -- LAPACK routine (version 3.2) --
10270 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
10271 * November 2006
10272 *
10273 * .. Scalar Arguments ..
10274 INTEGER IHI, ILO, INFO, LDA, N
10275 * ..
10276 * .. Array Arguments ..
10277 DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
10278 * ..
10279 *
10280 * Purpose
10281 * =======
10282 *
10283 * DGEHD2 reduces a real general matrix A to upper Hessenberg form H by
10284 * an orthogonal similarity transformation: Q' * A * Q = H .
10285 *
10286 * Arguments
10287 * =========
10288 *
10289 * N (input) INTEGER
10290 * The order of the matrix A. N >= 0.
10291 *
10292 * ILO (input) INTEGER
10293 * IHI (input) INTEGER
10294 * It is assumed that A is already upper triangular in rows
10295 * and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
10296 * set by a previous call to DGEBAL; otherwise they should be
10297 * set to 1 and N respectively. See Further Details.
10298 * 1 <= ILO <= IHI <= max(1,N).
10299 *
10300 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
10301 * On entry, the n by n general matrix to be reduced.
10302 * On exit, the upper triangle and the first subdiagonal of A
10303 * are overwritten with the upper Hessenberg matrix H, and the
10304 * elements below the first subdiagonal, with the array TAU,
10305 * represent the orthogonal matrix Q as a product of elementary
10306 * reflectors. See Further Details.
10307 *
10308 * LDA (input) INTEGER
10309 * The leading dimension of the array A. LDA >= max(1,N).
10310 *
10311 * TAU (output) DOUBLE PRECISION array, dimension (N-1)
10312 * The scalar factors of the elementary reflectors (see Further
10313 * Details).
10314 *
10315 * WORK (workspace) DOUBLE PRECISION array, dimension (N)
10316 *
10317 * INFO (output) INTEGER
10318 * = 0: successful exit.
10319 * < 0: if INFO = -i, the i-th argument had an illegal value.
10320 *
10321 * Further Details
10322 * ===============
10323 *
10324 * The matrix Q is represented as a product of (ihi-ilo) elementary
10325 * reflectors
10326 *
10327 * Q = H(ilo) H(ilo+1) . . . H(ihi-1).
10328 *
10329 * Each H(i) has the form
10330 *
10331 * H(i) = I - tau * v * v'
10332 *
10333 * where tau is a real scalar, and v is a real vector with
10334 * v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on
10335 * exit in A(i+2:ihi,i), and tau in TAU(i).
10336 *
10337 * The contents of A are illustrated by the following example, with
10338 * n = 7, ilo = 2 and ihi = 6:
10339 *
10340 * on entry, on exit,
10341 *
10342 * ( a a a a a a a ) ( a a h h h h a )
10343 * ( a a a a a a ) ( a h h h h a )
10344 * ( a a a a a a ) ( h h h h h h )
10345 * ( a a a a a a ) ( v2 h h h h h )
10346 * ( a a a a a a ) ( v2 v3 h h h h )
10347 * ( a a a a a a ) ( v2 v3 v4 h h h )
10348 * ( a ) ( a )
10349 *
10350 * where a denotes an element of the original matrix A, h denotes a
10351 * modified element of the upper Hessenberg matrix H, and vi denotes an
10352 * element of the vector defining H(i).
10353 *
10354 * =====================================================================
10355 *
10356 * .. Parameters ..
10357 DOUBLE PRECISION ONE
10358 PARAMETER ( ONE = 1.0D+0 )
10359 * ..
10360 * .. Local Scalars ..
10361 INTEGER I
10362 DOUBLE PRECISION AII
10363 * ..
10364 * .. External Subroutines ..
10365 EXTERNAL DLARF, DLARFG, XERBLA
10366 * ..
10367 * .. Intrinsic Functions ..
10368 INTRINSIC MAX, MIN
10369 * ..
10370 * .. Executable Statements ..
10371 *
10372 * Test the input parameters
10373 *
10374 INFO = 0
10375 IF( N.LT.0 ) THEN
10376 INFO = -1
10377 ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN
10378 INFO = -2
10379 ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN
10380 INFO = -3
10381 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
10382 INFO = -5
10383 END IF
10384 IF( INFO.NE.0 ) THEN
10385 CALL XERBLA( 'DGEHD2', -INFO )
10386 RETURN
10387 END IF
10388 *
10389 DO 10 I = ILO, IHI - 1
10390 *
10391 * Compute elementary reflector H(i) to annihilate A(i+2:ihi,i)
10392 *
10393 CALL DLARFG( IHI-I, A( I+1, I ), A( MIN( I+2, N ), I ), 1,
10394 $ TAU( I ) )
10395 AII = A( I+1, I )
10396 A( I+1, I ) = ONE
10397 *
10398 * Apply H(i) to A(1:ihi,i+1:ihi) from the right
10399 *
10400 CALL DLARF( 'Right', IHI, IHI-I, A( I+1, I ), 1, TAU( I ),
10401 $ A( 1, I+1 ), LDA, WORK )
10402 *
10403 * Apply H(i) to A(i+1:ihi,i+1:n) from the left
10404 *
10405 CALL DLARF( 'Left', IHI-I, N-I, A( I+1, I ), 1, TAU( I ),
10406 $ A( I+1, I+1 ), LDA, WORK )
10407 *
10408 A( I+1, I ) = AII
10409 10 CONTINUE
10410 *
10411 RETURN
10412 *
10413 * End of DGEHD2
10414 *
10415 END
10416 C
10417 C-----------------------------------------------------------------------
10418 C-----------------------------------------------------------------------
10419 SUBROUTINE DGEHRD( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO )
10420 *
10421 * -- LAPACK routine (version 3.2.1) --
10422 * -- LAPACK is a software package provided by Univ. of Tennessee, --
10423 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
10424 * -- April 2009 --
10425 *
10426 * .. Scalar Arguments ..
10427 INTEGER IHI, ILO, INFO, LDA, LWORK, N
10428 * ..
10429 * .. Array Arguments ..
10430 DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
10431 * ..
10432 *
10433 * Purpose
10434 * =======
10435 *
10436 * DGEHRD reduces a real general matrix A to upper Hessenberg form H by
10437 * an orthogonal similarity transformation: Q' * A * Q = H .
10438 *
10439 * Arguments
10440 * =========
10441 *
10442 * N (input) INTEGER
10443 * The order of the matrix A. N >= 0.
10444 *
10445 * ILO (input) INTEGER
10446 * IHI (input) INTEGER
10447 * It is assumed that A is already upper triangular in rows
10448 * and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
10449 * set by a previous call to DGEBAL; otherwise they should be
10450 * set to 1 and N respectively. See Further Details.
10451 * 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
10452 *
10453 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
10454 * On entry, the N-by-N general matrix to be reduced.
10455 * On exit, the upper triangle and the first subdiagonal of A
10456 * are overwritten with the upper Hessenberg matrix H, and the
10457 * elements below the first subdiagonal, with the array TAU,
10458 * represent the orthogonal matrix Q as a product of elementary
10459 * reflectors. See Further Details.
10460 *
10461 * LDA (input) INTEGER
10462 * The leading dimension of the array A. LDA >= max(1,N).
10463 *
10464 * TAU (output) DOUBLE PRECISION array, dimension (N-1)
10465 * The scalar factors of the elementary reflectors (see Further
10466 * Details). Elements 1:ILO-1 and IHI:N-1 of TAU are set to
10467 * zero.
10468 *
10469 * WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
10470 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
10471 *
10472 * LWORK (input) INTEGER
10473 * The length of the array WORK. LWORK >= max(1,N).
10474 * For optimum performance LWORK >= N*NB, where NB is the
10475 * optimal blocksize.
10476 *
10477 * If LWORK = -1, then a workspace query is assumed; the routine
10478 * only calculates the optimal size of the WORK array, returns
10479 * this value as the first entry of the WORK array, and no error
10480 * message related to LWORK is issued by XERBLA.
10481 *
10482 * INFO (output) INTEGER
10483 * = 0: successful exit
10484 * < 0: if INFO = -i, the i-th argument had an illegal value.
10485 *
10486 * Further Details
10487 * ===============
10488 *
10489 * The matrix Q is represented as a product of (ihi-ilo) elementary
10490 * reflectors
10491 *
10492 * Q = H(ilo) H(ilo+1) . . . H(ihi-1).
10493 *
10494 * Each H(i) has the form
10495 *
10496 * H(i) = I - tau * v * v'
10497 *
10498 * where tau is a real scalar, and v is a real vector with
10499 * v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on
10500 * exit in A(i+2:ihi,i), and tau in TAU(i).
10501 *
10502 * The contents of A are illustrated by the following example, with
10503 * n = 7, ilo = 2 and ihi = 6:
10504 *
10505 * on entry, on exit,
10506 *
10507 * ( a a a a a a a ) ( a a h h h h a )
10508 * ( a a a a a a ) ( a h h h h a )
10509 * ( a a a a a a ) ( h h h h h h )
10510 * ( a a a a a a ) ( v2 h h h h h )
10511 * ( a a a a a a ) ( v2 v3 h h h h )
10512 * ( a a a a a a ) ( v2 v3 v4 h h h )
10513 * ( a ) ( a )
10514 *
10515 * where a denotes an element of the original matrix A, h denotes a
10516 * modified element of the upper Hessenberg matrix H, and vi denotes an
10517 * element of the vector defining H(i).
10518 *
10519 * This file is a slight modification of LAPACK-3.0's DGEHRD
10520 * subroutine incorporating improvements proposed by Quintana-Orti and
10521 * Van de Geijn (2006). (See DLAHR2.)
10522 *
10523 * =====================================================================
10524 *
10525 * .. Parameters ..
10526 INTEGER NBMAX, LDT
10527 PARAMETER ( NBMAX = 64, LDT = NBMAX+1 )
10528 DOUBLE PRECISION ZERO, ONE
10529 PARAMETER ( ZERO = 0.0D+0,
10530 $ ONE = 1.0D+0 )
10531 * ..
10532 * .. Local Scalars ..
10533 LOGICAL LQUERY
10534 INTEGER I, IB, IINFO, IWS, J, LDWORK, LWKOPT, NB,
10535 $ NBMIN, NH, NX
10536 DOUBLE PRECISION EI
10537 * ..
10538 * .. Local Arrays ..
10539 DOUBLE PRECISION T( LDT, NBMAX )
10540 * ..
10541 * .. External Subroutines ..
10542 EXTERNAL DAXPY, DGEHD2, DGEMM, DLAHR2, DLARFB, DTRMM,
10543 $ XERBLA
10544 * ..
10545 * .. Intrinsic Functions ..
10546 INTRINSIC MAX, MIN
10547 * ..
10548 * .. External Functions ..
10549 INTEGER ILAENV
10550 EXTERNAL ILAENV
10551 * ..
10552 * .. Executable Statements ..
10553 *
10554 * Test the input parameters
10555 *
10556 INFO = 0
10557 NB = MIN( NBMAX, ILAENV( 1, 'DGEHRD', ' ', N, ILO, IHI, -1 ) )
10558 LWKOPT = N*NB
10559 WORK( 1 ) = LWKOPT
10560 LQUERY = ( LWORK.EQ.-1 )
10561 IF( N.LT.0 ) THEN
10562 INFO = -1
10563 ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN
10564 INFO = -2
10565 ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN
10566 INFO = -3
10567 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
10568 INFO = -5
10569 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
10570 INFO = -8
10571 END IF
10572 IF( INFO.NE.0 ) THEN
10573 CALL XERBLA( 'DGEHRD', -INFO )
10574 RETURN
10575 ELSE IF( LQUERY ) THEN
10576 RETURN
10577 END IF
10578 *
10579 * Set elements 1:ILO-1 and IHI:N-1 of TAU to zero
10580 *
10581 DO 10 I = 1, ILO - 1
10582 TAU( I ) = ZERO
10583 10 CONTINUE
10584 DO 20 I = MAX( 1, IHI ), N - 1
10585 TAU( I ) = ZERO
10586 20 CONTINUE
10587 *
10588 * Quick return if possible
10589 *
10590 NH = IHI - ILO + 1
10591 IF( NH.LE.1 ) THEN
10592 WORK( 1 ) = 1
10593 RETURN
10594 END IF
10595 *
10596 * Determine the block size
10597 *
10598 NB = MIN( NBMAX, ILAENV( 1, 'DGEHRD', ' ', N, ILO, IHI, -1 ) )
10599 NBMIN = 2
10600 IWS = 1
10601 IF( NB.GT.1 .AND. NB.LT.NH ) THEN
10602 *
10603 * Determine when to cross over from blocked to unblocked code
10604 * (last block is always handled by unblocked code)
10605 *
10606 NX = MAX( NB, ILAENV( 3, 'DGEHRD', ' ', N, ILO, IHI, -1 ) )
10607 IF( NX.LT.NH ) THEN
10608 *
10609 * Determine if workspace is large enough for blocked code
10610 *
10611 IWS = N*NB
10612 IF( LWORK.LT.IWS ) THEN
10613 *
10614 * Not enough workspace to use optimal NB: determine the
10615 * minimum value of NB, and reduce NB or force use of
10616 * unblocked code
10617 *
10618 NBMIN = MAX( 2, ILAENV( 2, 'DGEHRD', ' ', N, ILO, IHI,
10619 $ -1 ) )
10620 IF( LWORK.GE.N*NBMIN ) THEN
10621 NB = LWORK / N
10622 ELSE
10623 NB = 1
10624 END IF
10625 END IF
10626 END IF
10627 END IF
10628 LDWORK = N
10629 *
10630 IF( NB.LT.NBMIN .OR. NB.GE.NH ) THEN
10631 *
10632 * Use unblocked code below
10633 *
10634 I = ILO
10635 *
10636 ELSE
10637 *
10638 * Use blocked code
10639 *
10640 DO 40 I = ILO, IHI - 1 - NX, NB
10641 IB = MIN( NB, IHI-I )
10642 *
10643 * Reduce columns i:i+ib-1 to Hessenberg form, returning the
10644 * matrices V and T of the block reflector H = I - V*T*V'
10645 * which performs the reduction, and also the matrix Y = A*V*T
10646 *
10647 CALL DLAHR2( IHI, I, IB, A( 1, I ), LDA, TAU( I ), T, LDT,
10648 $ WORK, LDWORK )
10649 *
10650 * Apply the block reflector H to A(1:ihi,i+ib:ihi) from the
10651 * right, computing A := A - Y * V'. V(i+ib,ib-1) must be set
10652 * to 1
10653 *
10654 EI = A( I+IB, I+IB-1 )
10655 A( I+IB, I+IB-1 ) = ONE
10656 CALL DGEMM( 'No transpose', 'Transpose',
10657 $ IHI, IHI-I-IB+1,
10658 $ IB, -ONE, WORK, LDWORK, A( I+IB, I ), LDA, ONE,
10659 $ A( 1, I+IB ), LDA )
10660 A( I+IB, I+IB-1 ) = EI
10661 *
10662 * Apply the block reflector H to A(1:i,i+1:i+ib-1) from the
10663 * right
10664 *
10665 CALL DTRMM( 'Right', 'Lower', 'Transpose',
10666 $ 'Unit', I, IB-1,
10667 $ ONE, A( I+1, I ), LDA, WORK, LDWORK )
10668 DO 30 J = 0, IB-2
10669 CALL DAXPY( I, -ONE, WORK( LDWORK*J+1 ), 1,
10670 $ A( 1, I+J+1 ), 1 )
10671 30 CONTINUE
10672 *
10673 * Apply the block reflector H to A(i+1:ihi,i+ib:n) from the
10674 * left
10675 *
10676 CALL DLARFB( 'Left', 'Transpose', 'Forward',
10677 $ 'Columnwise',
10678 $ IHI-I, N-I-IB+1, IB, A( I+1, I ), LDA, T, LDT,
10679 $ A( I+1, I+IB ), LDA, WORK, LDWORK )
10680 40 CONTINUE
10681 END IF
10682 *
10683 * Use unblocked code to reduce the rest of the matrix
10684 *
10685 CALL DGEHD2( N, I, IHI, A, LDA, TAU, WORK, IINFO )
10686 WORK( 1 ) = IWS
10687 *
10688 RETURN
10689 *
10690 * End of DGEHRD
10691 *
10692 END
10693 C
10694 C-----------------------------------------------------------------------
10695 C-----------------------------------------------------------------------
10696 SUBROUTINE DHSEQR( JOB, COMPZ, N, ILO, IHI, H, LDH, WR, WI, Z,
10697 $ LDZ, WORK, LWORK, INFO )
10698 *
10699 * -- LAPACK computational routine (version 3.2.2) --
10700 * Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
10701 * June 2010
10702 *
10703 * .. Scalar Arguments ..
10704 INTEGER IHI, ILO, INFO, LDH, LDZ, LWORK, N
10705 CHARACTER COMPZ, JOB
10706 * ..
10707 * .. Array Arguments ..
10708 DOUBLE PRECISION H( LDH, * ), WI( * ), WORK( * ), WR( * ),
10709 $ Z( LDZ, * )
10710 * ..
10711 * Purpose
10712 * =======
10713 *
10714 * DHSEQR computes the eigenvalues of a Hessenberg matrix H
10715 * and, optionally, the matrices T and Z from the Schur decomposition
10716 * H = Z T Z**T, where T is an upper quasi-triangular matrix (the
10717 * Schur form), and Z is the orthogonal matrix of Schur vectors.
10718 *
10719 * Optionally Z may be postmultiplied into an input orthogonal
10720 * matrix Q so that this routine can give the Schur factorization
10721 * of a matrix A which has been reduced to the Hessenberg form H
10722 * by the orthogonal matrix Q: A = Q*H*Q**T = (QZ)*T*(QZ)**T.
10723 *
10724 * Arguments
10725 * =========
10726 *
10727 * JOB (input) CHARACTER*1
10728 * = 'E': compute eigenvalues only;
10729 * = 'S': compute eigenvalues and the Schur form T.
10730 *
10731 * COMPZ (input) CHARACTER*1
10732 * = 'N': no Schur vectors are computed;
10733 * = 'I': Z is initialized to the unit matrix and the matrix Z
10734 * of Schur vectors of H is returned;
10735 * = 'V': Z must contain an orthogonal matrix Q on entry, and
10736 * the product Q*Z is returned.
10737 *
10738 * N (input) INTEGER
10739 * The order of the matrix H. N .GE. 0.
10740 *
10741 * ILO (input) INTEGER
10742 * IHI (input) INTEGER
10743 * It is assumed that H is already upper triangular in rows
10744 * and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
10745 * set by a previous call to DGEBAL, and then passed to DGEHRD
10746 * when the matrix output by DGEBAL is reduced to Hessenberg
10747 * form. Otherwise ILO and IHI should be set to 1 and N
10748 * respectively. If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N.
10749 * If N = 0, then ILO = 1 and IHI = 0.
10750 *
10751 * H (input/output) DOUBLE PRECISION array, dimension (LDH,N)
10752 * On entry, the upper Hessenberg matrix H.
10753 * On exit, if INFO = 0 and JOB = 'S', then H contains the
10754 * upper quasi-triangular matrix T from the Schur decomposition
10755 * (the Schur form); 2-by-2 diagonal blocks (corresponding to
10756 * complex conjugate pairs of eigenvalues) are returned in
10757 * standard form, with H(i,i) = H(i+1,i+1) and
10758 * H(i+1,i)*H(i,i+1).LT.0. If INFO = 0 and JOB = 'E', the
10759 * contents of H are unspecified on exit. (The output value of
10760 * H when INFO.GT.0 is given under the description of INFO
10761 * below.)
10762 *
10763 * Unlike earlier versions of DHSEQR, this subroutine may
10764 * explicitly H(i,j) = 0 for i.GT.j and j = 1, 2, ... ILO-1
10765 * or j = IHI+1, IHI+2, ... N.
10766 *
10767 * LDH (input) INTEGER
10768 * The leading dimension of the array H. LDH .GE. max(1,N).
10769 *
10770 * WR (output) DOUBLE PRECISION array, dimension (N)
10771 * WI (output) DOUBLE PRECISION array, dimension (N)
10772 * The real and imaginary parts, respectively, of the computed
10773 * eigenvalues. If two eigenvalues are computed as a complex
10774 * conjugate pair, they are stored in consecutive elements of
10775 * WR and WI, say the i-th and (i+1)th, with WI(i) .GT. 0 and
10776 * WI(i+1) .LT. 0. If JOB = 'S', the eigenvalues are stored in
10777 * the same order as on the diagonal of the Schur form returned
10778 * in H, with WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2
10779 * diagonal block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and
10780 * WI(i+1) = -WI(i).
10781 *
10782 * Z (input/output) DOUBLE PRECISION array, dimension (LDZ,N)
10783 * If COMPZ = 'N', Z is not referenced.
10784 * If COMPZ = 'I', on entry Z need not be set and on exit,
10785 * if INFO = 0, Z contains the orthogonal matrix Z of the Schur
10786 * vectors of H. If COMPZ = 'V', on entry Z must contain an
10787 * N-by-N matrix Q, which is assumed to be equal to the unit
10788 * matrix except for the submatrix Z(ILO:IHI,ILO:IHI). On exit,
10789 * if INFO = 0, Z contains Q*Z.
10790 * Normally Q is the orthogonal matrix generated by DORGHR
10791 * after the call to DGEHRD which formed the Hessenberg matrix
10792 * H. (The output value of Z when INFO.GT.0 is given under
10793 * the description of INFO below.)
10794 *
10795 * LDZ (input) INTEGER
10796 * The leading dimension of the array Z. if COMPZ = 'I' or
10797 * COMPZ = 'V', then LDZ.GE.MAX(1,N). Otherwize, LDZ.GE.1.
10798 *
10799 * WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
10800 * On exit, if INFO = 0, WORK(1) returns an estimate of
10801 * the optimal value for LWORK.
10802 *
10803 * LWORK (input) INTEGER
10804 * The dimension of the array WORK. LWORK .GE. max(1,N)
10805 * is sufficient and delivers very good and sometimes
10806 * optimal performance. However, LWORK as large as 11*N
10807 * may be required for optimal performance. A workspace
10808 * query is recommended to determine the optimal workspace
10809 * size.
10810 *
10811 * If LWORK = -1, then DHSEQR does a workspace query.
10812 * In this case, DHSEQR checks the input parameters and
10813 * estimates the optimal workspace size for the given
10814 * values of N, ILO and IHI. The estimate is returned
10815 * in WORK(1). No error message related to LWORK is
10816 * issued by XERBLA. Neither H nor Z are accessed.
10817 *
10818 *
10819 * INFO (output) INTEGER
10820 * = 0: successful exit
10821 * .LT. 0: if INFO = -i, the i-th argument had an illegal
10822 * value
10823 * .GT. 0: if INFO = i, DHSEQR failed to compute all of
10824 * the eigenvalues. Elements 1:ilo-1 and i+1:n of WR
10825 * and WI contain those eigenvalues which have been
10826 * successfully computed. (Failures are rare.)
10827 *
10828 * If INFO .GT. 0 and JOB = 'E', then on exit, the
10829 * remaining unconverged eigenvalues are the eigen-
10830 * values of the upper Hessenberg matrix rows and
10831 * columns ILO through INFO of the final, output
10832 * value of H.
10833 *
10834 * If INFO .GT. 0 and JOB = 'S', then on exit
10835 *
10836 * (*) (initial value of H)*U = U*(final value of H)
10837 *
10838 * where U is an orthogonal matrix. The final
10839 * value of H is upper Hessenberg and quasi-triangular
10840 * in rows and columns INFO+1 through IHI.
10841 *
10842 * If INFO .GT. 0 and COMPZ = 'V', then on exit
10843 *
10844 * (final value of Z) = (initial value of Z)*U
10845 *
10846 * where U is the orthogonal matrix in (*) (regard-
10847 * less of the value of JOB.)
10848 *
10849 * If INFO .GT. 0 and COMPZ = 'I', then on exit
10850 * (final value of Z) = U
10851 * where U is the orthogonal matrix in (*) (regard-
10852 * less of the value of JOB.)
10853 *
10854 * If INFO .GT. 0 and COMPZ = 'N', then Z is not
10855 * accessed.
10856 *
10857 * ================================================================
10858 * Default values supplied by
10859 * ILAENV(ISPEC,'DHSEQR',JOB(:1)//COMPZ(:1),N,ILO,IHI,LWORK).
10860 * It is suggested that these defaults be adjusted in order
10861 * to attain best performance in each particular
10862 * computational environment.
10863 *
10864 * ISPEC=12: The DLAHQR vs DLAQR0 crossover point.
10865 * Default: 75. (Must be at least 11.)
10866 *
10867 * ISPEC=13: Recommended deflation window size.
10868 * This depends on ILO, IHI and NS. NS is the
10869 * number of simultaneous shifts returned
10870 * by ILAENV(ISPEC=15). (See ISPEC=15 below.)
10871 * The default for (IHI-ILO+1).LE.500 is NS.
10872 * The default for (IHI-ILO+1).GT.500 is 3*NS/2.
10873 *
10874 * ISPEC=14: Nibble crossover point. (See IPARMQ for
10875 * details.) Default: 14% of deflation window
10876 * size.
10877 *
10878 * ISPEC=15: Number of simultaneous shifts in a multishift
10879 * QR iteration.
10880 *
10881 * If IHI-ILO+1 is ...
10882 *
10883 * greater than ...but less ... the
10884 * or equal to ... than default is
10885 *
10886 * 1 30 NS = 2(+)
10887 * 30 60 NS = 4(+)
10888 * 60 150 NS = 10(+)
10889 * 150 590 NS = **
10890 * 590 3000 NS = 64
10891 * 3000 6000 NS = 128
10892 * 6000 infinity NS = 256
10893 *
10894 * (+) By default some or all matrices of this order
10895 * are passed to the implicit double shift routine
10896 * DLAHQR and this parameter is ignored. See
10897 * ISPEC=12 above and comments in IPARMQ for
10898 * details.
10899 *
10900 * (**) The asterisks (**) indicate an ad-hoc
10901 * function of N increasing from 10 to 64.
10902 *
10903 * ISPEC=16: Select structured matrix multiply.
10904 * If the number of simultaneous shifts (specified
10905 * by ISPEC=15) is less than 14, then the default
10906 * for ISPEC=16 is 0. Otherwise the default for
10907 * ISPEC=16 is 2.
10908 *
10909 * ================================================================
10910 * Based on contributions by
10911 * Karen Braman and Ralph Byers, Department of Mathematics,
10912 * University of Kansas, USA
10913 *
10914 * ================================================================
10915 * References:
10916 * K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
10917 * Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
10918 * Performance, SIAM Journal of Matrix Analysis, volume 23, pages
10919 * 929--947, 2002.
10920 *
10921 * K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
10922 * Algorithm Part II: Aggressive Early Deflation, SIAM Journal
10923 * of Matrix Analysis, volume 23, pages 948--973, 2002.
10924 *
10925 * ================================================================
10926 * .. Parameters ..
10927 *
10928 * ==== Matrices of order NTINY or smaller must be processed by
10929 * . DLAHQR because of insufficient subdiagonal scratch space.
10930 * . (This is a hard limit.) ====
10931 INTEGER NTINY
10932 PARAMETER ( NTINY = 11 )
10933 *
10934 * ==== NL allocates some local workspace to help small matrices
10935 * . through a rare DLAHQR failure. NL .GT. NTINY = 11 is
10936 * . required and NL .LE. NMIN = ILAENV(ISPEC=12,...) is recom-
10937 * . mended. (The default value of NMIN is 75.) Using NL = 49
10938 * . allows up to six simultaneous shifts and a 16-by-16
10939 * . deflation window. ====
10940 INTEGER NL
10941 PARAMETER ( NL = 49 )
10942 DOUBLE PRECISION ZERO, ONE
10943 PARAMETER ( ZERO = 0.0d0, ONE = 1.0d0 )
10944 * ..
10945 * .. Local Arrays ..
10946 DOUBLE PRECISION HL( NL, NL ), WORKL( NL )
10947 * ..
10948 * .. Local Scalars ..
10949 INTEGER I, KBOT, NMIN
10950 LOGICAL INITZ, LQUERY, WANTT, WANTZ
10951 * ..
10952 * .. External Functions ..
10953 INTEGER ILAENV
10954 LOGICAL LSAME
10955 EXTERNAL ILAENV, LSAME
10956 * ..
10957 * .. External Subroutines ..
10958 EXTERNAL DLACPY, DLAHQR, DLAQR0, DLASET, XERBLA
10959 * ..
10960 * .. Intrinsic Functions ..
10961 INTRINSIC DBLE, MAX, MIN
10962 * ..
10963 * .. Executable Statements ..
10964 *
10965 * ==== Decode and check the input parameters. ====
10966 *
10967 WANTT = LSAME( JOB, 'S' )
10968 INITZ = LSAME( COMPZ, 'I' )
10969 WANTZ = INITZ .OR. LSAME( COMPZ, 'V' )
10970 WORK( 1 ) = DBLE( MAX( 1, N ) )
10971 LQUERY = LWORK.EQ.-1
10972 *
10973 INFO = 0
10974 IF( .NOT.LSAME( JOB, 'E' ) .AND. .NOT.WANTT ) THEN
10975 INFO = -1
10976 ELSE IF( .NOT.LSAME( COMPZ, 'N' ) .AND. .NOT.WANTZ ) THEN
10977 INFO = -2
10978 ELSE IF( N.LT.0 ) THEN
10979 INFO = -3
10980 ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN
10981 INFO = -4
10982 ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN
10983 INFO = -5
10984 ELSE IF( LDH.LT.MAX( 1, N ) ) THEN
10985 INFO = -7
10986 ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.MAX( 1, N ) ) ) THEN
10987 INFO = -11
10988 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
10989 INFO = -13
10990 END IF
10991 *
10992 IF( INFO.NE.0 ) THEN
10993 *
10994 * ==== Quick return in case of invalid argument. ====
10995 *
10996 CALL XERBLA( 'DHSEQR', -INFO )
10997 RETURN
10998 *
10999 ELSE IF( N.EQ.0 ) THEN
11000 *
11001 * ==== Quick return in case N = 0; nothing to do. ====
11002 *
11003 RETURN
11004 *
11005 ELSE IF( LQUERY ) THEN
11006 *
11007 * ==== Quick return in case of a workspace query ====
11008 *
11009 CALL DLAQR0( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI, ILO,
11010 $ IHI, Z, LDZ, WORK, LWORK, INFO )
11011 * ==== Ensure reported workspace size is backward-compatible with
11012 * . previous LAPACK versions. ====
11013 WORK( 1 ) = MAX( DBLE( MAX( 1, N ) ), WORK( 1 ) )
11014 RETURN
11015 *
11016 ELSE
11017 *
11018 * ==== copy eigenvalues isolated by DGEBAL ====
11019 *
11020 DO 10 I = 1, ILO - 1
11021 WR( I ) = H( I, I )
11022 WI( I ) = ZERO
11023 10 CONTINUE
11024 DO 20 I = IHI + 1, N
11025 WR( I ) = H( I, I )
11026 WI( I ) = ZERO
11027 20 CONTINUE
11028 *
11029 * ==== Initialize Z, if requested ====
11030 *
11031 IF( INITZ )
11032 $ CALL DLASET( 'A', N, N, ZERO, ONE, Z, LDZ )
11033 *
11034 * ==== Quick return if possible ====
11035 *
11036 IF( ILO.EQ.IHI ) THEN
11037 WR( ILO ) = H( ILO, ILO )
11038 WI( ILO ) = ZERO
11039 RETURN
11040 END IF
11041 *
11042 * ==== DLAHQR/DLAQR0 crossover point ====
11043 *
11044 NMIN = ILAENV( 12, 'DHSEQR', JOB( : 1 ) // COMPZ( : 1 ), N,
11045 $ ILO, IHI, LWORK )
11046 NMIN = MAX( NTINY, NMIN )
11047 *
11048 * ==== DLAQR0 for big matrices; DLAHQR for small ones ====
11049 *
11050 IF( N.GT.NMIN ) THEN
11051 CALL DLAQR0( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI, ILO,
11052 $ IHI, Z, LDZ, WORK, LWORK, INFO )
11053 ELSE
11054 *
11055 * ==== Small matrix ====
11056 *
11057 CALL DLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI, ILO,
11058 $ IHI, Z, LDZ, INFO )
11059 *
11060 IF( INFO.GT.0 ) THEN
11061 *
11062 * ==== A rare DLAHQR failure! DLAQR0 sometimes succeeds
11063 * . when DLAHQR fails. ====
11064 *
11065 KBOT = INFO
11066 *
11067 IF( N.GE.NL ) THEN
11068 *
11069 * ==== Larger matrices have enough subdiagonal scratch
11070 * . space to call DLAQR0 directly. ====
11071 *
11072 CALL DLAQR0( WANTT, WANTZ, N, ILO, KBOT, H, LDH, WR,
11073 $ WI, ILO, IHI, Z, LDZ, WORK, LWORK, INFO )
11074 *
11075 ELSE
11076 *
11077 * ==== Tiny matrices don't have enough subdiagonal
11078 * . scratch space to benefit from DLAQR0. Hence,
11079 * . tiny matrices must be copied into a larger
11080 * . array before calling DLAQR0. ====
11081 *
11082 CALL DLACPY( 'A', N, N, H, LDH, HL, NL )
11083 HL( N+1, N ) = ZERO
11084 CALL DLASET( 'A', NL, NL-N, ZERO, ZERO, HL( 1, N+1 ),
11085 $ NL )
11086 CALL DLAQR0( WANTT, WANTZ, NL, ILO, KBOT, HL, NL, WR,
11087 $ WI, ILO, IHI, Z, LDZ, WORKL, NL, INFO )
11088 IF( WANTT .OR. INFO.NE.0 )
11089 $ CALL DLACPY( 'A', N, N, HL, NL, H, LDH )
11090 END IF
11091 END IF
11092 END IF
11093 *
11094 * ==== Clear out the trash, if necessary. ====
11095 *
11096 IF( ( WANTT .OR. INFO.NE.0 ) .AND. N.GT.2 )
11097 $ CALL DLASET( 'L', N-2, N-2, ZERO, ZERO, H( 3, 1 ), LDH )
11098 *
11099 * ==== Ensure reported workspace size is backward-compatible with
11100 * . previous LAPACK versions. ====
11101 *
11102 WORK( 1 ) = MAX( DBLE( MAX( 1, N ) ), WORK( 1 ) )
11103 END IF
11104 *
11105 * ==== End of DHSEQR ====
11106 *
11107 END
11108 C
11109 C-----------------------------------------------------------------------
11110 C-----------------------------------------------------------------------
11111 SUBROUTINE DLABAD( SMALL, LARGE )
11112 *
11113 * -- LAPACK auxiliary routine (version 3.2) --
11114 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
11115 * November 2006
11116 *
11117 * .. Scalar Arguments ..
11118 DOUBLE PRECISION LARGE, SMALL
11119 * ..
11120 *
11121 * Purpose
11122 * =======
11123 *
11124 * DLABAD takes as input the values computed by DLAMCH for underflow and
11125 * overflow, and returns the square root of each of these values if the
11126 * log of LARGE is sufficiently large. This subroutine is intended to
11127 * identify machines with a large exponent range, such as the Crays, and
11128 * redefine the underflow and overflow limits to be the square roots of
11129 * the values computed by DLAMCH. This subroutine is needed because
11130 * DLAMCH does not compensate for poor arithmetic in the upper half of
11131 * the exponent range, as is found on a Cray.
11132 *
11133 * Arguments
11134 * =========
11135 *
11136 * SMALL (input/output) DOUBLE PRECISION
11137 * On entry, the underflow threshold as computed by DLAMCH.
11138 * On exit, if LOG10(LARGE) is sufficiently large, the square
11139 * root of SMALL, otherwise unchanged.
11140 *
11141 * LARGE (input/output) DOUBLE PRECISION
11142 * On entry, the overflow threshold as computed by DLAMCH.
11143 * On exit, if LOG10(LARGE) is sufficiently large, the square
11144 * root of LARGE, otherwise unchanged.
11145 *
11146 * =====================================================================
11147 *
11148 * .. Intrinsic Functions ..
11149 INTRINSIC LOG10, SQRT
11150 * ..
11151 * .. Executable Statements ..
11152 *
11153 * If it looks like we're on a Cray, take the square root of
11154 * SMALL and LARGE to avoid overflow and underflow problems.
11155 *
11156 IF( LOG10( LARGE ).GT.2000.D0 ) THEN
11157 SMALL = SQRT( SMALL )
11158 LARGE = SQRT( LARGE )
11159 END IF
11160 *
11161 RETURN
11162 *
11163 * End of DLABAD
11164 *
11165 END
11166 C
11167 C-----------------------------------------------------------------------
11168 C-----------------------------------------------------------------------
11169 SUBROUTINE DLACN2( N, V, X, ISGN, EST, KASE, ISAVE )
11170 *
11171 * -- LAPACK auxiliary routine (version 3.2) --
11172 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
11173 * November 2006
11174 *
11175 * .. Scalar Arguments ..
11176 INTEGER KASE, N
11177 DOUBLE PRECISION EST
11178 * ..
11179 * .. Array Arguments ..
11180 INTEGER ISGN( * ), ISAVE( 3 )
11181 DOUBLE PRECISION V( * ), X( * )
11182 * ..
11183 *
11184 * Purpose
11185 * =======
11186 *
11187 * DLACN2 estimates the 1-norm of a square, real matrix A.
11188 * Reverse communication is used for evaluating matrix-vector products.
11189 *
11190 * Arguments
11191 * =========
11192 *
11193 * N (input) INTEGER
11194 * The order of the matrix. N >= 1.
11195 *
11196 * V (workspace) DOUBLE PRECISION array, dimension (N)
11197 * On the final return, V = A*W, where EST = norm(V)/norm(W)
11198 * (W is not returned).
11199 *
11200 * X (input/output) DOUBLE PRECISION array, dimension (N)
11201 * On an intermediate return, X should be overwritten by
11202 * A * X, if KASE=1,
11203 * A' * X, if KASE=2,
11204 * and DLACN2 must be re-called with all the other parameters
11205 * unchanged.
11206 *
11207 * ISGN (workspace) INTEGER array, dimension (N)
11208 *
11209 * EST (input/output) DOUBLE PRECISION
11210 * On entry with KASE = 1 or 2 and ISAVE(1) = 3, EST should be
11211 * unchanged from the previous call to DLACN2.
11212 * On exit, EST is an estimate (a lower bound) for norm(A).
11213 *
11214 * KASE (input/output) INTEGER
11215 * On the initial call to DLACN2, KASE should be 0.
11216 * On an intermediate return, KASE will be 1 or 2, indicating
11217 * whether X should be overwritten by A * X or A' * X.
11218 * On the final return from DLACN2, KASE will again be 0.
11219 *
11220 * ISAVE (input/output) INTEGER array, dimension (3)
11221 * ISAVE is used to save variables between calls to DLACN2
11222 *
11223 * Further Details
11224 * ======= =======
11225 *
11226 * Contributed by Nick Higham, University of Manchester.
11227 * Originally named SONEST, dated March 16, 1988.
11228 *
11229 * Reference: N.J. Higham, "FORTRAN codes for estimating the one-norm of
11230 * a real or complex matrix, with applications to condition estimation",
11231 * ACM Trans. Math. Soft., vol. 14, no. 4, pp. 381-396, December 1988.
11232 *
11233 * This is a thread safe version of DLACON, which uses the array ISAVE
11234 * in place of a SAVE statement, as follows:
11235 *
11236 * DLACON DLACN2
11237 * JUMP ISAVE(1)
11238 * J ISAVE(2)
11239 * ITER ISAVE(3)
11240 *
11241 * =====================================================================
11242 *
11243 * .. Parameters ..
11244 INTEGER ITMAX
11245 PARAMETER ( ITMAX = 5 )
11246 DOUBLE PRECISION ZERO, ONE, TWO
11247 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TWO = 2.0D+0 )
11248 * ..
11249 * .. Local Scalars ..
11250 INTEGER I, JLAST
11251 DOUBLE PRECISION ALTSGN, ESTOLD, TEMP
11252 * ..
11253 * .. External Functions ..
11254 INTEGER IDAMAX
11255 DOUBLE PRECISION DASUM
11256 EXTERNAL IDAMAX, DASUM
11257 * ..
11258 * .. External Subroutines ..
11259 EXTERNAL DCOPY
11260 * ..
11261 * .. Intrinsic Functions ..
11262 INTRINSIC ABS, DBLE, NINT, SIGN
11263 * ..
11264 * .. Executable Statements ..
11265 *
11266 IF( KASE.EQ.0 ) THEN
11267 DO 10 I = 1, N
11268 X( I ) = ONE / DBLE( N )
11269 10 CONTINUE
11270 KASE = 1
11271 ISAVE( 1 ) = 1
11272 RETURN
11273 END IF
11274 *
11275 GO TO ( 20, 40, 70, 110, 140 )ISAVE( 1 )
11276 *
11277 * ................ ENTRY (ISAVE( 1 ) = 1)
11278 * FIRST ITERATION. X HAS BEEN OVERWRITTEN BY A*X.
11279 *
11280 20 CONTINUE
11281 IF( N.EQ.1 ) THEN
11282 V( 1 ) = X( 1 )
11283 EST = ABS( V( 1 ) )
11284 * ... QUIT
11285 GO TO 150
11286 END IF
11287 EST = DASUM( N, X, 1 )
11288 *
11289 DO 30 I = 1, N
11290 X( I ) = SIGN( ONE, X( I ) )
11291 ISGN( I ) = NINT( X( I ) )
11292 30 CONTINUE
11293 KASE = 2
11294 ISAVE( 1 ) = 2
11295 RETURN
11296 *
11297 * ................ ENTRY (ISAVE( 1 ) = 2)
11298 * FIRST ITERATION. X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X.
11299 *
11300 40 CONTINUE
11301 ISAVE( 2 ) = IDAMAX( N, X, 1 )
11302 ISAVE( 3 ) = 2
11303 *
11304 * MAIN LOOP - ITERATIONS 2,3,...,ITMAX.
11305 *
11306 50 CONTINUE
11307 DO 60 I = 1, N
11308 X( I ) = ZERO
11309 60 CONTINUE
11310 X( ISAVE( 2 ) ) = ONE
11311 KASE = 1
11312 ISAVE( 1 ) = 3
11313 RETURN
11314 *
11315 * ................ ENTRY (ISAVE( 1 ) = 3)
11316 * X HAS BEEN OVERWRITTEN BY A*X.
11317 *
11318 70 CONTINUE
11319 CALL DCOPY( N, X, 1, V, 1 )
11320 ESTOLD = EST
11321 EST = DASUM( N, V, 1 )
11322 DO 80 I = 1, N
11323 IF( NINT( SIGN( ONE, X( I ) ) ).NE.ISGN( I ) )
11324 $ GO TO 90
11325 80 CONTINUE
11326 * REPEATED SIGN VECTOR DETECTED, HENCE ALGORITHM HAS CONVERGED.
11327 GO TO 120
11328 *
11329 90 CONTINUE
11330 * TEST FOR CYCLING.
11331 IF( EST.LE.ESTOLD )
11332 $ GO TO 120
11333 *
11334 DO 100 I = 1, N
11335 X( I ) = SIGN( ONE, X( I ) )
11336 ISGN( I ) = NINT( X( I ) )
11337 100 CONTINUE
11338 KASE = 2
11339 ISAVE( 1 ) = 4
11340 RETURN
11341 *
11342 * ................ ENTRY (ISAVE( 1 ) = 4)
11343 * X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X.
11344 *
11345 110 CONTINUE
11346 JLAST = ISAVE( 2 )
11347 ISAVE( 2 ) = IDAMAX( N, X, 1 )
11348 IF( ( X( JLAST ).NE.ABS( X( ISAVE( 2 ) ) ) ) .AND.
11349 $ ( ISAVE( 3 ).LT.ITMAX ) ) THEN
11350 ISAVE( 3 ) = ISAVE( 3 ) + 1
11351 GO TO 50
11352 END IF
11353 *
11354 * ITERATION COMPLETE. FINAL STAGE.
11355 *
11356 120 CONTINUE
11357 ALTSGN = ONE
11358 DO 130 I = 1, N
11359 X( I ) = ALTSGN*( ONE+DBLE( I-1 ) / DBLE( N-1 ) )
11360 ALTSGN = -ALTSGN
11361 130 CONTINUE
11362 KASE = 1
11363 ISAVE( 1 ) = 5
11364 RETURN
11365 *
11366 * ................ ENTRY (ISAVE( 1 ) = 5)
11367 * X HAS BEEN OVERWRITTEN BY A*X.
11368 *
11369 140 CONTINUE
11370 TEMP = TWO*( DASUM( N, X, 1 ) / DBLE( 3*N ) )
11371 IF( TEMP.GT.EST ) THEN
11372 CALL DCOPY( N, X, 1, V, 1 )
11373 EST = TEMP
11374 END IF
11375 *
11376 150 CONTINUE
11377 KASE = 0
11378 RETURN
11379 *
11380 * End of DLACN2
11381 *
11382 END
11383 C
11384 C-----------------------------------------------------------------------
11385 C-----------------------------------------------------------------------
11386 SUBROUTINE DLACPY( UPLO, M, N, A, LDA, B, LDB )
11387 *
11388 * -- LAPACK auxiliary routine (version 3.2) --
11389 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
11390 * November 2006
11391 *
11392 * .. Scalar Arguments ..
11393 CHARACTER UPLO
11394 INTEGER LDA, LDB, M, N
11395 * ..
11396 * .. Array Arguments ..
11397 DOUBLE PRECISION A( LDA, * ), B( LDB, * )
11398 * ..
11399 *
11400 * Purpose
11401 * =======
11402 *
11403 * DLACPY copies all or part of a two-dimensional matrix A to another
11404 * matrix B.
11405 *
11406 * Arguments
11407 * =========
11408 *
11409 * UPLO (input) CHARACTER*1
11410 * Specifies the part of the matrix A to be copied to B.
11411 * = 'U': Upper triangular part
11412 * = 'L': Lower triangular part
11413 * Otherwise: All of the matrix A
11414 *
11415 * M (input) INTEGER
11416 * The number of rows of the matrix A. M >= 0.
11417 *
11418 * N (input) INTEGER
11419 * The number of columns of the matrix A. N >= 0.
11420 *
11421 * A (input) DOUBLE PRECISION array, dimension (LDA,N)
11422 * The m by n matrix A. If UPLO = 'U', only the upper triangle
11423 * or trapezoid is accessed; if UPLO = 'L', only the lower
11424 * triangle or trapezoid is accessed.
11425 *
11426 * LDA (input) INTEGER
11427 * The leading dimension of the array A. LDA >= max(1,M).
11428 *
11429 * B (output) DOUBLE PRECISION array, dimension (LDB,N)
11430 * On exit, B = A in the locations specified by UPLO.
11431 *
11432 * LDB (input) INTEGER
11433 * The leading dimension of the array B. LDB >= max(1,M).
11434 *
11435 * =====================================================================
11436 *
11437 * .. Local Scalars ..
11438 INTEGER I, J
11439 * ..
11440 * .. External Functions ..
11441 LOGICAL LSAME
11442 EXTERNAL LSAME
11443 * ..
11444 * .. Intrinsic Functions ..
11445 INTRINSIC MIN
11446 * ..
11447 * .. Executable Statements ..
11448 *
11449 IF( LSAME( UPLO, 'U' ) ) THEN
11450 DO 20 J = 1, N
11451 DO 10 I = 1, MIN( J, M )
11452 B( I, J ) = A( I, J )
11453 10 CONTINUE
11454 20 CONTINUE
11455 ELSE IF( LSAME( UPLO, 'L' ) ) THEN
11456 DO 40 J = 1, N
11457 DO 30 I = J, M
11458 B( I, J ) = A( I, J )
11459 30 CONTINUE
11460 40 CONTINUE
11461 ELSE
11462 DO 60 J = 1, N
11463 DO 50 I = 1, M
11464 B( I, J ) = A( I, J )
11465 50 CONTINUE
11466 60 CONTINUE
11467 END IF
11468 RETURN
11469 *
11470 * End of DLACPY
11471 *
11472 END
11473 C
11474 C-----------------------------------------------------------------------
11475 C-----------------------------------------------------------------------
11476 SUBROUTINE DLADIV( A, B, C, D, P, Q )
11477 *
11478 * -- LAPACK auxiliary routine (version 3.2) --
11479 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
11480 * November 2006
11481 *
11482 * .. Scalar Arguments ..
11483 DOUBLE PRECISION A, B, C, D, P, Q
11484 * ..
11485 *
11486 * Purpose
11487 * =======
11488 *
11489 * DLADIV performs complex division in real arithmetic
11490 *
11491 * a + i*b
11492 * p + i*q = ---------
11493 * c + i*d
11494 *
11495 * The algorithm is due to Robert L. Smith and can be found
11496 * in D. Knuth, The art of Computer Programming, Vol.2, p.195
11497 *
11498 * Arguments
11499 * =========
11500 *
11501 * A (input) DOUBLE PRECISION
11502 * B (input) DOUBLE PRECISION
11503 * C (input) DOUBLE PRECISION
11504 * D (input) DOUBLE PRECISION
11505 * The scalars a, b, c, and d in the above expression.
11506 *
11507 * P (output) DOUBLE PRECISION
11508 * Q (output) DOUBLE PRECISION
11509 * The scalars p and q in the above expression.
11510 *
11511 * =====================================================================
11512 *
11513 * .. Local Scalars ..
11514 DOUBLE PRECISION E, F
11515 * ..
11516 * .. Intrinsic Functions ..
11517 INTRINSIC ABS
11518 * ..
11519 * .. Executable Statements ..
11520 *
11521 IF( ABS( D ).LT.ABS( C ) ) THEN
11522 E = D / C
11523 F = C + D*E
11524 P = ( A+B*E ) / F
11525 Q = ( B-A*E ) / F
11526 ELSE
11527 E = C / D
11528 F = D + C*E
11529 P = ( B+A*E ) / F
11530 Q = ( -A+B*E ) / F
11531 END IF
11532 *
11533 RETURN
11534 *
11535 * End of DLADIV
11536 *
11537 END
11538 C
11539 C-----------------------------------------------------------------------
11540 C-----------------------------------------------------------------------
11541 SUBROUTINE DLAEXC( WANTQ, N, T, LDT, Q, LDQ, J1, N1, N2, WORK,
11542 $ INFO )
11543 *
11544 * -- LAPACK auxiliary routine (version 3.2.2) --
11545 * -- LAPACK is a software package provided by Univ. of Tennessee, --
11546 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
11547 * June 2010
11548 *
11549 * .. Scalar Arguments ..
11550 LOGICAL WANTQ
11551 INTEGER INFO, J1, LDQ, LDT, N, N1, N2
11552 * ..
11553 * .. Array Arguments ..
11554 DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WORK( * )
11555 * ..
11556 *
11557 * Purpose
11558 * =======
11559 *
11560 * DLAEXC swaps adjacent diagonal blocks T11 and T22 of order 1 or 2 in
11561 * an upper quasi-triangular matrix T by an orthogonal similarity
11562 * transformation.
11563 *
11564 * T must be in Schur canonical form, that is, block upper triangular
11565 * with 1-by-1 and 2-by-2 diagonal blocks; each 2-by-2 diagonal block
11566 * has its diagonal elemnts equal and its off-diagonal elements of
11567 * opposite sign.
11568 *
11569 * Arguments
11570 * =========
11571 *
11572 * WANTQ (input) LOGICAL
11573 * = .TRUE. : accumulate the transformation in the matrix Q;
11574 * = .FALSE.: do not accumulate the transformation.
11575 *
11576 * N (input) INTEGER
11577 * The order of the matrix T. N >= 0.
11578 *
11579 * T (input/output) DOUBLE PRECISION array, dimension (LDT,N)
11580 * On entry, the upper quasi-triangular matrix T, in Schur
11581 * canonical form.
11582 * On exit, the updated matrix T, again in Schur canonical form.
11583 *
11584 * LDT (input) INTEGER
11585 * The leading dimension of the array T. LDT >= max(1,N).
11586 *
11587 * Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N)
11588 * On entry, if WANTQ is .TRUE., the orthogonal matrix Q.
11589 * On exit, if WANTQ is .TRUE., the updated matrix Q.
11590 * If WANTQ is .FALSE., Q is not referenced.
11591 *
11592 * LDQ (input) INTEGER
11593 * The leading dimension of the array Q.
11594 * LDQ >= 1; and if WANTQ is .TRUE., LDQ >= N.
11595 *
11596 * J1 (input) INTEGER
11597 * The index of the first row of the first block T11.
11598 *
11599 * N1 (input) INTEGER
11600 * The order of the first block T11. N1 = 0, 1 or 2.
11601 *
11602 * N2 (input) INTEGER
11603 * The order of the second block T22. N2 = 0, 1 or 2.
11604 *
11605 * WORK (workspace) DOUBLE PRECISION array, dimension (N)
11606 *
11607 * INFO (output) INTEGER
11608 * = 0: successful exit
11609 * = 1: the transformed matrix T would be too far from Schur
11610 * form; the blocks are not swapped and T and Q are
11611 * unchanged.
11612 *
11613 * =====================================================================
11614 *
11615 * .. Parameters ..
11616 DOUBLE PRECISION ZERO, ONE
11617 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
11618 DOUBLE PRECISION TEN
11619 PARAMETER ( TEN = 1.0D+1 )
11620 INTEGER LDD, LDX
11621 PARAMETER ( LDD = 4, LDX = 2 )
11622 * ..
11623 * .. Local Scalars ..
11624 INTEGER IERR, J2, J3, J4, K, ND
11625 DOUBLE PRECISION CS, DNORM, EPS, SCALE, SMLNUM, SN, T11, T22,
11626 $ T33, TAU, TAU1, TAU2, TEMP, THRESH, WI1, WI2,
11627 $ WR1, WR2, XNORM
11628 * ..
11629 * .. Local Arrays ..
11630 DOUBLE PRECISION D( LDD, 4 ), U( 3 ), U1( 3 ), U2( 3 ),
11631 $ X( LDX, 2 )
11632 * ..
11633 * .. External Functions ..
11634 DOUBLE PRECISION DLAMCH, DLANGE
11635 EXTERNAL DLAMCH, DLANGE
11636 * ..
11637 * .. External Subroutines ..
11638 EXTERNAL DLACPY, DLANV2, DLARFG, DLARFX, DLARTG, DLASY2,
11639 $ DROT
11640 * ..
11641 * .. Intrinsic Functions ..
11642 INTRINSIC ABS, MAX
11643 * ..
11644 * .. Executable Statements ..
11645 *
11646 INFO = 0
11647 *
11648 * Quick return if possible
11649 *
11650 IF( N.EQ.0 .OR. N1.EQ.0 .OR. N2.EQ.0 )
11651 $ RETURN
11652 IF( J1+N1.GT.N )
11653 $ RETURN
11654 *
11655 J2 = J1 + 1
11656 J3 = J1 + 2
11657 J4 = J1 + 3
11658 *
11659 IF( N1.EQ.1 .AND. N2.EQ.1 ) THEN
11660 *
11661 * Swap two 1-by-1 blocks.
11662 *
11663 T11 = T( J1, J1 )
11664 T22 = T( J2, J2 )
11665 *
11666 * Determine the transformation to perform the interchange.
11667 *
11668 CALL DLARTG( T( J1, J2 ), T22-T11, CS, SN, TEMP )
11669 *
11670 * Apply transformation to the matrix T.
11671 *
11672 IF( J3.LE.N )
11673 $ CALL DROT( N-J1-1, T( J1, J3 ), LDT, T( J2, J3 ), LDT, CS,
11674 $ SN )
11675 CALL DROT( J1-1, T( 1, J1 ), 1, T( 1, J2 ), 1, CS, SN )
11676 *
11677 T( J1, J1 ) = T22
11678 T( J2, J2 ) = T11
11679 *
11680 IF( WANTQ ) THEN
11681 *
11682 * Accumulate transformation in the matrix Q.
11683 *
11684 CALL DROT( N, Q( 1, J1 ), 1, Q( 1, J2 ), 1, CS, SN )
11685 END IF
11686 *
11687 ELSE
11688 *
11689 * Swapping involves at least one 2-by-2 block.
11690 *
11691 * Copy the diagonal block of order N1+N2 to the local array D
11692 * and compute its norm.
11693 *
11694 ND = N1 + N2
11695 CALL DLACPY( 'Full', ND, ND, T( J1, J1 ), LDT, D, LDD )
11696 DNORM = DLANGE( 'Max', ND, ND, D, LDD, WORK )
11697 *
11698 * Compute machine-dependent threshold for test for accepting
11699 * swap.
11700 *
11701 EPS = DLAMCH( 'P' )
11702 SMLNUM = DLAMCH( 'S' ) / EPS
11703 THRESH = MAX( TEN*EPS*DNORM, SMLNUM )
11704 *
11705 * Solve T11*X - X*T22 = scale*T12 for X.
11706 *
11707 CALL DLASY2( .FALSE., .FALSE., -1, N1, N2, D, LDD,
11708 $ D( N1+1, N1+1 ), LDD, D( 1, N1+1 ), LDD, SCALE, X,
11709 $ LDX, XNORM, IERR )
11710 *
11711 * Swap the adjacent diagonal blocks.
11712 *
11713 K = N1 + N1 + N2 - 3
11714 GO TO ( 10, 20, 30 )K
11715 *
11716 10 CONTINUE
11717 *
11718 * N1 = 1, N2 = 2: generate elementary reflector H so that:
11719 *
11720 * ( scale, X11, X12 ) H = ( 0, 0, * )
11721 *
11722 U( 1 ) = SCALE
11723 U( 2 ) = X( 1, 1 )
11724 U( 3 ) = X( 1, 2 )
11725 CALL DLARFG( 3, U( 3 ), U, 1, TAU )
11726 U( 3 ) = ONE
11727 T11 = T( J1, J1 )
11728 *
11729 * Perform swap provisionally on diagonal block in D.
11730 *
11731 CALL DLARFX( 'L', 3, 3, U, TAU, D, LDD, WORK )
11732 CALL DLARFX( 'R', 3, 3, U, TAU, D, LDD, WORK )
11733 *
11734 * Test whether to reject swap.
11735 *
11736 IF( MAX( ABS( D( 3, 1 ) ), ABS( D( 3, 2 ) ), ABS( D( 3,
11737 $ 3 )-T11 ) ).GT.THRESH )GO TO 50
11738 *
11739 * Accept swap: apply transformation to the entire matrix T.
11740 *
11741 CALL DLARFX( 'L', 3, N-J1+1, U, TAU, T( J1, J1 ), LDT, WORK )
11742 CALL DLARFX( 'R', J2, 3, U, TAU, T( 1, J1 ), LDT, WORK )
11743 *
11744 T( J3, J1 ) = ZERO
11745 T( J3, J2 ) = ZERO
11746 T( J3, J3 ) = T11
11747 *
11748 IF( WANTQ ) THEN
11749 *
11750 * Accumulate transformation in the matrix Q.
11751 *
11752 CALL DLARFX( 'R', N, 3, U, TAU, Q( 1, J1 ), LDQ, WORK )
11753 END IF
11754 GO TO 40
11755 *
11756 20 CONTINUE
11757 *
11758 * N1 = 2, N2 = 1: generate elementary reflector H so that:
11759 *
11760 * H ( -X11 ) = ( * )
11761 * ( -X21 ) = ( 0 )
11762 * ( scale ) = ( 0 )
11763 *
11764 U( 1 ) = -X( 1, 1 )
11765 U( 2 ) = -X( 2, 1 )
11766 U( 3 ) = SCALE
11767 CALL DLARFG( 3, U( 1 ), U( 2 ), 1, TAU )
11768 U( 1 ) = ONE
11769 T33 = T( J3, J3 )
11770 *
11771 * Perform swap provisionally on diagonal block in D.
11772 *
11773 CALL DLARFX( 'L', 3, 3, U, TAU, D, LDD, WORK )
11774 CALL DLARFX( 'R', 3, 3, U, TAU, D, LDD, WORK )
11775 *
11776 * Test whether to reject swap.
11777 *
11778 IF( MAX( ABS( D( 2, 1 ) ), ABS( D( 3, 1 ) ), ABS( D( 1,
11779 $ 1 )-T33 ) ).GT.THRESH )GO TO 50
11780 *
11781 * Accept swap: apply transformation to the entire matrix T.
11782 *
11783 CALL DLARFX( 'R', J3, 3, U, TAU, T( 1, J1 ), LDT, WORK )
11784 CALL DLARFX( 'L', 3, N-J1, U, TAU, T( J1, J2 ), LDT, WORK )
11785 *
11786 T( J1, J1 ) = T33
11787 T( J2, J1 ) = ZERO
11788 T( J3, J1 ) = ZERO
11789 *
11790 IF( WANTQ ) THEN
11791 *
11792 * Accumulate transformation in the matrix Q.
11793 *
11794 CALL DLARFX( 'R', N, 3, U, TAU, Q( 1, J1 ), LDQ, WORK )
11795 END IF
11796 GO TO 40
11797 *
11798 30 CONTINUE
11799 *
11800 * N1 = 2, N2 = 2: generate elementary reflectors H(1) and H(2) so
11801 * that:
11802 *
11803 * H(2) H(1) ( -X11 -X12 ) = ( * * )
11804 * ( -X21 -X22 ) ( 0 * )
11805 * ( scale 0 ) ( 0 0 )
11806 * ( 0 scale ) ( 0 0 )
11807 *
11808 U1( 1 ) = -X( 1, 1 )
11809 U1( 2 ) = -X( 2, 1 )
11810 U1( 3 ) = SCALE
11811 CALL DLARFG( 3, U1( 1 ), U1( 2 ), 1, TAU1 )
11812 U1( 1 ) = ONE
11813 *
11814 TEMP = -TAU1*( X( 1, 2 )+U1( 2 )*X( 2, 2 ) )
11815 U2( 1 ) = -TEMP*U1( 2 ) - X( 2, 2 )
11816 U2( 2 ) = -TEMP*U1( 3 )
11817 U2( 3 ) = SCALE
11818 CALL DLARFG( 3, U2( 1 ), U2( 2 ), 1, TAU2 )
11819 U2( 1 ) = ONE
11820 *
11821 * Perform swap provisionally on diagonal block in D.
11822 *
11823 CALL DLARFX( 'L', 3, 4, U1, TAU1, D, LDD, WORK )
11824 CALL DLARFX( 'R', 4, 3, U1, TAU1, D, LDD, WORK )
11825 CALL DLARFX( 'L', 3, 4, U2, TAU2, D( 2, 1 ), LDD, WORK )
11826 CALL DLARFX( 'R', 4, 3, U2, TAU2, D( 1, 2 ), LDD, WORK )
11827 *
11828 * Test whether to reject swap.
11829 *
11830 IF( MAX( ABS( D( 3, 1 ) ), ABS( D( 3, 2 ) ), ABS( D( 4, 1 ) ),
11831 $ ABS( D( 4, 2 ) ) ).GT.THRESH )GO TO 50
11832 *
11833 * Accept swap: apply transformation to the entire matrix T.
11834 *
11835 CALL DLARFX( 'L', 3, N-J1+1, U1, TAU1, T( J1, J1 ), LDT, WORK )
11836 CALL DLARFX( 'R', J4, 3, U1, TAU1, T( 1, J1 ), LDT, WORK )
11837 CALL DLARFX( 'L', 3, N-J1+1, U2, TAU2, T( J2, J1 ), LDT, WORK )
11838 CALL DLARFX( 'R', J4, 3, U2, TAU2, T( 1, J2 ), LDT, WORK )
11839 *
11840 T( J3, J1 ) = ZERO
11841 T( J3, J2 ) = ZERO
11842 T( J4, J1 ) = ZERO
11843 T( J4, J2 ) = ZERO
11844 *
11845 IF( WANTQ ) THEN
11846 *
11847 * Accumulate transformation in the matrix Q.
11848 *
11849 CALL DLARFX( 'R', N, 3, U1, TAU1, Q( 1, J1 ), LDQ, WORK )
11850 CALL DLARFX( 'R', N, 3, U2, TAU2, Q( 1, J2 ), LDQ, WORK )
11851 END IF
11852 *
11853 40 CONTINUE
11854 *
11855 IF( N2.EQ.2 ) THEN
11856 *
11857 * Standardize new 2-by-2 block T11
11858 *
11859 CALL DLANV2( T( J1, J1 ), T( J1, J2 ), T( J2, J1 ),
11860 $ T( J2, J2 ), WR1, WI1, WR2, WI2, CS, SN )
11861 CALL DROT( N-J1-1, T( J1, J1+2 ), LDT, T( J2, J1+2 ), LDT,
11862 $ CS, SN )
11863 CALL DROT( J1-1, T( 1, J1 ), 1, T( 1, J2 ), 1, CS, SN )
11864 IF( WANTQ )
11865 $ CALL DROT( N, Q( 1, J1 ), 1, Q( 1, J2 ), 1, CS, SN )
11866 END IF
11867 *
11868 IF( N1.EQ.2 ) THEN
11869 *
11870 * Standardize new 2-by-2 block T22
11871 *
11872 J3 = J1 + N2
11873 J4 = J3 + 1
11874 CALL DLANV2( T( J3, J3 ), T( J3, J4 ), T( J4, J3 ),
11875 $ T( J4, J4 ), WR1, WI1, WR2, WI2, CS, SN )
11876 IF( J3+2.LE.N )
11877 $ CALL DROT( N-J3-1, T( J3, J3+2 ), LDT, T( J4, J3+2 ),
11878 $ LDT, CS, SN )
11879 CALL DROT( J3-1, T( 1, J3 ), 1, T( 1, J4 ), 1, CS, SN )
11880 IF( WANTQ )
11881 $ CALL DROT( N, Q( 1, J3 ), 1, Q( 1, J4 ), 1, CS, SN )
11882 END IF
11883 *
11884 END IF
11885 RETURN
11886 *
11887 * Exit with INFO = 1 if swap was rejected.
11888 *
11889 50 CONTINUE
11890 INFO = 1
11891 RETURN
11892 *
11893 * End of DLAEXC
11894 *
11895 END
11896 C
11897 C-----------------------------------------------------------------------
11898 C-----------------------------------------------------------------------
11899 SUBROUTINE DLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI,
11900 $ ILOZ, IHIZ, Z, LDZ, INFO )
11901 *
11902 * -- LAPACK auxiliary routine (version 3.2) --
11903 * Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
11904 * November 2006
11905 *
11906 * .. Scalar Arguments ..
11907 INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N
11908 LOGICAL WANTT, WANTZ
11909 * ..
11910 * .. Array Arguments ..
11911 DOUBLE PRECISION H( LDH, * ), WI( * ), WR( * ), Z( LDZ, * )
11912 * ..
11913 *
11914 * Purpose
11915 * =======
11916 *
11917 * DLAHQR is an auxiliary routine called by DHSEQR to update the
11918 * eigenvalues and Schur decomposition already computed by DHSEQR, by
11919 * dealing with the Hessenberg submatrix in rows and columns ILO to
11920 * IHI.
11921 *
11922 * Arguments
11923 * =========
11924 *
11925 * WANTT (input) LOGICAL
11926 * = .TRUE. : the full Schur form T is required;
11927 * = .FALSE.: only eigenvalues are required.
11928 *
11929 * WANTZ (input) LOGICAL
11930 * = .TRUE. : the matrix of Schur vectors Z is required;
11931 * = .FALSE.: Schur vectors are not required.
11932 *
11933 * N (input) INTEGER
11934 * The order of the matrix H. N >= 0.
11935 *
11936 * ILO (input) INTEGER
11937 * IHI (input) INTEGER
11938 * It is assumed that H is already upper quasi-triangular in
11939 * rows and columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless
11940 * ILO = 1). DLAHQR works primarily with the Hessenberg
11941 * submatrix in rows and columns ILO to IHI, but applies
11942 * transformations to all of H if WANTT is .TRUE..
11943 * 1 <= ILO <= max(1,IHI); IHI <= N.
11944 *
11945 * H (input/output) DOUBLE PRECISION array, dimension (LDH,N)
11946 * On entry, the upper Hessenberg matrix H.
11947 * On exit, if INFO is zero and if WANTT is .TRUE., H is upper
11948 * quasi-triangular in rows and columns ILO:IHI, with any
11949 * 2-by-2 diagonal blocks in standard form. If INFO is zero
11950 * and WANTT is .FALSE., the contents of H are unspecified on
11951 * exit. The output state of H if INFO is nonzero is given
11952 * below under the description of INFO.
11953 *
11954 * LDH (input) INTEGER
11955 * The leading dimension of the array H. LDH >= max(1,N).
11956 *
11957 * WR (output) DOUBLE PRECISION array, dimension (N)
11958 * WI (output) DOUBLE PRECISION array, dimension (N)
11959 * The real and imaginary parts, respectively, of the computed
11960 * eigenvalues ILO to IHI are stored in the corresponding
11961 * elements of WR and WI. If two eigenvalues are computed as a
11962 * complex conjugate pair, they are stored in consecutive
11963 * elements of WR and WI, say the i-th and (i+1)th, with
11964 * WI(i) > 0 and WI(i+1) < 0. If WANTT is .TRUE., the
11965 * eigenvalues are stored in the same order as on the diagonal
11966 * of the Schur form returned in H, with WR(i) = H(i,i), and, if
11967 * H(i:i+1,i:i+1) is a 2-by-2 diagonal block,
11968 * WI(i) = sqrt(H(i+1,i)*H(i,i+1)) and WI(i+1) = -WI(i).
11969 *
11970 * ILOZ (input) INTEGER
11971 * IHIZ (input) INTEGER
11972 * Specify the rows of Z to which transformations must be
11973 * applied if WANTZ is .TRUE..
11974 * 1 <= ILOZ <= ILO; IHI <= IHIZ <= N.
11975 *
11976 * Z (input/output) DOUBLE PRECISION array, dimension (LDZ,N)
11977 * If WANTZ is .TRUE., on entry Z must contain the current
11978 * matrix Z of transformations accumulated by DHSEQR, and on
11979 * exit Z has been updated; transformations are applied only to
11980 * the submatrix Z(ILOZ:IHIZ,ILO:IHI).
11981 * If WANTZ is .FALSE., Z is not referenced.
11982 *
11983 * LDZ (input) INTEGER
11984 * The leading dimension of the array Z. LDZ >= max(1,N).
11985 *
11986 * INFO (output) INTEGER
11987 * = 0: successful exit
11988 * .GT. 0: If INFO = i, DLAHQR failed to compute all the
11989 * eigenvalues ILO to IHI in a total of 30 iterations
11990 * per eigenvalue; elements i+1:ihi of WR and WI
11991 * contain those eigenvalues which have been
11992 * successfully computed.
11993 *
11994 * If INFO .GT. 0 and WANTT is .FALSE., then on exit,
11995 * the remaining unconverged eigenvalues are the
11996 * eigenvalues of the upper Hessenberg matrix rows
11997 * and columns ILO thorugh INFO of the final, output
11998 * value of H.
11999 *
12000 * If INFO .GT. 0 and WANTT is .TRUE., then on exit
12001 * (*) (initial value of H)*U = U*(final value of H)
12002 * where U is an orthognal matrix. The final
12003 * value of H is upper Hessenberg and triangular in
12004 * rows and columns INFO+1 through IHI.
12005 *
12006 * If INFO .GT. 0 and WANTZ is .TRUE., then on exit
12007 * (final value of Z) = (initial value of Z)*U
12008 * where U is the orthogonal matrix in (*)
12009 * (regardless of the value of WANTT.)
12010 *
12011 * Further Details
12012 * ===============
12013 *
12014 * 02-96 Based on modifications by
12015 * David Day, Sandia National Laboratory, USA
12016 *
12017 * 12-04 Further modifications by
12018 * Ralph Byers, University of Kansas, USA
12019 * This is a modified version of DLAHQR from LAPACK version 3.0.
12020 * It is (1) more robust against overflow and underflow and
12021 * (2) adopts the more conservative Ahues & Tisseur stopping
12022 * criterion (LAWN 122, 1997).
12023 *
12024 * =========================================================
12025 *
12026 * .. Parameters ..
12027 INTEGER ITMAX
12028 PARAMETER ( ITMAX = 30 )
12029 DOUBLE PRECISION ZERO, ONE, TWO
12030 PARAMETER ( ZERO = 0.0d0, ONE = 1.0d0, TWO = 2.0d0 )
12031 DOUBLE PRECISION DAT1, DAT2
12032 PARAMETER ( DAT1 = 3.0d0 / 4.0d0, DAT2 = -0.4375d0 )
12033 * ..
12034 * .. Local Scalars ..
12035 DOUBLE PRECISION AA, AB, BA, BB, CS, DET, H11, H12, H21, H21S,
12036 $ H22, RT1I, RT1R, RT2I, RT2R, RTDISC, S, SAFMAX,
12037 $ SAFMIN, SMLNUM, SN, SUM, T1, T2, T3, TR, TST,
12038 $ ULP, V2, V3
12039 INTEGER I, I1, I2, ITS, J, K, L, M, NH, NR, NZ
12040 * ..
12041 * .. Local Arrays ..
12042 DOUBLE PRECISION V( 3 )
12043 * ..
12044 * .. External Functions ..
12045 DOUBLE PRECISION DLAMCH
12046 EXTERNAL DLAMCH
12047 * ..
12048 * .. External Subroutines ..
12049 EXTERNAL DCOPY, DLABAD, DLANV2, DLARFG, DROT
12050 * ..
12051 * .. Intrinsic Functions ..
12052 INTRINSIC ABS, DBLE, MAX, MIN, SQRT
12053 * ..
12054 * .. Executable Statements ..
12055 *
12056 INFO = 0
12057 *
12058 * Quick return if possible
12059 *
12060 IF( N.EQ.0 )
12061 $ RETURN
12062 IF( ILO.EQ.IHI ) THEN
12063 WR( ILO ) = H( ILO, ILO )
12064 WI( ILO ) = ZERO
12065 RETURN
12066 END IF
12067 *
12068 * ==== clear out the trash ====
12069 DO 10 J = ILO, IHI - 3
12070 H( J+2, J ) = ZERO
12071 H( J+3, J ) = ZERO
12072 10 CONTINUE
12073 IF( ILO.LE.IHI-2 )
12074 $ H( IHI, IHI-2 ) = ZERO
12075 *
12076 NH = IHI - ILO + 1
12077 NZ = IHIZ - ILOZ + 1
12078 *
12079 * Set machine-dependent constants for the stopping criterion.
12080 *
12081 SAFMIN = DLAMCH( 'SAFE MINIMUM' )
12082 SAFMAX = ONE / SAFMIN
12083 CALL DLABAD( SAFMIN, SAFMAX )
12084 ULP = DLAMCH( 'PRECISION' )
12085 SMLNUM = SAFMIN*( DBLE( NH ) / ULP )
12086 *
12087 * I1 and I2 are the indices of the first row and last column of H
12088 * to which transformations must be applied. If eigenvalues only are
12089 * being computed, I1 and I2 are set inside the main loop.
12090 *
12091 IF( WANTT ) THEN
12092 I1 = 1
12093 I2 = N
12094 END IF
12095 *
12096 * The main loop begins here. I is the loop index and decreases from
12097 * IHI to ILO in steps of 1 or 2. Each iteration of the loop works
12098 * with the active submatrix in rows and columns L to I.
12099 * Eigenvalues I+1 to IHI have already converged. Either L = ILO or
12100 * H(L,L-1) is negligible so that the matrix splits.
12101 *
12102 I = IHI
12103 20 CONTINUE
12104 L = ILO
12105 IF( I.LT.ILO )
12106 $ GO TO 160
12107 *
12108 * Perform QR iterations on rows and columns ILO to I until a
12109 * submatrix of order 1 or 2 splits off at the bottom because a
12110 * subdiagonal element has become negligible.
12111 *
12112 DO 140 ITS = 0, ITMAX
12113 *
12114 * Look for a single small subdiagonal element.
12115 *
12116 DO 30 K = I, L + 1, -1
12117 IF( ABS( H( K, K-1 ) ).LE.SMLNUM )
12118 $ GO TO 40
12119 TST = ABS( H( K-1, K-1 ) ) + ABS( H( K, K ) )
12120 IF( TST.EQ.ZERO ) THEN
12121 IF( K-2.GE.ILO )
12122 $ TST = TST + ABS( H( K-1, K-2 ) )
12123 IF( K+1.LE.IHI )
12124 $ TST = TST + ABS( H( K+1, K ) )
12125 END IF
12126 * ==== The following is a conservative small subdiagonal
12127 * . deflation criterion due to Ahues & Tisseur (LAWN 122,
12128 * . 1997). It has better mathematical foundation and
12129 * . improves accuracy in some cases. ====
12130 IF( ABS( H( K, K-1 ) ).LE.ULP*TST ) THEN
12131 AB = MAX( ABS( H( K, K-1 ) ), ABS( H( K-1, K ) ) )
12132 BA = MIN( ABS( H( K, K-1 ) ), ABS( H( K-1, K ) ) )
12133 AA = MAX( ABS( H( K, K ) ),
12134 $ ABS( H( K-1, K-1 )-H( K, K ) ) )
12135 BB = MIN( ABS( H( K, K ) ),
12136 $ ABS( H( K-1, K-1 )-H( K, K ) ) )
12137 S = AA + AB
12138 IF( BA*( AB / S ).LE.MAX( SMLNUM,
12139 $ ULP*( BB*( AA / S ) ) ) )GO TO 40
12140 END IF
12141 30 CONTINUE
12142 40 CONTINUE
12143 L = K
12144 IF( L.GT.ILO ) THEN
12145 *
12146 * H(L,L-1) is negligible
12147 *
12148 H( L, L-1 ) = ZERO
12149 END IF
12150 *
12151 * Exit from loop if a submatrix of order 1 or 2 has split off.
12152 *
12153 IF( L.GE.I-1 )
12154 $ GO TO 150
12155 *
12156 * Now the active submatrix is in rows and columns L to I. If
12157 * eigenvalues only are being computed, only the active submatrix
12158 * need be transformed.
12159 *
12160 IF( .NOT.WANTT ) THEN
12161 I1 = L
12162 I2 = I
12163 END IF
12164 *
12165 IF( ITS.EQ.10 ) THEN
12166 *
12167 * Exceptional shift.
12168 *
12169 S = ABS( H( L+1, L ) ) + ABS( H( L+2, L+1 ) )
12170 H11 = DAT1*S + H( L, L )
12171 H12 = DAT2*S
12172 H21 = S
12173 H22 = H11
12174 ELSE IF( ITS.EQ.20 ) THEN
12175 *
12176 * Exceptional shift.
12177 *
12178 S = ABS( H( I, I-1 ) ) + ABS( H( I-1, I-2 ) )
12179 H11 = DAT1*S + H( I, I )
12180 H12 = DAT2*S
12181 H21 = S
12182 H22 = H11
12183 ELSE
12184 *
12185 * Prepare to use Francis' double shift
12186 * (i.e. 2nd degree generalized Rayleigh quotient)
12187 *
12188 H11 = H( I-1, I-1 )
12189 H21 = H( I, I-1 )
12190 H12 = H( I-1, I )
12191 H22 = H( I, I )
12192 END IF
12193 S = ABS( H11 ) + ABS( H12 ) + ABS( H21 ) + ABS( H22 )
12194 IF( S.EQ.ZERO ) THEN
12195 RT1R = ZERO
12196 RT1I = ZERO
12197 RT2R = ZERO
12198 RT2I = ZERO
12199 ELSE
12200 H11 = H11 / S
12201 H21 = H21 / S
12202 H12 = H12 / S
12203 H22 = H22 / S
12204 TR = ( H11+H22 ) / TWO
12205 DET = ( H11-TR )*( H22-TR ) - H12*H21
12206 RTDISC = SQRT( ABS( DET ) )
12207 IF( DET.GE.ZERO ) THEN
12208 *
12209 * ==== complex conjugate shifts ====
12210 *
12211 RT1R = TR*S
12212 RT2R = RT1R
12213 RT1I = RTDISC*S
12214 RT2I = -RT1I
12215 ELSE
12216 *
12217 * ==== real shifts (use only one of them) ====
12218 *
12219 RT1R = TR + RTDISC
12220 RT2R = TR - RTDISC
12221 IF( ABS( RT1R-H22 ).LE.ABS( RT2R-H22 ) ) THEN
12222 RT1R = RT1R*S
12223 RT2R = RT1R
12224 ELSE
12225 RT2R = RT2R*S
12226 RT1R = RT2R
12227 END IF
12228 RT1I = ZERO
12229 RT2I = ZERO
12230 END IF
12231 END IF
12232 *
12233 * Look for two consecutive small subdiagonal elements.
12234 *
12235 DO 50 M = I - 2, L, -1
12236 * Determine the effect of starting the double-shift QR
12237 * iteration at row M, and see if this would make H(M,M-1)
12238 * negligible. (The following uses scaling to avoid
12239 * overflows and most underflows.)
12240 *
12241 H21S = H( M+1, M )
12242 S = ABS( H( M, M )-RT2R ) + ABS( RT2I ) + ABS( H21S )
12243 H21S = H( M+1, M ) / S
12244 V( 1 ) = H21S*H( M, M+1 ) + ( H( M, M )-RT1R )*
12245 $ ( ( H( M, M )-RT2R ) / S ) - RT1I*( RT2I / S )
12246 V( 2 ) = H21S*( H( M, M )+H( M+1, M+1 )-RT1R-RT2R )
12247 V( 3 ) = H21S*H( M+2, M+1 )
12248 S = ABS( V( 1 ) ) + ABS( V( 2 ) ) + ABS( V( 3 ) )
12249 V( 1 ) = V( 1 ) / S
12250 V( 2 ) = V( 2 ) / S
12251 V( 3 ) = V( 3 ) / S
12252 IF( M.EQ.L )
12253 $ GO TO 60
12254 IF( ABS( H( M, M-1 ) )*( ABS( V( 2 ) )+ABS( V( 3 ) ) ).LE.
12255 $ ULP*ABS( V( 1 ) )*( ABS( H( M-1, M-1 ) )+ABS( H( M,
12256 $ M ) )+ABS( H( M+1, M+1 ) ) ) )GO TO 60
12257 50 CONTINUE
12258 60 CONTINUE
12259 *
12260 * Double-shift QR step
12261 *
12262 DO 130 K = M, I - 1
12263 *
12264 * The first iteration of this loop determines a reflection G
12265 * from the vector V and applies it from left and right to H,
12266 * thus creating a nonzero bulge below the subdiagonal.
12267 *
12268 * Each subsequent iteration determines a reflection G to
12269 * restore the Hessenberg form in the (K-1)th column, and thus
12270 * chases the bulge one step toward the bottom of the active
12271 * submatrix. NR is the order of G.
12272 *
12273 NR = MIN( 3, I-K+1 )
12274 IF( K.GT.M )
12275 $ CALL DCOPY( NR, H( K, K-1 ), 1, V, 1 )
12276 CALL DLARFG( NR, V( 1 ), V( 2 ), 1, T1 )
12277 IF( K.GT.M ) THEN
12278 H( K, K-1 ) = V( 1 )
12279 H( K+1, K-1 ) = ZERO
12280 IF( K.LT.I-1 )
12281 $ H( K+2, K-1 ) = ZERO
12282 ELSE IF( M.GT.L ) THEN
12283 * ==== Use the following instead of
12284 * . H( K, K-1 ) = -H( K, K-1 ) to
12285 * . avoid a bug when v(2) and v(3)
12286 * . underflow. ====
12287 H( K, K-1 ) = H( K, K-1 )*( ONE-T1 )
12288 END IF
12289 V2 = V( 2 )
12290 T2 = T1*V2
12291 IF( NR.EQ.3 ) THEN
12292 V3 = V( 3 )
12293 T3 = T1*V3
12294 *
12295 * Apply G from the left to transform the rows of the matrix
12296 * in columns K to I2.
12297 *
12298 DO 70 J = K, I2
12299 SUM = H( K, J ) + V2*H( K+1, J ) + V3*H( K+2, J )
12300 H( K, J ) = H( K, J ) - SUM*T1
12301 H( K+1, J ) = H( K+1, J ) - SUM*T2
12302 H( K+2, J ) = H( K+2, J ) - SUM*T3
12303 70 CONTINUE
12304 *
12305 * Apply G from the right to transform the columns of the
12306 * matrix in rows I1 to min(K+3,I).
12307 *
12308 DO 80 J = I1, MIN( K+3, I )
12309 SUM = H( J, K ) + V2*H( J, K+1 ) + V3*H( J, K+2 )
12310 H( J, K ) = H( J, K ) - SUM*T1
12311 H( J, K+1 ) = H( J, K+1 ) - SUM*T2
12312 H( J, K+2 ) = H( J, K+2 ) - SUM*T3
12313 80 CONTINUE
12314 *
12315 IF( WANTZ ) THEN
12316 *
12317 * Accumulate transformations in the matrix Z
12318 *
12319 DO 90 J = ILOZ, IHIZ
12320 SUM = Z( J, K ) + V2*Z( J, K+1 ) + V3*Z( J, K+2 )
12321 Z( J, K ) = Z( J, K ) - SUM*T1
12322 Z( J, K+1 ) = Z( J, K+1 ) - SUM*T2
12323 Z( J, K+2 ) = Z( J, K+2 ) - SUM*T3
12324 90 CONTINUE
12325 END IF
12326 ELSE IF( NR.EQ.2 ) THEN
12327 *
12328 * Apply G from the left to transform the rows of the matrix
12329 * in columns K to I2.
12330 *
12331 DO 100 J = K, I2
12332 SUM = H( K, J ) + V2*H( K+1, J )
12333 H( K, J ) = H( K, J ) - SUM*T1
12334 H( K+1, J ) = H( K+1, J ) - SUM*T2
12335 100 CONTINUE
12336 *
12337 * Apply G from the right to transform the columns of the
12338 * matrix in rows I1 to min(K+3,I).
12339 *
12340 DO 110 J = I1, I
12341 SUM = H( J, K ) + V2*H( J, K+1 )
12342 H( J, K ) = H( J, K ) - SUM*T1
12343 H( J, K+1 ) = H( J, K+1 ) - SUM*T2
12344 110 CONTINUE
12345 *
12346 IF( WANTZ ) THEN
12347 *
12348 * Accumulate transformations in the matrix Z
12349 *
12350 DO 120 J = ILOZ, IHIZ
12351 SUM = Z( J, K ) + V2*Z( J, K+1 )
12352 Z( J, K ) = Z( J, K ) - SUM*T1
12353 Z( J, K+1 ) = Z( J, K+1 ) - SUM*T2
12354 120 CONTINUE
12355 END IF
12356 END IF
12357 130 CONTINUE
12358 *
12359 140 CONTINUE
12360 *
12361 * Failure to converge in remaining number of iterations
12362 *
12363 INFO = I
12364 RETURN
12365 *
12366 150 CONTINUE
12367 *
12368 IF( L.EQ.I ) THEN
12369 *
12370 * H(I,I-1) is negligible: one eigenvalue has converged.
12371 *
12372 WR( I ) = H( I, I )
12373 WI( I ) = ZERO
12374 ELSE IF( L.EQ.I-1 ) THEN
12375 *
12376 * H(I-1,I-2) is negligible: a pair of eigenvalues have converged.
12377 *
12378 * Transform the 2-by-2 submatrix to standard Schur form,
12379 * and compute and store the eigenvalues.
12380 *
12381 CALL DLANV2( H( I-1, I-1 ), H( I-1, I ), H( I, I-1 ),
12382 $ H( I, I ), WR( I-1 ), WI( I-1 ), WR( I ), WI( I ),
12383 $ CS, SN )
12384 *
12385 IF( WANTT ) THEN
12386 *
12387 * Apply the transformation to the rest of H.
12388 *
12389 IF( I2.GT.I )
12390 $ CALL DROT( I2-I, H( I-1, I+1 ), LDH, H( I, I+1 ), LDH,
12391 $ CS, SN )
12392 CALL DROT( I-I1-1, H( I1, I-1 ), 1, H( I1, I ), 1, CS, SN )
12393 END IF
12394 IF( WANTZ ) THEN
12395 *
12396 * Apply the transformation to Z.
12397 *
12398 CALL DROT( NZ, Z( ILOZ, I-1 ), 1, Z( ILOZ, I ), 1, CS, SN )
12399 END IF
12400 END IF
12401 *
12402 * return to start of the main loop with new value of I.
12403 *
12404 I = L - 1
12405 GO TO 20
12406 *
12407 160 CONTINUE
12408 RETURN
12409 *
12410 * End of DLAHQR
12411 *
12412 END
12413 C
12414 C-----------------------------------------------------------------------
12415 C-----------------------------------------------------------------------
12416 SUBROUTINE DLAHR2( N, K, NB, A, LDA, TAU, T, LDT, Y, LDY )
12417 *
12418 * -- LAPACK auxiliary routine (version 3.2.1) --
12419 * -- LAPACK is a software package provided by Univ. of Tennessee, --
12420 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
12421 * -- April 2009 --
12422 *
12423 * .. Scalar Arguments ..
12424 INTEGER K, LDA, LDT, LDY, N, NB
12425 * ..
12426 * .. Array Arguments ..
12427 DOUBLE PRECISION A( LDA, * ), T( LDT, NB ), TAU( NB ),
12428 $ Y( LDY, NB )
12429 * ..
12430 *
12431 * Purpose
12432 * =======
12433 *
12434 * DLAHR2 reduces the first NB columns of A real general n-BY-(n-k+1)
12435 * matrix A so that elements below the k-th subdiagonal are zero. The
12436 * reduction is performed by an orthogonal similarity transformation
12437 * Q' * A * Q. The routine returns the matrices V and T which determine
12438 * Q as a block reflector I - V*T*V', and also the matrix Y = A * V * T.
12439 *
12440 * This is an auxiliary routine called by DGEHRD.
12441 *
12442 * Arguments
12443 * =========
12444 *
12445 * N (input) INTEGER
12446 * The order of the matrix A.
12447 *
12448 * K (input) INTEGER
12449 * The offset for the reduction. Elements below the k-th
12450 * subdiagonal in the first NB columns are reduced to zero.
12451 * K < N.
12452 *
12453 * NB (input) INTEGER
12454 * The number of columns to be reduced.
12455 *
12456 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N-K+1)
12457 * On entry, the n-by-(n-k+1) general matrix A.
12458 * On exit, the elements on and above the k-th subdiagonal in
12459 * the first NB columns are overwritten with the corresponding
12460 * elements of the reduced matrix; the elements below the k-th
12461 * subdiagonal, with the array TAU, represent the matrix Q as a
12462 * product of elementary reflectors. The other columns of A are
12463 * unchanged. See Further Details.
12464 *
12465 * LDA (input) INTEGER
12466 * The leading dimension of the array A. LDA >= max(1,N).
12467 *
12468 * TAU (output) DOUBLE PRECISION array, dimension (NB)
12469 * The scalar factors of the elementary reflectors. See Further
12470 * Details.
12471 *
12472 * T (output) DOUBLE PRECISION array, dimension (LDT,NB)
12473 * The upper triangular matrix T.
12474 *
12475 * LDT (input) INTEGER
12476 * The leading dimension of the array T. LDT >= NB.
12477 *
12478 * Y (output) DOUBLE PRECISION array, dimension (LDY,NB)
12479 * The n-by-nb matrix Y.
12480 *
12481 * LDY (input) INTEGER
12482 * The leading dimension of the array Y. LDY >= N.
12483 *
12484 * Further Details
12485 * ===============
12486 *
12487 * The matrix Q is represented as a product of nb elementary reflectors
12488 *
12489 * Q = H(1) H(2) . . . H(nb).
12490 *
12491 * Each H(i) has the form
12492 *
12493 * H(i) = I - tau * v * v'
12494 *
12495 * where tau is a real scalar, and v is a real vector with
12496 * v(1:i+k-1) = 0, v(i+k) = 1; v(i+k+1:n) is stored on exit in
12497 * A(i+k+1:n,i), and tau in TAU(i).
12498 *
12499 * The elements of the vectors v together form the (n-k+1)-by-nb matrix
12500 * V which is needed, with T and Y, to apply the transformation to the
12501 * unreduced part of the matrix, using an update of the form:
12502 * A := (I - V*T*V') * (A - Y*V').
12503 *
12504 * The contents of A on exit are illustrated by the following example
12505 * with n = 7, k = 3 and nb = 2:
12506 *
12507 * ( a a a a a )
12508 * ( a a a a a )
12509 * ( a a a a a )
12510 * ( h h a a a )
12511 * ( v1 h a a a )
12512 * ( v1 v2 a a a )
12513 * ( v1 v2 a a a )
12514 *
12515 * where a denotes an element of the original matrix A, h denotes a
12516 * modified element of the upper Hessenberg matrix H, and vi denotes an
12517 * element of the vector defining H(i).
12518 *
12519 * This subroutine is a slight modification of LAPACK-3.0's DLAHRD
12520 * incorporating improvements proposed by Quintana-Orti and Van de
12521 * Gejin. Note that the entries of A(1:K,2:NB) differ from those
12522 * returned by the original LAPACK-3.0's DLAHRD routine. (This
12523 * subroutine is not backward compatible with LAPACK-3.0's DLAHRD.)
12524 *
12525 * References
12526 * ==========
12527 *
12528 * Gregorio Quintana-Orti and Robert van de Geijn, "Improving the
12529 * performance of reduction to Hessenberg form," ACM Transactions on
12530 * Mathematical Software, 32(2):180-194, June 2006.
12531 *
12532 * =====================================================================
12533 *
12534 * .. Parameters ..
12535 DOUBLE PRECISION ZERO, ONE
12536 PARAMETER ( ZERO = 0.0D+0,
12537 $ ONE = 1.0D+0 )
12538 * ..
12539 * .. Local Scalars ..
12540 INTEGER I
12541 DOUBLE PRECISION EI
12542 * ..
12543 * .. External Subroutines ..
12544 EXTERNAL DAXPY, DCOPY, DGEMM, DGEMV, DLACPY,
12545 $ DLARFG, DSCAL, DTRMM, DTRMV
12546 * ..
12547 * .. Intrinsic Functions ..
12548 INTRINSIC MIN
12549 * ..
12550 * .. Executable Statements ..
12551 *
12552 * Quick return if possible
12553 *
12554 IF( N.LE.1 )
12555 $ RETURN
12556 *
12557 DO 10 I = 1, NB
12558 IF( I.GT.1 ) THEN
12559 *
12560 * Update A(K+1:N,I)
12561 *
12562 * Update I-th column of A - Y * V'
12563 *
12564 CALL DGEMV( 'NO TRANSPOSE', N-K, I-1, -ONE, Y(K+1,1), LDY,
12565 $ A( K+I-1, 1 ), LDA, ONE, A( K+1, I ), 1 )
12566 *
12567 * Apply I - V * T' * V' to this column (call it b) from the
12568 * left, using the last column of T as workspace
12569 *
12570 * Let V = ( V1 ) and b = ( b1 ) (first I-1 rows)
12571 * ( V2 ) ( b2 )
12572 *
12573 * where V1 is unit lower triangular
12574 *
12575 * w := V1' * b1
12576 *
12577 CALL DCOPY( I-1, A( K+1, I ), 1, T( 1, NB ), 1 )
12578 CALL DTRMV( 'Lower', 'Transpose', 'UNIT',
12579 $ I-1, A( K+1, 1 ),
12580 $ LDA, T( 1, NB ), 1 )
12581 *
12582 * w := w + V2'*b2
12583 *
12584 CALL DGEMV( 'Transpose', N-K-I+1, I-1,
12585 $ ONE, A( K+I, 1 ),
12586 $ LDA, A( K+I, I ), 1, ONE, T( 1, NB ), 1 )
12587 *
12588 * w := T'*w
12589 *
12590 CALL DTRMV( 'Upper', 'Transpose', 'NON-UNIT',
12591 $ I-1, T, LDT,
12592 $ T( 1, NB ), 1 )
12593 *
12594 * b2 := b2 - V2*w
12595 *
12596 CALL DGEMV( 'NO TRANSPOSE', N-K-I+1, I-1, -ONE,
12597 $ A( K+I, 1 ),
12598 $ LDA, T( 1, NB ), 1, ONE, A( K+I, I ), 1 )
12599 *
12600 * b1 := b1 - V1*w
12601 *
12602 CALL DTRMV( 'Lower', 'NO TRANSPOSE',
12603 $ 'UNIT', I-1,
12604 $ A( K+1, 1 ), LDA, T( 1, NB ), 1 )
12605 CALL DAXPY( I-1, -ONE, T( 1, NB ), 1, A( K+1, I ), 1 )
12606 *
12607 A( K+I-1, I-1 ) = EI
12608 END IF
12609 *
12610 * Generate the elementary reflector H(I) to annihilate
12611 * A(K+I+1:N,I)
12612 *
12613 CALL DLARFG( N-K-I+1, A( K+I, I ), A( MIN( K+I+1, N ), I ), 1,
12614 $ TAU( I ) )
12615 EI = A( K+I, I )
12616 A( K+I, I ) = ONE
12617 *
12618 * Compute Y(K+1:N,I)
12619 *
12620 CALL DGEMV( 'NO TRANSPOSE', N-K, N-K-I+1,
12621 $ ONE, A( K+1, I+1 ),
12622 $ LDA, A( K+I, I ), 1, ZERO, Y( K+1, I ), 1 )
12623 CALL DGEMV( 'Transpose', N-K-I+1, I-1,
12624 $ ONE, A( K+I, 1 ), LDA,
12625 $ A( K+I, I ), 1, ZERO, T( 1, I ), 1 )
12626 CALL DGEMV( 'NO TRANSPOSE', N-K, I-1, -ONE,
12627 $ Y( K+1, 1 ), LDY,
12628 $ T( 1, I ), 1, ONE, Y( K+1, I ), 1 )
12629 CALL DSCAL( N-K, TAU( I ), Y( K+1, I ), 1 )
12630 *
12631 * Compute T(1:I,I)
12632 *
12633 CALL DSCAL( I-1, -TAU( I ), T( 1, I ), 1 )
12634 CALL DTRMV( 'Upper', 'No Transpose', 'NON-UNIT',
12635 $ I-1, T, LDT,
12636 $ T( 1, I ), 1 )
12637 T( I, I ) = TAU( I )
12638 *
12639 10 CONTINUE
12640 A( K+NB, NB ) = EI
12641 *
12642 * Compute Y(1:K,1:NB)
12643 *
12644 CALL DLACPY( 'ALL', K, NB, A( 1, 2 ), LDA, Y, LDY )
12645 CALL DTRMM( 'RIGHT', 'Lower', 'NO TRANSPOSE',
12646 $ 'UNIT', K, NB,
12647 $ ONE, A( K+1, 1 ), LDA, Y, LDY )
12648 IF( N.GT.K+NB )
12649 $ CALL DGEMM( 'NO TRANSPOSE', 'NO TRANSPOSE', K,
12650 $ NB, N-K-NB, ONE,
12651 $ A( 1, 2+NB ), LDA, A( K+1+NB, 1 ), LDA, ONE, Y,
12652 $ LDY )
12653 CALL DTRMM( 'RIGHT', 'Upper', 'NO TRANSPOSE',
12654 $ 'NON-UNIT', K, NB,
12655 $ ONE, T, LDT, Y, LDY )
12656 *
12657 RETURN
12658 *
12659 * End of DLAHR2
12660 *
12661 END
12662 C
12663 C-----------------------------------------------------------------------
12664 C-----------------------------------------------------------------------
12665 SUBROUTINE DLALN2( LTRANS, NA, NW, SMIN, CA, A, LDA, D1, D2, B,
12666 $ LDB, WR, WI, X, LDX, SCALE, XNORM, INFO )
12667 *
12668 * -- LAPACK auxiliary routine (version 3.2) --
12669 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
12670 * November 2006
12671 *
12672 * .. Scalar Arguments ..
12673 LOGICAL LTRANS
12674 INTEGER INFO, LDA, LDB, LDX, NA, NW
12675 DOUBLE PRECISION CA, D1, D2, SCALE, SMIN, WI, WR, XNORM
12676 * ..
12677 * .. Array Arguments ..
12678 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), X( LDX, * )
12679 * ..
12680 *
12681 * Purpose
12682 * =======
12683 *
12684 * DLALN2 solves a system of the form (ca A - w D ) X = s B
12685 * or (ca A' - w D) X = s B with possible scaling ("s") and
12686 * perturbation of A. (A' means A-transpose.)
12687 *
12688 * A is an NA x NA real matrix, ca is a real scalar, D is an NA x NA
12689 * real diagonal matrix, w is a real or complex value, and X and B are
12690 * NA x 1 matrices -- real if w is real, complex if w is complex. NA
12691 * may be 1 or 2.
12692 *
12693 * If w is complex, X and B are represented as NA x 2 matrices,
12694 * the first column of each being the real part and the second
12695 * being the imaginary part.
12696 *
12697 * "s" is a scaling factor (.LE. 1), computed by DLALN2, which is
12698 * so chosen that X can be computed without overflow. X is further
12699 * scaled if necessary to assure that norm(ca A - w D)*norm(X) is less
12700 * than overflow.
12701 *
12702 * If both singular values of (ca A - w D) are less than SMIN,
12703 * SMIN*identity will be used instead of (ca A - w D). If only one
12704 * singular value is less than SMIN, one element of (ca A - w D) will be
12705 * perturbed enough to make the smallest singular value roughly SMIN.
12706 * If both singular values are at least SMIN, (ca A - w D) will not be
12707 * perturbed. In any case, the perturbation will be at most some small
12708 * multiple of max( SMIN, ulp*norm(ca A - w D) ). The singular values
12709 * are computed by infinity-norm approximations, and thus will only be
12710 * correct to a factor of 2 or so.
12711 *
12712 * Note: all input quantities are assumed to be smaller than overflow
12713 * by a reasonable factor. (See BIGNUM.)
12714 *
12715 * Arguments
12716 * ==========
12717 *
12718 * LTRANS (input) LOGICAL
12719 * =.TRUE.: A-transpose will be used.
12720 * =.FALSE.: A will be used (not transposed.)
12721 *
12722 * NA (input) INTEGER
12723 * The size of the matrix A. It may (only) be 1 or 2.
12724 *
12725 * NW (input) INTEGER
12726 * 1 if "w" is real, 2 if "w" is complex. It may only be 1
12727 * or 2.
12728 *
12729 * SMIN (input) DOUBLE PRECISION
12730 * The desired lower bound on the singular values of A. This
12731 * should be a safe distance away from underflow or overflow,
12732 * say, between (underflow/machine precision) and (machine
12733 * precision * overflow ). (See BIGNUM and ULP.)
12734 *
12735 * CA (input) DOUBLE PRECISION
12736 * The coefficient c, which A is multiplied by.
12737 *
12738 * A (input) DOUBLE PRECISION array, dimension (LDA,NA)
12739 * The NA x NA matrix A.
12740 *
12741 * LDA (input) INTEGER
12742 * The leading dimension of A. It must be at least NA.
12743 *
12744 * D1 (input) DOUBLE PRECISION
12745 * The 1,1 element in the diagonal matrix D.
12746 *
12747 * D2 (input) DOUBLE PRECISION
12748 * The 2,2 element in the diagonal matrix D. Not used if NW=1.
12749 *
12750 * B (input) DOUBLE PRECISION array, dimension (LDB,NW)
12751 * The NA x NW matrix B (right-hand side). If NW=2 ("w" is
12752 * complex), column 1 contains the real part of B and column 2
12753 * contains the imaginary part.
12754 *
12755 * LDB (input) INTEGER
12756 * The leading dimension of B. It must be at least NA.
12757 *
12758 * WR (input) DOUBLE PRECISION
12759 * The real part of the scalar "w".
12760 *
12761 * WI (input) DOUBLE PRECISION
12762 * The imaginary part of the scalar "w". Not used if NW=1.
12763 *
12764 * X (output) DOUBLE PRECISION array, dimension (LDX,NW)
12765 * The NA x NW matrix X (unknowns), as computed by DLALN2.
12766 * If NW=2 ("w" is complex), on exit, column 1 will contain
12767 * the real part of X and column 2 will contain the imaginary
12768 * part.
12769 *
12770 * LDX (input) INTEGER
12771 * The leading dimension of X. It must be at least NA.
12772 *
12773 * SCALE (output) DOUBLE PRECISION
12774 * The scale factor that B must be multiplied by to insure
12775 * that overflow does not occur when computing X. Thus,
12776 * (ca A - w D) X will be SCALE*B, not B (ignoring
12777 * perturbations of A.) It will be at most 1.
12778 *
12779 * XNORM (output) DOUBLE PRECISION
12780 * The infinity-norm of X, when X is regarded as an NA x NW
12781 * real matrix.
12782 *
12783 * INFO (output) INTEGER
12784 * An error flag. It will be set to zero if no error occurs,
12785 * a negative number if an argument is in error, or a positive
12786 * number if ca A - w D had to be perturbed.
12787 * The possible values are:
12788 * = 0: No error occurred, and (ca A - w D) did not have to be
12789 * perturbed.
12790 * = 1: (ca A - w D) had to be perturbed to make its smallest
12791 * (or only) singular value greater than SMIN.
12792 * NOTE: In the interests of speed, this routine does not
12793 * check the inputs for errors.
12794 *
12795 * =====================================================================
12796 *
12797 * .. Parameters ..
12798 DOUBLE PRECISION ZERO, ONE
12799 PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
12800 DOUBLE PRECISION TWO
12801 PARAMETER ( TWO = 2.0D0 )
12802 * ..
12803 * .. Local Scalars ..
12804 INTEGER ICMAX, J
12805 DOUBLE PRECISION BBND, BI1, BI2, BIGNUM, BNORM, BR1, BR2, CI21,
12806 $ CI22, CMAX, CNORM, CR21, CR22, CSI, CSR, LI21,
12807 $ LR21, SMINI, SMLNUM, TEMP, U22ABS, UI11, UI11R,
12808 $ UI12, UI12S, UI22, UR11, UR11R, UR12, UR12S,
12809 $ UR22, XI1, XI2, XR1, XR2
12810 * ..
12811 * .. Local Arrays ..
12812 LOGICAL RSWAP( 4 ), ZSWAP( 4 )
12813 INTEGER IPIVOT( 4, 4 )
12814 DOUBLE PRECISION CI( 2, 2 ), CIV( 4 ), CR( 2, 2 ), CRV( 4 )
12815 * ..
12816 * .. External Functions ..
12817 DOUBLE PRECISION DLAMCH
12818 EXTERNAL DLAMCH
12819 * ..
12820 * .. External Subroutines ..
12821 EXTERNAL DLADIV
12822 * ..
12823 * .. Intrinsic Functions ..
12824 INTRINSIC ABS, MAX
12825 * ..
12826 * .. Equivalences ..
12827 EQUIVALENCE ( CI( 1, 1 ), CIV( 1 ) ),
12828 $ ( CR( 1, 1 ), CRV( 1 ) )
12829 * ..
12830 * .. Data statements ..
12831 DATA ZSWAP / .FALSE., .FALSE., .TRUE., .TRUE. /
12832 DATA RSWAP / .FALSE., .TRUE., .FALSE., .TRUE. /
12833 DATA IPIVOT / 1, 2, 3, 4, 2, 1, 4, 3, 3, 4, 1, 2, 4,
12834 $ 3, 2, 1 /
12835 * ..
12836 * .. Executable Statements ..
12837 *
12838 * Compute BIGNUM
12839 *
12840 SMLNUM = TWO*DLAMCH( 'Safe minimum' )
12841 BIGNUM = ONE / SMLNUM
12842 SMINI = MAX( SMIN, SMLNUM )
12843 *
12844 * Don't check for input errors
12845 *
12846 INFO = 0
12847 *
12848 * Standard Initializations
12849 *
12850 SCALE = ONE
12851 *
12852 IF( NA.EQ.1 ) THEN
12853 *
12854 * 1 x 1 (i.e., scalar) system C X = B
12855 *
12856 IF( NW.EQ.1 ) THEN
12857 *
12858 * Real 1x1 system.
12859 *
12860 * C = ca A - w D
12861 *
12862 CSR = CA*A( 1, 1 ) - WR*D1
12863 CNORM = ABS( CSR )
12864 *
12865 * If | C | < SMINI, use C = SMINI
12866 *
12867 IF( CNORM.LT.SMINI ) THEN
12868 CSR = SMINI
12869 CNORM = SMINI
12870 INFO = 1
12871 END IF
12872 *
12873 * Check scaling for X = B / C
12874 *
12875 BNORM = ABS( B( 1, 1 ) )
12876 IF( CNORM.LT.ONE .AND. BNORM.GT.ONE ) THEN
12877 IF( BNORM.GT.BIGNUM*CNORM )
12878 $ SCALE = ONE / BNORM
12879 END IF
12880 *
12881 * Compute X
12882 *
12883 X( 1, 1 ) = ( B( 1, 1 )*SCALE ) / CSR
12884 XNORM = ABS( X( 1, 1 ) )
12885 ELSE
12886 *
12887 * Complex 1x1 system (w is complex)
12888 *
12889 * C = ca A - w D
12890 *
12891 CSR = CA*A( 1, 1 ) - WR*D1
12892 CSI = -WI*D1
12893 CNORM = ABS( CSR ) + ABS( CSI )
12894 *
12895 * If | C | < SMINI, use C = SMINI
12896 *
12897 IF( CNORM.LT.SMINI ) THEN
12898 CSR = SMINI
12899 CSI = ZERO
12900 CNORM = SMINI
12901 INFO = 1
12902 END IF
12903 *
12904 * Check scaling for X = B / C
12905 *
12906 BNORM = ABS( B( 1, 1 ) ) + ABS( B( 1, 2 ) )
12907 IF( CNORM.LT.ONE .AND. BNORM.GT.ONE ) THEN
12908 IF( BNORM.GT.BIGNUM*CNORM )
12909 $ SCALE = ONE / BNORM
12910 END IF
12911 *
12912 * Compute X
12913 *
12914 CALL DLADIV( SCALE*B( 1, 1 ), SCALE*B( 1, 2 ), CSR, CSI,
12915 $ X( 1, 1 ), X( 1, 2 ) )
12916 XNORM = ABS( X( 1, 1 ) ) + ABS( X( 1, 2 ) )
12917 END IF
12918 *
12919 ELSE
12920 *
12921 * 2x2 System
12922 *
12923 * Compute the real part of C = ca A - w D (or ca A' - w D )
12924 *
12925 CR( 1, 1 ) = CA*A( 1, 1 ) - WR*D1
12926 CR( 2, 2 ) = CA*A( 2, 2 ) - WR*D2
12927 IF( LTRANS ) THEN
12928 CR( 1, 2 ) = CA*A( 2, 1 )
12929 CR( 2, 1 ) = CA*A( 1, 2 )
12930 ELSE
12931 CR( 2, 1 ) = CA*A( 2, 1 )
12932 CR( 1, 2 ) = CA*A( 1, 2 )
12933 END IF
12934 *
12935 IF( NW.EQ.1 ) THEN
12936 *
12937 * Real 2x2 system (w is real)
12938 *
12939 * Find the largest element in C
12940 *
12941 CMAX = ZERO
12942 ICMAX = 0
12943 *
12944 DO 10 J = 1, 4
12945 IF( ABS( CRV( J ) ).GT.CMAX ) THEN
12946 CMAX = ABS( CRV( J ) )
12947 ICMAX = J
12948 END IF
12949 10 CONTINUE
12950 *
12951 * If norm(C) < SMINI, use SMINI*identity.
12952 *
12953 IF( CMAX.LT.SMINI ) THEN
12954 BNORM = MAX( ABS( B( 1, 1 ) ), ABS( B( 2, 1 ) ) )
12955 IF( SMINI.LT.ONE .AND. BNORM.GT.ONE ) THEN
12956 IF( BNORM.GT.BIGNUM*SMINI )
12957 $ SCALE = ONE / BNORM
12958 END IF
12959 TEMP = SCALE / SMINI
12960 X( 1, 1 ) = TEMP*B( 1, 1 )
12961 X( 2, 1 ) = TEMP*B( 2, 1 )
12962 XNORM = TEMP*BNORM
12963 INFO = 1
12964 RETURN
12965 END IF
12966 *
12967 * Gaussian elimination with complete pivoting.
12968 *
12969 UR11 = CRV( ICMAX )
12970 CR21 = CRV( IPIVOT( 2, ICMAX ) )
12971 UR12 = CRV( IPIVOT( 3, ICMAX ) )
12972 CR22 = CRV( IPIVOT( 4, ICMAX ) )
12973 UR11R = ONE / UR11
12974 LR21 = UR11R*CR21
12975 UR22 = CR22 - UR12*LR21
12976 *
12977 * If smaller pivot < SMINI, use SMINI
12978 *
12979 IF( ABS( UR22 ).LT.SMINI ) THEN
12980 UR22 = SMINI
12981 INFO = 1
12982 END IF
12983 IF( RSWAP( ICMAX ) ) THEN
12984 BR1 = B( 2, 1 )
12985 BR2 = B( 1, 1 )
12986 ELSE
12987 BR1 = B( 1, 1 )
12988 BR2 = B( 2, 1 )
12989 END IF
12990 BR2 = BR2 - LR21*BR1
12991 BBND = MAX( ABS( BR1*( UR22*UR11R ) ), ABS( BR2 ) )
12992 IF( BBND.GT.ONE .AND. ABS( UR22 ).LT.ONE ) THEN
12993 IF( BBND.GE.BIGNUM*ABS( UR22 ) )
12994 $ SCALE = ONE / BBND
12995 END IF
12996 *
12997 XR2 = ( BR2*SCALE ) / UR22
12998 XR1 = ( SCALE*BR1 )*UR11R - XR2*( UR11R*UR12 )
12999 IF( ZSWAP( ICMAX ) ) THEN
13000 X( 1, 1 ) = XR2
13001 X( 2, 1 ) = XR1
13002 ELSE
13003 X( 1, 1 ) = XR1
13004 X( 2, 1 ) = XR2
13005 END IF
13006 XNORM = MAX( ABS( XR1 ), ABS( XR2 ) )
13007 *
13008 * Further scaling if norm(A) norm(X) > overflow
13009 *
13010 IF( XNORM.GT.ONE .AND. CMAX.GT.ONE ) THEN
13011 IF( XNORM.GT.BIGNUM / CMAX ) THEN
13012 TEMP = CMAX / BIGNUM
13013 X( 1, 1 ) = TEMP*X( 1, 1 )
13014 X( 2, 1 ) = TEMP*X( 2, 1 )
13015 XNORM = TEMP*XNORM
13016 SCALE = TEMP*SCALE
13017 END IF
13018 END IF
13019 ELSE
13020 *
13021 * Complex 2x2 system (w is complex)
13022 *
13023 * Find the largest element in C
13024 *
13025 CI( 1, 1 ) = -WI*D1
13026 CI( 2, 1 ) = ZERO
13027 CI( 1, 2 ) = ZERO
13028 CI( 2, 2 ) = -WI*D2
13029 CMAX = ZERO
13030 ICMAX = 0
13031 *
13032 DO 20 J = 1, 4
13033 IF( ABS( CRV( J ) )+ABS( CIV( J ) ).GT.CMAX ) THEN
13034 CMAX = ABS( CRV( J ) ) + ABS( CIV( J ) )
13035 ICMAX = J
13036 END IF
13037 20 CONTINUE
13038 *
13039 * If norm(C) < SMINI, use SMINI*identity.
13040 *
13041 IF( CMAX.LT.SMINI ) THEN
13042 BNORM = MAX( ABS( B( 1, 1 ) )+ABS( B( 1, 2 ) ),
13043 $ ABS( B( 2, 1 ) )+ABS( B( 2, 2 ) ) )
13044 IF( SMINI.LT.ONE .AND. BNORM.GT.ONE ) THEN
13045 IF( BNORM.GT.BIGNUM*SMINI )
13046 $ SCALE = ONE / BNORM
13047 END IF
13048 TEMP = SCALE / SMINI
13049 X( 1, 1 ) = TEMP*B( 1, 1 )
13050 X( 2, 1 ) = TEMP*B( 2, 1 )
13051 X( 1, 2 ) = TEMP*B( 1, 2 )
13052 X( 2, 2 ) = TEMP*B( 2, 2 )
13053 XNORM = TEMP*BNORM
13054 INFO = 1
13055 RETURN
13056 END IF
13057 *
13058 * Gaussian elimination with complete pivoting.
13059 *
13060 UR11 = CRV( ICMAX )
13061 UI11 = CIV( ICMAX )
13062 CR21 = CRV( IPIVOT( 2, ICMAX ) )
13063 CI21 = CIV( IPIVOT( 2, ICMAX ) )
13064 UR12 = CRV( IPIVOT( 3, ICMAX ) )
13065 UI12 = CIV( IPIVOT( 3, ICMAX ) )
13066 CR22 = CRV( IPIVOT( 4, ICMAX ) )
13067 CI22 = CIV( IPIVOT( 4, ICMAX ) )
13068 IF( ICMAX.EQ.1 .OR. ICMAX.EQ.4 ) THEN
13069 *
13070 * Code when off-diagonals of pivoted C are real
13071 *
13072 IF( ABS( UR11 ).GT.ABS( UI11 ) ) THEN
13073 TEMP = UI11 / UR11
13074 UR11R = ONE / ( UR11*( ONE+TEMP**2 ) )
13075 UI11R = -TEMP*UR11R
13076 ELSE
13077 TEMP = UR11 / UI11
13078 UI11R = -ONE / ( UI11*( ONE+TEMP**2 ) )
13079 UR11R = -TEMP*UI11R
13080 END IF
13081 LR21 = CR21*UR11R
13082 LI21 = CR21*UI11R
13083 UR12S = UR12*UR11R
13084 UI12S = UR12*UI11R
13085 UR22 = CR22 - UR12*LR21
13086 UI22 = CI22 - UR12*LI21
13087 ELSE
13088 *
13089 * Code when diagonals of pivoted C are real
13090 *
13091 UR11R = ONE / UR11
13092 UI11R = ZERO
13093 LR21 = CR21*UR11R
13094 LI21 = CI21*UR11R
13095 UR12S = UR12*UR11R
13096 UI12S = UI12*UR11R
13097 UR22 = CR22 - UR12*LR21 + UI12*LI21
13098 UI22 = -UR12*LI21 - UI12*LR21
13099 END IF
13100 U22ABS = ABS( UR22 ) + ABS( UI22 )
13101 *
13102 * If smaller pivot < SMINI, use SMINI
13103 *
13104 IF( U22ABS.LT.SMINI ) THEN
13105 UR22 = SMINI
13106 UI22 = ZERO
13107 INFO = 1
13108 END IF
13109 IF( RSWAP( ICMAX ) ) THEN
13110 BR2 = B( 1, 1 )
13111 BR1 = B( 2, 1 )
13112 BI2 = B( 1, 2 )
13113 BI1 = B( 2, 2 )
13114 ELSE
13115 BR1 = B( 1, 1 )
13116 BR2 = B( 2, 1 )
13117 BI1 = B( 1, 2 )
13118 BI2 = B( 2, 2 )
13119 END IF
13120 BR2 = BR2 - LR21*BR1 + LI21*BI1
13121 BI2 = BI2 - LI21*BR1 - LR21*BI1
13122 BBND = MAX( ( ABS( BR1 )+ABS( BI1 ) )*
13123 $ ( U22ABS*( ABS( UR11R )+ABS( UI11R ) ) ),
13124 $ ABS( BR2 )+ABS( BI2 ) )
13125 IF( BBND.GT.ONE .AND. U22ABS.LT.ONE ) THEN
13126 IF( BBND.GE.BIGNUM*U22ABS ) THEN
13127 SCALE = ONE / BBND
13128 BR1 = SCALE*BR1
13129 BI1 = SCALE*BI1
13130 BR2 = SCALE*BR2
13131 BI2 = SCALE*BI2
13132 END IF
13133 END IF
13134 *
13135 CALL DLADIV( BR2, BI2, UR22, UI22, XR2, XI2 )
13136 XR1 = UR11R*BR1 - UI11R*BI1 - UR12S*XR2 + UI12S*XI2
13137 XI1 = UI11R*BR1 + UR11R*BI1 - UI12S*XR2 - UR12S*XI2
13138 IF( ZSWAP( ICMAX ) ) THEN
13139 X( 1, 1 ) = XR2
13140 X( 2, 1 ) = XR1
13141 X( 1, 2 ) = XI2
13142 X( 2, 2 ) = XI1
13143 ELSE
13144 X( 1, 1 ) = XR1
13145 X( 2, 1 ) = XR2
13146 X( 1, 2 ) = XI1
13147 X( 2, 2 ) = XI2
13148 END IF
13149 XNORM = MAX( ABS( XR1 )+ABS( XI1 ), ABS( XR2 )+ABS( XI2 ) )
13150 *
13151 * Further scaling if norm(A) norm(X) > overflow
13152 *
13153 IF( XNORM.GT.ONE .AND. CMAX.GT.ONE ) THEN
13154 IF( XNORM.GT.BIGNUM / CMAX ) THEN
13155 TEMP = CMAX / BIGNUM
13156 X( 1, 1 ) = TEMP*X( 1, 1 )
13157 X( 2, 1 ) = TEMP*X( 2, 1 )
13158 X( 1, 2 ) = TEMP*X( 1, 2 )
13159 X( 2, 2 ) = TEMP*X( 2, 2 )
13160 XNORM = TEMP*XNORM
13161 SCALE = TEMP*SCALE
13162 END IF
13163 END IF
13164 END IF
13165 END IF
13166 *
13167 RETURN
13168 *
13169 * End of DLALN2
13170 *
13171 END
13172 C
13173 C-----------------------------------------------------------------------
13174 C-----------------------------------------------------------------------
13175 SUBROUTINE DLANV2( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN )
13176 *
13177 * -- LAPACK auxiliary routine (version 3.2.2) --
13178 * -- LAPACK is a software package provided by Univ. of Tennessee, --
13179 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
13180 * June 2010
13181 *
13182 * .. Scalar Arguments ..
13183 DOUBLE PRECISION A, B, C, CS, D, RT1I, RT1R, RT2I, RT2R, SN
13184 * ..
13185 *
13186 * Purpose
13187 * =======
13188 *
13189 * DLANV2 computes the Schur factorization of a real 2-by-2 nonsymmetric
13190 * matrix in standard form:
13191 *
13192 * [ A B ] = [ CS -SN ] [ AA BB ] [ CS SN ]
13193 * [ C D ] [ SN CS ] [ CC DD ] [-SN CS ]
13194 *
13195 * where either
13196 * 1) CC = 0 so that AA and DD are real eigenvalues of the matrix, or
13197 * 2) AA = DD and BB*CC < 0, so that AA + or - sqrt(BB*CC) are complex
13198 * conjugate eigenvalues.
13199 *
13200 * Arguments
13201 * =========
13202 *
13203 * A (input/output) DOUBLE PRECISION
13204 * B (input/output) DOUBLE PRECISION
13205 * C (input/output) DOUBLE PRECISION
13206 * D (input/output) DOUBLE PRECISION
13207 * On entry, the elements of the input matrix.
13208 * On exit, they are overwritten by the elements of the
13209 * standardised Schur form.
13210 *
13211 * RT1R (output) DOUBLE PRECISION
13212 * RT1I (output) DOUBLE PRECISION
13213 * RT2R (output) DOUBLE PRECISION
13214 * RT2I (output) DOUBLE PRECISION
13215 * The real and imaginary parts of the eigenvalues. If the
13216 * eigenvalues are a complex conjugate pair, RT1I > 0.
13217 *
13218 * CS (output) DOUBLE PRECISION
13219 * SN (output) DOUBLE PRECISION
13220 * Parameters of the rotation matrix.
13221 *
13222 * Further Details
13223 * ===============
13224 *
13225 * Modified by V. Sima, Research Institute for Informatics, Bucharest,
13226 * Romania, to reduce the risk of cancellation errors,
13227 * when computing real eigenvalues, and to ensure, if possible, that
13228 * abs(RT1R) >= abs(RT2R).
13229 *
13230 * =====================================================================
13231 *
13232 * .. Parameters ..
13233 DOUBLE PRECISION ZERO, HALF, ONE
13234 PARAMETER ( ZERO = 0.0D+0, HALF = 0.5D+0, ONE = 1.0D+0 )
13235 DOUBLE PRECISION MULTPL
13236 PARAMETER ( MULTPL = 4.0D+0 )
13237 * ..
13238 * .. Local Scalars ..
13239 DOUBLE PRECISION AA, BB, BCMAX, BCMIS, CC, CS1, DD, EPS, P, SAB,
13240 $ SAC, SCALE, SIGMA, SN1, TAU, TEMP, Z
13241 * ..
13242 * .. External Functions ..
13243 DOUBLE PRECISION DLAMCH, DLAPY2
13244 EXTERNAL DLAMCH, DLAPY2
13245 * ..
13246 * .. Intrinsic Functions ..
13247 INTRINSIC ABS, MAX, MIN, SIGN, SQRT
13248 * ..
13249 * .. Executable Statements ..
13250 *
13251 EPS = DLAMCH( 'P' )
13252 IF( C.EQ.ZERO ) THEN
13253 CS = ONE
13254 SN = ZERO
13255 GO TO 10
13256 *
13257 ELSE IF( B.EQ.ZERO ) THEN
13258 *
13259 * Swap rows and columns
13260 *
13261 CS = ZERO
13262 SN = ONE
13263 TEMP = D
13264 D = A
13265 A = TEMP
13266 B = -C
13267 C = ZERO
13268 GO TO 10
13269 ELSE IF( ( A-D ).EQ.ZERO .AND. SIGN( ONE, B ).NE.SIGN( ONE, C ) )
13270 $ THEN
13271 CS = ONE
13272 SN = ZERO
13273 GO TO 10
13274 ELSE
13275 *
13276 TEMP = A - D
13277 P = HALF*TEMP
13278 BCMAX = MAX( ABS( B ), ABS( C ) )
13279 BCMIS = MIN( ABS( B ), ABS( C ) )*SIGN( ONE, B )*SIGN( ONE, C )
13280 SCALE = MAX( ABS( P ), BCMAX )
13281 Z = ( P / SCALE )*P + ( BCMAX / SCALE )*BCMIS
13282 *
13283 * If Z is of the order of the machine accuracy, postpone the
13284 * decision on the nature of eigenvalues
13285 *
13286 IF( Z.GE.MULTPL*EPS ) THEN
13287 *
13288 * Real eigenvalues. Compute A and D.
13289 *
13290 Z = P + SIGN( SQRT( SCALE )*SQRT( Z ), P )
13291 A = D + Z
13292 D = D - ( BCMAX / Z )*BCMIS
13293 *
13294 * Compute B and the rotation matrix
13295 *
13296 TAU = DLAPY2( C, Z )
13297 CS = Z / TAU
13298 SN = C / TAU
13299 B = B - C
13300 C = ZERO
13301 ELSE
13302 *
13303 * Complex eigenvalues, or real (almost) equal eigenvalues.
13304 * Make diagonal elements equal.
13305 *
13306 SIGMA = B + C
13307 TAU = DLAPY2( SIGMA, TEMP )
13308 CS = SQRT( HALF*( ONE+ABS( SIGMA ) / TAU ) )
13309 SN = -( P / ( TAU*CS ) )*SIGN( ONE, SIGMA )
13310 *
13311 * Compute [ AA BB ] = [ A B ] [ CS -SN ]
13312 * [ CC DD ] [ C D ] [ SN CS ]
13313 *
13314 AA = A*CS + B*SN
13315 BB = -A*SN + B*CS
13316 CC = C*CS + D*SN
13317 DD = -C*SN + D*CS
13318 *
13319 * Compute [ A B ] = [ CS SN ] [ AA BB ]
13320 * [ C D ] [-SN CS ] [ CC DD ]
13321 *
13322 A = AA*CS + CC*SN
13323 B = BB*CS + DD*SN
13324 C = -AA*SN + CC*CS
13325 D = -BB*SN + DD*CS
13326 *
13327 TEMP = HALF*( A+D )
13328 A = TEMP
13329 D = TEMP
13330 *
13331 IF( C.NE.ZERO ) THEN
13332 IF( B.NE.ZERO ) THEN
13333 IF( SIGN( ONE, B ).EQ.SIGN( ONE, C ) ) THEN
13334 *
13335 * Real eigenvalues: reduce to upper triangular form
13336 *
13337 SAB = SQRT( ABS( B ) )
13338 SAC = SQRT( ABS( C ) )
13339 P = SIGN( SAB*SAC, C )
13340 TAU = ONE / SQRT( ABS( B+C ) )
13341 A = TEMP + P
13342 D = TEMP - P
13343 B = B - C
13344 C = ZERO
13345 CS1 = SAB*TAU
13346 SN1 = SAC*TAU
13347 TEMP = CS*CS1 - SN*SN1
13348 SN = CS*SN1 + SN*CS1
13349 CS = TEMP
13350 END IF
13351 ELSE
13352 B = -C
13353 C = ZERO
13354 TEMP = CS
13355 CS = -SN
13356 SN = TEMP
13357 END IF
13358 END IF
13359 END IF
13360 *
13361 END IF
13362 *
13363 10 CONTINUE
13364 *
13365 * Store eigenvalues in (RT1R,RT1I) and (RT2R,RT2I).
13366 *
13367 RT1R = A
13368 RT2R = D
13369 IF( C.EQ.ZERO ) THEN
13370 RT1I = ZERO
13371 RT2I = ZERO
13372 ELSE
13373 RT1I = SQRT( ABS( B ) )*SQRT( ABS( C ) )
13374 RT2I = -RT1I
13375 END IF
13376 RETURN
13377 *
13378 * End of DLANV2
13379 *
13380 END
13381 C
13382 C-----------------------------------------------------------------------
13383 C-----------------------------------------------------------------------
13384 SUBROUTINE DLAQR0( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI,
13385 $ ILOZ, IHIZ, Z, LDZ, WORK, LWORK, INFO )
13386 *
13387 * -- LAPACK auxiliary routine (version 3.2) --
13388 * Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
13389 * November 2006
13390 *
13391 * .. Scalar Arguments ..
13392 INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
13393 LOGICAL WANTT, WANTZ
13394 * ..
13395 * .. Array Arguments ..
13396 DOUBLE PRECISION H( LDH, * ), WI( * ), WORK( * ), WR( * ),
13397 $ Z( LDZ, * )
13398 * ..
13399 *
13400 * Purpose
13401 * =======
13402 *
13403 * DLAQR0 computes the eigenvalues of a Hessenberg matrix H
13404 * and, optionally, the matrices T and Z from the Schur decomposition
13405 * H = Z T Z**T, where T is an upper quasi-triangular matrix (the
13406 * Schur form), and Z is the orthogonal matrix of Schur vectors.
13407 *
13408 * Optionally Z may be postmultiplied into an input orthogonal
13409 * matrix Q so that this routine can give the Schur factorization
13410 * of a matrix A which has been reduced to the Hessenberg form H
13411 * by the orthogonal matrix Q: A = Q*H*Q**T = (QZ)*T*(QZ)**T.
13412 *
13413 * Arguments
13414 * =========
13415 *
13416 * WANTT (input) LOGICAL
13417 * = .TRUE. : the full Schur form T is required;
13418 * = .FALSE.: only eigenvalues are required.
13419 *
13420 * WANTZ (input) LOGICAL
13421 * = .TRUE. : the matrix of Schur vectors Z is required;
13422 * = .FALSE.: Schur vectors are not required.
13423 *
13424 * N (input) INTEGER
13425 * The order of the matrix H. N .GE. 0.
13426 *
13427 * ILO (input) INTEGER
13428 * IHI (input) INTEGER
13429 * It is assumed that H is already upper triangular in rows
13430 * and columns 1:ILO-1 and IHI+1:N and, if ILO.GT.1,
13431 * H(ILO,ILO-1) is zero. ILO and IHI are normally set by a
13432 * previous call to DGEBAL, and then passed to DGEHRD when the
13433 * matrix output by DGEBAL is reduced to Hessenberg form.
13434 * Otherwise, ILO and IHI should be set to 1 and N,
13435 * respectively. If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N.
13436 * If N = 0, then ILO = 1 and IHI = 0.
13437 *
13438 * H (input/output) DOUBLE PRECISION array, dimension (LDH,N)
13439 * On entry, the upper Hessenberg matrix H.
13440 * On exit, if INFO = 0 and WANTT is .TRUE., then H contains
13441 * the upper quasi-triangular matrix T from the Schur
13442 * decomposition (the Schur form); 2-by-2 diagonal blocks
13443 * (corresponding to complex conjugate pairs of eigenvalues)
13444 * are returned in standard form, with H(i,i) = H(i+1,i+1)
13445 * and H(i+1,i)*H(i,i+1).LT.0. If INFO = 0 and WANTT is
13446 * .FALSE., then the contents of H are unspecified on exit.
13447 * (The output value of H when INFO.GT.0 is given under the
13448 * description of INFO below.)
13449 *
13450 * This subroutine may explicitly set H(i,j) = 0 for i.GT.j and
13451 * j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N.
13452 *
13453 * LDH (input) INTEGER
13454 * The leading dimension of the array H. LDH .GE. max(1,N).
13455 *
13456 * WR (output) DOUBLE PRECISION array, dimension (IHI)
13457 * WI (output) DOUBLE PRECISION array, dimension (IHI)
13458 * The real and imaginary parts, respectively, of the computed
13459 * eigenvalues of H(ILO:IHI,ILO:IHI) are stored in WR(ILO:IHI)
13460 * and WI(ILO:IHI). If two eigenvalues are computed as a
13461 * complex conjugate pair, they are stored in consecutive
13462 * elements of WR and WI, say the i-th and (i+1)th, with
13463 * WI(i) .GT. 0 and WI(i+1) .LT. 0. If WANTT is .TRUE., then
13464 * the eigenvalues are stored in the same order as on the
13465 * diagonal of the Schur form returned in H, with
13466 * WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2 diagonal
13467 * block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and
13468 * WI(i+1) = -WI(i).
13469 *
13470 * ILOZ (input) INTEGER
13471 * IHIZ (input) INTEGER
13472 * Specify the rows of Z to which transformations must be
13473 * applied if WANTZ is .TRUE..
13474 * 1 .LE. ILOZ .LE. ILO; IHI .LE. IHIZ .LE. N.
13475 *
13476 * Z (input/output) DOUBLE PRECISION array, dimension (LDZ,IHI)
13477 * If WANTZ is .FALSE., then Z is not referenced.
13478 * If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is
13479 * replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the
13480 * orthogonal Schur factor of H(ILO:IHI,ILO:IHI).
13481 * (The output value of Z when INFO.GT.0 is given under
13482 * the description of INFO below.)
13483 *
13484 * LDZ (input) INTEGER
13485 * The leading dimension of the array Z. if WANTZ is .TRUE.
13486 * then LDZ.GE.MAX(1,IHIZ). Otherwize, LDZ.GE.1.
13487 *
13488 * WORK (workspace/output) DOUBLE PRECISION array, dimension LWORK
13489 * On exit, if LWORK = -1, WORK(1) returns an estimate of
13490 * the optimal value for LWORK.
13491 *
13492 * LWORK (input) INTEGER
13493 * The dimension of the array WORK. LWORK .GE. max(1,N)
13494 * is sufficient, but LWORK typically as large as 6*N may
13495 * be required for optimal performance. A workspace query
13496 * to determine the optimal workspace size is recommended.
13497 *
13498 * If LWORK = -1, then DLAQR0 does a workspace query.
13499 * In this case, DLAQR0 checks the input parameters and
13500 * estimates the optimal workspace size for the given
13501 * values of N, ILO and IHI. The estimate is returned
13502 * in WORK(1). No error message related to LWORK is
13503 * issued by XERBLA. Neither H nor Z are accessed.
13504 *
13505 *
13506 * INFO (output) INTEGER
13507 * = 0: successful exit
13508 * .GT. 0: if INFO = i, DLAQR0 failed to compute all of
13509 * the eigenvalues. Elements 1:ilo-1 and i+1:n of WR
13510 * and WI contain those eigenvalues which have been
13511 * successfully computed. (Failures are rare.)
13512 *
13513 * If INFO .GT. 0 and WANT is .FALSE., then on exit,
13514 * the remaining unconverged eigenvalues are the eigen-
13515 * values of the upper Hessenberg matrix rows and
13516 * columns ILO through INFO of the final, output
13517 * value of H.
13518 *
13519 * If INFO .GT. 0 and WANTT is .TRUE., then on exit
13520 *
13521 * (*) (initial value of H)*U = U*(final value of H)
13522 *
13523 * where U is an orthogonal matrix. The final
13524 * value of H is upper Hessenberg and quasi-triangular
13525 * in rows and columns INFO+1 through IHI.
13526 *
13527 * If INFO .GT. 0 and WANTZ is .TRUE., then on exit
13528 *
13529 * (final value of Z(ILO:IHI,ILOZ:IHIZ)
13530 * = (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U
13531 *
13532 * where U is the orthogonal matrix in (*) (regard-
13533 * less of the value of WANTT.)
13534 *
13535 * If INFO .GT. 0 and WANTZ is .FALSE., then Z is not
13536 * accessed.
13537 *
13538 * ================================================================
13539 * Based on contributions by
13540 * Karen Braman and Ralph Byers, Department of Mathematics,
13541 * University of Kansas, USA
13542 *
13543 * ================================================================
13544 * References:
13545 * K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
13546 * Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
13547 * Performance, SIAM Journal of Matrix Analysis, volume 23, pages
13548 * 929--947, 2002.
13549 *
13550 * K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
13551 * Algorithm Part II: Aggressive Early Deflation, SIAM Journal
13552 * of Matrix Analysis, volume 23, pages 948--973, 2002.
13553 *
13554 * ================================================================
13555 * .. Parameters ..
13556 *
13557 * ==== Matrices of order NTINY or smaller must be processed by
13558 * . DLAHQR because of insufficient subdiagonal scratch space.
13559 * . (This is a hard limit.) ====
13560 INTEGER NTINY
13561 PARAMETER ( NTINY = 11 )
13562 *
13563 * ==== Exceptional deflation windows: try to cure rare
13564 * . slow convergence by varying the size of the
13565 * . deflation window after KEXNW iterations. ====
13566 INTEGER KEXNW
13567 PARAMETER ( KEXNW = 5 )
13568 *
13569 * ==== Exceptional shifts: try to cure rare slow convergence
13570 * . with ad-hoc exceptional shifts every KEXSH iterations.
13571 * . ====
13572 INTEGER KEXSH
13573 PARAMETER ( KEXSH = 6 )
13574 *
13575 * ==== The constants WILK1 and WILK2 are used to form the
13576 * . exceptional shifts. ====
13577 DOUBLE PRECISION WILK1, WILK2
13578 PARAMETER ( WILK1 = 0.75d0, WILK2 = -0.4375d0 )
13579 DOUBLE PRECISION ZERO, ONE
13580 PARAMETER ( ZERO = 0.0d0, ONE = 1.0d0 )
13581 * ..
13582 * .. Local Scalars ..
13583 DOUBLE PRECISION AA, BB, CC, CS, DD, SN, SS, SWAP
13584 INTEGER I, INF, IT, ITMAX, K, KACC22, KBOT, KDU, KS,
13585 $ KT, KTOP, KU, KV, KWH, KWTOP, KWV, LD, LS,
13586 $ LWKOPT, NDEC, NDFL, NH, NHO, NIBBLE, NMIN, NS,
13587 $ NSMAX, NSR, NVE, NW, NWMAX, NWR, NWUPBD
13588 LOGICAL SORTED
13589 CHARACTER JBCMPZ*2
13590 * ..
13591 * .. External Functions ..
13592 INTEGER ILAENV
13593 EXTERNAL ILAENV
13594 * ..
13595 * .. Local Arrays ..
13596 DOUBLE PRECISION ZDUM( 1, 1 )
13597 * ..
13598 * .. External Subroutines ..
13599 EXTERNAL DLACPY, DLAHQR, DLANV2, DLAQR3, DLAQR4, DLAQR5
13600 * ..
13601 * .. Intrinsic Functions ..
13602 INTRINSIC ABS, DBLE, INT, MAX, MIN, MOD
13603 * ..
13604 * .. Executable Statements ..
13605 INFO = 0
13606 *
13607 * ==== Quick return for N = 0: nothing to do. ====
13608 *
13609 IF( N.EQ.0 ) THEN
13610 WORK( 1 ) = ONE
13611 RETURN
13612 END IF
13613 *
13614 IF( N.LE.NTINY ) THEN
13615 *
13616 * ==== Tiny matrices must use DLAHQR. ====
13617 *
13618 LWKOPT = 1
13619 IF( LWORK.NE.-1 )
13620 $ CALL DLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI,
13621 $ ILOZ, IHIZ, Z, LDZ, INFO )
13622 ELSE
13623 *
13624 * ==== Use small bulge multi-shift QR with aggressive early
13625 * . deflation on larger-than-tiny matrices. ====
13626 *
13627 * ==== Hope for the best. ====
13628 *
13629 INFO = 0
13630 *
13631 * ==== Set up job flags for ILAENV. ====
13632 *
13633 IF( WANTT ) THEN
13634 JBCMPZ( 1: 1 ) = 'S'
13635 ELSE
13636 JBCMPZ( 1: 1 ) = 'E'
13637 END IF
13638 IF( WANTZ ) THEN
13639 JBCMPZ( 2: 2 ) = 'V'
13640 ELSE
13641 JBCMPZ( 2: 2 ) = 'N'
13642 END IF
13643 *
13644 * ==== NWR = recommended deflation window size. At this
13645 * . point, N .GT. NTINY = 11, so there is enough
13646 * . subdiagonal workspace for NWR.GE.2 as required.
13647 * . (In fact, there is enough subdiagonal space for
13648 * . NWR.GE.3.) ====
13649 *
13650 NWR = ILAENV( 13, 'DLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
13651 NWR = MAX( 2, NWR )
13652 NWR = MIN( IHI-ILO+1, ( N-1 ) / 3, NWR )
13653 *
13654 * ==== NSR = recommended number of simultaneous shifts.
13655 * . At this point N .GT. NTINY = 11, so there is at
13656 * . enough subdiagonal workspace for NSR to be even
13657 * . and greater than or equal to two as required. ====
13658 *
13659 NSR = ILAENV( 15, 'DLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
13660 NSR = MIN( NSR, ( N+6 ) / 9, IHI-ILO )
13661 NSR = MAX( 2, NSR-MOD( NSR, 2 ) )
13662 *
13663 * ==== Estimate optimal workspace ====
13664 *
13665 * ==== Workspace query call to DLAQR3 ====
13666 *
13667 CALL DLAQR3( WANTT, WANTZ, N, ILO, IHI, NWR+1, H, LDH, ILOZ,
13668 $ IHIZ, Z, LDZ, LS, LD, WR, WI, H, LDH, N, H, LDH,
13669 $ N, H, LDH, WORK, -1 )
13670 *
13671 * ==== Optimal workspace = MAX(DLAQR5, DLAQR3) ====
13672 *
13673 LWKOPT = MAX( 3*NSR / 2, INT( WORK( 1 ) ) )
13674 *
13675 * ==== Quick return in case of workspace query. ====
13676 *
13677 IF( LWORK.EQ.-1 ) THEN
13678 WORK( 1 ) = DBLE( LWKOPT )
13679 RETURN
13680 END IF
13681 *
13682 * ==== DLAHQR/DLAQR0 crossover point ====
13683 *
13684 NMIN = ILAENV( 12, 'DLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
13685 NMIN = MAX( NTINY, NMIN )
13686 *
13687 * ==== Nibble crossover point ====
13688 *
13689 NIBBLE = ILAENV( 14, 'DLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
13690 NIBBLE = MAX( 0, NIBBLE )
13691 *
13692 * ==== Accumulate reflections during ttswp? Use block
13693 * . 2-by-2 structure during matrix-matrix multiply? ====
13694 *
13695 KACC22 = ILAENV( 16, 'DLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
13696 KACC22 = MAX( 0, KACC22 )
13697 KACC22 = MIN( 2, KACC22 )
13698 *
13699 * ==== NWMAX = the largest possible deflation window for
13700 * . which there is sufficient workspace. ====
13701 *
13702 NWMAX = MIN( ( N-1 ) / 3, LWORK / 2 )
13703 NW = NWMAX
13704 *
13705 * ==== NSMAX = the Largest number of simultaneous shifts
13706 * . for which there is sufficient workspace. ====
13707 *
13708 NSMAX = MIN( ( N+6 ) / 9, 2*LWORK / 3 )
13709 NSMAX = NSMAX - MOD( NSMAX, 2 )
13710 *
13711 * ==== NDFL: an iteration count restarted at deflation. ====
13712 *
13713 NDFL = 1
13714 *
13715 * ==== ITMAX = iteration limit ====
13716 *
13717 ITMAX = MAX( 30, 2*KEXSH )*MAX( 10, ( IHI-ILO+1 ) )
13718 *
13719 * ==== Last row and column in the active block ====
13720 *
13721 KBOT = IHI
13722 *
13723 * ==== Main Loop ====
13724 *
13725 DO 80 IT = 1, ITMAX
13726 *
13727 * ==== Done when KBOT falls below ILO ====
13728 *
13729 IF( KBOT.LT.ILO )
13730 $ GO TO 90
13731 *
13732 * ==== Locate active block ====
13733 *
13734 DO 10 K = KBOT, ILO + 1, -1
13735 IF( H( K, K-1 ).EQ.ZERO )
13736 $ GO TO 20
13737 10 CONTINUE
13738 K = ILO
13739 20 CONTINUE
13740 KTOP = K
13741 *
13742 * ==== Select deflation window size:
13743 * . Typical Case:
13744 * . If possible and advisable, nibble the entire
13745 * . active block. If not, use size MIN(NWR,NWMAX)
13746 * . or MIN(NWR+1,NWMAX) depending upon which has
13747 * . the smaller corresponding subdiagonal entry
13748 * . (a heuristic).
13749 * .
13750 * . Exceptional Case:
13751 * . If there have been no deflations in KEXNW or
13752 * . more iterations, then vary the deflation window
13753 * . size. At first, because, larger windows are,
13754 * . in general, more powerful than smaller ones,
13755 * . rapidly increase the window to the maximum possible.
13756 * . Then, gradually reduce the window size. ====
13757 *
13758 NH = KBOT - KTOP + 1
13759 NWUPBD = MIN( NH, NWMAX )
13760 IF( NDFL.LT.KEXNW ) THEN
13761 NW = MIN( NWUPBD, NWR )
13762 ELSE
13763 NW = MIN( NWUPBD, 2*NW )
13764 END IF
13765 IF( NW.LT.NWMAX ) THEN
13766 IF( NW.GE.NH-1 ) THEN
13767 NW = NH
13768 ELSE
13769 KWTOP = KBOT - NW + 1
13770 IF( ABS( H( KWTOP, KWTOP-1 ) ).GT.
13771 $ ABS( H( KWTOP-1, KWTOP-2 ) ) )NW = NW + 1
13772 END IF
13773 END IF
13774 IF( NDFL.LT.KEXNW ) THEN
13775 NDEC = -1
13776 ELSE IF( NDEC.GE.0 .OR. NW.GE.NWUPBD ) THEN
13777 NDEC = NDEC + 1
13778 IF( NW-NDEC.LT.2 )
13779 $ NDEC = 0
13780 NW = NW - NDEC
13781 END IF
13782 *
13783 * ==== Aggressive early deflation:
13784 * . split workspace under the subdiagonal into
13785 * . - an nw-by-nw work array V in the lower
13786 * . left-hand-corner,
13787 * . - an NW-by-at-least-NW-but-more-is-better
13788 * . (NW-by-NHO) horizontal work array along
13789 * . the bottom edge,
13790 * . - an at-least-NW-but-more-is-better (NHV-by-NW)
13791 * . vertical work array along the left-hand-edge.
13792 * . ====
13793 *
13794 KV = N - NW + 1
13795 KT = NW + 1
13796 NHO = ( N-NW-1 ) - KT + 1
13797 KWV = NW + 2
13798 NVE = ( N-NW ) - KWV + 1
13799 *
13800 * ==== Aggressive early deflation ====
13801 *
13802 CALL DLAQR3( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
13803 $ IHIZ, Z, LDZ, LS, LD, WR, WI, H( KV, 1 ), LDH,
13804 $ NHO, H( KV, KT ), LDH, NVE, H( KWV, 1 ), LDH,
13805 $ WORK, LWORK )
13806 *
13807 * ==== Adjust KBOT accounting for new deflations. ====
13808 *
13809 KBOT = KBOT - LD
13810 *
13811 * ==== KS points to the shifts. ====
13812 *
13813 KS = KBOT - LS + 1
13814 *
13815 * ==== Skip an expensive QR sweep if there is a (partly
13816 * . heuristic) reason to expect that many eigenvalues
13817 * . will deflate without it. Here, the QR sweep is
13818 * . skipped if many eigenvalues have just been deflated
13819 * . or if the remaining active block is small.
13820 *
13821 IF( ( LD.EQ.0 ) .OR. ( ( 100*LD.LE.NW*NIBBLE ) .AND. ( KBOT-
13822 $ KTOP+1.GT.MIN( NMIN, NWMAX ) ) ) ) THEN
13823 *
13824 * ==== NS = nominal number of simultaneous shifts.
13825 * . This may be lowered (slightly) if DLAQR3
13826 * . did not provide that many shifts. ====
13827 *
13828 NS = MIN( NSMAX, NSR, MAX( 2, KBOT-KTOP ) )
13829 NS = NS - MOD( NS, 2 )
13830 *
13831 * ==== If there have been no deflations
13832 * . in a multiple of KEXSH iterations,
13833 * . then try exceptional shifts.
13834 * . Otherwise use shifts provided by
13835 * . DLAQR3 above or from the eigenvalues
13836 * . of a trailing principal submatrix. ====
13837 *
13838 IF( MOD( NDFL, KEXSH ).EQ.0 ) THEN
13839 KS = KBOT - NS + 1
13840 DO 30 I = KBOT, MAX( KS+1, KTOP+2 ), -2
13841 SS = ABS( H( I, I-1 ) ) + ABS( H( I-1, I-2 ) )
13842 AA = WILK1*SS + H( I, I )
13843 BB = SS
13844 CC = WILK2*SS
13845 DD = AA
13846 CALL DLANV2( AA, BB, CC, DD, WR( I-1 ), WI( I-1 ),
13847 $ WR( I ), WI( I ), CS, SN )
13848 30 CONTINUE
13849 IF( KS.EQ.KTOP ) THEN
13850 WR( KS+1 ) = H( KS+1, KS+1 )
13851 WI( KS+1 ) = ZERO
13852 WR( KS ) = WR( KS+1 )
13853 WI( KS ) = WI( KS+1 )
13854 END IF
13855 ELSE
13856 *
13857 * ==== Got NS/2 or fewer shifts? Use DLAQR4 or
13858 * . DLAHQR on a trailing principal submatrix to
13859 * . get more. (Since NS.LE.NSMAX.LE.(N+6)/9,
13860 * . there is enough space below the subdiagonal
13861 * . to fit an NS-by-NS scratch array.) ====
13862 *
13863 IF( KBOT-KS+1.LE.NS / 2 ) THEN
13864 KS = KBOT - NS + 1
13865 KT = N - NS + 1
13866 CALL DLACPY( 'A', NS, NS, H( KS, KS ), LDH,
13867 $ H( KT, 1 ), LDH )
13868 IF( NS.GT.NMIN ) THEN
13869 CALL DLAQR4( .false., .false., NS, 1, NS,
13870 $ H( KT, 1 ), LDH, WR( KS ),
13871 $ WI( KS ), 1, 1, ZDUM, 1, WORK,
13872 $ LWORK, INF )
13873 ELSE
13874 CALL DLAHQR( .false., .false., NS, 1, NS,
13875 $ H( KT, 1 ), LDH, WR( KS ),
13876 $ WI( KS ), 1, 1, ZDUM, 1, INF )
13877 END IF
13878 KS = KS + INF
13879 *
13880 * ==== In case of a rare QR failure use
13881 * . eigenvalues of the trailing 2-by-2
13882 * . principal submatrix. ====
13883 *
13884 IF( KS.GE.KBOT ) THEN
13885 AA = H( KBOT-1, KBOT-1 )
13886 CC = H( KBOT, KBOT-1 )
13887 BB = H( KBOT-1, KBOT )
13888 DD = H( KBOT, KBOT )
13889 CALL DLANV2( AA, BB, CC, DD, WR( KBOT-1 ),
13890 $ WI( KBOT-1 ), WR( KBOT ),
13891 $ WI( KBOT ), CS, SN )
13892 KS = KBOT - 1
13893 END IF
13894 END IF
13895 *
13896 IF( KBOT-KS+1.GT.NS ) THEN
13897 *
13898 * ==== Sort the shifts (Helps a little)
13899 * . Bubble sort keeps complex conjugate
13900 * . pairs together. ====
13901 *
13902 SORTED = .false.
13903 DO 50 K = KBOT, KS + 1, -1
13904 IF( SORTED )
13905 $ GO TO 60
13906 SORTED = .true.
13907 DO 40 I = KS, K - 1
13908 IF( ABS( WR( I ) )+ABS( WI( I ) ).LT.
13909 $ ABS( WR( I+1 ) )+ABS( WI( I+1 ) ) ) THEN
13910 SORTED = .false.
13911 *
13912 SWAP = WR( I )
13913 WR( I ) = WR( I+1 )
13914 WR( I+1 ) = SWAP
13915 *
13916 SWAP = WI( I )
13917 WI( I ) = WI( I+1 )
13918 WI( I+1 ) = SWAP
13919 END IF
13920 40 CONTINUE
13921 50 CONTINUE
13922 60 CONTINUE
13923 END IF
13924 *
13925 * ==== Shuffle shifts into pairs of real shifts
13926 * . and pairs of complex conjugate shifts
13927 * . assuming complex conjugate shifts are
13928 * . already adjacent to one another. (Yes,
13929 * . they are.) ====
13930 *
13931 DO 70 I = KBOT, KS + 2, -2
13932 IF( WI( I ).NE.-WI( I-1 ) ) THEN
13933 *
13934 SWAP = WR( I )
13935 WR( I ) = WR( I-1 )
13936 WR( I-1 ) = WR( I-2 )
13937 WR( I-2 ) = SWAP
13938 *
13939 SWAP = WI( I )
13940 WI( I ) = WI( I-1 )
13941 WI( I-1 ) = WI( I-2 )
13942 WI( I-2 ) = SWAP
13943 END IF
13944 70 CONTINUE
13945 END IF
13946 *
13947 * ==== If there are only two shifts and both are
13948 * . real, then use only one. ====
13949 *
13950 IF( KBOT-KS+1.EQ.2 ) THEN
13951 IF( WI( KBOT ).EQ.ZERO ) THEN
13952 IF( ABS( WR( KBOT )-H( KBOT, KBOT ) ).LT.
13953 $ ABS( WR( KBOT-1 )-H( KBOT, KBOT ) ) ) THEN
13954 WR( KBOT-1 ) = WR( KBOT )
13955 ELSE
13956 WR( KBOT ) = WR( KBOT-1 )
13957 END IF
13958 END IF
13959 END IF
13960 *
13961 * ==== Use up to NS of the the smallest magnatiude
13962 * . shifts. If there aren't NS shifts available,
13963 * . then use them all, possibly dropping one to
13964 * . make the number of shifts even. ====
13965 *
13966 NS = MIN( NS, KBOT-KS+1 )
13967 NS = NS - MOD( NS, 2 )
13968 KS = KBOT - NS + 1
13969 *
13970 * ==== Small-bulge multi-shift QR sweep:
13971 * . split workspace under the subdiagonal into
13972 * . - a KDU-by-KDU work array U in the lower
13973 * . left-hand-corner,
13974 * . - a KDU-by-at-least-KDU-but-more-is-better
13975 * . (KDU-by-NHo) horizontal work array WH along
13976 * . the bottom edge,
13977 * . - and an at-least-KDU-but-more-is-better-by-KDU
13978 * . (NVE-by-KDU) vertical work WV arrow along
13979 * . the left-hand-edge. ====
13980 *
13981 KDU = 3*NS - 3
13982 KU = N - KDU + 1
13983 KWH = KDU + 1
13984 NHO = ( N-KDU+1-4 ) - ( KDU+1 ) + 1
13985 KWV = KDU + 4
13986 NVE = N - KDU - KWV + 1
13987 *
13988 * ==== Small-bulge multi-shift QR sweep ====
13989 *
13990 CALL DLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NS,
13991 $ WR( KS ), WI( KS ), H, LDH, ILOZ, IHIZ, Z,
13992 $ LDZ, WORK, 3, H( KU, 1 ), LDH, NVE,
13993 $ H( KWV, 1 ), LDH, NHO, H( KU, KWH ), LDH )
13994 END IF
13995 *
13996 * ==== Note progress (or the lack of it). ====
13997 *
13998 IF( LD.GT.0 ) THEN
13999 NDFL = 1
14000 ELSE
14001 NDFL = NDFL + 1
14002 END IF
14003 *
14004 * ==== End of main loop ====
14005 80 CONTINUE
14006 *
14007 * ==== Iteration limit exceeded. Set INFO to show where
14008 * . the problem occurred and exit. ====
14009 *
14010 INFO = KBOT
14011 90 CONTINUE
14012 END IF
14013 *
14014 * ==== Return the optimal value of LWORK. ====
14015 *
14016 WORK( 1 ) = DBLE( LWKOPT )
14017 *
14018 * ==== End of DLAQR0 ====
14019 *
14020 END
14021 C
14022 C-----------------------------------------------------------------------
14023 C-----------------------------------------------------------------------
14024 SUBROUTINE DLAQR1( N, H, LDH, SR1, SI1, SR2, SI2, V )
14025 *
14026 * -- LAPACK auxiliary routine (version 3.2) --
14027 * Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
14028 * November 2006
14029 *
14030 * .. Scalar Arguments ..
14031 DOUBLE PRECISION SI1, SI2, SR1, SR2
14032 INTEGER LDH, N
14033 * ..
14034 * .. Array Arguments ..
14035 DOUBLE PRECISION H( LDH, * ), V( * )
14036 * ..
14037 *
14038 * Given a 2-by-2 or 3-by-3 matrix H, DLAQR1 sets v to a
14039 * scalar multiple of the first column of the product
14040 *
14041 * (*) K = (H - (sr1 + i*si1)*I)*(H - (sr2 + i*si2)*I)
14042 *
14043 * scaling to avoid overflows and most underflows. It
14044 * is assumed that either
14045 *
14046 * 1) sr1 = sr2 and si1 = -si2
14047 * or
14048 * 2) si1 = si2 = 0.
14049 *
14050 * This is useful for starting double implicit shift bulges
14051 * in the QR algorithm.
14052 *
14053 *
14054 * N (input) integer
14055 * Order of the matrix H. N must be either 2 or 3.
14056 *
14057 * H (input) DOUBLE PRECISION array of dimension (LDH,N)
14058 * The 2-by-2 or 3-by-3 matrix H in (*).
14059 *
14060 * LDH (input) integer
14061 * The leading dimension of H as declared in
14062 * the calling procedure. LDH.GE.N
14063 *
14064 * SR1 (input) DOUBLE PRECISION
14065 * SI1 The shifts in (*).
14066 * SR2
14067 * SI2
14068 *
14069 * V (output) DOUBLE PRECISION array of dimension N
14070 * A scalar multiple of the first column of the
14071 * matrix K in (*).
14072 *
14073 * ================================================================
14074 * Based on contributions by
14075 * Karen Braman and Ralph Byers, Department of Mathematics,
14076 * University of Kansas, USA
14077 *
14078 * ================================================================
14079 *
14080 * .. Parameters ..
14081 DOUBLE PRECISION ZERO
14082 PARAMETER ( ZERO = 0.0d0 )
14083 * ..
14084 * .. Local Scalars ..
14085 DOUBLE PRECISION H21S, H31S, S
14086 * ..
14087 * .. Intrinsic Functions ..
14088 INTRINSIC ABS
14089 * ..
14090 * .. Executable Statements ..
14091 IF( N.EQ.2 ) THEN
14092 S = ABS( H( 1, 1 )-SR2 ) + ABS( SI2 ) + ABS( H( 2, 1 ) )
14093 IF( S.EQ.ZERO ) THEN
14094 V( 1 ) = ZERO
14095 V( 2 ) = ZERO
14096 ELSE
14097 H21S = H( 2, 1 ) / S
14098 V( 1 ) = H21S*H( 1, 2 ) + ( H( 1, 1 )-SR1 )*
14099 $ ( ( H( 1, 1 )-SR2 ) / S ) - SI1*( SI2 / S )
14100 V( 2 ) = H21S*( H( 1, 1 )+H( 2, 2 )-SR1-SR2 )
14101 END IF
14102 ELSE
14103 S = ABS( H( 1, 1 )-SR2 ) + ABS( SI2 ) + ABS( H( 2, 1 ) ) +
14104 $ ABS( H( 3, 1 ) )
14105 IF( S.EQ.ZERO ) THEN
14106 V( 1 ) = ZERO
14107 V( 2 ) = ZERO
14108 V( 3 ) = ZERO
14109 ELSE
14110 H21S = H( 2, 1 ) / S
14111 H31S = H( 3, 1 ) / S
14112 V( 1 ) = ( H( 1, 1 )-SR1 )*( ( H( 1, 1 )-SR2 ) / S ) -
14113 $ SI1*( SI2 / S ) + H( 1, 2 )*H21S + H( 1, 3 )*H31S
14114 V( 2 ) = H21S*( H( 1, 1 )+H( 2, 2 )-SR1-SR2 ) +
14115 $ H( 2, 3 )*H31S
14116 V( 3 ) = H31S*( H( 1, 1 )+H( 3, 3 )-SR1-SR2 ) +
14117 $ H21S*H( 3, 2 )
14118 END IF
14119 END IF
14120 END
14121 C
14122 C-----------------------------------------------------------------------
14123 C-----------------------------------------------------------------------
14124 SUBROUTINE DLAQR2( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
14125 $ IHIZ, Z, LDZ, NS, ND, SR, SI, V, LDV, NH, T,
14126 $ LDT, NV, WV, LDWV, WORK, LWORK )
14127 *
14128 * -- LAPACK auxiliary routine (version 3.2.2) --
14129 * Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
14130 * -- June 2010 --
14131 *
14132 * .. Scalar Arguments ..
14133 INTEGER IHIZ, ILOZ, KBOT, KTOP, LDH, LDT, LDV, LDWV,
14134 $ LDZ, LWORK, N, ND, NH, NS, NV, NW
14135 LOGICAL WANTT, WANTZ
14136 * ..
14137 * .. Array Arguments ..
14138 DOUBLE PRECISION H( LDH, * ), SI( * ), SR( * ), T( LDT, * ),
14139 $ V( LDV, * ), WORK( * ), WV( LDWV, * ),
14140 $ Z( LDZ, * )
14141 * ..
14142 *
14143 * This subroutine is identical to DLAQR3 except that it avoids
14144 * recursion by calling DLAHQR instead of DLAQR4.
14145 *
14146 *
14147 * ******************************************************************
14148 * Aggressive early deflation:
14149 *
14150 * This subroutine accepts as input an upper Hessenberg matrix
14151 * H and performs an orthogonal similarity transformation
14152 * designed to detect and deflate fully converged eigenvalues from
14153 * a trailing principal submatrix. On output H has been over-
14154 * written by a new Hessenberg matrix that is a perturbation of
14155 * an orthogonal similarity transformation of H. It is to be
14156 * hoped that the final version of H has many zero subdiagonal
14157 * entries.
14158 *
14159 * ******************************************************************
14160 * WANTT (input) LOGICAL
14161 * If .TRUE., then the Hessenberg matrix H is fully updated
14162 * so that the quasi-triangular Schur factor may be
14163 * computed (in cooperation with the calling subroutine).
14164 * If .FALSE., then only enough of H is updated to preserve
14165 * the eigenvalues.
14166 *
14167 * WANTZ (input) LOGICAL
14168 * If .TRUE., then the orthogonal matrix Z is updated so
14169 * so that the orthogonal Schur factor may be computed
14170 * (in cooperation with the calling subroutine).
14171 * If .FALSE., then Z is not referenced.
14172 *
14173 * N (input) INTEGER
14174 * The order of the matrix H and (if WANTZ is .TRUE.) the
14175 * order of the orthogonal matrix Z.
14176 *
14177 * KTOP (input) INTEGER
14178 * It is assumed that either KTOP = 1 or H(KTOP,KTOP-1)=0.
14179 * KBOT and KTOP together determine an isolated block
14180 * along the diagonal of the Hessenberg matrix.
14181 *
14182 * KBOT (input) INTEGER
14183 * It is assumed without a check that either
14184 * KBOT = N or H(KBOT+1,KBOT)=0. KBOT and KTOP together
14185 * determine an isolated block along the diagonal of the
14186 * Hessenberg matrix.
14187 *
14188 * NW (input) INTEGER
14189 * Deflation window size. 1 .LE. NW .LE. (KBOT-KTOP+1).
14190 *
14191 * H (input/output) DOUBLE PRECISION array, dimension (LDH,N)
14192 * On input the initial N-by-N section of H stores the
14193 * Hessenberg matrix undergoing aggressive early deflation.
14194 * On output H has been transformed by an orthogonal
14195 * similarity transformation, perturbed, and the returned
14196 * to Hessenberg form that (it is to be hoped) has some
14197 * zero subdiagonal entries.
14198 *
14199 * LDH (input) integer
14200 * Leading dimension of H just as declared in the calling
14201 * subroutine. N .LE. LDH
14202 *
14203 * ILOZ (input) INTEGER
14204 * IHIZ (input) INTEGER
14205 * Specify the rows of Z to which transformations must be
14206 * applied if WANTZ is .TRUE.. 1 .LE. ILOZ .LE. IHIZ .LE. N.
14207 *
14208 * Z (input/output) DOUBLE PRECISION array, dimension (LDZ,N)
14209 * IF WANTZ is .TRUE., then on output, the orthogonal
14210 * similarity transformation mentioned above has been
14211 * accumulated into Z(ILOZ:IHIZ,ILO:IHI) from the right.
14212 * If WANTZ is .FALSE., then Z is unreferenced.
14213 *
14214 * LDZ (input) integer
14215 * The leading dimension of Z just as declared in the
14216 * calling subroutine. 1 .LE. LDZ.
14217 *
14218 * NS (output) integer
14219 * The number of unconverged (ie approximate) eigenvalues
14220 * returned in SR and SI that may be used as shifts by the
14221 * calling subroutine.
14222 *
14223 * ND (output) integer
14224 * The number of converged eigenvalues uncovered by this
14225 * subroutine.
14226 *
14227 * SR (output) DOUBLE PRECISION array, dimension (KBOT)
14228 * SI (output) DOUBLE PRECISION array, dimension (KBOT)
14229 * On output, the real and imaginary parts of approximate
14230 * eigenvalues that may be used for shifts are stored in
14231 * SR(KBOT-ND-NS+1) through SR(KBOT-ND) and
14232 * SI(KBOT-ND-NS+1) through SI(KBOT-ND), respectively.
14233 * The real and imaginary parts of converged eigenvalues
14234 * are stored in SR(KBOT-ND+1) through SR(KBOT) and
14235 * SI(KBOT-ND+1) through SI(KBOT), respectively.
14236 *
14237 * V (workspace) DOUBLE PRECISION array, dimension (LDV,NW)
14238 * An NW-by-NW work array.
14239 *
14240 * LDV (input) integer scalar
14241 * The leading dimension of V just as declared in the
14242 * calling subroutine. NW .LE. LDV
14243 *
14244 * NH (input) integer scalar
14245 * The number of columns of T. NH.GE.NW.
14246 *
14247 * T (workspace) DOUBLE PRECISION array, dimension (LDT,NW)
14248 *
14249 * LDT (input) integer
14250 * The leading dimension of T just as declared in the
14251 * calling subroutine. NW .LE. LDT
14252 *
14253 * NV (input) integer
14254 * The number of rows of work array WV available for
14255 * workspace. NV.GE.NW.
14256 *
14257 * WV (workspace) DOUBLE PRECISION array, dimension (LDWV,NW)
14258 *
14259 * LDWV (input) integer
14260 * The leading dimension of W just as declared in the
14261 * calling subroutine. NW .LE. LDV
14262 *
14263 * WORK (workspace) DOUBLE PRECISION array, dimension (LWORK)
14264 * On exit, WORK(1) is set to an estimate of the optimal value
14265 * of LWORK for the given values of N, NW, KTOP and KBOT.
14266 *
14267 * LWORK (input) integer
14268 * The dimension of the work array WORK. LWORK = 2*NW
14269 * suffices, but greater efficiency may result from larger
14270 * values of LWORK.
14271 *
14272 * If LWORK = -1, then a workspace query is assumed; DLAQR2
14273 * only estimates the optimal workspace size for the given
14274 * values of N, NW, KTOP and KBOT. The estimate is returned
14275 * in WORK(1). No error message related to LWORK is issued
14276 * by XERBLA. Neither H nor Z are accessed.
14277 *
14278 * ================================================================
14279 * Based on contributions by
14280 * Karen Braman and Ralph Byers, Department of Mathematics,
14281 * University of Kansas, USA
14282 *
14283 * ================================================================
14284 * .. Parameters ..
14285 DOUBLE PRECISION ZERO, ONE
14286 PARAMETER ( ZERO = 0.0d0, ONE = 1.0d0 )
14287 * ..
14288 * .. Local Scalars ..
14289 DOUBLE PRECISION AA, BB, BETA, CC, CS, DD, EVI, EVK, FOO, S,
14290 $ SAFMAX, SAFMIN, SMLNUM, SN, TAU, ULP
14291 INTEGER I, IFST, ILST, INFO, INFQR, J, JW, K, KCOL,
14292 $ KEND, KLN, KROW, KWTOP, LTOP, LWK1, LWK2,
14293 $ LWKOPT
14294 LOGICAL BULGE, SORTED
14295 * ..
14296 * .. External Functions ..
14297 DOUBLE PRECISION DLAMCH
14298 EXTERNAL DLAMCH
14299 * ..
14300 * .. External Subroutines ..
14301 EXTERNAL DCOPY, DGEHRD, DGEMM, DLABAD, DLACPY, DLAHQR,
14302 $ DLANV2, DLARF, DLARFG, DLASET, DORMHR, DTREXC
14303 * ..
14304 * .. Intrinsic Functions ..
14305 INTRINSIC ABS, DBLE, INT, MAX, MIN, SQRT
14306 * ..
14307 * .. Executable Statements ..
14308 *
14309 * ==== Estimate optimal workspace. ====
14310 *
14311 JW = MIN( NW, KBOT-KTOP+1 )
14312 IF( JW.LE.2 ) THEN
14313 LWKOPT = 1
14314 ELSE
14315 *
14316 * ==== Workspace query call to DGEHRD ====
14317 *
14318 CALL DGEHRD( JW, 1, JW-1, T, LDT, WORK, WORK, -1, INFO )
14319 LWK1 = INT( WORK( 1 ) )
14320 *
14321 * ==== Workspace query call to DORMHR ====
14322 *
14323 CALL DORMHR( 'R', 'N', JW, JW, 1, JW-1, T, LDT, WORK, V, LDV,
14324 $ WORK, -1, INFO )
14325 LWK2 = INT( WORK( 1 ) )
14326 *
14327 * ==== Optimal workspace ====
14328 *
14329 LWKOPT = JW + MAX( LWK1, LWK2 )
14330 END IF
14331 *
14332 * ==== Quick return in case of workspace query. ====
14333 *
14334 IF( LWORK.EQ.-1 ) THEN
14335 WORK( 1 ) = DBLE( LWKOPT )
14336 RETURN
14337 END IF
14338 *
14339 * ==== Nothing to do ...
14340 * ... for an empty active block ... ====
14341 NS = 0
14342 ND = 0
14343 WORK( 1 ) = ONE
14344 IF( KTOP.GT.KBOT )
14345 $ RETURN
14346 * ... nor for an empty deflation window. ====
14347 IF( NW.LT.1 )
14348 $ RETURN
14349 *
14350 * ==== Machine constants ====
14351 *
14352 SAFMIN = DLAMCH( 'SAFE MINIMUM' )
14353 SAFMAX = ONE / SAFMIN
14354 CALL DLABAD( SAFMIN, SAFMAX )
14355 ULP = DLAMCH( 'PRECISION' )
14356 SMLNUM = SAFMIN*( DBLE( N ) / ULP )
14357 *
14358 * ==== Setup deflation window ====
14359 *
14360 JW = MIN( NW, KBOT-KTOP+1 )
14361 KWTOP = KBOT - JW + 1
14362 IF( KWTOP.EQ.KTOP ) THEN
14363 S = ZERO
14364 ELSE
14365 S = H( KWTOP, KWTOP-1 )
14366 END IF
14367 *
14368 IF( KBOT.EQ.KWTOP ) THEN
14369 *
14370 * ==== 1-by-1 deflation window: not much to do ====
14371 *
14372 SR( KWTOP ) = H( KWTOP, KWTOP )
14373 SI( KWTOP ) = ZERO
14374 NS = 1
14375 ND = 0
14376 IF( ABS( S ).LE.MAX( SMLNUM, ULP*ABS( H( KWTOP, KWTOP ) ) ) )
14377 $ THEN
14378 NS = 0
14379 ND = 1
14380 IF( KWTOP.GT.KTOP )
14381 $ H( KWTOP, KWTOP-1 ) = ZERO
14382 END IF
14383 WORK( 1 ) = ONE
14384 RETURN
14385 END IF
14386 *
14387 * ==== Convert to spike-triangular form. (In case of a
14388 * . rare QR failure, this routine continues to do
14389 * . aggressive early deflation using that part of
14390 * . the deflation window that converged using INFQR
14391 * . here and there to keep track.) ====
14392 *
14393 CALL DLACPY( 'U', JW, JW, H( KWTOP, KWTOP ), LDH, T, LDT )
14394 CALL DCOPY( JW-1, H( KWTOP+1, KWTOP ), LDH+1, T( 2, 1 ), LDT+1 )
14395 *
14396 CALL DLASET( 'A', JW, JW, ZERO, ONE, V, LDV )
14397 CALL DLAHQR( .true., .true., JW, 1, JW, T, LDT, SR( KWTOP ),
14398 $ SI( KWTOP ), 1, JW, V, LDV, INFQR )
14399 *
14400 * ==== DTREXC needs a clean margin near the diagonal ====
14401 *
14402 DO 10 J = 1, JW - 3
14403 T( J+2, J ) = ZERO
14404 T( J+3, J ) = ZERO
14405 10 CONTINUE
14406 IF( JW.GT.2 )
14407 $ T( JW, JW-2 ) = ZERO
14408 *
14409 * ==== Deflation detection loop ====
14410 *
14411 NS = JW
14412 ILST = INFQR + 1
14413 20 CONTINUE
14414 IF( ILST.LE.NS ) THEN
14415 IF( NS.EQ.1 ) THEN
14416 BULGE = .FALSE.
14417 ELSE
14418 BULGE = T( NS, NS-1 ).NE.ZERO
14419 END IF
14420 *
14421 * ==== Small spike tip test for deflation ====
14422 *
14423 IF( .NOT.BULGE ) THEN
14424 *
14425 * ==== Real eigenvalue ====
14426 *
14427 FOO = ABS( T( NS, NS ) )
14428 IF( FOO.EQ.ZERO )
14429 $ FOO = ABS( S )
14430 IF( ABS( S*V( 1, NS ) ).LE.MAX( SMLNUM, ULP*FOO ) ) THEN
14431 *
14432 * ==== Deflatable ====
14433 *
14434 NS = NS - 1
14435 ELSE
14436 *
14437 * ==== Undeflatable. Move it up out of the way.
14438 * . (DTREXC can not fail in this case.) ====
14439 *
14440 IFST = NS
14441 CALL DTREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, WORK,
14442 $ INFO )
14443 ILST = ILST + 1
14444 END IF
14445 ELSE
14446 *
14447 * ==== Complex conjugate pair ====
14448 *
14449 FOO = ABS( T( NS, NS ) ) + SQRT( ABS( T( NS, NS-1 ) ) )*
14450 $ SQRT( ABS( T( NS-1, NS ) ) )
14451 IF( FOO.EQ.ZERO )
14452 $ FOO = ABS( S )
14453 IF( MAX( ABS( S*V( 1, NS ) ), ABS( S*V( 1, NS-1 ) ) ).LE.
14454 $ MAX( SMLNUM, ULP*FOO ) ) THEN
14455 *
14456 * ==== Deflatable ====
14457 *
14458 NS = NS - 2
14459 ELSE
14460 *
14461 * ==== Undeflatable. Move them up out of the way.
14462 * . Fortunately, DTREXC does the right thing with
14463 * . ILST in case of a rare exchange failure. ====
14464 *
14465 IFST = NS
14466 CALL DTREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, WORK,
14467 $ INFO )
14468 ILST = ILST + 2
14469 END IF
14470 END IF
14471 *
14472 * ==== End deflation detection loop ====
14473 *
14474 GO TO 20
14475 END IF
14476 *
14477 * ==== Return to Hessenberg form ====
14478 *
14479 IF( NS.EQ.0 )
14480 $ S = ZERO
14481 *
14482 IF( NS.LT.JW ) THEN
14483 *
14484 * ==== sorting diagonal blocks of T improves accuracy for
14485 * . graded matrices. Bubble sort deals well with
14486 * . exchange failures. ====
14487 *
14488 SORTED = .false.
14489 I = NS + 1
14490 30 CONTINUE
14491 IF( SORTED )
14492 $ GO TO 50
14493 SORTED = .true.
14494 *
14495 KEND = I - 1
14496 I = INFQR + 1
14497 IF( I.EQ.NS ) THEN
14498 K = I + 1
14499 ELSE IF( T( I+1, I ).EQ.ZERO ) THEN
14500 K = I + 1
14501 ELSE
14502 K = I + 2
14503 END IF
14504 40 CONTINUE
14505 IF( K.LE.KEND ) THEN
14506 IF( K.EQ.I+1 ) THEN
14507 EVI = ABS( T( I, I ) )
14508 ELSE
14509 EVI = ABS( T( I, I ) ) + SQRT( ABS( T( I+1, I ) ) )*
14510 $ SQRT( ABS( T( I, I+1 ) ) )
14511 END IF
14512 *
14513 IF( K.EQ.KEND ) THEN
14514 EVK = ABS( T( K, K ) )
14515 ELSE IF( T( K+1, K ).EQ.ZERO ) THEN
14516 EVK = ABS( T( K, K ) )
14517 ELSE
14518 EVK = ABS( T( K, K ) ) + SQRT( ABS( T( K+1, K ) ) )*
14519 $ SQRT( ABS( T( K, K+1 ) ) )
14520 END IF
14521 *
14522 IF( EVI.GE.EVK ) THEN
14523 I = K
14524 ELSE
14525 SORTED = .false.
14526 IFST = I
14527 ILST = K
14528 CALL DTREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, WORK,
14529 $ INFO )
14530 IF( INFO.EQ.0 ) THEN
14531 I = ILST
14532 ELSE
14533 I = K
14534 END IF
14535 END IF
14536 IF( I.EQ.KEND ) THEN
14537 K = I + 1
14538 ELSE IF( T( I+1, I ).EQ.ZERO ) THEN
14539 K = I + 1
14540 ELSE
14541 K = I + 2
14542 END IF
14543 GO TO 40
14544 END IF
14545 GO TO 30
14546 50 CONTINUE
14547 END IF
14548 *
14549 * ==== Restore shift/eigenvalue array from T ====
14550 *
14551 I = JW
14552 60 CONTINUE
14553 IF( I.GE.INFQR+1 ) THEN
14554 IF( I.EQ.INFQR+1 ) THEN
14555 SR( KWTOP+I-1 ) = T( I, I )
14556 SI( KWTOP+I-1 ) = ZERO
14557 I = I - 1
14558 ELSE IF( T( I, I-1 ).EQ.ZERO ) THEN
14559 SR( KWTOP+I-1 ) = T( I, I )
14560 SI( KWTOP+I-1 ) = ZERO
14561 I = I - 1
14562 ELSE
14563 AA = T( I-1, I-1 )
14564 CC = T( I, I-1 )
14565 BB = T( I-1, I )
14566 DD = T( I, I )
14567 CALL DLANV2( AA, BB, CC, DD, SR( KWTOP+I-2 ),
14568 $ SI( KWTOP+I-2 ), SR( KWTOP+I-1 ),
14569 $ SI( KWTOP+I-1 ), CS, SN )
14570 I = I - 2
14571 END IF
14572 GO TO 60
14573 END IF
14574 *
14575 IF( NS.LT.JW .OR. S.EQ.ZERO ) THEN
14576 IF( NS.GT.1 .AND. S.NE.ZERO ) THEN
14577 *
14578 * ==== Reflect spike back into lower triangle ====
14579 *
14580 CALL DCOPY( NS, V, LDV, WORK, 1 )
14581 BETA = WORK( 1 )
14582 CALL DLARFG( NS, BETA, WORK( 2 ), 1, TAU )
14583 WORK( 1 ) = ONE
14584 *
14585 CALL DLASET( 'L', JW-2, JW-2, ZERO, ZERO, T( 3, 1 ), LDT )
14586 *
14587 CALL DLARF( 'L', NS, JW, WORK, 1, TAU, T, LDT,
14588 $ WORK( JW+1 ) )
14589 CALL DLARF( 'R', NS, NS, WORK, 1, TAU, T, LDT,
14590 $ WORK( JW+1 ) )
14591 CALL DLARF( 'R', JW, NS, WORK, 1, TAU, V, LDV,
14592 $ WORK( JW+1 ) )
14593 *
14594 CALL DGEHRD( JW, 1, NS, T, LDT, WORK, WORK( JW+1 ),
14595 $ LWORK-JW, INFO )
14596 END IF
14597 *
14598 * ==== Copy updated reduced window into place ====
14599 *
14600 IF( KWTOP.GT.1 )
14601 $ H( KWTOP, KWTOP-1 ) = S*V( 1, 1 )
14602 CALL DLACPY( 'U', JW, JW, T, LDT, H( KWTOP, KWTOP ), LDH )
14603 CALL DCOPY( JW-1, T( 2, 1 ), LDT+1, H( KWTOP+1, KWTOP ),
14604 $ LDH+1 )
14605 *
14606 * ==== Accumulate orthogonal matrix in order update
14607 * . H and Z, if requested. ====
14608 *
14609 IF( NS.GT.1 .AND. S.NE.ZERO )
14610 $ CALL DORMHR( 'R', 'N', JW, NS, 1, NS, T, LDT, WORK, V, LDV,
14611 $ WORK( JW+1 ), LWORK-JW, INFO )
14612 *
14613 * ==== Update vertical slab in H ====
14614 *
14615 IF( WANTT ) THEN
14616 LTOP = 1
14617 ELSE
14618 LTOP = KTOP
14619 END IF
14620 DO 70 KROW = LTOP, KWTOP - 1, NV
14621 KLN = MIN( NV, KWTOP-KROW )
14622 CALL DGEMM( 'N', 'N', KLN, JW, JW, ONE, H( KROW, KWTOP ),
14623 $ LDH, V, LDV, ZERO, WV, LDWV )
14624 CALL DLACPY( 'A', KLN, JW, WV, LDWV, H( KROW, KWTOP ), LDH )
14625 70 CONTINUE
14626 *
14627 * ==== Update horizontal slab in H ====
14628 *
14629 IF( WANTT ) THEN
14630 DO 80 KCOL = KBOT + 1, N, NH
14631 KLN = MIN( NH, N-KCOL+1 )
14632 CALL DGEMM( 'C', 'N', JW, KLN, JW, ONE, V, LDV,
14633 $ H( KWTOP, KCOL ), LDH, ZERO, T, LDT )
14634 CALL DLACPY( 'A', JW, KLN, T, LDT, H( KWTOP, KCOL ),
14635 $ LDH )
14636 80 CONTINUE
14637 END IF
14638 *
14639 * ==== Update vertical slab in Z ====
14640 *
14641 IF( WANTZ ) THEN
14642 DO 90 KROW = ILOZ, IHIZ, NV
14643 KLN = MIN( NV, IHIZ-KROW+1 )
14644 CALL DGEMM( 'N', 'N', KLN, JW, JW, ONE, Z( KROW, KWTOP ),
14645 $ LDZ, V, LDV, ZERO, WV, LDWV )
14646 CALL DLACPY( 'A', KLN, JW, WV, LDWV, Z( KROW, KWTOP ),
14647 $ LDZ )
14648 90 CONTINUE
14649 END IF
14650 END IF
14651 *
14652 * ==== Return the number of deflations ... ====
14653 *
14654 ND = JW - NS
14655 *
14656 * ==== ... and the number of shifts. (Subtracting
14657 * . INFQR from the spike length takes care
14658 * . of the case of a rare QR failure while
14659 * . calculating eigenvalues of the deflation
14660 * . window.) ====
14661 *
14662 NS = NS - INFQR
14663 *
14664 * ==== Return optimal workspace. ====
14665 *
14666 WORK( 1 ) = DBLE( LWKOPT )
14667 *
14668 * ==== End of DLAQR2 ====
14669 *
14670 END
14671 C
14672 C-----------------------------------------------------------------------
14673 C-----------------------------------------------------------------------
14674 SUBROUTINE DLAQR3( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
14675 $ IHIZ, Z, LDZ, NS, ND, SR, SI, V, LDV, NH, T,
14676 $ LDT, NV, WV, LDWV, WORK, LWORK )
14677 *
14678 * -- LAPACK auxiliary routine (version 3.2.2) --
14679 * Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
14680 * -- June 2010 --
14681 *
14682 * .. Scalar Arguments ..
14683 INTEGER IHIZ, ILOZ, KBOT, KTOP, LDH, LDT, LDV, LDWV,
14684 $ LDZ, LWORK, N, ND, NH, NS, NV, NW
14685 LOGICAL WANTT, WANTZ
14686 * ..
14687 * .. Array Arguments ..
14688 DOUBLE PRECISION H( LDH, * ), SI( * ), SR( * ), T( LDT, * ),
14689 $ V( LDV, * ), WORK( * ), WV( LDWV, * ),
14690 $ Z( LDZ, * )
14691 * ..
14692 *
14693 * ******************************************************************
14694 * Aggressive early deflation:
14695 *
14696 * This subroutine accepts as input an upper Hessenberg matrix
14697 * H and performs an orthogonal similarity transformation
14698 * designed to detect and deflate fully converged eigenvalues from
14699 * a trailing principal submatrix. On output H has been over-
14700 * written by a new Hessenberg matrix that is a perturbation of
14701 * an orthogonal similarity transformation of H. It is to be
14702 * hoped that the final version of H has many zero subdiagonal
14703 * entries.
14704 *
14705 * ******************************************************************
14706 * WANTT (input) LOGICAL
14707 * If .TRUE., then the Hessenberg matrix H is fully updated
14708 * so that the quasi-triangular Schur factor may be
14709 * computed (in cooperation with the calling subroutine).
14710 * If .FALSE., then only enough of H is updated to preserve
14711 * the eigenvalues.
14712 *
14713 * WANTZ (input) LOGICAL
14714 * If .TRUE., then the orthogonal matrix Z is updated so
14715 * so that the orthogonal Schur factor may be computed
14716 * (in cooperation with the calling subroutine).
14717 * If .FALSE., then Z is not referenced.
14718 *
14719 * N (input) INTEGER
14720 * The order of the matrix H and (if WANTZ is .TRUE.) the
14721 * order of the orthogonal matrix Z.
14722 *
14723 * KTOP (input) INTEGER
14724 * It is assumed that either KTOP = 1 or H(KTOP,KTOP-1)=0.
14725 * KBOT and KTOP together determine an isolated block
14726 * along the diagonal of the Hessenberg matrix.
14727 *
14728 * KBOT (input) INTEGER
14729 * It is assumed without a check that either
14730 * KBOT = N or H(KBOT+1,KBOT)=0. KBOT and KTOP together
14731 * determine an isolated block along the diagonal of the
14732 * Hessenberg matrix.
14733 *
14734 * NW (input) INTEGER
14735 * Deflation window size. 1 .LE. NW .LE. (KBOT-KTOP+1).
14736 *
14737 * H (input/output) DOUBLE PRECISION array, dimension (LDH,N)
14738 * On input the initial N-by-N section of H stores the
14739 * Hessenberg matrix undergoing aggressive early deflation.
14740 * On output H has been transformed by an orthogonal
14741 * similarity transformation, perturbed, and the returned
14742 * to Hessenberg form that (it is to be hoped) has some
14743 * zero subdiagonal entries.
14744 *
14745 * LDH (input) integer
14746 * Leading dimension of H just as declared in the calling
14747 * subroutine. N .LE. LDH
14748 *
14749 * ILOZ (input) INTEGER
14750 * IHIZ (input) INTEGER
14751 * Specify the rows of Z to which transformations must be
14752 * applied if WANTZ is .TRUE.. 1 .LE. ILOZ .LE. IHIZ .LE. N.
14753 *
14754 * Z (input/output) DOUBLE PRECISION array, dimension (LDZ,N)
14755 * IF WANTZ is .TRUE., then on output, the orthogonal
14756 * similarity transformation mentioned above has been
14757 * accumulated into Z(ILOZ:IHIZ,ILO:IHI) from the right.
14758 * If WANTZ is .FALSE., then Z is unreferenced.
14759 *
14760 * LDZ (input) integer
14761 * The leading dimension of Z just as declared in the
14762 * calling subroutine. 1 .LE. LDZ.
14763 *
14764 * NS (output) integer
14765 * The number of unconverged (ie approximate) eigenvalues
14766 * returned in SR and SI that may be used as shifts by the
14767 * calling subroutine.
14768 *
14769 * ND (output) integer
14770 * The number of converged eigenvalues uncovered by this
14771 * subroutine.
14772 *
14773 * SR (output) DOUBLE PRECISION array, dimension (KBOT)
14774 * SI (output) DOUBLE PRECISION array, dimension (KBOT)
14775 * On output, the real and imaginary parts of approximate
14776 * eigenvalues that may be used for shifts are stored in
14777 * SR(KBOT-ND-NS+1) through SR(KBOT-ND) and
14778 * SI(KBOT-ND-NS+1) through SI(KBOT-ND), respectively.
14779 * The real and imaginary parts of converged eigenvalues
14780 * are stored in SR(KBOT-ND+1) through SR(KBOT) and
14781 * SI(KBOT-ND+1) through SI(KBOT), respectively.
14782 *
14783 * V (workspace) DOUBLE PRECISION array, dimension (LDV,NW)
14784 * An NW-by-NW work array.
14785 *
14786 * LDV (input) integer scalar
14787 * The leading dimension of V just as declared in the
14788 * calling subroutine. NW .LE. LDV
14789 *
14790 * NH (input) integer scalar
14791 * The number of columns of T. NH.GE.NW.
14792 *
14793 * T (workspace) DOUBLE PRECISION array, dimension (LDT,NW)
14794 *
14795 * LDT (input) integer
14796 * The leading dimension of T just as declared in the
14797 * calling subroutine. NW .LE. LDT
14798 *
14799 * NV (input) integer
14800 * The number of rows of work array WV available for
14801 * workspace. NV.GE.NW.
14802 *
14803 * WV (workspace) DOUBLE PRECISION array, dimension (LDWV,NW)
14804 *
14805 * LDWV (input) integer
14806 * The leading dimension of W just as declared in the
14807 * calling subroutine. NW .LE. LDV
14808 *
14809 * WORK (workspace) DOUBLE PRECISION array, dimension (LWORK)
14810 * On exit, WORK(1) is set to an estimate of the optimal value
14811 * of LWORK for the given values of N, NW, KTOP and KBOT.
14812 *
14813 * LWORK (input) integer
14814 * The dimension of the work array WORK. LWORK = 2*NW
14815 * suffices, but greater efficiency may result from larger
14816 * values of LWORK.
14817 *
14818 * If LWORK = -1, then a workspace query is assumed; DLAQR3
14819 * only estimates the optimal workspace size for the given
14820 * values of N, NW, KTOP and KBOT. The estimate is returned
14821 * in WORK(1). No error message related to LWORK is issued
14822 * by XERBLA. Neither H nor Z are accessed.
14823 *
14824 * ================================================================
14825 * Based on contributions by
14826 * Karen Braman and Ralph Byers, Department of Mathematics,
14827 * University of Kansas, USA
14828 *
14829 * ================================================================
14830 * .. Parameters ..
14831 DOUBLE PRECISION ZERO, ONE
14832 PARAMETER ( ZERO = 0.0d0, ONE = 1.0d0 )
14833 * ..
14834 * .. Local Scalars ..
14835 DOUBLE PRECISION AA, BB, BETA, CC, CS, DD, EVI, EVK, FOO, S,
14836 $ SAFMAX, SAFMIN, SMLNUM, SN, TAU, ULP
14837 INTEGER I, IFST, ILST, INFO, INFQR, J, JW, K, KCOL,
14838 $ KEND, KLN, KROW, KWTOP, LTOP, LWK1, LWK2, LWK3,
14839 $ LWKOPT, NMIN
14840 LOGICAL BULGE, SORTED
14841 * ..
14842 * .. External Functions ..
14843 DOUBLE PRECISION DLAMCH
14844 INTEGER ILAENV
14845 EXTERNAL DLAMCH, ILAENV
14846 * ..
14847 * .. External Subroutines ..
14848 EXTERNAL DCOPY, DGEHRD, DGEMM, DLABAD, DLACPY, DLAHQR,
14849 $ DLANV2, DLAQR4, DLARF, DLARFG, DLASET, DORMHR,
14850 $ DTREXC
14851 * ..
14852 * .. Intrinsic Functions ..
14853 INTRINSIC ABS, DBLE, INT, MAX, MIN, SQRT
14854 * ..
14855 * .. Executable Statements ..
14856 *
14857 * ==== Estimate optimal workspace. ====
14858 *
14859 JW = MIN( NW, KBOT-KTOP+1 )
14860 IF( JW.LE.2 ) THEN
14861 LWKOPT = 1
14862 ELSE
14863 *
14864 * ==== Workspace query call to DGEHRD ====
14865 *
14866 CALL DGEHRD( JW, 1, JW-1, T, LDT, WORK, WORK, -1, INFO )
14867 LWK1 = INT( WORK( 1 ) )
14868 *
14869 * ==== Workspace query call to DORMHR ====
14870 *
14871 CALL DORMHR( 'R', 'N', JW, JW, 1, JW-1, T, LDT, WORK, V, LDV,
14872 $ WORK, -1, INFO )
14873 LWK2 = INT( WORK( 1 ) )
14874 *
14875 * ==== Workspace query call to DLAQR4 ====
14876 *
14877 CALL DLAQR4( .true., .true., JW, 1, JW, T, LDT, SR, SI, 1, JW,
14878 $ V, LDV, WORK, -1, INFQR )
14879 LWK3 = INT( WORK( 1 ) )
14880 *
14881 * ==== Optimal workspace ====
14882 *
14883 LWKOPT = MAX( JW+MAX( LWK1, LWK2 ), LWK3 )
14884 END IF
14885 *
14886 * ==== Quick return in case of workspace query. ====
14887 *
14888 IF( LWORK.EQ.-1 ) THEN
14889 WORK( 1 ) = DBLE( LWKOPT )
14890 RETURN
14891 END IF
14892 *
14893 * ==== Nothing to do ...
14894 * ... for an empty active block ... ====
14895 NS = 0
14896 ND = 0
14897 WORK( 1 ) = ONE
14898 IF( KTOP.GT.KBOT )
14899 $ RETURN
14900 * ... nor for an empty deflation window. ====
14901 IF( NW.LT.1 )
14902 $ RETURN
14903 *
14904 * ==== Machine constants ====
14905 *
14906 SAFMIN = DLAMCH( 'SAFE MINIMUM' )
14907 SAFMAX = ONE / SAFMIN
14908 CALL DLABAD( SAFMIN, SAFMAX )
14909 ULP = DLAMCH( 'PRECISION' )
14910 SMLNUM = SAFMIN*( DBLE( N ) / ULP )
14911 *
14912 * ==== Setup deflation window ====
14913 *
14914 JW = MIN( NW, KBOT-KTOP+1 )
14915 KWTOP = KBOT - JW + 1
14916 IF( KWTOP.EQ.KTOP ) THEN
14917 S = ZERO
14918 ELSE
14919 S = H( KWTOP, KWTOP-1 )
14920 END IF
14921 *
14922 IF( KBOT.EQ.KWTOP ) THEN
14923 *
14924 * ==== 1-by-1 deflation window: not much to do ====
14925 *
14926 SR( KWTOP ) = H( KWTOP, KWTOP )
14927 SI( KWTOP ) = ZERO
14928 NS = 1
14929 ND = 0
14930 IF( ABS( S ).LE.MAX( SMLNUM, ULP*ABS( H( KWTOP, KWTOP ) ) ) )
14931 $ THEN
14932 NS = 0
14933 ND = 1
14934 IF( KWTOP.GT.KTOP )
14935 $ H( KWTOP, KWTOP-1 ) = ZERO
14936 END IF
14937 WORK( 1 ) = ONE
14938 RETURN
14939 END IF
14940 *
14941 * ==== Convert to spike-triangular form. (In case of a
14942 * . rare QR failure, this routine continues to do
14943 * . aggressive early deflation using that part of
14944 * . the deflation window that converged using INFQR
14945 * . here and there to keep track.) ====
14946 *
14947 CALL DLACPY( 'U', JW, JW, H( KWTOP, KWTOP ), LDH, T, LDT )
14948 CALL DCOPY( JW-1, H( KWTOP+1, KWTOP ), LDH+1, T( 2, 1 ), LDT+1 )
14949 *
14950 CALL DLASET( 'A', JW, JW, ZERO, ONE, V, LDV )
14951 NMIN = ILAENV( 12, 'DLAQR3', 'SV', JW, 1, JW, LWORK )
14952 IF( JW.GT.NMIN ) THEN
14953 CALL DLAQR4( .true., .true., JW, 1, JW, T, LDT, SR( KWTOP ),
14954 $ SI( KWTOP ), 1, JW, V, LDV, WORK, LWORK, INFQR )
14955 ELSE
14956 CALL DLAHQR( .true., .true., JW, 1, JW, T, LDT, SR( KWTOP ),
14957 $ SI( KWTOP ), 1, JW, V, LDV, INFQR )
14958 END IF
14959 *
14960 * ==== DTREXC needs a clean margin near the diagonal ====
14961 *
14962 DO 10 J = 1, JW - 3
14963 T( J+2, J ) = ZERO
14964 T( J+3, J ) = ZERO
14965 10 CONTINUE
14966 IF( JW.GT.2 )
14967 $ T( JW, JW-2 ) = ZERO
14968 *
14969 * ==== Deflation detection loop ====
14970 *
14971 NS = JW
14972 ILST = INFQR + 1
14973 20 CONTINUE
14974 IF( ILST.LE.NS ) THEN
14975 IF( NS.EQ.1 ) THEN
14976 BULGE = .FALSE.
14977 ELSE
14978 BULGE = T( NS, NS-1 ).NE.ZERO
14979 END IF
14980 *
14981 * ==== Small spike tip test for deflation ====
14982 *
14983 IF( .NOT.BULGE ) THEN
14984 *
14985 * ==== Real eigenvalue ====
14986 *
14987 FOO = ABS( T( NS, NS ) )
14988 IF( FOO.EQ.ZERO )
14989 $ FOO = ABS( S )
14990 IF( ABS( S*V( 1, NS ) ).LE.MAX( SMLNUM, ULP*FOO ) ) THEN
14991 *
14992 * ==== Deflatable ====
14993 *
14994 NS = NS - 1
14995 ELSE
14996 *
14997 * ==== Undeflatable. Move it up out of the way.
14998 * . (DTREXC can not fail in this case.) ====
14999 *
15000 IFST = NS
15001 CALL DTREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, WORK,
15002 $ INFO )
15003 ILST = ILST + 1
15004 END IF
15005 ELSE
15006 *
15007 * ==== Complex conjugate pair ====
15008 *
15009 FOO = ABS( T( NS, NS ) ) + SQRT( ABS( T( NS, NS-1 ) ) )*
15010 $ SQRT( ABS( T( NS-1, NS ) ) )
15011 IF( FOO.EQ.ZERO )
15012 $ FOO = ABS( S )
15013 IF( MAX( ABS( S*V( 1, NS ) ), ABS( S*V( 1, NS-1 ) ) ).LE.
15014 $ MAX( SMLNUM, ULP*FOO ) ) THEN
15015 *
15016 * ==== Deflatable ====
15017 *
15018 NS = NS - 2
15019 ELSE
15020 *
15021 * ==== Undeflatable. Move them up out of the way.
15022 * . Fortunately, DTREXC does the right thing with
15023 * . ILST in case of a rare exchange failure. ====
15024 *
15025 IFST = NS
15026 CALL DTREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, WORK,
15027 $ INFO )
15028 ILST = ILST + 2
15029 END IF
15030 END IF
15031 *
15032 * ==== End deflation detection loop ====
15033 *
15034 GO TO 20
15035 END IF
15036 *
15037 * ==== Return to Hessenberg form ====
15038 *
15039 IF( NS.EQ.0 )
15040 $ S = ZERO
15041 *
15042 IF( NS.LT.JW ) THEN
15043 *
15044 * ==== sorting diagonal blocks of T improves accuracy for
15045 * . graded matrices. Bubble sort deals well with
15046 * . exchange failures. ====
15047 *
15048 SORTED = .false.
15049 I = NS + 1
15050 30 CONTINUE
15051 IF( SORTED )
15052 $ GO TO 50
15053 SORTED = .true.
15054 *
15055 KEND = I - 1
15056 I = INFQR + 1
15057 IF( I.EQ.NS ) THEN
15058 K = I + 1
15059 ELSE IF( T( I+1, I ).EQ.ZERO ) THEN
15060 K = I + 1
15061 ELSE
15062 K = I + 2
15063 END IF
15064 40 CONTINUE
15065 IF( K.LE.KEND ) THEN
15066 IF( K.EQ.I+1 ) THEN
15067 EVI = ABS( T( I, I ) )
15068 ELSE
15069 EVI = ABS( T( I, I ) ) + SQRT( ABS( T( I+1, I ) ) )*
15070 $ SQRT( ABS( T( I, I+1 ) ) )
15071 END IF
15072 *
15073 IF( K.EQ.KEND ) THEN
15074 EVK = ABS( T( K, K ) )
15075 ELSE IF( T( K+1, K ).EQ.ZERO ) THEN
15076 EVK = ABS( T( K, K ) )
15077 ELSE
15078 EVK = ABS( T( K, K ) ) + SQRT( ABS( T( K+1, K ) ) )*
15079 $ SQRT( ABS( T( K, K+1 ) ) )
15080 END IF
15081 *
15082 IF( EVI.GE.EVK ) THEN
15083 I = K
15084 ELSE
15085 SORTED = .false.
15086 IFST = I
15087 ILST = K
15088 CALL DTREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, WORK,
15089 $ INFO )
15090 IF( INFO.EQ.0 ) THEN
15091 I = ILST
15092 ELSE
15093 I = K
15094 END IF
15095 END IF
15096 IF( I.EQ.KEND ) THEN
15097 K = I + 1
15098 ELSE IF( T( I+1, I ).EQ.ZERO ) THEN
15099 K = I + 1
15100 ELSE
15101 K = I + 2
15102 END IF
15103 GO TO 40
15104 END IF
15105 GO TO 30
15106 50 CONTINUE
15107 END IF
15108 *
15109 * ==== Restore shift/eigenvalue array from T ====
15110 *
15111 I = JW
15112 60 CONTINUE
15113 IF( I.GE.INFQR+1 ) THEN
15114 IF( I.EQ.INFQR+1 ) THEN
15115 SR( KWTOP+I-1 ) = T( I, I )
15116 SI( KWTOP+I-1 ) = ZERO
15117 I = I - 1
15118 ELSE IF( T( I, I-1 ).EQ.ZERO ) THEN
15119 SR( KWTOP+I-1 ) = T( I, I )
15120 SI( KWTOP+I-1 ) = ZERO
15121 I = I - 1
15122 ELSE
15123 AA = T( I-1, I-1 )
15124 CC = T( I, I-1 )
15125 BB = T( I-1, I )
15126 DD = T( I, I )
15127 CALL DLANV2( AA, BB, CC, DD, SR( KWTOP+I-2 ),
15128 $ SI( KWTOP+I-2 ), SR( KWTOP+I-1 ),
15129 $ SI( KWTOP+I-1 ), CS, SN )
15130 I = I - 2
15131 END IF
15132 GO TO 60
15133 END IF
15134 *
15135 IF( NS.LT.JW .OR. S.EQ.ZERO ) THEN
15136 IF( NS.GT.1 .AND. S.NE.ZERO ) THEN
15137 *
15138 * ==== Reflect spike back into lower triangle ====
15139 *
15140 CALL DCOPY( NS, V, LDV, WORK, 1 )
15141 BETA = WORK( 1 )
15142 CALL DLARFG( NS, BETA, WORK( 2 ), 1, TAU )
15143 WORK( 1 ) = ONE
15144 *
15145 CALL DLASET( 'L', JW-2, JW-2, ZERO, ZERO, T( 3, 1 ), LDT )
15146 *
15147 CALL DLARF( 'L', NS, JW, WORK, 1, TAU, T, LDT,
15148 $ WORK( JW+1 ) )
15149 CALL DLARF( 'R', NS, NS, WORK, 1, TAU, T, LDT,
15150 $ WORK( JW+1 ) )
15151 CALL DLARF( 'R', JW, NS, WORK, 1, TAU, V, LDV,
15152 $ WORK( JW+1 ) )
15153 *
15154 CALL DGEHRD( JW, 1, NS, T, LDT, WORK, WORK( JW+1 ),
15155 $ LWORK-JW, INFO )
15156 END IF
15157 *
15158 * ==== Copy updated reduced window into place ====
15159 *
15160 IF( KWTOP.GT.1 )
15161 $ H( KWTOP, KWTOP-1 ) = S*V( 1, 1 )
15162 CALL DLACPY( 'U', JW, JW, T, LDT, H( KWTOP, KWTOP ), LDH )
15163 CALL DCOPY( JW-1, T( 2, 1 ), LDT+1, H( KWTOP+1, KWTOP ),
15164 $ LDH+1 )
15165 *
15166 * ==== Accumulate orthogonal matrix in order update
15167 * . H and Z, if requested. ====
15168 *
15169 IF( NS.GT.1 .AND. S.NE.ZERO )
15170 $ CALL DORMHR( 'R', 'N', JW, NS, 1, NS, T, LDT, WORK, V, LDV,
15171 $ WORK( JW+1 ), LWORK-JW, INFO )
15172 *
15173 * ==== Update vertical slab in H ====
15174 *
15175 IF( WANTT ) THEN
15176 LTOP = 1
15177 ELSE
15178 LTOP = KTOP
15179 END IF
15180 DO 70 KROW = LTOP, KWTOP - 1, NV
15181 KLN = MIN( NV, KWTOP-KROW )
15182 CALL DGEMM( 'N', 'N', KLN, JW, JW, ONE, H( KROW, KWTOP ),
15183 $ LDH, V, LDV, ZERO, WV, LDWV )
15184 CALL DLACPY( 'A', KLN, JW, WV, LDWV, H( KROW, KWTOP ), LDH )
15185 70 CONTINUE
15186 *
15187 * ==== Update horizontal slab in H ====
15188 *
15189 IF( WANTT ) THEN
15190 DO 80 KCOL = KBOT + 1, N, NH
15191 KLN = MIN( NH, N-KCOL+1 )
15192 CALL DGEMM( 'C', 'N', JW, KLN, JW, ONE, V, LDV,
15193 $ H( KWTOP, KCOL ), LDH, ZERO, T, LDT )
15194 CALL DLACPY( 'A', JW, KLN, T, LDT, H( KWTOP, KCOL ),
15195 $ LDH )
15196 80 CONTINUE
15197 END IF
15198 *
15199 * ==== Update vertical slab in Z ====
15200 *
15201 IF( WANTZ ) THEN
15202 DO 90 KROW = ILOZ, IHIZ, NV
15203 KLN = MIN( NV, IHIZ-KROW+1 )
15204 CALL DGEMM( 'N', 'N', KLN, JW, JW, ONE, Z( KROW, KWTOP ),
15205 $ LDZ, V, LDV, ZERO, WV, LDWV )
15206 CALL DLACPY( 'A', KLN, JW, WV, LDWV, Z( KROW, KWTOP ),
15207 $ LDZ )
15208 90 CONTINUE
15209 END IF
15210 END IF
15211 *
15212 * ==== Return the number of deflations ... ====
15213 *
15214 ND = JW - NS
15215 *
15216 * ==== ... and the number of shifts. (Subtracting
15217 * . INFQR from the spike length takes care
15218 * . of the case of a rare QR failure while
15219 * . calculating eigenvalues of the deflation
15220 * . window.) ====
15221 *
15222 NS = NS - INFQR
15223 *
15224 * ==== Return optimal workspace. ====
15225 *
15226 WORK( 1 ) = DBLE( LWKOPT )
15227 *
15228 * ==== End of DLAQR3 ====
15229 *
15230 END
15231 C
15232 C-----------------------------------------------------------------------
15233 C-----------------------------------------------------------------------
15234 SUBROUTINE DLAQR4( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI,
15235 $ ILOZ, IHIZ, Z, LDZ, WORK, LWORK, INFO )
15236 *
15237 * -- LAPACK auxiliary routine (version 3.2) --
15238 * Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
15239 * November 2006
15240 *
15241 * .. Scalar Arguments ..
15242 INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
15243 LOGICAL WANTT, WANTZ
15244 * ..
15245 * .. Array Arguments ..
15246 DOUBLE PRECISION H( LDH, * ), WI( * ), WORK( * ), WR( * ),
15247 $ Z( LDZ, * )
15248 * ..
15249 *
15250 * This subroutine implements one level of recursion for DLAQR0.
15251 * It is a complete implementation of the small bulge multi-shift
15252 * QR algorithm. It may be called by DLAQR0 and, for large enough
15253 * deflation window size, it may be called by DLAQR3. This
15254 * subroutine is identical to DLAQR0 except that it calls DLAQR2
15255 * instead of DLAQR3.
15256 *
15257 * Purpose
15258 * =======
15259 *
15260 * DLAQR4 computes the eigenvalues of a Hessenberg matrix H
15261 * and, optionally, the matrices T and Z from the Schur decomposition
15262 * H = Z T Z**T, where T is an upper quasi-triangular matrix (the
15263 * Schur form), and Z is the orthogonal matrix of Schur vectors.
15264 *
15265 * Optionally Z may be postmultiplied into an input orthogonal
15266 * matrix Q so that this routine can give the Schur factorization
15267 * of a matrix A which has been reduced to the Hessenberg form H
15268 * by the orthogonal matrix Q: A = Q*H*Q**T = (QZ)*T*(QZ)**T.
15269 *
15270 * Arguments
15271 * =========
15272 *
15273 * WANTT (input) LOGICAL
15274 * = .TRUE. : the full Schur form T is required;
15275 * = .FALSE.: only eigenvalues are required.
15276 *
15277 * WANTZ (input) LOGICAL
15278 * = .TRUE. : the matrix of Schur vectors Z is required;
15279 * = .FALSE.: Schur vectors are not required.
15280 *
15281 * N (input) INTEGER
15282 * The order of the matrix H. N .GE. 0.
15283 *
15284 * ILO (input) INTEGER
15285 * IHI (input) INTEGER
15286 * It is assumed that H is already upper triangular in rows
15287 * and columns 1:ILO-1 and IHI+1:N and, if ILO.GT.1,
15288 * H(ILO,ILO-1) is zero. ILO and IHI are normally set by a
15289 * previous call to DGEBAL, and then passed to DGEHRD when the
15290 * matrix output by DGEBAL is reduced to Hessenberg form.
15291 * Otherwise, ILO and IHI should be set to 1 and N,
15292 * respectively. If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N.
15293 * If N = 0, then ILO = 1 and IHI = 0.
15294 *
15295 * H (input/output) DOUBLE PRECISION array, dimension (LDH,N)
15296 * On entry, the upper Hessenberg matrix H.
15297 * On exit, if INFO = 0 and WANTT is .TRUE., then H contains
15298 * the upper quasi-triangular matrix T from the Schur
15299 * decomposition (the Schur form); 2-by-2 diagonal blocks
15300 * (corresponding to complex conjugate pairs of eigenvalues)
15301 * are returned in standard form, with H(i,i) = H(i+1,i+1)
15302 * and H(i+1,i)*H(i,i+1).LT.0. If INFO = 0 and WANTT is
15303 * .FALSE., then the contents of H are unspecified on exit.
15304 * (The output value of H when INFO.GT.0 is given under the
15305 * description of INFO below.)
15306 *
15307 * This subroutine may explicitly set H(i,j) = 0 for i.GT.j and
15308 * j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N.
15309 *
15310 * LDH (input) INTEGER
15311 * The leading dimension of the array H. LDH .GE. max(1,N).
15312 *
15313 * WR (output) DOUBLE PRECISION array, dimension (IHI)
15314 * WI (output) DOUBLE PRECISION array, dimension (IHI)
15315 * The real and imaginary parts, respectively, of the computed
15316 * eigenvalues of H(ILO:IHI,ILO:IHI) are stored in WR(ILO:IHI)
15317 * and WI(ILO:IHI). If two eigenvalues are computed as a
15318 * complex conjugate pair, they are stored in consecutive
15319 * elements of WR and WI, say the i-th and (i+1)th, with
15320 * WI(i) .GT. 0 and WI(i+1) .LT. 0. If WANTT is .TRUE., then
15321 * the eigenvalues are stored in the same order as on the
15322 * diagonal of the Schur form returned in H, with
15323 * WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2 diagonal
15324 * block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and
15325 * WI(i+1) = -WI(i).
15326 *
15327 * ILOZ (input) INTEGER
15328 * IHIZ (input) INTEGER
15329 * Specify the rows of Z to which transformations must be
15330 * applied if WANTZ is .TRUE..
15331 * 1 .LE. ILOZ .LE. ILO; IHI .LE. IHIZ .LE. N.
15332 *
15333 * Z (input/output) DOUBLE PRECISION array, dimension (LDZ,IHI)
15334 * If WANTZ is .FALSE., then Z is not referenced.
15335 * If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is
15336 * replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the
15337 * orthogonal Schur factor of H(ILO:IHI,ILO:IHI).
15338 * (The output value of Z when INFO.GT.0 is given under
15339 * the description of INFO below.)
15340 *
15341 * LDZ (input) INTEGER
15342 * The leading dimension of the array Z. if WANTZ is .TRUE.
15343 * then LDZ.GE.MAX(1,IHIZ). Otherwize, LDZ.GE.1.
15344 *
15345 * WORK (workspace/output) DOUBLE PRECISION array, dimension LWORK
15346 * On exit, if LWORK = -1, WORK(1) returns an estimate of
15347 * the optimal value for LWORK.
15348 *
15349 * LWORK (input) INTEGER
15350 * The dimension of the array WORK. LWORK .GE. max(1,N)
15351 * is sufficient, but LWORK typically as large as 6*N may
15352 * be required for optimal performance. A workspace query
15353 * to determine the optimal workspace size is recommended.
15354 *
15355 * If LWORK = -1, then DLAQR4 does a workspace query.
15356 * In this case, DLAQR4 checks the input parameters and
15357 * estimates the optimal workspace size for the given
15358 * values of N, ILO and IHI. The estimate is returned
15359 * in WORK(1). No error message related to LWORK is
15360 * issued by XERBLA. Neither H nor Z are accessed.
15361 *
15362 *
15363 * INFO (output) INTEGER
15364 * = 0: successful exit
15365 * .GT. 0: if INFO = i, DLAQR4 failed to compute all of
15366 * the eigenvalues. Elements 1:ilo-1 and i+1:n of WR
15367 * and WI contain those eigenvalues which have been
15368 * successfully computed. (Failures are rare.)
15369 *
15370 * If INFO .GT. 0 and WANT is .FALSE., then on exit,
15371 * the remaining unconverged eigenvalues are the eigen-
15372 * values of the upper Hessenberg matrix rows and
15373 * columns ILO through INFO of the final, output
15374 * value of H.
15375 *
15376 * If INFO .GT. 0 and WANTT is .TRUE., then on exit
15377 *
15378 * (*) (initial value of H)*U = U*(final value of H)
15379 *
15380 * where U is an orthogonal matrix. The final
15381 * value of H is upper Hessenberg and quasi-triangular
15382 * in rows and columns INFO+1 through IHI.
15383 *
15384 * If INFO .GT. 0 and WANTZ is .TRUE., then on exit
15385 *
15386 * (final value of Z(ILO:IHI,ILOZ:IHIZ)
15387 * = (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U
15388 *
15389 * where U is the orthogonal matrix in (*) (regard-
15390 * less of the value of WANTT.)
15391 *
15392 * If INFO .GT. 0 and WANTZ is .FALSE., then Z is not
15393 * accessed.
15394 *
15395 * ================================================================
15396 * Based on contributions by
15397 * Karen Braman and Ralph Byers, Department of Mathematics,
15398 * University of Kansas, USA
15399 *
15400 * ================================================================
15401 * References:
15402 * K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
15403 * Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
15404 * Performance, SIAM Journal of Matrix Analysis, volume 23, pages
15405 * 929--947, 2002.
15406 *
15407 * K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
15408 * Algorithm Part II: Aggressive Early Deflation, SIAM Journal
15409 * of Matrix Analysis, volume 23, pages 948--973, 2002.
15410 *
15411 * ================================================================
15412 * .. Parameters ..
15413 *
15414 * ==== Matrices of order NTINY or smaller must be processed by
15415 * . DLAHQR because of insufficient subdiagonal scratch space.
15416 * . (This is a hard limit.) ====
15417 INTEGER NTINY
15418 PARAMETER ( NTINY = 11 )
15419 *
15420 * ==== Exceptional deflation windows: try to cure rare
15421 * . slow convergence by varying the size of the
15422 * . deflation window after KEXNW iterations. ====
15423 INTEGER KEXNW
15424 PARAMETER ( KEXNW = 5 )
15425 *
15426 * ==== Exceptional shifts: try to cure rare slow convergence
15427 * . with ad-hoc exceptional shifts every KEXSH iterations.
15428 * . ====
15429 INTEGER KEXSH
15430 PARAMETER ( KEXSH = 6 )
15431 *
15432 * ==== The constants WILK1 and WILK2 are used to form the
15433 * . exceptional shifts. ====
15434 DOUBLE PRECISION WILK1, WILK2
15435 PARAMETER ( WILK1 = 0.75d0, WILK2 = -0.4375d0 )
15436 DOUBLE PRECISION ZERO, ONE
15437 PARAMETER ( ZERO = 0.0d0, ONE = 1.0d0 )
15438 * ..
15439 * .. Local Scalars ..
15440 DOUBLE PRECISION AA, BB, CC, CS, DD, SN, SS, SWAP
15441 INTEGER I, INF, IT, ITMAX, K, KACC22, KBOT, KDU, KS,
15442 $ KT, KTOP, KU, KV, KWH, KWTOP, KWV, LD, LS,
15443 $ LWKOPT, NDEC, NDFL, NH, NHO, NIBBLE, NMIN, NS,
15444 $ NSMAX, NSR, NVE, NW, NWMAX, NWR, NWUPBD
15445 LOGICAL SORTED
15446 CHARACTER JBCMPZ*2
15447 * ..
15448 * .. External Functions ..
15449 INTEGER ILAENV
15450 EXTERNAL ILAENV
15451 * ..
15452 * .. Local Arrays ..
15453 DOUBLE PRECISION ZDUM( 1, 1 )
15454 * ..
15455 * .. External Subroutines ..
15456 EXTERNAL DLACPY, DLAHQR, DLANV2, DLAQR2, DLAQR5
15457 * ..
15458 * .. Intrinsic Functions ..
15459 INTRINSIC ABS, DBLE, INT, MAX, MIN, MOD
15460 * ..
15461 * .. Executable Statements ..
15462 INFO = 0
15463 *
15464 * ==== Quick return for N = 0: nothing to do. ====
15465 *
15466 IF( N.EQ.0 ) THEN
15467 WORK( 1 ) = ONE
15468 RETURN
15469 END IF
15470 *
15471 IF( N.LE.NTINY ) THEN
15472 *
15473 * ==== Tiny matrices must use DLAHQR. ====
15474 *
15475 LWKOPT = 1
15476 IF( LWORK.NE.-1 )
15477 $ CALL DLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI,
15478 $ ILOZ, IHIZ, Z, LDZ, INFO )
15479 ELSE
15480 *
15481 * ==== Use small bulge multi-shift QR with aggressive early
15482 * . deflation on larger-than-tiny matrices. ====
15483 *
15484 * ==== Hope for the best. ====
15485 *
15486 INFO = 0
15487 *
15488 * ==== Set up job flags for ILAENV. ====
15489 *
15490 IF( WANTT ) THEN
15491 JBCMPZ( 1: 1 ) = 'S'
15492 ELSE
15493 JBCMPZ( 1: 1 ) = 'E'
15494 END IF
15495 IF( WANTZ ) THEN
15496 JBCMPZ( 2: 2 ) = 'V'
15497 ELSE
15498 JBCMPZ( 2: 2 ) = 'N'
15499 END IF
15500 *
15501 * ==== NWR = recommended deflation window size. At this
15502 * . point, N .GT. NTINY = 11, so there is enough
15503 * . subdiagonal workspace for NWR.GE.2 as required.
15504 * . (In fact, there is enough subdiagonal space for
15505 * . NWR.GE.3.) ====
15506 *
15507 NWR = ILAENV( 13, 'DLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
15508 NWR = MAX( 2, NWR )
15509 NWR = MIN( IHI-ILO+1, ( N-1 ) / 3, NWR )
15510 *
15511 * ==== NSR = recommended number of simultaneous shifts.
15512 * . At this point N .GT. NTINY = 11, so there is at
15513 * . enough subdiagonal workspace for NSR to be even
15514 * . and greater than or equal to two as required. ====
15515 *
15516 NSR = ILAENV( 15, 'DLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
15517 NSR = MIN( NSR, ( N+6 ) / 9, IHI-ILO )
15518 NSR = MAX( 2, NSR-MOD( NSR, 2 ) )
15519 *
15520 * ==== Estimate optimal workspace ====
15521 *
15522 * ==== Workspace query call to DLAQR2 ====
15523 *
15524 CALL DLAQR2( WANTT, WANTZ, N, ILO, IHI, NWR+1, H, LDH, ILOZ,
15525 $ IHIZ, Z, LDZ, LS, LD, WR, WI, H, LDH, N, H, LDH,
15526 $ N, H, LDH, WORK, -1 )
15527 *
15528 * ==== Optimal workspace = MAX(DLAQR5, DLAQR2) ====
15529 *
15530 LWKOPT = MAX( 3*NSR / 2, INT( WORK( 1 ) ) )
15531 *
15532 * ==== Quick return in case of workspace query. ====
15533 *
15534 IF( LWORK.EQ.-1 ) THEN
15535 WORK( 1 ) = DBLE( LWKOPT )
15536 RETURN
15537 END IF
15538 *
15539 * ==== DLAHQR/DLAQR0 crossover point ====
15540 *
15541 NMIN = ILAENV( 12, 'DLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
15542 NMIN = MAX( NTINY, NMIN )
15543 *
15544 * ==== Nibble crossover point ====
15545 *
15546 NIBBLE = ILAENV( 14, 'DLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
15547 NIBBLE = MAX( 0, NIBBLE )
15548 *
15549 * ==== Accumulate reflections during ttswp? Use block
15550 * . 2-by-2 structure during matrix-matrix multiply? ====
15551 *
15552 KACC22 = ILAENV( 16, 'DLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
15553 KACC22 = MAX( 0, KACC22 )
15554 KACC22 = MIN( 2, KACC22 )
15555 *
15556 * ==== NWMAX = the largest possible deflation window for
15557 * . which there is sufficient workspace. ====
15558 *
15559 NWMAX = MIN( ( N-1 ) / 3, LWORK / 2 )
15560 NW = NWMAX
15561 *
15562 * ==== NSMAX = the Largest number of simultaneous shifts
15563 * . for which there is sufficient workspace. ====
15564 *
15565 NSMAX = MIN( ( N+6 ) / 9, 2*LWORK / 3 )
15566 NSMAX = NSMAX - MOD( NSMAX, 2 )
15567 *
15568 * ==== NDFL: an iteration count restarted at deflation. ====
15569 *
15570 NDFL = 1
15571 *
15572 * ==== ITMAX = iteration limit ====
15573 *
15574 ITMAX = MAX( 30, 2*KEXSH )*MAX( 10, ( IHI-ILO+1 ) )
15575 *
15576 * ==== Last row and column in the active block ====
15577 *
15578 KBOT = IHI
15579 *
15580 * ==== Main Loop ====
15581 *
15582 DO 80 IT = 1, ITMAX
15583 *
15584 * ==== Done when KBOT falls below ILO ====
15585 *
15586 IF( KBOT.LT.ILO )
15587 $ GO TO 90
15588 *
15589 * ==== Locate active block ====
15590 *
15591 DO 10 K = KBOT, ILO + 1, -1
15592 IF( H( K, K-1 ).EQ.ZERO )
15593 $ GO TO 20
15594 10 CONTINUE
15595 K = ILO
15596 20 CONTINUE
15597 KTOP = K
15598 *
15599 * ==== Select deflation window size:
15600 * . Typical Case:
15601 * . If possible and advisable, nibble the entire
15602 * . active block. If not, use size MIN(NWR,NWMAX)
15603 * . or MIN(NWR+1,NWMAX) depending upon which has
15604 * . the smaller corresponding subdiagonal entry
15605 * . (a heuristic).
15606 * .
15607 * . Exceptional Case:
15608 * . If there have been no deflations in KEXNW or
15609 * . more iterations, then vary the deflation window
15610 * . size. At first, because, larger windows are,
15611 * . in general, more powerful than smaller ones,
15612 * . rapidly increase the window to the maximum possible.
15613 * . Then, gradually reduce the window size. ====
15614 *
15615 NH = KBOT - KTOP + 1
15616 NWUPBD = MIN( NH, NWMAX )
15617 IF( NDFL.LT.KEXNW ) THEN
15618 NW = MIN( NWUPBD, NWR )
15619 ELSE
15620 NW = MIN( NWUPBD, 2*NW )
15621 END IF
15622 IF( NW.LT.NWMAX ) THEN
15623 IF( NW.GE.NH-1 ) THEN
15624 NW = NH
15625 ELSE
15626 KWTOP = KBOT - NW + 1
15627 IF( ABS( H( KWTOP, KWTOP-1 ) ).GT.
15628 $ ABS( H( KWTOP-1, KWTOP-2 ) ) )NW = NW + 1
15629 END IF
15630 END IF
15631 IF( NDFL.LT.KEXNW ) THEN
15632 NDEC = -1
15633 ELSE IF( NDEC.GE.0 .OR. NW.GE.NWUPBD ) THEN
15634 NDEC = NDEC + 1
15635 IF( NW-NDEC.LT.2 )
15636 $ NDEC = 0
15637 NW = NW - NDEC
15638 END IF
15639 *
15640 * ==== Aggressive early deflation:
15641 * . split workspace under the subdiagonal into
15642 * . - an nw-by-nw work array V in the lower
15643 * . left-hand-corner,
15644 * . - an NW-by-at-least-NW-but-more-is-better
15645 * . (NW-by-NHO) horizontal work array along
15646 * . the bottom edge,
15647 * . - an at-least-NW-but-more-is-better (NHV-by-NW)
15648 * . vertical work array along the left-hand-edge.
15649 * . ====
15650 *
15651 KV = N - NW + 1
15652 KT = NW + 1
15653 NHO = ( N-NW-1 ) - KT + 1
15654 KWV = NW + 2
15655 NVE = ( N-NW ) - KWV + 1
15656 *
15657 * ==== Aggressive early deflation ====
15658 *
15659 CALL DLAQR2( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
15660 $ IHIZ, Z, LDZ, LS, LD, WR, WI, H( KV, 1 ), LDH,
15661 $ NHO, H( KV, KT ), LDH, NVE, H( KWV, 1 ), LDH,
15662 $ WORK, LWORK )
15663 *
15664 * ==== Adjust KBOT accounting for new deflations. ====
15665 *
15666 KBOT = KBOT - LD
15667 *
15668 * ==== KS points to the shifts. ====
15669 *
15670 KS = KBOT - LS + 1
15671 *
15672 * ==== Skip an expensive QR sweep if there is a (partly
15673 * . heuristic) reason to expect that many eigenvalues
15674 * . will deflate without it. Here, the QR sweep is
15675 * . skipped if many eigenvalues have just been deflated
15676 * . or if the remaining active block is small.
15677 *
15678 IF( ( LD.EQ.0 ) .OR. ( ( 100*LD.LE.NW*NIBBLE ) .AND. ( KBOT-
15679 $ KTOP+1.GT.MIN( NMIN, NWMAX ) ) ) ) THEN
15680 *
15681 * ==== NS = nominal number of simultaneous shifts.
15682 * . This may be lowered (slightly) if DLAQR2
15683 * . did not provide that many shifts. ====
15684 *
15685 NS = MIN( NSMAX, NSR, MAX( 2, KBOT-KTOP ) )
15686 NS = NS - MOD( NS, 2 )
15687 *
15688 * ==== If there have been no deflations
15689 * . in a multiple of KEXSH iterations,
15690 * . then try exceptional shifts.
15691 * . Otherwise use shifts provided by
15692 * . DLAQR2 above or from the eigenvalues
15693 * . of a trailing principal submatrix. ====
15694 *
15695 IF( MOD( NDFL, KEXSH ).EQ.0 ) THEN
15696 KS = KBOT - NS + 1
15697 DO 30 I = KBOT, MAX( KS+1, KTOP+2 ), -2
15698 SS = ABS( H( I, I-1 ) ) + ABS( H( I-1, I-2 ) )
15699 AA = WILK1*SS + H( I, I )
15700 BB = SS
15701 CC = WILK2*SS
15702 DD = AA
15703 CALL DLANV2( AA, BB, CC, DD, WR( I-1 ), WI( I-1 ),
15704 $ WR( I ), WI( I ), CS, SN )
15705 30 CONTINUE
15706 IF( KS.EQ.KTOP ) THEN
15707 WR( KS+1 ) = H( KS+1, KS+1 )
15708 WI( KS+1 ) = ZERO
15709 WR( KS ) = WR( KS+1 )
15710 WI( KS ) = WI( KS+1 )
15711 END IF
15712 ELSE
15713 *
15714 * ==== Got NS/2 or fewer shifts? Use DLAHQR
15715 * . on a trailing principal submatrix to
15716 * . get more. (Since NS.LE.NSMAX.LE.(N+6)/9,
15717 * . there is enough space below the subdiagonal
15718 * . to fit an NS-by-NS scratch array.) ====
15719 *
15720 IF( KBOT-KS+1.LE.NS / 2 ) THEN
15721 KS = KBOT - NS + 1
15722 KT = N - NS + 1
15723 CALL DLACPY( 'A', NS, NS, H( KS, KS ), LDH,
15724 $ H( KT, 1 ), LDH )
15725 CALL DLAHQR( .false., .false., NS, 1, NS,
15726 $ H( KT, 1 ), LDH, WR( KS ), WI( KS ),
15727 $ 1, 1, ZDUM, 1, INF )
15728 KS = KS + INF
15729 *
15730 * ==== In case of a rare QR failure use
15731 * . eigenvalues of the trailing 2-by-2
15732 * . principal submatrix. ====
15733 *
15734 IF( KS.GE.KBOT ) THEN
15735 AA = H( KBOT-1, KBOT-1 )
15736 CC = H( KBOT, KBOT-1 )
15737 BB = H( KBOT-1, KBOT )
15738 DD = H( KBOT, KBOT )
15739 CALL DLANV2( AA, BB, CC, DD, WR( KBOT-1 ),
15740 $ WI( KBOT-1 ), WR( KBOT ),
15741 $ WI( KBOT ), CS, SN )
15742 KS = KBOT - 1
15743 END IF
15744 END IF
15745 *
15746 IF( KBOT-KS+1.GT.NS ) THEN
15747 *
15748 * ==== Sort the shifts (Helps a little)
15749 * . Bubble sort keeps complex conjugate
15750 * . pairs together. ====
15751 *
15752 SORTED = .false.
15753 DO 50 K = KBOT, KS + 1, -1
15754 IF( SORTED )
15755 $ GO TO 60
15756 SORTED = .true.
15757 DO 40 I = KS, K - 1
15758 IF( ABS( WR( I ) )+ABS( WI( I ) ).LT.
15759 $ ABS( WR( I+1 ) )+ABS( WI( I+1 ) ) ) THEN
15760 SORTED = .false.
15761 *
15762 SWAP = WR( I )
15763 WR( I ) = WR( I+1 )
15764 WR( I+1 ) = SWAP
15765 *
15766 SWAP = WI( I )
15767 WI( I ) = WI( I+1 )
15768 WI( I+1 ) = SWAP
15769 END IF
15770 40 CONTINUE
15771 50 CONTINUE
15772 60 CONTINUE
15773 END IF
15774 *
15775 * ==== Shuffle shifts into pairs of real shifts
15776 * . and pairs of complex conjugate shifts
15777 * . assuming complex conjugate shifts are
15778 * . already adjacent to one another. (Yes,
15779 * . they are.) ====
15780 *
15781 DO 70 I = KBOT, KS + 2, -2
15782 IF( WI( I ).NE.-WI( I-1 ) ) THEN
15783 *
15784 SWAP = WR( I )
15785 WR( I ) = WR( I-1 )
15786 WR( I-1 ) = WR( I-2 )
15787 WR( I-2 ) = SWAP
15788 *
15789 SWAP = WI( I )
15790 WI( I ) = WI( I-1 )
15791 WI( I-1 ) = WI( I-2 )
15792 WI( I-2 ) = SWAP
15793 END IF
15794 70 CONTINUE
15795 END IF
15796 *
15797 * ==== If there are only two shifts and both are
15798 * . real, then use only one. ====
15799 *
15800 IF( KBOT-KS+1.EQ.2 ) THEN
15801 IF( WI( KBOT ).EQ.ZERO ) THEN
15802 IF( ABS( WR( KBOT )-H( KBOT, KBOT ) ).LT.
15803 $ ABS( WR( KBOT-1 )-H( KBOT, KBOT ) ) ) THEN
15804 WR( KBOT-1 ) = WR( KBOT )
15805 ELSE
15806 WR( KBOT ) = WR( KBOT-1 )
15807 END IF
15808 END IF
15809 END IF
15810 *
15811 * ==== Use up to NS of the the smallest magnatiude
15812 * . shifts. If there aren't NS shifts available,
15813 * . then use them all, possibly dropping one to
15814 * . make the number of shifts even. ====
15815 *
15816 NS = MIN( NS, KBOT-KS+1 )
15817 NS = NS - MOD( NS, 2 )
15818 KS = KBOT - NS + 1
15819 *
15820 * ==== Small-bulge multi-shift QR sweep:
15821 * . split workspace under the subdiagonal into
15822 * . - a KDU-by-KDU work array U in the lower
15823 * . left-hand-corner,
15824 * . - a KDU-by-at-least-KDU-but-more-is-better
15825 * . (KDU-by-NHo) horizontal work array WH along
15826 * . the bottom edge,
15827 * . - and an at-least-KDU-but-more-is-better-by-KDU
15828 * . (NVE-by-KDU) vertical work WV arrow along
15829 * . the left-hand-edge. ====
15830 *
15831 KDU = 3*NS - 3
15832 KU = N - KDU + 1
15833 KWH = KDU + 1
15834 NHO = ( N-KDU+1-4 ) - ( KDU+1 ) + 1
15835 KWV = KDU + 4
15836 NVE = N - KDU - KWV + 1
15837 *
15838 * ==== Small-bulge multi-shift QR sweep ====
15839 *
15840 CALL DLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NS,
15841 $ WR( KS ), WI( KS ), H, LDH, ILOZ, IHIZ, Z,
15842 $ LDZ, WORK, 3, H( KU, 1 ), LDH, NVE,
15843 $ H( KWV, 1 ), LDH, NHO, H( KU, KWH ), LDH )
15844 END IF
15845 *
15846 * ==== Note progress (or the lack of it). ====
15847 *
15848 IF( LD.GT.0 ) THEN
15849 NDFL = 1
15850 ELSE
15851 NDFL = NDFL + 1
15852 END IF
15853 *
15854 * ==== End of main loop ====
15855 80 CONTINUE
15856 *
15857 * ==== Iteration limit exceeded. Set INFO to show where
15858 * . the problem occurred and exit. ====
15859 *
15860 INFO = KBOT
15861 90 CONTINUE
15862 END IF
15863 *
15864 * ==== Return the optimal value of LWORK. ====
15865 *
15866 WORK( 1 ) = DBLE( LWKOPT )
15867 *
15868 * ==== End of DLAQR4 ====
15869 *
15870 END
15871 C
15872 C-----------------------------------------------------------------------
15873 C-----------------------------------------------------------------------
15874 SUBROUTINE DLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NSHFTS,
15875 $ SR, SI, H, LDH, ILOZ, IHIZ, Z, LDZ, V, LDV, U,
15876 $ LDU, NV, WV, LDWV, NH, WH, LDWH )
15877 *
15878 * -- LAPACK auxiliary routine (version 3.2) --
15879 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
15880 * November 2006
15881 *
15882 * .. Scalar Arguments ..
15883 INTEGER IHIZ, ILOZ, KACC22, KBOT, KTOP, LDH, LDU, LDV,
15884 $ LDWH, LDWV, LDZ, N, NH, NSHFTS, NV
15885 LOGICAL WANTT, WANTZ
15886 * ..
15887 * .. Array Arguments ..
15888 DOUBLE PRECISION H( LDH, * ), SI( * ), SR( * ), U( LDU, * ),
15889 $ V( LDV, * ), WH( LDWH, * ), WV( LDWV, * ),
15890 $ Z( LDZ, * )
15891 * ..
15892 *
15893 * This auxiliary subroutine called by DLAQR0 performs a
15894 * single small-bulge multi-shift QR sweep.
15895 *
15896 * WANTT (input) logical scalar
15897 * WANTT = .true. if the quasi-triangular Schur factor
15898 * is being computed. WANTT is set to .false. otherwise.
15899 *
15900 * WANTZ (input) logical scalar
15901 * WANTZ = .true. if the orthogonal Schur factor is being
15902 * computed. WANTZ is set to .false. otherwise.
15903 *
15904 * KACC22 (input) integer with value 0, 1, or 2.
15905 * Specifies the computation mode of far-from-diagonal
15906 * orthogonal updates.
15907 * = 0: DLAQR5 does not accumulate reflections and does not
15908 * use matrix-matrix multiply to update far-from-diagonal
15909 * matrix entries.
15910 * = 1: DLAQR5 accumulates reflections and uses matrix-matrix
15911 * multiply to update the far-from-diagonal matrix entries.
15912 * = 2: DLAQR5 accumulates reflections, uses matrix-matrix
15913 * multiply to update the far-from-diagonal matrix entries,
15914 * and takes advantage of 2-by-2 block structure during
15915 * matrix multiplies.
15916 *
15917 * N (input) integer scalar
15918 * N is the order of the Hessenberg matrix H upon which this
15919 * subroutine operates.
15920 *
15921 * KTOP (input) integer scalar
15922 * KBOT (input) integer scalar
15923 * These are the first and last rows and columns of an
15924 * isolated diagonal block upon which the QR sweep is to be
15925 * applied. It is assumed without a check that
15926 * either KTOP = 1 or H(KTOP,KTOP-1) = 0
15927 * and
15928 * either KBOT = N or H(KBOT+1,KBOT) = 0.
15929 *
15930 * NSHFTS (input) integer scalar
15931 * NSHFTS gives the number of simultaneous shifts. NSHFTS
15932 * must be positive and even.
15933 *
15934 * SR (input/output) DOUBLE PRECISION array of size (NSHFTS)
15935 * SI (input/output) DOUBLE PRECISION array of size (NSHFTS)
15936 * SR contains the real parts and SI contains the imaginary
15937 * parts of the NSHFTS shifts of origin that define the
15938 * multi-shift QR sweep. On output SR and SI may be
15939 * reordered.
15940 *
15941 * H (input/output) DOUBLE PRECISION array of size (LDH,N)
15942 * On input H contains a Hessenberg matrix. On output a
15943 * multi-shift QR sweep with shifts SR(J)+i*SI(J) is applied
15944 * to the isolated diagonal block in rows and columns KTOP
15945 * through KBOT.
15946 *
15947 * LDH (input) integer scalar
15948 * LDH is the leading dimension of H just as declared in the
15949 * calling procedure. LDH.GE.MAX(1,N).
15950 *
15951 * ILOZ (input) INTEGER
15952 * IHIZ (input) INTEGER
15953 * Specify the rows of Z to which transformations must be
15954 * applied if WANTZ is .TRUE.. 1 .LE. ILOZ .LE. IHIZ .LE. N
15955 *
15956 * Z (input/output) DOUBLE PRECISION array of size (LDZ,IHI)
15957 * If WANTZ = .TRUE., then the QR Sweep orthogonal
15958 * similarity transformation is accumulated into
15959 * Z(ILOZ:IHIZ,ILO:IHI) from the right.
15960 * If WANTZ = .FALSE., then Z is unreferenced.
15961 *
15962 * LDZ (input) integer scalar
15963 * LDA is the leading dimension of Z just as declared in
15964 * the calling procedure. LDZ.GE.N.
15965 *
15966 * V (workspace) DOUBLE PRECISION array of size (LDV,NSHFTS/2)
15967 *
15968 * LDV (input) integer scalar
15969 * LDV is the leading dimension of V as declared in the
15970 * calling procedure. LDV.GE.3.
15971 *
15972 * U (workspace) DOUBLE PRECISION array of size
15973 * (LDU,3*NSHFTS-3)
15974 *
15975 * LDU (input) integer scalar
15976 * LDU is the leading dimension of U just as declared in the
15977 * in the calling subroutine. LDU.GE.3*NSHFTS-3.
15978 *
15979 * NH (input) integer scalar
15980 * NH is the number of columns in array WH available for
15981 * workspace. NH.GE.1.
15982 *
15983 * WH (workspace) DOUBLE PRECISION array of size (LDWH,NH)
15984 *
15985 * LDWH (input) integer scalar
15986 * Leading dimension of WH just as declared in the
15987 * calling procedure. LDWH.GE.3*NSHFTS-3.
15988 *
15989 * NV (input) integer scalar
15990 * NV is the number of rows in WV agailable for workspace.
15991 * NV.GE.1.
15992 *
15993 * WV (workspace) DOUBLE PRECISION array of size
15994 * (LDWV,3*NSHFTS-3)
15995 *
15996 * LDWV (input) integer scalar
15997 * LDWV is the leading dimension of WV as declared in the
15998 * in the calling subroutine. LDWV.GE.NV.
15999 *
16000 * ================================================================
16001 * Based on contributions by
16002 * Karen Braman and Ralph Byers, Department of Mathematics,
16003 * University of Kansas, USA
16004 *
16005 * ================================================================
16006 * Reference:
16007 *
16008 * K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
16009 * Algorithm Part I: Maintaining Well Focused Shifts, and
16010 * Level 3 Performance, SIAM Journal of Matrix Analysis,
16011 * volume 23, pages 929--947, 2002.
16012 *
16013 * ================================================================
16014 * .. Parameters ..
16015 DOUBLE PRECISION ZERO, ONE
16016 PARAMETER ( ZERO = 0.0d0, ONE = 1.0d0 )
16017 * ..
16018 * .. Local Scalars ..
16019 DOUBLE PRECISION ALPHA, BETA, H11, H12, H21, H22, REFSUM,
16020 $ SAFMAX, SAFMIN, SCL, SMLNUM, SWAP, TST1, TST2,
16021 $ ULP
16022 INTEGER I, I2, I4, INCOL, J, J2, J4, JBOT, JCOL, JLEN,
16023 $ JROW, JTOP, K, K1, KDU, KMS, KNZ, KRCOL, KZS,
16024 $ M, M22, MBOT, MEND, MSTART, MTOP, NBMPS, NDCOL,
16025 $ NS, NU
16026 LOGICAL ACCUM, BLK22, BMP22
16027 * ..
16028 * .. External Functions ..
16029 DOUBLE PRECISION DLAMCH
16030 EXTERNAL DLAMCH
16031 * ..
16032 * .. Intrinsic Functions ..
16033 *
16034 INTRINSIC ABS, DBLE, MAX, MIN, MOD
16035 * ..
16036 * .. Local Arrays ..
16037 DOUBLE PRECISION VT( 3 )
16038 * ..
16039 * .. External Subroutines ..
16040 EXTERNAL DGEMM, DLABAD, DLACPY, DLAQR1, DLARFG, DLASET,
16041 $ DTRMM
16042 * ..
16043 * .. Executable Statements ..
16044 *
16045 * ==== If there are no shifts, then there is nothing to do. ====
16046 *
16047 IF( NSHFTS.LT.2 )
16048 $ RETURN
16049 *
16050 * ==== If the active block is empty or 1-by-1, then there
16051 * . is nothing to do. ====
16052 *
16053 IF( KTOP.GE.KBOT )
16054 $ RETURN
16055 *
16056 * ==== Shuffle shifts into pairs of real shifts and pairs
16057 * . of complex conjugate shifts assuming complex
16058 * . conjugate shifts are already adjacent to one
16059 * . another. ====
16060 *
16061 DO 10 I = 1, NSHFTS - 2, 2
16062 IF( SI( I ).NE.-SI( I+1 ) ) THEN
16063 *
16064 SWAP = SR( I )
16065 SR( I ) = SR( I+1 )
16066 SR( I+1 ) = SR( I+2 )
16067 SR( I+2 ) = SWAP
16068 *
16069 SWAP = SI( I )
16070 SI( I ) = SI( I+1 )
16071 SI( I+1 ) = SI( I+2 )
16072 SI( I+2 ) = SWAP
16073 END IF
16074 10 CONTINUE
16075 *
16076 * ==== NSHFTS is supposed to be even, but if it is odd,
16077 * . then simply reduce it by one. The shuffle above
16078 * . ensures that the dropped shift is real and that
16079 * . the remaining shifts are paired. ====
16080 *
16081 NS = NSHFTS - MOD( NSHFTS, 2 )
16082 *
16083 * ==== Machine constants for deflation ====
16084 *
16085 SAFMIN = DLAMCH( 'SAFE MINIMUM' )
16086 SAFMAX = ONE / SAFMIN
16087 CALL DLABAD( SAFMIN, SAFMAX )
16088 ULP = DLAMCH( 'PRECISION' )
16089 SMLNUM = SAFMIN*( DBLE( N ) / ULP )
16090 *
16091 * ==== Use accumulated reflections to update far-from-diagonal
16092 * . entries ? ====
16093 *
16094 ACCUM = ( KACC22.EQ.1 ) .OR. ( KACC22.EQ.2 )
16095 *
16096 * ==== If so, exploit the 2-by-2 block structure? ====
16097 *
16098 BLK22 = ( NS.GT.2 ) .AND. ( KACC22.EQ.2 )
16099 *
16100 * ==== clear trash ====
16101 *
16102 IF( KTOP+2.LE.KBOT )
16103 $ H( KTOP+2, KTOP ) = ZERO
16104 *
16105 * ==== NBMPS = number of 2-shift bulges in the chain ====
16106 *
16107 NBMPS = NS / 2
16108 *
16109 * ==== KDU = width of slab ====
16110 *
16111 KDU = 6*NBMPS - 3
16112 *
16113 * ==== Create and chase chains of NBMPS bulges ====
16114 *
16115 DO 220 INCOL = 3*( 1-NBMPS ) + KTOP - 1, KBOT - 2, 3*NBMPS - 2
16116 NDCOL = INCOL + KDU
16117 IF( ACCUM )
16118 $ CALL DLASET( 'ALL', KDU, KDU, ZERO, ONE, U, LDU )
16119 *
16120 * ==== Near-the-diagonal bulge chase. The following loop
16121 * . performs the near-the-diagonal part of a small bulge
16122 * . multi-shift QR sweep. Each 6*NBMPS-2 column diagonal
16123 * . chunk extends from column INCOL to column NDCOL
16124 * . (including both column INCOL and column NDCOL). The
16125 * . following loop chases a 3*NBMPS column long chain of
16126 * . NBMPS bulges 3*NBMPS-2 columns to the right. (INCOL
16127 * . may be less than KTOP and and NDCOL may be greater than
16128 * . KBOT indicating phantom columns from which to chase
16129 * . bulges before they are actually introduced or to which
16130 * . to chase bulges beyond column KBOT.) ====
16131 *
16132 DO 150 KRCOL = INCOL, MIN( INCOL+3*NBMPS-3, KBOT-2 )
16133 *
16134 * ==== Bulges number MTOP to MBOT are active double implicit
16135 * . shift bulges. There may or may not also be small
16136 * . 2-by-2 bulge, if there is room. The inactive bulges
16137 * . (if any) must wait until the active bulges have moved
16138 * . down the diagonal to make room. The phantom matrix
16139 * . paradigm described above helps keep track. ====
16140 *
16141 MTOP = MAX( 1, ( ( KTOP-1 )-KRCOL+2 ) / 3+1 )
16142 MBOT = MIN( NBMPS, ( KBOT-KRCOL ) / 3 )
16143 M22 = MBOT + 1
16144 BMP22 = ( MBOT.LT.NBMPS ) .AND. ( KRCOL+3*( M22-1 ) ).EQ.
16145 $ ( KBOT-2 )
16146 *
16147 * ==== Generate reflections to chase the chain right
16148 * . one column. (The minimum value of K is KTOP-1.) ====
16149 *
16150 DO 20 M = MTOP, MBOT
16151 K = KRCOL + 3*( M-1 )
16152 IF( K.EQ.KTOP-1 ) THEN
16153 CALL DLAQR1( 3, H( KTOP, KTOP ), LDH, SR( 2*M-1 ),
16154 $ SI( 2*M-1 ), SR( 2*M ), SI( 2*M ),
16155 $ V( 1, M ) )
16156 ALPHA = V( 1, M )
16157 CALL DLARFG( 3, ALPHA, V( 2, M ), 1, V( 1, M ) )
16158 ELSE
16159 BETA = H( K+1, K )
16160 V( 2, M ) = H( K+2, K )
16161 V( 3, M ) = H( K+3, K )
16162 CALL DLARFG( 3, BETA, V( 2, M ), 1, V( 1, M ) )
16163 *
16164 * ==== A Bulge may collapse because of vigilant
16165 * . deflation or destructive underflow. In the
16166 * . underflow case, try the two-small-subdiagonals
16167 * . trick to try to reinflate the bulge. ====
16168 *
16169 IF( H( K+3, K ).NE.ZERO .OR. H( K+3, K+1 ).NE.
16170 $ ZERO .OR. H( K+3, K+2 ).EQ.ZERO ) THEN
16171 *
16172 * ==== Typical case: not collapsed (yet). ====
16173 *
16174 H( K+1, K ) = BETA
16175 H( K+2, K ) = ZERO
16176 H( K+3, K ) = ZERO
16177 ELSE
16178 *
16179 * ==== Atypical case: collapsed. Attempt to
16180 * . reintroduce ignoring H(K+1,K) and H(K+2,K).
16181 * . If the fill resulting from the new
16182 * . reflector is too large, then abandon it.
16183 * . Otherwise, use the new one. ====
16184 *
16185 CALL DLAQR1( 3, H( K+1, K+1 ), LDH, SR( 2*M-1 ),
16186 $ SI( 2*M-1 ), SR( 2*M ), SI( 2*M ),
16187 $ VT )
16188 ALPHA = VT( 1 )
16189 CALL DLARFG( 3, ALPHA, VT( 2 ), 1, VT( 1 ) )
16190 REFSUM = VT( 1 )*( H( K+1, K )+VT( 2 )*
16191 $ H( K+2, K ) )
16192 *
16193 IF( ABS( H( K+2, K )-REFSUM*VT( 2 ) )+
16194 $ ABS( REFSUM*VT( 3 ) ).GT.ULP*
16195 $ ( ABS( H( K, K ) )+ABS( H( K+1,
16196 $ K+1 ) )+ABS( H( K+2, K+2 ) ) ) ) THEN
16197 *
16198 * ==== Starting a new bulge here would
16199 * . create non-negligible fill. Use
16200 * . the old one with trepidation. ====
16201 *
16202 H( K+1, K ) = BETA
16203 H( K+2, K ) = ZERO
16204 H( K+3, K ) = ZERO
16205 ELSE
16206 *
16207 * ==== Stating a new bulge here would
16208 * . create only negligible fill.
16209 * . Replace the old reflector with
16210 * . the new one. ====
16211 *
16212 H( K+1, K ) = H( K+1, K ) - REFSUM
16213 H( K+2, K ) = ZERO
16214 H( K+3, K ) = ZERO
16215 V( 1, M ) = VT( 1 )
16216 V( 2, M ) = VT( 2 )
16217 V( 3, M ) = VT( 3 )
16218 END IF
16219 END IF
16220 END IF
16221 20 CONTINUE
16222 *
16223 * ==== Generate a 2-by-2 reflection, if needed. ====
16224 *
16225 K = KRCOL + 3*( M22-1 )
16226 IF( BMP22 ) THEN
16227 IF( K.EQ.KTOP-1 ) THEN
16228 CALL DLAQR1( 2, H( K+1, K+1 ), LDH, SR( 2*M22-1 ),
16229 $ SI( 2*M22-1 ), SR( 2*M22 ), SI( 2*M22 ),
16230 $ V( 1, M22 ) )
16231 BETA = V( 1, M22 )
16232 CALL DLARFG( 2, BETA, V( 2, M22 ), 1, V( 1, M22 ) )
16233 ELSE
16234 BETA = H( K+1, K )
16235 V( 2, M22 ) = H( K+2, K )
16236 CALL DLARFG( 2, BETA, V( 2, M22 ), 1, V( 1, M22 ) )
16237 H( K+1, K ) = BETA
16238 H( K+2, K ) = ZERO
16239 END IF
16240 END IF
16241 *
16242 * ==== Multiply H by reflections from the left ====
16243 *
16244 IF( ACCUM ) THEN
16245 JBOT = MIN( NDCOL, KBOT )
16246 ELSE IF( WANTT ) THEN
16247 JBOT = N
16248 ELSE
16249 JBOT = KBOT
16250 END IF
16251 DO 40 J = MAX( KTOP, KRCOL ), JBOT
16252 MEND = MIN( MBOT, ( J-KRCOL+2 ) / 3 )
16253 DO 30 M = MTOP, MEND
16254 K = KRCOL + 3*( M-1 )
16255 REFSUM = V( 1, M )*( H( K+1, J )+V( 2, M )*
16256 $ H( K+2, J )+V( 3, M )*H( K+3, J ) )
16257 H( K+1, J ) = H( K+1, J ) - REFSUM
16258 H( K+2, J ) = H( K+2, J ) - REFSUM*V( 2, M )
16259 H( K+3, J ) = H( K+3, J ) - REFSUM*V( 3, M )
16260 30 CONTINUE
16261 40 CONTINUE
16262 IF( BMP22 ) THEN
16263 K = KRCOL + 3*( M22-1 )
16264 DO 50 J = MAX( K+1, KTOP ), JBOT
16265 REFSUM = V( 1, M22 )*( H( K+1, J )+V( 2, M22 )*
16266 $ H( K+2, J ) )
16267 H( K+1, J ) = H( K+1, J ) - REFSUM
16268 H( K+2, J ) = H( K+2, J ) - REFSUM*V( 2, M22 )
16269 50 CONTINUE
16270 END IF
16271 *
16272 * ==== Multiply H by reflections from the right.
16273 * . Delay filling in the last row until the
16274 * . vigilant deflation check is complete. ====
16275 *
16276 IF( ACCUM ) THEN
16277 JTOP = MAX( KTOP, INCOL )
16278 ELSE IF( WANTT ) THEN
16279 JTOP = 1
16280 ELSE
16281 JTOP = KTOP
16282 END IF
16283 DO 90 M = MTOP, MBOT
16284 IF( V( 1, M ).NE.ZERO ) THEN
16285 K = KRCOL + 3*( M-1 )
16286 DO 60 J = JTOP, MIN( KBOT, K+3 )
16287 REFSUM = V( 1, M )*( H( J, K+1 )+V( 2, M )*
16288 $ H( J, K+2 )+V( 3, M )*H( J, K+3 ) )
16289 H( J, K+1 ) = H( J, K+1 ) - REFSUM
16290 H( J, K+2 ) = H( J, K+2 ) - REFSUM*V( 2, M )
16291 H( J, K+3 ) = H( J, K+3 ) - REFSUM*V( 3, M )
16292 60 CONTINUE
16293 *
16294 IF( ACCUM ) THEN
16295 *
16296 * ==== Accumulate U. (If necessary, update Z later
16297 * . with with an efficient matrix-matrix
16298 * . multiply.) ====
16299 *
16300 KMS = K - INCOL
16301 DO 70 J = MAX( 1, KTOP-INCOL ), KDU
16302 REFSUM = V( 1, M )*( U( J, KMS+1 )+V( 2, M )*
16303 $ U( J, KMS+2 )+V( 3, M )*U( J, KMS+3 ) )
16304 U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM
16305 U( J, KMS+2 ) = U( J, KMS+2 ) - REFSUM*V( 2, M )
16306 U( J, KMS+3 ) = U( J, KMS+3 ) - REFSUM*V( 3, M )
16307 70 CONTINUE
16308 ELSE IF( WANTZ ) THEN
16309 *
16310 * ==== U is not accumulated, so update Z
16311 * . now by multiplying by reflections
16312 * . from the right. ====
16313 *
16314 DO 80 J = ILOZ, IHIZ
16315 REFSUM = V( 1, M )*( Z( J, K+1 )+V( 2, M )*
16316 $ Z( J, K+2 )+V( 3, M )*Z( J, K+3 ) )
16317 Z( J, K+1 ) = Z( J, K+1 ) - REFSUM
16318 Z( J, K+2 ) = Z( J, K+2 ) - REFSUM*V( 2, M )
16319 Z( J, K+3 ) = Z( J, K+3 ) - REFSUM*V( 3, M )
16320 80 CONTINUE
16321 END IF
16322 END IF
16323 90 CONTINUE
16324 *
16325 * ==== Special case: 2-by-2 reflection (if needed) ====
16326 *
16327 K = KRCOL + 3*( M22-1 )
16328 IF( BMP22 .AND. ( V( 1, M22 ).NE.ZERO ) ) THEN
16329 DO 100 J = JTOP, MIN( KBOT, K+3 )
16330 REFSUM = V( 1, M22 )*( H( J, K+1 )+V( 2, M22 )*
16331 $ H( J, K+2 ) )
16332 H( J, K+1 ) = H( J, K+1 ) - REFSUM
16333 H( J, K+2 ) = H( J, K+2 ) - REFSUM*V( 2, M22 )
16334 100 CONTINUE
16335 *
16336 IF( ACCUM ) THEN
16337 KMS = K - INCOL
16338 DO 110 J = MAX( 1, KTOP-INCOL ), KDU
16339 REFSUM = V( 1, M22 )*( U( J, KMS+1 )+V( 2, M22 )*
16340 $ U( J, KMS+2 ) )
16341 U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM
16342 U( J, KMS+2 ) = U( J, KMS+2 ) - REFSUM*V( 2, M22 )
16343 110 CONTINUE
16344 ELSE IF( WANTZ ) THEN
16345 DO 120 J = ILOZ, IHIZ
16346 REFSUM = V( 1, M22 )*( Z( J, K+1 )+V( 2, M22 )*
16347 $ Z( J, K+2 ) )
16348 Z( J, K+1 ) = Z( J, K+1 ) - REFSUM
16349 Z( J, K+2 ) = Z( J, K+2 ) - REFSUM*V( 2, M22 )
16350 120 CONTINUE
16351 END IF
16352 END IF
16353 *
16354 * ==== Vigilant deflation check ====
16355 *
16356 MSTART = MTOP
16357 IF( KRCOL+3*( MSTART-1 ).LT.KTOP )
16358 $ MSTART = MSTART + 1
16359 MEND = MBOT
16360 IF( BMP22 )
16361 $ MEND = MEND + 1
16362 IF( KRCOL.EQ.KBOT-2 )
16363 $ MEND = MEND + 1
16364 DO 130 M = MSTART, MEND
16365 K = MIN( KBOT-1, KRCOL+3*( M-1 ) )
16366 *
16367 * ==== The following convergence test requires that
16368 * . the tradition small-compared-to-nearby-diagonals
16369 * . criterion and the Ahues & Tisseur (LAWN 122, 1997)
16370 * . criteria both be satisfied. The latter improves
16371 * . accuracy in some examples. Falling back on an
16372 * . alternate convergence criterion when TST1 or TST2
16373 * . is zero (as done here) is traditional but probably
16374 * . unnecessary. ====
16375 *
16376 IF( H( K+1, K ).NE.ZERO ) THEN
16377 TST1 = ABS( H( K, K ) ) + ABS( H( K+1, K+1 ) )
16378 IF( TST1.EQ.ZERO ) THEN
16379 IF( K.GE.KTOP+1 )
16380 $ TST1 = TST1 + ABS( H( K, K-1 ) )
16381 IF( K.GE.KTOP+2 )
16382 $ TST1 = TST1 + ABS( H( K, K-2 ) )
16383 IF( K.GE.KTOP+3 )
16384 $ TST1 = TST1 + ABS( H( K, K-3 ) )
16385 IF( K.LE.KBOT-2 )
16386 $ TST1 = TST1 + ABS( H( K+2, K+1 ) )
16387 IF( K.LE.KBOT-3 )
16388 $ TST1 = TST1 + ABS( H( K+3, K+1 ) )
16389 IF( K.LE.KBOT-4 )
16390 $ TST1 = TST1 + ABS( H( K+4, K+1 ) )
16391 END IF
16392 IF( ABS( H( K+1, K ) ).LE.MAX( SMLNUM, ULP*TST1 ) )
16393 $ THEN
16394 H12 = MAX( ABS( H( K+1, K ) ), ABS( H( K, K+1 ) ) )
16395 H21 = MIN( ABS( H( K+1, K ) ), ABS( H( K, K+1 ) ) )
16396 H11 = MAX( ABS( H( K+1, K+1 ) ),
16397 $ ABS( H( K, K )-H( K+1, K+1 ) ) )
16398 H22 = MIN( ABS( H( K+1, K+1 ) ),
16399 $ ABS( H( K, K )-H( K+1, K+1 ) ) )
16400 SCL = H11 + H12
16401 TST2 = H22*( H11 / SCL )
16402 *
16403 IF( TST2.EQ.ZERO .OR. H21*( H12 / SCL ).LE.
16404 $ MAX( SMLNUM, ULP*TST2 ) )H( K+1, K ) = ZERO
16405 END IF
16406 END IF
16407 130 CONTINUE
16408 *
16409 * ==== Fill in the last row of each bulge. ====
16410 *
16411 MEND = MIN( NBMPS, ( KBOT-KRCOL-1 ) / 3 )
16412 DO 140 M = MTOP, MEND
16413 K = KRCOL + 3*( M-1 )
16414 REFSUM = V( 1, M )*V( 3, M )*H( K+4, K+3 )
16415 H( K+4, K+1 ) = -REFSUM
16416 H( K+4, K+2 ) = -REFSUM*V( 2, M )
16417 H( K+4, K+3 ) = H( K+4, K+3 ) - REFSUM*V( 3, M )
16418 140 CONTINUE
16419 *
16420 * ==== End of near-the-diagonal bulge chase. ====
16421 *
16422 150 CONTINUE
16423 *
16424 * ==== Use U (if accumulated) to update far-from-diagonal
16425 * . entries in H. If required, use U to update Z as
16426 * . well. ====
16427 *
16428 IF( ACCUM ) THEN
16429 IF( WANTT ) THEN
16430 JTOP = 1
16431 JBOT = N
16432 ELSE
16433 JTOP = KTOP
16434 JBOT = KBOT
16435 END IF
16436 IF( ( .NOT.BLK22 ) .OR. ( INCOL.LT.KTOP ) .OR.
16437 $ ( NDCOL.GT.KBOT ) .OR. ( NS.LE.2 ) ) THEN
16438 *
16439 * ==== Updates not exploiting the 2-by-2 block
16440 * . structure of U. K1 and NU keep track of
16441 * . the location and size of U in the special
16442 * . cases of introducing bulges and chasing
16443 * . bulges off the bottom. In these special
16444 * . cases and in case the number of shifts
16445 * . is NS = 2, there is no 2-by-2 block
16446 * . structure to exploit. ====
16447 *
16448 K1 = MAX( 1, KTOP-INCOL )
16449 NU = ( KDU-MAX( 0, NDCOL-KBOT ) ) - K1 + 1
16450 *
16451 * ==== Horizontal Multiply ====
16452 *
16453 DO 160 JCOL = MIN( NDCOL, KBOT ) + 1, JBOT, NH
16454 JLEN = MIN( NH, JBOT-JCOL+1 )
16455 CALL DGEMM( 'C', 'N', NU, JLEN, NU, ONE, U( K1, K1 ),
16456 $ LDU, H( INCOL+K1, JCOL ), LDH, ZERO, WH,
16457 $ LDWH )
16458 CALL DLACPY( 'ALL', NU, JLEN, WH, LDWH,
16459 $ H( INCOL+K1, JCOL ), LDH )
16460 160 CONTINUE
16461 *
16462 * ==== Vertical multiply ====
16463 *
16464 DO 170 JROW = JTOP, MAX( KTOP, INCOL ) - 1, NV
16465 JLEN = MIN( NV, MAX( KTOP, INCOL )-JROW )
16466 CALL DGEMM( 'N', 'N', JLEN, NU, NU, ONE,
16467 $ H( JROW, INCOL+K1 ), LDH, U( K1, K1 ),
16468 $ LDU, ZERO, WV, LDWV )
16469 CALL DLACPY( 'ALL', JLEN, NU, WV, LDWV,
16470 $ H( JROW, INCOL+K1 ), LDH )
16471 170 CONTINUE
16472 *
16473 * ==== Z multiply (also vertical) ====
16474 *
16475 IF( WANTZ ) THEN
16476 DO 180 JROW = ILOZ, IHIZ, NV
16477 JLEN = MIN( NV, IHIZ-JROW+1 )
16478 CALL DGEMM( 'N', 'N', JLEN, NU, NU, ONE,
16479 $ Z( JROW, INCOL+K1 ), LDZ, U( K1, K1 ),
16480 $ LDU, ZERO, WV, LDWV )
16481 CALL DLACPY( 'ALL', JLEN, NU, WV, LDWV,
16482 $ Z( JROW, INCOL+K1 ), LDZ )
16483 180 CONTINUE
16484 END IF
16485 ELSE
16486 *
16487 * ==== Updates exploiting U's 2-by-2 block structure.
16488 * . (I2, I4, J2, J4 are the last rows and columns
16489 * . of the blocks.) ====
16490 *
16491 I2 = ( KDU+1 ) / 2
16492 I4 = KDU
16493 J2 = I4 - I2
16494 J4 = KDU
16495 *
16496 * ==== KZS and KNZ deal with the band of zeros
16497 * . along the diagonal of one of the triangular
16498 * . blocks. ====
16499 *
16500 KZS = ( J4-J2 ) - ( NS+1 )
16501 KNZ = NS + 1
16502 *
16503 * ==== Horizontal multiply ====
16504 *
16505 DO 190 JCOL = MIN( NDCOL, KBOT ) + 1, JBOT, NH
16506 JLEN = MIN( NH, JBOT-JCOL+1 )
16507 *
16508 * ==== Copy bottom of H to top+KZS of scratch ====
16509 * (The first KZS rows get multiplied by zero.) ====
16510 *
16511 CALL DLACPY( 'ALL', KNZ, JLEN, H( INCOL+1+J2, JCOL ),
16512 $ LDH, WH( KZS+1, 1 ), LDWH )
16513 *
16514 * ==== Multiply by U21' ====
16515 *
16516 CALL DLASET( 'ALL', KZS, JLEN, ZERO, ZERO, WH, LDWH )
16517 CALL DTRMM( 'L', 'U', 'C', 'N', KNZ, JLEN, ONE,
16518 $ U( J2+1, 1+KZS ), LDU, WH( KZS+1, 1 ),
16519 $ LDWH )
16520 *
16521 * ==== Multiply top of H by U11' ====
16522 *
16523 CALL DGEMM( 'C', 'N', I2, JLEN, J2, ONE, U, LDU,
16524 $ H( INCOL+1, JCOL ), LDH, ONE, WH, LDWH )
16525 *
16526 * ==== Copy top of H to bottom of WH ====
16527 *
16528 CALL DLACPY( 'ALL', J2, JLEN, H( INCOL+1, JCOL ), LDH,
16529 $ WH( I2+1, 1 ), LDWH )
16530 *
16531 * ==== Multiply by U21' ====
16532 *
16533 CALL DTRMM( 'L', 'L', 'C', 'N', J2, JLEN, ONE,
16534 $ U( 1, I2+1 ), LDU, WH( I2+1, 1 ), LDWH )
16535 *
16536 * ==== Multiply by U22 ====
16537 *
16538 CALL DGEMM( 'C', 'N', I4-I2, JLEN, J4-J2, ONE,
16539 $ U( J2+1, I2+1 ), LDU,
16540 $ H( INCOL+1+J2, JCOL ), LDH, ONE,
16541 $ WH( I2+1, 1 ), LDWH )
16542 *
16543 * ==== Copy it back ====
16544 *
16545 CALL DLACPY( 'ALL', KDU, JLEN, WH, LDWH,
16546 $ H( INCOL+1, JCOL ), LDH )
16547 190 CONTINUE
16548 *
16549 * ==== Vertical multiply ====
16550 *
16551 DO 200 JROW = JTOP, MAX( INCOL, KTOP ) - 1, NV
16552 JLEN = MIN( NV, MAX( INCOL, KTOP )-JROW )
16553 *
16554 * ==== Copy right of H to scratch (the first KZS
16555 * . columns get multiplied by zero) ====
16556 *
16557 CALL DLACPY( 'ALL', JLEN, KNZ, H( JROW, INCOL+1+J2 ),
16558 $ LDH, WV( 1, 1+KZS ), LDWV )
16559 *
16560 * ==== Multiply by U21 ====
16561 *
16562 CALL DLASET( 'ALL', JLEN, KZS, ZERO, ZERO, WV, LDWV )
16563 CALL DTRMM( 'R', 'U', 'N', 'N', JLEN, KNZ, ONE,
16564 $ U( J2+1, 1+KZS ), LDU, WV( 1, 1+KZS ),
16565 $ LDWV )
16566 *
16567 * ==== Multiply by U11 ====
16568 *
16569 CALL DGEMM( 'N', 'N', JLEN, I2, J2, ONE,
16570 $ H( JROW, INCOL+1 ), LDH, U, LDU, ONE, WV,
16571 $ LDWV )
16572 *
16573 * ==== Copy left of H to right of scratch ====
16574 *
16575 CALL DLACPY( 'ALL', JLEN, J2, H( JROW, INCOL+1 ), LDH,
16576 $ WV( 1, 1+I2 ), LDWV )
16577 *
16578 * ==== Multiply by U21 ====
16579 *
16580 CALL DTRMM( 'R', 'L', 'N', 'N', JLEN, I4-I2, ONE,
16581 $ U( 1, I2+1 ), LDU, WV( 1, 1+I2 ), LDWV )
16582 *
16583 * ==== Multiply by U22 ====
16584 *
16585 CALL DGEMM( 'N', 'N', JLEN, I4-I2, J4-J2, ONE,
16586 $ H( JROW, INCOL+1+J2 ), LDH,
16587 $ U( J2+1, I2+1 ), LDU, ONE, WV( 1, 1+I2 ),
16588 $ LDWV )
16589 *
16590 * ==== Copy it back ====
16591 *
16592 CALL DLACPY( 'ALL', JLEN, KDU, WV, LDWV,
16593 $ H( JROW, INCOL+1 ), LDH )
16594 200 CONTINUE
16595 *
16596 * ==== Multiply Z (also vertical) ====
16597 *
16598 IF( WANTZ ) THEN
16599 DO 210 JROW = ILOZ, IHIZ, NV
16600 JLEN = MIN( NV, IHIZ-JROW+1 )
16601 *
16602 * ==== Copy right of Z to left of scratch (first
16603 * . KZS columns get multiplied by zero) ====
16604 *
16605 CALL DLACPY( 'ALL', JLEN, KNZ,
16606 $ Z( JROW, INCOL+1+J2 ), LDZ,
16607 $ WV( 1, 1+KZS ), LDWV )
16608 *
16609 * ==== Multiply by U12 ====
16610 *
16611 CALL DLASET( 'ALL', JLEN, KZS, ZERO, ZERO, WV,
16612 $ LDWV )
16613 CALL DTRMM( 'R', 'U', 'N', 'N', JLEN, KNZ, ONE,
16614 $ U( J2+1, 1+KZS ), LDU, WV( 1, 1+KZS ),
16615 $ LDWV )
16616 *
16617 * ==== Multiply by U11 ====
16618 *
16619 CALL DGEMM( 'N', 'N', JLEN, I2, J2, ONE,
16620 $ Z( JROW, INCOL+1 ), LDZ, U, LDU, ONE,
16621 $ WV, LDWV )
16622 *
16623 * ==== Copy left of Z to right of scratch ====
16624 *
16625 CALL DLACPY( 'ALL', JLEN, J2, Z( JROW, INCOL+1 ),
16626 $ LDZ, WV( 1, 1+I2 ), LDWV )
16627 *
16628 * ==== Multiply by U21 ====
16629 *
16630 CALL DTRMM( 'R', 'L', 'N', 'N', JLEN, I4-I2, ONE,
16631 $ U( 1, I2+1 ), LDU, WV( 1, 1+I2 ),
16632 $ LDWV )
16633 *
16634 * ==== Multiply by U22 ====
16635 *
16636 CALL DGEMM( 'N', 'N', JLEN, I4-I2, J4-J2, ONE,
16637 $ Z( JROW, INCOL+1+J2 ), LDZ,
16638 $ U( J2+1, I2+1 ), LDU, ONE,
16639 $ WV( 1, 1+I2 ), LDWV )
16640 *
16641 * ==== Copy the result back to Z ====
16642 *
16643 CALL DLACPY( 'ALL', JLEN, KDU, WV, LDWV,
16644 $ Z( JROW, INCOL+1 ), LDZ )
16645 210 CONTINUE
16646 END IF
16647 END IF
16648 END IF
16649 220 CONTINUE
16650 *
16651 * ==== End of DLAQR5 ====
16652 *
16653 END
16654 C
16655 C-----------------------------------------------------------------------
16656 C-----------------------------------------------------------------------
16657 SUBROUTINE DLARF( SIDE, M, N, V, INCV, TAU, C, LDC, WORK )
16658 IMPLICIT NONE
16659 *
16660 * -- LAPACK auxiliary routine (version 3.2) --
16661 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
16662 * November 2006
16663 *
16664 * .. Scalar Arguments ..
16665 CHARACTER SIDE
16666 INTEGER INCV, LDC, M, N
16667 DOUBLE PRECISION TAU
16668 * ..
16669 * .. Array Arguments ..
16670 DOUBLE PRECISION C( LDC, * ), V( * ), WORK( * )
16671 * ..
16672 *
16673 * Purpose
16674 * =======
16675 *
16676 * DLARF applies a real elementary reflector H to a real m by n matrix
16677 * C, from either the left or the right. H is represented in the form
16678 *
16679 * H = I - tau * v * v'
16680 *
16681 * where tau is a real scalar and v is a real vector.
16682 *
16683 * If tau = 0, then H is taken to be the unit matrix.
16684 *
16685 * Arguments
16686 * =========
16687 *
16688 * SIDE (input) CHARACTER*1
16689 * = 'L': form H * C
16690 * = 'R': form C * H
16691 *
16692 * M (input) INTEGER
16693 * The number of rows of the matrix C.
16694 *
16695 * N (input) INTEGER
16696 * The number of columns of the matrix C.
16697 *
16698 * V (input) DOUBLE PRECISION array, dimension
16699 * (1 + (M-1)*abs(INCV)) if SIDE = 'L'
16700 * or (1 + (N-1)*abs(INCV)) if SIDE = 'R'
16701 * The vector v in the representation of H. V is not used if
16702 * TAU = 0.
16703 *
16704 * INCV (input) INTEGER
16705 * The increment between elements of v. INCV <> 0.
16706 *
16707 * TAU (input) DOUBLE PRECISION
16708 * The value tau in the representation of H.
16709 *
16710 * C (input/output) DOUBLE PRECISION array, dimension (LDC,N)
16711 * On entry, the m by n matrix C.
16712 * On exit, C is overwritten by the matrix H * C if SIDE = 'L',
16713 * or C * H if SIDE = 'R'.
16714 *
16715 * LDC (input) INTEGER
16716 * The leading dimension of the array C. LDC >= max(1,M).
16717 *
16718 * WORK (workspace) DOUBLE PRECISION array, dimension
16719 * (N) if SIDE = 'L'
16720 * or (M) if SIDE = 'R'
16721 *
16722 * =====================================================================
16723 *
16724 * .. Parameters ..
16725 DOUBLE PRECISION ONE, ZERO
16726 PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
16727 * ..
16728 * .. Local Scalars ..
16729 LOGICAL APPLYLEFT
16730 INTEGER I, LASTV, LASTC
16731 * ..
16732 * .. External Subroutines ..
16733 EXTERNAL DGEMV, DGER
16734 * ..
16735 * .. External Functions ..
16736 LOGICAL LSAME
16737 INTEGER ILADLR, ILADLC
16738 EXTERNAL LSAME, ILADLR, ILADLC
16739 * ..
16740 * .. Executable Statements ..
16741 *
16742 APPLYLEFT = LSAME( SIDE, 'L' )
16743 LASTV = 0
16744 LASTC = 0
16745 IF( TAU.NE.ZERO ) THEN
16746 ! Set up variables for scanning V. LASTV begins pointing to the end
16747 ! of V.
16748 IF( APPLYLEFT ) THEN
16749 LASTV = M
16750 ELSE
16751 LASTV = N
16752 END IF
16753 IF( INCV.GT.0 ) THEN
16754 I = 1 + (LASTV-1) * INCV
16755 ELSE
16756 I = 1
16757 END IF
16758 ! Look for the last non-zero row in V.
16759 DO WHILE( LASTV.GT.0 .AND. V( I ).EQ.ZERO )
16760 LASTV = LASTV - 1
16761 I = I - INCV
16762 END DO
16763 IF( APPLYLEFT ) THEN
16764 ! Scan for the last non-zero column in C(1:lastv,:).
16765 LASTC = ILADLC(LASTV, N, C, LDC)
16766 ELSE
16767 ! Scan for the last non-zero row in C(:,1:lastv).
16768 LASTC = ILADLR(M, LASTV, C, LDC)
16769 END IF
16770 END IF
16771 ! Note that lastc.eq.0 renders the BLAS operations null; no special
16772 ! case is needed at this level.
16773 IF( APPLYLEFT ) THEN
16774 *
16775 * Form H * C
16776 *
16777 IF( LASTV.GT.0 ) THEN
16778 *
16779 * w(1:lastc,1) := C(1:lastv,1:lastc)' * v(1:lastv,1)
16780 *
16781 CALL DGEMV( 'Transpose', LASTV, LASTC, ONE, C, LDC, V, INCV,
16782 $ ZERO, WORK, 1 )
16783 *
16784 * C(1:lastv,1:lastc) := C(...) - v(1:lastv,1) * w(1:lastc,1)'
16785 *
16786 CALL DGER( LASTV, LASTC, -TAU, V, INCV, WORK, 1, C, LDC )
16787 END IF
16788 ELSE
16789 *
16790 * Form C * H
16791 *
16792 IF( LASTV.GT.0 ) THEN
16793 *
16794 * w(1:lastc,1) := C(1:lastc,1:lastv) * v(1:lastv,1)
16795 *
16796 CALL DGEMV( 'No transpose', LASTC, LASTV, ONE, C, LDC,
16797 $ V, INCV, ZERO, WORK, 1 )
16798 *
16799 * C(1:lastc,1:lastv) := C(...) - w(1:lastc,1) * v(1:lastv,1)'
16800 *
16801 CALL DGER( LASTC, LASTV, -TAU, WORK, 1, V, INCV, C, LDC )
16802 END IF
16803 END IF
16804 RETURN
16805 *
16806 * End of DLARF
16807 *
16808 END
16809 C
16810 C-----------------------------------------------------------------------
16811 C-----------------------------------------------------------------------
16812 SUBROUTINE DLARFB( SIDE, TRANS, DIRECT, STOREV, M, N, K, V, LDV,
16813 $ T, LDT, C, LDC, WORK, LDWORK )
16814 IMPLICIT NONE
16815 *
16816 * -- LAPACK auxiliary routine (version 3.2) --
16817 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
16818 * November 2006
16819 *
16820 * .. Scalar Arguments ..
16821 CHARACTER DIRECT, SIDE, STOREV, TRANS
16822 INTEGER K, LDC, LDT, LDV, LDWORK, M, N
16823 * ..
16824 * .. Array Arguments ..
16825 DOUBLE PRECISION C( LDC, * ), T( LDT, * ), V( LDV, * ),
16826 $ WORK( LDWORK, * )
16827 * ..
16828 *
16829 * Purpose
16830 * =======
16831 *
16832 * DLARFB applies a real block reflector H or its transpose H' to a
16833 * real m by n matrix C, from either the left or the right.
16834 *
16835 * Arguments
16836 * =========
16837 *
16838 * SIDE (input) CHARACTER*1
16839 * = 'L': apply H or H' from the Left
16840 * = 'R': apply H or H' from the Right
16841 *
16842 * TRANS (input) CHARACTER*1
16843 * = 'N': apply H (No transpose)
16844 * = 'T': apply H' (Transpose)
16845 *
16846 * DIRECT (input) CHARACTER*1
16847 * Indicates how H is formed from a product of elementary
16848 * reflectors
16849 * = 'F': H = H(1) H(2) . . . H(k) (Forward)
16850 * = 'B': H = H(k) . . . H(2) H(1) (Backward)
16851 *
16852 * STOREV (input) CHARACTER*1
16853 * Indicates how the vectors which define the elementary
16854 * reflectors are stored:
16855 * = 'C': Columnwise
16856 * = 'R': Rowwise
16857 *
16858 * M (input) INTEGER
16859 * The number of rows of the matrix C.
16860 *
16861 * N (input) INTEGER
16862 * The number of columns of the matrix C.
16863 *
16864 * K (input) INTEGER
16865 * The order of the matrix T (= the number of elementary
16866 * reflectors whose product defines the block reflector).
16867 *
16868 * V (input) DOUBLE PRECISION array, dimension
16869 * (LDV,K) if STOREV = 'C'
16870 * (LDV,M) if STOREV = 'R' and SIDE = 'L'
16871 * (LDV,N) if STOREV = 'R' and SIDE = 'R'
16872 * The matrix V. See further details.
16873 *
16874 * LDV (input) INTEGER
16875 * The leading dimension of the array V.
16876 * If STOREV = 'C' and SIDE = 'L', LDV >= max(1,M);
16877 * if STOREV = 'C' and SIDE = 'R', LDV >= max(1,N);
16878 * if STOREV = 'R', LDV >= K.
16879 *
16880 * T (input) DOUBLE PRECISION array, dimension (LDT,K)
16881 * The triangular k by k matrix T in the representation of the
16882 * block reflector.
16883 *
16884 * LDT (input) INTEGER
16885 * The leading dimension of the array T. LDT >= K.
16886 *
16887 * C (input/output) DOUBLE PRECISION array, dimension (LDC,N)
16888 * On entry, the m by n matrix C.
16889 * On exit, C is overwritten by H*C or H'*C or C*H or C*H'.
16890 *
16891 * LDC (input) INTEGER
16892 * The leading dimension of the array C. LDA >= max(1,M).
16893 *
16894 * WORK (workspace) DOUBLE PRECISION array, dimension (LDWORK,K)
16895 *
16896 * LDWORK (input) INTEGER
16897 * The leading dimension of the array WORK.
16898 * If SIDE = 'L', LDWORK >= max(1,N);
16899 * if SIDE = 'R', LDWORK >= max(1,M).
16900 *
16901 * =====================================================================
16902 *
16903 * .. Parameters ..
16904 DOUBLE PRECISION ONE
16905 PARAMETER ( ONE = 1.0D+0 )
16906 * ..
16907 * .. Local Scalars ..
16908 CHARACTER TRANST
16909 INTEGER I, J, LASTV, LASTC
16910 * ..
16911 * .. External Functions ..
16912 LOGICAL LSAME
16913 INTEGER ILADLR, ILADLC
16914 EXTERNAL LSAME, ILADLR, ILADLC
16915 * ..
16916 * .. External Subroutines ..
16917 EXTERNAL DCOPY, DGEMM, DTRMM
16918 * ..
16919 * .. Executable Statements ..
16920 *
16921 * Quick return if possible
16922 *
16923 IF( M.LE.0 .OR. N.LE.0 )
16924 $ RETURN
16925 *
16926 IF( LSAME( TRANS, 'N' ) ) THEN
16927 TRANST = 'T'
16928 ELSE
16929 TRANST = 'N'
16930 END IF
16931 *
16932 IF( LSAME( STOREV, 'C' ) ) THEN
16933 *
16934 IF( LSAME( DIRECT, 'F' ) ) THEN
16935 *
16936 * Let V = ( V1 ) (first K rows)
16937 * ( V2 )
16938 * where V1 is unit lower triangular.
16939 *
16940 IF( LSAME( SIDE, 'L' ) ) THEN
16941 *
16942 * Form H * C or H' * C where C = ( C1 )
16943 * ( C2 )
16944 *
16945 LASTV = MAX( K, ILADLR( M, K, V, LDV ) )
16946 LASTC = ILADLC( LASTV, N, C, LDC )
16947 *
16948 * W := C' * V = (C1'*V1 + C2'*V2) (stored in WORK)
16949 *
16950 * W := C1'
16951 *
16952 DO 10 J = 1, K
16953 CALL DCOPY( LASTC, C( J, 1 ), LDC, WORK( 1, J ), 1 )
16954 10 CONTINUE
16955 *
16956 * W := W * V1
16957 *
16958 CALL DTRMM( 'Right', 'Lower', 'No transpose', 'Unit',
16959 $ LASTC, K, ONE, V, LDV, WORK, LDWORK )
16960 IF( LASTV.GT.K ) THEN
16961 *
16962 * W := W + C2'*V2
16963 *
16964 CALL DGEMM( 'Transpose', 'No transpose',
16965 $ LASTC, K, LASTV-K,
16966 $ ONE, C( K+1, 1 ), LDC, V( K+1, 1 ), LDV,
16967 $ ONE, WORK, LDWORK )
16968 END IF
16969 *
16970 * W := W * T' or W * T
16971 *
16972 CALL DTRMM( 'Right', 'Upper', TRANST, 'Non-unit',
16973 $ LASTC, K, ONE, T, LDT, WORK, LDWORK )
16974 *
16975 * C := C - V * W'
16976 *
16977 IF( LASTV.GT.K ) THEN
16978 *
16979 * C2 := C2 - V2 * W'
16980 *
16981 CALL DGEMM( 'No transpose', 'Transpose',
16982 $ LASTV-K, LASTC, K,
16983 $ -ONE, V( K+1, 1 ), LDV, WORK, LDWORK, ONE,
16984 $ C( K+1, 1 ), LDC )
16985 END IF
16986 *
16987 * W := W * V1'
16988 *
16989 CALL DTRMM( 'Right', 'Lower', 'Transpose', 'Unit',
16990 $ LASTC, K, ONE, V, LDV, WORK, LDWORK )
16991 *
16992 * C1 := C1 - W'
16993 *
16994 DO 30 J = 1, K
16995 DO 20 I = 1, LASTC
16996 C( J, I ) = C( J, I ) - WORK( I, J )
16997 20 CONTINUE
16998 30 CONTINUE
16999 *
17000 ELSE IF( LSAME( SIDE, 'R' ) ) THEN
17001 *
17002 * Form C * H or C * H' where C = ( C1 C2 )
17003 *
17004 LASTV = MAX( K, ILADLR( N, K, V, LDV ) )
17005 LASTC = ILADLR( M, LASTV, C, LDC )
17006 *
17007 * W := C * V = (C1*V1 + C2*V2) (stored in WORK)
17008 *
17009 * W := C1
17010 *
17011 DO 40 J = 1, K
17012 CALL DCOPY( LASTC, C( 1, J ), 1, WORK( 1, J ), 1 )
17013 40 CONTINUE
17014 *
17015 * W := W * V1
17016 *
17017 CALL DTRMM( 'Right', 'Lower', 'No transpose', 'Unit',
17018 $ LASTC, K, ONE, V, LDV, WORK, LDWORK )
17019 IF( LASTV.GT.K ) THEN
17020 *
17021 * W := W + C2 * V2
17022 *
17023 CALL DGEMM( 'No transpose', 'No transpose',
17024 $ LASTC, K, LASTV-K,
17025 $ ONE, C( 1, K+1 ), LDC, V( K+1, 1 ), LDV,
17026 $ ONE, WORK, LDWORK )
17027 END IF
17028 *
17029 * W := W * T or W * T'
17030 *
17031 CALL DTRMM( 'Right', 'Upper', TRANS, 'Non-unit',
17032 $ LASTC, K, ONE, T, LDT, WORK, LDWORK )
17033 *
17034 * C := C - W * V'
17035 *
17036 IF( LASTV.GT.K ) THEN
17037 *
17038 * C2 := C2 - W * V2'
17039 *
17040 CALL DGEMM( 'No transpose', 'Transpose',
17041 $ LASTC, LASTV-K, K,
17042 $ -ONE, WORK, LDWORK, V( K+1, 1 ), LDV, ONE,
17043 $ C( 1, K+1 ), LDC )
17044 END IF
17045 *
17046 * W := W * V1'
17047 *
17048 CALL DTRMM( 'Right', 'Lower', 'Transpose', 'Unit',
17049 $ LASTC, K, ONE, V, LDV, WORK, LDWORK )
17050 *
17051 * C1 := C1 - W
17052 *
17053 DO 60 J = 1, K
17054 DO 50 I = 1, LASTC
17055 C( I, J ) = C( I, J ) - WORK( I, J )
17056 50 CONTINUE
17057 60 CONTINUE
17058 END IF
17059 *
17060 ELSE
17061 *
17062 * Let V = ( V1 )
17063 * ( V2 ) (last K rows)
17064 * where V2 is unit upper triangular.
17065 *
17066 IF( LSAME( SIDE, 'L' ) ) THEN
17067 *
17068 * Form H * C or H' * C where C = ( C1 )
17069 * ( C2 )
17070 *
17071 LASTV = MAX( K, ILADLR( M, K, V, LDV ) )
17072 LASTC = ILADLC( LASTV, N, C, LDC )
17073 *
17074 * W := C' * V = (C1'*V1 + C2'*V2) (stored in WORK)
17075 *
17076 * W := C2'
17077 *
17078 DO 70 J = 1, K
17079 CALL DCOPY( LASTC, C( LASTV-K+J, 1 ), LDC,
17080 $ WORK( 1, J ), 1 )
17081 70 CONTINUE
17082 *
17083 * W := W * V2
17084 *
17085 CALL DTRMM( 'Right', 'Upper', 'No transpose', 'Unit',
17086 $ LASTC, K, ONE, V( LASTV-K+1, 1 ), LDV,
17087 $ WORK, LDWORK )
17088 IF( LASTV.GT.K ) THEN
17089 *
17090 * W := W + C1'*V1
17091 *
17092 CALL DGEMM( 'Transpose', 'No transpose',
17093 $ LASTC, K, LASTV-K, ONE, C, LDC, V, LDV,
17094 $ ONE, WORK, LDWORK )
17095 END IF
17096 *
17097 * W := W * T' or W * T
17098 *
17099 CALL DTRMM( 'Right', 'Lower', TRANST, 'Non-unit',
17100 $ LASTC, K, ONE, T, LDT, WORK, LDWORK )
17101 *
17102 * C := C - V * W'
17103 *
17104 IF( LASTV.GT.K ) THEN
17105 *
17106 * C1 := C1 - V1 * W'
17107 *
17108 CALL DGEMM( 'No transpose', 'Transpose',
17109 $ LASTV-K, LASTC, K, -ONE, V, LDV, WORK, LDWORK,
17110 $ ONE, C, LDC )
17111 END IF
17112 *
17113 * W := W * V2'
17114 *
17115 CALL DTRMM( 'Right', 'Upper', 'Transpose', 'Unit',
17116 $ LASTC, K, ONE, V( LASTV-K+1, 1 ), LDV,
17117 $ WORK, LDWORK )
17118 *
17119 * C2 := C2 - W'
17120 *
17121 DO 90 J = 1, K
17122 DO 80 I = 1, LASTC
17123 C( LASTV-K+J, I ) = C( LASTV-K+J, I ) - WORK(I, J)
17124 80 CONTINUE
17125 90 CONTINUE
17126 *
17127 ELSE IF( LSAME( SIDE, 'R' ) ) THEN
17128 *
17129 * Form C * H or C * H' where C = ( C1 C2 )
17130 *
17131 LASTV = MAX( K, ILADLR( N, K, V, LDV ) )
17132 LASTC = ILADLR( M, LASTV, C, LDC )
17133 *
17134 * W := C * V = (C1*V1 + C2*V2) (stored in WORK)
17135 *
17136 * W := C2
17137 *
17138 DO 100 J = 1, K
17139 CALL DCOPY( LASTC, C( 1, N-K+J ), 1, WORK( 1, J ), 1 )
17140 100 CONTINUE
17141 *
17142 * W := W * V2
17143 *
17144 CALL DTRMM( 'Right', 'Upper', 'No transpose', 'Unit',
17145 $ LASTC, K, ONE, V( LASTV-K+1, 1 ), LDV,
17146 $ WORK, LDWORK )
17147 IF( LASTV.GT.K ) THEN
17148 *
17149 * W := W + C1 * V1
17150 *
17151 CALL DGEMM( 'No transpose', 'No transpose',
17152 $ LASTC, K, LASTV-K, ONE, C, LDC, V, LDV,
17153 $ ONE, WORK, LDWORK )
17154 END IF
17155 *
17156 * W := W * T or W * T'
17157 *
17158 CALL DTRMM( 'Right', 'Lower', TRANS, 'Non-unit',
17159 $ LASTC, K, ONE, T, LDT, WORK, LDWORK )
17160 *
17161 * C := C - W * V'
17162 *
17163 IF( LASTV.GT.K ) THEN
17164 *
17165 * C1 := C1 - W * V1'
17166 *
17167 CALL DGEMM( 'No transpose', 'Transpose',
17168 $ LASTC, LASTV-K, K, -ONE, WORK, LDWORK, V, LDV,
17169 $ ONE, C, LDC )
17170 END IF
17171 *
17172 * W := W * V2'
17173 *
17174 CALL DTRMM( 'Right', 'Upper', 'Transpose', 'Unit',
17175 $ LASTC, K, ONE, V( LASTV-K+1, 1 ), LDV,
17176 $ WORK, LDWORK )
17177 *
17178 * C2 := C2 - W
17179 *
17180 DO 120 J = 1, K
17181 DO 110 I = 1, LASTC
17182 C( I, LASTV-K+J ) = C( I, LASTV-K+J ) - WORK(I, J)
17183 110 CONTINUE
17184 120 CONTINUE
17185 END IF
17186 END IF
17187 *
17188 ELSE IF( LSAME( STOREV, 'R' ) ) THEN
17189 *
17190 IF( LSAME( DIRECT, 'F' ) ) THEN
17191 *
17192 * Let V = ( V1 V2 ) (V1: first K columns)
17193 * where V1 is unit upper triangular.
17194 *
17195 IF( LSAME( SIDE, 'L' ) ) THEN
17196 *
17197 * Form H * C or H' * C where C = ( C1 )
17198 * ( C2 )
17199 *
17200 LASTV = MAX( K, ILADLC( K, M, V, LDV ) )
17201 LASTC = ILADLC( LASTV, N, C, LDC )
17202 *
17203 * W := C' * V' = (C1'*V1' + C2'*V2') (stored in WORK)
17204 *
17205 * W := C1'
17206 *
17207 DO 130 J = 1, K
17208 CALL DCOPY( LASTC, C( J, 1 ), LDC, WORK( 1, J ), 1 )
17209 130 CONTINUE
17210 *
17211 * W := W * V1'
17212 *
17213 CALL DTRMM( 'Right', 'Upper', 'Transpose', 'Unit',
17214 $ LASTC, K, ONE, V, LDV, WORK, LDWORK )
17215 IF( LASTV.GT.K ) THEN
17216 *
17217 * W := W + C2'*V2'
17218 *
17219 CALL DGEMM( 'Transpose', 'Transpose',
17220 $ LASTC, K, LASTV-K,
17221 $ ONE, C( K+1, 1 ), LDC, V( 1, K+1 ), LDV,
17222 $ ONE, WORK, LDWORK )
17223 END IF
17224 *
17225 * W := W * T' or W * T
17226 *
17227 CALL DTRMM( 'Right', 'Upper', TRANST, 'Non-unit',
17228 $ LASTC, K, ONE, T, LDT, WORK, LDWORK )
17229 *
17230 * C := C - V' * W'
17231 *
17232 IF( LASTV.GT.K ) THEN
17233 *
17234 * C2 := C2 - V2' * W'
17235 *
17236 CALL DGEMM( 'Transpose', 'Transpose',
17237 $ LASTV-K, LASTC, K,
17238 $ -ONE, V( 1, K+1 ), LDV, WORK, LDWORK,
17239 $ ONE, C( K+1, 1 ), LDC )
17240 END IF
17241 *
17242 * W := W * V1
17243 *
17244 CALL DTRMM( 'Right', 'Upper', 'No transpose', 'Unit',
17245 $ LASTC, K, ONE, V, LDV, WORK, LDWORK )
17246 *
17247 * C1 := C1 - W'
17248 *
17249 DO 150 J = 1, K
17250 DO 140 I = 1, LASTC
17251 C( J, I ) = C( J, I ) - WORK( I, J )
17252 140 CONTINUE
17253 150 CONTINUE
17254 *
17255 ELSE IF( LSAME( SIDE, 'R' ) ) THEN
17256 *
17257 * Form C * H or C * H' where C = ( C1 C2 )
17258 *
17259 LASTV = MAX( K, ILADLC( K, N, V, LDV ) )
17260 LASTC = ILADLR( M, LASTV, C, LDC )
17261 *
17262 * W := C * V' = (C1*V1' + C2*V2') (stored in WORK)
17263 *
17264 * W := C1
17265 *
17266 DO 160 J = 1, K
17267 CALL DCOPY( LASTC, C( 1, J ), 1, WORK( 1, J ), 1 )
17268 160 CONTINUE
17269 *
17270 * W := W * V1'
17271 *
17272 CALL DTRMM( 'Right', 'Upper', 'Transpose', 'Unit',
17273 $ LASTC, K, ONE, V, LDV, WORK, LDWORK )
17274 IF( LASTV.GT.K ) THEN
17275 *
17276 * W := W + C2 * V2'
17277 *
17278 CALL DGEMM( 'No transpose', 'Transpose',
17279 $ LASTC, K, LASTV-K,
17280 $ ONE, C( 1, K+1 ), LDC, V( 1, K+1 ), LDV,
17281 $ ONE, WORK, LDWORK )
17282 END IF
17283 *
17284 * W := W * T or W * T'
17285 *
17286 CALL DTRMM( 'Right', 'Upper', TRANS, 'Non-unit',
17287 $ LASTC, K, ONE, T, LDT, WORK, LDWORK )
17288 *
17289 * C := C - W * V
17290 *
17291 IF( LASTV.GT.K ) THEN
17292 *
17293 * C2 := C2 - W * V2
17294 *
17295 CALL DGEMM( 'No transpose', 'No transpose',
17296 $ LASTC, LASTV-K, K,
17297 $ -ONE, WORK, LDWORK, V( 1, K+1 ), LDV,
17298 $ ONE, C( 1, K+1 ), LDC )
17299 END IF
17300 *
17301 * W := W * V1
17302 *
17303 CALL DTRMM( 'Right', 'Upper', 'No transpose', 'Unit',
17304 $ LASTC, K, ONE, V, LDV, WORK, LDWORK )
17305 *
17306 * C1 := C1 - W
17307 *
17308 DO 180 J = 1, K
17309 DO 170 I = 1, LASTC
17310 C( I, J ) = C( I, J ) - WORK( I, J )
17311 170 CONTINUE
17312 180 CONTINUE
17313 *
17314 END IF
17315 *
17316 ELSE
17317 *
17318 * Let V = ( V1 V2 ) (V2: last K columns)
17319 * where V2 is unit lower triangular.
17320 *
17321 IF( LSAME( SIDE, 'L' ) ) THEN
17322 *
17323 * Form H * C or H' * C where C = ( C1 )
17324 * ( C2 )
17325 *
17326 LASTV = MAX( K, ILADLC( K, M, V, LDV ) )
17327 LASTC = ILADLC( LASTV, N, C, LDC )
17328 *
17329 * W := C' * V' = (C1'*V1' + C2'*V2') (stored in WORK)
17330 *
17331 * W := C2'
17332 *
17333 DO 190 J = 1, K
17334 CALL DCOPY( LASTC, C( LASTV-K+J, 1 ), LDC,
17335 $ WORK( 1, J ), 1 )
17336 190 CONTINUE
17337 *
17338 * W := W * V2'
17339 *
17340 CALL DTRMM( 'Right', 'Lower', 'Transpose', 'Unit',
17341 $ LASTC, K, ONE, V( 1, LASTV-K+1 ), LDV,
17342 $ WORK, LDWORK )
17343 IF( LASTV.GT.K ) THEN
17344 *
17345 * W := W + C1'*V1'
17346 *
17347 CALL DGEMM( 'Transpose', 'Transpose',
17348 $ LASTC, K, LASTV-K, ONE, C, LDC, V, LDV,
17349 $ ONE, WORK, LDWORK )
17350 END IF
17351 *
17352 * W := W * T' or W * T
17353 *
17354 CALL DTRMM( 'Right', 'Lower', TRANST, 'Non-unit',
17355 $ LASTC, K, ONE, T, LDT, WORK, LDWORK )
17356 *
17357 * C := C - V' * W'
17358 *
17359 IF( LASTV.GT.K ) THEN
17360 *
17361 * C1 := C1 - V1' * W'
17362 *
17363 CALL DGEMM( 'Transpose', 'Transpose',
17364 $ LASTV-K, LASTC, K, -ONE, V, LDV, WORK, LDWORK,
17365 $ ONE, C, LDC )
17366 END IF
17367 *
17368 * W := W * V2
17369 *
17370 CALL DTRMM( 'Right', 'Lower', 'No transpose', 'Unit',
17371 $ LASTC, K, ONE, V( 1, LASTV-K+1 ), LDV,
17372 $ WORK, LDWORK )
17373 *
17374 * C2 := C2 - W'
17375 *
17376 DO 210 J = 1, K
17377 DO 200 I = 1, LASTC
17378 C( LASTV-K+J, I ) = C( LASTV-K+J, I ) - WORK(I, J)
17379 200 CONTINUE
17380 210 CONTINUE
17381 *
17382 ELSE IF( LSAME( SIDE, 'R' ) ) THEN
17383 *
17384 * Form C * H or C * H' where C = ( C1 C2 )
17385 *
17386 LASTV = MAX( K, ILADLC( K, N, V, LDV ) )
17387 LASTC = ILADLR( M, LASTV, C, LDC )
17388 *
17389 * W := C * V' = (C1*V1' + C2*V2') (stored in WORK)
17390 *
17391 * W := C2
17392 *
17393 DO 220 J = 1, K
17394 CALL DCOPY( LASTC, C( 1, LASTV-K+J ), 1,
17395 $ WORK( 1, J ), 1 )
17396 220 CONTINUE
17397 *
17398 * W := W * V2'
17399 *
17400 CALL DTRMM( 'Right', 'Lower', 'Transpose', 'Unit',
17401 $ LASTC, K, ONE, V( 1, LASTV-K+1 ), LDV,
17402 $ WORK, LDWORK )
17403 IF( LASTV.GT.K ) THEN
17404 *
17405 * W := W + C1 * V1'
17406 *
17407 CALL DGEMM( 'No transpose', 'Transpose',
17408 $ LASTC, K, LASTV-K, ONE, C, LDC, V, LDV,
17409 $ ONE, WORK, LDWORK )
17410 END IF
17411 *
17412 * W := W * T or W * T'
17413 *
17414 CALL DTRMM( 'Right', 'Lower', TRANS, 'Non-unit',
17415 $ LASTC, K, ONE, T, LDT, WORK, LDWORK )
17416 *
17417 * C := C - W * V
17418 *
17419 IF( LASTV.GT.K ) THEN
17420 *
17421 * C1 := C1 - W * V1
17422 *
17423 CALL DGEMM( 'No transpose', 'No transpose',
17424 $ LASTC, LASTV-K, K, -ONE, WORK, LDWORK, V, LDV,
17425 $ ONE, C, LDC )
17426 END IF
17427 *
17428 * W := W * V2
17429 *
17430 CALL DTRMM( 'Right', 'Lower', 'No transpose', 'Unit',
17431 $ LASTC, K, ONE, V( 1, LASTV-K+1 ), LDV,
17432 $ WORK, LDWORK )
17433 *
17434 * C1 := C1 - W
17435 *
17436 DO 240 J = 1, K
17437 DO 230 I = 1, LASTC
17438 C( I, LASTV-K+J ) = C( I, LASTV-K+J ) - WORK(I, J)
17439 230 CONTINUE
17440 240 CONTINUE
17441 *
17442 END IF
17443 *
17444 END IF
17445 END IF
17446 *
17447 RETURN
17448 *
17449 * End of DLARFB
17450 *
17451 END
17452 C
17453 C-----------------------------------------------------------------------
17454 C-----------------------------------------------------------------------
17455 SUBROUTINE DLARFG( N, ALPHA, X, INCX, TAU )
17456 *
17457 * -- LAPACK auxiliary routine (version 3.2) --
17458 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
17459 * November 2006
17460 *
17461 * .. Scalar Arguments ..
17462 INTEGER INCX, N
17463 DOUBLE PRECISION ALPHA, TAU
17464 * ..
17465 * .. Array Arguments ..
17466 DOUBLE PRECISION X( * )
17467 * ..
17468 *
17469 * Purpose
17470 * =======
17471 *
17472 * DLARFG generates a real elementary reflector H of order n, such
17473 * that
17474 *
17475 * H * ( alpha ) = ( beta ), H' * H = I.
17476 * ( x ) ( 0 )
17477 *
17478 * where alpha and beta are scalars, and x is an (n-1)-element real
17479 * vector. H is represented in the form
17480 *
17481 * H = I - tau * ( 1 ) * ( 1 v' ) ,
17482 * ( v )
17483 *
17484 * where tau is a real scalar and v is a real (n-1)-element
17485 * vector.
17486 *
17487 * If the elements of x are all zero, then tau = 0 and H is taken to be
17488 * the unit matrix.
17489 *
17490 * Otherwise 1 <= tau <= 2.
17491 *
17492 * Arguments
17493 * =========
17494 *
17495 * N (input) INTEGER
17496 * The order of the elementary reflector.
17497 *
17498 * ALPHA (input/output) DOUBLE PRECISION
17499 * On entry, the value alpha.
17500 * On exit, it is overwritten with the value beta.
17501 *
17502 * X (input/output) DOUBLE PRECISION array, dimension
17503 * (1+(N-2)*abs(INCX))
17504 * On entry, the vector x.
17505 * On exit, it is overwritten with the vector v.
17506 *
17507 * INCX (input) INTEGER
17508 * The increment between elements of X. INCX > 0.
17509 *
17510 * TAU (output) DOUBLE PRECISION
17511 * The value tau.
17512 *
17513 * =====================================================================
17514 *
17515 * .. Parameters ..
17516 DOUBLE PRECISION ONE, ZERO
17517 PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
17518 * ..
17519 * .. Local Scalars ..
17520 INTEGER J, KNT
17521 DOUBLE PRECISION BETA, RSAFMN, SAFMIN, XNORM
17522 * ..
17523 * .. External Functions ..
17524 DOUBLE PRECISION DLAMCH, DLAPY2, DNRM2
17525 EXTERNAL DLAMCH, DLAPY2, DNRM2
17526 * ..
17527 * .. Intrinsic Functions ..
17528 INTRINSIC ABS, SIGN
17529 * ..
17530 * .. External Subroutines ..
17531 EXTERNAL DSCAL
17532 * ..
17533 * .. Executable Statements ..
17534 *
17535 IF( N.LE.1 ) THEN
17536 TAU = ZERO
17537 RETURN
17538 END IF
17539 *
17540 XNORM = DNRM2( N-1, X, INCX )
17541 *
17542 IF( XNORM.EQ.ZERO ) THEN
17543 *
17544 * H = I
17545 *
17546 TAU = ZERO
17547 ELSE
17548 *
17549 * general case
17550 *
17551 BETA = -SIGN( DLAPY2( ALPHA, XNORM ), ALPHA )
17552 SAFMIN = DLAMCH( 'S' ) / DLAMCH( 'E' )
17553 KNT = 0
17554 IF( ABS( BETA ).LT.SAFMIN ) THEN
17555 *
17556 * XNORM, BETA may be inaccurate; scale X and recompute them
17557 *
17558 RSAFMN = ONE / SAFMIN
17559 10 CONTINUE
17560 KNT = KNT + 1
17561 CALL DSCAL( N-1, RSAFMN, X, INCX )
17562 BETA = BETA*RSAFMN
17563 ALPHA = ALPHA*RSAFMN
17564 IF( ABS( BETA ).LT.SAFMIN )
17565 $ GO TO 10
17566 *
17567 * New BETA is at most 1, at least SAFMIN
17568 *
17569 XNORM = DNRM2( N-1, X, INCX )
17570 BETA = -SIGN( DLAPY2( ALPHA, XNORM ), ALPHA )
17571 END IF
17572 TAU = ( BETA-ALPHA ) / BETA
17573 CALL DSCAL( N-1, ONE / ( ALPHA-BETA ), X, INCX )
17574 *
17575 * If ALPHA is subnormal, it may lose relative accuracy
17576 *
17577 DO 20 J = 1, KNT
17578 BETA = BETA*SAFMIN
17579 20 CONTINUE
17580 ALPHA = BETA
17581 END IF
17582 *
17583 RETURN
17584 *
17585 * End of DLARFG
17586 *
17587 END
17588 C
17589 C-----------------------------------------------------------------------
17590 C-----------------------------------------------------------------------
17591 SUBROUTINE DLARFT( DIRECT, STOREV, N, K, V, LDV, TAU, T, LDT )
17592 IMPLICIT NONE
17593 *
17594 * -- LAPACK auxiliary routine (version 3.2) --
17595 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
17596 * November 2006
17597 *
17598 * .. Scalar Arguments ..
17599 CHARACTER DIRECT, STOREV
17600 INTEGER K, LDT, LDV, N
17601 * ..
17602 * .. Array Arguments ..
17603 DOUBLE PRECISION T( LDT, * ), TAU( * ), V( LDV, * )
17604 * ..
17605 *
17606 * Purpose
17607 * =======
17608 *
17609 * DLARFT forms the triangular factor T of a real block reflector H
17610 * of order n, which is defined as a product of k elementary reflectors.
17611 *
17612 * If DIRECT = 'F', H = H(1) H(2) . . . H(k) and T is upper triangular;
17613 *
17614 * If DIRECT = 'B', H = H(k) . . . H(2) H(1) and T is lower triangular.
17615 *
17616 * If STOREV = 'C', the vector which defines the elementary reflector
17617 * H(i) is stored in the i-th column of the array V, and
17618 *
17619 * H = I - V * T * V'
17620 *
17621 * If STOREV = 'R', the vector which defines the elementary reflector
17622 * H(i) is stored in the i-th row of the array V, and
17623 *
17624 * H = I - V' * T * V
17625 *
17626 * Arguments
17627 * =========
17628 *
17629 * DIRECT (input) CHARACTER*1
17630 * Specifies the order in which the elementary reflectors are
17631 * multiplied to form the block reflector:
17632 * = 'F': H = H(1) H(2) . . . H(k) (Forward)
17633 * = 'B': H = H(k) . . . H(2) H(1) (Backward)
17634 *
17635 * STOREV (input) CHARACTER*1
17636 * Specifies how the vectors which define the elementary
17637 * reflectors are stored (see also Further Details):
17638 * = 'C': columnwise
17639 * = 'R': rowwise
17640 *
17641 * N (input) INTEGER
17642 * The order of the block reflector H. N >= 0.
17643 *
17644 * K (input) INTEGER
17645 * The order of the triangular factor T (= the number of
17646 * elementary reflectors). K >= 1.
17647 *
17648 * V (input/output) DOUBLE PRECISION array, dimension
17649 * (LDV,K) if STOREV = 'C'
17650 * (LDV,N) if STOREV = 'R'
17651 * The matrix V. See further details.
17652 *
17653 * LDV (input) INTEGER
17654 * The leading dimension of the array V.
17655 * If STOREV = 'C', LDV >= max(1,N); if STOREV = 'R', LDV >= K.
17656 *
17657 * TAU (input) DOUBLE PRECISION array, dimension (K)
17658 * TAU(i) must contain the scalar factor of the elementary
17659 * reflector H(i).
17660 *
17661 * T (output) DOUBLE PRECISION array, dimension (LDT,K)
17662 * The k by k triangular factor T of the block reflector.
17663 * If DIRECT = 'F', T is upper triangular; if DIRECT = 'B', T is
17664 * lower triangular. The rest of the array is not used.
17665 *
17666 * LDT (input) INTEGER
17667 * The leading dimension of the array T. LDT >= K.
17668 *
17669 * Further Details
17670 * ===============
17671 *
17672 * The shape of the matrix V and the storage of the vectors which define
17673 * the H(i) is best illustrated by the following example with n = 5 and
17674 * k = 3. The elements equal to 1 are not stored; the corresponding
17675 * array elements are modified but restored on exit. The rest of the
17676 * array is not used.
17677 *
17678 * DIRECT = 'F' and STOREV = 'C': DIRECT = 'F' and STOREV = 'R':
17679 *
17680 * V = ( 1 ) V = ( 1 v1 v1 v1 v1 )
17681 * ( v1 1 ) ( 1 v2 v2 v2 )
17682 * ( v1 v2 1 ) ( 1 v3 v3 )
17683 * ( v1 v2 v3 )
17684 * ( v1 v2 v3 )
17685 *
17686 * DIRECT = 'B' and STOREV = 'C': DIRECT = 'B' and STOREV = 'R':
17687 *
17688 * V = ( v1 v2 v3 ) V = ( v1 v1 1 )
17689 * ( v1 v2 v3 ) ( v2 v2 v2 1 )
17690 * ( 1 v2 v3 ) ( v3 v3 v3 v3 1 )
17691 * ( 1 v3 )
17692 * ( 1 )
17693 *
17694 * =====================================================================
17695 *
17696 * .. Parameters ..
17697 DOUBLE PRECISION ONE, ZERO
17698 PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
17699 * ..
17700 * .. Local Scalars ..
17701 INTEGER I, J, PREVLASTV, LASTV
17702 DOUBLE PRECISION VII
17703 * ..
17704 * .. External Subroutines ..
17705 EXTERNAL DGEMV, DTRMV
17706 * ..
17707 * .. External Functions ..
17708 LOGICAL LSAME
17709 EXTERNAL LSAME
17710 * ..
17711 * .. Executable Statements ..
17712 *
17713 * Quick return if possible
17714 *
17715 IF( N.EQ.0 )
17716 $ RETURN
17717 *
17718 IF( LSAME( DIRECT, 'F' ) ) THEN
17719 PREVLASTV = N
17720 DO 20 I = 1, K
17721 PREVLASTV = MAX( I, PREVLASTV )
17722 IF( TAU( I ).EQ.ZERO ) THEN
17723 *
17724 * H(i) = I
17725 *
17726 DO 10 J = 1, I
17727 T( J, I ) = ZERO
17728 10 CONTINUE
17729 ELSE
17730 *
17731 * general case
17732 *
17733 VII = V( I, I )
17734 V( I, I ) = ONE
17735 IF( LSAME( STOREV, 'C' ) ) THEN
17736 ! Skip any trailing zeros.
17737 DO LASTV = N, I+1, -1
17738 IF( V( LASTV, I ).NE.ZERO ) EXIT
17739 END DO
17740 J = MIN( LASTV, PREVLASTV )
17741 *
17742 * T(1:i-1,i) := - tau(i) * V(i:j,1:i-1)' * V(i:j,i)
17743 *
17744 CALL DGEMV( 'Transpose', J-I+1, I-1, -TAU( I ),
17745 $ V( I, 1 ), LDV, V( I, I ), 1, ZERO,
17746 $ T( 1, I ), 1 )
17747 ELSE
17748 ! Skip any trailing zeros.
17749 DO LASTV = N, I+1, -1
17750 IF( V( I, LASTV ).NE.ZERO ) EXIT
17751 END DO
17752 J = MIN( LASTV, PREVLASTV )
17753 *
17754 * T(1:i-1,i) := - tau(i) * V(1:i-1,i:j) * V(i,i:j)'
17755 *
17756 CALL DGEMV( 'No transpose', I-1, J-I+1, -TAU( I ),
17757 $ V( 1, I ), LDV, V( I, I ), LDV, ZERO,
17758 $ T( 1, I ), 1 )
17759 END IF
17760 V( I, I ) = VII
17761 *
17762 * T(1:i-1,i) := T(1:i-1,1:i-1) * T(1:i-1,i)
17763 *
17764 CALL DTRMV( 'Upper', 'No transpose', 'Non-unit', I-1, T,
17765 $ LDT, T( 1, I ), 1 )
17766 T( I, I ) = TAU( I )
17767 IF( I.GT.1 ) THEN
17768 PREVLASTV = MAX( PREVLASTV, LASTV )
17769 ELSE
17770 PREVLASTV = LASTV
17771 END IF
17772 END IF
17773 20 CONTINUE
17774 ELSE
17775 PREVLASTV = 1
17776 DO 40 I = K, 1, -1
17777 IF( TAU( I ).EQ.ZERO ) THEN
17778 *
17779 * H(i) = I
17780 *
17781 DO 30 J = I, K
17782 T( J, I ) = ZERO
17783 30 CONTINUE
17784 ELSE
17785 *
17786 * general case
17787 *
17788 IF( I.LT.K ) THEN
17789 IF( LSAME( STOREV, 'C' ) ) THEN
17790 VII = V( N-K+I, I )
17791 V( N-K+I, I ) = ONE
17792 ! Skip any leading zeros.
17793 DO LASTV = 1, I-1
17794 IF( V( LASTV, I ).NE.ZERO ) EXIT
17795 END DO
17796 J = MAX( LASTV, PREVLASTV )
17797 *
17798 * T(i+1:k,i) :=
17799 * - tau(i) * V(j:n-k+i,i+1:k)' * V(j:n-k+i,i)
17800 *
17801 CALL DGEMV( 'Transpose', N-K+I-J+1, K-I, -TAU( I ),
17802 $ V( J, I+1 ), LDV, V( J, I ), 1, ZERO,
17803 $ T( I+1, I ), 1 )
17804 V( N-K+I, I ) = VII
17805 ELSE
17806 VII = V( I, N-K+I )
17807 V( I, N-K+I ) = ONE
17808 ! Skip any leading zeros.
17809 DO LASTV = 1, I-1
17810 IF( V( I, LASTV ).NE.ZERO ) EXIT
17811 END DO
17812 J = MAX( LASTV, PREVLASTV )
17813 *
17814 * T(i+1:k,i) :=
17815 * - tau(i) * V(i+1:k,j:n-k+i) * V(i,j:n-k+i)'
17816 *
17817 CALL DGEMV( 'No transpose', K-I, N-K+I-J+1,
17818 $ -TAU( I ), V( I+1, J ), LDV, V( I, J ), LDV,
17819 $ ZERO, T( I+1, I ), 1 )
17820 V( I, N-K+I ) = VII
17821 END IF
17822 *
17823 * T(i+1:k,i) := T(i+1:k,i+1:k) * T(i+1:k,i)
17824 *
17825 CALL DTRMV( 'Lower', 'No transpose', 'Non-unit', K-I,
17826 $ T( I+1, I+1 ), LDT, T( I+1, I ), 1 )
17827 IF( I.GT.1 ) THEN
17828 PREVLASTV = MIN( PREVLASTV, LASTV )
17829 ELSE
17830 PREVLASTV = LASTV
17831 END IF
17832 END IF
17833 T( I, I ) = TAU( I )
17834 END IF
17835 40 CONTINUE
17836 END IF
17837 RETURN
17838 *
17839 * End of DLARFT
17840 *
17841 END
17842 C
17843 C-----------------------------------------------------------------------
17844 C-----------------------------------------------------------------------
17845 SUBROUTINE DLARFX( SIDE, M, N, V, TAU, C, LDC, WORK )
17846 IMPLICIT NONE
17847 *
17848 * -- LAPACK auxiliary routine (version 3.2) --
17849 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
17850 * November 2006
17851 *
17852 * .. Scalar Arguments ..
17853 CHARACTER SIDE
17854 INTEGER LDC, M, N
17855 DOUBLE PRECISION TAU
17856 * ..
17857 * .. Array Arguments ..
17858 DOUBLE PRECISION C( LDC, * ), V( * ), WORK( * )
17859 * ..
17860 *
17861 * Purpose
17862 * =======
17863 *
17864 * DLARFX applies a real elementary reflector H to a real m by n
17865 * matrix C, from either the left or the right. H is represented in the
17866 * form
17867 *
17868 * H = I - tau * v * v'
17869 *
17870 * where tau is a real scalar and v is a real vector.
17871 *
17872 * If tau = 0, then H is taken to be the unit matrix
17873 *
17874 * This version uses inline code if H has order < 11.
17875 *
17876 * Arguments
17877 * =========
17878 *
17879 * SIDE (input) CHARACTER*1
17880 * = 'L': form H * C
17881 * = 'R': form C * H
17882 *
17883 * M (input) INTEGER
17884 * The number of rows of the matrix C.
17885 *
17886 * N (input) INTEGER
17887 * The number of columns of the matrix C.
17888 *
17889 * V (input) DOUBLE PRECISION array, dimension (M) if SIDE = 'L'
17890 * or (N) if SIDE = 'R'
17891 * The vector v in the representation of H.
17892 *
17893 * TAU (input) DOUBLE PRECISION
17894 * The value tau in the representation of H.
17895 *
17896 * C (input/output) DOUBLE PRECISION array, dimension (LDC,N)
17897 * On entry, the m by n matrix C.
17898 * On exit, C is overwritten by the matrix H * C if SIDE = 'L',
17899 * or C * H if SIDE = 'R'.
17900 *
17901 * LDC (input) INTEGER
17902 * The leading dimension of the array C. LDA >= (1,M).
17903 *
17904 * WORK (workspace) DOUBLE PRECISION array, dimension
17905 * (N) if SIDE = 'L'
17906 * or (M) if SIDE = 'R'
17907 * WORK is not referenced if H has order < 11.
17908 *
17909 * =====================================================================
17910 *
17911 * .. Parameters ..
17912 DOUBLE PRECISION ZERO, ONE
17913 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
17914 * ..
17915 * .. Local Scalars ..
17916 INTEGER J
17917 DOUBLE PRECISION SUM, T1, T10, T2, T3, T4, T5, T6, T7, T8, T9,
17918 $ V1, V10, V2, V3, V4, V5, V6, V7, V8, V9
17919 * ..
17920 * .. External Functions ..
17921 LOGICAL LSAME
17922 EXTERNAL LSAME
17923 * ..
17924 * .. External Subroutines ..
17925 EXTERNAL DLARF
17926 * ..
17927 * .. Executable Statements ..
17928 *
17929 IF( TAU.EQ.ZERO )
17930 $ RETURN
17931 IF( LSAME( SIDE, 'L' ) ) THEN
17932 *
17933 * Form H * C, where H has order m.
17934 *
17935 GO TO ( 10, 30, 50, 70, 90, 110, 130, 150,
17936 $ 170, 190 )M
17937 *
17938 * Code for general M
17939 *
17940 CALL DLARF( SIDE, M, N, V, 1, TAU, C, LDC, WORK )
17941 GO TO 410
17942 10 CONTINUE
17943 *
17944 * Special code for 1 x 1 Householder
17945 *
17946 T1 = ONE - TAU*V( 1 )*V( 1 )
17947 DO 20 J = 1, N
17948 C( 1, J ) = T1*C( 1, J )
17949 20 CONTINUE
17950 GO TO 410
17951 30 CONTINUE
17952 *
17953 * Special code for 2 x 2 Householder
17954 *
17955 V1 = V( 1 )
17956 T1 = TAU*V1
17957 V2 = V( 2 )
17958 T2 = TAU*V2
17959 DO 40 J = 1, N
17960 SUM = V1*C( 1, J ) + V2*C( 2, J )
17961 C( 1, J ) = C( 1, J ) - SUM*T1
17962 C( 2, J ) = C( 2, J ) - SUM*T2
17963 40 CONTINUE
17964 GO TO 410
17965 50 CONTINUE
17966 *
17967 * Special code for 3 x 3 Householder
17968 *
17969 V1 = V( 1 )
17970 T1 = TAU*V1
17971 V2 = V( 2 )
17972 T2 = TAU*V2
17973 V3 = V( 3 )
17974 T3 = TAU*V3
17975 DO 60 J = 1, N
17976 SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J )
17977 C( 1, J ) = C( 1, J ) - SUM*T1
17978 C( 2, J ) = C( 2, J ) - SUM*T2
17979 C( 3, J ) = C( 3, J ) - SUM*T3
17980 60 CONTINUE
17981 GO TO 410
17982 70 CONTINUE
17983 *
17984 * Special code for 4 x 4 Householder
17985 *
17986 V1 = V( 1 )
17987 T1 = TAU*V1
17988 V2 = V( 2 )
17989 T2 = TAU*V2
17990 V3 = V( 3 )
17991 T3 = TAU*V3
17992 V4 = V( 4 )
17993 T4 = TAU*V4
17994 DO 80 J = 1, N
17995 SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
17996 $ V4*C( 4, J )
17997 C( 1, J ) = C( 1, J ) - SUM*T1
17998 C( 2, J ) = C( 2, J ) - SUM*T2
17999 C( 3, J ) = C( 3, J ) - SUM*T3
18000 C( 4, J ) = C( 4, J ) - SUM*T4
18001 80 CONTINUE
18002 GO TO 410
18003 90 CONTINUE
18004 *
18005 * Special code for 5 x 5 Householder
18006 *
18007 V1 = V( 1 )
18008 T1 = TAU*V1
18009 V2 = V( 2 )
18010 T2 = TAU*V2
18011 V3 = V( 3 )
18012 T3 = TAU*V3
18013 V4 = V( 4 )
18014 T4 = TAU*V4
18015 V5 = V( 5 )
18016 T5 = TAU*V5
18017 DO 100 J = 1, N
18018 SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
18019 $ V4*C( 4, J ) + V5*C( 5, J )
18020 C( 1, J ) = C( 1, J ) - SUM*T1
18021 C( 2, J ) = C( 2, J ) - SUM*T2
18022 C( 3, J ) = C( 3, J ) - SUM*T3
18023 C( 4, J ) = C( 4, J ) - SUM*T4
18024 C( 5, J ) = C( 5, J ) - SUM*T5
18025 100 CONTINUE
18026 GO TO 410
18027 110 CONTINUE
18028 *
18029 * Special code for 6 x 6 Householder
18030 *
18031 V1 = V( 1 )
18032 T1 = TAU*V1
18033 V2 = V( 2 )
18034 T2 = TAU*V2
18035 V3 = V( 3 )
18036 T3 = TAU*V3
18037 V4 = V( 4 )
18038 T4 = TAU*V4
18039 V5 = V( 5 )
18040 T5 = TAU*V5
18041 V6 = V( 6 )
18042 T6 = TAU*V6
18043 DO 120 J = 1, N
18044 SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
18045 $ V4*C( 4, J ) + V5*C( 5, J ) + V6*C( 6, J )
18046 C( 1, J ) = C( 1, J ) - SUM*T1
18047 C( 2, J ) = C( 2, J ) - SUM*T2
18048 C( 3, J ) = C( 3, J ) - SUM*T3
18049 C( 4, J ) = C( 4, J ) - SUM*T4
18050 C( 5, J ) = C( 5, J ) - SUM*T5
18051 C( 6, J ) = C( 6, J ) - SUM*T6
18052 120 CONTINUE
18053 GO TO 410
18054 130 CONTINUE
18055 *
18056 * Special code for 7 x 7 Householder
18057 *
18058 V1 = V( 1 )
18059 T1 = TAU*V1
18060 V2 = V( 2 )
18061 T2 = TAU*V2
18062 V3 = V( 3 )
18063 T3 = TAU*V3
18064 V4 = V( 4 )
18065 T4 = TAU*V4
18066 V5 = V( 5 )
18067 T5 = TAU*V5
18068 V6 = V( 6 )
18069 T6 = TAU*V6
18070 V7 = V( 7 )
18071 T7 = TAU*V7
18072 DO 140 J = 1, N
18073 SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
18074 $ V4*C( 4, J ) + V5*C( 5, J ) + V6*C( 6, J ) +
18075 $ V7*C( 7, J )
18076 C( 1, J ) = C( 1, J ) - SUM*T1
18077 C( 2, J ) = C( 2, J ) - SUM*T2
18078 C( 3, J ) = C( 3, J ) - SUM*T3
18079 C( 4, J ) = C( 4, J ) - SUM*T4
18080 C( 5, J ) = C( 5, J ) - SUM*T5
18081 C( 6, J ) = C( 6, J ) - SUM*T6
18082 C( 7, J ) = C( 7, J ) - SUM*T7
18083 140 CONTINUE
18084 GO TO 410
18085 150 CONTINUE
18086 *
18087 * Special code for 8 x 8 Householder
18088 *
18089 V1 = V( 1 )
18090 T1 = TAU*V1
18091 V2 = V( 2 )
18092 T2 = TAU*V2
18093 V3 = V( 3 )
18094 T3 = TAU*V3
18095 V4 = V( 4 )
18096 T4 = TAU*V4
18097 V5 = V( 5 )
18098 T5 = TAU*V5
18099 V6 = V( 6 )
18100 T6 = TAU*V6
18101 V7 = V( 7 )
18102 T7 = TAU*V7
18103 V8 = V( 8 )
18104 T8 = TAU*V8
18105 DO 160 J = 1, N
18106 SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
18107 $ V4*C( 4, J ) + V5*C( 5, J ) + V6*C( 6, J ) +
18108 $ V7*C( 7, J ) + V8*C( 8, J )
18109 C( 1, J ) = C( 1, J ) - SUM*T1
18110 C( 2, J ) = C( 2, J ) - SUM*T2
18111 C( 3, J ) = C( 3, J ) - SUM*T3
18112 C( 4, J ) = C( 4, J ) - SUM*T4
18113 C( 5, J ) = C( 5, J ) - SUM*T5
18114 C( 6, J ) = C( 6, J ) - SUM*T6
18115 C( 7, J ) = C( 7, J ) - SUM*T7
18116 C( 8, J ) = C( 8, J ) - SUM*T8
18117 160 CONTINUE
18118 GO TO 410
18119 170 CONTINUE
18120 *
18121 * Special code for 9 x 9 Householder
18122 *
18123 V1 = V( 1 )
18124 T1 = TAU*V1
18125 V2 = V( 2 )
18126 T2 = TAU*V2
18127 V3 = V( 3 )
18128 T3 = TAU*V3
18129 V4 = V( 4 )
18130 T4 = TAU*V4
18131 V5 = V( 5 )
18132 T5 = TAU*V5
18133 V6 = V( 6 )
18134 T6 = TAU*V6
18135 V7 = V( 7 )
18136 T7 = TAU*V7
18137 V8 = V( 8 )
18138 T8 = TAU*V8
18139 V9 = V( 9 )
18140 T9 = TAU*V9
18141 DO 180 J = 1, N
18142 SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
18143 $ V4*C( 4, J ) + V5*C( 5, J ) + V6*C( 6, J ) +
18144 $ V7*C( 7, J ) + V8*C( 8, J ) + V9*C( 9, J )
18145 C( 1, J ) = C( 1, J ) - SUM*T1
18146 C( 2, J ) = C( 2, J ) - SUM*T2
18147 C( 3, J ) = C( 3, J ) - SUM*T3
18148 C( 4, J ) = C( 4, J ) - SUM*T4
18149 C( 5, J ) = C( 5, J ) - SUM*T5
18150 C( 6, J ) = C( 6, J ) - SUM*T6
18151 C( 7, J ) = C( 7, J ) - SUM*T7
18152 C( 8, J ) = C( 8, J ) - SUM*T8
18153 C( 9, J ) = C( 9, J ) - SUM*T9
18154 180 CONTINUE
18155 GO TO 410
18156 190 CONTINUE
18157 *
18158 * Special code for 10 x 10 Householder
18159 *
18160 V1 = V( 1 )
18161 T1 = TAU*V1
18162 V2 = V( 2 )
18163 T2 = TAU*V2
18164 V3 = V( 3 )
18165 T3 = TAU*V3
18166 V4 = V( 4 )
18167 T4 = TAU*V4
18168 V5 = V( 5 )
18169 T5 = TAU*V5
18170 V6 = V( 6 )
18171 T6 = TAU*V6
18172 V7 = V( 7 )
18173 T7 = TAU*V7
18174 V8 = V( 8 )
18175 T8 = TAU*V8
18176 V9 = V( 9 )
18177 T9 = TAU*V9
18178 V10 = V( 10 )
18179 T10 = TAU*V10
18180 DO 200 J = 1, N
18181 SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
18182 $ V4*C( 4, J ) + V5*C( 5, J ) + V6*C( 6, J ) +
18183 $ V7*C( 7, J ) + V8*C( 8, J ) + V9*C( 9, J ) +
18184 $ V10*C( 10, J )
18185 C( 1, J ) = C( 1, J ) - SUM*T1
18186 C( 2, J ) = C( 2, J ) - SUM*T2
18187 C( 3, J ) = C( 3, J ) - SUM*T3
18188 C( 4, J ) = C( 4, J ) - SUM*T4
18189 C( 5, J ) = C( 5, J ) - SUM*T5
18190 C( 6, J ) = C( 6, J ) - SUM*T6
18191 C( 7, J ) = C( 7, J ) - SUM*T7
18192 C( 8, J ) = C( 8, J ) - SUM*T8
18193 C( 9, J ) = C( 9, J ) - SUM*T9
18194 C( 10, J ) = C( 10, J ) - SUM*T10
18195 200 CONTINUE
18196 GO TO 410
18197 ELSE
18198 *
18199 * Form C * H, where H has order n.
18200 *
18201 GO TO ( 210, 230, 250, 270, 290, 310, 330, 350,
18202 $ 370, 390 )N
18203 *
18204 * Code for general N
18205 *
18206 CALL DLARF( SIDE, M, N, V, 1, TAU, C, LDC, WORK )
18207 GO TO 410
18208 210 CONTINUE
18209 *
18210 * Special code for 1 x 1 Householder
18211 *
18212 T1 = ONE - TAU*V( 1 )*V( 1 )
18213 DO 220 J = 1, M
18214 C( J, 1 ) = T1*C( J, 1 )
18215 220 CONTINUE
18216 GO TO 410
18217 230 CONTINUE
18218 *
18219 * Special code for 2 x 2 Householder
18220 *
18221 V1 = V( 1 )
18222 T1 = TAU*V1
18223 V2 = V( 2 )
18224 T2 = TAU*V2
18225 DO 240 J = 1, M
18226 SUM = V1*C( J, 1 ) + V2*C( J, 2 )
18227 C( J, 1 ) = C( J, 1 ) - SUM*T1
18228 C( J, 2 ) = C( J, 2 ) - SUM*T2
18229 240 CONTINUE
18230 GO TO 410
18231 250 CONTINUE
18232 *
18233 * Special code for 3 x 3 Householder
18234 *
18235 V1 = V( 1 )
18236 T1 = TAU*V1
18237 V2 = V( 2 )
18238 T2 = TAU*V2
18239 V3 = V( 3 )
18240 T3 = TAU*V3
18241 DO 260 J = 1, M
18242 SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 )
18243 C( J, 1 ) = C( J, 1 ) - SUM*T1
18244 C( J, 2 ) = C( J, 2 ) - SUM*T2
18245 C( J, 3 ) = C( J, 3 ) - SUM*T3
18246 260 CONTINUE
18247 GO TO 410
18248 270 CONTINUE
18249 *
18250 * Special code for 4 x 4 Householder
18251 *
18252 V1 = V( 1 )
18253 T1 = TAU*V1
18254 V2 = V( 2 )
18255 T2 = TAU*V2
18256 V3 = V( 3 )
18257 T3 = TAU*V3
18258 V4 = V( 4 )
18259 T4 = TAU*V4
18260 DO 280 J = 1, M
18261 SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
18262 $ V4*C( J, 4 )
18263 C( J, 1 ) = C( J, 1 ) - SUM*T1
18264 C( J, 2 ) = C( J, 2 ) - SUM*T2
18265 C( J, 3 ) = C( J, 3 ) - SUM*T3
18266 C( J, 4 ) = C( J, 4 ) - SUM*T4
18267 280 CONTINUE
18268 GO TO 410
18269 290 CONTINUE
18270 *
18271 * Special code for 5 x 5 Householder
18272 *
18273 V1 = V( 1 )
18274 T1 = TAU*V1
18275 V2 = V( 2 )
18276 T2 = TAU*V2
18277 V3 = V( 3 )
18278 T3 = TAU*V3
18279 V4 = V( 4 )
18280 T4 = TAU*V4
18281 V5 = V( 5 )
18282 T5 = TAU*V5
18283 DO 300 J = 1, M
18284 SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
18285 $ V4*C( J, 4 ) + V5*C( J, 5 )
18286 C( J, 1 ) = C( J, 1 ) - SUM*T1
18287 C( J, 2 ) = C( J, 2 ) - SUM*T2
18288 C( J, 3 ) = C( J, 3 ) - SUM*T3
18289 C( J, 4 ) = C( J, 4 ) - SUM*T4
18290 C( J, 5 ) = C( J, 5 ) - SUM*T5
18291 300 CONTINUE
18292 GO TO 410
18293 310 CONTINUE
18294 *
18295 * Special code for 6 x 6 Householder
18296 *
18297 V1 = V( 1 )
18298 T1 = TAU*V1
18299 V2 = V( 2 )
18300 T2 = TAU*V2
18301 V3 = V( 3 )
18302 T3 = TAU*V3
18303 V4 = V( 4 )
18304 T4 = TAU*V4
18305 V5 = V( 5 )
18306 T5 = TAU*V5
18307 V6 = V( 6 )
18308 T6 = TAU*V6
18309 DO 320 J = 1, M
18310 SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
18311 $ V4*C( J, 4 ) + V5*C( J, 5 ) + V6*C( J, 6 )
18312 C( J, 1 ) = C( J, 1 ) - SUM*T1
18313 C( J, 2 ) = C( J, 2 ) - SUM*T2
18314 C( J, 3 ) = C( J, 3 ) - SUM*T3
18315 C( J, 4 ) = C( J, 4 ) - SUM*T4
18316 C( J, 5 ) = C( J, 5 ) - SUM*T5
18317 C( J, 6 ) = C( J, 6 ) - SUM*T6
18318 320 CONTINUE
18319 GO TO 410
18320 330 CONTINUE
18321 *
18322 * Special code for 7 x 7 Householder
18323 *
18324 V1 = V( 1 )
18325 T1 = TAU*V1
18326 V2 = V( 2 )
18327 T2 = TAU*V2
18328 V3 = V( 3 )
18329 T3 = TAU*V3
18330 V4 = V( 4 )
18331 T4 = TAU*V4
18332 V5 = V( 5 )
18333 T5 = TAU*V5
18334 V6 = V( 6 )
18335 T6 = TAU*V6
18336 V7 = V( 7 )
18337 T7 = TAU*V7
18338 DO 340 J = 1, M
18339 SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
18340 $ V4*C( J, 4 ) + V5*C( J, 5 ) + V6*C( J, 6 ) +
18341 $ V7*C( J, 7 )
18342 C( J, 1 ) = C( J, 1 ) - SUM*T1
18343 C( J, 2 ) = C( J, 2 ) - SUM*T2
18344 C( J, 3 ) = C( J, 3 ) - SUM*T3
18345 C( J, 4 ) = C( J, 4 ) - SUM*T4
18346 C( J, 5 ) = C( J, 5 ) - SUM*T5
18347 C( J, 6 ) = C( J, 6 ) - SUM*T6
18348 C( J, 7 ) = C( J, 7 ) - SUM*T7
18349 340 CONTINUE
18350 GO TO 410
18351 350 CONTINUE
18352 *
18353 * Special code for 8 x 8 Householder
18354 *
18355 V1 = V( 1 )
18356 T1 = TAU*V1
18357 V2 = V( 2 )
18358 T2 = TAU*V2
18359 V3 = V( 3 )
18360 T3 = TAU*V3
18361 V4 = V( 4 )
18362 T4 = TAU*V4
18363 V5 = V( 5 )
18364 T5 = TAU*V5
18365 V6 = V( 6 )
18366 T6 = TAU*V6
18367 V7 = V( 7 )
18368 T7 = TAU*V7
18369 V8 = V( 8 )
18370 T8 = TAU*V8
18371 DO 360 J = 1, M
18372 SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
18373 $ V4*C( J, 4 ) + V5*C( J, 5 ) + V6*C( J, 6 ) +
18374 $ V7*C( J, 7 ) + V8*C( J, 8 )
18375 C( J, 1 ) = C( J, 1 ) - SUM*T1
18376 C( J, 2 ) = C( J, 2 ) - SUM*T2
18377 C( J, 3 ) = C( J, 3 ) - SUM*T3
18378 C( J, 4 ) = C( J, 4 ) - SUM*T4
18379 C( J, 5 ) = C( J, 5 ) - SUM*T5
18380 C( J, 6 ) = C( J, 6 ) - SUM*T6
18381 C( J, 7 ) = C( J, 7 ) - SUM*T7
18382 C( J, 8 ) = C( J, 8 ) - SUM*T8
18383 360 CONTINUE
18384 GO TO 410
18385 370 CONTINUE
18386 *
18387 * Special code for 9 x 9 Householder
18388 *
18389 V1 = V( 1 )
18390 T1 = TAU*V1
18391 V2 = V( 2 )
18392 T2 = TAU*V2
18393 V3 = V( 3 )
18394 T3 = TAU*V3
18395 V4 = V( 4 )
18396 T4 = TAU*V4
18397 V5 = V( 5 )
18398 T5 = TAU*V5
18399 V6 = V( 6 )
18400 T6 = TAU*V6
18401 V7 = V( 7 )
18402 T7 = TAU*V7
18403 V8 = V( 8 )
18404 T8 = TAU*V8
18405 V9 = V( 9 )
18406 T9 = TAU*V9
18407 DO 380 J = 1, M
18408 SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
18409 $ V4*C( J, 4 ) + V5*C( J, 5 ) + V6*C( J, 6 ) +
18410 $ V7*C( J, 7 ) + V8*C( J, 8 ) + V9*C( J, 9 )
18411 C( J, 1 ) = C( J, 1 ) - SUM*T1
18412 C( J, 2 ) = C( J, 2 ) - SUM*T2
18413 C( J, 3 ) = C( J, 3 ) - SUM*T3
18414 C( J, 4 ) = C( J, 4 ) - SUM*T4
18415 C( J, 5 ) = C( J, 5 ) - SUM*T5
18416 C( J, 6 ) = C( J, 6 ) - SUM*T6
18417 C( J, 7 ) = C( J, 7 ) - SUM*T7
18418 C( J, 8 ) = C( J, 8 ) - SUM*T8
18419 C( J, 9 ) = C( J, 9 ) - SUM*T9
18420 380 CONTINUE
18421 GO TO 410
18422 390 CONTINUE
18423 *
18424 * Special code for 10 x 10 Householder
18425 *
18426 V1 = V( 1 )
18427 T1 = TAU*V1
18428 V2 = V( 2 )
18429 T2 = TAU*V2
18430 V3 = V( 3 )
18431 T3 = TAU*V3
18432 V4 = V( 4 )
18433 T4 = TAU*V4
18434 V5 = V( 5 )
18435 T5 = TAU*V5
18436 V6 = V( 6 )
18437 T6 = TAU*V6
18438 V7 = V( 7 )
18439 T7 = TAU*V7
18440 V8 = V( 8 )
18441 T8 = TAU*V8
18442 V9 = V( 9 )
18443 T9 = TAU*V9
18444 V10 = V( 10 )
18445 T10 = TAU*V10
18446 DO 400 J = 1, M
18447 SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
18448 $ V4*C( J, 4 ) + V5*C( J, 5 ) + V6*C( J, 6 ) +
18449 $ V7*C( J, 7 ) + V8*C( J, 8 ) + V9*C( J, 9 ) +
18450 $ V10*C( J, 10 )
18451 C( J, 1 ) = C( J, 1 ) - SUM*T1
18452 C( J, 2 ) = C( J, 2 ) - SUM*T2
18453 C( J, 3 ) = C( J, 3 ) - SUM*T3
18454 C( J, 4 ) = C( J, 4 ) - SUM*T4
18455 C( J, 5 ) = C( J, 5 ) - SUM*T5
18456 C( J, 6 ) = C( J, 6 ) - SUM*T6
18457 C( J, 7 ) = C( J, 7 ) - SUM*T7
18458 C( J, 8 ) = C( J, 8 ) - SUM*T8
18459 C( J, 9 ) = C( J, 9 ) - SUM*T9
18460 C( J, 10 ) = C( J, 10 ) - SUM*T10
18461 400 CONTINUE
18462 GO TO 410
18463 END IF
18464 410 CONTINUE
18465 RETURN
18466 *
18467 * End of DLARFX
18468 *
18469 END
18470 C
18471 C-----------------------------------------------------------------------
18472 C-----------------------------------------------------------------------
18473 SUBROUTINE DLARTG( F, G, CS, SN, R )
18474 *
18475 * -- LAPACK auxiliary routine (version 3.2) --
18476 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
18477 * November 2006
18478 *
18479 * .. Scalar Arguments ..
18480 DOUBLE PRECISION CS, F, G, R, SN
18481 * ..
18482 *
18483 * Purpose
18484 * =======
18485 *
18486 * DLARTG generate a plane rotation so that
18487 *
18488 * [ CS SN ] . [ F ] = [ R ] where CS**2 + SN**2 = 1.
18489 * [ -SN CS ] [ G ] [ 0 ]
18490 *
18491 * This is a slower, more accurate version of the BLAS1 routine DROTG,
18492 * with the following other differences:
18493 * F and G are unchanged on return.
18494 * If G=0, then CS=1 and SN=0.
18495 * If F=0 and (G .ne. 0), then CS=0 and SN=1 without doing any
18496 * floating point operations (saves work in DBDSQR when
18497 * there are zeros on the diagonal).
18498 *
18499 * If F exceeds G in magnitude, CS will be positive.
18500 *
18501 * Arguments
18502 * =========
18503 *
18504 * F (input) DOUBLE PRECISION
18505 * The first component of vector to be rotated.
18506 *
18507 * G (input) DOUBLE PRECISION
18508 * The second component of vector to be rotated.
18509 *
18510 * CS (output) DOUBLE PRECISION
18511 * The cosine of the rotation.
18512 *
18513 * SN (output) DOUBLE PRECISION
18514 * The sine of the rotation.
18515 *
18516 * R (output) DOUBLE PRECISION
18517 * The nonzero component of the rotated vector.
18518 *
18519 * This version has a few statements commented out for thread safety
18520 * (machine parameters are computed on each entry). 10 feb 03, SJH.
18521 *
18522 * =====================================================================
18523 *
18524 * .. Parameters ..
18525 DOUBLE PRECISION ZERO
18526 PARAMETER ( ZERO = 0.0D0 )
18527 DOUBLE PRECISION ONE
18528 PARAMETER ( ONE = 1.0D0 )
18529 DOUBLE PRECISION TWO
18530 PARAMETER ( TWO = 2.0D0 )
18531 * ..
18532 * .. Local Scalars ..
18533 * LOGICAL FIRST
18534 INTEGER COUNT, I
18535 DOUBLE PRECISION EPS, F1, G1, SAFMIN, SAFMN2, SAFMX2, SCALE
18536 * ..
18537 * .. External Functions ..
18538 DOUBLE PRECISION DLAMCH
18539 EXTERNAL DLAMCH
18540 * ..
18541 * .. Intrinsic Functions ..
18542 INTRINSIC ABS, INT, LOG, MAX, SQRT
18543 * ..
18544 * .. Save statement ..
18545 * SAVE FIRST, SAFMX2, SAFMIN, SAFMN2
18546 * ..
18547 * .. Data statements ..
18548 * DATA FIRST / .TRUE. /
18549 * ..
18550 * .. Executable Statements ..
18551 *
18552 * IF( FIRST ) THEN
18553 SAFMIN = DLAMCH( 'S' )
18554 EPS = DLAMCH( 'E' )
18555 SAFMN2 = DLAMCH( 'B' )**INT( LOG( SAFMIN / EPS ) /
18556 $ LOG( DLAMCH( 'B' ) ) / TWO )
18557 SAFMX2 = ONE / SAFMN2
18558 * FIRST = .FALSE.
18559 * END IF
18560 IF( G.EQ.ZERO ) THEN
18561 CS = ONE
18562 SN = ZERO
18563 R = F
18564 ELSE IF( F.EQ.ZERO ) THEN
18565 CS = ZERO
18566 SN = ONE
18567 R = G
18568 ELSE
18569 F1 = F
18570 G1 = G
18571 SCALE = MAX( ABS( F1 ), ABS( G1 ) )
18572 IF( SCALE.GE.SAFMX2 ) THEN
18573 COUNT = 0
18574 10 CONTINUE
18575 COUNT = COUNT + 1
18576 F1 = F1*SAFMN2
18577 G1 = G1*SAFMN2
18578 SCALE = MAX( ABS( F1 ), ABS( G1 ) )
18579 IF( SCALE.GE.SAFMX2 )
18580 $ GO TO 10
18581 R = SQRT( F1**2+G1**2 )
18582 CS = F1 / R
18583 SN = G1 / R
18584 DO 20 I = 1, COUNT
18585 R = R*SAFMX2
18586 20 CONTINUE
18587 ELSE IF( SCALE.LE.SAFMN2 ) THEN
18588 COUNT = 0
18589 30 CONTINUE
18590 COUNT = COUNT + 1
18591 F1 = F1*SAFMX2
18592 G1 = G1*SAFMX2
18593 SCALE = MAX( ABS( F1 ), ABS( G1 ) )
18594 IF( SCALE.LE.SAFMN2 )
18595 $ GO TO 30
18596 R = SQRT( F1**2+G1**2 )
18597 CS = F1 / R
18598 SN = G1 / R
18599 DO 40 I = 1, COUNT
18600 R = R*SAFMN2
18601 40 CONTINUE
18602 ELSE
18603 R = SQRT( F1**2+G1**2 )
18604 CS = F1 / R
18605 SN = G1 / R
18606 END IF
18607 IF( ABS( F ).GT.ABS( G ) .AND. CS.LT.ZERO ) THEN
18608 CS = -CS
18609 SN = -SN
18610 R = -R
18611 END IF
18612 END IF
18613 RETURN
18614 *
18615 * End of DLARTG
18616 *
18617 END
18618 C
18619 C-----------------------------------------------------------------------
18620 C-----------------------------------------------------------------------
18621 SUBROUTINE DLASCL( TYPE, KL, KU, CFROM, CTO, M, N, A, LDA, INFO )
18622 *
18623 * -- LAPACK auxiliary routine (version 3.2) --
18624 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
18625 * November 2006
18626 *
18627 * .. Scalar Arguments ..
18628 CHARACTER TYPE
18629 INTEGER INFO, KL, KU, LDA, M, N
18630 DOUBLE PRECISION CFROM, CTO
18631 * ..
18632 * .. Array Arguments ..
18633 DOUBLE PRECISION A( LDA, * )
18634 * ..
18635 *
18636 * Purpose
18637 * =======
18638 *
18639 * DLASCL multiplies the M by N real matrix A by the real scalar
18640 * CTO/CFROM. This is done without over/underflow as long as the final
18641 * result CTO*A(I,J)/CFROM does not over/underflow. TYPE specifies that
18642 * A may be full, upper triangular, lower triangular, upper Hessenberg,
18643 * or banded.
18644 *
18645 * Arguments
18646 * =========
18647 *
18648 * TYPE (input) CHARACTER*1
18649 * TYPE indices the storage type of the input matrix.
18650 * = 'G': A is a full matrix.
18651 * = 'L': A is a lower triangular matrix.
18652 * = 'U': A is an upper triangular matrix.
18653 * = 'H': A is an upper Hessenberg matrix.
18654 * = 'B': A is a symmetric band matrix with lower bandwidth KL
18655 * and upper bandwidth KU and with the only the lower
18656 * half stored.
18657 * = 'Q': A is a symmetric band matrix with lower bandwidth KL
18658 * and upper bandwidth KU and with the only the upper
18659 * half stored.
18660 * = 'Z': A is a band matrix with lower bandwidth KL and upper
18661 * bandwidth KU.
18662 *
18663 * KL (input) INTEGER
18664 * The lower bandwidth of A. Referenced only if TYPE = 'B',
18665 * 'Q' or 'Z'.
18666 *
18667 * KU (input) INTEGER
18668 * The upper bandwidth of A. Referenced only if TYPE = 'B',
18669 * 'Q' or 'Z'.
18670 *
18671 * CFROM (input) DOUBLE PRECISION
18672 * CTO (input) DOUBLE PRECISION
18673 * The matrix A is multiplied by CTO/CFROM. A(I,J) is computed
18674 * without over/underflow if the final result CTO*A(I,J)/CFROM
18675 * can be represented without over/underflow. CFROM must be
18676 * nonzero.
18677 *
18678 * M (input) INTEGER
18679 * The number of rows of the matrix A. M >= 0.
18680 *
18681 * N (input) INTEGER
18682 * The number of columns of the matrix A. N >= 0.
18683 *
18684 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
18685 * The matrix to be multiplied by CTO/CFROM. See TYPE for the
18686 * storage type.
18687 *
18688 * LDA (input) INTEGER
18689 * The leading dimension of the array A. LDA >= max(1,M).
18690 *
18691 * INFO (output) INTEGER
18692 * 0 - successful exit
18693 * <0 - if INFO = -i, the i-th argument had an illegal value.
18694 *
18695 * =====================================================================
18696 *
18697 * .. Parameters ..
18698 DOUBLE PRECISION ZERO, ONE
18699 PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
18700 * ..
18701 * .. Local Scalars ..
18702 LOGICAL DONE
18703 INTEGER I, ITYPE, J, K1, K2, K3, K4
18704 DOUBLE PRECISION BIGNUM, CFROM1, CFROMC, CTO1, CTOC, MUL, SMLNUM
18705 * ..
18706 * .. External Functions ..
18707 LOGICAL LSAME, DISNAN
18708 DOUBLE PRECISION DLAMCH
18709 EXTERNAL LSAME, DLAMCH, DISNAN
18710 * ..
18711 * .. Intrinsic Functions ..
18712 INTRINSIC ABS, MAX, MIN
18713 * ..
18714 * .. External Subroutines ..
18715 EXTERNAL XERBLA
18716 * ..
18717 * .. Executable Statements ..
18718 *
18719 * Test the input arguments
18720 *
18721 INFO = 0
18722 *
18723 IF( LSAME( TYPE, 'G' ) ) THEN
18724 ITYPE = 0
18725 ELSE IF( LSAME( TYPE, 'L' ) ) THEN
18726 ITYPE = 1
18727 ELSE IF( LSAME( TYPE, 'U' ) ) THEN
18728 ITYPE = 2
18729 ELSE IF( LSAME( TYPE, 'H' ) ) THEN
18730 ITYPE = 3
18731 ELSE IF( LSAME( TYPE, 'B' ) ) THEN
18732 ITYPE = 4
18733 ELSE IF( LSAME( TYPE, 'Q' ) ) THEN
18734 ITYPE = 5
18735 ELSE IF( LSAME( TYPE, 'Z' ) ) THEN
18736 ITYPE = 6
18737 ELSE
18738 ITYPE = -1
18739 END IF
18740 *
18741 IF( ITYPE.EQ.-1 ) THEN
18742 INFO = -1
18743 ELSE IF( CFROM.EQ.ZERO .OR. DISNAN(CFROM) ) THEN
18744 INFO = -4
18745 ELSE IF( DISNAN(CTO) ) THEN
18746 INFO = -5
18747 ELSE IF( M.LT.0 ) THEN
18748 INFO = -6
18749 ELSE IF( N.LT.0 .OR. ( ITYPE.EQ.4 .AND. N.NE.M ) .OR.
18750 $ ( ITYPE.EQ.5 .AND. N.NE.M ) ) THEN
18751 INFO = -7
18752 ELSE IF( ITYPE.LE.3 .AND. LDA.LT.MAX( 1, M ) ) THEN
18753 INFO = -9
18754 ELSE IF( ITYPE.GE.4 ) THEN
18755 IF( KL.LT.0 .OR. KL.GT.MAX( M-1, 0 ) ) THEN
18756 INFO = -2
18757 ELSE IF( KU.LT.0 .OR. KU.GT.MAX( N-1, 0 ) .OR.
18758 $ ( ( ITYPE.EQ.4 .OR. ITYPE.EQ.5 ) .AND. KL.NE.KU ) )
18759 $ THEN
18760 INFO = -3
18761 ELSE IF( ( ITYPE.EQ.4 .AND. LDA.LT.KL+1 ) .OR.
18762 $ ( ITYPE.EQ.5 .AND. LDA.LT.KU+1 ) .OR.
18763 $ ( ITYPE.EQ.6 .AND. LDA.LT.2*KL+KU+1 ) ) THEN
18764 INFO = -9
18765 END IF
18766 END IF
18767 *
18768 IF( INFO.NE.0 ) THEN
18769 CALL XERBLA( 'DLASCL', -INFO )
18770 RETURN
18771 END IF
18772 *
18773 * Quick return if possible
18774 *
18775 IF( N.EQ.0 .OR. M.EQ.0 )
18776 $ RETURN
18777 *
18778 * Get machine parameters
18779 *
18780 SMLNUM = DLAMCH( 'S' )
18781 BIGNUM = ONE / SMLNUM
18782 *
18783 CFROMC = CFROM
18784 CTOC = CTO
18785 *
18786 10 CONTINUE
18787 CFROM1 = CFROMC*SMLNUM
18788 IF( CFROM1.EQ.CFROMC ) THEN
18789 ! CFROMC is an inf. Multiply by a correctly signed zero for
18790 ! finite CTOC, or a NaN if CTOC is infinite.
18791 MUL = CTOC / CFROMC
18792 DONE = .TRUE.
18793 CTO1 = CTOC
18794 ELSE
18795 CTO1 = CTOC / BIGNUM
18796 IF( CTO1.EQ.CTOC ) THEN
18797 ! CTOC is either 0 or an inf. In both cases, CTOC itself
18798 ! serves as the correct multiplication factor.
18799 MUL = CTOC
18800 DONE = .TRUE.
18801 CFROMC = ONE
18802 ELSE IF( ABS( CFROM1 ).GT.ABS( CTOC ) .AND. CTOC.NE.ZERO ) THEN
18803 MUL = SMLNUM
18804 DONE = .FALSE.
18805 CFROMC = CFROM1
18806 ELSE IF( ABS( CTO1 ).GT.ABS( CFROMC ) ) THEN
18807 MUL = BIGNUM
18808 DONE = .FALSE.
18809 CTOC = CTO1
18810 ELSE
18811 MUL = CTOC / CFROMC
18812 DONE = .TRUE.
18813 END IF
18814 END IF
18815 *
18816 IF( ITYPE.EQ.0 ) THEN
18817 *
18818 * Full matrix
18819 *
18820 DO 30 J = 1, N
18821 DO 20 I = 1, M
18822 A( I, J ) = A( I, J )*MUL
18823 20 CONTINUE
18824 30 CONTINUE
18825 *
18826 ELSE IF( ITYPE.EQ.1 ) THEN
18827 *
18828 * Lower triangular matrix
18829 *
18830 DO 50 J = 1, N
18831 DO 40 I = J, M
18832 A( I, J ) = A( I, J )*MUL
18833 40 CONTINUE
18834 50 CONTINUE
18835 *
18836 ELSE IF( ITYPE.EQ.2 ) THEN
18837 *
18838 * Upper triangular matrix
18839 *
18840 DO 70 J = 1, N
18841 DO 60 I = 1, MIN( J, M )
18842 A( I, J ) = A( I, J )*MUL
18843 60 CONTINUE
18844 70 CONTINUE
18845 *
18846 ELSE IF( ITYPE.EQ.3 ) THEN
18847 *
18848 * Upper Hessenberg matrix
18849 *
18850 DO 90 J = 1, N
18851 DO 80 I = 1, MIN( J+1, M )
18852 A( I, J ) = A( I, J )*MUL
18853 80 CONTINUE
18854 90 CONTINUE
18855 *
18856 ELSE IF( ITYPE.EQ.4 ) THEN
18857 *
18858 * Lower half of a symmetric band matrix
18859 *
18860 K3 = KL + 1
18861 K4 = N + 1
18862 DO 110 J = 1, N
18863 DO 100 I = 1, MIN( K3, K4-J )
18864 A( I, J ) = A( I, J )*MUL
18865 100 CONTINUE
18866 110 CONTINUE
18867 *
18868 ELSE IF( ITYPE.EQ.5 ) THEN
18869 *
18870 * Upper half of a symmetric band matrix
18871 *
18872 K1 = KU + 2
18873 K3 = KU + 1
18874 DO 130 J = 1, N
18875 DO 120 I = MAX( K1-J, 1 ), K3
18876 A( I, J ) = A( I, J )*MUL
18877 120 CONTINUE
18878 130 CONTINUE
18879 *
18880 ELSE IF( ITYPE.EQ.6 ) THEN
18881 *
18882 * Band matrix
18883 *
18884 K1 = KL + KU + 2
18885 K2 = KL + 1
18886 K3 = 2*KL + KU + 1
18887 K4 = KL + KU + 1 + M
18888 DO 150 J = 1, N
18889 DO 140 I = MAX( K1-J, K2 ), MIN( K3, K4-J )
18890 A( I, J ) = A( I, J )*MUL
18891 140 CONTINUE
18892 150 CONTINUE
18893 *
18894 END IF
18895 *
18896 IF( .NOT.DONE )
18897 $ GO TO 10
18898 *
18899 RETURN
18900 *
18901 * End of DLASCL
18902 *
18903 END
18904 C
18905 C-----------------------------------------------------------------------
18906 C-----------------------------------------------------------------------
18907 LOGICAL FUNCTION DISNAN( DIN )
18908 *
18909 * -- LAPACK auxiliary routine (version 3.2.2) --
18910 * -- LAPACK is a software package provided by Univ. of Tennessee, --
18911 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
18912 * June 2010
18913 *
18914 * .. Scalar Arguments ..
18915 DOUBLE PRECISION DIN
18916 * ..
18917 *
18918 * Purpose
18919 * =======
18920 *
18921 * DISNAN returns .TRUE. if its argument is NaN, and .FALSE.
18922 * otherwise. To be replaced by the Fortran 2003 intrinsic in the
18923 * future.
18924 *
18925 * Arguments
18926 * =========
18927 *
18928 * DIN (input) DOUBLE PRECISION
18929 * Input to test for NaN.
18930 *
18931 * =====================================================================
18932 *
18933 * .. External Functions ..
18934 LOGICAL DLAISNAN
18935 EXTERNAL DLAISNAN
18936 * ..
18937 * .. Executable Statements ..
18938 DISNAN = DLAISNAN(DIN,DIN)
18939 RETURN
18940 END
18941 C
18942 C-----------------------------------------------------------------------
18943 C-----------------------------------------------------------------------
18944 LOGICAL FUNCTION DLAISNAN( DIN1, DIN2 )
18945 *
18946 * -- LAPACK auxiliary routine (version 3.2.2) --
18947 * -- LAPACK is a software package provided by Univ. of Tennessee, --
18948 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
18949 * June 2010
18950 *
18951 * .. Scalar Arguments ..
18952 DOUBLE PRECISION DIN1, DIN2
18953 * ..
18954 *
18955 * Purpose
18956 * =======
18957 *
18958 * This routine is not for general use. It exists solely to avoid
18959 * over-optimization in DISNAN.
18960 *
18961 * DLAISNAN checks for NaNs by comparing its two arguments for
18962 * inequality. NaN is the only floating-point value where NaN != NaN
18963 * returns .TRUE. To check for NaNs, pass the same variable as both
18964 * arguments.
18965 *
18966 * A compiler must assume that the two arguments are
18967 * not the same variable, and the test will not be optimized away.
18968 * Interprocedural or whole-program optimization may delete this
18969 * test. The ISNAN functions will be replaced by the correct
18970 * Fortran 03 intrinsic once the intrinsic is widely available.
18971 *
18972 * Arguments
18973 * =========
18974 *
18975 * DIN1 (input) DOUBLE PRECISION
18976 *
18977 * DIN2 (input) DOUBLE PRECISION
18978 * Two numbers to compare for inequality.
18979 *
18980 * =====================================================================
18981 *
18982 * .. Executable Statements ..
18983 DLAISNAN = (DIN1.NE.DIN2)
18984 RETURN
18985 END
18986 C
18987 C-----------------------------------------------------------------------
18988 C-----------------------------------------------------------------------
18989 SUBROUTINE DLASET( UPLO, M, N, ALPHA, BETA, A, LDA )
18990 *
18991 * -- LAPACK auxiliary routine (version 3.2) --
18992 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
18993 * November 2006
18994 *
18995 * .. Scalar Arguments ..
18996 CHARACTER UPLO
18997 INTEGER LDA, M, N
18998 DOUBLE PRECISION ALPHA, BETA
18999 * ..
19000 * .. Array Arguments ..
19001 DOUBLE PRECISION A( LDA, * )
19002 * ..
19003 *
19004 * Purpose
19005 * =======
19006 *
19007 * DLASET initializes an m-by-n matrix A to BETA on the diagonal and
19008 * ALPHA on the offdiagonals.
19009 *
19010 * Arguments
19011 * =========
19012 *
19013 * UPLO (input) CHARACTER*1
19014 * Specifies the part of the matrix A to be set.
19015 * = 'U': Upper triangular part is set; the strictly lower
19016 * triangular part of A is not changed.
19017 * = 'L': Lower triangular part is set; the strictly upper
19018 * triangular part of A is not changed.
19019 * Otherwise: All of the matrix A is set.
19020 *
19021 * M (input) INTEGER
19022 * The number of rows of the matrix A. M >= 0.
19023 *
19024 * N (input) INTEGER
19025 * The number of columns of the matrix A. N >= 0.
19026 *
19027 * ALPHA (input) DOUBLE PRECISION
19028 * The constant to which the offdiagonal elements are to be set.
19029 *
19030 * BETA (input) DOUBLE PRECISION
19031 * The constant to which the diagonal elements are to be set.
19032 *
19033 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
19034 * On exit, the leading m-by-n submatrix of A is set as follows:
19035 *
19036 * if UPLO = 'U', A(i,j) = ALPHA, 1<=i<=j-1, 1<=j<=n,
19037 * if UPLO = 'L', A(i,j) = ALPHA, j+1<=i<=m, 1<=j<=n,
19038 * otherwise, A(i,j) = ALPHA, 1<=i<=m, 1<=j<=n, i.ne.j,
19039 *
19040 * and, for all UPLO, A(i,i) = BETA, 1<=i<=min(m,n).
19041 *
19042 * LDA (input) INTEGER
19043 * The leading dimension of the array A. LDA >= max(1,M).
19044 *
19045 * =====================================================================
19046 *
19047 * .. Local Scalars ..
19048 INTEGER I, J
19049 * ..
19050 * .. External Functions ..
19051 LOGICAL LSAME
19052 EXTERNAL LSAME
19053 * ..
19054 * .. Intrinsic Functions ..
19055 INTRINSIC MIN
19056 * ..
19057 * .. Executable Statements ..
19058 *
19059 IF( LSAME( UPLO, 'U' ) ) THEN
19060 *
19061 * Set the strictly upper triangular or trapezoidal part of the
19062 * array to ALPHA.
19063 *
19064 DO 20 J = 2, N
19065 DO 10 I = 1, MIN( J-1, M )
19066 A( I, J ) = ALPHA
19067 10 CONTINUE
19068 20 CONTINUE
19069 *
19070 ELSE IF( LSAME( UPLO, 'L' ) ) THEN
19071 *
19072 * Set the strictly lower triangular or trapezoidal part of the
19073 * array to ALPHA.
19074 *
19075 DO 40 J = 1, MIN( M, N )
19076 DO 30 I = J + 1, M
19077 A( I, J ) = ALPHA
19078 30 CONTINUE
19079 40 CONTINUE
19080 *
19081 ELSE
19082 *
19083 * Set the leading m-by-n submatrix to ALPHA.
19084 *
19085 DO 60 J = 1, N
19086 DO 50 I = 1, M
19087 A( I, J ) = ALPHA
19088 50 CONTINUE
19089 60 CONTINUE
19090 END IF
19091 *
19092 * Set the first min(M,N) diagonal elements to BETA.
19093 *
19094 DO 70 I = 1, MIN( M, N )
19095 A( I, I ) = BETA
19096 70 CONTINUE
19097 *
19098 RETURN
19099 *
19100 * End of DLASET
19101 *
19102 END
19103 C
19104 C-----------------------------------------------------------------------
19105 C-----------------------------------------------------------------------
19106 SUBROUTINE DLASSQ( N, X, INCX, SCALE, SUMSQ )
19107 *
19108 * -- LAPACK auxiliary routine (version 3.2) --
19109 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
19110 * November 2006
19111 *
19112 * .. Scalar Arguments ..
19113 INTEGER INCX, N
19114 DOUBLE PRECISION SCALE, SUMSQ
19115 * ..
19116 * .. Array Arguments ..
19117 DOUBLE PRECISION X( * )
19118 * ..
19119 *
19120 * Purpose
19121 * =======
19122 *
19123 * DLASSQ returns the values scl and smsq such that
19124 *
19125 * ( scl**2 )*smsq = x( 1 )**2 +...+ x( n )**2 + ( scale**2 )*sumsq,
19126 *
19127 * where x( i ) = X( 1 + ( i - 1 )*INCX ). The value of sumsq is
19128 * assumed to be non-negative and scl returns the value
19129 *
19130 * scl = max( scale, abs( x( i ) ) ).
19131 *
19132 * scale and sumsq must be supplied in SCALE and SUMSQ and
19133 * scl and smsq are overwritten on SCALE and SUMSQ respectively.
19134 *
19135 * The routine makes only one pass through the vector x.
19136 *
19137 * Arguments
19138 * =========
19139 *
19140 * N (input) INTEGER
19141 * The number of elements to be used from the vector X.
19142 *
19143 * X (input) DOUBLE PRECISION array, dimension (N)
19144 * The vector for which a scaled sum of squares is computed.
19145 * x( i ) = X( 1 + ( i - 1 )*INCX ), 1 <= i <= n.
19146 *
19147 * INCX (input) INTEGER
19148 * The increment between successive values of the vector X.
19149 * INCX > 0.
19150 *
19151 * SCALE (input/output) DOUBLE PRECISION
19152 * On entry, the value scale in the equation above.
19153 * On exit, SCALE is overwritten with scl , the scaling factor
19154 * for the sum of squares.
19155 *
19156 * SUMSQ (input/output) DOUBLE PRECISION
19157 * On entry, the value sumsq in the equation above.
19158 * On exit, SUMSQ is overwritten with smsq , the basic sum of
19159 * squares from which scl has been factored out.
19160 *
19161 * =====================================================================
19162 *
19163 * .. Parameters ..
19164 DOUBLE PRECISION ZERO
19165 PARAMETER ( ZERO = 0.0D+0 )
19166 * ..
19167 * .. Local Scalars ..
19168 INTEGER IX
19169 DOUBLE PRECISION ABSXI
19170 * ..
19171 * .. Intrinsic Functions ..
19172 INTRINSIC ABS
19173 * ..
19174 * .. Executable Statements ..
19175 *
19176 IF( N.GT.0 ) THEN
19177 DO 10 IX = 1, 1 + ( N-1 )*INCX, INCX
19178 IF( X( IX ).NE.ZERO ) THEN
19179 ABSXI = ABS( X( IX ) )
19180 IF( SCALE.LT.ABSXI ) THEN
19181 SUMSQ = 1 + SUMSQ*( SCALE / ABSXI )**2
19182 SCALE = ABSXI
19183 ELSE
19184 SUMSQ = SUMSQ + ( ABSXI / SCALE )**2
19185 END IF
19186 END IF
19187 10 CONTINUE
19188 END IF
19189 RETURN
19190 *
19191 * End of DLASSQ
19192 *
19193 END
19194 C
19195 C-----------------------------------------------------------------------
19196 C-----------------------------------------------------------------------
19197 SUBROUTINE DLASY2( LTRANL, LTRANR, ISGN, N1, N2, TL, LDTL, TR,
19198 $ LDTR, B, LDB, SCALE, X, LDX, XNORM, INFO )
19199 *
19200 * -- LAPACK auxiliary routine (version 3.2) --
19201 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
19202 * November 2006
19203 *
19204 * .. Scalar Arguments ..
19205 LOGICAL LTRANL, LTRANR
19206 INTEGER INFO, ISGN, LDB, LDTL, LDTR, LDX, N1, N2
19207 DOUBLE PRECISION SCALE, XNORM
19208 * ..
19209 * .. Array Arguments ..
19210 DOUBLE PRECISION B( LDB, * ), TL( LDTL, * ), TR( LDTR, * ),
19211 $ X( LDX, * )
19212 * ..
19213 *
19214 * Purpose
19215 * =======
19216 *
19217 * DLASY2 solves for the N1 by N2 matrix X, 1 <= N1,N2 <= 2, in
19218 *
19219 * op(TL)*X + ISGN*X*op(TR) = SCALE*B,
19220 *
19221 * where TL is N1 by N1, TR is N2 by N2, B is N1 by N2, and ISGN = 1 or
19222 * -1. op(T) = T or T', where T' denotes the transpose of T.
19223 *
19224 * Arguments
19225 * =========
19226 *
19227 * LTRANL (input) LOGICAL
19228 * On entry, LTRANL specifies the op(TL):
19229 * = .FALSE., op(TL) = TL,
19230 * = .TRUE., op(TL) = TL'.
19231 *
19232 * LTRANR (input) LOGICAL
19233 * On entry, LTRANR specifies the op(TR):
19234 * = .FALSE., op(TR) = TR,
19235 * = .TRUE., op(TR) = TR'.
19236 *
19237 * ISGN (input) INTEGER
19238 * On entry, ISGN specifies the sign of the equation
19239 * as described before. ISGN may only be 1 or -1.
19240 *
19241 * N1 (input) INTEGER
19242 * On entry, N1 specifies the order of matrix TL.
19243 * N1 may only be 0, 1 or 2.
19244 *
19245 * N2 (input) INTEGER
19246 * On entry, N2 specifies the order of matrix TR.
19247 * N2 may only be 0, 1 or 2.
19248 *
19249 * TL (input) DOUBLE PRECISION array, dimension (LDTL,2)
19250 * On entry, TL contains an N1 by N1 matrix.
19251 *
19252 * LDTL (input) INTEGER
19253 * The leading dimension of the matrix TL. LDTL >= max(1,N1).
19254 *
19255 * TR (input) DOUBLE PRECISION array, dimension (LDTR,2)
19256 * On entry, TR contains an N2 by N2 matrix.
19257 *
19258 * LDTR (input) INTEGER
19259 * The leading dimension of the matrix TR. LDTR >= max(1,N2).
19260 *
19261 * B (input) DOUBLE PRECISION array, dimension (LDB,2)
19262 * On entry, the N1 by N2 matrix B contains the right-hand
19263 * side of the equation.
19264 *
19265 * LDB (input) INTEGER
19266 * The leading dimension of the matrix B. LDB >= max(1,N1).
19267 *
19268 * SCALE (output) DOUBLE PRECISION
19269 * On exit, SCALE contains the scale factor. SCALE is chosen
19270 * less than or equal to 1 to prevent the solution overflowing.
19271 *
19272 * X (output) DOUBLE PRECISION array, dimension (LDX,2)
19273 * On exit, X contains the N1 by N2 solution.
19274 *
19275 * LDX (input) INTEGER
19276 * The leading dimension of the matrix X. LDX >= max(1,N1).
19277 *
19278 * XNORM (output) DOUBLE PRECISION
19279 * On exit, XNORM is the infinity-norm of the solution.
19280 *
19281 * INFO (output) INTEGER
19282 * On exit, INFO is set to
19283 * 0: successful exit.
19284 * 1: TL and TR have too close eigenvalues, so TL or
19285 * TR is perturbed to get a nonsingular equation.
19286 * NOTE: In the interests of speed, this routine does not
19287 * check the inputs for errors.
19288 *
19289 * =====================================================================
19290 *
19291 * .. Parameters ..
19292 DOUBLE PRECISION ZERO, ONE
19293 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
19294 DOUBLE PRECISION TWO, HALF, EIGHT
19295 PARAMETER ( TWO = 2.0D+0, HALF = 0.5D+0, EIGHT = 8.0D+0 )
19296 * ..
19297 * .. Local Scalars ..
19298 LOGICAL BSWAP, XSWAP
19299 INTEGER I, IP, IPIV, IPSV, J, JP, JPSV, K
19300 DOUBLE PRECISION BET, EPS, GAM, L21, SGN, SMIN, SMLNUM, TAU1,
19301 $ TEMP, U11, U12, U22, XMAX
19302 * ..
19303 * .. Local Arrays ..
19304 LOGICAL BSWPIV( 4 ), XSWPIV( 4 )
19305 INTEGER JPIV( 4 ), LOCL21( 4 ), LOCU12( 4 ),
19306 $ LOCU22( 4 )
19307 DOUBLE PRECISION BTMP( 4 ), T16( 4, 4 ), TMP( 4 ), X2( 2 )
19308 * ..
19309 * .. External Functions ..
19310 INTEGER IDAMAX
19311 DOUBLE PRECISION DLAMCH
19312 EXTERNAL IDAMAX, DLAMCH
19313 * ..
19314 * .. External Subroutines ..
19315 EXTERNAL DCOPY, DSWAP
19316 * ..
19317 * .. Intrinsic Functions ..
19318 INTRINSIC ABS, MAX
19319 * ..
19320 * .. Data statements ..
19321 DATA LOCU12 / 3, 4, 1, 2 / , LOCL21 / 2, 1, 4, 3 / ,
19322 $ LOCU22 / 4, 3, 2, 1 /
19323 DATA XSWPIV / .FALSE., .FALSE., .TRUE., .TRUE. /
19324 DATA BSWPIV / .FALSE., .TRUE., .FALSE., .TRUE. /
19325 * ..
19326 * .. Executable Statements ..
19327 *
19328 * Do not check the input parameters for errors
19329 *
19330 INFO = 0
19331 *
19332 * Quick return if possible
19333 *
19334 IF( N1.EQ.0 .OR. N2.EQ.0 )
19335 $ RETURN
19336 *
19337 * Set constants to control overflow
19338 *
19339 EPS = DLAMCH( 'P' )
19340 SMLNUM = DLAMCH( 'S' ) / EPS
19341 SGN = ISGN
19342 *
19343 K = N1 + N1 + N2 - 2
19344 GO TO ( 10, 20, 30, 50 )K
19345 *
19346 * 1 by 1: TL11*X + SGN*X*TR11 = B11
19347 *
19348 10 CONTINUE
19349 TAU1 = TL( 1, 1 ) + SGN*TR( 1, 1 )
19350 BET = ABS( TAU1 )
19351 IF( BET.LE.SMLNUM ) THEN
19352 TAU1 = SMLNUM
19353 BET = SMLNUM
19354 INFO = 1
19355 END IF
19356 *
19357 SCALE = ONE
19358 GAM = ABS( B( 1, 1 ) )
19359 IF( SMLNUM*GAM.GT.BET )
19360 $ SCALE = ONE / GAM
19361 *
19362 X( 1, 1 ) = ( B( 1, 1 )*SCALE ) / TAU1
19363 XNORM = ABS( X( 1, 1 ) )
19364 RETURN
19365 *
19366 * 1 by 2:
19367 * TL11*[X11 X12] + ISGN*[X11 X12]*op[TR11 TR12] = [B11 B12]
19368 * [TR21 TR22]
19369 *
19370 20 CONTINUE
19371 *
19372 SMIN = MAX( EPS*MAX( ABS( TL( 1, 1 ) ), ABS( TR( 1, 1 ) ),
19373 $ ABS( TR( 1, 2 ) ), ABS( TR( 2, 1 ) ), ABS( TR( 2, 2 ) ) ),
19374 $ SMLNUM )
19375 TMP( 1 ) = TL( 1, 1 ) + SGN*TR( 1, 1 )
19376 TMP( 4 ) = TL( 1, 1 ) + SGN*TR( 2, 2 )
19377 IF( LTRANR ) THEN
19378 TMP( 2 ) = SGN*TR( 2, 1 )
19379 TMP( 3 ) = SGN*TR( 1, 2 )
19380 ELSE
19381 TMP( 2 ) = SGN*TR( 1, 2 )
19382 TMP( 3 ) = SGN*TR( 2, 1 )
19383 END IF
19384 BTMP( 1 ) = B( 1, 1 )
19385 BTMP( 2 ) = B( 1, 2 )
19386 GO TO 40
19387 *
19388 * 2 by 1:
19389 * op[TL11 TL12]*[X11] + ISGN* [X11]*TR11 = [B11]
19390 * [TL21 TL22] [X21] [X21] [B21]
19391 *
19392 30 CONTINUE
19393 SMIN = MAX( EPS*MAX( ABS( TR( 1, 1 ) ), ABS( TL( 1, 1 ) ),
19394 $ ABS( TL( 1, 2 ) ), ABS( TL( 2, 1 ) ), ABS( TL( 2, 2 ) ) ),
19395 $ SMLNUM )
19396 TMP( 1 ) = TL( 1, 1 ) + SGN*TR( 1, 1 )
19397 TMP( 4 ) = TL( 2, 2 ) + SGN*TR( 1, 1 )
19398 IF( LTRANL ) THEN
19399 TMP( 2 ) = TL( 1, 2 )
19400 TMP( 3 ) = TL( 2, 1 )
19401 ELSE
19402 TMP( 2 ) = TL( 2, 1 )
19403 TMP( 3 ) = TL( 1, 2 )
19404 END IF
19405 BTMP( 1 ) = B( 1, 1 )
19406 BTMP( 2 ) = B( 2, 1 )
19407 40 CONTINUE
19408 *
19409 * Solve 2 by 2 system using complete pivoting.
19410 * Set pivots less than SMIN to SMIN.
19411 *
19412 IPIV = IDAMAX( 4, TMP, 1 )
19413 U11 = TMP( IPIV )
19414 IF( ABS( U11 ).LE.SMIN ) THEN
19415 INFO = 1
19416 U11 = SMIN
19417 END IF
19418 U12 = TMP( LOCU12( IPIV ) )
19419 L21 = TMP( LOCL21( IPIV ) ) / U11
19420 U22 = TMP( LOCU22( IPIV ) ) - U12*L21
19421 XSWAP = XSWPIV( IPIV )
19422 BSWAP = BSWPIV( IPIV )
19423 IF( ABS( U22 ).LE.SMIN ) THEN
19424 INFO = 1
19425 U22 = SMIN
19426 END IF
19427 IF( BSWAP ) THEN
19428 TEMP = BTMP( 2 )
19429 BTMP( 2 ) = BTMP( 1 ) - L21*TEMP
19430 BTMP( 1 ) = TEMP
19431 ELSE
19432 BTMP( 2 ) = BTMP( 2 ) - L21*BTMP( 1 )
19433 END IF
19434 SCALE = ONE
19435 IF( ( TWO*SMLNUM )*ABS( BTMP( 2 ) ).GT.ABS( U22 ) .OR.
19436 $ ( TWO*SMLNUM )*ABS( BTMP( 1 ) ).GT.ABS( U11 ) ) THEN
19437 SCALE = HALF / MAX( ABS( BTMP( 1 ) ), ABS( BTMP( 2 ) ) )
19438 BTMP( 1 ) = BTMP( 1 )*SCALE
19439 BTMP( 2 ) = BTMP( 2 )*SCALE
19440 END IF
19441 X2( 2 ) = BTMP( 2 ) / U22
19442 X2( 1 ) = BTMP( 1 ) / U11 - ( U12 / U11 )*X2( 2 )
19443 IF( XSWAP ) THEN
19444 TEMP = X2( 2 )
19445 X2( 2 ) = X2( 1 )
19446 X2( 1 ) = TEMP
19447 END IF
19448 X( 1, 1 ) = X2( 1 )
19449 IF( N1.EQ.1 ) THEN
19450 X( 1, 2 ) = X2( 2 )
19451 XNORM = ABS( X( 1, 1 ) ) + ABS( X( 1, 2 ) )
19452 ELSE
19453 X( 2, 1 ) = X2( 2 )
19454 XNORM = MAX( ABS( X( 1, 1 ) ), ABS( X( 2, 1 ) ) )
19455 END IF
19456 RETURN
19457 *
19458 * 2 by 2:
19459 * op[TL11 TL12]*[X11 X12] +ISGN* [X11 X12]*op[TR11 TR12] = [B11 B12]
19460 * [TL21 TL22] [X21 X22] [X21 X22] [TR21 TR22] [B21 B22]
19461 *
19462 * Solve equivalent 4 by 4 system using complete pivoting.
19463 * Set pivots less than SMIN to SMIN.
19464 *
19465 50 CONTINUE
19466 SMIN = MAX( ABS( TR( 1, 1 ) ), ABS( TR( 1, 2 ) ),
19467 $ ABS( TR( 2, 1 ) ), ABS( TR( 2, 2 ) ) )
19468 SMIN = MAX( SMIN, ABS( TL( 1, 1 ) ), ABS( TL( 1, 2 ) ),
19469 $ ABS( TL( 2, 1 ) ), ABS( TL( 2, 2 ) ) )
19470 SMIN = MAX( EPS*SMIN, SMLNUM )
19471 BTMP( 1 ) = ZERO
19472 CALL DCOPY( 16, BTMP, 0, T16, 1 )
19473 T16( 1, 1 ) = TL( 1, 1 ) + SGN*TR( 1, 1 )
19474 T16( 2, 2 ) = TL( 2, 2 ) + SGN*TR( 1, 1 )
19475 T16( 3, 3 ) = TL( 1, 1 ) + SGN*TR( 2, 2 )
19476 T16( 4, 4 ) = TL( 2, 2 ) + SGN*TR( 2, 2 )
19477 IF( LTRANL ) THEN
19478 T16( 1, 2 ) = TL( 2, 1 )
19479 T16( 2, 1 ) = TL( 1, 2 )
19480 T16( 3, 4 ) = TL( 2, 1 )
19481 T16( 4, 3 ) = TL( 1, 2 )
19482 ELSE
19483 T16( 1, 2 ) = TL( 1, 2 )
19484 T16( 2, 1 ) = TL( 2, 1 )
19485 T16( 3, 4 ) = TL( 1, 2 )
19486 T16( 4, 3 ) = TL( 2, 1 )
19487 END IF
19488 IF( LTRANR ) THEN
19489 T16( 1, 3 ) = SGN*TR( 1, 2 )
19490 T16( 2, 4 ) = SGN*TR( 1, 2 )
19491 T16( 3, 1 ) = SGN*TR( 2, 1 )
19492 T16( 4, 2 ) = SGN*TR( 2, 1 )
19493 ELSE
19494 T16( 1, 3 ) = SGN*TR( 2, 1 )
19495 T16( 2, 4 ) = SGN*TR( 2, 1 )
19496 T16( 3, 1 ) = SGN*TR( 1, 2 )
19497 T16( 4, 2 ) = SGN*TR( 1, 2 )
19498 END IF
19499 BTMP( 1 ) = B( 1, 1 )
19500 BTMP( 2 ) = B( 2, 1 )
19501 BTMP( 3 ) = B( 1, 2 )
19502 BTMP( 4 ) = B( 2, 2 )
19503 *
19504 * Perform elimination
19505 *
19506 DO 100 I = 1, 3
19507 XMAX = ZERO
19508 DO 70 IP = I, 4
19509 DO 60 JP = I, 4
19510 IF( ABS( T16( IP, JP ) ).GE.XMAX ) THEN
19511 XMAX = ABS( T16( IP, JP ) )
19512 IPSV = IP
19513 JPSV = JP
19514 END IF
19515 60 CONTINUE
19516 70 CONTINUE
19517 IF( IPSV.NE.I ) THEN
19518 CALL DSWAP( 4, T16( IPSV, 1 ), 4, T16( I, 1 ), 4 )
19519 TEMP = BTMP( I )
19520 BTMP( I ) = BTMP( IPSV )
19521 BTMP( IPSV ) = TEMP
19522 END IF
19523 IF( JPSV.NE.I )
19524 $ CALL DSWAP( 4, T16( 1, JPSV ), 1, T16( 1, I ), 1 )
19525 JPIV( I ) = JPSV
19526 IF( ABS( T16( I, I ) ).LT.SMIN ) THEN
19527 INFO = 1
19528 T16( I, I ) = SMIN
19529 END IF
19530 DO 90 J = I + 1, 4
19531 T16( J, I ) = T16( J, I ) / T16( I, I )
19532 BTMP( J ) = BTMP( J ) - T16( J, I )*BTMP( I )
19533 DO 80 K = I + 1, 4
19534 T16( J, K ) = T16( J, K ) - T16( J, I )*T16( I, K )
19535 80 CONTINUE
19536 90 CONTINUE
19537 100 CONTINUE
19538 IF( ABS( T16( 4, 4 ) ).LT.SMIN )
19539 $ T16( 4, 4 ) = SMIN
19540 SCALE = ONE
19541 IF( ( EIGHT*SMLNUM )*ABS( BTMP( 1 ) ).GT.ABS( T16( 1, 1 ) ) .OR.
19542 $ ( EIGHT*SMLNUM )*ABS( BTMP( 2 ) ).GT.ABS( T16( 2, 2 ) ) .OR.
19543 $ ( EIGHT*SMLNUM )*ABS( BTMP( 3 ) ).GT.ABS( T16( 3, 3 ) ) .OR.
19544 $ ( EIGHT*SMLNUM )*ABS( BTMP( 4 ) ).GT.ABS( T16( 4, 4 ) ) ) THEN
19545 SCALE = ( ONE / EIGHT ) / MAX( ABS( BTMP( 1 ) ),
19546 $ ABS( BTMP( 2 ) ), ABS( BTMP( 3 ) ), ABS( BTMP( 4 ) ) )
19547 BTMP( 1 ) = BTMP( 1 )*SCALE
19548 BTMP( 2 ) = BTMP( 2 )*SCALE
19549 BTMP( 3 ) = BTMP( 3 )*SCALE
19550 BTMP( 4 ) = BTMP( 4 )*SCALE
19551 END IF
19552 DO 120 I = 1, 4
19553 K = 5 - I
19554 TEMP = ONE / T16( K, K )
19555 TMP( K ) = BTMP( K )*TEMP
19556 DO 110 J = K + 1, 4
19557 TMP( K ) = TMP( K ) - ( TEMP*T16( K, J ) )*TMP( J )
19558 110 CONTINUE
19559 120 CONTINUE
19560 DO 130 I = 1, 3
19561 IF( JPIV( 4-I ).NE.4-I ) THEN
19562 TEMP = TMP( 4-I )
19563 TMP( 4-I ) = TMP( JPIV( 4-I ) )
19564 TMP( JPIV( 4-I ) ) = TEMP
19565 END IF
19566 130 CONTINUE
19567 X( 1, 1 ) = TMP( 1 )
19568 X( 2, 1 ) = TMP( 2 )
19569 X( 1, 2 ) = TMP( 3 )
19570 X( 2, 2 ) = TMP( 4 )
19571 XNORM = MAX( ABS( TMP( 1 ) )+ABS( TMP( 3 ) ),
19572 $ ABS( TMP( 2 ) )+ABS( TMP( 4 ) ) )
19573 RETURN
19574 *
19575 * End of DLASY2
19576 *
19577 END
19578 C
19579 C-----------------------------------------------------------------------
19580 C-----------------------------------------------------------------------
19581 SUBROUTINE DORG2R( M, N, K, A, LDA, TAU, WORK, INFO )
19582 *
19583 * -- LAPACK routine (version 3.2) --
19584 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
19585 * November 2006
19586 *
19587 * .. Scalar Arguments ..
19588 INTEGER INFO, K, LDA, M, N
19589 * ..
19590 * .. Array Arguments ..
19591 DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
19592 * ..
19593 *
19594 * Purpose
19595 * =======
19596 *
19597 * DORG2R generates an m by n real matrix Q with orthonormal columns,
19598 * which is defined as the first n columns of a product of k elementary
19599 * reflectors of order m
19600 *
19601 * Q = H(1) H(2) . . . H(k)
19602 *
19603 * as returned by DGEQRF.
19604 *
19605 * Arguments
19606 * =========
19607 *
19608 * M (input) INTEGER
19609 * The number of rows of the matrix Q. M >= 0.
19610 *
19611 * N (input) INTEGER
19612 * The number of columns of the matrix Q. M >= N >= 0.
19613 *
19614 * K (input) INTEGER
19615 * The number of elementary reflectors whose product defines the
19616 * matrix Q. N >= K >= 0.
19617 *
19618 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
19619 * On entry, the i-th column must contain the vector which
19620 * defines the elementary reflector H(i), for i = 1,2,...,k, as
19621 * returned by DGEQRF in the first k columns of its array
19622 * argument A.
19623 * On exit, the m-by-n matrix Q.
19624 *
19625 * LDA (input) INTEGER
19626 * The first dimension of the array A. LDA >= max(1,M).
19627 *
19628 * TAU (input) DOUBLE PRECISION array, dimension (K)
19629 * TAU(i) must contain the scalar factor of the elementary
19630 * reflector H(i), as returned by DGEQRF.
19631 *
19632 * WORK (workspace) DOUBLE PRECISION array, dimension (N)
19633 *
19634 * INFO (output) INTEGER
19635 * = 0: successful exit
19636 * < 0: if INFO = -i, the i-th argument has an illegal value
19637 *
19638 * =====================================================================
19639 *
19640 * .. Parameters ..
19641 DOUBLE PRECISION ONE, ZERO
19642 PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
19643 * ..
19644 * .. Local Scalars ..
19645 INTEGER I, J, L
19646 * ..
19647 * .. External Subroutines ..
19648 EXTERNAL DLARF, DSCAL, XERBLA
19649 * ..
19650 * .. Intrinsic Functions ..
19651 INTRINSIC MAX
19652 * ..
19653 * .. Executable Statements ..
19654 *
19655 * Test the input arguments
19656 *
19657 INFO = 0
19658 IF( M.LT.0 ) THEN
19659 INFO = -1
19660 ELSE IF( N.LT.0 .OR. N.GT.M ) THEN
19661 INFO = -2
19662 ELSE IF( K.LT.0 .OR. K.GT.N ) THEN
19663 INFO = -3
19664 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
19665 INFO = -5
19666 END IF
19667 IF( INFO.NE.0 ) THEN
19668 CALL XERBLA( 'DORG2R', -INFO )
19669 RETURN
19670 END IF
19671 *
19672 * Quick return if possible
19673 *
19674 IF( N.LE.0 )
19675 $ RETURN
19676 *
19677 * Initialise columns k+1:n to columns of the unit matrix
19678 *
19679 DO 20 J = K + 1, N
19680 DO 10 L = 1, M
19681 A( L, J ) = ZERO
19682 10 CONTINUE
19683 A( J, J ) = ONE
19684 20 CONTINUE
19685 *
19686 DO 40 I = K, 1, -1
19687 *
19688 * Apply H(i) to A(i:m,i:n) from the left
19689 *
19690 IF( I.LT.N ) THEN
19691 A( I, I ) = ONE
19692 CALL DLARF( 'Left', M-I+1, N-I, A( I, I ), 1, TAU( I ),
19693 $ A( I, I+1 ), LDA, WORK )
19694 END IF
19695 IF( I.LT.M )
19696 $ CALL DSCAL( M-I, -TAU( I ), A( I+1, I ), 1 )
19697 A( I, I ) = ONE - TAU( I )
19698 *
19699 * Set A(1:i-1,i) to zero
19700 *
19701 DO 30 L = 1, I - 1
19702 A( L, I ) = ZERO
19703 30 CONTINUE
19704 40 CONTINUE
19705 RETURN
19706 *
19707 * End of DORG2R
19708 *
19709 END
19710 C
19711 C-----------------------------------------------------------------------
19712 C-----------------------------------------------------------------------
19713 SUBROUTINE DORGHR( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO )
19714 *
19715 * -- LAPACK routine (version 3.2) --
19716 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
19717 * November 2006
19718 *
19719 * .. Scalar Arguments ..
19720 INTEGER IHI, ILO, INFO, LDA, LWORK, N
19721 * ..
19722 * .. Array Arguments ..
19723 DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
19724 * ..
19725 *
19726 * Purpose
19727 * =======
19728 *
19729 * DORGHR generates a real orthogonal matrix Q which is defined as the
19730 * product of IHI-ILO elementary reflectors of order N, as returned by
19731 * DGEHRD:
19732 *
19733 * Q = H(ilo) H(ilo+1) . . . H(ihi-1).
19734 *
19735 * Arguments
19736 * =========
19737 *
19738 * N (input) INTEGER
19739 * The order of the matrix Q. N >= 0.
19740 *
19741 * ILO (input) INTEGER
19742 * IHI (input) INTEGER
19743 * ILO and IHI must have the same values as in the previous call
19744 * of DGEHRD. Q is equal to the unit matrix except in the
19745 * submatrix Q(ilo+1:ihi,ilo+1:ihi).
19746 * 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
19747 *
19748 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
19749 * On entry, the vectors which define the elementary reflectors,
19750 * as returned by DGEHRD.
19751 * On exit, the N-by-N orthogonal matrix Q.
19752 *
19753 * LDA (input) INTEGER
19754 * The leading dimension of the array A. LDA >= max(1,N).
19755 *
19756 * TAU (input) DOUBLE PRECISION array, dimension (N-1)
19757 * TAU(i) must contain the scalar factor of the elementary
19758 * reflector H(i), as returned by DGEHRD.
19759 *
19760 * WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
19761 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
19762 *
19763 * LWORK (input) INTEGER
19764 * The dimension of the array WORK. LWORK >= IHI-ILO.
19765 * For optimum performance LWORK >= (IHI-ILO)*NB, where NB is
19766 * the optimal blocksize.
19767 *
19768 * If LWORK = -1, then a workspace query is assumed; the routine
19769 * only calculates the optimal size of the WORK array, returns
19770 * this value as the first entry of the WORK array, and no error
19771 * message related to LWORK is issued by XERBLA.
19772 *
19773 * INFO (output) INTEGER
19774 * = 0: successful exit
19775 * < 0: if INFO = -i, the i-th argument had an illegal value
19776 *
19777 * =====================================================================
19778 *
19779 * .. Parameters ..
19780 DOUBLE PRECISION ZERO, ONE
19781 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
19782 * ..
19783 * .. Local Scalars ..
19784 LOGICAL LQUERY
19785 INTEGER I, IINFO, J, LWKOPT, NB, NH
19786 * ..
19787 * .. External Subroutines ..
19788 EXTERNAL DORGQR, XERBLA
19789 * ..
19790 * .. External Functions ..
19791 INTEGER ILAENV
19792 EXTERNAL ILAENV
19793 * ..
19794 * .. Intrinsic Functions ..
19795 INTRINSIC MAX, MIN
19796 * ..
19797 * .. Executable Statements ..
19798 *
19799 * Test the input arguments
19800 *
19801 INFO = 0
19802 NH = IHI - ILO
19803 LQUERY = ( LWORK.EQ.-1 )
19804 IF( N.LT.0 ) THEN
19805 INFO = -1
19806 ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN
19807 INFO = -2
19808 ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN
19809 INFO = -3
19810 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
19811 INFO = -5
19812 ELSE IF( LWORK.LT.MAX( 1, NH ) .AND. .NOT.LQUERY ) THEN
19813 INFO = -8
19814 END IF
19815 *
19816 IF( INFO.EQ.0 ) THEN
19817 NB = ILAENV( 1, 'DORGQR', ' ', NH, NH, NH, -1 )
19818 LWKOPT = MAX( 1, NH )*NB
19819 WORK( 1 ) = LWKOPT
19820 END IF
19821 *
19822 IF( INFO.NE.0 ) THEN
19823 CALL XERBLA( 'DORGHR', -INFO )
19824 RETURN
19825 ELSE IF( LQUERY ) THEN
19826 RETURN
19827 END IF
19828 *
19829 * Quick return if possible
19830 *
19831 IF( N.EQ.0 ) THEN
19832 WORK( 1 ) = 1
19833 RETURN
19834 END IF
19835 *
19836 * Shift the vectors which define the elementary reflectors one
19837 * column to the right, and set the first ilo and the last n-ihi
19838 * rows and columns to those of the unit matrix
19839 *
19840 DO 40 J = IHI, ILO + 1, -1
19841 DO 10 I = 1, J - 1
19842 A( I, J ) = ZERO
19843 10 CONTINUE
19844 DO 20 I = J + 1, IHI
19845 A( I, J ) = A( I, J-1 )
19846 20 CONTINUE
19847 DO 30 I = IHI + 1, N
19848 A( I, J ) = ZERO
19849 30 CONTINUE
19850 40 CONTINUE
19851 DO 60 J = 1, ILO
19852 DO 50 I = 1, N
19853 A( I, J ) = ZERO
19854 50 CONTINUE
19855 A( J, J ) = ONE
19856 60 CONTINUE
19857 DO 80 J = IHI + 1, N
19858 DO 70 I = 1, N
19859 A( I, J ) = ZERO
19860 70 CONTINUE
19861 A( J, J ) = ONE
19862 80 CONTINUE
19863 *
19864 IF( NH.GT.0 ) THEN
19865 *
19866 * Generate Q(ilo+1:ihi,ilo+1:ihi)
19867 *
19868 CALL DORGQR( NH, NH, NH, A( ILO+1, ILO+1 ), LDA, TAU( ILO ),
19869 $ WORK, LWORK, IINFO )
19870 END IF
19871 WORK( 1 ) = LWKOPT
19872 RETURN
19873 *
19874 * End of DORGHR
19875 *
19876 END
19877 C
19878 C-----------------------------------------------------------------------
19879 C-----------------------------------------------------------------------
19880 SUBROUTINE DORGQR( M, N, K, A, LDA, TAU, WORK, LWORK, INFO )
19881 *
19882 * -- LAPACK routine (version 3.2) --
19883 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
19884 * November 2006
19885 *
19886 * .. Scalar Arguments ..
19887 INTEGER INFO, K, LDA, LWORK, M, N
19888 * ..
19889 * .. Array Arguments ..
19890 DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
19891 * ..
19892 *
19893 * Purpose
19894 * =======
19895 *
19896 * DORGQR generates an M-by-N real matrix Q with orthonormal columns,
19897 * which is defined as the first N columns of a product of K elementary
19898 * reflectors of order M
19899 *
19900 * Q = H(1) H(2) . . . H(k)
19901 *
19902 * as returned by DGEQRF.
19903 *
19904 * Arguments
19905 * =========
19906 *
19907 * M (input) INTEGER
19908 * The number of rows of the matrix Q. M >= 0.
19909 *
19910 * N (input) INTEGER
19911 * The number of columns of the matrix Q. M >= N >= 0.
19912 *
19913 * K (input) INTEGER
19914 * The number of elementary reflectors whose product defines the
19915 * matrix Q. N >= K >= 0.
19916 *
19917 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
19918 * On entry, the i-th column must contain the vector which
19919 * defines the elementary reflector H(i), for i = 1,2,...,k, as
19920 * returned by DGEQRF in the first k columns of its array
19921 * argument A.
19922 * On exit, the M-by-N matrix Q.
19923 *
19924 * LDA (input) INTEGER
19925 * The first dimension of the array A. LDA >= max(1,M).
19926 *
19927 * TAU (input) DOUBLE PRECISION array, dimension (K)
19928 * TAU(i) must contain the scalar factor of the elementary
19929 * reflector H(i), as returned by DGEQRF.
19930 *
19931 * WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
19932 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
19933 *
19934 * LWORK (input) INTEGER
19935 * The dimension of the array WORK. LWORK >= max(1,N).
19936 * For optimum performance LWORK >= N*NB, where NB is the
19937 * optimal blocksize.
19938 *
19939 * If LWORK = -1, then a workspace query is assumed; the routine
19940 * only calculates the optimal size of the WORK array, returns
19941 * this value as the first entry of the WORK array, and no error
19942 * message related to LWORK is issued by XERBLA.
19943 *
19944 * INFO (output) INTEGER
19945 * = 0: successful exit
19946 * < 0: if INFO = -i, the i-th argument has an illegal value
19947 *
19948 * =====================================================================
19949 *
19950 * .. Parameters ..
19951 DOUBLE PRECISION ZERO
19952 PARAMETER ( ZERO = 0.0D+0 )
19953 * ..
19954 * .. Local Scalars ..
19955 LOGICAL LQUERY
19956 INTEGER I, IB, IINFO, IWS, J, KI, KK, L, LDWORK,
19957 $ LWKOPT, NB, NBMIN, NX
19958 * ..
19959 * .. External Subroutines ..
19960 EXTERNAL DLARFB, DLARFT, DORG2R, XERBLA
19961 * ..
19962 * .. Intrinsic Functions ..
19963 INTRINSIC MAX, MIN
19964 * ..
19965 * .. External Functions ..
19966 INTEGER ILAENV
19967 EXTERNAL ILAENV
19968 * ..
19969 * .. Executable Statements ..
19970 *
19971 * Test the input arguments
19972 *
19973 INFO = 0
19974 NB = ILAENV( 1, 'DORGQR', ' ', M, N, K, -1 )
19975 LWKOPT = MAX( 1, N )*NB
19976 WORK( 1 ) = LWKOPT
19977 LQUERY = ( LWORK.EQ.-1 )
19978 IF( M.LT.0 ) THEN
19979 INFO = -1
19980 ELSE IF( N.LT.0 .OR. N.GT.M ) THEN
19981 INFO = -2
19982 ELSE IF( K.LT.0 .OR. K.GT.N ) THEN
19983 INFO = -3
19984 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
19985 INFO = -5
19986 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
19987 INFO = -8
19988 END IF
19989 IF( INFO.NE.0 ) THEN
19990 CALL XERBLA( 'DORGQR', -INFO )
19991 RETURN
19992 ELSE IF( LQUERY ) THEN
19993 RETURN
19994 END IF
19995 *
19996 * Quick return if possible
19997 *
19998 IF( N.LE.0 ) THEN
19999 WORK( 1 ) = 1
20000 RETURN
20001 END IF
20002 *
20003 NBMIN = 2
20004 NX = 0
20005 IWS = N
20006 IF( NB.GT.1 .AND. NB.LT.K ) THEN
20007 *
20008 * Determine when to cross over from blocked to unblocked code.
20009 *
20010 NX = MAX( 0, ILAENV( 3, 'DORGQR', ' ', M, N, K, -1 ) )
20011 IF( NX.LT.K ) THEN
20012 *
20013 * Determine if workspace is large enough for blocked code.
20014 *
20015 LDWORK = N
20016 IWS = LDWORK*NB
20017 IF( LWORK.LT.IWS ) THEN
20018 *
20019 * Not enough workspace to use optimal NB: reduce NB and
20020 * determine the minimum value of NB.
20021 *
20022 NB = LWORK / LDWORK
20023 NBMIN = MAX( 2, ILAENV( 2, 'DORGQR', ' ', M, N, K, -1 ) )
20024 END IF
20025 END IF
20026 END IF
20027 *
20028 IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN
20029 *
20030 * Use blocked code after the last block.
20031 * The first kk columns are handled by the block method.
20032 *
20033 KI = ( ( K-NX-1 ) / NB )*NB
20034 KK = MIN( K, KI+NB )
20035 *
20036 * Set A(1:kk,kk+1:n) to zero.
20037 *
20038 DO 20 J = KK + 1, N
20039 DO 10 I = 1, KK
20040 A( I, J ) = ZERO
20041 10 CONTINUE
20042 20 CONTINUE
20043 ELSE
20044 KK = 0
20045 END IF
20046 *
20047 * Use unblocked code for the last or only block.
20048 *
20049 IF( KK.LT.N )
20050 $ CALL DORG2R( M-KK, N-KK, K-KK, A( KK+1, KK+1 ), LDA,
20051 $ TAU( KK+1 ), WORK, IINFO )
20052 *
20053 IF( KK.GT.0 ) THEN
20054 *
20055 * Use blocked code
20056 *
20057 DO 50 I = KI + 1, 1, -NB
20058 IB = MIN( NB, K-I+1 )
20059 IF( I+IB.LE.N ) THEN
20060 *
20061 * Form the triangular factor of the block reflector
20062 * H = H(i) H(i+1) . . . H(i+ib-1)
20063 *
20064 CALL DLARFT( 'Forward', 'Columnwise', M-I+1, IB,
20065 $ A( I, I ), LDA, TAU( I ), WORK, LDWORK )
20066 *
20067 * Apply H to A(i:m,i+ib:n) from the left
20068 *
20069 CALL DLARFB( 'Left', 'No transpose', 'Forward',
20070 $ 'Columnwise', M-I+1, N-I-IB+1, IB,
20071 $ A( I, I ), LDA, WORK, LDWORK, A( I, I+IB ),
20072 $ LDA, WORK( IB+1 ), LDWORK )
20073 END IF
20074 *
20075 * Apply H to rows i:m of current block
20076 *
20077 CALL DORG2R( M-I+1, IB, IB, A( I, I ), LDA, TAU( I ), WORK,
20078 $ IINFO )
20079 *
20080 * Set rows 1:i-1 of current block to zero
20081 *
20082 DO 40 J = I, I + IB - 1
20083 DO 30 L = 1, I - 1
20084 A( L, J ) = ZERO
20085 30 CONTINUE
20086 40 CONTINUE
20087 50 CONTINUE
20088 END IF
20089 *
20090 WORK( 1 ) = IWS
20091 RETURN
20092 *
20093 * End of DORGQR
20094 *
20095 END
20096 C
20097 C-----------------------------------------------------------------------
20098 C-----------------------------------------------------------------------
20099 SUBROUTINE DTREVC( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL, VR,
20100 $ LDVR, MM, M, WORK, INFO )
20101 *
20102 * -- LAPACK routine (version 3.2) --
20103 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
20104 * November 2006
20105 *
20106 * .. Scalar Arguments ..
20107 CHARACTER HOWMNY, SIDE
20108 INTEGER INFO, LDT, LDVL, LDVR, M, MM, N
20109 * ..
20110 * .. Array Arguments ..
20111 LOGICAL SELECT( * )
20112 DOUBLE PRECISION T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ),
20113 $ WORK( * )
20114 * ..
20115 *
20116 * Purpose
20117 * =======
20118 *
20119 * DTREVC computes some or all of the right and/or left eigenvectors of
20120 * a real upper quasi-triangular matrix T.
20121 * Matrices of this type are produced by the Schur factorization of
20122 * a real general matrix: A = Q*T*Q**T, as computed by DHSEQR.
20123 *
20124 * The right eigenvector x and the left eigenvector y of T corresponding
20125 * to an eigenvalue w are defined by:
20126 *
20127 * T*x = w*x, (y**H)*T = w*(y**H)
20128 *
20129 * where y**H denotes the conjugate transpose of y.
20130 * The eigenvalues are not input to this routine, but are read directly
20131 * from the diagonal blocks of T.
20132 *
20133 * This routine returns the matrices X and/or Y of right and left
20134 * eigenvectors of T, or the products Q*X and/or Q*Y, where Q is an
20135 * input matrix. If Q is the orthogonal factor that reduces a matrix
20136 * A to Schur form T, then Q*X and Q*Y are the matrices of right and
20137 * left eigenvectors of A.
20138 *
20139 * Arguments
20140 * =========
20141 *
20142 * SIDE (input) CHARACTER*1
20143 * = 'R': compute right eigenvectors only;
20144 * = 'L': compute left eigenvectors only;
20145 * = 'B': compute both right and left eigenvectors.
20146 *
20147 * HOWMNY (input) CHARACTER*1
20148 * = 'A': compute all right and/or left eigenvectors;
20149 * = 'B': compute all right and/or left eigenvectors,
20150 * backtransformed by the matrices in VR and/or VL;
20151 * = 'S': compute selected right and/or left eigenvectors,
20152 * as indicated by the logical array SELECT.
20153 *
20154 * SELECT (input/output) LOGICAL array, dimension (N)
20155 * If HOWMNY = 'S', SELECT specifies the eigenvectors to be
20156 * computed.
20157 * If w(j) is a real eigenvalue, the corresponding real
20158 * eigenvector is computed if SELECT(j) is .TRUE..
20159 * If w(j) and w(j+1) are the real and imaginary parts of a
20160 * complex eigenvalue, the corresponding complex eigenvector is
20161 * computed if either SELECT(j) or SELECT(j+1) is .TRUE., and
20162 * on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is set to
20163 * .FALSE..
20164 * Not referenced if HOWMNY = 'A' or 'B'.
20165 *
20166 * N (input) INTEGER
20167 * The order of the matrix T. N >= 0.
20168 *
20169 * T (input) DOUBLE PRECISION array, dimension (LDT,N)
20170 * The upper quasi-triangular matrix T in Schur canonical form.
20171 *
20172 * LDT (input) INTEGER
20173 * The leading dimension of the array T. LDT >= max(1,N).
20174 *
20175 * VL (input/output) DOUBLE PRECISION array, dimension (LDVL,MM)
20176 * On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must
20177 * contain an N-by-N matrix Q (usually the orthogonal matrix Q
20178 * of Schur vectors returned by DHSEQR).
20179 * On exit, if SIDE = 'L' or 'B', VL contains:
20180 * if HOWMNY = 'A', the matrix Y of left eigenvectors of T;
20181 * if HOWMNY = 'B', the matrix Q*Y;
20182 * if HOWMNY = 'S', the left eigenvectors of T specified by
20183 * SELECT, stored consecutively in the columns
20184 * of VL, in the same order as their
20185 * eigenvalues.
20186 * A complex eigenvector corresponding to a complex eigenvalue
20187 * is stored in two consecutive columns, the first holding the
20188 * real part, and the second the imaginary part.
20189 * Not referenced if SIDE = 'R'.
20190 *
20191 * LDVL (input) INTEGER
20192 * The leading dimension of the array VL. LDVL >= 1, and if
20193 * SIDE = 'L' or 'B', LDVL >= N.
20194 *
20195 * VR (input/output) DOUBLE PRECISION array, dimension (LDVR,MM)
20196 * On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must
20197 * contain an N-by-N matrix Q (usually the orthogonal matrix Q
20198 * of Schur vectors returned by DHSEQR).
20199 * On exit, if SIDE = 'R' or 'B', VR contains:
20200 * if HOWMNY = 'A', the matrix X of right eigenvectors of T;
20201 * if HOWMNY = 'B', the matrix Q*X;
20202 * if HOWMNY = 'S', the right eigenvectors of T specified by
20203 * SELECT, stored consecutively in the columns
20204 * of VR, in the same order as their
20205 * eigenvalues.
20206 * A complex eigenvector corresponding to a complex eigenvalue
20207 * is stored in two consecutive columns, the first holding the
20208 * real part and the second the imaginary part.
20209 * Not referenced if SIDE = 'L'.
20210 *
20211 * LDVR (input) INTEGER
20212 * The leading dimension of the array VR. LDVR >= 1, and if
20213 * SIDE = 'R' or 'B', LDVR >= N.
20214 *
20215 * MM (input) INTEGER
20216 * The number of columns in the arrays VL and/or VR. MM >= M.
20217 *
20218 * M (output) INTEGER
20219 * The number of columns in the arrays VL and/or VR actually
20220 * used to store the eigenvectors.
20221 * If HOWMNY = 'A' or 'B', M is set to N.
20222 * Each selected real eigenvector occupies one column and each
20223 * selected complex eigenvector occupies two columns.
20224 *
20225 * WORK (workspace) DOUBLE PRECISION array, dimension (3*N)
20226 *
20227 * INFO (output) INTEGER
20228 * = 0: successful exit
20229 * < 0: if INFO = -i, the i-th argument had an illegal value
20230 *
20231 * Further Details
20232 * ===============
20233 *
20234 * The algorithm used in this program is basically backward (forward)
20235 * substitution, with scaling to make the the code robust against
20236 * possible overflow.
20237 *
20238 * Each eigenvector is normalized so that the element of largest
20239 * magnitude has magnitude 1; here the magnitude of a complex number
20240 * (x,y) is taken to be |x| + |y|.
20241 *
20242 * =====================================================================
20243 *
20244 * .. Parameters ..
20245 DOUBLE PRECISION ZERO, ONE
20246 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
20247 * ..
20248 * .. Local Scalars ..
20249 LOGICAL ALLV, BOTHV, LEFTV, OVER, PAIR, RIGHTV, SOMEV
20250 INTEGER I, IERR, II, IP, IS, J, J1, J2, JNXT, K, KI, N2
20251 DOUBLE PRECISION BETA, BIGNUM, EMAX, OVFL, REC, REMAX, SCALE,
20252 $ SMIN, SMLNUM, ULP, UNFL, VCRIT, VMAX, WI, WR,
20253 $ XNORM
20254 * ..
20255 * .. External Functions ..
20256 LOGICAL LSAME
20257 INTEGER IDAMAX
20258 DOUBLE PRECISION DDOT, DLAMCH
20259 EXTERNAL LSAME, IDAMAX, DDOT, DLAMCH
20260 * ..
20261 * .. External Subroutines ..
20262 EXTERNAL DAXPY, DCOPY, DGEMV, DLALN2, DSCAL, XERBLA
20263 * ..
20264 * .. Intrinsic Functions ..
20265 INTRINSIC ABS, MAX, SQRT
20266 * ..
20267 * .. Local Arrays ..
20268 DOUBLE PRECISION X( 2, 2 )
20269 * ..
20270 * .. Executable Statements ..
20271 *
20272 * Decode and test the input parameters
20273 *
20274 BOTHV = LSAME( SIDE, 'B' )
20275 RIGHTV = LSAME( SIDE, 'R' ) .OR. BOTHV
20276 LEFTV = LSAME( SIDE, 'L' ) .OR. BOTHV
20277 *
20278 ALLV = LSAME( HOWMNY, 'A' )
20279 OVER = LSAME( HOWMNY, 'B' )
20280 SOMEV = LSAME( HOWMNY, 'S' )
20281 *
20282 INFO = 0
20283 IF( .NOT.RIGHTV .AND. .NOT.LEFTV ) THEN
20284 INFO = -1
20285 ELSE IF( .NOT.ALLV .AND. .NOT.OVER .AND. .NOT.SOMEV ) THEN
20286 INFO = -2
20287 ELSE IF( N.LT.0 ) THEN
20288 INFO = -4
20289 ELSE IF( LDT.LT.MAX( 1, N ) ) THEN
20290 INFO = -6
20291 ELSE IF( LDVL.LT.1 .OR. ( LEFTV .AND. LDVL.LT.N ) ) THEN
20292 INFO = -8
20293 ELSE IF( LDVR.LT.1 .OR. ( RIGHTV .AND. LDVR.LT.N ) ) THEN
20294 INFO = -10
20295 ELSE
20296 *
20297 * Set M to the number of columns required to store the selected
20298 * eigenvectors, standardize the array SELECT if necessary, and
20299 * test MM.
20300 *
20301 IF( SOMEV ) THEN
20302 M = 0
20303 PAIR = .FALSE.
20304 DO 10 J = 1, N
20305 IF( PAIR ) THEN
20306 PAIR = .FALSE.
20307 SELECT( J ) = .FALSE.
20308 ELSE
20309 IF( J.LT.N ) THEN
20310 IF( T( J+1, J ).EQ.ZERO ) THEN
20311 IF( SELECT( J ) )
20312 $ M = M + 1
20313 ELSE
20314 PAIR = .TRUE.
20315 IF( SELECT( J ) .OR. SELECT( J+1 ) ) THEN
20316 SELECT( J ) = .TRUE.
20317 M = M + 2
20318 END IF
20319 END IF
20320 ELSE
20321 IF( SELECT( N ) )
20322 $ M = M + 1
20323 END IF
20324 END IF
20325 10 CONTINUE
20326 ELSE
20327 M = N
20328 END IF
20329 *
20330 IF( MM.LT.M ) THEN
20331 INFO = -11
20332 END IF
20333 END IF
20334 IF( INFO.NE.0 ) THEN
20335 CALL XERBLA( 'DTREVC', -INFO )
20336 RETURN
20337 END IF
20338 *
20339 * Quick return if possible.
20340 *
20341 IF( N.EQ.0 )
20342 $ RETURN
20343 *
20344 * Set the constants to control overflow.
20345 *
20346 UNFL = DLAMCH( 'Safe minimum' )
20347 OVFL = ONE / UNFL
20348 CALL DLABAD( UNFL, OVFL )
20349 ULP = DLAMCH( 'Precision' )
20350 SMLNUM = UNFL*( N / ULP )
20351 BIGNUM = ( ONE-ULP ) / SMLNUM
20352 *
20353 * Compute 1-norm of each column of strictly upper triangular
20354 * part of T to control overflow in triangular solver.
20355 *
20356 WORK( 1 ) = ZERO
20357 DO 30 J = 2, N
20358 WORK( J ) = ZERO
20359 DO 20 I = 1, J - 1
20360 WORK( J ) = WORK( J ) + ABS( T( I, J ) )
20361 20 CONTINUE
20362 30 CONTINUE
20363 *
20364 * Index IP is used to specify the real or complex eigenvalue:
20365 * IP = 0, real eigenvalue,
20366 * 1, first of conjugate complex pair: (wr,wi)
20367 * -1, second of conjugate complex pair: (wr,wi)
20368 *
20369 N2 = 2*N
20370 *
20371 IF( RIGHTV ) THEN
20372 *
20373 * Compute right eigenvectors.
20374 *
20375 IP = 0
20376 IS = M
20377 DO 140 KI = N, 1, -1
20378 *
20379 IF( IP.EQ.1 )
20380 $ GO TO 130
20381 IF( KI.EQ.1 )
20382 $ GO TO 40
20383 IF( T( KI, KI-1 ).EQ.ZERO )
20384 $ GO TO 40
20385 IP = -1
20386 *
20387 40 CONTINUE
20388 IF( SOMEV ) THEN
20389 IF( IP.EQ.0 ) THEN
20390 IF( .NOT.SELECT( KI ) )
20391 $ GO TO 130
20392 ELSE
20393 IF( .NOT.SELECT( KI-1 ) )
20394 $ GO TO 130
20395 END IF
20396 END IF
20397 *
20398 * Compute the KI-th eigenvalue (WR,WI).
20399 *
20400 WR = T( KI, KI )
20401 WI = ZERO
20402 IF( IP.NE.0 )
20403 $ WI = SQRT( ABS( T( KI, KI-1 ) ) )*
20404 $ SQRT( ABS( T( KI-1, KI ) ) )
20405 SMIN = MAX( ULP*( ABS( WR )+ABS( WI ) ), SMLNUM )
20406 *
20407 IF( IP.EQ.0 ) THEN
20408 *
20409 * Real right eigenvector
20410 *
20411 WORK( KI+N ) = ONE
20412 *
20413 * Form right-hand side
20414 *
20415 DO 50 K = 1, KI - 1
20416 WORK( K+N ) = -T( K, KI )
20417 50 CONTINUE
20418 *
20419 * Solve the upper quasi-triangular system:
20420 * (T(1:KI-1,1:KI-1) - WR)*X = SCALE*WORK.
20421 *
20422 JNXT = KI - 1
20423 DO 60 J = KI - 1, 1, -1
20424 IF( J.GT.JNXT )
20425 $ GO TO 60
20426 J1 = J
20427 J2 = J
20428 JNXT = J - 1
20429 IF( J.GT.1 ) THEN
20430 IF( T( J, J-1 ).NE.ZERO ) THEN
20431 J1 = J - 1
20432 JNXT = J - 2
20433 END IF
20434 END IF
20435 *
20436 IF( J1.EQ.J2 ) THEN
20437 *
20438 * 1-by-1 diagonal block
20439 *
20440 CALL DLALN2( .FALSE., 1, 1, SMIN, ONE, T( J, J ),
20441 $ LDT, ONE, ONE, WORK( J+N ), N, WR,
20442 $ ZERO, X, 2, SCALE, XNORM, IERR )
20443 *
20444 * Scale X(1,1) to avoid overflow when updating
20445 * the right-hand side.
20446 *
20447 IF( XNORM.GT.ONE ) THEN
20448 IF( WORK( J ).GT.BIGNUM / XNORM ) THEN
20449 X( 1, 1 ) = X( 1, 1 ) / XNORM
20450 SCALE = SCALE / XNORM
20451 END IF
20452 END IF
20453 *
20454 * Scale if necessary
20455 *
20456 IF( SCALE.NE.ONE )
20457 $ CALL DSCAL( KI, SCALE, WORK( 1+N ), 1 )
20458 WORK( J+N ) = X( 1, 1 )
20459 *
20460 * Update right-hand side
20461 *
20462 CALL DAXPY( J-1, -X( 1, 1 ), T( 1, J ), 1,
20463 $ WORK( 1+N ), 1 )
20464 *
20465 ELSE
20466 *
20467 * 2-by-2 diagonal block
20468 *
20469 CALL DLALN2( .FALSE., 2, 1, SMIN, ONE,
20470 $ T( J-1, J-1 ), LDT, ONE, ONE,
20471 $ WORK( J-1+N ), N, WR, ZERO, X, 2,
20472 $ SCALE, XNORM, IERR )
20473 *
20474 * Scale X(1,1) and X(2,1) to avoid overflow when
20475 * updating the right-hand side.
20476 *
20477 IF( XNORM.GT.ONE ) THEN
20478 BETA = MAX( WORK( J-1 ), WORK( J ) )
20479 IF( BETA.GT.BIGNUM / XNORM ) THEN
20480 X( 1, 1 ) = X( 1, 1 ) / XNORM
20481 X( 2, 1 ) = X( 2, 1 ) / XNORM
20482 SCALE = SCALE / XNORM
20483 END IF
20484 END IF
20485 *
20486 * Scale if necessary
20487 *
20488 IF( SCALE.NE.ONE )
20489 $ CALL DSCAL( KI, SCALE, WORK( 1+N ), 1 )
20490 WORK( J-1+N ) = X( 1, 1 )
20491 WORK( J+N ) = X( 2, 1 )
20492 *
20493 * Update right-hand side
20494 *
20495 CALL DAXPY( J-2, -X( 1, 1 ), T( 1, J-1 ), 1,
20496 $ WORK( 1+N ), 1 )
20497 CALL DAXPY( J-2, -X( 2, 1 ), T( 1, J ), 1,
20498 $ WORK( 1+N ), 1 )
20499 END IF
20500 60 CONTINUE
20501 *
20502 * Copy the vector x or Q*x to VR and normalize.
20503 *
20504 IF( .NOT.OVER ) THEN
20505 CALL DCOPY( KI, WORK( 1+N ), 1, VR( 1, IS ), 1 )
20506 *
20507 II = IDAMAX( KI, VR( 1, IS ), 1 )
20508 REMAX = ONE / ABS( VR( II, IS ) )
20509 CALL DSCAL( KI, REMAX, VR( 1, IS ), 1 )
20510 *
20511 DO 70 K = KI + 1, N
20512 VR( K, IS ) = ZERO
20513 70 CONTINUE
20514 ELSE
20515 IF( KI.GT.1 )
20516 $ CALL DGEMV( 'N', N, KI-1, ONE, VR, LDVR,
20517 $ WORK( 1+N ), 1, WORK( KI+N ),
20518 $ VR( 1, KI ), 1 )
20519 *
20520 II = IDAMAX( N, VR( 1, KI ), 1 )
20521 REMAX = ONE / ABS( VR( II, KI ) )
20522 CALL DSCAL( N, REMAX, VR( 1, KI ), 1 )
20523 END IF
20524 *
20525 ELSE
20526 *
20527 * Complex right eigenvector.
20528 *
20529 * Initial solve
20530 * [ (T(KI-1,KI-1) T(KI-1,KI) ) - (WR + I* WI)]*X = 0.
20531 * [ (T(KI,KI-1) T(KI,KI) ) ]
20532 *
20533 IF( ABS( T( KI-1, KI ) ).GE.ABS( T( KI, KI-1 ) ) ) THEN
20534 WORK( KI-1+N ) = ONE
20535 WORK( KI+N2 ) = WI / T( KI-1, KI )
20536 ELSE
20537 WORK( KI-1+N ) = -WI / T( KI, KI-1 )
20538 WORK( KI+N2 ) = ONE
20539 END IF
20540 WORK( KI+N ) = ZERO
20541 WORK( KI-1+N2 ) = ZERO
20542 *
20543 * Form right-hand side
20544 *
20545 DO 80 K = 1, KI - 2
20546 WORK( K+N ) = -WORK( KI-1+N )*T( K, KI-1 )
20547 WORK( K+N2 ) = -WORK( KI+N2 )*T( K, KI )
20548 80 CONTINUE
20549 *
20550 * Solve upper quasi-triangular system:
20551 * (T(1:KI-2,1:KI-2) - (WR+i*WI))*X = SCALE*(WORK+i*WORK2)
20552 *
20553 JNXT = KI - 2
20554 DO 90 J = KI - 2, 1, -1
20555 IF( J.GT.JNXT )
20556 $ GO TO 90
20557 J1 = J
20558 J2 = J
20559 JNXT = J - 1
20560 IF( J.GT.1 ) THEN
20561 IF( T( J, J-1 ).NE.ZERO ) THEN
20562 J1 = J - 1
20563 JNXT = J - 2
20564 END IF
20565 END IF
20566 *
20567 IF( J1.EQ.J2 ) THEN
20568 *
20569 * 1-by-1 diagonal block
20570 *
20571 CALL DLALN2( .FALSE., 1, 2, SMIN, ONE, T( J, J ),
20572 $ LDT, ONE, ONE, WORK( J+N ), N, WR, WI,
20573 $ X, 2, SCALE, XNORM, IERR )
20574 *
20575 * Scale X(1,1) and X(1,2) to avoid overflow when
20576 * updating the right-hand side.
20577 *
20578 IF( XNORM.GT.ONE ) THEN
20579 IF( WORK( J ).GT.BIGNUM / XNORM ) THEN
20580 X( 1, 1 ) = X( 1, 1 ) / XNORM
20581 X( 1, 2 ) = X( 1, 2 ) / XNORM
20582 SCALE = SCALE / XNORM
20583 END IF
20584 END IF
20585 *
20586 * Scale if necessary
20587 *
20588 IF( SCALE.NE.ONE ) THEN
20589 CALL DSCAL( KI, SCALE, WORK( 1+N ), 1 )
20590 CALL DSCAL( KI, SCALE, WORK( 1+N2 ), 1 )
20591 END IF
20592 WORK( J+N ) = X( 1, 1 )
20593 WORK( J+N2 ) = X( 1, 2 )
20594 *
20595 * Update the right-hand side
20596 *
20597 CALL DAXPY( J-1, -X( 1, 1 ), T( 1, J ), 1,
20598 $ WORK( 1+N ), 1 )
20599 CALL DAXPY( J-1, -X( 1, 2 ), T( 1, J ), 1,
20600 $ WORK( 1+N2 ), 1 )
20601 *
20602 ELSE
20603 *
20604 * 2-by-2 diagonal block
20605 *
20606 CALL DLALN2( .FALSE., 2, 2, SMIN, ONE,
20607 $ T( J-1, J-1 ), LDT, ONE, ONE,
20608 $ WORK( J-1+N ), N, WR, WI, X, 2, SCALE,
20609 $ XNORM, IERR )
20610 *
20611 * Scale X to avoid overflow when updating
20612 * the right-hand side.
20613 *
20614 IF( XNORM.GT.ONE ) THEN
20615 BETA = MAX( WORK( J-1 ), WORK( J ) )
20616 IF( BETA.GT.BIGNUM / XNORM ) THEN
20617 REC = ONE / XNORM
20618 X( 1, 1 ) = X( 1, 1 )*REC
20619 X( 1, 2 ) = X( 1, 2 )*REC
20620 X( 2, 1 ) = X( 2, 1 )*REC
20621 X( 2, 2 ) = X( 2, 2 )*REC
20622 SCALE = SCALE*REC
20623 END IF
20624 END IF
20625 *
20626 * Scale if necessary
20627 *
20628 IF( SCALE.NE.ONE ) THEN
20629 CALL DSCAL( KI, SCALE, WORK( 1+N ), 1 )
20630 CALL DSCAL( KI, SCALE, WORK( 1+N2 ), 1 )
20631 END IF
20632 WORK( J-1+N ) = X( 1, 1 )
20633 WORK( J+N ) = X( 2, 1 )
20634 WORK( J-1+N2 ) = X( 1, 2 )
20635 WORK( J+N2 ) = X( 2, 2 )
20636 *
20637 * Update the right-hand side
20638 *
20639 CALL DAXPY( J-2, -X( 1, 1 ), T( 1, J-1 ), 1,
20640 $ WORK( 1+N ), 1 )
20641 CALL DAXPY( J-2, -X( 2, 1 ), T( 1, J ), 1,
20642 $ WORK( 1+N ), 1 )
20643 CALL DAXPY( J-2, -X( 1, 2 ), T( 1, J-1 ), 1,
20644 $ WORK( 1+N2 ), 1 )
20645 CALL DAXPY( J-2, -X( 2, 2 ), T( 1, J ), 1,
20646 $ WORK( 1+N2 ), 1 )
20647 END IF
20648 90 CONTINUE
20649 *
20650 * Copy the vector x or Q*x to VR and normalize.
20651 *
20652 IF( .NOT.OVER ) THEN
20653 CALL DCOPY( KI, WORK( 1+N ), 1, VR( 1, IS-1 ), 1 )
20654 CALL DCOPY( KI, WORK( 1+N2 ), 1, VR( 1, IS ), 1 )
20655 *
20656 EMAX = ZERO
20657 DO 100 K = 1, KI
20658 EMAX = MAX( EMAX, ABS( VR( K, IS-1 ) )+
20659 $ ABS( VR( K, IS ) ) )
20660 100 CONTINUE
20661 *
20662 REMAX = ONE / EMAX
20663 CALL DSCAL( KI, REMAX, VR( 1, IS-1 ), 1 )
20664 CALL DSCAL( KI, REMAX, VR( 1, IS ), 1 )
20665 *
20666 DO 110 K = KI + 1, N
20667 VR( K, IS-1 ) = ZERO
20668 VR( K, IS ) = ZERO
20669 110 CONTINUE
20670 *
20671 ELSE
20672 *
20673 IF( KI.GT.2 ) THEN
20674 CALL DGEMV( 'N', N, KI-2, ONE, VR, LDVR,
20675 $ WORK( 1+N ), 1, WORK( KI-1+N ),
20676 $ VR( 1, KI-1 ), 1 )
20677 CALL DGEMV( 'N', N, KI-2, ONE, VR, LDVR,
20678 $ WORK( 1+N2 ), 1, WORK( KI+N2 ),
20679 $ VR( 1, KI ), 1 )
20680 ELSE
20681 CALL DSCAL( N, WORK( KI-1+N ), VR( 1, KI-1 ), 1 )
20682 CALL DSCAL( N, WORK( KI+N2 ), VR( 1, KI ), 1 )
20683 END IF
20684 *
20685 EMAX = ZERO
20686 DO 120 K = 1, N
20687 EMAX = MAX( EMAX, ABS( VR( K, KI-1 ) )+
20688 $ ABS( VR( K, KI ) ) )
20689 120 CONTINUE
20690 REMAX = ONE / EMAX
20691 CALL DSCAL( N, REMAX, VR( 1, KI-1 ), 1 )
20692 CALL DSCAL( N, REMAX, VR( 1, KI ), 1 )
20693 END IF
20694 END IF
20695 *
20696 IS = IS - 1
20697 IF( IP.NE.0 )
20698 $ IS = IS - 1
20699 130 CONTINUE
20700 IF( IP.EQ.1 )
20701 $ IP = 0
20702 IF( IP.EQ.-1 )
20703 $ IP = 1
20704 140 CONTINUE
20705 END IF
20706 *
20707 IF( LEFTV ) THEN
20708 *
20709 * Compute left eigenvectors.
20710 *
20711 IP = 0
20712 IS = 1
20713 DO 260 KI = 1, N
20714 *
20715 IF( IP.EQ.-1 )
20716 $ GO TO 250
20717 IF( KI.EQ.N )
20718 $ GO TO 150
20719 IF( T( KI+1, KI ).EQ.ZERO )
20720 $ GO TO 150
20721 IP = 1
20722 *
20723 150 CONTINUE
20724 IF( SOMEV ) THEN
20725 IF( .NOT.SELECT( KI ) )
20726 $ GO TO 250
20727 END IF
20728 *
20729 * Compute the KI-th eigenvalue (WR,WI).
20730 *
20731 WR = T( KI, KI )
20732 WI = ZERO
20733 IF( IP.NE.0 )
20734 $ WI = SQRT( ABS( T( KI, KI+1 ) ) )*
20735 $ SQRT( ABS( T( KI+1, KI ) ) )
20736 SMIN = MAX( ULP*( ABS( WR )+ABS( WI ) ), SMLNUM )
20737 *
20738 IF( IP.EQ.0 ) THEN
20739 *
20740 * Real left eigenvector.
20741 *
20742 WORK( KI+N ) = ONE
20743 *
20744 * Form right-hand side
20745 *
20746 DO 160 K = KI + 1, N
20747 WORK( K+N ) = -T( KI, K )
20748 160 CONTINUE
20749 *
20750 * Solve the quasi-triangular system:
20751 * (T(KI+1:N,KI+1:N) - WR)'*X = SCALE*WORK
20752 *
20753 VMAX = ONE
20754 VCRIT = BIGNUM
20755 *
20756 JNXT = KI + 1
20757 DO 170 J = KI + 1, N
20758 IF( J.LT.JNXT )
20759 $ GO TO 170
20760 J1 = J
20761 J2 = J
20762 JNXT = J + 1
20763 IF( J.LT.N ) THEN
20764 IF( T( J+1, J ).NE.ZERO ) THEN
20765 J2 = J + 1
20766 JNXT = J + 2
20767 END IF
20768 END IF
20769 *
20770 IF( J1.EQ.J2 ) THEN
20771 *
20772 * 1-by-1 diagonal block
20773 *
20774 * Scale if necessary to avoid overflow when forming
20775 * the right-hand side.
20776 *
20777 IF( WORK( J ).GT.VCRIT ) THEN
20778 REC = ONE / VMAX
20779 CALL DSCAL( N-KI+1, REC, WORK( KI+N ), 1 )
20780 VMAX = ONE
20781 VCRIT = BIGNUM
20782 END IF
20783 *
20784 WORK( J+N ) = WORK( J+N ) -
20785 $ DDOT( J-KI-1, T( KI+1, J ), 1,
20786 $ WORK( KI+1+N ), 1 )
20787 *
20788 * Solve (T(J,J)-WR)'*X = WORK
20789 *
20790 CALL DLALN2( .FALSE., 1, 1, SMIN, ONE, T( J, J ),
20791 $ LDT, ONE, ONE, WORK( J+N ), N, WR,
20792 $ ZERO, X, 2, SCALE, XNORM, IERR )
20793 *
20794 * Scale if necessary
20795 *
20796 IF( SCALE.NE.ONE )
20797 $ CALL DSCAL( N-KI+1, SCALE, WORK( KI+N ), 1 )
20798 WORK( J+N ) = X( 1, 1 )
20799 VMAX = MAX( ABS( WORK( J+N ) ), VMAX )
20800 VCRIT = BIGNUM / VMAX
20801 *
20802 ELSE
20803 *
20804 * 2-by-2 diagonal block
20805 *
20806 * Scale if necessary to avoid overflow when forming
20807 * the right-hand side.
20808 *
20809 BETA = MAX( WORK( J ), WORK( J+1 ) )
20810 IF( BETA.GT.VCRIT ) THEN
20811 REC = ONE / VMAX
20812 CALL DSCAL( N-KI+1, REC, WORK( KI+N ), 1 )
20813 VMAX = ONE
20814 VCRIT = BIGNUM
20815 END IF
20816 *
20817 WORK( J+N ) = WORK( J+N ) -
20818 $ DDOT( J-KI-1, T( KI+1, J ), 1,
20819 $ WORK( KI+1+N ), 1 )
20820 *
20821 WORK( J+1+N ) = WORK( J+1+N ) -
20822 $ DDOT( J-KI-1, T( KI+1, J+1 ), 1,
20823 $ WORK( KI+1+N ), 1 )
20824 *
20825 * Solve
20826 * [T(J,J)-WR T(J,J+1) ]'* X = SCALE*( WORK1 )
20827 * [T(J+1,J) T(J+1,J+1)-WR] ( WORK2 )
20828 *
20829 CALL DLALN2( .TRUE., 2, 1, SMIN, ONE, T( J, J ),
20830 $ LDT, ONE, ONE, WORK( J+N ), N, WR,
20831 $ ZERO, X, 2, SCALE, XNORM, IERR )
20832 *
20833 * Scale if necessary
20834 *
20835 IF( SCALE.NE.ONE )
20836 $ CALL DSCAL( N-KI+1, SCALE, WORK( KI+N ), 1 )
20837 WORK( J+N ) = X( 1, 1 )
20838 WORK( J+1+N ) = X( 2, 1 )
20839 *
20840 VMAX = MAX( ABS( WORK( J+N ) ),
20841 $ ABS( WORK( J+1+N ) ), VMAX )
20842 VCRIT = BIGNUM / VMAX
20843 *
20844 END IF
20845 170 CONTINUE
20846 *
20847 * Copy the vector x or Q*x to VL and normalize.
20848 *
20849 IF( .NOT.OVER ) THEN
20850 CALL DCOPY( N-KI+1, WORK( KI+N ), 1, VL( KI, IS ), 1 )
20851 *
20852 II = IDAMAX( N-KI+1, VL( KI, IS ), 1 ) + KI - 1
20853 REMAX = ONE / ABS( VL( II, IS ) )
20854 CALL DSCAL( N-KI+1, REMAX, VL( KI, IS ), 1 )
20855 *
20856 DO 180 K = 1, KI - 1
20857 VL( K, IS ) = ZERO
20858 180 CONTINUE
20859 *
20860 ELSE
20861 *
20862 IF( KI.LT.N )
20863 $ CALL DGEMV( 'N', N, N-KI, ONE, VL( 1, KI+1 ), LDVL,
20864 $ WORK( KI+1+N ), 1, WORK( KI+N ),
20865 $ VL( 1, KI ), 1 )
20866 *
20867 II = IDAMAX( N, VL( 1, KI ), 1 )
20868 REMAX = ONE / ABS( VL( II, KI ) )
20869 CALL DSCAL( N, REMAX, VL( 1, KI ), 1 )
20870 *
20871 END IF
20872 *
20873 ELSE
20874 *
20875 * Complex left eigenvector.
20876 *
20877 * Initial solve:
20878 * ((T(KI,KI) T(KI,KI+1) )' - (WR - I* WI))*X = 0.
20879 * ((T(KI+1,KI) T(KI+1,KI+1)) )
20880 *
20881 IF( ABS( T( KI, KI+1 ) ).GE.ABS( T( KI+1, KI ) ) ) THEN
20882 WORK( KI+N ) = WI / T( KI, KI+1 )
20883 WORK( KI+1+N2 ) = ONE
20884 ELSE
20885 WORK( KI+N ) = ONE
20886 WORK( KI+1+N2 ) = -WI / T( KI+1, KI )
20887 END IF
20888 WORK( KI+1+N ) = ZERO
20889 WORK( KI+N2 ) = ZERO
20890 *
20891 * Form right-hand side
20892 *
20893 DO 190 K = KI + 2, N
20894 WORK( K+N ) = -WORK( KI+N )*T( KI, K )
20895 WORK( K+N2 ) = -WORK( KI+1+N2 )*T( KI+1, K )
20896 190 CONTINUE
20897 *
20898 * Solve complex quasi-triangular system:
20899 * ( T(KI+2,N:KI+2,N) - (WR-i*WI) )*X = WORK1+i*WORK2
20900 *
20901 VMAX = ONE
20902 VCRIT = BIGNUM
20903 *
20904 JNXT = KI + 2
20905 DO 200 J = KI + 2, N
20906 IF( J.LT.JNXT )
20907 $ GO TO 200
20908 J1 = J
20909 J2 = J
20910 JNXT = J + 1
20911 IF( J.LT.N ) THEN
20912 IF( T( J+1, J ).NE.ZERO ) THEN
20913 J2 = J + 1
20914 JNXT = J + 2
20915 END IF
20916 END IF
20917 *
20918 IF( J1.EQ.J2 ) THEN
20919 *
20920 * 1-by-1 diagonal block
20921 *
20922 * Scale if necessary to avoid overflow when
20923 * forming the right-hand side elements.
20924 *
20925 IF( WORK( J ).GT.VCRIT ) THEN
20926 REC = ONE / VMAX
20927 CALL DSCAL( N-KI+1, REC, WORK( KI+N ), 1 )
20928 CALL DSCAL( N-KI+1, REC, WORK( KI+N2 ), 1 )
20929 VMAX = ONE
20930 VCRIT = BIGNUM
20931 END IF
20932 *
20933 WORK( J+N ) = WORK( J+N ) -
20934 $ DDOT( J-KI-2, T( KI+2, J ), 1,
20935 $ WORK( KI+2+N ), 1 )
20936 WORK( J+N2 ) = WORK( J+N2 ) -
20937 $ DDOT( J-KI-2, T( KI+2, J ), 1,
20938 $ WORK( KI+2+N2 ), 1 )
20939 *
20940 * Solve (T(J,J)-(WR-i*WI))*(X11+i*X12)= WK+I*WK2
20941 *
20942 CALL DLALN2( .FALSE., 1, 2, SMIN, ONE, T( J, J ),
20943 $ LDT, ONE, ONE, WORK( J+N ), N, WR,
20944 $ -WI, X, 2, SCALE, XNORM, IERR )
20945 *
20946 * Scale if necessary
20947 *
20948 IF( SCALE.NE.ONE ) THEN
20949 CALL DSCAL( N-KI+1, SCALE, WORK( KI+N ), 1 )
20950 CALL DSCAL( N-KI+1, SCALE, WORK( KI+N2 ), 1 )
20951 END IF
20952 WORK( J+N ) = X( 1, 1 )
20953 WORK( J+N2 ) = X( 1, 2 )
20954 VMAX = MAX( ABS( WORK( J+N ) ),
20955 $ ABS( WORK( J+N2 ) ), VMAX )
20956 VCRIT = BIGNUM / VMAX
20957 *
20958 ELSE
20959 *
20960 * 2-by-2 diagonal block
20961 *
20962 * Scale if necessary to avoid overflow when forming
20963 * the right-hand side elements.
20964 *
20965 BETA = MAX( WORK( J ), WORK( J+1 ) )
20966 IF( BETA.GT.VCRIT ) THEN
20967 REC = ONE / VMAX
20968 CALL DSCAL( N-KI+1, REC, WORK( KI+N ), 1 )
20969 CALL DSCAL( N-KI+1, REC, WORK( KI+N2 ), 1 )
20970 VMAX = ONE
20971 VCRIT = BIGNUM
20972 END IF
20973 *
20974 WORK( J+N ) = WORK( J+N ) -
20975 $ DDOT( J-KI-2, T( KI+2, J ), 1,
20976 $ WORK( KI+2+N ), 1 )
20977 *
20978 WORK( J+N2 ) = WORK( J+N2 ) -
20979 $ DDOT( J-KI-2, T( KI+2, J ), 1,
20980 $ WORK( KI+2+N2 ), 1 )
20981 *
20982 WORK( J+1+N ) = WORK( J+1+N ) -
20983 $ DDOT( J-KI-2, T( KI+2, J+1 ), 1,
20984 $ WORK( KI+2+N ), 1 )
20985 *
20986 WORK( J+1+N2 ) = WORK( J+1+N2 ) -
20987 $ DDOT( J-KI-2, T( KI+2, J+1 ), 1,
20988 $ WORK( KI+2+N2 ), 1 )
20989 *
20990 * Solve 2-by-2 complex linear equation
20991 * ([T(j,j) T(j,j+1) ]'-(wr-i*wi)*I)*X = SCALE*B
20992 * ([T(j+1,j) T(j+1,j+1)] )
20993 *
20994 CALL DLALN2( .TRUE., 2, 2, SMIN, ONE, T( J, J ),
20995 $ LDT, ONE, ONE, WORK( J+N ), N, WR,
20996 $ -WI, X, 2, SCALE, XNORM, IERR )
20997 *
20998 * Scale if necessary
20999 *
21000 IF( SCALE.NE.ONE ) THEN
21001 CALL DSCAL( N-KI+1, SCALE, WORK( KI+N ), 1 )
21002 CALL DSCAL( N-KI+1, SCALE, WORK( KI+N2 ), 1 )
21003 END IF
21004 WORK( J+N ) = X( 1, 1 )
21005 WORK( J+N2 ) = X( 1, 2 )
21006 WORK( J+1+N ) = X( 2, 1 )
21007 WORK( J+1+N2 ) = X( 2, 2 )
21008 VMAX = MAX( ABS( X( 1, 1 ) ), ABS( X( 1, 2 ) ),
21009 $ ABS( X( 2, 1 ) ), ABS( X( 2, 2 ) ), VMAX )
21010 VCRIT = BIGNUM / VMAX
21011 *
21012 END IF
21013 200 CONTINUE
21014 *
21015 * Copy the vector x or Q*x to VL and normalize.
21016 *
21017 IF( .NOT.OVER ) THEN
21018 CALL DCOPY( N-KI+1, WORK( KI+N ), 1, VL( KI, IS ), 1 )
21019 CALL DCOPY( N-KI+1, WORK( KI+N2 ), 1, VL( KI, IS+1 ),
21020 $ 1 )
21021 *
21022 EMAX = ZERO
21023 DO 220 K = KI, N
21024 EMAX = MAX( EMAX, ABS( VL( K, IS ) )+
21025 $ ABS( VL( K, IS+1 ) ) )
21026 220 CONTINUE
21027 REMAX = ONE / EMAX
21028 CALL DSCAL( N-KI+1, REMAX, VL( KI, IS ), 1 )
21029 CALL DSCAL( N-KI+1, REMAX, VL( KI, IS+1 ), 1 )
21030 *
21031 DO 230 K = 1, KI - 1
21032 VL( K, IS ) = ZERO
21033 VL( K, IS+1 ) = ZERO
21034 230 CONTINUE
21035 ELSE
21036 IF( KI.LT.N-1 ) THEN
21037 CALL DGEMV( 'N', N, N-KI-1, ONE, VL( 1, KI+2 ),
21038 $ LDVL, WORK( KI+2+N ), 1, WORK( KI+N ),
21039 $ VL( 1, KI ), 1 )
21040 CALL DGEMV( 'N', N, N-KI-1, ONE, VL( 1, KI+2 ),
21041 $ LDVL, WORK( KI+2+N2 ), 1,
21042 $ WORK( KI+1+N2 ), VL( 1, KI+1 ), 1 )
21043 ELSE
21044 CALL DSCAL( N, WORK( KI+N ), VL( 1, KI ), 1 )
21045 CALL DSCAL( N, WORK( KI+1+N2 ), VL( 1, KI+1 ), 1 )
21046 END IF
21047 *
21048 EMAX = ZERO
21049 DO 240 K = 1, N
21050 EMAX = MAX( EMAX, ABS( VL( K, KI ) )+
21051 $ ABS( VL( K, KI+1 ) ) )
21052 240 CONTINUE
21053 REMAX = ONE / EMAX
21054 CALL DSCAL( N, REMAX, VL( 1, KI ), 1 )
21055 CALL DSCAL( N, REMAX, VL( 1, KI+1 ), 1 )
21056 *
21057 END IF
21058 *
21059 END IF
21060 *
21061 IS = IS + 1
21062 IF( IP.NE.0 )
21063 $ IS = IS + 1
21064 250 CONTINUE
21065 IF( IP.EQ.-1 )
21066 $ IP = 0
21067 IF( IP.EQ.1 )
21068 $ IP = -1
21069 *
21070 260 CONTINUE
21071 *
21072 END IF
21073 *
21074 RETURN
21075 *
21076 * End of DTREVC
21077 *
21078 END
21079 C
21080 C-----------------------------------------------------------------------
21081 C-----------------------------------------------------------------------
21082 SUBROUTINE DTREXC( COMPQ, N, T, LDT, Q, LDQ, IFST, ILST, WORK,
21083 $ INFO )
21084 *
21085 * -- LAPACK routine (version 3.2) --
21086 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
21087 * November 2006
21088 *
21089 * .. Scalar Arguments ..
21090 CHARACTER COMPQ
21091 INTEGER IFST, ILST, INFO, LDQ, LDT, N
21092 * ..
21093 * .. Array Arguments ..
21094 DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WORK( * )
21095 * ..
21096 *
21097 * Purpose
21098 * =======
21099 *
21100 * DTREXC reorders the real Schur factorization of a real matrix
21101 * A = Q*T*Q**T, so that the diagonal block of T with row index IFST is
21102 * moved to row ILST.
21103 *
21104 * The real Schur form T is reordered by an orthogonal similarity
21105 * transformation Z**T*T*Z, and optionally the matrix Q of Schur vectors
21106 * is updated by postmultiplying it with Z.
21107 *
21108 * T must be in Schur canonical form (as returned by DHSEQR), that is,
21109 * block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; each
21110 * 2-by-2 diagonal block has its diagonal elements equal and its
21111 * off-diagonal elements of opposite sign.
21112 *
21113 * Arguments
21114 * =========
21115 *
21116 * COMPQ (input) CHARACTER*1
21117 * = 'V': update the matrix Q of Schur vectors;
21118 * = 'N': do not update Q.
21119 *
21120 * N (input) INTEGER
21121 * The order of the matrix T. N >= 0.
21122 *
21123 * T (input/output) DOUBLE PRECISION array, dimension (LDT,N)
21124 * On entry, the upper quasi-triangular matrix T, in Schur
21125 * Schur canonical form.
21126 * On exit, the reordered upper quasi-triangular matrix, again
21127 * in Schur canonical form.
21128 *
21129 * LDT (input) INTEGER
21130 * The leading dimension of the array T. LDT >= max(1,N).
21131 *
21132 * Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N)
21133 * On entry, if COMPQ = 'V', the matrix Q of Schur vectors.
21134 * On exit, if COMPQ = 'V', Q has been postmultiplied by the
21135 * orthogonal transformation matrix Z which reorders T.
21136 * If COMPQ = 'N', Q is not referenced.
21137 *
21138 * LDQ (input) INTEGER
21139 * The leading dimension of the array Q. LDQ >= max(1,N).
21140 *
21141 * IFST (input/output) INTEGER
21142 * ILST (input/output) INTEGER
21143 * Specify the reordering of the diagonal blocks of T.
21144 * The block with row index IFST is moved to row ILST, by a
21145 * sequence of transpositions between adjacent blocks.
21146 * On exit, if IFST pointed on entry to the second row of a
21147 * 2-by-2 block, it is changed to point to the first row; ILST
21148 * always points to the first row of the block in its final
21149 * position (which may differ from its input value by +1 or -1).
21150 * 1 <= IFST <= N; 1 <= ILST <= N.
21151 *
21152 * WORK (workspace) DOUBLE PRECISION array, dimension (N)
21153 *
21154 * INFO (output) INTEGER
21155 * = 0: successful exit
21156 * < 0: if INFO = -i, the i-th argument had an illegal value
21157 * = 1: two adjacent blocks were too close to swap (the problem
21158 * is very ill-conditioned); T may have been partially
21159 * reordered, and ILST points to the first row of the
21160 * current position of the block being moved.
21161 *
21162 * =====================================================================
21163 *
21164 * .. Parameters ..
21165 DOUBLE PRECISION ZERO
21166 PARAMETER ( ZERO = 0.0D+0 )
21167 * ..
21168 * .. Local Scalars ..
21169 LOGICAL WANTQ
21170 INTEGER HERE, NBF, NBL, NBNEXT
21171 * ..
21172 * .. External Functions ..
21173 LOGICAL LSAME
21174 EXTERNAL LSAME
21175 * ..
21176 * .. External Subroutines ..
21177 EXTERNAL DLAEXC, XERBLA
21178 * ..
21179 * .. Intrinsic Functions ..
21180 INTRINSIC MAX
21181 * ..
21182 * .. Executable Statements ..
21183 *
21184 * Decode and test the input arguments.
21185 *
21186 INFO = 0
21187 WANTQ = LSAME( COMPQ, 'V' )
21188 IF( .NOT.WANTQ .AND. .NOT.LSAME( COMPQ, 'N' ) ) THEN
21189 INFO = -1
21190 ELSE IF( N.LT.0 ) THEN
21191 INFO = -2
21192 ELSE IF( LDT.LT.MAX( 1, N ) ) THEN
21193 INFO = -4
21194 ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.MAX( 1, N ) ) ) THEN
21195 INFO = -6
21196 ELSE IF( IFST.LT.1 .OR. IFST.GT.N ) THEN
21197 INFO = -7
21198 ELSE IF( ILST.LT.1 .OR. ILST.GT.N ) THEN
21199 INFO = -8
21200 END IF
21201 IF( INFO.NE.0 ) THEN
21202 CALL XERBLA( 'DTREXC', -INFO )
21203 RETURN
21204 END IF
21205 *
21206 * Quick return if possible
21207 *
21208 IF( N.LE.1 )
21209 $ RETURN
21210 *
21211 * Determine the first row of specified block
21212 * and find out it is 1 by 1 or 2 by 2.
21213 *
21214 IF( IFST.GT.1 ) THEN
21215 IF( T( IFST, IFST-1 ).NE.ZERO )
21216 $ IFST = IFST - 1
21217 END IF
21218 NBF = 1
21219 IF( IFST.LT.N ) THEN
21220 IF( T( IFST+1, IFST ).NE.ZERO )
21221 $ NBF = 2
21222 END IF
21223 *
21224 * Determine the first row of the final block
21225 * and find out it is 1 by 1 or 2 by 2.
21226 *
21227 IF( ILST.GT.1 ) THEN
21228 IF( T( ILST, ILST-1 ).NE.ZERO )
21229 $ ILST = ILST - 1
21230 END IF
21231 NBL = 1
21232 IF( ILST.LT.N ) THEN
21233 IF( T( ILST+1, ILST ).NE.ZERO )
21234 $ NBL = 2
21235 END IF
21236 *
21237 IF( IFST.EQ.ILST )
21238 $ RETURN
21239 *
21240 IF( IFST.LT.ILST ) THEN
21241 *
21242 * Update ILST
21243 *
21244 IF( NBF.EQ.2 .AND. NBL.EQ.1 )
21245 $ ILST = ILST - 1
21246 IF( NBF.EQ.1 .AND. NBL.EQ.2 )
21247 $ ILST = ILST + 1
21248 *
21249 HERE = IFST
21250 *
21251 10 CONTINUE
21252 *
21253 * Swap block with next one below
21254 *
21255 IF( NBF.EQ.1 .OR. NBF.EQ.2 ) THEN
21256 *
21257 * Current block either 1 by 1 or 2 by 2
21258 *
21259 NBNEXT = 1
21260 IF( HERE+NBF+1.LE.N ) THEN
21261 IF( T( HERE+NBF+1, HERE+NBF ).NE.ZERO )
21262 $ NBNEXT = 2
21263 END IF
21264 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, NBF, NBNEXT,
21265 $ WORK, INFO )
21266 IF( INFO.NE.0 ) THEN
21267 ILST = HERE
21268 RETURN
21269 END IF
21270 HERE = HERE + NBNEXT
21271 *
21272 * Test if 2 by 2 block breaks into two 1 by 1 blocks
21273 *
21274 IF( NBF.EQ.2 ) THEN
21275 IF( T( HERE+1, HERE ).EQ.ZERO )
21276 $ NBF = 3
21277 END IF
21278 *
21279 ELSE
21280 *
21281 * Current block consists of two 1 by 1 blocks each of which
21282 * must be swapped individually
21283 *
21284 NBNEXT = 1
21285 IF( HERE+3.LE.N ) THEN
21286 IF( T( HERE+3, HERE+2 ).NE.ZERO )
21287 $ NBNEXT = 2
21288 END IF
21289 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE+1, 1, NBNEXT,
21290 $ WORK, INFO )
21291 IF( INFO.NE.0 ) THEN
21292 ILST = HERE
21293 RETURN
21294 END IF
21295 IF( NBNEXT.EQ.1 ) THEN
21296 *
21297 * Swap two 1 by 1 blocks, no problems possible
21298 *
21299 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, 1, NBNEXT,
21300 $ WORK, INFO )
21301 HERE = HERE + 1
21302 ELSE
21303 *
21304 * Recompute NBNEXT in case 2 by 2 split
21305 *
21306 IF( T( HERE+2, HERE+1 ).EQ.ZERO )
21307 $ NBNEXT = 1
21308 IF( NBNEXT.EQ.2 ) THEN
21309 *
21310 * 2 by 2 Block did not split
21311 *
21312 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, 1,
21313 $ NBNEXT, WORK, INFO )
21314 IF( INFO.NE.0 ) THEN
21315 ILST = HERE
21316 RETURN
21317 END IF
21318 HERE = HERE + 2
21319 ELSE
21320 *
21321 * 2 by 2 Block did split
21322 *
21323 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, 1, 1,
21324 $ WORK, INFO )
21325 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE+1, 1, 1,
21326 $ WORK, INFO )
21327 HERE = HERE + 2
21328 END IF
21329 END IF
21330 END IF
21331 IF( HERE.LT.ILST )
21332 $ GO TO 10
21333 *
21334 ELSE
21335 *
21336 HERE = IFST
21337 20 CONTINUE
21338 *
21339 * Swap block with next one above
21340 *
21341 IF( NBF.EQ.1 .OR. NBF.EQ.2 ) THEN
21342 *
21343 * Current block either 1 by 1 or 2 by 2
21344 *
21345 NBNEXT = 1
21346 IF( HERE.GE.3 ) THEN
21347 IF( T( HERE-1, HERE-2 ).NE.ZERO )
21348 $ NBNEXT = 2
21349 END IF
21350 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE-NBNEXT, NBNEXT,
21351 $ NBF, WORK, INFO )
21352 IF( INFO.NE.0 ) THEN
21353 ILST = HERE
21354 RETURN
21355 END IF
21356 HERE = HERE - NBNEXT
21357 *
21358 * Test if 2 by 2 block breaks into two 1 by 1 blocks
21359 *
21360 IF( NBF.EQ.2 ) THEN
21361 IF( T( HERE+1, HERE ).EQ.ZERO )
21362 $ NBF = 3
21363 END IF
21364 *
21365 ELSE
21366 *
21367 * Current block consists of two 1 by 1 blocks each of which
21368 * must be swapped individually
21369 *
21370 NBNEXT = 1
21371 IF( HERE.GE.3 ) THEN
21372 IF( T( HERE-1, HERE-2 ).NE.ZERO )
21373 $ NBNEXT = 2
21374 END IF
21375 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE-NBNEXT, NBNEXT,
21376 $ 1, WORK, INFO )
21377 IF( INFO.NE.0 ) THEN
21378 ILST = HERE
21379 RETURN
21380 END IF
21381 IF( NBNEXT.EQ.1 ) THEN
21382 *
21383 * Swap two 1 by 1 blocks, no problems possible
21384 *
21385 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, NBNEXT, 1,
21386 $ WORK, INFO )
21387 HERE = HERE - 1
21388 ELSE
21389 *
21390 * Recompute NBNEXT in case 2 by 2 split
21391 *
21392 IF( T( HERE, HERE-1 ).EQ.ZERO )
21393 $ NBNEXT = 1
21394 IF( NBNEXT.EQ.2 ) THEN
21395 *
21396 * 2 by 2 Block did not split
21397 *
21398 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE-1, 2, 1,
21399 $ WORK, INFO )
21400 IF( INFO.NE.0 ) THEN
21401 ILST = HERE
21402 RETURN
21403 END IF
21404 HERE = HERE - 2
21405 ELSE
21406 *
21407 * 2 by 2 Block did split
21408 *
21409 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, 1, 1,
21410 $ WORK, INFO )
21411 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE-1, 1, 1,
21412 $ WORK, INFO )
21413 HERE = HERE - 2
21414 END IF
21415 END IF
21416 END IF
21417 IF( HERE.GT.ILST )
21418 $ GO TO 20
21419 END IF
21420 ILST = HERE
21421 *
21422 RETURN
21423 *
21424 * End of DTREXC
21425 *
21426 END
21427 C
21428 C-----------------------------------------------------------------------
21429 C-----------------------------------------------------------------------
21430 SUBROUTINE DTRSEN( JOB, COMPQ, SELECT, N, T, LDT, Q, LDQ, WR, WI,
21431 $ M, S, SEP, WORK, LWORK, IWORK, LIWORK, INFO )
21432 *
21433 * -- LAPACK routine (version 3.2) --
21434 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
21435 * November 2006
21436 *
21437 * .. Scalar Arguments ..
21438 CHARACTER COMPQ, JOB
21439 INTEGER INFO, LDQ, LDT, LIWORK, LWORK, M, N
21440 DOUBLE PRECISION S, SEP
21441 * ..
21442 * .. Array Arguments ..
21443 LOGICAL SELECT( * )
21444 INTEGER IWORK( * )
21445 DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WI( * ), WORK( * ),
21446 $ WR( * )
21447 * ..
21448 *
21449 * Purpose
21450 * =======
21451 *
21452 * DTRSEN reorders the real Schur factorization of a real matrix
21453 * A = Q*T*Q**T, so that a selected cluster of eigenvalues appears in
21454 * the leading diagonal blocks of the upper quasi-triangular matrix T,
21455 * and the leading columns of Q form an orthonormal basis of the
21456 * corresponding right invariant subspace.
21457 *
21458 * Optionally the routine computes the reciprocal condition numbers of
21459 * the cluster of eigenvalues and/or the invariant subspace.
21460 *
21461 * T must be in Schur canonical form (as returned by DHSEQR), that is,
21462 * block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; each
21463 * 2-by-2 diagonal block has its diagonal elemnts equal and its
21464 * off-diagonal elements of opposite sign.
21465 *
21466 * Arguments
21467 * =========
21468 *
21469 * JOB (input) CHARACTER*1
21470 * Specifies whether condition numbers are required for the
21471 * cluster of eigenvalues (S) or the invariant subspace (SEP):
21472 * = 'N': none;
21473 * = 'E': for eigenvalues only (S);
21474 * = 'V': for invariant subspace only (SEP);
21475 * = 'B': for both eigenvalues and invariant subspace (S and
21476 * SEP).
21477 *
21478 * COMPQ (input) CHARACTER*1
21479 * = 'V': update the matrix Q of Schur vectors;
21480 * = 'N': do not update Q.
21481 *
21482 * SELECT (input) LOGICAL array, dimension (N)
21483 * SELECT specifies the eigenvalues in the selected cluster. To
21484 * select a real eigenvalue w(j), SELECT(j) must be set to
21485 * .TRUE.. To select a complex conjugate pair of eigenvalues
21486 * w(j) and w(j+1), corresponding to a 2-by-2 diagonal block,
21487 * either SELECT(j) or SELECT(j+1) or both must be set to
21488 * .TRUE.; a complex conjugate pair of eigenvalues must be
21489 * either both included in the cluster or both excluded.
21490 *
21491 * N (input) INTEGER
21492 * The order of the matrix T. N >= 0.
21493 *
21494 * T (input/output) DOUBLE PRECISION array, dimension (LDT,N)
21495 * On entry, the upper quasi-triangular matrix T, in Schur
21496 * canonical form.
21497 * On exit, T is overwritten by the reordered matrix T, again in
21498 * Schur canonical form, with the selected eigenvalues in the
21499 * leading diagonal blocks.
21500 *
21501 * LDT (input) INTEGER
21502 * The leading dimension of the array T. LDT >= max(1,N).
21503 *
21504 * Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N)
21505 * On entry, if COMPQ = 'V', the matrix Q of Schur vectors.
21506 * On exit, if COMPQ = 'V', Q has been postmultiplied by the
21507 * orthogonal transformation matrix which reorders T; the
21508 * leading M columns of Q form an orthonormal basis for the
21509 * specified invariant subspace.
21510 * If COMPQ = 'N', Q is not referenced.
21511 *
21512 * LDQ (input) INTEGER
21513 * The leading dimension of the array Q.
21514 * LDQ >= 1; and if COMPQ = 'V', LDQ >= N.
21515 *
21516 * WR (output) DOUBLE PRECISION array, dimension (N)
21517 * WI (output) DOUBLE PRECISION array, dimension (N)
21518 * The real and imaginary parts, respectively, of the reordered
21519 * eigenvalues of T. The eigenvalues are stored in the same
21520 * order as on the diagonal of T, with WR(i) = T(i,i) and, if
21521 * T(i:i+1,i:i+1) is a 2-by-2 diagonal block, WI(i) > 0 and
21522 * WI(i+1) = -WI(i). Note that if a complex eigenvalue is
21523 * sufficiently ill-conditioned, then its value may differ
21524 * significantly from its value before reordering.
21525 *
21526 * M (output) INTEGER
21527 * The dimension of the specified invariant subspace.
21528 * 0 < = M <= N.
21529 *
21530 * S (output) DOUBLE PRECISION
21531 * If JOB = 'E' or 'B', S is a lower bound on the reciprocal
21532 * condition number for the selected cluster of eigenvalues.
21533 * S cannot underestimate the true reciprocal condition number
21534 * by more than a factor of sqrt(N). If M = 0 or N, S = 1.
21535 * If JOB = 'N' or 'V', S is not referenced.
21536 *
21537 * SEP (output) DOUBLE PRECISION
21538 * If JOB = 'V' or 'B', SEP is the estimated reciprocal
21539 * condition number of the specified invariant subspace. If
21540 * M = 0 or N, SEP = norm(T).
21541 * If JOB = 'N' or 'E', SEP is not referenced.
21542 *
21543 * WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
21544 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
21545 *
21546 * LWORK (input) INTEGER
21547 * The dimension of the array WORK.
21548 * If JOB = 'N', LWORK >= max(1,N);
21549 * if JOB = 'E', LWORK >= max(1,M*(N-M));
21550 * if JOB = 'V' or 'B', LWORK >= max(1,2*M*(N-M)).
21551 *
21552 * If LWORK = -1, then a workspace query is assumed; the routine
21553 * only calculates the optimal size of the WORK array, returns
21554 * this value as the first entry of the WORK array, and no error
21555 * message related to LWORK is issued by XERBLA.
21556 *
21557 * IWORK (workspace) INTEGER array, dimension (MAX(1,LIWORK))
21558 * On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
21559 *
21560 * LIWORK (input) INTEGER
21561 * The dimension of the array IWORK.
21562 * If JOB = 'N' or 'E', LIWORK >= 1;
21563 * if JOB = 'V' or 'B', LIWORK >= max(1,M*(N-M)).
21564 *
21565 * If LIWORK = -1, then a workspace query is assumed; the
21566 * routine only calculates the optimal size of the IWORK array,
21567 * returns this value as the first entry of the IWORK array, and
21568 * no error message related to LIWORK is issued by XERBLA.
21569 *
21570 * INFO (output) INTEGER
21571 * = 0: successful exit
21572 * < 0: if INFO = -i, the i-th argument had an illegal value
21573 * = 1: reordering of T failed because some eigenvalues are too
21574 * close to separate (the problem is very ill-conditioned);
21575 * T may have been partially reordered, and WR and WI
21576 * contain the eigenvalues in the same order as in T; S and
21577 * SEP (if requested) are set to zero.
21578 *
21579 * Further Details
21580 * ===============
21581 *
21582 * DTRSEN first collects the selected eigenvalues by computing an
21583 * orthogonal transformation Z to move them to the top left corner of T.
21584 * In other words, the selected eigenvalues are the eigenvalues of T11
21585 * in:
21586 *
21587 * Z'*T*Z = ( T11 T12 ) n1
21588 * ( 0 T22 ) n2
21589 * n1 n2
21590 *
21591 * where N = n1+n2 and Z' means the transpose of Z. The first n1 columns
21592 * of Z span the specified invariant subspace of T.
21593 *
21594 * If T has been obtained from the real Schur factorization of a matrix
21595 * A = Q*T*Q', then the reordered real Schur factorization of A is given
21596 * by A = (Q*Z)*(Z'*T*Z)*(Q*Z)', and the first n1 columns of Q*Z span
21597 * the corresponding invariant subspace of A.
21598 *
21599 * The reciprocal condition number of the average of the eigenvalues of
21600 * T11 may be returned in S. S lies between 0 (very badly conditioned)
21601 * and 1 (very well conditioned). It is computed as follows. First we
21602 * compute R so that
21603 *
21604 * P = ( I R ) n1
21605 * ( 0 0 ) n2
21606 * n1 n2
21607 *
21608 * is the projector on the invariant subspace associated with T11.
21609 * R is the solution of the Sylvester equation:
21610 *
21611 * T11*R - R*T22 = T12.
21612 *
21613 * Let F-norm(M) denote the Frobenius-norm of M and 2-norm(M) denote
21614 * the two-norm of M. Then S is computed as the lower bound
21615 *
21616 * (1 + F-norm(R)**2)**(-1/2)
21617 *
21618 * on the reciprocal of 2-norm(P), the true reciprocal condition number.
21619 * S cannot underestimate 1 / 2-norm(P) by more than a factor of
21620 * sqrt(N).
21621 *
21622 * An approximate error bound for the computed average of the
21623 * eigenvalues of T11 is
21624 *
21625 * EPS * norm(T) / S
21626 *
21627 * where EPS is the machine precision.
21628 *
21629 * The reciprocal condition number of the right invariant subspace
21630 * spanned by the first n1 columns of Z (or of Q*Z) is returned in SEP.
21631 * SEP is defined as the separation of T11 and T22:
21632 *
21633 * sep( T11, T22 ) = sigma-min( C )
21634 *
21635 * where sigma-min(C) is the smallest singular value of the
21636 * n1*n2-by-n1*n2 matrix
21637 *
21638 * C = kprod( I(n2), T11 ) - kprod( transpose(T22), I(n1) )
21639 *
21640 * I(m) is an m by m identity matrix, and kprod denotes the Kronecker
21641 * product. We estimate sigma-min(C) by the reciprocal of an estimate of
21642 * the 1-norm of inverse(C). The true reciprocal 1-norm of inverse(C)
21643 * cannot differ from sigma-min(C) by more than a factor of sqrt(n1*n2).
21644 *
21645 * When SEP is small, small changes in T can cause large changes in
21646 * the invariant subspace. An approximate bound on the maximum angular
21647 * error in the computed right invariant subspace is
21648 *
21649 * EPS * norm(T) / SEP
21650 *
21651 * =====================================================================
21652 *
21653 * .. Parameters ..
21654 DOUBLE PRECISION ZERO, ONE
21655 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
21656 * ..
21657 * .. Local Scalars ..
21658 LOGICAL LQUERY, PAIR, SWAP, WANTBH, WANTQ, WANTS,
21659 $ WANTSP
21660 INTEGER IERR, K, KASE, KK, KS, LIWMIN, LWMIN, N1, N2,
21661 $ NN
21662 DOUBLE PRECISION EST, RNORM, SCALE
21663 * ..
21664 * .. Local Arrays ..
21665 INTEGER ISAVE( 3 )
21666 * ..
21667 * .. External Functions ..
21668 LOGICAL LSAME
21669 DOUBLE PRECISION DLANGE
21670 EXTERNAL LSAME, DLANGE
21671 * ..
21672 * .. External Subroutines ..
21673 EXTERNAL DLACN2, DLACPY, DTREXC, DTRSYL, XERBLA
21674 * ..
21675 * .. Intrinsic Functions ..
21676 INTRINSIC ABS, MAX, SQRT
21677 * ..
21678 * .. Executable Statements ..
21679 *
21680 * Decode and test the input parameters
21681 *
21682 WANTBH = LSAME( JOB, 'B' )
21683 WANTS = LSAME( JOB, 'E' ) .OR. WANTBH
21684 WANTSP = LSAME( JOB, 'V' ) .OR. WANTBH
21685 WANTQ = LSAME( COMPQ, 'V' )
21686 *
21687 INFO = 0
21688 LQUERY = ( LWORK.EQ.-1 )
21689 IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.WANTS .AND. .NOT.WANTSP )
21690 $ THEN
21691 INFO = -1
21692 ELSE IF( .NOT.LSAME( COMPQ, 'N' ) .AND. .NOT.WANTQ ) THEN
21693 INFO = -2
21694 ELSE IF( N.LT.0 ) THEN
21695 INFO = -4
21696 ELSE IF( LDT.LT.MAX( 1, N ) ) THEN
21697 INFO = -6
21698 ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.N ) ) THEN
21699 INFO = -8
21700 ELSE
21701 *
21702 * Set M to the dimension of the specified invariant subspace,
21703 * and test LWORK and LIWORK.
21704 *
21705 M = 0
21706 PAIR = .FALSE.
21707 DO 10 K = 1, N
21708 IF( PAIR ) THEN
21709 PAIR = .FALSE.
21710 ELSE
21711 IF( K.LT.N ) THEN
21712 IF( T( K+1, K ).EQ.ZERO ) THEN
21713 IF( SELECT( K ) )
21714 $ M = M + 1
21715 ELSE
21716 PAIR = .TRUE.
21717 IF( SELECT( K ) .OR. SELECT( K+1 ) )
21718 $ M = M + 2
21719 END IF
21720 ELSE
21721 IF( SELECT( N ) )
21722 $ M = M + 1
21723 END IF
21724 END IF
21725 10 CONTINUE
21726 *
21727 N1 = M
21728 N2 = N - M
21729 NN = N1*N2
21730 *
21731 IF( WANTSP ) THEN
21732 LWMIN = MAX( 1, 2*NN )
21733 LIWMIN = MAX( 1, NN )
21734 ELSE IF( LSAME( JOB, 'N' ) ) THEN
21735 LWMIN = MAX( 1, N )
21736 LIWMIN = 1
21737 ELSE IF( LSAME( JOB, 'E' ) ) THEN
21738 LWMIN = MAX( 1, NN )
21739 LIWMIN = 1
21740 END IF
21741 *
21742 IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
21743 INFO = -15
21744 ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
21745 INFO = -17
21746 END IF
21747 END IF
21748 *
21749 IF( INFO.EQ.0 ) THEN
21750 WORK( 1 ) = LWMIN
21751 IWORK( 1 ) = LIWMIN
21752 END IF
21753 *
21754 IF( INFO.NE.0 ) THEN
21755 CALL XERBLA( 'DTRSEN', -INFO )
21756 RETURN
21757 ELSE IF( LQUERY ) THEN
21758 RETURN
21759 END IF
21760 *
21761 * Quick return if possible.
21762 *
21763 IF( M.EQ.N .OR. M.EQ.0 ) THEN
21764 IF( WANTS )
21765 $ S = ONE
21766 IF( WANTSP )
21767 $ SEP = DLANGE( '1', N, N, T, LDT, WORK )
21768 GO TO 40
21769 END IF
21770 *
21771 * Collect the selected blocks at the top-left corner of T.
21772 *
21773 KS = 0
21774 PAIR = .FALSE.
21775 DO 20 K = 1, N
21776 IF( PAIR ) THEN
21777 PAIR = .FALSE.
21778 ELSE
21779 SWAP = SELECT( K )
21780 IF( K.LT.N ) THEN
21781 IF( T( K+1, K ).NE.ZERO ) THEN
21782 PAIR = .TRUE.
21783 SWAP = SWAP .OR. SELECT( K+1 )
21784 END IF
21785 END IF
21786 IF( SWAP ) THEN
21787 KS = KS + 1
21788 *
21789 * Swap the K-th block to position KS.
21790 *
21791 IERR = 0
21792 KK = K
21793 IF( K.NE.KS )
21794 $ CALL DTREXC( COMPQ, N, T, LDT, Q, LDQ, KK, KS, WORK,
21795 $ IERR )
21796 IF( IERR.EQ.1 .OR. IERR.EQ.2 ) THEN
21797 *
21798 * Blocks too close to swap: exit.
21799 *
21800 INFO = 1
21801 IF( WANTS )
21802 $ S = ZERO
21803 IF( WANTSP )
21804 $ SEP = ZERO
21805 GO TO 40
21806 END IF
21807 IF( PAIR )
21808 $ KS = KS + 1
21809 END IF
21810 END IF
21811 20 CONTINUE
21812 *
21813 IF( WANTS ) THEN
21814 *
21815 * Solve Sylvester equation for R:
21816 *
21817 * T11*R - R*T22 = scale*T12
21818 *
21819 CALL DLACPY( 'F', N1, N2, T( 1, N1+1 ), LDT, WORK, N1 )
21820 CALL DTRSYL( 'N', 'N', -1, N1, N2, T, LDT, T( N1+1, N1+1 ),
21821 $ LDT, WORK, N1, SCALE, IERR )
21822 *
21823 * Estimate the reciprocal of the condition number of the cluster
21824 * of eigenvalues.
21825 *
21826 RNORM = DLANGE( 'F', N1, N2, WORK, N1, WORK )
21827 IF( RNORM.EQ.ZERO ) THEN
21828 S = ONE
21829 ELSE
21830 S = SCALE / ( SQRT( SCALE*SCALE / RNORM+RNORM )*
21831 $ SQRT( RNORM ) )
21832 END IF
21833 END IF
21834 *
21835 IF( WANTSP ) THEN
21836 *
21837 * Estimate sep(T11,T22).
21838 *
21839 EST = ZERO
21840 KASE = 0
21841 30 CONTINUE
21842 CALL DLACN2( NN, WORK( NN+1 ), WORK, IWORK, EST, KASE, ISAVE )
21843 IF( KASE.NE.0 ) THEN
21844 IF( KASE.EQ.1 ) THEN
21845 *
21846 * Solve T11*R - R*T22 = scale*X.
21847 *
21848 CALL DTRSYL( 'N', 'N', -1, N1, N2, T, LDT,
21849 $ T( N1+1, N1+1 ), LDT, WORK, N1, SCALE,
21850 $ IERR )
21851 ELSE
21852 *
21853 * Solve T11'*R - R*T22' = scale*X.
21854 *
21855 CALL DTRSYL( 'T', 'T', -1, N1, N2, T, LDT,
21856 $ T( N1+1, N1+1 ), LDT, WORK, N1, SCALE,
21857 $ IERR )
21858 END IF
21859 GO TO 30
21860 END IF
21861 *
21862 SEP = SCALE / EST
21863 END IF
21864 *
21865 40 CONTINUE
21866 *
21867 * Store the output eigenvalues in WR and WI.
21868 *
21869 DO 50 K = 1, N
21870 WR( K ) = T( K, K )
21871 WI( K ) = ZERO
21872 50 CONTINUE
21873 DO 60 K = 1, N - 1
21874 IF( T( K+1, K ).NE.ZERO ) THEN
21875 WI( K ) = SQRT( ABS( T( K, K+1 ) ) )*
21876 $ SQRT( ABS( T( K+1, K ) ) )
21877 WI( K+1 ) = -WI( K )
21878 END IF
21879 60 CONTINUE
21880 *
21881 WORK( 1 ) = LWMIN
21882 IWORK( 1 ) = LIWMIN
21883 *
21884 RETURN
21885 *
21886 * End of DTRSEN
21887 *
21888 END
21889 C
21890 C-----------------------------------------------------------------------
21891 C-----------------------------------------------------------------------
21892 SUBROUTINE DTRSYL( TRANA, TRANB, ISGN, M, N, A, LDA, B, LDB, C,
21893 $ LDC, SCALE, INFO )
21894 *
21895 * -- LAPACK routine (version 3.2) --
21896 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
21897 * November 2006
21898 *
21899 * .. Scalar Arguments ..
21900 CHARACTER TRANA, TRANB
21901 INTEGER INFO, ISGN, LDA, LDB, LDC, M, N
21902 DOUBLE PRECISION SCALE
21903 * ..
21904 * .. Array Arguments ..
21905 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( LDC, * )
21906 * ..
21907 *
21908 * Purpose
21909 * =======
21910 *
21911 * DTRSYL solves the real Sylvester matrix equation:
21912 *
21913 * op(A)*X + X*op(B) = scale*C or
21914 * op(A)*X - X*op(B) = scale*C,
21915 *
21916 * where op(A) = A or A**T, and A and B are both upper quasi-
21917 * triangular. A is M-by-M and B is N-by-N; the right hand side C and
21918 * the solution X are M-by-N; and scale is an output scale factor, set
21919 * <= 1 to avoid overflow in X.
21920 *
21921 * A and B must be in Schur canonical form (as returned by DHSEQR), that
21922 * is, block upper triangular with 1-by-1 and 2-by-2 diagonal blocks;
21923 * each 2-by-2 diagonal block has its diagonal elements equal and its
21924 * off-diagonal elements of opposite sign.
21925 *
21926 * Arguments
21927 * =========
21928 *
21929 * TRANA (input) CHARACTER*1
21930 * Specifies the option op(A):
21931 * = 'N': op(A) = A (No transpose)
21932 * = 'T': op(A) = A**T (Transpose)
21933 * = 'C': op(A) = A**H (Conjugate transpose = Transpose)
21934 *
21935 * TRANB (input) CHARACTER*1
21936 * Specifies the option op(B):
21937 * = 'N': op(B) = B (No transpose)
21938 * = 'T': op(B) = B**T (Transpose)
21939 * = 'C': op(B) = B**H (Conjugate transpose = Transpose)
21940 *
21941 * ISGN (input) INTEGER
21942 * Specifies the sign in the equation:
21943 * = +1: solve op(A)*X + X*op(B) = scale*C
21944 * = -1: solve op(A)*X - X*op(B) = scale*C
21945 *
21946 * M (input) INTEGER
21947 * The order of the matrix A, and the number of rows in the
21948 * matrices X and C. M >= 0.
21949 *
21950 * N (input) INTEGER
21951 * The order of the matrix B, and the number of columns in the
21952 * matrices X and C. N >= 0.
21953 *
21954 * A (input) DOUBLE PRECISION array, dimension (LDA,M)
21955 * The upper quasi-triangular matrix A, in Schur canonical form.
21956 *
21957 * LDA (input) INTEGER
21958 * The leading dimension of the array A. LDA >= max(1,M).
21959 *
21960 * B (input) DOUBLE PRECISION array, dimension (LDB,N)
21961 * The upper quasi-triangular matrix B, in Schur canonical form.
21962 *
21963 * LDB (input) INTEGER
21964 * The leading dimension of the array B. LDB >= max(1,N).
21965 *
21966 * C (input/output) DOUBLE PRECISION array, dimension (LDC,N)
21967 * On entry, the M-by-N right hand side matrix C.
21968 * On exit, C is overwritten by the solution matrix X.
21969 *
21970 * LDC (input) INTEGER
21971 * The leading dimension of the array C. LDC >= max(1,M)
21972 *
21973 * SCALE (output) DOUBLE PRECISION
21974 * The scale factor, scale, set <= 1 to avoid overflow in X.
21975 *
21976 * INFO (output) INTEGER
21977 * = 0: successful exit
21978 * < 0: if INFO = -i, the i-th argument had an illegal value
21979 * = 1: A and B have common or very close eigenvalues; perturbed
21980 * values were used to solve the equation (but the matrices
21981 * A and B are unchanged).
21982 *
21983 * =====================================================================
21984 *
21985 * .. Parameters ..
21986 DOUBLE PRECISION ZERO, ONE
21987 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
21988 * ..
21989 * .. Local Scalars ..
21990 LOGICAL NOTRNA, NOTRNB
21991 INTEGER IERR, J, K, K1, K2, KNEXT, L, L1, L2, LNEXT
21992 DOUBLE PRECISION A11, BIGNUM, DA11, DB, EPS, SCALOC, SGN, SMIN,
21993 $ SMLNUM, SUML, SUMR, XNORM
21994 * ..
21995 * .. Local Arrays ..
21996 DOUBLE PRECISION DUM( 1 ), VEC( 2, 2 ), X( 2, 2 )
21997 * ..
21998 * .. External Functions ..
21999 LOGICAL LSAME
22000 DOUBLE PRECISION DDOT, DLAMCH, DLANGE
22001 EXTERNAL LSAME, DDOT, DLAMCH, DLANGE
22002 * ..
22003 * .. External Subroutines ..
22004 EXTERNAL DLABAD, DLALN2, DLASY2, DSCAL, XERBLA
22005 * ..
22006 * .. Intrinsic Functions ..
22007 INTRINSIC ABS, DBLE, MAX, MIN
22008 * ..
22009 * .. Executable Statements ..
22010 *
22011 * Decode and Test input parameters
22012 *
22013 NOTRNA = LSAME( TRANA, 'N' )
22014 NOTRNB = LSAME( TRANB, 'N' )
22015 *
22016 INFO = 0
22017 IF( .NOT.NOTRNA .AND. .NOT.LSAME( TRANA, 'T' ) .AND. .NOT.
22018 $ LSAME( TRANA, 'C' ) ) THEN
22019 INFO = -1
22020 ELSE IF( .NOT.NOTRNB .AND. .NOT.LSAME( TRANB, 'T' ) .AND. .NOT.
22021 $ LSAME( TRANB, 'C' ) ) THEN
22022 INFO = -2
22023 ELSE IF( ISGN.NE.1 .AND. ISGN.NE.-1 ) THEN
22024 INFO = -3
22025 ELSE IF( M.LT.0 ) THEN
22026 INFO = -4
22027 ELSE IF( N.LT.0 ) THEN
22028 INFO = -5
22029 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
22030 INFO = -7
22031 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
22032 INFO = -9
22033 ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
22034 INFO = -11
22035 END IF
22036 IF( INFO.NE.0 ) THEN
22037 CALL XERBLA( 'DTRSYL', -INFO )
22038 RETURN
22039 END IF
22040 *
22041 * Quick return if possible
22042 *
22043 IF( M.EQ.0 .OR. N.EQ.0 )
22044 $ RETURN
22045 *
22046 * Set constants to control overflow
22047 *
22048 EPS = DLAMCH( 'P' )
22049 SMLNUM = DLAMCH( 'S' )
22050 BIGNUM = ONE / SMLNUM
22051 CALL DLABAD( SMLNUM, BIGNUM )
22052 SMLNUM = SMLNUM*DBLE( M*N ) / EPS
22053 BIGNUM = ONE / SMLNUM
22054 *
22055 SMIN = MAX( SMLNUM, EPS*DLANGE( 'M', M, M, A, LDA, DUM ),
22056 $ EPS*DLANGE( 'M', N, N, B, LDB, DUM ) )
22057 *
22058 SCALE = ONE
22059 SGN = ISGN
22060 *
22061 IF( NOTRNA .AND. NOTRNB ) THEN
22062 *
22063 * Solve A*X + ISGN*X*B = scale*C.
22064 *
22065 * The (K,L)th block of X is determined starting from
22066 * bottom-left corner column by column by
22067 *
22068 * A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L)
22069 *
22070 * Where
22071 * M L-1
22072 * R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(J,L)].
22073 * I=K+1 J=1
22074 *
22075 * Start column loop (index = L)
22076 * L1 (L2) : column index of the first (first) row of X(K,L).
22077 *
22078 LNEXT = 1
22079 DO 60 L = 1, N
22080 IF( L.LT.LNEXT )
22081 $ GO TO 60
22082 IF( L.EQ.N ) THEN
22083 L1 = L
22084 L2 = L
22085 ELSE
22086 IF( B( L+1, L ).NE.ZERO ) THEN
22087 L1 = L
22088 L2 = L + 1
22089 LNEXT = L + 2
22090 ELSE
22091 L1 = L
22092 L2 = L
22093 LNEXT = L + 1
22094 END IF
22095 END IF
22096 *
22097 * Start row loop (index = K)
22098 * K1 (K2): row index of the first (last) row of X(K,L).
22099 *
22100 KNEXT = M
22101 DO 50 K = M, 1, -1
22102 IF( K.GT.KNEXT )
22103 $ GO TO 50
22104 IF( K.EQ.1 ) THEN
22105 K1 = K
22106 K2 = K
22107 ELSE
22108 IF( A( K, K-1 ).NE.ZERO ) THEN
22109 K1 = K - 1
22110 K2 = K
22111 KNEXT = K - 2
22112 ELSE
22113 K1 = K
22114 K2 = K
22115 KNEXT = K - 1
22116 END IF
22117 END IF
22118 *
22119 IF( L1.EQ.L2 .AND. K1.EQ.K2 ) THEN
22120 SUML = DDOT( M-K1, A( K1, MIN( K1+1, M ) ), LDA,
22121 $ C( MIN( K1+1, M ), L1 ), 1 )
22122 SUMR = DDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
22123 VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
22124 SCALOC = ONE
22125 *
22126 A11 = A( K1, K1 ) + SGN*B( L1, L1 )
22127 DA11 = ABS( A11 )
22128 IF( DA11.LE.SMIN ) THEN
22129 A11 = SMIN
22130 DA11 = SMIN
22131 INFO = 1
22132 END IF
22133 DB = ABS( VEC( 1, 1 ) )
22134 IF( DA11.LT.ONE .AND. DB.GT.ONE ) THEN
22135 IF( DB.GT.BIGNUM*DA11 )
22136 $ SCALOC = ONE / DB
22137 END IF
22138 X( 1, 1 ) = ( VEC( 1, 1 )*SCALOC ) / A11
22139 *
22140 IF( SCALOC.NE.ONE ) THEN
22141 DO 10 J = 1, N
22142 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22143 10 CONTINUE
22144 SCALE = SCALE*SCALOC
22145 END IF
22146 C( K1, L1 ) = X( 1, 1 )
22147 *
22148 ELSE IF( L1.EQ.L2 .AND. K1.NE.K2 ) THEN
22149 *
22150 SUML = DDOT( M-K2, A( K1, MIN( K2+1, M ) ), LDA,
22151 $ C( MIN( K2+1, M ), L1 ), 1 )
22152 SUMR = DDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
22153 VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
22154 *
22155 SUML = DDOT( M-K2, A( K2, MIN( K2+1, M ) ), LDA,
22156 $ C( MIN( K2+1, M ), L1 ), 1 )
22157 SUMR = DDOT( L1-1, C( K2, 1 ), LDC, B( 1, L1 ), 1 )
22158 VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
22159 *
22160 CALL DLALN2( .FALSE., 2, 1, SMIN, ONE, A( K1, K1 ),
22161 $ LDA, ONE, ONE, VEC, 2, -SGN*B( L1, L1 ),
22162 $ ZERO, X, 2, SCALOC, XNORM, IERR )
22163 IF( IERR.NE.0 )
22164 $ INFO = 1
22165 *
22166 IF( SCALOC.NE.ONE ) THEN
22167 DO 20 J = 1, N
22168 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22169 20 CONTINUE
22170 SCALE = SCALE*SCALOC
22171 END IF
22172 C( K1, L1 ) = X( 1, 1 )
22173 C( K2, L1 ) = X( 2, 1 )
22174 *
22175 ELSE IF( L1.NE.L2 .AND. K1.EQ.K2 ) THEN
22176 *
22177 SUML = DDOT( M-K1, A( K1, MIN( K1+1, M ) ), LDA,
22178 $ C( MIN( K1+1, M ), L1 ), 1 )
22179 SUMR = DDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
22180 VEC( 1, 1 ) = SGN*( C( K1, L1 )-( SUML+SGN*SUMR ) )
22181 *
22182 SUML = DDOT( M-K1, A( K1, MIN( K1+1, M ) ), LDA,
22183 $ C( MIN( K1+1, M ), L2 ), 1 )
22184 SUMR = DDOT( L1-1, C( K1, 1 ), LDC, B( 1, L2 ), 1 )
22185 VEC( 2, 1 ) = SGN*( C( K1, L2 )-( SUML+SGN*SUMR ) )
22186 *
22187 CALL DLALN2( .TRUE., 2, 1, SMIN, ONE, B( L1, L1 ),
22188 $ LDB, ONE, ONE, VEC, 2, -SGN*A( K1, K1 ),
22189 $ ZERO, X, 2, SCALOC, XNORM, IERR )
22190 IF( IERR.NE.0 )
22191 $ INFO = 1
22192 *
22193 IF( SCALOC.NE.ONE ) THEN
22194 DO 30 J = 1, N
22195 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22196 30 CONTINUE
22197 SCALE = SCALE*SCALOC
22198 END IF
22199 C( K1, L1 ) = X( 1, 1 )
22200 C( K1, L2 ) = X( 2, 1 )
22201 *
22202 ELSE IF( L1.NE.L2 .AND. K1.NE.K2 ) THEN
22203 *
22204 SUML = DDOT( M-K2, A( K1, MIN( K2+1, M ) ), LDA,
22205 $ C( MIN( K2+1, M ), L1 ), 1 )
22206 SUMR = DDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
22207 VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
22208 *
22209 SUML = DDOT( M-K2, A( K1, MIN( K2+1, M ) ), LDA,
22210 $ C( MIN( K2+1, M ), L2 ), 1 )
22211 SUMR = DDOT( L1-1, C( K1, 1 ), LDC, B( 1, L2 ), 1 )
22212 VEC( 1, 2 ) = C( K1, L2 ) - ( SUML+SGN*SUMR )
22213 *
22214 SUML = DDOT( M-K2, A( K2, MIN( K2+1, M ) ), LDA,
22215 $ C( MIN( K2+1, M ), L1 ), 1 )
22216 SUMR = DDOT( L1-1, C( K2, 1 ), LDC, B( 1, L1 ), 1 )
22217 VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
22218 *
22219 SUML = DDOT( M-K2, A( K2, MIN( K2+1, M ) ), LDA,
22220 $ C( MIN( K2+1, M ), L2 ), 1 )
22221 SUMR = DDOT( L1-1, C( K2, 1 ), LDC, B( 1, L2 ), 1 )
22222 VEC( 2, 2 ) = C( K2, L2 ) - ( SUML+SGN*SUMR )
22223 *
22224 CALL DLASY2( .FALSE., .FALSE., ISGN, 2, 2,
22225 $ A( K1, K1 ), LDA, B( L1, L1 ), LDB, VEC,
22226 $ 2, SCALOC, X, 2, XNORM, IERR )
22227 IF( IERR.NE.0 )
22228 $ INFO = 1
22229 *
22230 IF( SCALOC.NE.ONE ) THEN
22231 DO 40 J = 1, N
22232 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22233 40 CONTINUE
22234 SCALE = SCALE*SCALOC
22235 END IF
22236 C( K1, L1 ) = X( 1, 1 )
22237 C( K1, L2 ) = X( 1, 2 )
22238 C( K2, L1 ) = X( 2, 1 )
22239 C( K2, L2 ) = X( 2, 2 )
22240 END IF
22241 *
22242 50 CONTINUE
22243 *
22244 60 CONTINUE
22245 *
22246 ELSE IF( .NOT.NOTRNA .AND. NOTRNB ) THEN
22247 *
22248 * Solve A' *X + ISGN*X*B = scale*C.
22249 *
22250 * The (K,L)th block of X is determined starting from
22251 * upper-left corner column by column by
22252 *
22253 * A(K,K)'*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L)
22254 *
22255 * Where
22256 * K-1 L-1
22257 * R(K,L) = SUM [A(I,K)'*X(I,L)] +ISGN*SUM [X(K,J)*B(J,L)]
22258 * I=1 J=1
22259 *
22260 * Start column loop (index = L)
22261 * L1 (L2): column index of the first (last) row of X(K,L)
22262 *
22263 LNEXT = 1
22264 DO 120 L = 1, N
22265 IF( L.LT.LNEXT )
22266 $ GO TO 120
22267 IF( L.EQ.N ) THEN
22268 L1 = L
22269 L2 = L
22270 ELSE
22271 IF( B( L+1, L ).NE.ZERO ) THEN
22272 L1 = L
22273 L2 = L + 1
22274 LNEXT = L + 2
22275 ELSE
22276 L1 = L
22277 L2 = L
22278 LNEXT = L + 1
22279 END IF
22280 END IF
22281 *
22282 * Start row loop (index = K)
22283 * K1 (K2): row index of the first (last) row of X(K,L)
22284 *
22285 KNEXT = 1
22286 DO 110 K = 1, M
22287 IF( K.LT.KNEXT )
22288 $ GO TO 110
22289 IF( K.EQ.M ) THEN
22290 K1 = K
22291 K2 = K
22292 ELSE
22293 IF( A( K+1, K ).NE.ZERO ) THEN
22294 K1 = K
22295 K2 = K + 1
22296 KNEXT = K + 2
22297 ELSE
22298 K1 = K
22299 K2 = K
22300 KNEXT = K + 1
22301 END IF
22302 END IF
22303 *
22304 IF( L1.EQ.L2 .AND. K1.EQ.K2 ) THEN
22305 SUML = DDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
22306 SUMR = DDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
22307 VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
22308 SCALOC = ONE
22309 *
22310 A11 = A( K1, K1 ) + SGN*B( L1, L1 )
22311 DA11 = ABS( A11 )
22312 IF( DA11.LE.SMIN ) THEN
22313 A11 = SMIN
22314 DA11 = SMIN
22315 INFO = 1
22316 END IF
22317 DB = ABS( VEC( 1, 1 ) )
22318 IF( DA11.LT.ONE .AND. DB.GT.ONE ) THEN
22319 IF( DB.GT.BIGNUM*DA11 )
22320 $ SCALOC = ONE / DB
22321 END IF
22322 X( 1, 1 ) = ( VEC( 1, 1 )*SCALOC ) / A11
22323 *
22324 IF( SCALOC.NE.ONE ) THEN
22325 DO 70 J = 1, N
22326 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22327 70 CONTINUE
22328 SCALE = SCALE*SCALOC
22329 END IF
22330 C( K1, L1 ) = X( 1, 1 )
22331 *
22332 ELSE IF( L1.EQ.L2 .AND. K1.NE.K2 ) THEN
22333 *
22334 SUML = DDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
22335 SUMR = DDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
22336 VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
22337 *
22338 SUML = DDOT( K1-1, A( 1, K2 ), 1, C( 1, L1 ), 1 )
22339 SUMR = DDOT( L1-1, C( K2, 1 ), LDC, B( 1, L1 ), 1 )
22340 VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
22341 *
22342 CALL DLALN2( .TRUE., 2, 1, SMIN, ONE, A( K1, K1 ),
22343 $ LDA, ONE, ONE, VEC, 2, -SGN*B( L1, L1 ),
22344 $ ZERO, X, 2, SCALOC, XNORM, IERR )
22345 IF( IERR.NE.0 )
22346 $ INFO = 1
22347 *
22348 IF( SCALOC.NE.ONE ) THEN
22349 DO 80 J = 1, N
22350 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22351 80 CONTINUE
22352 SCALE = SCALE*SCALOC
22353 END IF
22354 C( K1, L1 ) = X( 1, 1 )
22355 C( K2, L1 ) = X( 2, 1 )
22356 *
22357 ELSE IF( L1.NE.L2 .AND. K1.EQ.K2 ) THEN
22358 *
22359 SUML = DDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
22360 SUMR = DDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
22361 VEC( 1, 1 ) = SGN*( C( K1, L1 )-( SUML+SGN*SUMR ) )
22362 *
22363 SUML = DDOT( K1-1, A( 1, K1 ), 1, C( 1, L2 ), 1 )
22364 SUMR = DDOT( L1-1, C( K1, 1 ), LDC, B( 1, L2 ), 1 )
22365 VEC( 2, 1 ) = SGN*( C( K1, L2 )-( SUML+SGN*SUMR ) )
22366 *
22367 CALL DLALN2( .TRUE., 2, 1, SMIN, ONE, B( L1, L1 ),
22368 $ LDB, ONE, ONE, VEC, 2, -SGN*A( K1, K1 ),
22369 $ ZERO, X, 2, SCALOC, XNORM, IERR )
22370 IF( IERR.NE.0 )
22371 $ INFO = 1
22372 *
22373 IF( SCALOC.NE.ONE ) THEN
22374 DO 90 J = 1, N
22375 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22376 90 CONTINUE
22377 SCALE = SCALE*SCALOC
22378 END IF
22379 C( K1, L1 ) = X( 1, 1 )
22380 C( K1, L2 ) = X( 2, 1 )
22381 *
22382 ELSE IF( L1.NE.L2 .AND. K1.NE.K2 ) THEN
22383 *
22384 SUML = DDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
22385 SUMR = DDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
22386 VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
22387 *
22388 SUML = DDOT( K1-1, A( 1, K1 ), 1, C( 1, L2 ), 1 )
22389 SUMR = DDOT( L1-1, C( K1, 1 ), LDC, B( 1, L2 ), 1 )
22390 VEC( 1, 2 ) = C( K1, L2 ) - ( SUML+SGN*SUMR )
22391 *
22392 SUML = DDOT( K1-1, A( 1, K2 ), 1, C( 1, L1 ), 1 )
22393 SUMR = DDOT( L1-1, C( K2, 1 ), LDC, B( 1, L1 ), 1 )
22394 VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
22395 *
22396 SUML = DDOT( K1-1, A( 1, K2 ), 1, C( 1, L2 ), 1 )
22397 SUMR = DDOT( L1-1, C( K2, 1 ), LDC, B( 1, L2 ), 1 )
22398 VEC( 2, 2 ) = C( K2, L2 ) - ( SUML+SGN*SUMR )
22399 *
22400 CALL DLASY2( .TRUE., .FALSE., ISGN, 2, 2, A( K1, K1 ),
22401 $ LDA, B( L1, L1 ), LDB, VEC, 2, SCALOC, X,
22402 $ 2, XNORM, IERR )
22403 IF( IERR.NE.0 )
22404 $ INFO = 1
22405 *
22406 IF( SCALOC.NE.ONE ) THEN
22407 DO 100 J = 1, N
22408 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22409 100 CONTINUE
22410 SCALE = SCALE*SCALOC
22411 END IF
22412 C( K1, L1 ) = X( 1, 1 )
22413 C( K1, L2 ) = X( 1, 2 )
22414 C( K2, L1 ) = X( 2, 1 )
22415 C( K2, L2 ) = X( 2, 2 )
22416 END IF
22417 *
22418 110 CONTINUE
22419 120 CONTINUE
22420 *
22421 ELSE IF( .NOT.NOTRNA .AND. .NOT.NOTRNB ) THEN
22422 *
22423 * Solve A'*X + ISGN*X*B' = scale*C.
22424 *
22425 * The (K,L)th block of X is determined starting from
22426 * top-right corner column by column by
22427 *
22428 * A(K,K)'*X(K,L) + ISGN*X(K,L)*B(L,L)' = C(K,L) - R(K,L)
22429 *
22430 * Where
22431 * K-1 N
22432 * R(K,L) = SUM [A(I,K)'*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)'].
22433 * I=1 J=L+1
22434 *
22435 * Start column loop (index = L)
22436 * L1 (L2): column index of the first (last) row of X(K,L)
22437 *
22438 LNEXT = N
22439 DO 180 L = N, 1, -1
22440 IF( L.GT.LNEXT )
22441 $ GO TO 180
22442 IF( L.EQ.1 ) THEN
22443 L1 = L
22444 L2 = L
22445 ELSE
22446 IF( B( L, L-1 ).NE.ZERO ) THEN
22447 L1 = L - 1
22448 L2 = L
22449 LNEXT = L - 2
22450 ELSE
22451 L1 = L
22452 L2 = L
22453 LNEXT = L - 1
22454 END IF
22455 END IF
22456 *
22457 * Start row loop (index = K)
22458 * K1 (K2): row index of the first (last) row of X(K,L)
22459 *
22460 KNEXT = 1
22461 DO 170 K = 1, M
22462 IF( K.LT.KNEXT )
22463 $ GO TO 170
22464 IF( K.EQ.M ) THEN
22465 K1 = K
22466 K2 = K
22467 ELSE
22468 IF( A( K+1, K ).NE.ZERO ) THEN
22469 K1 = K
22470 K2 = K + 1
22471 KNEXT = K + 2
22472 ELSE
22473 K1 = K
22474 K2 = K
22475 KNEXT = K + 1
22476 END IF
22477 END IF
22478 *
22479 IF( L1.EQ.L2 .AND. K1.EQ.K2 ) THEN
22480 SUML = DDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
22481 SUMR = DDOT( N-L1, C( K1, MIN( L1+1, N ) ), LDC,
22482 $ B( L1, MIN( L1+1, N ) ), LDB )
22483 VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
22484 SCALOC = ONE
22485 *
22486 A11 = A( K1, K1 ) + SGN*B( L1, L1 )
22487 DA11 = ABS( A11 )
22488 IF( DA11.LE.SMIN ) THEN
22489 A11 = SMIN
22490 DA11 = SMIN
22491 INFO = 1
22492 END IF
22493 DB = ABS( VEC( 1, 1 ) )
22494 IF( DA11.LT.ONE .AND. DB.GT.ONE ) THEN
22495 IF( DB.GT.BIGNUM*DA11 )
22496 $ SCALOC = ONE / DB
22497 END IF
22498 X( 1, 1 ) = ( VEC( 1, 1 )*SCALOC ) / A11
22499 *
22500 IF( SCALOC.NE.ONE ) THEN
22501 DO 130 J = 1, N
22502 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22503 130 CONTINUE
22504 SCALE = SCALE*SCALOC
22505 END IF
22506 C( K1, L1 ) = X( 1, 1 )
22507 *
22508 ELSE IF( L1.EQ.L2 .AND. K1.NE.K2 ) THEN
22509 *
22510 SUML = DDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
22511 SUMR = DDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
22512 $ B( L1, MIN( L2+1, N ) ), LDB )
22513 VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
22514 *
22515 SUML = DDOT( K1-1, A( 1, K2 ), 1, C( 1, L1 ), 1 )
22516 SUMR = DDOT( N-L2, C( K2, MIN( L2+1, N ) ), LDC,
22517 $ B( L1, MIN( L2+1, N ) ), LDB )
22518 VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
22519 *
22520 CALL DLALN2( .TRUE., 2, 1, SMIN, ONE, A( K1, K1 ),
22521 $ LDA, ONE, ONE, VEC, 2, -SGN*B( L1, L1 ),
22522 $ ZERO, X, 2, SCALOC, XNORM, IERR )
22523 IF( IERR.NE.0 )
22524 $ INFO = 1
22525 *
22526 IF( SCALOC.NE.ONE ) THEN
22527 DO 140 J = 1, N
22528 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22529 140 CONTINUE
22530 SCALE = SCALE*SCALOC
22531 END IF
22532 C( K1, L1 ) = X( 1, 1 )
22533 C( K2, L1 ) = X( 2, 1 )
22534 *
22535 ELSE IF( L1.NE.L2 .AND. K1.EQ.K2 ) THEN
22536 *
22537 SUML = DDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
22538 SUMR = DDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
22539 $ B( L1, MIN( L2+1, N ) ), LDB )
22540 VEC( 1, 1 ) = SGN*( C( K1, L1 )-( SUML+SGN*SUMR ) )
22541 *
22542 SUML = DDOT( K1-1, A( 1, K1 ), 1, C( 1, L2 ), 1 )
22543 SUMR = DDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
22544 $ B( L2, MIN( L2+1, N ) ), LDB )
22545 VEC( 2, 1 ) = SGN*( C( K1, L2 )-( SUML+SGN*SUMR ) )
22546 *
22547 CALL DLALN2( .FALSE., 2, 1, SMIN, ONE, B( L1, L1 ),
22548 $ LDB, ONE, ONE, VEC, 2, -SGN*A( K1, K1 ),
22549 $ ZERO, X, 2, SCALOC, XNORM, IERR )
22550 IF( IERR.NE.0 )
22551 $ INFO = 1
22552 *
22553 IF( SCALOC.NE.ONE ) THEN
22554 DO 150 J = 1, N
22555 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22556 150 CONTINUE
22557 SCALE = SCALE*SCALOC
22558 END IF
22559 C( K1, L1 ) = X( 1, 1 )
22560 C( K1, L2 ) = X( 2, 1 )
22561 *
22562 ELSE IF( L1.NE.L2 .AND. K1.NE.K2 ) THEN
22563 *
22564 SUML = DDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
22565 SUMR = DDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
22566 $ B( L1, MIN( L2+1, N ) ), LDB )
22567 VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
22568 *
22569 SUML = DDOT( K1-1, A( 1, K1 ), 1, C( 1, L2 ), 1 )
22570 SUMR = DDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
22571 $ B( L2, MIN( L2+1, N ) ), LDB )
22572 VEC( 1, 2 ) = C( K1, L2 ) - ( SUML+SGN*SUMR )
22573 *
22574 SUML = DDOT( K1-1, A( 1, K2 ), 1, C( 1, L1 ), 1 )
22575 SUMR = DDOT( N-L2, C( K2, MIN( L2+1, N ) ), LDC,
22576 $ B( L1, MIN( L2+1, N ) ), LDB )
22577 VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
22578 *
22579 SUML = DDOT( K1-1, A( 1, K2 ), 1, C( 1, L2 ), 1 )
22580 SUMR = DDOT( N-L2, C( K2, MIN( L2+1, N ) ), LDC,
22581 $ B( L2, MIN( L2+1, N ) ), LDB )
22582 VEC( 2, 2 ) = C( K2, L2 ) - ( SUML+SGN*SUMR )
22583 *
22584 CALL DLASY2( .TRUE., .TRUE., ISGN, 2, 2, A( K1, K1 ),
22585 $ LDA, B( L1, L1 ), LDB, VEC, 2, SCALOC, X,
22586 $ 2, XNORM, IERR )
22587 IF( IERR.NE.0 )
22588 $ INFO = 1
22589 *
22590 IF( SCALOC.NE.ONE ) THEN
22591 DO 160 J = 1, N
22592 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22593 160 CONTINUE
22594 SCALE = SCALE*SCALOC
22595 END IF
22596 C( K1, L1 ) = X( 1, 1 )
22597 C( K1, L2 ) = X( 1, 2 )
22598 C( K2, L1 ) = X( 2, 1 )
22599 C( K2, L2 ) = X( 2, 2 )
22600 END IF
22601 *
22602 170 CONTINUE
22603 180 CONTINUE
22604 *
22605 ELSE IF( NOTRNA .AND. .NOT.NOTRNB ) THEN
22606 *
22607 * Solve A*X + ISGN*X*B' = scale*C.
22608 *
22609 * The (K,L)th block of X is determined starting from
22610 * bottom-right corner column by column by
22611 *
22612 * A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L)' = C(K,L) - R(K,L)
22613 *
22614 * Where
22615 * M N
22616 * R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)'].
22617 * I=K+1 J=L+1
22618 *
22619 * Start column loop (index = L)
22620 * L1 (L2): column index of the first (last) row of X(K,L)
22621 *
22622 LNEXT = N
22623 DO 240 L = N, 1, -1
22624 IF( L.GT.LNEXT )
22625 $ GO TO 240
22626 IF( L.EQ.1 ) THEN
22627 L1 = L
22628 L2 = L
22629 ELSE
22630 IF( B( L, L-1 ).NE.ZERO ) THEN
22631 L1 = L - 1
22632 L2 = L
22633 LNEXT = L - 2
22634 ELSE
22635 L1 = L
22636 L2 = L
22637 LNEXT = L - 1
22638 END IF
22639 END IF
22640 *
22641 * Start row loop (index = K)
22642 * K1 (K2): row index of the first (last) row of X(K,L)
22643 *
22644 KNEXT = M
22645 DO 230 K = M, 1, -1
22646 IF( K.GT.KNEXT )
22647 $ GO TO 230
22648 IF( K.EQ.1 ) THEN
22649 K1 = K
22650 K2 = K
22651 ELSE
22652 IF( A( K, K-1 ).NE.ZERO ) THEN
22653 K1 = K - 1
22654 K2 = K
22655 KNEXT = K - 2
22656 ELSE
22657 K1 = K
22658 K2 = K
22659 KNEXT = K - 1
22660 END IF
22661 END IF
22662 *
22663 IF( L1.EQ.L2 .AND. K1.EQ.K2 ) THEN
22664 SUML = DDOT( M-K1, A( K1, MIN( K1+1, M ) ), LDA,
22665 $ C( MIN( K1+1, M ), L1 ), 1 )
22666 SUMR = DDOT( N-L1, C( K1, MIN( L1+1, N ) ), LDC,
22667 $ B( L1, MIN( L1+1, N ) ), LDB )
22668 VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
22669 SCALOC = ONE
22670 *
22671 A11 = A( K1, K1 ) + SGN*B( L1, L1 )
22672 DA11 = ABS( A11 )
22673 IF( DA11.LE.SMIN ) THEN
22674 A11 = SMIN
22675 DA11 = SMIN
22676 INFO = 1
22677 END IF
22678 DB = ABS( VEC( 1, 1 ) )
22679 IF( DA11.LT.ONE .AND. DB.GT.ONE ) THEN
22680 IF( DB.GT.BIGNUM*DA11 )
22681 $ SCALOC = ONE / DB
22682 END IF
22683 X( 1, 1 ) = ( VEC( 1, 1 )*SCALOC ) / A11
22684 *
22685 IF( SCALOC.NE.ONE ) THEN
22686 DO 190 J = 1, N
22687 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22688 190 CONTINUE
22689 SCALE = SCALE*SCALOC
22690 END IF
22691 C( K1, L1 ) = X( 1, 1 )
22692 *
22693 ELSE IF( L1.EQ.L2 .AND. K1.NE.K2 ) THEN
22694 *
22695 SUML = DDOT( M-K2, A( K1, MIN( K2+1, M ) ), LDA,
22696 $ C( MIN( K2+1, M ), L1 ), 1 )
22697 SUMR = DDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
22698 $ B( L1, MIN( L2+1, N ) ), LDB )
22699 VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
22700 *
22701 SUML = DDOT( M-K2, A( K2, MIN( K2+1, M ) ), LDA,
22702 $ C( MIN( K2+1, M ), L1 ), 1 )
22703 SUMR = DDOT( N-L2, C( K2, MIN( L2+1, N ) ), LDC,
22704 $ B( L1, MIN( L2+1, N ) ), LDB )
22705 VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
22706 *
22707 CALL DLALN2( .FALSE., 2, 1, SMIN, ONE, A( K1, K1 ),
22708 $ LDA, ONE, ONE, VEC, 2, -SGN*B( L1, L1 ),
22709 $ ZERO, X, 2, SCALOC, XNORM, IERR )
22710 IF( IERR.NE.0 )
22711 $ INFO = 1
22712 *
22713 IF( SCALOC.NE.ONE ) THEN
22714 DO 200 J = 1, N
22715 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22716 200 CONTINUE
22717 SCALE = SCALE*SCALOC
22718 END IF
22719 C( K1, L1 ) = X( 1, 1 )
22720 C( K2, L1 ) = X( 2, 1 )
22721 *
22722 ELSE IF( L1.NE.L2 .AND. K1.EQ.K2 ) THEN
22723 *
22724 SUML = DDOT( M-K1, A( K1, MIN( K1+1, M ) ), LDA,
22725 $ C( MIN( K1+1, M ), L1 ), 1 )
22726 SUMR = DDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
22727 $ B( L1, MIN( L2+1, N ) ), LDB )
22728 VEC( 1, 1 ) = SGN*( C( K1, L1 )-( SUML+SGN*SUMR ) )
22729 *
22730 SUML = DDOT( M-K1, A( K1, MIN( K1+1, M ) ), LDA,
22731 $ C( MIN( K1+1, M ), L2 ), 1 )
22732 SUMR = DDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
22733 $ B( L2, MIN( L2+1, N ) ), LDB )
22734 VEC( 2, 1 ) = SGN*( C( K1, L2 )-( SUML+SGN*SUMR ) )
22735 *
22736 CALL DLALN2( .FALSE., 2, 1, SMIN, ONE, B( L1, L1 ),
22737 $ LDB, ONE, ONE, VEC, 2, -SGN*A( K1, K1 ),
22738 $ ZERO, X, 2, SCALOC, XNORM, IERR )
22739 IF( IERR.NE.0 )
22740 $ INFO = 1
22741 *
22742 IF( SCALOC.NE.ONE ) THEN
22743 DO 210 J = 1, N
22744 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22745 210 CONTINUE
22746 SCALE = SCALE*SCALOC
22747 END IF
22748 C( K1, L1 ) = X( 1, 1 )
22749 C( K1, L2 ) = X( 2, 1 )
22750 *
22751 ELSE IF( L1.NE.L2 .AND. K1.NE.K2 ) THEN
22752 *
22753 SUML = DDOT( M-K2, A( K1, MIN( K2+1, M ) ), LDA,
22754 $ C( MIN( K2+1, M ), L1 ), 1 )
22755 SUMR = DDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
22756 $ B( L1, MIN( L2+1, N ) ), LDB )
22757 VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
22758 *
22759 SUML = DDOT( M-K2, A( K1, MIN( K2+1, M ) ), LDA,
22760 $ C( MIN( K2+1, M ), L2 ), 1 )
22761 SUMR = DDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
22762 $ B( L2, MIN( L2+1, N ) ), LDB )
22763 VEC( 1, 2 ) = C( K1, L2 ) - ( SUML+SGN*SUMR )
22764 *
22765 SUML = DDOT( M-K2, A( K2, MIN( K2+1, M ) ), LDA,
22766 $ C( MIN( K2+1, M ), L1 ), 1 )
22767 SUMR = DDOT( N-L2, C( K2, MIN( L2+1, N ) ), LDC,
22768 $ B( L1, MIN( L2+1, N ) ), LDB )
22769 VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
22770 *
22771 SUML = DDOT( M-K2, A( K2, MIN( K2+1, M ) ), LDA,
22772 $ C( MIN( K2+1, M ), L2 ), 1 )
22773 SUMR = DDOT( N-L2, C( K2, MIN( L2+1, N ) ), LDC,
22774 $ B( L2, MIN( L2+1, N ) ), LDB )
22775 VEC( 2, 2 ) = C( K2, L2 ) - ( SUML+SGN*SUMR )
22776 *
22777 CALL DLASY2( .FALSE., .TRUE., ISGN, 2, 2, A( K1, K1 ),
22778 $ LDA, B( L1, L1 ), LDB, VEC, 2, SCALOC, X,
22779 $ 2, XNORM, IERR )
22780 IF( IERR.NE.0 )
22781 $ INFO = 1
22782 *
22783 IF( SCALOC.NE.ONE ) THEN
22784 DO 220 J = 1, N
22785 CALL DSCAL( M, SCALOC, C( 1, J ), 1 )
22786 220 CONTINUE
22787 SCALE = SCALE*SCALOC
22788 END IF
22789 C( K1, L1 ) = X( 1, 1 )
22790 C( K1, L2 ) = X( 1, 2 )
22791 C( K2, L1 ) = X( 2, 1 )
22792 C( K2, L2 ) = X( 2, 2 )
22793 END IF
22794 *
22795 230 CONTINUE
22796 240 CONTINUE
22797 *
22798 END IF
22799 *
22800 RETURN
22801 *
22802 * End of DTRSYL
22803 *
22804 END
22805 C
22806 C-----------------------------------------------------------------------
22807 C-----------------------------------------------------------------------
22808 DOUBLE PRECISION FUNCTION DLANGE( NORM, M, N, A, LDA, WORK )
22809 *
22810 * -- LAPACK auxiliary routine (version 3.2) --
22811 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
22812 * November 2006
22813 *
22814 * .. Scalar Arguments ..
22815 CHARACTER NORM
22816 INTEGER LDA, M, N
22817 * ..
22818 * .. Array Arguments ..
22819 DOUBLE PRECISION A( LDA, * ), WORK( * )
22820 * ..
22821 *
22822 * Purpose
22823 * =======
22824 *
22825 * DLANGE returns the value of the one norm, or the Frobenius norm, or
22826 * the infinity norm, or the element of largest absolute value of a
22827 * real matrix A.
22828 *
22829 * Description
22830 * ===========
22831 *
22832 * DLANGE returns the value
22833 *
22834 * DLANGE = ( max(abs(A(i,j))), NORM = 'M' or 'm'
22835 * (
22836 * ( norm1(A), NORM = '1', 'O' or 'o'
22837 * (
22838 * ( normI(A), NORM = 'I' or 'i'
22839 * (
22840 * ( normF(A), NORM = 'F', 'f', 'E' or 'e'
22841 *
22842 * where norm1 denotes the one norm of a matrix (maximum column sum),
22843 * normI denotes the infinity norm of a matrix (maximum row sum) and
22844 * normF denotes the Frobenius norm of a matrix (square root of sum of
22845 * squares). Note that max(abs(A(i,j))) is not a consistent matrix norm.
22846 *
22847 * Arguments
22848 * =========
22849 *
22850 * NORM (input) CHARACTER*1
22851 * Specifies the value to be returned in DLANGE as described
22852 * above.
22853 *
22854 * M (input) INTEGER
22855 * The number of rows of the matrix A. M >= 0. When M = 0,
22856 * DLANGE is set to zero.
22857 *
22858 * N (input) INTEGER
22859 * The number of columns of the matrix A. N >= 0. When N = 0,
22860 * DLANGE is set to zero.
22861 *
22862 * A (input) DOUBLE PRECISION array, dimension (LDA,N)
22863 * The m by n matrix A.
22864 *
22865 * LDA (input) INTEGER
22866 * The leading dimension of the array A. LDA >= max(M,1).
22867 *
22868 * WORK (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),
22869 * where LWORK >= M when NORM = 'I'; otherwise, WORK is not
22870 * referenced.
22871 *
22872 * =====================================================================
22873 *
22874 * .. Parameters ..
22875 DOUBLE PRECISION ONE, ZERO
22876 PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
22877 * ..
22878 * .. Local Scalars ..
22879 INTEGER I, J
22880 DOUBLE PRECISION SCALE, SUM, VALUE
22881 * ..
22882 * .. External Subroutines ..
22883 EXTERNAL DLASSQ
22884 * ..
22885 * .. External Functions ..
22886 LOGICAL LSAME
22887 EXTERNAL LSAME
22888 * ..
22889 * .. Intrinsic Functions ..
22890 INTRINSIC ABS, MAX, MIN, SQRT
22891 * ..
22892 * .. Executable Statements ..
22893 *
22894 IF( MIN( M, N ).EQ.0 ) THEN
22895 VALUE = ZERO
22896 ELSE IF( LSAME( NORM, 'M' ) ) THEN
22897 *
22898 * Find max(abs(A(i,j))).
22899 *
22900 VALUE = ZERO
22901 DO 20 J = 1, N
22902 DO 10 I = 1, M
22903 VALUE = MAX( VALUE, ABS( A( I, J ) ) )
22904 10 CONTINUE
22905 20 CONTINUE
22906 ELSE IF( ( LSAME( NORM, 'O' ) ) .OR. ( NORM.EQ.'1' ) ) THEN
22907 *
22908 * Find norm1(A).
22909 *
22910 VALUE = ZERO
22911 DO 40 J = 1, N
22912 SUM = ZERO
22913 DO 30 I = 1, M
22914 SUM = SUM + ABS( A( I, J ) )
22915 30 CONTINUE
22916 VALUE = MAX( VALUE, SUM )
22917 40 CONTINUE
22918 ELSE IF( LSAME( NORM, 'I' ) ) THEN
22919 *
22920 * Find normI(A).
22921 *
22922 DO 50 I = 1, M
22923 WORK( I ) = ZERO
22924 50 CONTINUE
22925 DO 70 J = 1, N
22926 DO 60 I = 1, M
22927 WORK( I ) = WORK( I ) + ABS( A( I, J ) )
22928 60 CONTINUE
22929 70 CONTINUE
22930 VALUE = ZERO
22931 DO 80 I = 1, M
22932 VALUE = MAX( VALUE, WORK( I ) )
22933 80 CONTINUE
22934 ELSE IF( ( LSAME( NORM, 'F' ) ) .OR. ( LSAME( NORM, 'E' ) ) ) THEN
22935 *
22936 * Find normF(A).
22937 *
22938 SCALE = ZERO
22939 SUM = ONE
22940 DO 90 J = 1, N
22941 CALL DLASSQ( M, A( 1, J ), 1, SCALE, SUM )
22942 90 CONTINUE
22943 VALUE = SCALE*SQRT( SUM )
22944 END IF
22945 *
22946 DLANGE = VALUE
22947 RETURN
22948 *
22949 * End of DLANGE
22950 *
22951 END
22952 C
22953 C-----------------------------------------------------------------------
22954 C-----------------------------------------------------------------------
22955 DOUBLE PRECISION FUNCTION DLAPY2( X, Y )
22956 *
22957 * -- LAPACK auxiliary routine (version 3.2) --
22958 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
22959 * November 2006
22960 *
22961 * .. Scalar Arguments ..
22962 DOUBLE PRECISION X, Y
22963 * ..
22964 *
22965 * Purpose
22966 * =======
22967 *
22968 * DLAPY2 returns sqrt(x**2+y**2), taking care not to cause unnecessary
22969 * overflow.
22970 *
22971 * Arguments
22972 * =========
22973 *
22974 * X (input) DOUBLE PRECISION
22975 * Y (input) DOUBLE PRECISION
22976 * X and Y specify the values x and y.
22977 *
22978 * =====================================================================
22979 *
22980 * .. Parameters ..
22981 DOUBLE PRECISION ZERO
22982 PARAMETER ( ZERO = 0.0D0 )
22983 DOUBLE PRECISION ONE
22984 PARAMETER ( ONE = 1.0D0 )
22985 * ..
22986 * .. Local Scalars ..
22987 DOUBLE PRECISION W, XABS, YABS, Z
22988 * ..
22989 * .. Intrinsic Functions ..
22990 INTRINSIC ABS, MAX, MIN, SQRT
22991 * ..
22992 * .. Executable Statements ..
22993 *
22994 XABS = ABS( X )
22995 YABS = ABS( Y )
22996 W = MAX( XABS, YABS )
22997 Z = MIN( XABS, YABS )
22998 IF( Z.EQ.ZERO ) THEN
22999 DLAPY2 = W
23000 ELSE
23001 DLAPY2 = W*SQRT( ONE+( Z / W )**2 )
23002 END IF
23003 RETURN
23004 *
23005 * End of DLAPY2
23006 *
23007 END
23008 C
23009 C-----------------------------------------------------------------------
23010 C-----------------------------------------------------------------------
23011 INTEGER FUNCTION ILADLR( M, N, A, LDA )
23012 IMPLICIT NONE
23013 *
23014 * -- LAPACK auxiliary routine (version 3.2.2) --
23015 *
23016 * -- June 2010 --
23017 *
23018 * -- LAPACK is a software package provided by Univ. of Tennessee, --
23019 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
23020 *
23021 * .. Scalar Arguments ..
23022 INTEGER M, N, LDA
23023 * ..
23024 * .. Array Arguments ..
23025 DOUBLE PRECISION A( LDA, * )
23026 * ..
23027 *
23028 * Purpose
23029 * =======
23030 *
23031 * ILADLR scans A for its last non-zero row.
23032 *
23033 * Arguments
23034 * =========
23035 *
23036 * M (input) INTEGER
23037 * The number of rows of the matrix A.
23038 *
23039 * N (input) INTEGER
23040 * The number of columns of the matrix A.
23041 *
23042 * A (input) DOUBLE PRECISION array, dimension (LDA,N)
23043 * The m by n matrix A.
23044 *
23045 * LDA (input) INTEGER
23046 * The leading dimension of the array A. LDA >= max(1,M).
23047 *
23048 * =====================================================================
23049 *
23050 * .. Parameters ..
23051 DOUBLE PRECISION ZERO
23052 PARAMETER ( ZERO = 0.0D+0 )
23053 * ..
23054 * .. Local Scalars ..
23055 INTEGER I, J
23056 * ..
23057 * .. Executable Statements ..
23058 *
23059 * Quick test for the common case where one corner is non-zero.
23060 IF( M.EQ.0 ) THEN
23061 ILADLR = M
23062 ELSE IF( A(M, 1).NE.ZERO .OR. A(M, N).NE.ZERO ) THEN
23063 ILADLR = M
23064 ELSE
23065 * Scan up each column tracking the last zero row seen.
23066 ILADLR = 0
23067 DO J = 1, N
23068 DO I = M, 1, -1
23069 IF( A(I, J).NE.ZERO ) EXIT
23070 END DO
23071 ILADLR = MAX( ILADLR, I )
23072 END DO
23073 END IF
23074 RETURN
23075 END
23076 C
23077 C-----------------------------------------------------------------------
23078 C-----------------------------------------------------------------------
23079 INTEGER FUNCTION ILADLC( M, N, A, LDA )
23080 IMPLICIT NONE
23081 *
23082 * -- LAPACK auxiliary routine (version 3.2.2) --
23083 *
23084 * -- June 2010 --
23085 *
23086 * -- LAPACK is a software package provided by Univ. of Tennessee, --
23087 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
23088 *
23089 * .. Scalar Arguments ..
23090 INTEGER M, N, LDA
23091 * ..
23092 * .. Array Arguments ..
23093 DOUBLE PRECISION A( LDA, * )
23094 * ..
23095 *
23096 * Purpose
23097 * =======
23098 *
23099 * ILADLC scans A for its last non-zero column.
23100 *
23101 * Arguments
23102 * =========
23103 *
23104 * M (input) INTEGER
23105 * The number of rows of the matrix A.
23106 *
23107 * N (input) INTEGER
23108 * The number of columns of the matrix A.
23109 *
23110 * A (input) DOUBLE PRECISION array, dimension (LDA,N)
23111 * The m by n matrix A.
23112 *
23113 * LDA (input) INTEGER
23114 * The leading dimension of the array A. LDA >= max(1,M).
23115 *
23116 * =====================================================================
23117 *
23118 * .. Parameters ..
23119 DOUBLE PRECISION ZERO
23120 PARAMETER ( ZERO = 0.0D+0 )
23121 * ..
23122 * .. Local Scalars ..
23123 INTEGER I
23124 * ..
23125 * .. Executable Statements ..
23126 *
23127 * Quick test for the common case where one corner is non-zero.
23128 IF( N.EQ.0 ) THEN
23129 ILADLC = N
23130 ELSE IF( A(1, N).NE.ZERO .OR. A(M, N).NE.ZERO ) THEN
23131 ILADLC = N
23132 ELSE
23133 * Now scan each column from the end, returning with the first non-zero.
23134 DO ILADLC = N, 1, -1
23135 DO I = 1, M
23136 IF( A(I, ILADLC).NE.ZERO ) RETURN
23137 END DO
23138 END DO
23139 END IF
23140 RETURN
23141 END
23142 C
23143 C-----------------------------------------------------------------------
23144 C-----------------------------------------------------------------------
23145 SUBROUTINE DORMHR( SIDE, TRANS, M, N, ILO, IHI, A, LDA, TAU, C,
23146 $ LDC, WORK, LWORK, INFO )
23147 *
23148 * -- LAPACK routine (version 3.2) --
23149 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
23150 * November 2006
23151 *
23152 * .. Scalar Arguments ..
23153 CHARACTER SIDE, TRANS
23154 INTEGER IHI, ILO, INFO, LDA, LDC, LWORK, M, N
23155 * ..
23156 * .. Array Arguments ..
23157 DOUBLE PRECISION A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * )
23158 * ..
23159 *
23160 * Purpose
23161 * =======
23162 *
23163 * DORMHR overwrites the general real M-by-N matrix C with
23164 *
23165 * SIDE = 'L' SIDE = 'R'
23166 * TRANS = 'N': Q * C C * Q
23167 * TRANS = 'T': Q**T * C C * Q**T
23168 *
23169 * where Q is a real orthogonal matrix of order nq, with nq = m if
23170 * SIDE = 'L' and nq = n if SIDE = 'R'. Q is defined as the product of
23171 * IHI-ILO elementary reflectors, as returned by DGEHRD:
23172 *
23173 * Q = H(ilo) H(ilo+1) . . . H(ihi-1).
23174 *
23175 * Arguments
23176 * =========
23177 *
23178 * SIDE (input) CHARACTER*1
23179 * = 'L': apply Q or Q**T from the Left;
23180 * = 'R': apply Q or Q**T from the Right.
23181 *
23182 * TRANS (input) CHARACTER*1
23183 * = 'N': No transpose, apply Q;
23184 * = 'T': Transpose, apply Q**T.
23185 *
23186 * M (input) INTEGER
23187 * The number of rows of the matrix C. M >= 0.
23188 *
23189 * N (input) INTEGER
23190 * The number of columns of the matrix C. N >= 0.
23191 *
23192 * ILO (input) INTEGER
23193 * IHI (input) INTEGER
23194 * ILO and IHI must have the same values as in the previous call
23195 * of DGEHRD. Q is equal to the unit matrix except in the
23196 * submatrix Q(ilo+1:ihi,ilo+1:ihi).
23197 * If SIDE = 'L', then 1 <= ILO <= IHI <= M, if M > 0, and
23198 * ILO = 1 and IHI = 0, if M = 0;
23199 * if SIDE = 'R', then 1 <= ILO <= IHI <= N, if N > 0, and
23200 * ILO = 1 and IHI = 0, if N = 0.
23201 *
23202 * A (input) DOUBLE PRECISION array, dimension
23203 * (LDA,M) if SIDE = 'L'
23204 * (LDA,N) if SIDE = 'R'
23205 * The vectors which define the elementary reflectors, as
23206 * returned by DGEHRD.
23207 *
23208 * LDA (input) INTEGER
23209 * The leading dimension of the array A.
23210 * LDA >= max(1,M) if SIDE = 'L'; LDA >= max(1,N) if SIDE = 'R'.
23211 *
23212 * TAU (input) DOUBLE PRECISION array, dimension
23213 * (M-1) if SIDE = 'L'
23214 * (N-1) if SIDE = 'R'
23215 * TAU(i) must contain the scalar factor of the elementary
23216 * reflector H(i), as returned by DGEHRD.
23217 *
23218 * C (input/output) DOUBLE PRECISION array, dimension (LDC,N)
23219 * On entry, the M-by-N matrix C.
23220 * On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.
23221 *
23222 * LDC (input) INTEGER
23223 * The leading dimension of the array C. LDC >= max(1,M).
23224 *
23225 * WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
23226 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
23227 *
23228 * LWORK (input) INTEGER
23229 * The dimension of the array WORK.
23230 * If SIDE = 'L', LWORK >= max(1,N);
23231 * if SIDE = 'R', LWORK >= max(1,M).
23232 * For optimum performance LWORK >= N*NB if SIDE = 'L', and
23233 * LWORK >= M*NB if SIDE = 'R', where NB is the optimal
23234 * blocksize.
23235 *
23236 * If LWORK = -1, then a workspace query is assumed; the routine
23237 * only calculates the optimal size of the WORK array, returns
23238 * this value as the first entry of the WORK array, and no error
23239 * message related to LWORK is issued by XERBLA.
23240 *
23241 * INFO (output) INTEGER
23242 * = 0: successful exit
23243 * < 0: if INFO = -i, the i-th argument had an illegal value
23244 *
23245 * =====================================================================
23246 *
23247 * .. Local Scalars ..
23248 LOGICAL LEFT, LQUERY
23249 INTEGER I1, I2, IINFO, LWKOPT, MI, NB, NH, NI, NQ, NW
23250 * ..
23251 * .. External Functions ..
23252 LOGICAL LSAME
23253 INTEGER ILAENV
23254 EXTERNAL LSAME, ILAENV
23255 * ..
23256 * .. External Subroutines ..
23257 EXTERNAL DORMQR, XERBLA
23258 * ..
23259 * .. Intrinsic Functions ..
23260 INTRINSIC MAX, MIN
23261 * ..
23262 * .. Executable Statements ..
23263 *
23264 * Test the input arguments
23265 *
23266 INFO = 0
23267 NH = IHI - ILO
23268 LEFT = LSAME( SIDE, 'L' )
23269 LQUERY = ( LWORK.EQ.-1 )
23270 *
23271 * NQ is the order of Q and NW is the minimum dimension of WORK
23272 *
23273 IF( LEFT ) THEN
23274 NQ = M
23275 NW = N
23276 ELSE
23277 NQ = N
23278 NW = M
23279 END IF
23280 IF( .NOT.LEFT .AND. .NOT.LSAME( SIDE, 'R' ) ) THEN
23281 INFO = -1
23282 ELSE IF( .NOT.LSAME( TRANS, 'N' ) .AND. .NOT.LSAME( TRANS, 'T' ) )
23283 $ THEN
23284 INFO = -2
23285 ELSE IF( M.LT.0 ) THEN
23286 INFO = -3
23287 ELSE IF( N.LT.0 ) THEN
23288 INFO = -4
23289 ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, NQ ) ) THEN
23290 INFO = -5
23291 ELSE IF( IHI.LT.MIN( ILO, NQ ) .OR. IHI.GT.NQ ) THEN
23292 INFO = -6
23293 ELSE IF( LDA.LT.MAX( 1, NQ ) ) THEN
23294 INFO = -8
23295 ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
23296 INFO = -11
23297 ELSE IF( LWORK.LT.MAX( 1, NW ) .AND. .NOT.LQUERY ) THEN
23298 INFO = -13
23299 END IF
23300 *
23301 IF( INFO.EQ.0 ) THEN
23302 IF( LEFT ) THEN
23303 NB = ILAENV( 1, 'DORMQR', SIDE // TRANS, NH, N, NH, -1 )
23304 ELSE
23305 NB = ILAENV( 1, 'DORMQR', SIDE // TRANS, M, NH, NH, -1 )
23306 END IF
23307 LWKOPT = MAX( 1, NW )*NB
23308 WORK( 1 ) = LWKOPT
23309 END IF
23310 *
23311 IF( INFO.NE.0 ) THEN
23312 CALL XERBLA( 'DORMHR', -INFO )
23313 RETURN
23314 ELSE IF( LQUERY ) THEN
23315 RETURN
23316 END IF
23317 *
23318 * Quick return if possible
23319 *
23320 IF( M.EQ.0 .OR. N.EQ.0 .OR. NH.EQ.0 ) THEN
23321 WORK( 1 ) = 1
23322 RETURN
23323 END IF
23324 *
23325 IF( LEFT ) THEN
23326 MI = NH
23327 NI = N
23328 I1 = ILO + 1
23329 I2 = 1
23330 ELSE
23331 MI = M
23332 NI = NH
23333 I1 = 1
23334 I2 = ILO + 1
23335 END IF
23336 *
23337 CALL DORMQR( SIDE, TRANS, MI, NI, NH, A( ILO+1, ILO ), LDA,
23338 $ TAU( ILO ), C( I1, I2 ), LDC, WORK, LWORK, IINFO )
23339 *
23340 WORK( 1 ) = LWKOPT
23341 RETURN
23342 *
23343 * End of DORMHR
23344 *
23345 END
23346 C
23347 C-----------------------------------------------------------------------
23348 C-----------------------------------------------------------------------
23349 SUBROUTINE DORMQR( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC,
23350 $ WORK, LWORK, INFO )
23351 *
23352 * -- LAPACK routine (version 3.2) --
23353 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
23354 * November 2006
23355 *
23356 * .. Scalar Arguments ..
23357 CHARACTER SIDE, TRANS
23358 INTEGER INFO, K, LDA, LDC, LWORK, M, N
23359 * ..
23360 * .. Array Arguments ..
23361 DOUBLE PRECISION A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * )
23362 * ..
23363 *
23364 * Purpose
23365 * =======
23366 *
23367 * DORMQR overwrites the general real M-by-N matrix C with
23368 *
23369 * SIDE = 'L' SIDE = 'R'
23370 * TRANS = 'N': Q * C C * Q
23371 * TRANS = 'T': Q**T * C C * Q**T
23372 *
23373 * where Q is a real orthogonal matrix defined as the product of k
23374 * elementary reflectors
23375 *
23376 * Q = H(1) H(2) . . . H(k)
23377 *
23378 * as returned by DGEQRF. Q is of order M if SIDE = 'L' and of order N
23379 * if SIDE = 'R'.
23380 *
23381 * Arguments
23382 * =========
23383 *
23384 * SIDE (input) CHARACTER*1
23385 * = 'L': apply Q or Q**T from the Left;
23386 * = 'R': apply Q or Q**T from the Right.
23387 *
23388 * TRANS (input) CHARACTER*1
23389 * = 'N': No transpose, apply Q;
23390 * = 'T': Transpose, apply Q**T.
23391 *
23392 * M (input) INTEGER
23393 * The number of rows of the matrix C. M >= 0.
23394 *
23395 * N (input) INTEGER
23396 * The number of columns of the matrix C. N >= 0.
23397 *
23398 * K (input) INTEGER
23399 * The number of elementary reflectors whose product defines
23400 * the matrix Q.
23401 * If SIDE = 'L', M >= K >= 0;
23402 * if SIDE = 'R', N >= K >= 0.
23403 *
23404 * A (input) DOUBLE PRECISION array, dimension (LDA,K)
23405 * The i-th column must contain the vector which defines the
23406 * elementary reflector H(i), for i = 1,2,...,k, as returned by
23407 * DGEQRF in the first k columns of its array argument A.
23408 * A is modified by the routine but restored on exit.
23409 *
23410 * LDA (input) INTEGER
23411 * The leading dimension of the array A.
23412 * If SIDE = 'L', LDA >= max(1,M);
23413 * if SIDE = 'R', LDA >= max(1,N).
23414 *
23415 * TAU (input) DOUBLE PRECISION array, dimension (K)
23416 * TAU(i) must contain the scalar factor of the elementary
23417 * reflector H(i), as returned by DGEQRF.
23418 *
23419 * C (input/output) DOUBLE PRECISION array, dimension (LDC,N)
23420 * On entry, the M-by-N matrix C.
23421 * On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.
23422 *
23423 * LDC (input) INTEGER
23424 * The leading dimension of the array C. LDC >= max(1,M).
23425 *
23426 * WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
23427 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
23428 *
23429 * LWORK (input) INTEGER
23430 * The dimension of the array WORK.
23431 * If SIDE = 'L', LWORK >= max(1,N);
23432 * if SIDE = 'R', LWORK >= max(1,M).
23433 * For optimum performance LWORK >= N*NB if SIDE = 'L', and
23434 * LWORK >= M*NB if SIDE = 'R', where NB is the optimal
23435 * blocksize.
23436 *
23437 * If LWORK = -1, then a workspace query is assumed; the routine
23438 * only calculates the optimal size of the WORK array, returns
23439 * this value as the first entry of the WORK array, and no error
23440 * message related to LWORK is issued by XERBLA.
23441 *
23442 * INFO (output) INTEGER
23443 * = 0: successful exit
23444 * < 0: if INFO = -i, the i-th argument had an illegal value
23445 *
23446 * =====================================================================
23447 *
23448 * .. Parameters ..
23449 INTEGER NBMAX, LDT
23450 PARAMETER ( NBMAX = 64, LDT = NBMAX+1 )
23451 * ..
23452 * .. Local Scalars ..
23453 LOGICAL LEFT, LQUERY, NOTRAN
23454 INTEGER I, I1, I2, I3, IB, IC, IINFO, IWS, JC, LDWORK,
23455 $ LWKOPT, MI, NB, NBMIN, NI, NQ, NW
23456 * ..
23457 * .. Local Arrays ..
23458 DOUBLE PRECISION T( LDT, NBMAX )
23459 * ..
23460 * .. External Functions ..
23461 LOGICAL LSAME
23462 INTEGER ILAENV
23463 EXTERNAL LSAME, ILAENV
23464 * ..
23465 * .. External Subroutines ..
23466 EXTERNAL DLARFB, DLARFT, DORM2R, XERBLA
23467 * ..
23468 * .. Intrinsic Functions ..
23469 INTRINSIC MAX, MIN
23470 * ..
23471 * .. Executable Statements ..
23472 *
23473 * Test the input arguments
23474 *
23475 INFO = 0
23476 LEFT = LSAME( SIDE, 'L' )
23477 NOTRAN = LSAME( TRANS, 'N' )
23478 LQUERY = ( LWORK.EQ.-1 )
23479 *
23480 * NQ is the order of Q and NW is the minimum dimension of WORK
23481 *
23482 IF( LEFT ) THEN
23483 NQ = M
23484 NW = N
23485 ELSE
23486 NQ = N
23487 NW = M
23488 END IF
23489 IF( .NOT.LEFT .AND. .NOT.LSAME( SIDE, 'R' ) ) THEN
23490 INFO = -1
23491 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) ) THEN
23492 INFO = -2
23493 ELSE IF( M.LT.0 ) THEN
23494 INFO = -3
23495 ELSE IF( N.LT.0 ) THEN
23496 INFO = -4
23497 ELSE IF( K.LT.0 .OR. K.GT.NQ ) THEN
23498 INFO = -5
23499 ELSE IF( LDA.LT.MAX( 1, NQ ) ) THEN
23500 INFO = -7
23501 ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
23502 INFO = -10
23503 ELSE IF( LWORK.LT.MAX( 1, NW ) .AND. .NOT.LQUERY ) THEN
23504 INFO = -12
23505 END IF
23506 *
23507 IF( INFO.EQ.0 ) THEN
23508 *
23509 * Determine the block size. NB may be at most NBMAX, where NBMAX
23510 * is used to define the local array T.
23511 *
23512 NB = MIN( NBMAX, ILAENV( 1, 'DORMQR', SIDE // TRANS, M, N, K,
23513 $ -1 ) )
23514 LWKOPT = MAX( 1, NW )*NB
23515 WORK( 1 ) = LWKOPT
23516 END IF
23517 *
23518 IF( INFO.NE.0 ) THEN
23519 CALL XERBLA( 'DORMQR', -INFO )
23520 RETURN
23521 ELSE IF( LQUERY ) THEN
23522 RETURN
23523 END IF
23524 *
23525 * Quick return if possible
23526 *
23527 IF( M.EQ.0 .OR. N.EQ.0 .OR. K.EQ.0 ) THEN
23528 WORK( 1 ) = 1
23529 RETURN
23530 END IF
23531 *
23532 NBMIN = 2
23533 LDWORK = NW
23534 IF( NB.GT.1 .AND. NB.LT.K ) THEN
23535 IWS = NW*NB
23536 IF( LWORK.LT.IWS ) THEN
23537 NB = LWORK / LDWORK
23538 NBMIN = MAX( 2, ILAENV( 2, 'DORMQR', SIDE // TRANS, M, N, K,
23539 $ -1 ) )
23540 END IF
23541 ELSE
23542 IWS = NW
23543 END IF
23544 *
23545 IF( NB.LT.NBMIN .OR. NB.GE.K ) THEN
23546 *
23547 * Use unblocked code
23548 *
23549 CALL DORM2R( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC, WORK,
23550 $ IINFO )
23551 ELSE
23552 *
23553 * Use blocked code
23554 *
23555 IF( ( LEFT .AND. .NOT.NOTRAN ) .OR.
23556 $ ( .NOT.LEFT .AND. NOTRAN ) ) THEN
23557 I1 = 1
23558 I2 = K
23559 I3 = NB
23560 ELSE
23561 I1 = ( ( K-1 ) / NB )*NB + 1
23562 I2 = 1
23563 I3 = -NB
23564 END IF
23565 *
23566 IF( LEFT ) THEN
23567 NI = N
23568 JC = 1
23569 ELSE
23570 MI = M
23571 IC = 1
23572 END IF
23573 *
23574 DO 10 I = I1, I2, I3
23575 IB = MIN( NB, K-I+1 )
23576 *
23577 * Form the triangular factor of the block reflector
23578 * H = H(i) H(i+1) . . . H(i+ib-1)
23579 *
23580 CALL DLARFT( 'Forward', 'Columnwise', NQ-I+1, IB, A( I, I ),
23581 $ LDA, TAU( I ), T, LDT )
23582 IF( LEFT ) THEN
23583 *
23584 * H or H' is applied to C(i:m,1:n)
23585 *
23586 MI = M - I + 1
23587 IC = I
23588 ELSE
23589 *
23590 * H or H' is applied to C(1:m,i:n)
23591 *
23592 NI = N - I + 1
23593 JC = I
23594 END IF
23595 *
23596 * Apply H or H'
23597 *
23598 CALL DLARFB( SIDE, TRANS, 'Forward', 'Columnwise', MI, NI,
23599 $ IB, A( I, I ), LDA, T, LDT, C( IC, JC ), LDC,
23600 $ WORK, LDWORK )
23601 10 CONTINUE
23602 END IF
23603 WORK( 1 ) = LWKOPT
23604 RETURN
23605 *
23606 * End of DORMQR
23607 *
23608 END
23609 C
23610 C-----------------------------------------------------------------------
23611 C-----------------------------------------------------------------------
23612 SUBROUTINE DORM2R( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC,
23613 $ WORK, INFO )
23614 *
23615 * -- LAPACK routine (version 3.2) --
23616 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
23617 * November 2006
23618 *
23619 * .. Scalar Arguments ..
23620 CHARACTER SIDE, TRANS
23621 INTEGER INFO, K, LDA, LDC, M, N
23622 * ..
23623 * .. Array Arguments ..
23624 DOUBLE PRECISION A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * )
23625 * ..
23626 *
23627 * Purpose
23628 * =======
23629 *
23630 * DORM2R overwrites the general real m by n matrix C with
23631 *
23632 * Q * C if SIDE = 'L' and TRANS = 'N', or
23633 *
23634 * Q'* C if SIDE = 'L' and TRANS = 'T', or
23635 *
23636 * C * Q if SIDE = 'R' and TRANS = 'N', or
23637 *
23638 * C * Q' if SIDE = 'R' and TRANS = 'T',
23639 *
23640 * where Q is a real orthogonal matrix defined as the product of k
23641 * elementary reflectors
23642 *
23643 * Q = H(1) H(2) . . . H(k)
23644 *
23645 * as returned by DGEQRF. Q is of order m if SIDE = 'L' and of order n
23646 * if SIDE = 'R'.
23647 *
23648 * Arguments
23649 * =========
23650 *
23651 * SIDE (input) CHARACTER*1
23652 * = 'L': apply Q or Q' from the Left
23653 * = 'R': apply Q or Q' from the Right
23654 *
23655 * TRANS (input) CHARACTER*1
23656 * = 'N': apply Q (No transpose)
23657 * = 'T': apply Q' (Transpose)
23658 *
23659 * M (input) INTEGER
23660 * The number of rows of the matrix C. M >= 0.
23661 *
23662 * N (input) INTEGER
23663 * The number of columns of the matrix C. N >= 0.
23664 *
23665 * K (input) INTEGER
23666 * The number of elementary reflectors whose product defines
23667 * the matrix Q.
23668 * If SIDE = 'L', M >= K >= 0;
23669 * if SIDE = 'R', N >= K >= 0.
23670 *
23671 * A (input) DOUBLE PRECISION array, dimension (LDA,K)
23672 * The i-th column must contain the vector which defines the
23673 * elementary reflector H(i), for i = 1,2,...,k, as returned by
23674 * DGEQRF in the first k columns of its array argument A.
23675 * A is modified by the routine but restored on exit.
23676 *
23677 * LDA (input) INTEGER
23678 * The leading dimension of the array A.
23679 * If SIDE = 'L', LDA >= max(1,M);
23680 * if SIDE = 'R', LDA >= max(1,N).
23681 *
23682 * TAU (input) DOUBLE PRECISION array, dimension (K)
23683 * TAU(i) must contain the scalar factor of the elementary
23684 * reflector H(i), as returned by DGEQRF.
23685 *
23686 * C (input/output) DOUBLE PRECISION array, dimension (LDC,N)
23687 * On entry, the m by n matrix C.
23688 * On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q.
23689 *
23690 * LDC (input) INTEGER
23691 * The leading dimension of the array C. LDC >= max(1,M).
23692 *
23693 * WORK (workspace) DOUBLE PRECISION array, dimension
23694 * (N) if SIDE = 'L',
23695 * (M) if SIDE = 'R'
23696 *
23697 * INFO (output) INTEGER
23698 * = 0: successful exit
23699 * < 0: if INFO = -i, the i-th argument had an illegal value
23700 *
23701 * =====================================================================
23702 *
23703 * .. Parameters ..
23704 DOUBLE PRECISION ONE
23705 PARAMETER ( ONE = 1.0D+0 )
23706 * ..
23707 * .. Local Scalars ..
23708 LOGICAL LEFT, NOTRAN
23709 INTEGER I, I1, I2, I3, IC, JC, MI, NI, NQ
23710 DOUBLE PRECISION AII
23711 * ..
23712 * .. External Functions ..
23713 LOGICAL LSAME
23714 EXTERNAL LSAME
23715 * ..
23716 * .. External Subroutines ..
23717 EXTERNAL DLARF, XERBLA
23718 * ..
23719 * .. Intrinsic Functions ..
23720 INTRINSIC MAX
23721 * ..
23722 * .. Executable Statements ..
23723 *
23724 * Test the input arguments
23725 *
23726 INFO = 0
23727 LEFT = LSAME( SIDE, 'L' )
23728 NOTRAN = LSAME( TRANS, 'N' )
23729 *
23730 * NQ is the order of Q
23731 *
23732 IF( LEFT ) THEN
23733 NQ = M
23734 ELSE
23735 NQ = N
23736 END IF
23737 IF( .NOT.LEFT .AND. .NOT.LSAME( SIDE, 'R' ) ) THEN
23738 INFO = -1
23739 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) ) THEN
23740 INFO = -2
23741 ELSE IF( M.LT.0 ) THEN
23742 INFO = -3
23743 ELSE IF( N.LT.0 ) THEN
23744 INFO = -4
23745 ELSE IF( K.LT.0 .OR. K.GT.NQ ) THEN
23746 INFO = -5
23747 ELSE IF( LDA.LT.MAX( 1, NQ ) ) THEN
23748 INFO = -7
23749 ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
23750 INFO = -10
23751 END IF
23752 IF( INFO.NE.0 ) THEN
23753 CALL XERBLA( 'DORM2R', -INFO )
23754 RETURN
23755 END IF
23756 *
23757 * Quick return if possible
23758 *
23759 IF( M.EQ.0 .OR. N.EQ.0 .OR. K.EQ.0 )
23760 $ RETURN
23761 *
23762 IF( ( LEFT .AND. .NOT.NOTRAN ) .OR. ( .NOT.LEFT .AND. NOTRAN ) )
23763 $ THEN
23764 I1 = 1
23765 I2 = K
23766 I3 = 1
23767 ELSE
23768 I1 = K
23769 I2 = 1
23770 I3 = -1
23771 END IF
23772 *
23773 IF( LEFT ) THEN
23774 NI = N
23775 JC = 1
23776 ELSE
23777 MI = M
23778 IC = 1
23779 END IF
23780 *
23781 DO 10 I = I1, I2, I3
23782 IF( LEFT ) THEN
23783 *
23784 * H(i) is applied to C(i:m,1:n)
23785 *
23786 MI = M - I + 1
23787 IC = I
23788 ELSE
23789 *
23790 * H(i) is applied to C(1:m,i:n)
23791 *
23792 NI = N - I + 1
23793 JC = I
23794 END IF
23795 *
23796 * Apply H(i)
23797 *
23798 AII = A( I, I )
23799 A( I, I ) = ONE
23800 CALL DLARF( SIDE, MI, NI, A( I, I ), 1, TAU( I ), C( IC, JC ),
23801 $ LDC, WORK )
23802 A( I, I ) = AII
23803 10 CONTINUE
23804 RETURN
23805 *
23806 * End of DORM2R
23807 *
23808 END
23809 C
23810 C-----------------------------------------------------------------------
23811 C-----------------------------------------------------------------------
23812 INTEGER FUNCTION IEEECK( ISPEC, ZERO, ONE )
23813 *
23814 * -- LAPACK auxiliary routine (version 3.2.2) --
23815 * -- LAPACK is a software package provided by Univ. of Tennessee, --
23816 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
23817 * June 2010
23818 *
23819 * .. Scalar Arguments ..
23820 INTEGER ISPEC
23821 REAL ONE, ZERO
23822 * ..
23823 *
23824 * Purpose
23825 * =======
23826 *
23827 * IEEECK is called from the ILAENV to verify that Infinity and
23828 * possibly NaN arithmetic is safe (i.e. will not trap).
23829 *
23830 * Arguments
23831 * =========
23832 *
23833 * ISPEC (input) INTEGER
23834 * Specifies whether to test just for inifinity arithmetic
23835 * or whether to test for infinity and NaN arithmetic.
23836 * = 0: Verify infinity arithmetic only.
23837 * = 1: Verify infinity and NaN arithmetic.
23838 *
23839 * ZERO (input) REAL
23840 * Must contain the value 0.0
23841 * This is passed to prevent the compiler from optimizing
23842 * away this code.
23843 *
23844 * ONE (input) REAL
23845 * Must contain the value 1.0
23846 * This is passed to prevent the compiler from optimizing
23847 * away this code.
23848 *
23849 * RETURN VALUE: INTEGER
23850 * = 0: Arithmetic failed to produce the correct answers
23851 * = 1: Arithmetic produced the correct answers
23852 *
23853 * .. Local Scalars ..
23854 REAL NAN1, NAN2, NAN3, NAN4, NAN5, NAN6, NEGINF,
23855 $ NEGZRO, NEWZRO, POSINF
23856 * ..
23857 * .. Executable Statements ..
23858 IEEECK = 1
23859 *
23860 POSINF = ONE / ZERO
23861 IF( POSINF.LE.ONE ) THEN
23862 IEEECK = 0
23863 RETURN
23864 END IF
23865 *
23866 NEGINF = -ONE / ZERO
23867 IF( NEGINF.GE.ZERO ) THEN
23868 IEEECK = 0
23869 RETURN
23870 END IF
23871 *
23872 NEGZRO = ONE / ( NEGINF+ONE )
23873 IF( NEGZRO.NE.ZERO ) THEN
23874 IEEECK = 0
23875 RETURN
23876 END IF
23877 *
23878 NEGINF = ONE / NEGZRO
23879 IF( NEGINF.GE.ZERO ) THEN
23880 IEEECK = 0
23881 RETURN
23882 END IF
23883 *
23884 NEWZRO = NEGZRO + ZERO
23885 IF( NEWZRO.NE.ZERO ) THEN
23886 IEEECK = 0
23887 RETURN
23888 END IF
23889 *
23890 POSINF = ONE / NEWZRO
23891 IF( POSINF.LE.ONE ) THEN
23892 IEEECK = 0
23893 RETURN
23894 END IF
23895 *
23896 NEGINF = NEGINF*POSINF
23897 IF( NEGINF.GE.ZERO ) THEN
23898 IEEECK = 0
23899 RETURN
23900 END IF
23901 *
23902 POSINF = POSINF*POSINF
23903 IF( POSINF.LE.ONE ) THEN
23904 IEEECK = 0
23905 RETURN
23906 END IF
23907 *
23908 *
23909 *
23910 *
23911 * Return if we were only asked to check infinity arithmetic
23912 *
23913 IF( ISPEC.EQ.0 )
23914 $ RETURN
23915 *
23916 NAN1 = POSINF + NEGINF
23917 *
23918 NAN2 = POSINF / NEGINF
23919 *
23920 NAN3 = POSINF / POSINF
23921 *
23922 NAN4 = POSINF*ZERO
23923 *
23924 NAN5 = NEGINF*NEGZRO
23925 *
23926 NAN6 = NAN5*ZERO
23927 *
23928 IF( NAN1.EQ.NAN1 ) THEN
23929 IEEECK = 0
23930 RETURN
23931 END IF
23932 *
23933 IF( NAN2.EQ.NAN2 ) THEN
23934 IEEECK = 0
23935 RETURN
23936 END IF
23937 *
23938 IF( NAN3.EQ.NAN3 ) THEN
23939 IEEECK = 0
23940 RETURN
23941 END IF
23942 *
23943 IF( NAN4.EQ.NAN4 ) THEN
23944 IEEECK = 0
23945 RETURN
23946 END IF
23947 *
23948 IF( NAN5.EQ.NAN5 ) THEN
23949 IEEECK = 0
23950 RETURN
23951 END IF
23952 *
23953 IF( NAN6.EQ.NAN6 ) THEN
23954 IEEECK = 0
23955 RETURN
23956 END IF
23957 *
23958 RETURN
23959 END
23960 C
23961 C-----------------------------------------------------------------------
23962 C-----------------------------------------------------------------------
23963 INTEGER FUNCTION IPARMQ( ISPEC, NAME, OPTS, N, ILO, IHI, LWORK )
23964 *
23965 * -- LAPACK auxiliary routine (version 3.2) --
23966 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
23967 * November 2006
23968 *
23969 * .. Scalar Arguments ..
23970 INTEGER IHI, ILO, ISPEC, LWORK, N
23971 CHARACTER NAME*( * ), OPTS*( * )
23972 *
23973 * Purpose
23974 * =======
23975 *
23976 * This program sets problem and machine dependent parameters
23977 * useful for xHSEQR and its subroutines. It is called whenever
23978 * ILAENV is called with 12 <= ISPEC <= 16
23979 *
23980 * Arguments
23981 * =========
23982 *
23983 * ISPEC (input) integer scalar
23984 * ISPEC specifies which tunable parameter IPARMQ should
23985 * return.
23986 *
23987 * ISPEC=12: (INMIN) Matrices of order nmin or less
23988 * are sent directly to xLAHQR, the implicit
23989 * double shift QR algorithm. NMIN must be
23990 * at least 11.
23991 *
23992 * ISPEC=13: (INWIN) Size of the deflation window.
23993 * This is best set greater than or equal to
23994 * the number of simultaneous shifts NS.
23995 * Larger matrices benefit from larger deflation
23996 * windows.
23997 *
23998 * ISPEC=14: (INIBL) Determines when to stop nibbling and
23999 * invest in an (expensive) multi-shift QR sweep.
24000 * If the aggressive early deflation subroutine
24001 * finds LD converged eigenvalues from an order
24002 * NW deflation window and LD.GT.(NW*NIBBLE)/100,
24003 * then the next QR sweep is skipped and early
24004 * deflation is applied immediately to the
24005 * remaining active diagonal block. Setting
24006 * IPARMQ(ISPEC=14) = 0 causes TTQRE to skip a
24007 * multi-shift QR sweep whenever early deflation
24008 * finds a converged eigenvalue. Setting
24009 * IPARMQ(ISPEC=14) greater than or equal to 100
24010 * prevents TTQRE from skipping a multi-shift
24011 * QR sweep.
24012 *
24013 * ISPEC=15: (NSHFTS) The number of simultaneous shifts in
24014 * a multi-shift QR iteration.
24015 *
24016 * ISPEC=16: (IACC22) IPARMQ is set to 0, 1 or 2 with the
24017 * following meanings.
24018 * 0: During the multi-shift QR sweep,
24019 * xLAQR5 does not accumulate reflections and
24020 * does not use matrix-matrix multiply to
24021 * update the far-from-diagonal matrix
24022 * entries.
24023 * 1: During the multi-shift QR sweep,
24024 * xLAQR5 and/or xLAQRaccumulates reflections and uses
24025 * matrix-matrix multiply to update the
24026 * far-from-diagonal matrix entries.
24027 * 2: During the multi-shift QR sweep.
24028 * xLAQR5 accumulates reflections and takes
24029 * advantage of 2-by-2 block structure during
24030 * matrix-matrix multiplies.
24031 * (If xTRMM is slower than xGEMM, then
24032 * IPARMQ(ISPEC=16)=1 may be more efficient than
24033 * IPARMQ(ISPEC=16)=2 despite the greater level of
24034 * arithmetic work implied by the latter choice.)
24035 *
24036 * NAME (input) character string
24037 * Name of the calling subroutine
24038 *
24039 * OPTS (input) character string
24040 * This is a concatenation of the string arguments to
24041 * TTQRE.
24042 *
24043 * N (input) integer scalar
24044 * N is the order of the Hessenberg matrix H.
24045 *
24046 * ILO (input) INTEGER
24047 * IHI (input) INTEGER
24048 * It is assumed that H is already upper triangular
24049 * in rows and columns 1:ILO-1 and IHI+1:N.
24050 *
24051 * LWORK (input) integer scalar
24052 * The amount of workspace available.
24053 *
24054 * Further Details
24055 * ===============
24056 *
24057 * Little is known about how best to choose these parameters.
24058 * It is possible to use different values of the parameters
24059 * for each of CHSEQR, DHSEQR, SHSEQR and ZHSEQR.
24060 *
24061 * It is probably best to choose different parameters for
24062 * different matrices and different parameters at different
24063 * times during the iteration, but this has not been
24064 * implemented --- yet.
24065 *
24066 *
24067 * The best choices of most of the parameters depend
24068 * in an ill-understood way on the relative execution
24069 * rate of xLAQR3 and xLAQR5 and on the nature of each
24070 * particular eigenvalue problem. Experiment may be the
24071 * only practical way to determine which choices are most
24072 * effective.
24073 *
24074 * Following is a list of default values supplied by IPARMQ.
24075 * These defaults may be adjusted in order to attain better
24076 * performance in any particular computational environment.
24077 *
24078 * IPARMQ(ISPEC=12) The xLAHQR vs xLAQR0 crossover point.
24079 * Default: 75. (Must be at least 11.)
24080 *
24081 * IPARMQ(ISPEC=13) Recommended deflation window size.
24082 * This depends on ILO, IHI and NS, the
24083 * number of simultaneous shifts returned
24084 * by IPARMQ(ISPEC=15). The default for
24085 * (IHI-ILO+1).LE.500 is NS. The default
24086 * for (IHI-ILO+1).GT.500 is 3*NS/2.
24087 *
24088 * IPARMQ(ISPEC=14) Nibble crossover point. Default: 14.
24089 *
24090 * IPARMQ(ISPEC=15) Number of simultaneous shifts, NS.
24091 * a multi-shift QR iteration.
24092 *
24093 * If IHI-ILO+1 is ...
24094 *
24095 * greater than ...but less ... the
24096 * or equal to ... than default is
24097 *
24098 * 0 30 NS = 2+
24099 * 30 60 NS = 4+
24100 * 60 150 NS = 10
24101 * 150 590 NS = **
24102 * 590 3000 NS = 64
24103 * 3000 6000 NS = 128
24104 * 6000 infinity NS = 256
24105 *
24106 * (+) By default matrices of this order are
24107 * passed to the implicit double shift routine
24108 * xLAHQR. See IPARMQ(ISPEC=12) above. These
24109 * values of NS are used only in case of a rare
24110 * xLAHQR failure.
24111 *
24112 * (**) The asterisks (**) indicate an ad-hoc
24113 * function increasing from 10 to 64.
24114 *
24115 * IPARMQ(ISPEC=16) Select structured matrix multiply.
24116 * (See ISPEC=16 above for details.)
24117 * Default: 3.
24118 *
24119 * ================================================================
24120 * .. Parameters ..
24121 INTEGER INMIN, INWIN, INIBL, ISHFTS, IACC22
24122 PARAMETER ( INMIN = 12, INWIN = 13, INIBL = 14,
24123 $ ISHFTS = 15, IACC22 = 16 )
24124 INTEGER NMIN, K22MIN, KACMIN, NIBBLE, KNWSWP
24125 PARAMETER ( NMIN = 75, K22MIN = 14, KACMIN = 14,
24126 $ NIBBLE = 14, KNWSWP = 500 )
24127 REAL TWO
24128 PARAMETER ( TWO = 2.0 )
24129 * ..
24130 * .. Local Scalars ..
24131 INTEGER NH, NS
24132 * ..
24133 * .. Intrinsic Functions ..
24134 INTRINSIC LOG, MAX, MOD, NINT, REAL
24135 * ..
24136 * .. Executable Statements ..
24137 IF( ( ISPEC.EQ.ISHFTS ) .OR. ( ISPEC.EQ.INWIN ) .OR.
24138 $ ( ISPEC.EQ.IACC22 ) ) THEN
24139 *
24140 * ==== Set the number simultaneous shifts ====
24141 *
24142 NH = IHI - ILO + 1
24143 NS = 2
24144 IF( NH.GE.30 )
24145 $ NS = 4
24146 IF( NH.GE.60 )
24147 $ NS = 10
24148 IF( NH.GE.150 )
24149 $ NS = MAX( 10, NH / NINT( LOG( REAL( NH ) ) / LOG( TWO ) ) )
24150 IF( NH.GE.590 )
24151 $ NS = 64
24152 IF( NH.GE.3000 )
24153 $ NS = 128
24154 IF( NH.GE.6000 )
24155 $ NS = 256
24156 NS = MAX( 2, NS-MOD( NS, 2 ) )
24157 END IF
24158 *
24159 IF( ISPEC.EQ.INMIN ) THEN
24160 *
24161 *
24162 * ===== Matrices of order smaller than NMIN get sent
24163 * . to xLAHQR, the classic double shift algorithm.
24164 * . This must be at least 11. ====
24165 *
24166 IPARMQ = NMIN
24167 *
24168 ELSE IF( ISPEC.EQ.INIBL ) THEN
24169 *
24170 * ==== INIBL: skip a multi-shift qr iteration and
24171 * . whenever aggressive early deflation finds
24172 * . at least (NIBBLE*(window size)/100) deflations. ====
24173 *
24174 IPARMQ = NIBBLE
24175 *
24176 ELSE IF( ISPEC.EQ.ISHFTS ) THEN
24177 *
24178 * ==== NSHFTS: The number of simultaneous shifts =====
24179 *
24180 IPARMQ = NS
24181 *
24182 ELSE IF( ISPEC.EQ.INWIN ) THEN
24183 *
24184 * ==== NW: deflation window size. ====
24185 *
24186 IF( NH.LE.KNWSWP ) THEN
24187 IPARMQ = NS
24188 ELSE
24189 IPARMQ = 3*NS / 2
24190 END IF
24191 *
24192 ELSE IF( ISPEC.EQ.IACC22 ) THEN
24193 *
24194 * ==== IACC22: Whether to accumulate reflections
24195 * . before updating the far-from-diagonal elements
24196 * . and whether to use 2-by-2 block structure while
24197 * . doing it. A small amount of work could be saved
24198 * . by making this choice dependent also upon the
24199 * . NH=IHI-ILO+1.
24200 *
24201 IPARMQ = 0
24202 IF( NS.GE.KACMIN )
24203 $ IPARMQ = 1
24204 IF( NS.GE.K22MIN )
24205 $ IPARMQ = 2
24206 *
24207 ELSE
24208 * ===== invalid value of ispec =====
24209 IPARMQ = -1
24210 *
24211 END IF
24212 *
24213 * ==== End of IPARMQ ====
24214 *
24215 END