00001 SUBROUTINE SLAQR3( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
00002 $ IHIZ, Z, LDZ, NS, ND, SR, SI, V, LDV, NH, T,
00003 $ LDT, NV, WV, LDWV, WORK, LWORK )
00004
00005
00006
00007
00008
00009
00010 INTEGER IHIZ, ILOZ, KBOT, KTOP, LDH, LDT, LDV, LDWV,
00011 $ LDZ, LWORK, N, ND, NH, NS, NV, NW
00012 LOGICAL WANTT, WANTZ
00013
00014
00015 REAL H( LDH, * ), SI( * ), SR( * ), T( LDT, * ),
00016 $ V( LDV, * ), WORK( * ), WV( LDWV, * ),
00017 $ Z( LDZ, * )
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 REAL ZERO, ONE
00159 PARAMETER ( ZERO = 0.0e0, ONE = 1.0e0 )
00160
00161
00162 REAL AA, BB, BETA, CC, CS, DD, EVI, EVK, FOO, S,
00163 $ SAFMAX, SAFMIN, SMLNUM, SN, TAU, ULP
00164 INTEGER I, IFST, ILST, INFO, INFQR, J, JW, K, KCOL,
00165 $ KEND, KLN, KROW, KWTOP, LTOP, LWK1, LWK2, LWK3,
00166 $ LWKOPT, NMIN
00167 LOGICAL BULGE, SORTED
00168
00169
00170 REAL SLAMCH
00171 INTEGER ILAENV
00172 EXTERNAL SLAMCH, ILAENV
00173
00174
00175 EXTERNAL SCOPY, SGEHRD, SGEMM, SLABAD, SLACPY, SLAHQR,
00176 $ SLANV2, SLAQR4, SLARF, SLARFG, SLASET, SORMHR,
00177 $ STREXC
00178
00179
00180 INTRINSIC ABS, INT, MAX, MIN, REAL, SQRT
00181
00182
00183
00184
00185
00186 JW = MIN( NW, KBOT-KTOP+1 )
00187 IF( JW.LE.2 ) THEN
00188 LWKOPT = 1
00189 ELSE
00190
00191
00192
00193 CALL SGEHRD( JW, 1, JW-1, T, LDT, WORK, WORK, -1, INFO )
00194 LWK1 = INT( WORK( 1 ) )
00195
00196
00197
00198 CALL SORMHR( 'R', 'N', JW, JW, 1, JW-1, T, LDT, WORK, V, LDV,
00199 $ WORK, -1, INFO )
00200 LWK2 = INT( WORK( 1 ) )
00201
00202
00203
00204 CALL SLAQR4( .true., .true., JW, 1, JW, T, LDT, SR, SI, 1, JW,
00205 $ V, LDV, WORK, -1, INFQR )
00206 LWK3 = INT( WORK( 1 ) )
00207
00208
00209
00210 LWKOPT = MAX( JW+MAX( LWK1, LWK2 ), LWK3 )
00211 END IF
00212
00213
00214
00215 IF( LWORK.EQ.-1 ) THEN
00216 WORK( 1 ) = REAL( LWKOPT )
00217 RETURN
00218 END IF
00219
00220
00221
00222 NS = 0
00223 ND = 0
00224 WORK( 1 ) = ONE
00225 IF( KTOP.GT.KBOT )
00226 $ RETURN
00227
00228 IF( NW.LT.1 )
00229 $ RETURN
00230
00231
00232
00233 SAFMIN = SLAMCH( 'SAFE MINIMUM' )
00234 SAFMAX = ONE / SAFMIN
00235 CALL SLABAD( SAFMIN, SAFMAX )
00236 ULP = SLAMCH( 'PRECISION' )
00237 SMLNUM = SAFMIN*( REAL( N ) / ULP )
00238
00239
00240
00241 JW = MIN( NW, KBOT-KTOP+1 )
00242 KWTOP = KBOT - JW + 1
00243 IF( KWTOP.EQ.KTOP ) THEN
00244 S = ZERO
00245 ELSE
00246 S = H( KWTOP, KWTOP-1 )
00247 END IF
00248
00249 IF( KBOT.EQ.KWTOP ) THEN
00250
00251
00252
00253 SR( KWTOP ) = H( KWTOP, KWTOP )
00254 SI( KWTOP ) = ZERO
00255 NS = 1
00256 ND = 0
00257 IF( ABS( S ).LE.MAX( SMLNUM, ULP*ABS( H( KWTOP, KWTOP ) ) ) )
00258 $ THEN
00259 NS = 0
00260 ND = 1
00261 IF( KWTOP.GT.KTOP )
00262 $ H( KWTOP, KWTOP-1 ) = ZERO
00263 END IF
00264 WORK( 1 ) = ONE
00265 RETURN
00266 END IF
00267
00268
00269
00270
00271
00272
00273
00274 CALL SLACPY( 'U', JW, JW, H( KWTOP, KWTOP ), LDH, T, LDT )
00275 CALL SCOPY( JW-1, H( KWTOP+1, KWTOP ), LDH+1, T( 2, 1 ), LDT+1 )
00276
00277 CALL SLASET( 'A', JW, JW, ZERO, ONE, V, LDV )
00278 NMIN = ILAENV( 12, 'SLAQR3', 'SV', JW, 1, JW, LWORK )
00279 IF( JW.GT.NMIN ) THEN
00280 CALL SLAQR4( .true., .true., JW, 1, JW, T, LDT, SR( KWTOP ),
00281 $ SI( KWTOP ), 1, JW, V, LDV, WORK, LWORK, INFQR )
00282 ELSE
00283 CALL SLAHQR( .true., .true., JW, 1, JW, T, LDT, SR( KWTOP ),
00284 $ SI( KWTOP ), 1, JW, V, LDV, INFQR )
00285 END IF
00286
00287
00288
00289 DO 10 J = 1, JW - 3
00290 T( J+2, J ) = ZERO
00291 T( J+3, J ) = ZERO
00292 10 CONTINUE
00293 IF( JW.GT.2 )
00294 $ T( JW, JW-2 ) = ZERO
00295
00296
00297
00298 NS = JW
00299 ILST = INFQR + 1
00300 20 CONTINUE
00301 IF( ILST.LE.NS ) THEN
00302 IF( NS.EQ.1 ) THEN
00303 BULGE = .FALSE.
00304 ELSE
00305 BULGE = T( NS, NS-1 ).NE.ZERO
00306 END IF
00307
00308
00309
00310 IF( .NOT.BULGE ) THEN
00311
00312
00313
00314 FOO = ABS( T( NS, NS ) )
00315 IF( FOO.EQ.ZERO )
00316 $ FOO = ABS( S )
00317 IF( ABS( S*V( 1, NS ) ).LE.MAX( SMLNUM, ULP*FOO ) ) THEN
00318
00319
00320
00321 NS = NS - 1
00322 ELSE
00323
00324
00325
00326
00327 IFST = NS
00328 CALL STREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, WORK,
00329 $ INFO )
00330 ILST = ILST + 1
00331 END IF
00332 ELSE
00333
00334
00335
00336 FOO = ABS( T( NS, NS ) ) + SQRT( ABS( T( NS, NS-1 ) ) )*
00337 $ SQRT( ABS( T( NS-1, NS ) ) )
00338 IF( FOO.EQ.ZERO )
00339 $ FOO = ABS( S )
00340 IF( MAX( ABS( S*V( 1, NS ) ), ABS( S*V( 1, NS-1 ) ) ).LE.
00341 $ MAX( SMLNUM, ULP*FOO ) ) THEN
00342
00343
00344
00345 NS = NS - 2
00346 ELSE
00347
00348
00349
00350
00351
00352 IFST = NS
00353 CALL STREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, WORK,
00354 $ INFO )
00355 ILST = ILST + 2
00356 END IF
00357 END IF
00358
00359
00360
00361 GO TO 20
00362 END IF
00363
00364
00365
00366 IF( NS.EQ.0 )
00367 $ S = ZERO
00368
00369 IF( NS.LT.JW ) THEN
00370
00371
00372
00373
00374
00375 SORTED = .false.
00376 I = NS + 1
00377 30 CONTINUE
00378 IF( SORTED )
00379 $ GO TO 50
00380 SORTED = .true.
00381
00382 KEND = I - 1
00383 I = INFQR + 1
00384 IF( I.EQ.NS ) THEN
00385 K = I + 1
00386 ELSE IF( T( I+1, I ).EQ.ZERO ) THEN
00387 K = I + 1
00388 ELSE
00389 K = I + 2
00390 END IF
00391 40 CONTINUE
00392 IF( K.LE.KEND ) THEN
00393 IF( K.EQ.I+1 ) THEN
00394 EVI = ABS( T( I, I ) )
00395 ELSE
00396 EVI = ABS( T( I, I ) ) + SQRT( ABS( T( I+1, I ) ) )*
00397 $ SQRT( ABS( T( I, I+1 ) ) )
00398 END IF
00399
00400 IF( K.EQ.KEND ) THEN
00401 EVK = ABS( T( K, K ) )
00402 ELSE IF( T( K+1, K ).EQ.ZERO ) THEN
00403 EVK = ABS( T( K, K ) )
00404 ELSE
00405 EVK = ABS( T( K, K ) ) + SQRT( ABS( T( K+1, K ) ) )*
00406 $ SQRT( ABS( T( K, K+1 ) ) )
00407 END IF
00408
00409 IF( EVI.GE.EVK ) THEN
00410 I = K
00411 ELSE
00412 SORTED = .false.
00413 IFST = I
00414 ILST = K
00415 CALL STREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, WORK,
00416 $ INFO )
00417 IF( INFO.EQ.0 ) THEN
00418 I = ILST
00419 ELSE
00420 I = K
00421 END IF
00422 END IF
00423 IF( I.EQ.KEND ) THEN
00424 K = I + 1
00425 ELSE IF( T( I+1, I ).EQ.ZERO ) THEN
00426 K = I + 1
00427 ELSE
00428 K = I + 2
00429 END IF
00430 GO TO 40
00431 END IF
00432 GO TO 30
00433 50 CONTINUE
00434 END IF
00435
00436
00437
00438 I = JW
00439 60 CONTINUE
00440 IF( I.GE.INFQR+1 ) THEN
00441 IF( I.EQ.INFQR+1 ) THEN
00442 SR( KWTOP+I-1 ) = T( I, I )
00443 SI( KWTOP+I-1 ) = ZERO
00444 I = I - 1
00445 ELSE IF( T( I, I-1 ).EQ.ZERO ) THEN
00446 SR( KWTOP+I-1 ) = T( I, I )
00447 SI( KWTOP+I-1 ) = ZERO
00448 I = I - 1
00449 ELSE
00450 AA = T( I-1, I-1 )
00451 CC = T( I, I-1 )
00452 BB = T( I-1, I )
00453 DD = T( I, I )
00454 CALL SLANV2( AA, BB, CC, DD, SR( KWTOP+I-2 ),
00455 $ SI( KWTOP+I-2 ), SR( KWTOP+I-1 ),
00456 $ SI( KWTOP+I-1 ), CS, SN )
00457 I = I - 2
00458 END IF
00459 GO TO 60
00460 END IF
00461
00462 IF( NS.LT.JW .OR. S.EQ.ZERO ) THEN
00463 IF( NS.GT.1 .AND. S.NE.ZERO ) THEN
00464
00465
00466
00467 CALL SCOPY( NS, V, LDV, WORK, 1 )
00468 BETA = WORK( 1 )
00469 CALL SLARFG( NS, BETA, WORK( 2 ), 1, TAU )
00470 WORK( 1 ) = ONE
00471
00472 CALL SLASET( 'L', JW-2, JW-2, ZERO, ZERO, T( 3, 1 ), LDT )
00473
00474 CALL SLARF( 'L', NS, JW, WORK, 1, TAU, T, LDT,
00475 $ WORK( JW+1 ) )
00476 CALL SLARF( 'R', NS, NS, WORK, 1, TAU, T, LDT,
00477 $ WORK( JW+1 ) )
00478 CALL SLARF( 'R', JW, NS, WORK, 1, TAU, V, LDV,
00479 $ WORK( JW+1 ) )
00480
00481 CALL SGEHRD( JW, 1, NS, T, LDT, WORK, WORK( JW+1 ),
00482 $ LWORK-JW, INFO )
00483 END IF
00484
00485
00486
00487 IF( KWTOP.GT.1 )
00488 $ H( KWTOP, KWTOP-1 ) = S*V( 1, 1 )
00489 CALL SLACPY( 'U', JW, JW, T, LDT, H( KWTOP, KWTOP ), LDH )
00490 CALL SCOPY( JW-1, T( 2, 1 ), LDT+1, H( KWTOP+1, KWTOP ),
00491 $ LDH+1 )
00492
00493
00494
00495
00496 IF( NS.GT.1 .AND. S.NE.ZERO )
00497 $ CALL SORMHR( 'R', 'N', JW, NS, 1, NS, T, LDT, WORK, V, LDV,
00498 $ WORK( JW+1 ), LWORK-JW, INFO )
00499
00500
00501
00502 IF( WANTT ) THEN
00503 LTOP = 1
00504 ELSE
00505 LTOP = KTOP
00506 END IF
00507 DO 70 KROW = LTOP, KWTOP - 1, NV
00508 KLN = MIN( NV, KWTOP-KROW )
00509 CALL SGEMM( 'N', 'N', KLN, JW, JW, ONE, H( KROW, KWTOP ),
00510 $ LDH, V, LDV, ZERO, WV, LDWV )
00511 CALL SLACPY( 'A', KLN, JW, WV, LDWV, H( KROW, KWTOP ), LDH )
00512 70 CONTINUE
00513
00514
00515
00516 IF( WANTT ) THEN
00517 DO 80 KCOL = KBOT + 1, N, NH
00518 KLN = MIN( NH, N-KCOL+1 )
00519 CALL SGEMM( 'C', 'N', JW, KLN, JW, ONE, V, LDV,
00520 $ H( KWTOP, KCOL ), LDH, ZERO, T, LDT )
00521 CALL SLACPY( 'A', JW, KLN, T, LDT, H( KWTOP, KCOL ),
00522 $ LDH )
00523 80 CONTINUE
00524 END IF
00525
00526
00527
00528 IF( WANTZ ) THEN
00529 DO 90 KROW = ILOZ, IHIZ, NV
00530 KLN = MIN( NV, IHIZ-KROW+1 )
00531 CALL SGEMM( 'N', 'N', KLN, JW, JW, ONE, Z( KROW, KWTOP ),
00532 $ LDZ, V, LDV, ZERO, WV, LDWV )
00533 CALL SLACPY( 'A', KLN, JW, WV, LDWV, Z( KROW, KWTOP ),
00534 $ LDZ )
00535 90 CONTINUE
00536 END IF
00537 END IF
00538
00539
00540
00541 ND = JW - NS
00542
00543
00544
00545
00546
00547
00548
00549 NS = NS - INFQR
00550
00551
00552
00553 WORK( 1 ) = REAL( LWKOPT )
00554
00555
00556
00557 END