222 SUBROUTINE sgegs( JOBVSL, JOBVSR, N, A, LDA, B, LDB, ALPHAR,
223 $ ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR, WORK,
231 CHARACTER JOBVSL, JOBVSR
232 INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N
235 REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
236 $ B( LDB, * ), BETA( * ), VSL( LDVSL, * ),
237 $ vsr( ldvsr, * ), work( * )
244 PARAMETER ( ZERO = 0.0e0, one = 1.0e0 )
247 LOGICAL ILASCL, ILBSCL, ILVSL, ILVSR, LQUERY
248 INTEGER ICOLS, IHI, IINFO, IJOBVL, IJOBVR, ILEFT,
249 $ ilo, iright, irows, itau, iwork, lopt, lwkmin,
250 $ lwkopt, nb, nb1, nb2, nb3
251 REAL ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
262 EXTERNAL ilaenv, lsame, slamch, slange
271 IF( lsame( jobvsl,
'N' ) )
THEN
274 ELSE IF( lsame( jobvsl,
'V' ) )
THEN
282 IF( lsame( jobvsr,
'N' ) )
THEN
285 ELSE IF( lsame( jobvsr,
'V' ) )
THEN
295 lwkmin = max( 4*n, 1 )
298 lquery = ( lwork.EQ.-1 )
300 IF( ijobvl.LE.0 )
THEN
302 ELSE IF( ijobvr.LE.0 )
THEN
304 ELSE IF( n.LT.0 )
THEN
306 ELSE IF( lda.LT.max( 1, n ) )
THEN
308 ELSE IF( ldb.LT.max( 1, n ) )
THEN
310 ELSE IF( ldvsl.LT.1 .OR. ( ilvsl .AND. ldvsl.LT.n ) )
THEN
312 ELSE IF( ldvsr.LT.1 .OR. ( ilvsr .AND. ldvsr.LT.n ) )
THEN
314 ELSE IF( lwork.LT.lwkmin .AND. .NOT.lquery )
THEN
319 nb1 = ilaenv( 1,
'SGEQRF',
' ', n, n, -1, -1 )
320 nb2 = ilaenv( 1,
'SORMQR',
' ', n, n, n, -1 )
321 nb3 = ilaenv( 1,
'SORGQR',
' ', n, n, n, -1 )
322 nb = max( nb1, nb2, nb3 )
328 CALL xerbla(
'SGEGS ', -info )
330 ELSE IF( lquery )
THEN
341 eps = slamch(
'E' )*slamch(
'B' )
342 safmin = slamch(
'S' )
343 smlnum = n*safmin / eps
344 bignum = one / smlnum
348 anrm = slange(
'M', n, n, a, lda, work )
350 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
353 ELSE IF( anrm.GT.bignum )
THEN
359 CALL slascl(
'G', -1, -1, anrm, anrmto, n, n, a, lda,
361 IF( iinfo.NE.0 )
THEN
369 bnrm = slange(
'M', n, n, b, ldb, work )
371 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
374 ELSE IF( bnrm.GT.bignum )
THEN
380 CALL slascl(
'G', -1, -1, bnrm, bnrmto, n, n, b, ldb,
382 IF( iinfo.NE.0 )
THEN
395 CALL sggbal(
'P', n, a, lda, b, ldb, ilo, ihi, work( ileft ),
396 $ work( iright ), work( iwork ), iinfo )
397 IF( iinfo.NE.0 )
THEN
406 irows = ihi + 1 - ilo
410 CALL sgeqrf( irows, icols, b( ilo, ilo ), ldb, work( itau ),
411 $ work( iwork ), lwork+1-iwork, iinfo )
413 $ lwkopt = max( lwkopt, int( work( iwork ) )+iwork-1 )
414 IF( iinfo.NE.0 )
THEN
419 CALL sormqr(
'L',
'T', irows, icols, irows, b( ilo, ilo ), ldb,
420 $ work( itau ), a( ilo, ilo ), lda, work( iwork ),
421 $ lwork+1-iwork, iinfo )
423 $ lwkopt = max( lwkopt, int( work( iwork ) )+iwork-1 )
424 IF( iinfo.NE.0 )
THEN
430 CALL slaset(
'Full', n, n, zero, one, vsl, ldvsl )
431 CALL slacpy(
'L', irows-1, irows-1, b( ilo+1, ilo ), ldb,
432 $ vsl( ilo+1, ilo ), ldvsl )
433 CALL sorgqr( irows, irows, irows, vsl( ilo, ilo ), ldvsl,
434 $ work( itau ), work( iwork ), lwork+1-iwork,
437 $ lwkopt = max( lwkopt, int( work( iwork ) )+iwork-1 )
438 IF( iinfo.NE.0 )
THEN
445 $
CALL slaset(
'Full', n, n, zero, one, vsr, ldvsr )
449 CALL sgghrd( jobvsl, jobvsr, n, ilo, ihi, a, lda, b, ldb, vsl,
450 $ ldvsl, vsr, ldvsr, iinfo )
451 IF( iinfo.NE.0 )
THEN
461 CALL shgeqz(
'S', jobvsl, jobvsr, n, ilo, ihi, a, lda, b, ldb,
462 $ alphar, alphai, beta, vsl, ldvsl, vsr, ldvsr,
463 $ work( iwork ), lwork+1-iwork, iinfo )
465 $ lwkopt = max( lwkopt, int( work( iwork ) )+iwork-1 )
466 IF( iinfo.NE.0 )
THEN
467 IF( iinfo.GT.0 .AND. iinfo.LE.n )
THEN
469 ELSE IF( iinfo.GT.n .AND. iinfo.LE.2*n )
THEN
480 CALL sggbak(
'P',
'L', n, ilo, ihi, work( ileft ),
481 $ work( iright ), n, vsl, ldvsl, iinfo )
482 IF( iinfo.NE.0 )
THEN
488 CALL sggbak(
'P',
'R', n, ilo, ihi, work( ileft ),
489 $ work( iright ), n, vsr, ldvsr, iinfo )
490 IF( iinfo.NE.0 )
THEN
499 CALL slascl(
'H', -1, -1, anrmto, anrm, n, n, a, lda,
501 IF( iinfo.NE.0 )
THEN
505 CALL slascl(
'G', -1, -1, anrmto, anrm, n, 1, alphar, n,
507 IF( iinfo.NE.0 )
THEN
511 CALL slascl(
'G', -1, -1, anrmto, anrm, n, 1, alphai, n,
513 IF( iinfo.NE.0 )
THEN
520 CALL slascl(
'U', -1, -1, bnrmto, bnrm, n, n, b, ldb,
522 IF( iinfo.NE.0 )
THEN
526 CALL slascl(
'G', -1, -1, bnrmto, bnrm, n, 1, beta, n,
528 IF( iinfo.NE.0 )
THEN