265 SUBROUTINE zgges3( 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
279 DOUBLE PRECISION RWORK( * )
280 COMPLEX*16 A( LDA, * ), ALPHA( * ), B( LDB, * ),
281 $ beta( * ), vsl( ldvsl, * ), vsr( ldvsr, * ),
292 DOUBLE PRECISION ZERO, ONE
293 PARAMETER ( ZERO = 0.0d0, one = 1.0d0 )
294 COMPLEX*16 CZERO, CONE
295 parameter( czero = ( 0.0d0, 0.0d0 ),
296 $ cone = ( 1.0d0, 0.0d0 ) )
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 DOUBLE PRECISION ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS, PVSL,
309 DOUBLE PRECISION DIF( 2 )
318 DOUBLE PRECISION DLAMCH, ZLANGE
319 EXTERNAL lsame, dlamch, zlange
328 IF( lsame( jobvsl,
'N' ) )
THEN
331 ELSE IF( lsame( jobvsl,
'V' ) )
THEN
339 IF( lsame( jobvsr,
'N' ) )
THEN
342 ELSE IF( lsame( jobvsr,
'V' ) )
THEN
350 wantst = lsame( sort,
'S' )
355 lquery = ( lwork.EQ.-1 )
356 lwkmin = max( 1, 2*n )
358 IF( ijobvl.LE.0 )
THEN
360 ELSE IF( ijobvr.LE.0 )
THEN
362 ELSE IF( ( .NOT.wantst ) .AND.
363 $ ( .NOT.lsame( sort,
'N' ) ) )
THEN
365 ELSE IF( n.LT.0 )
THEN
367 ELSE IF( lda.LT.max( 1, n ) )
THEN
369 ELSE IF( ldb.LT.max( 1, n ) )
THEN
371 ELSE IF( ldvsl.LT.1 .OR. ( ilvsl .AND. ldvsl.LT.n ) )
THEN
373 ELSE IF( ldvsr.LT.1 .OR. ( ilvsr .AND. ldvsr.LT.n ) )
THEN
375 ELSE IF( lwork.LT.lwkmin .AND. .NOT.lquery )
THEN
382 CALL zgeqrf( n, n, b, ldb, work, work, -1, ierr )
383 lwkopt = max( lwkmin, n + int( work( 1 ) ) )
384 CALL zunmqr(
'L',
'C', n, n, n, b, ldb, work, a, lda, work,
386 lwkopt = max( lwkopt, n + int( work( 1 ) ) )
388 CALL zungqr( n, n, n, vsl, ldvsl, work, work, -1, ierr )
389 lwkopt = max( lwkopt, n + int( work( 1 ) ) )
391 CALL zgghd3( jobvsl, jobvsr, n, 1, n, a, lda, b, ldb, vsl,
392 $ ldvsl, vsr, ldvsr, work, -1, ierr )
393 lwkopt = max( lwkopt, n + int( work( 1 ) ) )
394 CALL zlaqz0(
'S', jobvsl, jobvsr, n, 1, n, a, lda, b, ldb,
395 $ alpha, beta, vsl, ldvsl, vsr, ldvsr, work, -1,
397 lwkopt = max( lwkopt, int( work( 1 ) ) )
399 CALL ztgsen( 0, ilvsl, ilvsr, bwork, n, a, lda, b, ldb,
400 $ alpha, beta, vsl, ldvsl, vsr, ldvsr, sdim,
401 $ pvsl, pvsr, dif, work, -1, idum, 1, ierr )
402 lwkopt = max( lwkopt, int( work( 1 ) ) )
407 work( 1 ) = dcmplx( lwkopt )
412 CALL xerbla(
'ZGGES3 ', -info )
414 ELSE IF( lquery )
THEN
428 smlnum = dlamch(
'S' )
429 bignum = one / smlnum
430 smlnum = sqrt( smlnum ) / eps
431 bignum = one / smlnum
435 anrm = zlange(
'M', n, n, a, lda, rwork )
437 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
440 ELSE IF( anrm.GT.bignum )
THEN
446 $
CALL zlascl(
'G', 0, 0, anrm, anrmto, n, n, a, lda, ierr )
450 bnrm = zlange(
'M', n, n, b, ldb, rwork )
452 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
455 ELSE IF( bnrm.GT.bignum )
THEN
461 $
CALL zlascl(
'G', 0, 0, bnrm, bnrmto, n, n, b, ldb, ierr )
468 CALL zggbal(
'P', n, a, lda, b, ldb, ilo, ihi, rwork( ileft ),
469 $ rwork( iright ), rwork( irwrk ), ierr )
473 irows = ihi + 1 - ilo
477 CALL zgeqrf( irows, icols, b( ilo, ilo ), ldb, work( itau ),
478 $ work( iwrk ), lwork+1-iwrk, ierr )
482 CALL zunmqr(
'L',
'C', irows, icols, irows, b( ilo, ilo ), ldb,
483 $ work( itau ), a( ilo, ilo ), lda, work( iwrk ),
484 $ lwork+1-iwrk, ierr )
489 CALL zlaset(
'Full', n, n, czero, cone, vsl, ldvsl )
490 IF( irows.GT.1 )
THEN
491 CALL zlacpy(
'L', irows-1, irows-1, b( ilo+1, ilo ), ldb,
492 $ vsl( ilo+1, ilo ), ldvsl )
494 CALL zungqr( irows, irows, irows, vsl( ilo, ilo ), ldvsl,
495 $ work( itau ), work( iwrk ), lwork+1-iwrk, ierr )
501 $
CALL zlaset(
'Full', n, n, czero, cone, vsr, ldvsr )
505 CALL zgghd3( jobvsl, jobvsr, n, ilo, ihi, a, lda, b, ldb, vsl,
506 $ ldvsl, vsr, ldvsr, work( iwrk ), lwork+1-iwrk, ierr )
513 CALL zlaqz0(
'S', jobvsl, jobvsr, n, ilo, ihi, a, lda, b, ldb,
514 $ alpha, beta, vsl, ldvsl, vsr, ldvsr, work( iwrk ),
515 $ lwork+1-iwrk, rwork( irwrk ), 0, ierr )
517 IF( ierr.GT.0 .AND. ierr.LE.n )
THEN
519 ELSE IF( ierr.GT.n .AND. ierr.LE.2*n )
THEN
534 $
CALL zlascl(
'G', 0, 0, anrm, anrmto, n, 1, alpha, n,
537 $
CALL zlascl(
'G', 0, 0, bnrm, bnrmto, n, 1, beta, n,
543 bwork( i ) = selctg( alpha( i ), beta( i ) )
546 CALL ztgsen( 0, ilvsl, ilvsr, bwork, n, a, lda, b, ldb,
548 $ beta, vsl, ldvsl, vsr, ldvsr, sdim, pvsl, pvsr,
549 $ dif, work( iwrk ), lwork-iwrk+1, idum, 1, ierr )
558 $
CALL zggbak(
'P',
'L', n, ilo, ihi, rwork( ileft ),
559 $ rwork( iright ), n, vsl, ldvsl, ierr )
561 $
CALL zggbak(
'P',
'R', n, ilo, ihi, rwork( ileft ),
562 $ rwork( iright ), n, vsr, ldvsr, ierr )
567 CALL zlascl(
'U', 0, 0, anrmto, anrm, n, n, a, lda, ierr )
568 CALL zlascl(
'G', 0, 0, anrmto, anrm, n, 1, alpha, n, ierr )
572 CALL zlascl(
'U', 0, 0, bnrmto, bnrm, n, n, b, ldb, ierr )
573 CALL zlascl(
'G', 0, 0, bnrmto, bnrm, n, 1, beta, n, ierr )
583 cursl = selctg( alpha( i ), beta( i ) )
586 IF( cursl .AND. .NOT.lastsl )
595 work( 1 ) = dcmplx( lwkopt )