00001 SUBROUTINE ZLAQR2( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
00002 $ IHIZ, Z, LDZ, NS, ND, SH, V, LDV, NH, T, LDT,
00003 $ 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 COMPLEX*16 H( LDH, * ), SH( * ), T( LDT, * ), V( LDV, * ),
00016 $ WORK( * ), WV( LDWV, * ), Z( LDZ, * )
00017
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 COMPLEX*16 ZERO, ONE
00158 PARAMETER ( ZERO = ( 0.0d0, 0.0d0 ),
00159 $ ONE = ( 1.0d0, 0.0d0 ) )
00160 DOUBLE PRECISION RZERO, RONE
00161 PARAMETER ( RZERO = 0.0d0, RONE = 1.0d0 )
00162
00163
00164 COMPLEX*16 BETA, CDUM, S, TAU
00165 DOUBLE PRECISION FOO, SAFMAX, SAFMIN, SMLNUM, ULP
00166 INTEGER I, IFST, ILST, INFO, INFQR, J, JW, KCOL, KLN,
00167 $ KNT, KROW, KWTOP, LTOP, LWK1, LWK2, LWKOPT
00168
00169
00170 DOUBLE PRECISION DLAMCH
00171 EXTERNAL DLAMCH
00172
00173
00174 EXTERNAL DLABAD, ZCOPY, ZGEHRD, ZGEMM, ZLACPY, ZLAHQR,
00175 $ ZLARF, ZLARFG, ZLASET, ZTREXC, ZUNMHR
00176
00177
00178 INTRINSIC ABS, DBLE, DCMPLX, DCONJG, DIMAG, INT, MAX, MIN
00179
00180
00181 DOUBLE PRECISION CABS1
00182
00183
00184 CABS1( CDUM ) = ABS( DBLE( CDUM ) ) + ABS( DIMAG( CDUM ) )
00185
00186
00187
00188
00189
00190 JW = MIN( NW, KBOT-KTOP+1 )
00191 IF( JW.LE.2 ) THEN
00192 LWKOPT = 1
00193 ELSE
00194
00195
00196
00197 CALL ZGEHRD( JW, 1, JW-1, T, LDT, WORK, WORK, -1, INFO )
00198 LWK1 = INT( WORK( 1 ) )
00199
00200
00201
00202 CALL ZUNMHR( 'R', 'N', JW, JW, 1, JW-1, T, LDT, WORK, V, LDV,
00203 $ WORK, -1, INFO )
00204 LWK2 = INT( WORK( 1 ) )
00205
00206
00207
00208 LWKOPT = JW + MAX( LWK1, LWK2 )
00209 END IF
00210
00211
00212
00213 IF( LWORK.EQ.-1 ) THEN
00214 WORK( 1 ) = DCMPLX( LWKOPT, 0 )
00215 RETURN
00216 END IF
00217
00218
00219
00220 NS = 0
00221 ND = 0
00222 WORK( 1 ) = ONE
00223 IF( KTOP.GT.KBOT )
00224 $ RETURN
00225
00226 IF( NW.LT.1 )
00227 $ RETURN
00228
00229
00230
00231 SAFMIN = DLAMCH( 'SAFE MINIMUM' )
00232 SAFMAX = RONE / SAFMIN
00233 CALL DLABAD( SAFMIN, SAFMAX )
00234 ULP = DLAMCH( 'PRECISION' )
00235 SMLNUM = SAFMIN*( DBLE( N ) / ULP )
00236
00237
00238
00239 JW = MIN( NW, KBOT-KTOP+1 )
00240 KWTOP = KBOT - JW + 1
00241 IF( KWTOP.EQ.KTOP ) THEN
00242 S = ZERO
00243 ELSE
00244 S = H( KWTOP, KWTOP-1 )
00245 END IF
00246
00247 IF( KBOT.EQ.KWTOP ) THEN
00248
00249
00250
00251 SH( KWTOP ) = H( KWTOP, KWTOP )
00252 NS = 1
00253 ND = 0
00254 IF( CABS1( S ).LE.MAX( SMLNUM, ULP*CABS1( H( KWTOP,
00255 $ KWTOP ) ) ) ) THEN
00256 NS = 0
00257 ND = 1
00258 IF( KWTOP.GT.KTOP )
00259 $ H( KWTOP, KWTOP-1 ) = ZERO
00260 END IF
00261 WORK( 1 ) = ONE
00262 RETURN
00263 END IF
00264
00265
00266
00267
00268
00269
00270
00271 CALL ZLACPY( 'U', JW, JW, H( KWTOP, KWTOP ), LDH, T, LDT )
00272 CALL ZCOPY( JW-1, H( KWTOP+1, KWTOP ), LDH+1, T( 2, 1 ), LDT+1 )
00273
00274 CALL ZLASET( 'A', JW, JW, ZERO, ONE, V, LDV )
00275 CALL ZLAHQR( .true., .true., JW, 1, JW, T, LDT, SH( KWTOP ), 1,
00276 $ JW, V, LDV, INFQR )
00277
00278
00279
00280 NS = JW
00281 ILST = INFQR + 1
00282 DO 10 KNT = INFQR + 1, JW
00283
00284
00285
00286 FOO = CABS1( T( NS, NS ) )
00287 IF( FOO.EQ.RZERO )
00288 $ FOO = CABS1( S )
00289 IF( CABS1( S )*CABS1( V( 1, NS ) ).LE.MAX( SMLNUM, ULP*FOO ) )
00290 $ THEN
00291
00292
00293
00294 NS = NS - 1
00295 ELSE
00296
00297
00298
00299
00300 IFST = NS
00301 CALL ZTREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, INFO )
00302 ILST = ILST + 1
00303 END IF
00304 10 CONTINUE
00305
00306
00307
00308 IF( NS.EQ.0 )
00309 $ S = ZERO
00310
00311 IF( NS.LT.JW ) THEN
00312
00313
00314
00315
00316 DO 30 I = INFQR + 1, NS
00317 IFST = I
00318 DO 20 J = I + 1, NS
00319 IF( CABS1( T( J, J ) ).GT.CABS1( T( IFST, IFST ) ) )
00320 $ IFST = J
00321 20 CONTINUE
00322 ILST = I
00323 IF( IFST.NE.ILST )
00324 $ CALL ZTREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, INFO )
00325 30 CONTINUE
00326 END IF
00327
00328
00329
00330 DO 40 I = INFQR + 1, JW
00331 SH( KWTOP+I-1 ) = T( I, I )
00332 40 CONTINUE
00333
00334
00335 IF( NS.LT.JW .OR. S.EQ.ZERO ) THEN
00336 IF( NS.GT.1 .AND. S.NE.ZERO ) THEN
00337
00338
00339
00340 CALL ZCOPY( NS, V, LDV, WORK, 1 )
00341 DO 50 I = 1, NS
00342 WORK( I ) = DCONJG( WORK( I ) )
00343 50 CONTINUE
00344 BETA = WORK( 1 )
00345 CALL ZLARFG( NS, BETA, WORK( 2 ), 1, TAU )
00346 WORK( 1 ) = ONE
00347
00348 CALL ZLASET( 'L', JW-2, JW-2, ZERO, ZERO, T( 3, 1 ), LDT )
00349
00350 CALL ZLARF( 'L', NS, JW, WORK, 1, DCONJG( TAU ), T, LDT,
00351 $ WORK( JW+1 ) )
00352 CALL ZLARF( 'R', NS, NS, WORK, 1, TAU, T, LDT,
00353 $ WORK( JW+1 ) )
00354 CALL ZLARF( 'R', JW, NS, WORK, 1, TAU, V, LDV,
00355 $ WORK( JW+1 ) )
00356
00357 CALL ZGEHRD( JW, 1, NS, T, LDT, WORK, WORK( JW+1 ),
00358 $ LWORK-JW, INFO )
00359 END IF
00360
00361
00362
00363 IF( KWTOP.GT.1 )
00364 $ H( KWTOP, KWTOP-1 ) = S*DCONJG( V( 1, 1 ) )
00365 CALL ZLACPY( 'U', JW, JW, T, LDT, H( KWTOP, KWTOP ), LDH )
00366 CALL ZCOPY( JW-1, T( 2, 1 ), LDT+1, H( KWTOP+1, KWTOP ),
00367 $ LDH+1 )
00368
00369
00370
00371
00372 IF( NS.GT.1 .AND. S.NE.ZERO )
00373 $ CALL ZUNMHR( 'R', 'N', JW, NS, 1, NS, T, LDT, WORK, V, LDV,
00374 $ WORK( JW+1 ), LWORK-JW, INFO )
00375
00376
00377
00378 IF( WANTT ) THEN
00379 LTOP = 1
00380 ELSE
00381 LTOP = KTOP
00382 END IF
00383 DO 60 KROW = LTOP, KWTOP - 1, NV
00384 KLN = MIN( NV, KWTOP-KROW )
00385 CALL ZGEMM( 'N', 'N', KLN, JW, JW, ONE, H( KROW, KWTOP ),
00386 $ LDH, V, LDV, ZERO, WV, LDWV )
00387 CALL ZLACPY( 'A', KLN, JW, WV, LDWV, H( KROW, KWTOP ), LDH )
00388 60 CONTINUE
00389
00390
00391
00392 IF( WANTT ) THEN
00393 DO 70 KCOL = KBOT + 1, N, NH
00394 KLN = MIN( NH, N-KCOL+1 )
00395 CALL ZGEMM( 'C', 'N', JW, KLN, JW, ONE, V, LDV,
00396 $ H( KWTOP, KCOL ), LDH, ZERO, T, LDT )
00397 CALL ZLACPY( 'A', JW, KLN, T, LDT, H( KWTOP, KCOL ),
00398 $ LDH )
00399 70 CONTINUE
00400 END IF
00401
00402
00403
00404 IF( WANTZ ) THEN
00405 DO 80 KROW = ILOZ, IHIZ, NV
00406 KLN = MIN( NV, IHIZ-KROW+1 )
00407 CALL ZGEMM( 'N', 'N', KLN, JW, JW, ONE, Z( KROW, KWTOP ),
00408 $ LDZ, V, LDV, ZERO, WV, LDWV )
00409 CALL ZLACPY( 'A', KLN, JW, WV, LDWV, Z( KROW, KWTOP ),
00410 $ LDZ )
00411 80 CONTINUE
00412 END IF
00413 END IF
00414
00415
00416
00417 ND = JW - NS
00418
00419
00420
00421
00422
00423
00424
00425 NS = NS - INFQR
00426
00427
00428
00429 WORK( 1 ) = DCMPLX( LWKOPT, 0 )
00430
00431
00432
00433 END