265 SUBROUTINE cgges3( JOBVSL, JOBVSR, SORT, SELCTG, N, A, LDA, B,
266 $ LDB, SDIM, ALPHA, BETA, VSL, LDVSL, VSR, LDVSR,
267 $ WORK, LWORK, RWORK, BWORK, INFO )
274 CHARACTER JOBVSL, JOBVSR, SORT
275 INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N, SDIM
280 COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
281 $ beta( * ), vsl( ldvsl, * ), vsr( ldvsr, * ),
293 PARAMETER ( ZERO = 0.0e0, one = 1.0e0 )
295 parameter( czero = ( 0.0e0, 0.0e0 ),
296 $ cone = ( 1.0e0, 0.0e0 ) )
299 LOGICAL CURSL, ILASCL, ILBSCL, ILVSL, ILVSR, LASTSL,
301 INTEGER I, ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT,
302 $ ILO, IRIGHT, IROWS, IRWRK, ITAU, IWRK, LWKOPT,
304 REAL ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS, PVSL,
318 REAL CLANGE, SLAMCH, SROUNDUP_LWORK
319 EXTERNAL lsame, clange, slamch,
329 IF( lsame( jobvsl,
'N' ) )
THEN
332 ELSE IF( lsame( jobvsl,
'V' ) )
THEN
340 IF( lsame( jobvsr,
'N' ) )
THEN
343 ELSE IF( lsame( jobvsr,
'V' ) )
THEN
351 wantst = lsame( sort,
'S' )
356 lquery = ( lwork.EQ.-1 )
357 lwkmin = max( 1, 2*n )
359 IF( ijobvl.LE.0 )
THEN
361 ELSE IF( ijobvr.LE.0 )
THEN
363 ELSE IF( ( .NOT.wantst ) .AND.
364 $ ( .NOT.lsame( sort,
'N' ) ) )
THEN
366 ELSE IF( n.LT.0 )
THEN
368 ELSE IF( lda.LT.max( 1, n ) )
THEN
370 ELSE IF( ldb.LT.max( 1, n ) )
THEN
372 ELSE IF( ldvsl.LT.1 .OR. ( ilvsl .AND. ldvsl.LT.n ) )
THEN
374 ELSE IF( ldvsr.LT.1 .OR. ( ilvsr .AND. ldvsr.LT.n ) )
THEN
376 ELSE IF( lwork.LT.lwkmin .AND. .NOT.lquery )
THEN
383 CALL cgeqrf( n, n, b, ldb, work, work, -1, ierr )
384 lwkopt = max( lwkmin, n + int( work( 1 ) ) )
385 CALL cunmqr(
'L',
'C', n, n, n, b, ldb, work, a, lda, work,
387 lwkopt = max( lwkopt, n + int( work( 1 ) ) )
389 CALL cungqr( n, n, n, vsl, ldvsl, work, work, -1,
391 lwkopt = max( lwkopt, n + int( work( 1 ) ) )
393 CALL cgghd3( jobvsl, jobvsr, n, 1, n, a, lda, b, ldb, vsl,
394 $ ldvsl, vsr, ldvsr, work, -1, ierr )
395 lwkopt = max( lwkopt, n + int( work( 1 ) ) )
396 CALL claqz0(
'S', jobvsl, jobvsr, n, 1, n, a, lda, b, ldb,
397 $ alpha, beta, vsl, ldvsl, vsr, ldvsr, work, -1,
399 lwkopt = max( lwkopt, int( work( 1 ) ) )
401 CALL ctgsen( 0, ilvsl, ilvsr, bwork, n, a, lda, b, ldb,
402 $ alpha, beta, vsl, ldvsl, vsr, ldvsr, sdim,
403 $ pvsl, pvsr, dif, work, -1, idum, 1, ierr )
404 lwkopt = max( lwkopt, int( work( 1 ) ) )
409 work( 1 ) = sroundup_lwork( lwkopt )
415 CALL xerbla(
'CGGES3 ', -info )
417 ELSE IF( lquery )
THEN
431 smlnum = slamch(
'S' )
432 bignum = one / smlnum
433 smlnum = sqrt( smlnum ) / eps
434 bignum = one / smlnum
438 anrm = clange(
'M', n, n, a, lda, rwork )
440 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
443 ELSE IF( anrm.GT.bignum )
THEN
449 $
CALL clascl(
'G', 0, 0, anrm, anrmto, n, n, a, lda, ierr )
453 bnrm = clange(
'M', n, n, b, ldb, rwork )
455 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
458 ELSE IF( bnrm.GT.bignum )
THEN
464 $
CALL clascl(
'G', 0, 0, bnrm, bnrmto, n, n, b, ldb, ierr )
471 CALL cggbal(
'P', n, a, lda, b, ldb, ilo, ihi, rwork( ileft ),
472 $ rwork( iright ), rwork( irwrk ), ierr )
476 irows = ihi + 1 - ilo
480 CALL cgeqrf( irows, icols, b( ilo, ilo ), ldb, work( itau ),
481 $ work( iwrk ), lwork+1-iwrk, ierr )
485 CALL cunmqr(
'L',
'C', irows, icols, irows, b( ilo, ilo ), ldb,
486 $ work( itau ), a( ilo, ilo ), lda, work( iwrk ),
487 $ lwork+1-iwrk, ierr )
492 CALL claset(
'Full', n, n, czero, cone, vsl, ldvsl )
493 IF( irows.GT.1 )
THEN
494 CALL clacpy(
'L', irows-1, irows-1, b( ilo+1, ilo ), ldb,
495 $ vsl( ilo+1, ilo ), ldvsl )
497 CALL cungqr( irows, irows, irows, vsl( ilo, ilo ), ldvsl,
498 $ work( itau ), work( iwrk ), lwork+1-iwrk, ierr )
504 $
CALL claset(
'Full', n, n, czero, cone, vsr, ldvsr )
508 CALL cgghd3( jobvsl, jobvsr, n, ilo, ihi, a, lda, b, ldb, vsl,
509 $ ldvsl, vsr, ldvsr, work( iwrk ), lwork+1-iwrk, ierr )
516 CALL claqz0(
'S', jobvsl, jobvsr, n, ilo, ihi, a, lda, b, ldb,
517 $ alpha, beta, vsl, ldvsl, vsr, ldvsr, work( iwrk ),
518 $ lwork+1-iwrk, rwork( irwrk ), 0, ierr )
520 IF( ierr.GT.0 .AND. ierr.LE.n )
THEN
522 ELSE IF( ierr.GT.n .AND. ierr.LE.2*n )
THEN
537 $
CALL clascl(
'G', 0, 0, anrm, anrmto, n, 1, alpha, n,
540 $
CALL clascl(
'G', 0, 0, bnrm, bnrmto, n, 1, beta, n,
546 bwork( i ) = selctg( alpha( i ), beta( i ) )
549 CALL ctgsen( 0, ilvsl, ilvsr, bwork, n, a, lda, b, ldb,
551 $ beta, vsl, ldvsl, vsr, ldvsr, sdim, pvsl, pvsr,
552 $ dif, work( iwrk ), lwork-iwrk+1, idum, 1, ierr )
561 $
CALL cggbak(
'P',
'L', n, ilo, ihi, rwork( ileft ),
562 $ rwork( iright ), n, vsl, ldvsl, ierr )
564 $
CALL cggbak(
'P',
'R', n, ilo, ihi, rwork( ileft ),
565 $ rwork( iright ), n, vsr, ldvsr, ierr )
570 CALL clascl(
'U', 0, 0, anrmto, anrm, n, n, a, lda, ierr )
571 CALL clascl(
'G', 0, 0, anrmto, anrm, n, 1, alpha, n, ierr )
575 CALL clascl(
'U', 0, 0, bnrmto, bnrm, n, n, b, ldb, ierr )
576 CALL clascl(
'G', 0, 0, bnrmto, bnrm, n, 1, beta, n, ierr )
586 cursl = selctg( alpha( i ), beta( i ) )
589 IF( cursl .AND. .NOT.lastsl )
598 work( 1 ) = sroundup_lwork( lwkopt )