00001 SUBROUTINE SGGEVX( BALANC, JOBVL, JOBVR, SENSE, N, A, LDA, B, LDB,
00002 $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR, ILO,
00003 $ IHI, LSCALE, RSCALE, ABNRM, BBNRM, RCONDE,
00004 $ RCONDV, WORK, LWORK, IWORK, BWORK, INFO )
00005
00006
00007
00008
00009
00010
00011
00012 CHARACTER BALANC, JOBVL, JOBVR, SENSE
00013 INTEGER IHI, ILO, INFO, LDA, LDB, LDVL, LDVR, LWORK, N
00014 REAL ABNRM, BBNRM
00015
00016
00017 LOGICAL BWORK( * )
00018 INTEGER IWORK( * )
00019 REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
00020 $ B( LDB, * ), BETA( * ), LSCALE( * ),
00021 $ RCONDE( * ), RCONDV( * ), RSCALE( * ),
00022 $ VL( LDVL, * ), VR( LDVR, * ), WORK( * )
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
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 REAL ZERO, ONE
00268 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
00269
00270
00271 LOGICAL ILASCL, ILBSCL, ILV, ILVL, ILVR, LQUERY, NOSCL,
00272 $ PAIR, WANTSB, WANTSE, WANTSN, WANTSV
00273 CHARACTER CHTEMP
00274 INTEGER I, ICOLS, IERR, IJOBVL, IJOBVR, IN, IROWS,
00275 $ ITAU, IWRK, IWRK1, J, JC, JR, M, MAXWRK,
00276 $ MINWRK, MM
00277 REAL ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
00278 $ SMLNUM, TEMP
00279
00280
00281 LOGICAL LDUMMA( 1 )
00282
00283
00284 EXTERNAL SGEQRF, SGGBAK, SGGBAL, SGGHRD, SHGEQZ, SLABAD,
00285 $ SLACPY, SLASCL, SLASET, SORGQR, SORMQR, STGEVC,
00286 $ STGSNA, XERBLA
00287
00288
00289 LOGICAL LSAME
00290 INTEGER ILAENV
00291 REAL SLAMCH, SLANGE
00292 EXTERNAL LSAME, ILAENV, SLAMCH, SLANGE
00293
00294
00295 INTRINSIC ABS, MAX, SQRT
00296
00297
00298
00299
00300
00301 IF( LSAME( JOBVL, 'N' ) ) THEN
00302 IJOBVL = 1
00303 ILVL = .FALSE.
00304 ELSE IF( LSAME( JOBVL, 'V' ) ) THEN
00305 IJOBVL = 2
00306 ILVL = .TRUE.
00307 ELSE
00308 IJOBVL = -1
00309 ILVL = .FALSE.
00310 END IF
00311
00312 IF( LSAME( JOBVR, 'N' ) ) THEN
00313 IJOBVR = 1
00314 ILVR = .FALSE.
00315 ELSE IF( LSAME( JOBVR, 'V' ) ) THEN
00316 IJOBVR = 2
00317 ILVR = .TRUE.
00318 ELSE
00319 IJOBVR = -1
00320 ILVR = .FALSE.
00321 END IF
00322 ILV = ILVL .OR. ILVR
00323
00324 NOSCL = LSAME( BALANC, 'N' ) .OR. LSAME( BALANC, 'P' )
00325 WANTSN = LSAME( SENSE, 'N' )
00326 WANTSE = LSAME( SENSE, 'E' )
00327 WANTSV = LSAME( SENSE, 'V' )
00328 WANTSB = LSAME( SENSE, 'B' )
00329
00330
00331
00332 INFO = 0
00333 LQUERY = ( LWORK.EQ.-1 )
00334 IF( .NOT.( NOSCL .OR. LSAME( BALANC, 'S' ) .OR.
00335 $ LSAME( BALANC, 'B' ) ) ) THEN
00336 INFO = -1
00337 ELSE IF( IJOBVL.LE.0 ) THEN
00338 INFO = -2
00339 ELSE IF( IJOBVR.LE.0 ) THEN
00340 INFO = -3
00341 ELSE IF( .NOT.( WANTSN .OR. WANTSE .OR. WANTSB .OR. WANTSV ) )
00342 $ THEN
00343 INFO = -4
00344 ELSE IF( N.LT.0 ) THEN
00345 INFO = -5
00346 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
00347 INFO = -7
00348 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
00349 INFO = -9
00350 ELSE IF( LDVL.LT.1 .OR. ( ILVL .AND. LDVL.LT.N ) ) THEN
00351 INFO = -14
00352 ELSE IF( LDVR.LT.1 .OR. ( ILVR .AND. LDVR.LT.N ) ) THEN
00353 INFO = -16
00354 END IF
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 IF( INFO.EQ.0 ) THEN
00365 IF( N.EQ.0 ) THEN
00366 MINWRK = 1
00367 MAXWRK = 1
00368 ELSE
00369 IF( NOSCL .AND. .NOT.ILV ) THEN
00370 MINWRK = 2*N
00371 ELSE
00372 MINWRK = 6*N
00373 END IF
00374 IF( WANTSE ) THEN
00375 MINWRK = 10*N
00376 ELSE IF( WANTSV .OR. WANTSB ) THEN
00377 MINWRK = 2*N*( N + 4 ) + 16
00378 END IF
00379 MAXWRK = MINWRK
00380 MAXWRK = MAX( MAXWRK,
00381 $ N + N*ILAENV( 1, 'SGEQRF', ' ', N, 1, N, 0 ) )
00382 MAXWRK = MAX( MAXWRK,
00383 $ N + N*ILAENV( 1, 'SORMQR', ' ', N, 1, N, 0 ) )
00384 IF( ILVL ) THEN
00385 MAXWRK = MAX( MAXWRK, N +
00386 $ N*ILAENV( 1, 'SORGQR', ' ', N, 1, N, 0 ) )
00387 END IF
00388 END IF
00389 WORK( 1 ) = MAXWRK
00390
00391 IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN
00392 INFO = -26
00393 END IF
00394 END IF
00395
00396 IF( INFO.NE.0 ) THEN
00397 CALL XERBLA( 'SGGEVX', -INFO )
00398 RETURN
00399 ELSE IF( LQUERY ) THEN
00400 RETURN
00401 END IF
00402
00403
00404
00405 IF( N.EQ.0 )
00406 $ RETURN
00407
00408
00409
00410
00411 EPS = SLAMCH( 'P' )
00412 SMLNUM = SLAMCH( 'S' )
00413 BIGNUM = ONE / SMLNUM
00414 CALL SLABAD( SMLNUM, BIGNUM )
00415 SMLNUM = SQRT( SMLNUM ) / EPS
00416 BIGNUM = ONE / SMLNUM
00417
00418
00419
00420 ANRM = SLANGE( 'M', N, N, A, LDA, WORK )
00421 ILASCL = .FALSE.
00422 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
00423 ANRMTO = SMLNUM
00424 ILASCL = .TRUE.
00425 ELSE IF( ANRM.GT.BIGNUM ) THEN
00426 ANRMTO = BIGNUM
00427 ILASCL = .TRUE.
00428 END IF
00429 IF( ILASCL )
00430 $ CALL SLASCL( 'G', 0, 0, ANRM, ANRMTO, N, N, A, LDA, IERR )
00431
00432
00433
00434 BNRM = SLANGE( 'M', N, N, B, LDB, WORK )
00435 ILBSCL = .FALSE.
00436 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
00437 BNRMTO = SMLNUM
00438 ILBSCL = .TRUE.
00439 ELSE IF( BNRM.GT.BIGNUM ) THEN
00440 BNRMTO = BIGNUM
00441 ILBSCL = .TRUE.
00442 END IF
00443 IF( ILBSCL )
00444 $ CALL SLASCL( 'G', 0, 0, BNRM, BNRMTO, N, N, B, LDB, IERR )
00445
00446
00447
00448
00449 CALL SGGBAL( BALANC, N, A, LDA, B, LDB, ILO, IHI, LSCALE, RSCALE,
00450 $ WORK, IERR )
00451
00452
00453
00454 ABNRM = SLANGE( '1', N, N, A, LDA, WORK( 1 ) )
00455 IF( ILASCL ) THEN
00456 WORK( 1 ) = ABNRM
00457 CALL SLASCL( 'G', 0, 0, ANRMTO, ANRM, 1, 1, WORK( 1 ), 1,
00458 $ IERR )
00459 ABNRM = WORK( 1 )
00460 END IF
00461
00462 BBNRM = SLANGE( '1', N, N, B, LDB, WORK( 1 ) )
00463 IF( ILBSCL ) THEN
00464 WORK( 1 ) = BBNRM
00465 CALL SLASCL( 'G', 0, 0, BNRMTO, BNRM, 1, 1, WORK( 1 ), 1,
00466 $ IERR )
00467 BBNRM = WORK( 1 )
00468 END IF
00469
00470
00471
00472
00473 IROWS = IHI + 1 - ILO
00474 IF( ILV .OR. .NOT.WANTSN ) THEN
00475 ICOLS = N + 1 - ILO
00476 ELSE
00477 ICOLS = IROWS
00478 END IF
00479 ITAU = 1
00480 IWRK = ITAU + IROWS
00481 CALL SGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
00482 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
00483
00484
00485
00486
00487 CALL SORMQR( 'L', 'T', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
00488 $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWRK ),
00489 $ LWORK+1-IWRK, IERR )
00490
00491
00492
00493
00494 IF( ILVL ) THEN
00495 CALL SLASET( 'Full', N, N, ZERO, ONE, VL, LDVL )
00496 IF( IROWS.GT.1 ) THEN
00497 CALL SLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
00498 $ VL( ILO+1, ILO ), LDVL )
00499 END IF
00500 CALL SORGQR( IROWS, IROWS, IROWS, VL( ILO, ILO ), LDVL,
00501 $ WORK( ITAU ), WORK( IWRK ), LWORK+1-IWRK, IERR )
00502 END IF
00503
00504 IF( ILVR )
00505 $ CALL SLASET( 'Full', N, N, ZERO, ONE, VR, LDVR )
00506
00507
00508
00509
00510 IF( ILV .OR. .NOT.WANTSN ) THEN
00511
00512
00513
00514 CALL SGGHRD( JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, VL,
00515 $ LDVL, VR, LDVR, IERR )
00516 ELSE
00517 CALL SGGHRD( 'N', 'N', IROWS, 1, IROWS, A( ILO, ILO ), LDA,
00518 $ B( ILO, ILO ), LDB, VL, LDVL, VR, LDVR, IERR )
00519 END IF
00520
00521
00522
00523
00524
00525 IF( ILV .OR. .NOT.WANTSN ) THEN
00526 CHTEMP = 'S'
00527 ELSE
00528 CHTEMP = 'E'
00529 END IF
00530
00531 CALL SHGEQZ( CHTEMP, JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB,
00532 $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR, WORK,
00533 $ LWORK, IERR )
00534 IF( IERR.NE.0 ) THEN
00535 IF( IERR.GT.0 .AND. IERR.LE.N ) THEN
00536 INFO = IERR
00537 ELSE IF( IERR.GT.N .AND. IERR.LE.2*N ) THEN
00538 INFO = IERR - N
00539 ELSE
00540 INFO = N + 1
00541 END IF
00542 GO TO 130
00543 END IF
00544
00545
00546
00547
00548
00549
00550 IF( ILV .OR. .NOT.WANTSN ) THEN
00551 IF( ILV ) THEN
00552 IF( ILVL ) THEN
00553 IF( ILVR ) THEN
00554 CHTEMP = 'B'
00555 ELSE
00556 CHTEMP = 'L'
00557 END IF
00558 ELSE
00559 CHTEMP = 'R'
00560 END IF
00561
00562 CALL STGEVC( CHTEMP, 'B', LDUMMA, N, A, LDA, B, LDB, VL,
00563 $ LDVL, VR, LDVR, N, IN, WORK, IERR )
00564 IF( IERR.NE.0 ) THEN
00565 INFO = N + 2
00566 GO TO 130
00567 END IF
00568 END IF
00569
00570 IF( .NOT.WANTSN ) THEN
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580 PAIR = .FALSE.
00581 DO 20 I = 1, N
00582
00583 IF( PAIR ) THEN
00584 PAIR = .FALSE.
00585 GO TO 20
00586 END IF
00587 MM = 1
00588 IF( I.LT.N ) THEN
00589 IF( A( I+1, I ).NE.ZERO ) THEN
00590 PAIR = .TRUE.
00591 MM = 2
00592 END IF
00593 END IF
00594
00595 DO 10 J = 1, N
00596 BWORK( J ) = .FALSE.
00597 10 CONTINUE
00598 IF( MM.EQ.1 ) THEN
00599 BWORK( I ) = .TRUE.
00600 ELSE IF( MM.EQ.2 ) THEN
00601 BWORK( I ) = .TRUE.
00602 BWORK( I+1 ) = .TRUE.
00603 END IF
00604
00605 IWRK = MM*N + 1
00606 IWRK1 = IWRK + MM*N
00607
00608
00609
00610
00611 IF( WANTSE .OR. WANTSB ) THEN
00612 CALL STGEVC( 'B', 'S', BWORK, N, A, LDA, B, LDB,
00613 $ WORK( 1 ), N, WORK( IWRK ), N, MM, M,
00614 $ WORK( IWRK1 ), IERR )
00615 IF( IERR.NE.0 ) THEN
00616 INFO = N + 2
00617 GO TO 130
00618 END IF
00619 END IF
00620
00621 CALL STGSNA( SENSE, 'S', BWORK, N, A, LDA, B, LDB,
00622 $ WORK( 1 ), N, WORK( IWRK ), N, RCONDE( I ),
00623 $ RCONDV( I ), MM, M, WORK( IWRK1 ),
00624 $ LWORK-IWRK1+1, IWORK, IERR )
00625
00626 20 CONTINUE
00627 END IF
00628 END IF
00629
00630
00631
00632
00633 IF( ILVL ) THEN
00634 CALL SGGBAK( BALANC, 'L', N, ILO, IHI, LSCALE, RSCALE, N, VL,
00635 $ LDVL, IERR )
00636
00637 DO 70 JC = 1, N
00638 IF( ALPHAI( JC ).LT.ZERO )
00639 $ GO TO 70
00640 TEMP = ZERO
00641 IF( ALPHAI( JC ).EQ.ZERO ) THEN
00642 DO 30 JR = 1, N
00643 TEMP = MAX( TEMP, ABS( VL( JR, JC ) ) )
00644 30 CONTINUE
00645 ELSE
00646 DO 40 JR = 1, N
00647 TEMP = MAX( TEMP, ABS( VL( JR, JC ) )+
00648 $ ABS( VL( JR, JC+1 ) ) )
00649 40 CONTINUE
00650 END IF
00651 IF( TEMP.LT.SMLNUM )
00652 $ GO TO 70
00653 TEMP = ONE / TEMP
00654 IF( ALPHAI( JC ).EQ.ZERO ) THEN
00655 DO 50 JR = 1, N
00656 VL( JR, JC ) = VL( JR, JC )*TEMP
00657 50 CONTINUE
00658 ELSE
00659 DO 60 JR = 1, N
00660 VL( JR, JC ) = VL( JR, JC )*TEMP
00661 VL( JR, JC+1 ) = VL( JR, JC+1 )*TEMP
00662 60 CONTINUE
00663 END IF
00664 70 CONTINUE
00665 END IF
00666 IF( ILVR ) THEN
00667 CALL SGGBAK( BALANC, 'R', N, ILO, IHI, LSCALE, RSCALE, N, VR,
00668 $ LDVR, IERR )
00669 DO 120 JC = 1, N
00670 IF( ALPHAI( JC ).LT.ZERO )
00671 $ GO TO 120
00672 TEMP = ZERO
00673 IF( ALPHAI( JC ).EQ.ZERO ) THEN
00674 DO 80 JR = 1, N
00675 TEMP = MAX( TEMP, ABS( VR( JR, JC ) ) )
00676 80 CONTINUE
00677 ELSE
00678 DO 90 JR = 1, N
00679 TEMP = MAX( TEMP, ABS( VR( JR, JC ) )+
00680 $ ABS( VR( JR, JC+1 ) ) )
00681 90 CONTINUE
00682 END IF
00683 IF( TEMP.LT.SMLNUM )
00684 $ GO TO 120
00685 TEMP = ONE / TEMP
00686 IF( ALPHAI( JC ).EQ.ZERO ) THEN
00687 DO 100 JR = 1, N
00688 VR( JR, JC ) = VR( JR, JC )*TEMP
00689 100 CONTINUE
00690 ELSE
00691 DO 110 JR = 1, N
00692 VR( JR, JC ) = VR( JR, JC )*TEMP
00693 VR( JR, JC+1 ) = VR( JR, JC+1 )*TEMP
00694 110 CONTINUE
00695 END IF
00696 120 CONTINUE
00697 END IF
00698
00699
00700
00701 IF( ILASCL ) THEN
00702 CALL SLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAR, N, IERR )
00703 CALL SLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAI, N, IERR )
00704 END IF
00705
00706 IF( ILBSCL ) THEN
00707 CALL SLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR )
00708 END IF
00709
00710 130 CONTINUE
00711 WORK( 1 ) = MAXWRK
00712
00713 RETURN
00714
00715
00716
00717 END