00001 SUBROUTINE CTGEVC( SIDE, HOWMNY, SELECT, N, S, LDS, P, LDP, VL,
00002 $ LDVL, VR, LDVR, MM, M, WORK, RWORK, INFO )
00003
00004
00005
00006
00007
00008
00009
00010 CHARACTER HOWMNY, SIDE
00011 INTEGER INFO, LDP, LDS, LDVL, LDVR, M, MM, N
00012
00013
00014 LOGICAL SELECT( * )
00015 REAL RWORK( * )
00016 COMPLEX P( LDP, * ), S( LDS, * ), VL( LDVL, * ),
00017 $ VR( LDVR, * ), WORK( * )
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 REAL ZERO, ONE
00140 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
00141 COMPLEX CZERO, CONE
00142 PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ),
00143 $ CONE = ( 1.0E+0, 0.0E+0 ) )
00144
00145
00146 LOGICAL COMPL, COMPR, ILALL, ILBACK, ILBBAD, ILCOMP,
00147 $ LSA, LSB
00148 INTEGER I, IBEG, IEIG, IEND, IHWMNY, IM, ISIDE, ISRC,
00149 $ J, JE, JR
00150 REAL ACOEFA, ACOEFF, ANORM, ASCALE, BCOEFA, BIG,
00151 $ BIGNUM, BNORM, BSCALE, DMIN, SAFMIN, SBETA,
00152 $ SCALE, SMALL, TEMP, ULP, XMAX
00153 COMPLEX BCOEFF, CA, CB, D, SALPHA, SUM, SUMA, SUMB, X
00154
00155
00156 LOGICAL LSAME
00157 REAL SLAMCH
00158 COMPLEX CLADIV
00159 EXTERNAL LSAME, SLAMCH, CLADIV
00160
00161
00162 EXTERNAL CGEMV, SLABAD, XERBLA
00163
00164
00165 INTRINSIC ABS, AIMAG, CMPLX, CONJG, MAX, MIN, REAL
00166
00167
00168 REAL ABS1
00169
00170
00171 ABS1( X ) = ABS( REAL( X ) ) + ABS( AIMAG( X ) )
00172
00173
00174
00175
00176
00177 IF( LSAME( HOWMNY, 'A' ) ) THEN
00178 IHWMNY = 1
00179 ILALL = .TRUE.
00180 ILBACK = .FALSE.
00181 ELSE IF( LSAME( HOWMNY, 'S' ) ) THEN
00182 IHWMNY = 2
00183 ILALL = .FALSE.
00184 ILBACK = .FALSE.
00185 ELSE IF( LSAME( HOWMNY, 'B' ) ) THEN
00186 IHWMNY = 3
00187 ILALL = .TRUE.
00188 ILBACK = .TRUE.
00189 ELSE
00190 IHWMNY = -1
00191 END IF
00192
00193 IF( LSAME( SIDE, 'R' ) ) THEN
00194 ISIDE = 1
00195 COMPL = .FALSE.
00196 COMPR = .TRUE.
00197 ELSE IF( LSAME( SIDE, 'L' ) ) THEN
00198 ISIDE = 2
00199 COMPL = .TRUE.
00200 COMPR = .FALSE.
00201 ELSE IF( LSAME( SIDE, 'B' ) ) THEN
00202 ISIDE = 3
00203 COMPL = .TRUE.
00204 COMPR = .TRUE.
00205 ELSE
00206 ISIDE = -1
00207 END IF
00208
00209 INFO = 0
00210 IF( ISIDE.LT.0 ) THEN
00211 INFO = -1
00212 ELSE IF( IHWMNY.LT.0 ) THEN
00213 INFO = -2
00214 ELSE IF( N.LT.0 ) THEN
00215 INFO = -4
00216 ELSE IF( LDS.LT.MAX( 1, N ) ) THEN
00217 INFO = -6
00218 ELSE IF( LDP.LT.MAX( 1, N ) ) THEN
00219 INFO = -8
00220 END IF
00221 IF( INFO.NE.0 ) THEN
00222 CALL XERBLA( 'CTGEVC', -INFO )
00223 RETURN
00224 END IF
00225
00226
00227
00228 IF( .NOT.ILALL ) THEN
00229 IM = 0
00230 DO 10 J = 1, N
00231 IF( SELECT( J ) )
00232 $ IM = IM + 1
00233 10 CONTINUE
00234 ELSE
00235 IM = N
00236 END IF
00237
00238
00239
00240 ILBBAD = .FALSE.
00241 DO 20 J = 1, N
00242 IF( AIMAG( P( J, J ) ).NE.ZERO )
00243 $ ILBBAD = .TRUE.
00244 20 CONTINUE
00245
00246 IF( ILBBAD ) THEN
00247 INFO = -7
00248 ELSE IF( COMPL .AND. LDVL.LT.N .OR. LDVL.LT.1 ) THEN
00249 INFO = -10
00250 ELSE IF( COMPR .AND. LDVR.LT.N .OR. LDVR.LT.1 ) THEN
00251 INFO = -12
00252 ELSE IF( MM.LT.IM ) THEN
00253 INFO = -13
00254 END IF
00255 IF( INFO.NE.0 ) THEN
00256 CALL XERBLA( 'CTGEVC', -INFO )
00257 RETURN
00258 END IF
00259
00260
00261
00262 M = IM
00263 IF( N.EQ.0 )
00264 $ RETURN
00265
00266
00267
00268 SAFMIN = SLAMCH( 'Safe minimum' )
00269 BIG = ONE / SAFMIN
00270 CALL SLABAD( SAFMIN, BIG )
00271 ULP = SLAMCH( 'Epsilon' )*SLAMCH( 'Base' )
00272 SMALL = SAFMIN*N / ULP
00273 BIG = ONE / SMALL
00274 BIGNUM = ONE / ( SAFMIN*N )
00275
00276
00277
00278
00279
00280 ANORM = ABS1( S( 1, 1 ) )
00281 BNORM = ABS1( P( 1, 1 ) )
00282 RWORK( 1 ) = ZERO
00283 RWORK( N+1 ) = ZERO
00284 DO 40 J = 2, N
00285 RWORK( J ) = ZERO
00286 RWORK( N+J ) = ZERO
00287 DO 30 I = 1, J - 1
00288 RWORK( J ) = RWORK( J ) + ABS1( S( I, J ) )
00289 RWORK( N+J ) = RWORK( N+J ) + ABS1( P( I, J ) )
00290 30 CONTINUE
00291 ANORM = MAX( ANORM, RWORK( J )+ABS1( S( J, J ) ) )
00292 BNORM = MAX( BNORM, RWORK( N+J )+ABS1( P( J, J ) ) )
00293 40 CONTINUE
00294
00295 ASCALE = ONE / MAX( ANORM, SAFMIN )
00296 BSCALE = ONE / MAX( BNORM, SAFMIN )
00297
00298
00299
00300 IF( COMPL ) THEN
00301 IEIG = 0
00302
00303
00304
00305 DO 140 JE = 1, N
00306 IF( ILALL ) THEN
00307 ILCOMP = .TRUE.
00308 ELSE
00309 ILCOMP = SELECT( JE )
00310 END IF
00311 IF( ILCOMP ) THEN
00312 IEIG = IEIG + 1
00313
00314 IF( ABS1( S( JE, JE ) ).LE.SAFMIN .AND.
00315 $ ABS( REAL( P( JE, JE ) ) ).LE.SAFMIN ) THEN
00316
00317
00318
00319 DO 50 JR = 1, N
00320 VL( JR, IEIG ) = CZERO
00321 50 CONTINUE
00322 VL( IEIG, IEIG ) = CONE
00323 GO TO 140
00324 END IF
00325
00326
00327
00328
00329
00330
00331 TEMP = ONE / MAX( ABS1( S( JE, JE ) )*ASCALE,
00332 $ ABS( REAL( P( JE, JE ) ) )*BSCALE, SAFMIN )
00333 SALPHA = ( TEMP*S( JE, JE ) )*ASCALE
00334 SBETA = ( TEMP*REAL( P( JE, JE ) ) )*BSCALE
00335 ACOEFF = SBETA*ASCALE
00336 BCOEFF = SALPHA*BSCALE
00337
00338
00339
00340 LSA = ABS( SBETA ).GE.SAFMIN .AND. ABS( ACOEFF ).LT.SMALL
00341 LSB = ABS1( SALPHA ).GE.SAFMIN .AND. ABS1( BCOEFF ).LT.
00342 $ SMALL
00343
00344 SCALE = ONE
00345 IF( LSA )
00346 $ SCALE = ( SMALL / ABS( SBETA ) )*MIN( ANORM, BIG )
00347 IF( LSB )
00348 $ SCALE = MAX( SCALE, ( SMALL / ABS1( SALPHA ) )*
00349 $ MIN( BNORM, BIG ) )
00350 IF( LSA .OR. LSB ) THEN
00351 SCALE = MIN( SCALE, ONE /
00352 $ ( SAFMIN*MAX( ONE, ABS( ACOEFF ),
00353 $ ABS1( BCOEFF ) ) ) )
00354 IF( LSA ) THEN
00355 ACOEFF = ASCALE*( SCALE*SBETA )
00356 ELSE
00357 ACOEFF = SCALE*ACOEFF
00358 END IF
00359 IF( LSB ) THEN
00360 BCOEFF = BSCALE*( SCALE*SALPHA )
00361 ELSE
00362 BCOEFF = SCALE*BCOEFF
00363 END IF
00364 END IF
00365
00366 ACOEFA = ABS( ACOEFF )
00367 BCOEFA = ABS1( BCOEFF )
00368 XMAX = ONE
00369 DO 60 JR = 1, N
00370 WORK( JR ) = CZERO
00371 60 CONTINUE
00372 WORK( JE ) = CONE
00373 DMIN = MAX( ULP*ACOEFA*ANORM, ULP*BCOEFA*BNORM, SAFMIN )
00374
00375
00376
00377
00378
00379
00380
00381 DO 100 J = JE + 1, N
00382
00383
00384
00385
00386
00387
00388
00389 TEMP = ONE / XMAX
00390 IF( ACOEFA*RWORK( J )+BCOEFA*RWORK( N+J ).GT.BIGNUM*
00391 $ TEMP ) THEN
00392 DO 70 JR = JE, J - 1
00393 WORK( JR ) = TEMP*WORK( JR )
00394 70 CONTINUE
00395 XMAX = ONE
00396 END IF
00397 SUMA = CZERO
00398 SUMB = CZERO
00399
00400 DO 80 JR = JE, J - 1
00401 SUMA = SUMA + CONJG( S( JR, J ) )*WORK( JR )
00402 SUMB = SUMB + CONJG( P( JR, J ) )*WORK( JR )
00403 80 CONTINUE
00404 SUM = ACOEFF*SUMA - CONJG( BCOEFF )*SUMB
00405
00406
00407
00408
00409
00410 D = CONJG( ACOEFF*S( J, J )-BCOEFF*P( J, J ) )
00411 IF( ABS1( D ).LE.DMIN )
00412 $ D = CMPLX( DMIN )
00413
00414 IF( ABS1( D ).LT.ONE ) THEN
00415 IF( ABS1( SUM ).GE.BIGNUM*ABS1( D ) ) THEN
00416 TEMP = ONE / ABS1( SUM )
00417 DO 90 JR = JE, J - 1
00418 WORK( JR ) = TEMP*WORK( JR )
00419 90 CONTINUE
00420 XMAX = TEMP*XMAX
00421 SUM = TEMP*SUM
00422 END IF
00423 END IF
00424 WORK( J ) = CLADIV( -SUM, D )
00425 XMAX = MAX( XMAX, ABS1( WORK( J ) ) )
00426 100 CONTINUE
00427
00428
00429
00430 IF( ILBACK ) THEN
00431 CALL CGEMV( 'N', N, N+1-JE, CONE, VL( 1, JE ), LDVL,
00432 $ WORK( JE ), 1, CZERO, WORK( N+1 ), 1 )
00433 ISRC = 2
00434 IBEG = 1
00435 ELSE
00436 ISRC = 1
00437 IBEG = JE
00438 END IF
00439
00440
00441
00442 XMAX = ZERO
00443 DO 110 JR = IBEG, N
00444 XMAX = MAX( XMAX, ABS1( WORK( ( ISRC-1 )*N+JR ) ) )
00445 110 CONTINUE
00446
00447 IF( XMAX.GT.SAFMIN ) THEN
00448 TEMP = ONE / XMAX
00449 DO 120 JR = IBEG, N
00450 VL( JR, IEIG ) = TEMP*WORK( ( ISRC-1 )*N+JR )
00451 120 CONTINUE
00452 ELSE
00453 IBEG = N + 1
00454 END IF
00455
00456 DO 130 JR = 1, IBEG - 1
00457 VL( JR, IEIG ) = CZERO
00458 130 CONTINUE
00459
00460 END IF
00461 140 CONTINUE
00462 END IF
00463
00464
00465
00466 IF( COMPR ) THEN
00467 IEIG = IM + 1
00468
00469
00470
00471 DO 250 JE = N, 1, -1
00472 IF( ILALL ) THEN
00473 ILCOMP = .TRUE.
00474 ELSE
00475 ILCOMP = SELECT( JE )
00476 END IF
00477 IF( ILCOMP ) THEN
00478 IEIG = IEIG - 1
00479
00480 IF( ABS1( S( JE, JE ) ).LE.SAFMIN .AND.
00481 $ ABS( REAL( P( JE, JE ) ) ).LE.SAFMIN ) THEN
00482
00483
00484
00485 DO 150 JR = 1, N
00486 VR( JR, IEIG ) = CZERO
00487 150 CONTINUE
00488 VR( IEIG, IEIG ) = CONE
00489 GO TO 250
00490 END IF
00491
00492
00493
00494
00495
00496
00497 TEMP = ONE / MAX( ABS1( S( JE, JE ) )*ASCALE,
00498 $ ABS( REAL( P( JE, JE ) ) )*BSCALE, SAFMIN )
00499 SALPHA = ( TEMP*S( JE, JE ) )*ASCALE
00500 SBETA = ( TEMP*REAL( P( JE, JE ) ) )*BSCALE
00501 ACOEFF = SBETA*ASCALE
00502 BCOEFF = SALPHA*BSCALE
00503
00504
00505
00506 LSA = ABS( SBETA ).GE.SAFMIN .AND. ABS( ACOEFF ).LT.SMALL
00507 LSB = ABS1( SALPHA ).GE.SAFMIN .AND. ABS1( BCOEFF ).LT.
00508 $ SMALL
00509
00510 SCALE = ONE
00511 IF( LSA )
00512 $ SCALE = ( SMALL / ABS( SBETA ) )*MIN( ANORM, BIG )
00513 IF( LSB )
00514 $ SCALE = MAX( SCALE, ( SMALL / ABS1( SALPHA ) )*
00515 $ MIN( BNORM, BIG ) )
00516 IF( LSA .OR. LSB ) THEN
00517 SCALE = MIN( SCALE, ONE /
00518 $ ( SAFMIN*MAX( ONE, ABS( ACOEFF ),
00519 $ ABS1( BCOEFF ) ) ) )
00520 IF( LSA ) THEN
00521 ACOEFF = ASCALE*( SCALE*SBETA )
00522 ELSE
00523 ACOEFF = SCALE*ACOEFF
00524 END IF
00525 IF( LSB ) THEN
00526 BCOEFF = BSCALE*( SCALE*SALPHA )
00527 ELSE
00528 BCOEFF = SCALE*BCOEFF
00529 END IF
00530 END IF
00531
00532 ACOEFA = ABS( ACOEFF )
00533 BCOEFA = ABS1( BCOEFF )
00534 XMAX = ONE
00535 DO 160 JR = 1, N
00536 WORK( JR ) = CZERO
00537 160 CONTINUE
00538 WORK( JE ) = CONE
00539 DMIN = MAX( ULP*ACOEFA*ANORM, ULP*BCOEFA*BNORM, SAFMIN )
00540
00541
00542
00543
00544
00545
00546 DO 170 JR = 1, JE - 1
00547 WORK( JR ) = ACOEFF*S( JR, JE ) - BCOEFF*P( JR, JE )
00548 170 CONTINUE
00549 WORK( JE ) = CONE
00550
00551 DO 210 J = JE - 1, 1, -1
00552
00553
00554
00555
00556 D = ACOEFF*S( J, J ) - BCOEFF*P( J, J )
00557 IF( ABS1( D ).LE.DMIN )
00558 $ D = CMPLX( DMIN )
00559
00560 IF( ABS1( D ).LT.ONE ) THEN
00561 IF( ABS1( WORK( J ) ).GE.BIGNUM*ABS1( D ) ) THEN
00562 TEMP = ONE / ABS1( WORK( J ) )
00563 DO 180 JR = 1, JE
00564 WORK( JR ) = TEMP*WORK( JR )
00565 180 CONTINUE
00566 END IF
00567 END IF
00568
00569 WORK( J ) = CLADIV( -WORK( J ), D )
00570
00571 IF( J.GT.1 ) THEN
00572
00573
00574
00575 IF( ABS1( WORK( J ) ).GT.ONE ) THEN
00576 TEMP = ONE / ABS1( WORK( J ) )
00577 IF( ACOEFA*RWORK( J )+BCOEFA*RWORK( N+J ).GE.
00578 $ BIGNUM*TEMP ) THEN
00579 DO 190 JR = 1, JE
00580 WORK( JR ) = TEMP*WORK( JR )
00581 190 CONTINUE
00582 END IF
00583 END IF
00584
00585 CA = ACOEFF*WORK( J )
00586 CB = BCOEFF*WORK( J )
00587 DO 200 JR = 1, J - 1
00588 WORK( JR ) = WORK( JR ) + CA*S( JR, J ) -
00589 $ CB*P( JR, J )
00590 200 CONTINUE
00591 END IF
00592 210 CONTINUE
00593
00594
00595
00596 IF( ILBACK ) THEN
00597 CALL CGEMV( 'N', N, JE, CONE, VR, LDVR, WORK, 1,
00598 $ CZERO, WORK( N+1 ), 1 )
00599 ISRC = 2
00600 IEND = N
00601 ELSE
00602 ISRC = 1
00603 IEND = JE
00604 END IF
00605
00606
00607
00608 XMAX = ZERO
00609 DO 220 JR = 1, IEND
00610 XMAX = MAX( XMAX, ABS1( WORK( ( ISRC-1 )*N+JR ) ) )
00611 220 CONTINUE
00612
00613 IF( XMAX.GT.SAFMIN ) THEN
00614 TEMP = ONE / XMAX
00615 DO 230 JR = 1, IEND
00616 VR( JR, IEIG ) = TEMP*WORK( ( ISRC-1 )*N+JR )
00617 230 CONTINUE
00618 ELSE
00619 IEND = 0
00620 END IF
00621
00622 DO 240 JR = IEND + 1, N
00623 VR( JR, IEIG ) = CZERO
00624 240 CONTINUE
00625
00626 END IF
00627 250 CONTINUE
00628 END IF
00629
00630 RETURN
00631
00632
00633
00634 END