00001 SUBROUTINE CGEGS( JOBVSL, JOBVSR, N, A, LDA, B, LDB, ALPHA, BETA,
00002 $ VSL, LDVSL, VSR, LDVSR, WORK, LWORK, RWORK,
00003 $ INFO )
00004
00005
00006
00007
00008
00009
00010
00011 CHARACTER JOBVSL, JOBVSR
00012 INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N
00013
00014
00015 REAL RWORK( * )
00016 COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
00017 $ BETA( * ), VSL( LDVSL, * ), VSR( LDVSR, * ),
00018 $ WORK( * )
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 REAL ZERO, ONE
00145 PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
00146 COMPLEX CZERO, CONE
00147 PARAMETER ( CZERO = ( 0.0E0, 0.0E0 ),
00148 $ CONE = ( 1.0E0, 0.0E0 ) )
00149
00150
00151 LOGICAL ILASCL, ILBSCL, ILVSL, ILVSR, LQUERY
00152 INTEGER ICOLS, IHI, IINFO, IJOBVL, IJOBVR, ILEFT,
00153 $ ILO, IRIGHT, IROWS, IRWORK, ITAU, IWORK,
00154 $ LOPT, LWKMIN, LWKOPT, NB, NB1, NB2, NB3
00155 REAL ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
00156 $ SAFMIN, SMLNUM
00157
00158
00159 EXTERNAL CGEQRF, CGGBAK, CGGBAL, CGGHRD, CHGEQZ, CLACPY,
00160 $ CLASCL, CLASET, CUNGQR, CUNMQR, XERBLA
00161
00162
00163 LOGICAL LSAME
00164 INTEGER ILAENV
00165 REAL CLANGE, SLAMCH
00166 EXTERNAL ILAENV, LSAME, CLANGE, SLAMCH
00167
00168
00169 INTRINSIC INT, MAX
00170
00171
00172
00173
00174
00175 IF( LSAME( JOBVSL, 'N' ) ) THEN
00176 IJOBVL = 1
00177 ILVSL = .FALSE.
00178 ELSE IF( LSAME( JOBVSL, 'V' ) ) THEN
00179 IJOBVL = 2
00180 ILVSL = .TRUE.
00181 ELSE
00182 IJOBVL = -1
00183 ILVSL = .FALSE.
00184 END IF
00185
00186 IF( LSAME( JOBVSR, 'N' ) ) THEN
00187 IJOBVR = 1
00188 ILVSR = .FALSE.
00189 ELSE IF( LSAME( JOBVSR, 'V' ) ) THEN
00190 IJOBVR = 2
00191 ILVSR = .TRUE.
00192 ELSE
00193 IJOBVR = -1
00194 ILVSR = .FALSE.
00195 END IF
00196
00197
00198
00199 LWKMIN = MAX( 2*N, 1 )
00200 LWKOPT = LWKMIN
00201 WORK( 1 ) = LWKOPT
00202 LQUERY = ( LWORK.EQ.-1 )
00203 INFO = 0
00204 IF( IJOBVL.LE.0 ) THEN
00205 INFO = -1
00206 ELSE IF( IJOBVR.LE.0 ) THEN
00207 INFO = -2
00208 ELSE IF( N.LT.0 ) THEN
00209 INFO = -3
00210 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
00211 INFO = -5
00212 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
00213 INFO = -7
00214 ELSE IF( LDVSL.LT.1 .OR. ( ILVSL .AND. LDVSL.LT.N ) ) THEN
00215 INFO = -11
00216 ELSE IF( LDVSR.LT.1 .OR. ( ILVSR .AND. LDVSR.LT.N ) ) THEN
00217 INFO = -13
00218 ELSE IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY ) THEN
00219 INFO = -15
00220 END IF
00221
00222 IF( INFO.EQ.0 ) THEN
00223 NB1 = ILAENV( 1, 'CGEQRF', ' ', N, N, -1, -1 )
00224 NB2 = ILAENV( 1, 'CUNMQR', ' ', N, N, N, -1 )
00225 NB3 = ILAENV( 1, 'CUNGQR', ' ', N, N, N, -1 )
00226 NB = MAX( NB1, NB2, NB3 )
00227 LOPT = N*(NB+1)
00228 WORK( 1 ) = LOPT
00229 END IF
00230
00231 IF( INFO.NE.0 ) THEN
00232 CALL XERBLA( 'CGEGS ', -INFO )
00233 RETURN
00234 ELSE IF( LQUERY ) THEN
00235 RETURN
00236 END IF
00237
00238
00239
00240 IF( N.EQ.0 )
00241 $ RETURN
00242
00243
00244
00245 EPS = SLAMCH( 'E' )*SLAMCH( 'B' )
00246 SAFMIN = SLAMCH( 'S' )
00247 SMLNUM = N*SAFMIN / EPS
00248 BIGNUM = ONE / SMLNUM
00249
00250
00251
00252 ANRM = CLANGE( 'M', N, N, A, LDA, RWORK )
00253 ILASCL = .FALSE.
00254 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
00255 ANRMTO = SMLNUM
00256 ILASCL = .TRUE.
00257 ELSE IF( ANRM.GT.BIGNUM ) THEN
00258 ANRMTO = BIGNUM
00259 ILASCL = .TRUE.
00260 END IF
00261
00262 IF( ILASCL ) THEN
00263 CALL CLASCL( 'G', -1, -1, ANRM, ANRMTO, N, N, A, LDA, IINFO )
00264 IF( IINFO.NE.0 ) THEN
00265 INFO = N + 9
00266 RETURN
00267 END IF
00268 END IF
00269
00270
00271
00272 BNRM = CLANGE( 'M', N, N, B, LDB, RWORK )
00273 ILBSCL = .FALSE.
00274 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
00275 BNRMTO = SMLNUM
00276 ILBSCL = .TRUE.
00277 ELSE IF( BNRM.GT.BIGNUM ) THEN
00278 BNRMTO = BIGNUM
00279 ILBSCL = .TRUE.
00280 END IF
00281
00282 IF( ILBSCL ) THEN
00283 CALL CLASCL( 'G', -1, -1, BNRM, BNRMTO, N, N, B, LDB, IINFO )
00284 IF( IINFO.NE.0 ) THEN
00285 INFO = N + 9
00286 RETURN
00287 END IF
00288 END IF
00289
00290
00291
00292 ILEFT = 1
00293 IRIGHT = N + 1
00294 IRWORK = IRIGHT + N
00295 IWORK = 1
00296 CALL CGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, RWORK( ILEFT ),
00297 $ RWORK( IRIGHT ), RWORK( IRWORK ), IINFO )
00298 IF( IINFO.NE.0 ) THEN
00299 INFO = N + 1
00300 GO TO 10
00301 END IF
00302
00303
00304
00305 IROWS = IHI + 1 - ILO
00306 ICOLS = N + 1 - ILO
00307 ITAU = IWORK
00308 IWORK = ITAU + IROWS
00309 CALL CGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
00310 $ WORK( IWORK ), LWORK+1-IWORK, IINFO )
00311 IF( IINFO.GE.0 )
00312 $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 )
00313 IF( IINFO.NE.0 ) THEN
00314 INFO = N + 2
00315 GO TO 10
00316 END IF
00317
00318 CALL CUNMQR( 'L', 'C', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
00319 $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWORK ),
00320 $ LWORK+1-IWORK, IINFO )
00321 IF( IINFO.GE.0 )
00322 $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 )
00323 IF( IINFO.NE.0 ) THEN
00324 INFO = N + 3
00325 GO TO 10
00326 END IF
00327
00328 IF( ILVSL ) THEN
00329 CALL CLASET( 'Full', N, N, CZERO, CONE, VSL, LDVSL )
00330 CALL CLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
00331 $ VSL( ILO+1, ILO ), LDVSL )
00332 CALL CUNGQR( IROWS, IROWS, IROWS, VSL( ILO, ILO ), LDVSL,
00333 $ WORK( ITAU ), WORK( IWORK ), LWORK+1-IWORK,
00334 $ IINFO )
00335 IF( IINFO.GE.0 )
00336 $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 )
00337 IF( IINFO.NE.0 ) THEN
00338 INFO = N + 4
00339 GO TO 10
00340 END IF
00341 END IF
00342
00343 IF( ILVSR )
00344 $ CALL CLASET( 'Full', N, N, CZERO, CONE, VSR, LDVSR )
00345
00346
00347
00348 CALL CGGHRD( JOBVSL, JOBVSR, N, ILO, IHI, A, LDA, B, LDB, VSL,
00349 $ LDVSL, VSR, LDVSR, IINFO )
00350 IF( IINFO.NE.0 ) THEN
00351 INFO = N + 5
00352 GO TO 10
00353 END IF
00354
00355
00356
00357 IWORK = ITAU
00358 CALL CHGEQZ( 'S', JOBVSL, JOBVSR, N, ILO, IHI, A, LDA, B, LDB,
00359 $ ALPHA, BETA, VSL, LDVSL, VSR, LDVSR, WORK( IWORK ),
00360 $ LWORK+1-IWORK, RWORK( IRWORK ), IINFO )
00361 IF( IINFO.GE.0 )
00362 $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 )
00363 IF( IINFO.NE.0 ) THEN
00364 IF( IINFO.GT.0 .AND. IINFO.LE.N ) THEN
00365 INFO = IINFO
00366 ELSE IF( IINFO.GT.N .AND. IINFO.LE.2*N ) THEN
00367 INFO = IINFO - N
00368 ELSE
00369 INFO = N + 6
00370 END IF
00371 GO TO 10
00372 END IF
00373
00374
00375
00376 IF( ILVSL ) THEN
00377 CALL CGGBAK( 'P', 'L', N, ILO, IHI, RWORK( ILEFT ),
00378 $ RWORK( IRIGHT ), N, VSL, LDVSL, IINFO )
00379 IF( IINFO.NE.0 ) THEN
00380 INFO = N + 7
00381 GO TO 10
00382 END IF
00383 END IF
00384 IF( ILVSR ) THEN
00385 CALL CGGBAK( 'P', 'R', N, ILO, IHI, RWORK( ILEFT ),
00386 $ RWORK( IRIGHT ), N, VSR, LDVSR, IINFO )
00387 IF( IINFO.NE.0 ) THEN
00388 INFO = N + 8
00389 GO TO 10
00390 END IF
00391 END IF
00392
00393
00394
00395 IF( ILASCL ) THEN
00396 CALL CLASCL( 'U', -1, -1, ANRMTO, ANRM, N, N, A, LDA, IINFO )
00397 IF( IINFO.NE.0 ) THEN
00398 INFO = N + 9
00399 RETURN
00400 END IF
00401 CALL CLASCL( 'G', -1, -1, ANRMTO, ANRM, N, 1, ALPHA, N, IINFO )
00402 IF( IINFO.NE.0 ) THEN
00403 INFO = N + 9
00404 RETURN
00405 END IF
00406 END IF
00407
00408 IF( ILBSCL ) THEN
00409 CALL CLASCL( 'U', -1, -1, BNRMTO, BNRM, N, N, B, LDB, IINFO )
00410 IF( IINFO.NE.0 ) THEN
00411 INFO = N + 9
00412 RETURN
00413 END IF
00414 CALL CLASCL( 'G', -1, -1, BNRMTO, BNRM, N, 1, BETA, N, IINFO )
00415 IF( IINFO.NE.0 ) THEN
00416 INFO = N + 9
00417 RETURN
00418 END IF
00419 END IF
00420
00421 10 CONTINUE
00422 WORK( 1 ) = LWKOPT
00423
00424 RETURN
00425
00426
00427
00428 END