00001 SUBROUTINE CGEEV( JOBVL, JOBVR, N, A, LDA, W, VL, LDVL, VR, LDVR,
00002 $ WORK, LWORK, RWORK, INFO )
00003
00004
00005
00006
00007
00008
00009
00010 CHARACTER JOBVL, JOBVR
00011 INTEGER INFO, LDA, LDVL, LDVR, LWORK, N
00012
00013
00014 REAL RWORK( * )
00015 COMPLEX A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ),
00016 $ W( * ), WORK( * )
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 REAL ZERO, ONE
00107 PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
00108
00109
00110 LOGICAL LQUERY, SCALEA, WANTVL, WANTVR
00111 CHARACTER SIDE
00112 INTEGER HSWORK, I, IBAL, IERR, IHI, ILO, IRWORK, ITAU,
00113 $ IWRK, K, MAXWRK, MINWRK, NOUT
00114 REAL ANRM, BIGNUM, CSCALE, EPS, SCL, SMLNUM
00115 COMPLEX TMP
00116
00117
00118 LOGICAL SELECT( 1 )
00119 REAL DUM( 1 )
00120
00121
00122 EXTERNAL CGEBAK, CGEBAL, CGEHRD, CHSEQR, CLACPY, CLASCL,
00123 $ CSCAL, CSSCAL, CTREVC, CUNGHR, SLABAD, XERBLA
00124
00125
00126 LOGICAL LSAME
00127 INTEGER ILAENV, ISAMAX
00128 REAL CLANGE, SCNRM2, SLAMCH
00129 EXTERNAL LSAME, ILAENV, ISAMAX, CLANGE, SCNRM2, SLAMCH
00130
00131
00132 INTRINSIC AIMAG, CMPLX, CONJG, MAX, REAL, SQRT
00133
00134
00135
00136
00137
00138 INFO = 0
00139 LQUERY = ( LWORK.EQ.-1 )
00140 WANTVL = LSAME( JOBVL, 'V' )
00141 WANTVR = LSAME( JOBVR, 'V' )
00142 IF( ( .NOT.WANTVL ) .AND. ( .NOT.LSAME( JOBVL, 'N' ) ) ) THEN
00143 INFO = -1
00144 ELSE IF( ( .NOT.WANTVR ) .AND. ( .NOT.LSAME( JOBVR, 'N' ) ) ) THEN
00145 INFO = -2
00146 ELSE IF( N.LT.0 ) THEN
00147 INFO = -3
00148 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
00149 INFO = -5
00150 ELSE IF( LDVL.LT.1 .OR. ( WANTVL .AND. LDVL.LT.N ) ) THEN
00151 INFO = -8
00152 ELSE IF( LDVR.LT.1 .OR. ( WANTVR .AND. LDVR.LT.N ) ) THEN
00153 INFO = -10
00154 END IF
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 IF( INFO.EQ.0 ) THEN
00169 IF( N.EQ.0 ) THEN
00170 MINWRK = 1
00171 MAXWRK = 1
00172 ELSE
00173 MAXWRK = N + N*ILAENV( 1, 'CGEHRD', ' ', N, 1, N, 0 )
00174 MINWRK = 2*N
00175 IF( WANTVL ) THEN
00176 MAXWRK = MAX( MAXWRK, N + ( N - 1 )*ILAENV( 1, 'CUNGHR',
00177 $ ' ', N, 1, N, -1 ) )
00178 CALL CHSEQR( 'S', 'V', N, 1, N, A, LDA, W, VL, LDVL,
00179 $ WORK, -1, INFO )
00180 ELSE IF( WANTVR ) THEN
00181 MAXWRK = MAX( MAXWRK, N + ( N - 1 )*ILAENV( 1, 'CUNGHR',
00182 $ ' ', N, 1, N, -1 ) )
00183 CALL CHSEQR( 'S', 'V', N, 1, N, A, LDA, W, VR, LDVR,
00184 $ WORK, -1, INFO )
00185 ELSE
00186 CALL CHSEQR( 'E', 'N', N, 1, N, A, LDA, W, VR, LDVR,
00187 $ WORK, -1, INFO )
00188 END IF
00189 HSWORK = WORK( 1 )
00190 MAXWRK = MAX( MAXWRK, HSWORK, MINWRK )
00191 END IF
00192 WORK( 1 ) = MAXWRK
00193
00194 IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN
00195 INFO = -12
00196 END IF
00197 END IF
00198
00199 IF( INFO.NE.0 ) THEN
00200 CALL XERBLA( 'CGEEV ', -INFO )
00201 RETURN
00202 ELSE IF( LQUERY ) THEN
00203 RETURN
00204 END IF
00205
00206
00207
00208 IF( N.EQ.0 )
00209 $ RETURN
00210
00211
00212
00213 EPS = SLAMCH( 'P' )
00214 SMLNUM = SLAMCH( 'S' )
00215 BIGNUM = ONE / SMLNUM
00216 CALL SLABAD( SMLNUM, BIGNUM )
00217 SMLNUM = SQRT( SMLNUM ) / EPS
00218 BIGNUM = ONE / SMLNUM
00219
00220
00221
00222 ANRM = CLANGE( 'M', N, N, A, LDA, DUM )
00223 SCALEA = .FALSE.
00224 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
00225 SCALEA = .TRUE.
00226 CSCALE = SMLNUM
00227 ELSE IF( ANRM.GT.BIGNUM ) THEN
00228 SCALEA = .TRUE.
00229 CSCALE = BIGNUM
00230 END IF
00231 IF( SCALEA )
00232 $ CALL CLASCL( 'G', 0, 0, ANRM, CSCALE, N, N, A, LDA, IERR )
00233
00234
00235
00236
00237
00238 IBAL = 1
00239 CALL CGEBAL( 'B', N, A, LDA, ILO, IHI, RWORK( IBAL ), IERR )
00240
00241
00242
00243
00244
00245 ITAU = 1
00246 IWRK = ITAU + N
00247 CALL CGEHRD( N, ILO, IHI, A, LDA, WORK( ITAU ), WORK( IWRK ),
00248 $ LWORK-IWRK+1, IERR )
00249
00250 IF( WANTVL ) THEN
00251
00252
00253
00254
00255 SIDE = 'L'
00256 CALL CLACPY( 'L', N, N, A, LDA, VL, LDVL )
00257
00258
00259
00260
00261
00262 CALL CUNGHR( N, ILO, IHI, VL, LDVL, WORK( ITAU ), WORK( IWRK ),
00263 $ LWORK-IWRK+1, IERR )
00264
00265
00266
00267
00268
00269 IWRK = ITAU
00270 CALL CHSEQR( 'S', 'V', N, ILO, IHI, A, LDA, W, VL, LDVL,
00271 $ WORK( IWRK ), LWORK-IWRK+1, INFO )
00272
00273 IF( WANTVR ) THEN
00274
00275
00276
00277
00278 SIDE = 'B'
00279 CALL CLACPY( 'F', N, N, VL, LDVL, VR, LDVR )
00280 END IF
00281
00282 ELSE IF( WANTVR ) THEN
00283
00284
00285
00286
00287 SIDE = 'R'
00288 CALL CLACPY( 'L', N, N, A, LDA, VR, LDVR )
00289
00290
00291
00292
00293
00294 CALL CUNGHR( N, ILO, IHI, VR, LDVR, WORK( ITAU ), WORK( IWRK ),
00295 $ LWORK-IWRK+1, IERR )
00296
00297
00298
00299
00300
00301 IWRK = ITAU
00302 CALL CHSEQR( 'S', 'V', N, ILO, IHI, A, LDA, W, VR, LDVR,
00303 $ WORK( IWRK ), LWORK-IWRK+1, INFO )
00304
00305 ELSE
00306
00307
00308
00309
00310
00311 IWRK = ITAU
00312 CALL CHSEQR( 'E', 'N', N, ILO, IHI, A, LDA, W, VR, LDVR,
00313 $ WORK( IWRK ), LWORK-IWRK+1, INFO )
00314 END IF
00315
00316
00317
00318 IF( INFO.GT.0 )
00319 $ GO TO 50
00320
00321 IF( WANTVL .OR. WANTVR ) THEN
00322
00323
00324
00325
00326
00327 IRWORK = IBAL + N
00328 CALL CTREVC( SIDE, 'B', SELECT, N, A, LDA, VL, LDVL, VR, LDVR,
00329 $ N, NOUT, WORK( IWRK ), RWORK( IRWORK ), IERR )
00330 END IF
00331
00332 IF( WANTVL ) THEN
00333
00334
00335
00336
00337
00338 CALL CGEBAK( 'B', 'L', N, ILO, IHI, RWORK( IBAL ), N, VL, LDVL,
00339 $ IERR )
00340
00341
00342
00343 DO 20 I = 1, N
00344 SCL = ONE / SCNRM2( N, VL( 1, I ), 1 )
00345 CALL CSSCAL( N, SCL, VL( 1, I ), 1 )
00346 DO 10 K = 1, N
00347 RWORK( IRWORK+K-1 ) = REAL( VL( K, I ) )**2 +
00348 $ AIMAG( VL( K, I ) )**2
00349 10 CONTINUE
00350 K = ISAMAX( N, RWORK( IRWORK ), 1 )
00351 TMP = CONJG( VL( K, I ) ) / SQRT( RWORK( IRWORK+K-1 ) )
00352 CALL CSCAL( N, TMP, VL( 1, I ), 1 )
00353 VL( K, I ) = CMPLX( REAL( VL( K, I ) ), ZERO )
00354 20 CONTINUE
00355 END IF
00356
00357 IF( WANTVR ) THEN
00358
00359
00360
00361
00362
00363 CALL CGEBAK( 'B', 'R', N, ILO, IHI, RWORK( IBAL ), N, VR, LDVR,
00364 $ IERR )
00365
00366
00367
00368 DO 40 I = 1, N
00369 SCL = ONE / SCNRM2( N, VR( 1, I ), 1 )
00370 CALL CSSCAL( N, SCL, VR( 1, I ), 1 )
00371 DO 30 K = 1, N
00372 RWORK( IRWORK+K-1 ) = REAL( VR( K, I ) )**2 +
00373 $ AIMAG( VR( K, I ) )**2
00374 30 CONTINUE
00375 K = ISAMAX( N, RWORK( IRWORK ), 1 )
00376 TMP = CONJG( VR( K, I ) ) / SQRT( RWORK( IRWORK+K-1 ) )
00377 CALL CSCAL( N, TMP, VR( 1, I ), 1 )
00378 VR( K, I ) = CMPLX( REAL( VR( K, I ) ), ZERO )
00379 40 CONTINUE
00380 END IF
00381
00382
00383
00384 50 CONTINUE
00385 IF( SCALEA ) THEN
00386 CALL CLASCL( 'G', 0, 0, CSCALE, ANRM, N-INFO, 1, W( INFO+1 ),
00387 $ MAX( N-INFO, 1 ), IERR )
00388 IF( INFO.GT.0 ) THEN
00389 CALL CLASCL( 'G', 0, 0, CSCALE, ANRM, ILO-1, 1, W, N, IERR )
00390 END IF
00391 END IF
00392
00393 WORK( 1 ) = MAXWRK
00394 RETURN
00395
00396
00397
00398 END