214 SUBROUTINE cgsvj0( JOBV, M, N, A, LDA, D, SVA, MV, V, LDV, EPS,
215 $ SFMIN, TOL, NSWEEP, WORK, LWORK, INFO )
223 INTEGER INFO, LDA, LDV, LWORK, M, MV, N, NSWEEP
228 COMPLEX A( LDA, * ), D( N ), V( LDV, * ), WORK( LWORK )
236 parameter( zero = 0.0e0, half = 0.5e0, one = 1.0e0)
238 parameter( czero = (0.0e0, 0.0e0), cone = (1.0e0, 0.0e0) )
242 REAL AAPP, AAPP0, AAPQ1, AAQQ, APOAQ, AQOAP, BIG,
243 $ bigtheta, cs, mxaapq, mxsinj, rootbig, rooteps,
244 $ rootsfmin, roottol, small, sn, t, temp1, theta,
246 INTEGER BLSKIP, EMPTSW, i, ibr, IERR, igl, IJBLSK, ir1,
247 $ iswrot, jbc, jgl, kbl, lkahead, mvl, nbl,
248 $ notrot, p, pskipped, q, rowskip, swband
249 LOGICAL APPLV, ROTOK, RSVEC
253 INTRINSIC abs, max, conjg, real, min, sign, sqrt
260 EXTERNAL isamax, lsame, cdotc, scnrm2
274 applv = lsame( jobv,
'A' )
275 rsvec = lsame( jobv,
'V' )
276 IF( .NOT.( rsvec .OR. applv .OR. lsame( jobv,
'N' ) ) )
THEN
278 ELSE IF( m.LT.0 )
THEN
280 ELSE IF( ( n.LT.0 ) .OR. ( n.GT.m ) )
THEN
282 ELSE IF( lda.LT.m )
THEN
284 ELSE IF( ( rsvec.OR.applv ) .AND. ( mv.LT.0 ) )
THEN
286 ELSE IF( ( rsvec.AND.( ldv.LT.n ) ).OR.
287 $ ( applv.AND.( ldv.LT.mv ) ) )
THEN
289 ELSE IF( tol.LE.eps )
THEN
291 ELSE IF( nsweep.LT.0 )
THEN
293 ELSE IF( lwork.LT.m )
THEN
301 CALL xerbla(
'CGSVJ0', -info )
307 ELSE IF( applv )
THEN
310 rsvec = rsvec .OR. applv
312 rooteps = sqrt( eps )
313 rootsfmin = sqrt( sfmin )
316 rootbig = one / rootsfmin
317 bigtheta = one / rooteps
318 roottol = sqrt( tol )
322 emptsw = ( n*( n-1 ) ) / 2
343 IF( ( nbl*kbl ).NE.n )nbl = nbl + 1
348 rowskip = min( 5, kbl )
362 DO 1993 i = 1, nsweep
380 igl = ( ibr-1 )*kbl + 1
382 DO 1002 ir1 = 0, min( lkahead, nbl-ibr )
386 DO 2001 p = igl, min( igl+kbl-1, n-1 )
390 q = isamax( n-p+1, sva( p ), 1 ) + p - 1
392 CALL cswap( m, a( 1, p ), 1, a( 1, q ), 1 )
393 IF( rsvec )
CALL cswap( mvl, v( 1, p ), 1,
417 IF( ( sva( p ).LT.rootbig ) .AND.
418 $ ( sva( p ).GT.rootsfmin ) )
THEN
419 sva( p ) = scnrm2( m, a( 1, p ), 1 )
423 CALL classq( m, a( 1, p ), 1, temp1, aapp )
424 sva( p ) = temp1*sqrt( aapp )
431 IF( aapp.GT.zero )
THEN
435 DO 2002 q = p + 1, min( igl+kbl-1, n )
439 IF( aaqq.GT.zero )
THEN
442 IF( aaqq.GE.one )
THEN
443 rotok = ( small*aapp ).LE.aaqq
444 IF( aapp.LT.( big / aaqq ) )
THEN
445 aapq = ( cdotc( m, a( 1, p ), 1,
446 $ a( 1, q ), 1 ) / aaqq ) / aapp
448 CALL ccopy( m, a( 1, p ), 1,
450 CALL clascl(
'G', 0, 0, aapp, one,
451 $ m, 1, work, lda, ierr )
452 aapq = cdotc( m, work, 1,
453 $ a( 1, q ), 1 ) / aaqq
456 rotok = aapp.LE.( aaqq / small )
457 IF( aapp.GT.( small / aaqq ) )
THEN
458 aapq = ( cdotc( m, a( 1, p ), 1,
459 $ a( 1, q ), 1 ) / aapp ) / aaqq
461 CALL ccopy( m, a( 1, q ), 1,
463 CALL clascl(
'G', 0, 0, aaqq,
466 aapq = cdotc( m, a( 1, p ), 1,
473 mxaapq = max( mxaapq, -aapq1 )
477 IF( abs( aapq1 ).GT.tol )
THEN
478 ompq = aapq / abs(aapq)
493 theta = -half*abs( aqoap-apoaq )/aapq1
495 IF( abs( theta ).GT.bigtheta )
THEN
500 CALL crot( m, a(1,p), 1, a(1,q),
502 $ cs, conjg(ompq)*t )
504 CALL crot( mvl, v(1,p), 1,
505 $ v(1,q), 1, cs, conjg(ompq)*t )
508 sva( q ) = aaqq*sqrt( max( zero,
509 $ one+t*apoaq*aapq1 ) )
510 aapp = aapp*sqrt( max( zero,
511 $ one-t*aqoap*aapq1 ) )
512 mxsinj = max( mxsinj, abs( t ) )
518 thsign = -sign( one, aapq1 )
519 t = one / ( theta+thsign*
520 $ sqrt( one+theta*theta ) )
521 cs = sqrt( one / ( one+t*t ) )
524 mxsinj = max( mxsinj, abs( sn ) )
525 sva( q ) = aaqq*sqrt( max( zero,
526 $ one+t*apoaq*aapq1 ) )
527 aapp = aapp*sqrt( max( zero,
528 $ one-t*aqoap*aapq1 ) )
530 CALL crot( m, a(1,p), 1, a(1,q),
532 $ cs, conjg(ompq)*sn )
534 CALL crot( mvl, v(1,p), 1,
535 $ v(1,q), 1, cs, conjg(ompq)*sn )
542 CALL ccopy( m, a( 1, p ), 1,
544 CALL clascl(
'G', 0, 0, aapp, one,
548 CALL clascl(
'G', 0, 0, aaqq, one,
550 $ 1, a( 1, q ), lda, ierr )
551 CALL caxpy( m, -aapq, work, 1,
553 CALL clascl(
'G', 0, 0, one, aaqq,
555 $ 1, a( 1, q ), lda, ierr )
556 sva( q ) = aaqq*sqrt( max( zero,
557 $ one-aapq1*aapq1 ) )
558 mxsinj = max( mxsinj, sfmin )
565 IF( ( sva( q ) / aaqq )**2.LE.rooteps )
567 IF( ( aaqq.LT.rootbig ) .AND.
568 $ ( aaqq.GT.rootsfmin ) )
THEN
569 sva( q ) = scnrm2( m, a( 1, q ),
574 CALL classq( m, a( 1, q ), 1, t,
576 sva( q ) = t*sqrt( aaqq )
579 IF( ( aapp / aapp0 ).LE.rooteps )
THEN
580 IF( ( aapp.LT.rootbig ) .AND.
581 $ ( aapp.GT.rootsfmin ) )
THEN
582 aapp = scnrm2( m, a( 1, p ), 1 )
586 CALL classq( m, a( 1, p ), 1, t,
588 aapp = t*sqrt( aapp )
595 IF( ir1.EQ.0 )notrot = notrot + 1
597 pskipped = pskipped + 1
601 IF( ir1.EQ.0 )notrot = notrot + 1
602 pskipped = pskipped + 1
605 IF( ( i.LE.swband ) .AND.
606 $ ( pskipped.GT.rowskip ) )
THEN
607 IF( ir1.EQ.0 )aapp = -aapp
622 IF( ( ir1.EQ.0 ) .AND. ( aapp.EQ.zero ) )
623 $ notrot = notrot + min( igl+kbl-1, n ) - p
634 igl = ( ibr-1 )*kbl + 1
636 DO 2010 jbc = ibr + 1, nbl
638 jgl = ( jbc-1 )*kbl + 1
643 DO 2100 p = igl, min( igl+kbl-1, n )
646 IF( aapp.GT.zero )
THEN
650 DO 2200 q = jgl, min( jgl+kbl-1, n )
653 IF( aaqq.GT.zero )
THEN
660 IF( aaqq.GE.one )
THEN
661 IF( aapp.GE.aaqq )
THEN
662 rotok = ( small*aapp ).LE.aaqq
664 rotok = ( small*aaqq ).LE.aapp
666 IF( aapp.LT.( big / aaqq ) )
THEN
667 aapq = ( cdotc( m, a( 1, p ), 1,
668 $ a( 1, q ), 1 ) / aaqq ) / aapp
670 CALL ccopy( m, a( 1, p ), 1,
672 CALL clascl(
'G', 0, 0, aapp,
675 aapq = cdotc( m, work, 1,
676 $ a( 1, q ), 1 ) / aaqq
679 IF( aapp.GE.aaqq )
THEN
680 rotok = aapp.LE.( aaqq / small )
682 rotok = aaqq.LE.( aapp / small )
684 IF( aapp.GT.( small / aaqq ) )
THEN
685 aapq = ( cdotc( m, a( 1, p ), 1,
686 $ a( 1, q ), 1 ) / max(aaqq,aapp) )
689 CALL ccopy( m, a( 1, q ), 1,
691 CALL clascl(
'G', 0, 0, aaqq,
694 aapq = cdotc( m, a( 1, p ), 1,
701 mxaapq = max( mxaapq, -aapq1 )
705 IF( abs( aapq1 ).GT.tol )
THEN
706 ompq = aapq / abs(aapq)
716 theta = -half*abs( aqoap-apoaq )/ aapq1
717 IF( aaqq.GT.aapp0 )theta = -theta
719 IF( abs( theta ).GT.bigtheta )
THEN
722 CALL crot( m, a(1,p), 1, a(1,q),
724 $ cs, conjg(ompq)*t )
726 CALL crot( mvl, v(1,p), 1,
727 $ v(1,q), 1, cs, conjg(ompq)*t )
729 sva( q ) = aaqq*sqrt( max( zero,
730 $ one+t*apoaq*aapq1 ) )
731 aapp = aapp*sqrt( max( zero,
732 $ one-t*aqoap*aapq1 ) )
733 mxsinj = max( mxsinj, abs( t ) )
738 thsign = -sign( one, aapq1 )
739 IF( aaqq.GT.aapp0 )thsign = -thsign
740 t = one / ( theta+thsign*
741 $ sqrt( one+theta*theta ) )
742 cs = sqrt( one / ( one+t*t ) )
744 mxsinj = max( mxsinj, abs( sn ) )
745 sva( q ) = aaqq*sqrt( max( zero,
746 $ one+t*apoaq*aapq1 ) )
747 aapp = aapp*sqrt( max( zero,
748 $ one-t*aqoap*aapq1 ) )
750 CALL crot( m, a(1,p), 1, a(1,q),
752 $ cs, conjg(ompq)*sn )
754 CALL crot( mvl, v(1,p), 1,
755 $ v(1,q), 1, cs, conjg(ompq)*sn )
762 IF( aapp.GT.aaqq )
THEN
763 CALL ccopy( m, a( 1, p ), 1,
765 CALL clascl(
'G', 0, 0, aapp,
769 CALL clascl(
'G', 0, 0, aaqq,
771 $ m, 1, a( 1, q ), lda,
773 CALL caxpy( m, -aapq, work,
775 CALL clascl(
'G', 0, 0, one,
777 $ m, 1, a( 1, q ), lda,
779 sva( q ) = aaqq*sqrt( max( zero,
780 $ one-aapq1*aapq1 ) )
781 mxsinj = max( mxsinj, sfmin )
783 CALL ccopy( m, a( 1, q ), 1,
785 CALL clascl(
'G', 0, 0, aaqq,
789 CALL clascl(
'G', 0, 0, aapp,
791 $ m, 1, a( 1, p ), lda,
793 CALL caxpy( m, -conjg(aapq),
794 $ work, 1, a( 1, p ), 1 )
795 CALL clascl(
'G', 0, 0, one,
797 $ m, 1, a( 1, p ), lda,
799 sva( p ) = aapp*sqrt( max( zero,
800 $ one-aapq1*aapq1 ) )
801 mxsinj = max( mxsinj, sfmin )
808 IF( ( sva( q ) / aaqq )**2.LE.rooteps )
810 IF( ( aaqq.LT.rootbig ) .AND.
811 $ ( aaqq.GT.rootsfmin ) )
THEN
812 sva( q ) = scnrm2( m, a( 1, q ),
817 CALL classq( m, a( 1, q ), 1, t,
819 sva( q ) = t*sqrt( aaqq )
822 IF( ( aapp / aapp0 )**2.LE.rooteps )
THEN
823 IF( ( aapp.LT.rootbig ) .AND.
824 $ ( aapp.GT.rootsfmin ) )
THEN
825 aapp = scnrm2( m, a( 1, p ), 1 )
829 CALL classq( m, a( 1, p ), 1, t,
831 aapp = t*sqrt( aapp )
839 pskipped = pskipped + 1
844 pskipped = pskipped + 1
848 IF( ( i.LE.swband ) .AND. ( ijblsk.GE.blskip ) )
854 IF( ( i.LE.swband ) .AND.
855 $ ( pskipped.GT.rowskip ) )
THEN
869 IF( aapp.EQ.zero )notrot = notrot +
870 $ min( jgl+kbl-1, n ) - jgl + 1
871 IF( aapp.LT.zero )notrot = 0
881 DO 2012 p = igl, min( igl+kbl-1, n )
882 sva( p ) = abs( sva( p ) )
889 IF( ( sva( n ).LT.rootbig ) .AND. ( sva( n ).GT.rootsfmin ) )
891 sva( n ) = scnrm2( m, a( 1, n ), 1 )
895 CALL classq( m, a( 1, n ), 1, t, aapp )
896 sva( n ) = t*sqrt( aapp )
901 IF( ( i.LT.swband ) .AND. ( ( mxaapq.LE.roottol ) .OR.
902 $ ( iswrot.LE.n ) ) )swband = i
904 IF( ( i.GT.swband+1 ) .AND. ( mxaapq.LT.sqrt( real( n ) )*
905 $ tol ) .AND. ( real( n )*mxaapq*mxsinj.LT.tol ) )
THEN
909 IF( notrot.GE.emptsw )
GO TO 1994
928 q = isamax( n-p+1, sva( p ), 1 ) + p - 1
936 CALL cswap( m, a( 1, p ), 1, a( 1, q ), 1 )
937 IF( rsvec )
CALL cswap( mvl, v( 1, p ), 1, v( 1, q ), 1 )