00001 SUBROUTINE CGEGV( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHA, BETA,
00002 $ VL, LDVL, VR, LDVR, WORK, LWORK, RWORK, INFO )
00003
00004
00005
00006
00007
00008
00009
00010 CHARACTER JOBVL, JOBVR
00011 INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N
00012
00013
00014 REAL RWORK( * )
00015 COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
00016 $ BETA( * ), VL( LDVL, * ), VR( LDVR, * ),
00017 $ 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
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 REAL ZERO, ONE
00202 PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
00203 COMPLEX CZERO, CONE
00204 PARAMETER ( CZERO = ( 0.0E0, 0.0E0 ),
00205 $ CONE = ( 1.0E0, 0.0E0 ) )
00206
00207
00208 LOGICAL ILIMIT, ILV, ILVL, ILVR, LQUERY
00209 CHARACTER CHTEMP
00210 INTEGER ICOLS, IHI, IINFO, IJOBVL, IJOBVR, ILEFT, ILO,
00211 $ IN, IRIGHT, IROWS, IRWORK, ITAU, IWORK, JC, JR,
00212 $ LOPT, LWKMIN, LWKOPT, NB, NB1, NB2, NB3
00213 REAL ABSAI, ABSAR, ABSB, ANRM, ANRM1, ANRM2, BNRM,
00214 $ BNRM1, BNRM2, EPS, SAFMAX, SAFMIN, SALFAI,
00215 $ SALFAR, SBETA, SCALE, TEMP
00216 COMPLEX X
00217
00218
00219 LOGICAL LDUMMA( 1 )
00220
00221
00222 EXTERNAL CGEQRF, CGGBAK, CGGBAL, CGGHRD, CHGEQZ, CLACPY,
00223 $ CLASCL, CLASET, CTGEVC, CUNGQR, CUNMQR, XERBLA
00224
00225
00226 LOGICAL LSAME
00227 INTEGER ILAENV
00228 REAL CLANGE, SLAMCH
00229 EXTERNAL ILAENV, LSAME, CLANGE, SLAMCH
00230
00231
00232 INTRINSIC ABS, AIMAG, CMPLX, INT, MAX, REAL
00233
00234
00235 REAL ABS1
00236
00237
00238 ABS1( X ) = ABS( REAL( X ) ) + ABS( AIMAG( X ) )
00239
00240
00241
00242
00243
00244 IF( LSAME( JOBVL, 'N' ) ) THEN
00245 IJOBVL = 1
00246 ILVL = .FALSE.
00247 ELSE IF( LSAME( JOBVL, 'V' ) ) THEN
00248 IJOBVL = 2
00249 ILVL = .TRUE.
00250 ELSE
00251 IJOBVL = -1
00252 ILVL = .FALSE.
00253 END IF
00254
00255 IF( LSAME( JOBVR, 'N' ) ) THEN
00256 IJOBVR = 1
00257 ILVR = .FALSE.
00258 ELSE IF( LSAME( JOBVR, 'V' ) ) THEN
00259 IJOBVR = 2
00260 ILVR = .TRUE.
00261 ELSE
00262 IJOBVR = -1
00263 ILVR = .FALSE.
00264 END IF
00265 ILV = ILVL .OR. ILVR
00266
00267
00268
00269 LWKMIN = MAX( 2*N, 1 )
00270 LWKOPT = LWKMIN
00271 WORK( 1 ) = LWKOPT
00272 LQUERY = ( LWORK.EQ.-1 )
00273 INFO = 0
00274 IF( IJOBVL.LE.0 ) THEN
00275 INFO = -1
00276 ELSE IF( IJOBVR.LE.0 ) THEN
00277 INFO = -2
00278 ELSE IF( N.LT.0 ) THEN
00279 INFO = -3
00280 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
00281 INFO = -5
00282 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
00283 INFO = -7
00284 ELSE IF( LDVL.LT.1 .OR. ( ILVL .AND. LDVL.LT.N ) ) THEN
00285 INFO = -11
00286 ELSE IF( LDVR.LT.1 .OR. ( ILVR .AND. LDVR.LT.N ) ) THEN
00287 INFO = -13
00288 ELSE IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY ) THEN
00289 INFO = -15
00290 END IF
00291
00292 IF( INFO.EQ.0 ) THEN
00293 NB1 = ILAENV( 1, 'CGEQRF', ' ', N, N, -1, -1 )
00294 NB2 = ILAENV( 1, 'CUNMQR', ' ', N, N, N, -1 )
00295 NB3 = ILAENV( 1, 'CUNGQR', ' ', N, N, N, -1 )
00296 NB = MAX( NB1, NB2, NB3 )
00297 LOPT = MAX( 2*N, N*(NB+1) )
00298 WORK( 1 ) = LOPT
00299 END IF
00300
00301 IF( INFO.NE.0 ) THEN
00302 CALL XERBLA( 'CGEGV ', -INFO )
00303 RETURN
00304 ELSE IF( LQUERY ) THEN
00305 RETURN
00306 END IF
00307
00308
00309
00310 IF( N.EQ.0 )
00311 $ RETURN
00312
00313
00314
00315 EPS = SLAMCH( 'E' )*SLAMCH( 'B' )
00316 SAFMIN = SLAMCH( 'S' )
00317 SAFMIN = SAFMIN + SAFMIN
00318 SAFMAX = ONE / SAFMIN
00319
00320
00321
00322 ANRM = CLANGE( 'M', N, N, A, LDA, RWORK )
00323 ANRM1 = ANRM
00324 ANRM2 = ONE
00325 IF( ANRM.LT.ONE ) THEN
00326 IF( SAFMAX*ANRM.LT.ONE ) THEN
00327 ANRM1 = SAFMIN
00328 ANRM2 = SAFMAX*ANRM
00329 END IF
00330 END IF
00331
00332 IF( ANRM.GT.ZERO ) THEN
00333 CALL CLASCL( 'G', -1, -1, ANRM, ONE, N, N, A, LDA, IINFO )
00334 IF( IINFO.NE.0 ) THEN
00335 INFO = N + 10
00336 RETURN
00337 END IF
00338 END IF
00339
00340
00341
00342 BNRM = CLANGE( 'M', N, N, B, LDB, RWORK )
00343 BNRM1 = BNRM
00344 BNRM2 = ONE
00345 IF( BNRM.LT.ONE ) THEN
00346 IF( SAFMAX*BNRM.LT.ONE ) THEN
00347 BNRM1 = SAFMIN
00348 BNRM2 = SAFMAX*BNRM
00349 END IF
00350 END IF
00351
00352 IF( BNRM.GT.ZERO ) THEN
00353 CALL CLASCL( 'G', -1, -1, BNRM, ONE, N, N, B, LDB, IINFO )
00354 IF( IINFO.NE.0 ) THEN
00355 INFO = N + 10
00356 RETURN
00357 END IF
00358 END IF
00359
00360
00361
00362
00363 ILEFT = 1
00364 IRIGHT = N + 1
00365 IRWORK = IRIGHT + N
00366 CALL CGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, RWORK( ILEFT ),
00367 $ RWORK( IRIGHT ), RWORK( IRWORK ), IINFO )
00368 IF( IINFO.NE.0 ) THEN
00369 INFO = N + 1
00370 GO TO 80
00371 END IF
00372
00373
00374
00375 IROWS = IHI + 1 - ILO
00376 IF( ILV ) THEN
00377 ICOLS = N + 1 - ILO
00378 ELSE
00379 ICOLS = IROWS
00380 END IF
00381 ITAU = 1
00382 IWORK = ITAU + IROWS
00383 CALL CGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
00384 $ WORK( IWORK ), LWORK+1-IWORK, IINFO )
00385 IF( IINFO.GE.0 )
00386 $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 )
00387 IF( IINFO.NE.0 ) THEN
00388 INFO = N + 2
00389 GO TO 80
00390 END IF
00391
00392 CALL CUNMQR( 'L', 'C', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
00393 $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWORK ),
00394 $ LWORK+1-IWORK, IINFO )
00395 IF( IINFO.GE.0 )
00396 $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 )
00397 IF( IINFO.NE.0 ) THEN
00398 INFO = N + 3
00399 GO TO 80
00400 END IF
00401
00402 IF( ILVL ) THEN
00403 CALL CLASET( 'Full', N, N, CZERO, CONE, VL, LDVL )
00404 CALL CLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
00405 $ VL( ILO+1, ILO ), LDVL )
00406 CALL CUNGQR( IROWS, IROWS, IROWS, VL( ILO, ILO ), LDVL,
00407 $ WORK( ITAU ), WORK( IWORK ), LWORK+1-IWORK,
00408 $ IINFO )
00409 IF( IINFO.GE.0 )
00410 $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 )
00411 IF( IINFO.NE.0 ) THEN
00412 INFO = N + 4
00413 GO TO 80
00414 END IF
00415 END IF
00416
00417 IF( ILVR )
00418 $ CALL CLASET( 'Full', N, N, CZERO, CONE, VR, LDVR )
00419
00420
00421
00422 IF( ILV ) THEN
00423
00424
00425
00426 CALL CGGHRD( JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, VL,
00427 $ LDVL, VR, LDVR, IINFO )
00428 ELSE
00429 CALL CGGHRD( 'N', 'N', IROWS, 1, IROWS, A( ILO, ILO ), LDA,
00430 $ B( ILO, ILO ), LDB, VL, LDVL, VR, LDVR, IINFO )
00431 END IF
00432 IF( IINFO.NE.0 ) THEN
00433 INFO = N + 5
00434 GO TO 80
00435 END IF
00436
00437
00438
00439 IWORK = ITAU
00440 IF( ILV ) THEN
00441 CHTEMP = 'S'
00442 ELSE
00443 CHTEMP = 'E'
00444 END IF
00445 CALL CHGEQZ( CHTEMP, JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB,
00446 $ ALPHA, BETA, VL, LDVL, VR, LDVR, WORK( IWORK ),
00447 $ LWORK+1-IWORK, RWORK( IRWORK ), IINFO )
00448 IF( IINFO.GE.0 )
00449 $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 )
00450 IF( IINFO.NE.0 ) THEN
00451 IF( IINFO.GT.0 .AND. IINFO.LE.N ) THEN
00452 INFO = IINFO
00453 ELSE IF( IINFO.GT.N .AND. IINFO.LE.2*N ) THEN
00454 INFO = IINFO - N
00455 ELSE
00456 INFO = N + 6
00457 END IF
00458 GO TO 80
00459 END IF
00460
00461 IF( ILV ) THEN
00462
00463
00464
00465 IF( ILVL ) THEN
00466 IF( ILVR ) THEN
00467 CHTEMP = 'B'
00468 ELSE
00469 CHTEMP = 'L'
00470 END IF
00471 ELSE
00472 CHTEMP = 'R'
00473 END IF
00474
00475 CALL CTGEVC( CHTEMP, 'B', LDUMMA, N, A, LDA, B, LDB, VL, LDVL,
00476 $ VR, LDVR, N, IN, WORK( IWORK ), RWORK( IRWORK ),
00477 $ IINFO )
00478 IF( IINFO.NE.0 ) THEN
00479 INFO = N + 7
00480 GO TO 80
00481 END IF
00482
00483
00484
00485 IF( ILVL ) THEN
00486 CALL CGGBAK( 'P', 'L', N, ILO, IHI, RWORK( ILEFT ),
00487 $ RWORK( IRIGHT ), N, VL, LDVL, IINFO )
00488 IF( IINFO.NE.0 ) THEN
00489 INFO = N + 8
00490 GO TO 80
00491 END IF
00492 DO 30 JC = 1, N
00493 TEMP = ZERO
00494 DO 10 JR = 1, N
00495 TEMP = MAX( TEMP, ABS1( VL( JR, JC ) ) )
00496 10 CONTINUE
00497 IF( TEMP.LT.SAFMIN )
00498 $ GO TO 30
00499 TEMP = ONE / TEMP
00500 DO 20 JR = 1, N
00501 VL( JR, JC ) = VL( JR, JC )*TEMP
00502 20 CONTINUE
00503 30 CONTINUE
00504 END IF
00505 IF( ILVR ) THEN
00506 CALL CGGBAK( 'P', 'R', N, ILO, IHI, RWORK( ILEFT ),
00507 $ RWORK( IRIGHT ), N, VR, LDVR, IINFO )
00508 IF( IINFO.NE.0 ) THEN
00509 INFO = N + 9
00510 GO TO 80
00511 END IF
00512 DO 60 JC = 1, N
00513 TEMP = ZERO
00514 DO 40 JR = 1, N
00515 TEMP = MAX( TEMP, ABS1( VR( JR, JC ) ) )
00516 40 CONTINUE
00517 IF( TEMP.LT.SAFMIN )
00518 $ GO TO 60
00519 TEMP = ONE / TEMP
00520 DO 50 JR = 1, N
00521 VR( JR, JC ) = VR( JR, JC )*TEMP
00522 50 CONTINUE
00523 60 CONTINUE
00524 END IF
00525
00526
00527
00528 END IF
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538 DO 70 JC = 1, N
00539 ABSAR = ABS( REAL( ALPHA( JC ) ) )
00540 ABSAI = ABS( AIMAG( ALPHA( JC ) ) )
00541 ABSB = ABS( REAL( BETA( JC ) ) )
00542 SALFAR = ANRM*REAL( ALPHA( JC ) )
00543 SALFAI = ANRM*AIMAG( ALPHA( JC ) )
00544 SBETA = BNRM*REAL( BETA( JC ) )
00545 ILIMIT = .FALSE.
00546 SCALE = ONE
00547
00548
00549
00550 IF( ABS( SALFAI ).LT.SAFMIN .AND. ABSAI.GE.
00551 $ MAX( SAFMIN, EPS*ABSAR, EPS*ABSB ) ) THEN
00552 ILIMIT = .TRUE.
00553 SCALE = ( SAFMIN / ANRM1 ) / MAX( SAFMIN, ANRM2*ABSAI )
00554 END IF
00555
00556
00557
00558 IF( ABS( SALFAR ).LT.SAFMIN .AND. ABSAR.GE.
00559 $ MAX( SAFMIN, EPS*ABSAI, EPS*ABSB ) ) THEN
00560 ILIMIT = .TRUE.
00561 SCALE = MAX( SCALE, ( SAFMIN / ANRM1 ) /
00562 $ MAX( SAFMIN, ANRM2*ABSAR ) )
00563 END IF
00564
00565
00566
00567 IF( ABS( SBETA ).LT.SAFMIN .AND. ABSB.GE.
00568 $ MAX( SAFMIN, EPS*ABSAR, EPS*ABSAI ) ) THEN
00569 ILIMIT = .TRUE.
00570 SCALE = MAX( SCALE, ( SAFMIN / BNRM1 ) /
00571 $ MAX( SAFMIN, BNRM2*ABSB ) )
00572 END IF
00573
00574
00575
00576 IF( ILIMIT ) THEN
00577 TEMP = ( SCALE*SAFMIN )*MAX( ABS( SALFAR ), ABS( SALFAI ),
00578 $ ABS( SBETA ) )
00579 IF( TEMP.GT.ONE )
00580 $ SCALE = SCALE / TEMP
00581 IF( SCALE.LT.ONE )
00582 $ ILIMIT = .FALSE.
00583 END IF
00584
00585
00586
00587 IF( ILIMIT ) THEN
00588 SALFAR = ( SCALE*REAL( ALPHA( JC ) ) )*ANRM
00589 SALFAI = ( SCALE*AIMAG( ALPHA( JC ) ) )*ANRM
00590 SBETA = ( SCALE*BETA( JC ) )*BNRM
00591 END IF
00592 ALPHA( JC ) = CMPLX( SALFAR, SALFAI )
00593 BETA( JC ) = SBETA
00594 70 CONTINUE
00595
00596 80 CONTINUE
00597 WORK( 1 ) = LWKOPT
00598
00599 RETURN
00600
00601
00602
00603 END