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