565 SUBROUTINE cgejsv( JOBA, JOBU, JOBV, JOBR, JOBT, JOBP,
566 $ M, N, A, LDA, SVA, U, LDU, V, LDV,
567 $ CWORK, LWORK, RWORK, LRWORK, IWORK, INFO )
575 INTEGER INFO, LDA, LDU, LDV, LWORK, LRWORK, M, N
578 COMPLEX A( LDA, * ), U( LDU, * ), V( LDV, * ), CWORK( LWORK )
579 REAL SVA( N ), RWORK( LRWORK )
581 CHARACTER*1 JOBA, JOBP, JOBR, JOBT, JOBU, JOBV
588 PARAMETER ( ZERO = 0.0e0, one = 1.0e0 )
590 parameter( czero = ( 0.0e0, 0.0e0 ), cone = ( 1.0e0, 0.0e0 ) )
594 REAL AAPP, AAQQ, AATMAX, AATMIN, BIG, BIG1, COND_OK,
595 $ condr1, condr2, entra, entrat, epsln, maxprj, scalem,
596 $ sconda, sfmin, small, temp1, uscal1, uscal2, xsc
597 INTEGER IERR, N1, NR, NUMRANK, p, q, WARNING
598 LOGICAL ALMORT, DEFR, ERREST, GOSCAL, JRACC, KILL, LQUERY,
599 $ lsvec, l2aber, l2kill, l2pert, l2rank, l2tran, noscal,
600 $ rowpiv, rsvec, transp
602 INTEGER OPTWRK, MINWRK, MINRWRK, MINIWRK
603 INTEGER LWCON, LWLQF, LWQP3, LWQRF, LWUNMLQ, LWUNMQR, LWUNMQRM,
604 $ lwsvdj, lwsvdjv, lrwqp3, lrwcon, lrwsvdj, iwoff
605 INTEGER LWRK_CGELQF, LWRK_CGEQP3, LWRK_CGEQP3N, LWRK_CGEQRF,
606 $ LWRK_CGESVJ, LWRK_CGESVJV, LWRK_CGESVJU, LWRK_CUNMLQ,
607 $ lwrk_cunmqr, lwrk_cunmqrm
614 INTRINSIC abs, cmplx, conjg, alog, max, min, real, nint, sqrt
618 INTEGER ISAMAX, ICAMAX
620 EXTERNAL isamax, icamax, lsame, slamch, scnrm2
633 lsvec = lsame( jobu,
'U' ) .OR. lsame( jobu,
'F' )
634 jracc = lsame( jobv,
'J' )
635 rsvec = lsame( jobv,
'V' ) .OR. jracc
636 rowpiv = lsame( joba,
'F' ) .OR. lsame( joba,
'G' )
637 l2rank = lsame( joba,
'R' )
638 l2aber = lsame( joba,
'A' )
639 errest = lsame( joba,
'E' ) .OR. lsame( joba,
'G' )
640 l2tran = lsame( jobt,
'T' ) .AND. ( m .EQ. n )
641 l2kill = lsame( jobr,
'R' )
642 defr = lsame( jobr,
'N' )
643 l2pert = lsame( jobp,
'P' )
645 lquery = ( lwork .EQ. -1 ) .OR. ( lrwork .EQ. -1 )
647 IF ( .NOT.(rowpiv .OR. l2rank .OR. l2aber .OR.
648 $ errest .OR. lsame( joba,
'C' ) ))
THEN
650 ELSE IF ( .NOT.( lsvec .OR. lsame( jobu,
'N' ) .OR.
651 $ ( lsame( jobu,
'W' ) .AND. rsvec .AND. l2tran ) ) )
THEN
653 ELSE IF ( .NOT.( rsvec .OR. lsame( jobv,
'N' ) .OR.
654 $ ( lsame( jobv,
'W' ) .AND. lsvec .AND. l2tran ) ) )
THEN
656 ELSE IF ( .NOT. ( l2kill .OR. defr ) )
THEN
658 ELSE IF ( .NOT. ( lsame(jobt,
'T') .OR. lsame(jobt,
'N') ) )
THEN
660 ELSE IF ( .NOT. ( l2pert .OR. lsame( jobp,
'N' ) ) )
THEN
662 ELSE IF ( m .LT. 0 )
THEN
664 ELSE IF ( ( n .LT. 0 ) .OR. ( n .GT. m ) )
THEN
666 ELSE IF ( lda .LT. m )
THEN
668 ELSE IF ( lsvec .AND. ( ldu .LT. m ) )
THEN
670 ELSE IF ( rsvec .AND. ( ldv .LT. n ) )
THEN
677 IF ( info .EQ. 0 )
THEN
691 lwunmlq = max( 1, n )
692 lwunmqr = max( 1, n )
693 lwunmqrm = max( 1, m )
698 lwsvdj = max( 2 * n, 1 )
699 lwsvdjv = max( 2 * n, 1 )
705 CALL cgeqp3( m, n, a, lda, iwork, cdummy, cdummy, -1,
707 lwrk_cgeqp3 = int( cdummy(1) )
708 CALL cgeqrf( n, n, a, lda, cdummy, cdummy,-1, ierr )
709 lwrk_cgeqrf = int( cdummy(1) )
710 CALL cgelqf( n, n, a, lda, cdummy, cdummy,-1, ierr )
711 lwrk_cgelqf = int( cdummy(1) )
716 IF ( .NOT. (lsvec .OR. rsvec ) )
THEN
720 minwrk = max( n+lwqp3, n**2+lwcon, n+lwqrf, lwsvdj )
722 minwrk = max( n+lwqp3, n+lwqrf, lwsvdj )
725 CALL cgesvj(
'L',
'N',
'N', n, n, a, lda, sva, n, v,
726 $ ldv, cdummy, -1, rdummy, -1, ierr )
727 lwrk_cgesvj = int( cdummy(1) )
729 optwrk = max( n+lwrk_cgeqp3, n**2+lwcon,
730 $ n+lwrk_cgeqrf, lwrk_cgesvj )
732 optwrk = max( n+lwrk_cgeqp3, n+lwrk_cgeqrf,
736 IF ( l2tran .OR. rowpiv )
THEN
738 minrwrk = max( 7, 2*m, lrwqp3, lrwcon, lrwsvdj )
740 minrwrk = max( 7, 2*m, lrwqp3, lrwsvdj )
744 minrwrk = max( 7, lrwqp3, lrwcon, lrwsvdj )
746 minrwrk = max( 7, lrwqp3, lrwsvdj )
749 IF ( rowpiv .OR. l2tran ) miniwrk = miniwrk + m
750 ELSE IF ( rsvec .AND. (.NOT.lsvec) )
THEN
754 minwrk = max( n+lwqp3, lwcon, lwsvdj, n+lwlqf,
755 $ 2*n+lwqrf, n+lwsvdj, n+lwunmlq )
757 minwrk = max( n+lwqp3, lwsvdj, n+lwlqf, 2*n+lwqrf,
758 $ n+lwsvdj, n+lwunmlq )
761 CALL cgesvj(
'L',
'U',
'N', n,n, u, ldu, sva, n, a,
762 $ lda, cdummy, -1, rdummy, -1, ierr )
763 lwrk_cgesvj = int( cdummy(1) )
764 CALL cunmlq(
'L',
'C', n, n, n, a, lda, cdummy,
765 $ v, ldv, cdummy, -1, ierr )
766 lwrk_cunmlq = int( cdummy(1) )
768 optwrk = max( n+lwrk_cgeqp3, lwcon, lwrk_cgesvj,
769 $ n+lwrk_cgelqf, 2*n+lwrk_cgeqrf,
770 $ n+lwrk_cgesvj, n+lwrk_cunmlq )
772 optwrk = max( n+lwrk_cgeqp3, lwrk_cgesvj,n+lwrk_cgelqf,
773 $ 2*n+lwrk_cgeqrf, n+lwrk_cgesvj,
777 IF ( l2tran .OR. rowpiv )
THEN
779 minrwrk = max( 7, 2*m, lrwqp3, lrwsvdj, lrwcon )
781 minrwrk = max( 7, 2*m, lrwqp3, lrwsvdj )
785 minrwrk = max( 7, lrwqp3, lrwsvdj, lrwcon )
787 minrwrk = max( 7, lrwqp3, lrwsvdj )
790 IF ( rowpiv .OR. l2tran ) miniwrk = miniwrk + m
791 ELSE IF ( lsvec .AND. (.NOT.rsvec) )
THEN
795 minwrk = n + max( lwqp3,lwcon,n+lwqrf,lwsvdj,lwunmqrm )
797 minwrk = n + max( lwqp3, n+lwqrf, lwsvdj, lwunmqrm )
800 CALL cgesvj(
'L',
'U',
'N', n,n, u, ldu, sva, n, a,
801 $ lda, cdummy, -1, rdummy, -1, ierr )
802 lwrk_cgesvj = int( cdummy(1) )
803 CALL cunmqr(
'L',
'N', m, n, n, a, lda, cdummy, u,
804 $ ldu, cdummy, -1, ierr )
805 lwrk_cunmqrm = int( cdummy(1) )
807 optwrk = n + max( lwrk_cgeqp3, lwcon, n+lwrk_cgeqrf,
808 $ lwrk_cgesvj, lwrk_cunmqrm )
810 optwrk = n + max( lwrk_cgeqp3, n+lwrk_cgeqrf,
811 $ lwrk_cgesvj, lwrk_cunmqrm )
814 IF ( l2tran .OR. rowpiv )
THEN
816 minrwrk = max( 7, 2*m, lrwqp3, lrwsvdj, lrwcon )
818 minrwrk = max( 7, 2*m, lrwqp3, lrwsvdj )
822 minrwrk = max( 7, lrwqp3, lrwsvdj, lrwcon )
824 minrwrk = max( 7, lrwqp3, lrwsvdj )
827 IF ( rowpiv .OR. l2tran ) miniwrk = miniwrk + m
831 IF ( .NOT. jracc )
THEN
833 minwrk = max( n+lwqp3, n+lwcon, 2*n+n**2+lwcon,
834 $ 2*n+lwqrf, 2*n+lwqp3,
835 $ 2*n+n**2+n+lwlqf, 2*n+n**2+n+n**2+lwcon,
836 $ 2*n+n**2+n+lwsvdj, 2*n+n**2+n+lwsvdjv,
837 $ 2*n+n**2+n+lwunmqr,2*n+n**2+n+lwunmlq,
838 $ n+n**2+lwsvdj, n+lwunmqrm )
840 minwrk = max( n+lwqp3, 2*n+n**2+lwcon,
841 $ 2*n+lwqrf, 2*n+lwqp3,
842 $ 2*n+n**2+n+lwlqf, 2*n+n**2+n+n**2+lwcon,
843 $ 2*n+n**2+n+lwsvdj, 2*n+n**2+n+lwsvdjv,
844 $ 2*n+n**2+n+lwunmqr,2*n+n**2+n+lwunmlq,
845 $ n+n**2+lwsvdj, n+lwunmqrm )
847 miniwrk = miniwrk + n
848 IF ( rowpiv .OR. l2tran ) miniwrk = miniwrk + m
851 minwrk = max( n+lwqp3, n+lwcon, 2*n+lwqrf,
852 $ 2*n+n**2+lwsvdjv, 2*n+n**2+n+lwunmqr,
855 minwrk = max( n+lwqp3, 2*n+lwqrf,
856 $ 2*n+n**2+lwsvdjv, 2*n+n**2+n+lwunmqr,
859 IF ( rowpiv .OR. l2tran ) miniwrk = miniwrk + m
862 CALL cunmqr(
'L',
'N', m, n, n, a, lda, cdummy, u,
863 $ ldu, cdummy, -1, ierr )
864 lwrk_cunmqrm = int( cdummy(1) )
865 CALL cunmqr(
'L',
'N', n, n, n, a, lda, cdummy, u,
866 $ ldu, cdummy, -1, ierr )
867 lwrk_cunmqr = int( cdummy(1) )
868 IF ( .NOT. jracc )
THEN
869 CALL cgeqp3( n,n, a, lda, iwork, cdummy,cdummy, -1,
871 lwrk_cgeqp3n = int( cdummy(1) )
872 CALL cgesvj(
'L',
'U',
'N', n, n, u, ldu, sva,
873 $ n, v, ldv, cdummy, -1, rdummy, -1, ierr )
874 lwrk_cgesvj = int( cdummy(1) )
875 CALL cgesvj(
'U',
'U',
'N', n, n, u, ldu, sva,
876 $ n, v, ldv, cdummy, -1, rdummy, -1, ierr )
877 lwrk_cgesvju = int( cdummy(1) )
878 CALL cgesvj(
'L',
'U',
'V', n, n, u, ldu, sva,
879 $ n, v, ldv, cdummy, -1, rdummy, -1, ierr )
880 lwrk_cgesvjv = int( cdummy(1) )
881 CALL cunmlq(
'L',
'C', n, n, n, a, lda, cdummy,
882 $ v, ldv, cdummy, -1, ierr )
883 lwrk_cunmlq = int( cdummy(1) )
885 optwrk = max( n+lwrk_cgeqp3, n+lwcon,
886 $ 2*n+n**2+lwcon, 2*n+lwrk_cgeqrf,
888 $ 2*n+n**2+n+lwrk_cgelqf,
889 $ 2*n+n**2+n+n**2+lwcon,
890 $ 2*n+n**2+n+lwrk_cgesvj,
891 $ 2*n+n**2+n+lwrk_cgesvjv,
892 $ 2*n+n**2+n+lwrk_cunmqr,
893 $ 2*n+n**2+n+lwrk_cunmlq,
894 $ n+n**2+lwrk_cgesvju,
897 optwrk = max( n+lwrk_cgeqp3,
898 $ 2*n+n**2+lwcon, 2*n+lwrk_cgeqrf,
900 $ 2*n+n**2+n+lwrk_cgelqf,
901 $ 2*n+n**2+n+n**2+lwcon,
902 $ 2*n+n**2+n+lwrk_cgesvj,
903 $ 2*n+n**2+n+lwrk_cgesvjv,
904 $ 2*n+n**2+n+lwrk_cunmqr,
905 $ 2*n+n**2+n+lwrk_cunmlq,
906 $ n+n**2+lwrk_cgesvju,
910 CALL cgesvj(
'L',
'U',
'V', n, n, u, ldu, sva,
911 $ n, v, ldv, cdummy, -1, rdummy, -1, ierr )
912 lwrk_cgesvjv = int( cdummy(1) )
913 CALL cunmqr(
'L',
'N', n, n, n, cdummy, n, cdummy,
914 $ v, ldv, cdummy, -1, ierr )
915 lwrk_cunmqr = int( cdummy(1) )
916 CALL cunmqr(
'L',
'N', m, n, n, a, lda, cdummy, u,
917 $ ldu, cdummy, -1, ierr )
918 lwrk_cunmqrm = int( cdummy(1) )
920 optwrk = max( n+lwrk_cgeqp3, n+lwcon,
921 $ 2*n+lwrk_cgeqrf, 2*n+n**2,
922 $ 2*n+n**2+lwrk_cgesvjv,
923 $ 2*n+n**2+n+lwrk_cunmqr,n+lwrk_cunmqrm )
925 optwrk = max( n+lwrk_cgeqp3, 2*n+lwrk_cgeqrf,
926 $ 2*n+n**2, 2*n+n**2+lwrk_cgesvjv,
927 $ 2*n+n**2+n+lwrk_cunmqr,
932 IF ( l2tran .OR. rowpiv )
THEN
933 minrwrk = max( 7, 2*m, lrwqp3, lrwsvdj, lrwcon )
935 minrwrk = max( 7, lrwqp3, lrwsvdj, lrwcon )
938 minwrk = max( 2, minwrk )
939 optwrk = max( optwrk, minwrk )
940 IF ( lwork .LT. minwrk .AND. (.NOT.lquery) ) info = - 17
941 IF ( lrwork .LT. minrwrk .AND. (.NOT.lquery) ) info = - 19
944 IF ( info .NE. 0 )
THEN
946 CALL xerbla(
'CGEJSV', - info )
948 ELSE IF ( lquery )
THEN
952 iwork(1) = max( 4, miniwrk )
958 IF ( ( m .EQ. 0 ) .OR. ( n .EQ. 0 ) )
THEN
968 IF ( lsame( jobu,
'F' ) ) n1 = m
975 epsln = slamch(
'Epsilon')
976 sfmin = slamch(
'SafeMinimum')
977 small = sfmin / epsln
987 scalem = one / sqrt(real(m)*real(n))
993 CALL classq( m, a(1,p), 1, aapp, aaqq )
994 IF ( aapp .GT. big )
THEN
996 CALL xerbla(
'CGEJSV', -info )
1000 IF ( ( aapp .LT. (big / aaqq) ) .AND. noscal )
THEN
1001 sva(p) = aapp * aaqq
1004 sva(p) = aapp * ( aaqq * scalem )
1007 CALL sscal( p-1, scalem, sva, 1 )
1012 IF ( noscal ) scalem = one
1017 aapp = max( aapp, sva(p) )
1018 IF ( sva(p) .NE. zero ) aaqq = min( aaqq, sva(p) )
1023 IF ( aapp .EQ. zero )
THEN
1024 IF ( lsvec )
CALL claset(
'G', m, n1, czero, cone, u, ldu )
1025 IF ( rsvec )
CALL claset(
'G', n, n, czero, cone, v, ldv )
1028 IF ( errest ) rwork(3) = one
1029 IF ( lsvec .AND. rsvec )
THEN
1049 IF ( aaqq .LE. sfmin )
THEN
1057 IF ( n .EQ. 1 )
THEN
1060 CALL clascl(
'G',0,0,sva(1),scalem, m,1,a(1,1),lda,ierr )
1061 CALL clacpy(
'A', m, 1, a, lda, u, ldu )
1063 IF ( n1 .NE. n )
THEN
1064 CALL cgeqrf( m, n, u,ldu, cwork, cwork(n+1),lwork-n,ierr )
1065 CALL cungqr( m,n1,1, u,ldu,cwork,cwork(n+1),lwork-n,ierr )
1066 CALL ccopy( m, a(1,1), 1, u(1,1), 1 )
1072 IF ( sva(1) .LT. (big*scalem) )
THEN
1073 sva(1) = sva(1) / scalem
1076 rwork(1) = one / scalem
1078 IF ( sva(1) .NE. zero )
THEN
1080 IF ( ( sva(1) / scalem) .GE. sfmin )
THEN
1091 IF ( errest ) rwork(3) = one
1092 IF ( lsvec .AND. rsvec )
THEN
1108 IF ( rowpiv .OR. l2tran )
THEN
1119 CALL classq( n, a(p,1), lda, xsc, temp1 )
1122 rwork(m+p) = xsc * scalem
1123 rwork(p) = xsc * (scalem*sqrt(temp1))
1124 aatmax = max( aatmax, rwork(p) )
1125 IF (rwork(p) .NE. zero)
1126 $ aatmin = min(aatmin,rwork(p))
1130 rwork(m+p) = scalem*abs( a(p,icamax(n,a(p,1),lda)) )
1131 aatmax = max( aatmax, rwork(m+p) )
1132 aatmin = min( aatmin, rwork(m+p) )
1151 CALL slassq( n, sva, 1, xsc, temp1 )
1156 big1 = ( ( sva(p) / xsc )**2 ) * temp1
1157 IF ( big1 .NE. zero ) entra = entra + big1 * alog(big1)
1159 entra = - entra / alog(real(n))
1169 big1 = ( ( rwork(p) / xsc )**2 ) * temp1
1170 IF ( big1 .NE. zero ) entrat = entrat + big1 * alog(big1)
1172 entrat = - entrat / alog(real(m))
1177 transp = ( entrat .LT. entra )
1184 DO 1115 p = 1, n - 1
1185 a(p,p) = conjg(a(p,p))
1186 DO 1116 q = p + 1, n
1187 ctemp = conjg(a(q,p))
1188 a(q,p) = conjg(a(p,q))
1192 a(n,n) = conjg(a(n,n))
1226 temp1 = sqrt( big / real(n) )
1232 CALL slascl(
'G', 0, 0, aapp, temp1, n, 1, sva, n, ierr )
1233 IF ( aaqq .GT. (aapp * sfmin) )
THEN
1234 aaqq = ( aaqq / aapp ) * temp1
1236 aaqq = ( aaqq * temp1 ) / aapp
1238 temp1 = temp1 * scalem
1239 CALL clascl(
'G', 0, 0, aapp, temp1, m, n, a, lda, ierr )
1263 IF ( ( aaqq.LT.sqrt(sfmin) ) .AND. lsvec .AND. rsvec )
THEN
1268 IF ( aaqq .LT. xsc )
THEN
1270 IF ( sva(p) .LT. xsc )
THEN
1271 CALL claset(
'A', m, 1, czero, czero, a(1,p), lda )
1285 IF ( ( lsvec .AND. rsvec ) .AND. .NOT.( jracc ) )
THEN
1290 DO 1952 p = 1, m - 1
1291 q = isamax( m-p+1, rwork(m+p), 1 ) + p - 1
1293 IF ( p .NE. q )
THEN
1295 rwork(m+p) = rwork(m+q)
1299 CALL claswp( n, a, lda, 1, m-1, iwork(iwoff+1), 1 )
1321 CALL cgeqp3( m, n, a, lda, iwork, cwork, cwork(n+1), lwork-n,
1338 temp1 = sqrt(real(n))*epsln
1340 IF ( abs(a(p,p)) .GE. (temp1*abs(a(1,1))) )
THEN
1347 ELSE IF ( l2rank )
THEN
1353 IF ( ( abs(a(p,p)) .LT. (epsln*abs(a(p-1,p-1))) ) .OR.
1354 $ ( abs(a(p,p)) .LT. small ) .OR.
1355 $ ( l2kill .AND. (abs(a(p,p)) .LT. temp1) ) )
GO TO 3402
1370 IF ( ( abs(a(p,p)) .LT. small ) .OR.
1371 $ ( l2kill .AND. (abs(a(p,p)) .LT. temp1) ) )
GO TO 3302
1379 IF ( nr .EQ. n )
THEN
1382 temp1 = abs(a(p,p)) / sva(iwork(p))
1383 maxprj = min( maxprj, temp1 )
1385 IF ( maxprj**2 .GE. one - real(n)*epsln ) almort = .true.
1394 IF ( n .EQ. nr )
THEN
1397 CALL clacpy(
'U', n, n, a, lda, v, ldv )
1399 temp1 = sva(iwork(p))
1400 CALL csscal( p, one/temp1, v(1,p), 1 )
1403 CALL cpocon(
'U', n, v, ldv, one, temp1,
1404 $ cwork(n+1), rwork, ierr )
1406 CALL cpocon(
'U', n, v, ldv, one, temp1,
1407 $ cwork, rwork, ierr )
1410 ELSE IF ( lsvec )
THEN
1412 CALL clacpy(
'U', n, n, a, lda, u, ldu )
1414 temp1 = sva(iwork(p))
1415 CALL csscal( p, one/temp1, u(1,p), 1 )
1417 CALL cpocon(
'U', n, u, ldu, one, temp1,
1418 $ cwork(n+1), rwork, ierr )
1420 CALL clacpy(
'U', n, n, a, lda, cwork, n )
1425 temp1 = sva(iwork(p))
1427 CALL csscal( p, one/temp1, cwork((p-1)*n+1), 1 )
1432 CALL cpocon(
'U', n, cwork, n, one, temp1,
1433 $ cwork(n*n+1), rwork, ierr )
1436 IF ( temp1 .NE. zero )
THEN
1437 sconda = one / sqrt(temp1)
1448 l2pert = l2pert .AND. ( abs( a(1,1)/a(nr,nr) ) .GT. sqrt(big1) )
1453 IF ( .NOT. ( rsvec .OR. lsvec ) )
THEN
1458 DO 1946 p = 1, min( n-1, nr )
1459 CALL ccopy( n-p, a(p,p+1), lda, a(p+1,p), 1 )
1460 CALL clacgv( n-p+1, a(p,p), 1 )
1462 IF ( nr .EQ. n ) a(n,n) = conjg(a(n,n))
1476 IF ( .NOT. almort )
THEN
1480 xsc = epsln / real(n)
1482 ctemp = cmplx(xsc*abs(a(q,q)),zero)
1484 IF ( ( (p.GT.q) .AND. (abs(a(p,q)).LE.temp1) )
1485 $ .OR. ( p .LT. q ) )
1491 CALL claset(
'U', nr-1,nr-1, czero,czero, a(1,2),lda )
1496 CALL cgeqrf( n,nr, a,lda, cwork, cwork(n+1),lwork-n, ierr )
1499 DO 1948 p = 1, nr - 1
1500 CALL ccopy( nr-p, a(p,p+1), lda, a(p+1,p), 1 )
1501 CALL clacgv( nr-p+1, a(p,p), 1 )
1512 xsc = epsln / real(n)
1514 ctemp = cmplx(xsc*abs(a(q,q)),zero)
1516 IF ( ( (p.GT.q) .AND. (abs(a(p,q)).LE.temp1) )
1517 $ .OR. ( p .LT. q ) )
1523 CALL claset(
'U', nr-1, nr-1, czero, czero, a(1,2), lda )
1530 CALL cgesvj(
'L',
'N',
'N', nr, nr, a, lda, sva,
1531 $ n, v, ldv, cwork, lwork, rwork, lrwork, info )
1534 numrank = nint(rwork(2))
1537 ELSE IF ( ( rsvec .AND. ( .NOT. lsvec ) .AND. ( .NOT. jracc ) )
1539 $ ( jracc .AND. ( .NOT. lsvec ) .AND. ( nr .NE. n ) ) )
THEN
1547 CALL ccopy( n-p+1, a(p,p), lda, v(p,p), 1 )
1548 CALL clacgv( n-p+1, v(p,p), 1 )
1550 CALL claset(
'U', nr-1,nr-1, czero, czero, v(1,2), ldv )
1552 CALL cgesvj(
'L',
'U',
'N', n, nr, v, ldv, sva, nr, a, lda,
1553 $ cwork, lwork, rwork, lrwork, info )
1555 numrank = nint(rwork(2))
1562 CALL claset(
'L', nr-1,nr-1, czero, czero, a(2,1), lda )
1563 CALL cgelqf( nr,n, a, lda, cwork, cwork(n+1), lwork-n, ierr)
1564 CALL clacpy(
'L', nr, nr, a, lda, v, ldv )
1565 CALL claset(
'U', nr-1,nr-1, czero, czero, v(1,2), ldv )
1566 CALL cgeqrf( nr, nr, v, ldv, cwork(n+1), cwork(2*n+1),
1569 CALL ccopy( nr-p+1, v(p,p), ldv, v(p,p), 1 )
1570 CALL clacgv( nr-p+1, v(p,p), 1 )
1572 CALL claset(
'U', nr-1, nr-1, czero, czero, v(1,2), ldv)
1574 CALL cgesvj(
'L',
'U',
'N', nr, nr, v,ldv, sva, nr, u,
1575 $ ldu, cwork(n+1), lwork-n, rwork, lrwork, info )
1577 numrank = nint(rwork(2))
1578 IF ( nr .LT. n )
THEN
1579 CALL claset(
'A',n-nr, nr, czero,czero, v(nr+1,1), ldv )
1580 CALL claset(
'A',nr, n-nr, czero,czero, v(1,nr+1), ldv )
1581 CALL claset(
'A',n-nr,n-nr,czero,cone, v(nr+1,nr+1),ldv )
1584 CALL cunmlq(
'L',
'C', n, n, nr, a, lda, cwork,
1585 $ v, ldv, cwork(n+1), lwork-n, ierr )
1593 CALL clapmr( .false., n, n, v, ldv, iwork )
1596 CALL clacpy(
'A', n, n, v, ldv, u, ldu )
1599 ELSE IF ( jracc .AND. (.NOT. lsvec) .AND. ( nr.EQ. n ) )
THEN
1601 CALL claset(
'L', n-1,n-1, czero, czero, a(2,1), lda )
1603 CALL cgesvj(
'U',
'N',
'V', n, n, a, lda, sva, n, v, ldv,
1604 $ cwork, lwork, rwork, lrwork, info )
1606 numrank = nint(rwork(2))
1607 CALL clapmr( .false., n, n, v, ldv, iwork )
1609 ELSE IF ( lsvec .AND. ( .NOT. rsvec ) )
THEN
1616 CALL ccopy( n-p+1, a(p,p), lda, u(p,p), 1 )
1617 CALL clacgv( n-p+1, u(p,p), 1 )
1619 CALL claset(
'U', nr-1, nr-1, czero, czero, u(1,2), ldu )
1621 CALL cgeqrf( n, nr, u, ldu, cwork(n+1), cwork(2*n+1),
1624 DO 1967 p = 1, nr - 1
1625 CALL ccopy( nr-p, u(p,p+1), ldu, u(p+1,p), 1 )
1626 CALL clacgv( n-p+1, u(p,p), 1 )
1628 CALL claset(
'U', nr-1, nr-1, czero, czero, u(1,2), ldu )
1630 CALL cgesvj(
'L',
'U',
'N', nr,nr, u, ldu, sva, nr, a,
1631 $ lda, cwork(n+1), lwork-n, rwork, lrwork, info )
1633 numrank = nint(rwork(2))
1635 IF ( nr .LT. m )
THEN
1636 CALL claset(
'A', m-nr, nr,czero, czero, u(nr+1,1), ldu )
1637 IF ( nr .LT. n1 )
THEN
1638 CALL claset(
'A',nr, n1-nr, czero, czero, u(1,nr+1),ldu )
1639 CALL claset(
'A',m-nr,n1-nr,czero,cone,u(nr+1,nr+1),ldu )
1643 CALL cunmqr(
'L',
'N', m, n1, n, a, lda, cwork, u,
1644 $ ldu, cwork(n+1), lwork-n, ierr )
1647 $
CALL claswp( n1, u, ldu, 1, m-1, iwork(iwoff+1), -1 )
1650 xsc = one / scnrm2( m, u(1,p), 1 )
1651 CALL csscal( m, xsc, u(1,p), 1 )
1655 CALL clacpy(
'A', n, n, u, ldu, v, ldv )
1662 IF ( .NOT. jracc )
THEN
1664 IF ( .NOT. almort )
THEN
1674 CALL ccopy( n-p+1, a(p,p), lda, v(p,p), 1 )
1675 CALL clacgv( n-p+1, v(p,p), 1 )
1693 ctemp = cmplx(xsc*abs( v(q,q) ),zero)
1695 IF ( ( p .GT. q ) .AND. ( abs(v(p,q)) .LE. temp1 )
1696 $ .OR. ( p .LT. q ) )
1699 IF ( p .LT. q ) v(p,q) = - v(p,q)
1703 CALL claset(
'U', nr-1, nr-1, czero, czero, v(1,2), ldv )
1710 CALL clacpy(
'L', nr, nr, v, ldv, cwork(2*n+1), nr )
1712 temp1 = scnrm2(nr-p+1,cwork(2*n+(p-1)*nr+p),1)
1713 CALL csscal(nr-p+1,one/temp1,cwork(2*n+(p-1)*nr+p),1)
1715 CALL cpocon(
'L',nr,cwork(2*n+1),nr,one,temp1,
1716 $ cwork(2*n+nr*nr+1),rwork,ierr)
1717 condr1 = one / sqrt(temp1)
1723 cond_ok = sqrt(sqrt(real(nr)))
1726 IF ( condr1 .LT. cond_ok )
THEN
1731 CALL cgeqrf( n, nr, v, ldv, cwork(n+1), cwork(2*n+1),
1735 xsc = sqrt(small)/epsln
1737 DO 3958 q = 1, p - 1
1738 ctemp=cmplx(xsc*min(abs(v(p,p)),abs(v(q,q))),
1740 IF ( abs(v(q,p)) .LE. temp1 )
1748 $
CALL clacpy(
'A', n, nr, v, ldv, cwork(2*n+1), n )
1752 DO 1969 p = 1, nr - 1
1753 CALL ccopy( nr-p, v(p,p+1), ldv, v(p+1,p), 1 )
1754 CALL clacgv(nr-p+1, v(p,p), 1 )
1756 v(nr,nr)=conjg(v(nr,nr))
1773 CALL cgeqp3( n, nr, v, ldv, iwork(n+1), cwork(n+1),
1774 $ cwork(2*n+1), lwork-2*n, rwork, ierr )
1780 DO 3968 q = 1, p - 1
1781 ctemp=cmplx(xsc*min(abs(v(p,p)),abs(v(q,q))),
1783 IF ( abs(v(q,p)) .LE. temp1 )
1790 CALL clacpy(
'A', n, nr, v, ldv, cwork(2*n+1), n )
1795 DO 8971 q = 1, p - 1
1796 ctemp=cmplx(xsc*min(abs(v(p,p)),abs(v(q,q))),
1803 CALL claset(
'L',nr-1,nr-1,czero,czero,v(2,1),ldv )
1806 CALL cgelqf( nr, nr, v, ldv, cwork(2*n+n*nr+1),
1807 $ cwork(2*n+n*nr+nr+1), lwork-2*n-n*nr-nr, ierr )
1809 CALL clacpy(
'L',nr,nr,v,ldv,cwork(2*n+n*nr+nr+1),nr )
1811 temp1 = scnrm2( p, cwork(2*n+n*nr+nr+p), nr )
1812 CALL csscal( p, one/temp1, cwork(2*n+n*nr+nr+p), nr )
1814 CALL cpocon(
'L',nr,cwork(2*n+n*nr+nr+1),nr,one,temp1,
1815 $ cwork(2*n+n*nr+nr+nr*nr+1),rwork,ierr )
1816 condr2 = one / sqrt(temp1)
1819 IF ( condr2 .GE. cond_ok )
THEN
1824 CALL clacpy(
'U', nr, nr, v, ldv, cwork(2*n+1), n )
1834 ctemp = xsc * v(q,q)
1835 DO 4969 p = 1, q - 1
1841 CALL claset(
'U', nr-1,nr-1, czero,czero, v(1,2), ldv )
1850 IF ( condr1 .LT. cond_ok )
THEN
1852 CALL cgesvj(
'L',
'U',
'N',nr,nr,v,ldv,sva,nr,u, ldu,
1853 $ cwork(2*n+n*nr+nr+1),lwork-2*n-n*nr-nr,rwork,
1856 numrank = nint(rwork(2))
1858 CALL ccopy( nr, v(1,p), 1, u(1,p), 1 )
1859 CALL csscal( nr, sva(p), v(1,p), 1 )
1864 IF ( nr .EQ. n )
THEN
1869 CALL ctrsm(
'L',
'U',
'N',
'N', nr,nr,cone, a,lda, v,ldv)
1875 CALL ctrsm(
'L',
'U',
'C',
'N',nr,nr,cone,cwork(2*n+1),
1877 IF ( nr .LT. n )
THEN
1878 CALL claset(
'A',n-nr,nr,czero,czero,v(nr+1,1),ldv)
1879 CALL claset(
'A',nr,n-nr,czero,czero,v(1,nr+1),ldv)
1880 CALL claset(
'A',n-nr,n-nr,czero,cone,v(nr+1,nr+1),ldv)
1882 CALL cunmqr(
'L',
'N',n,n,nr,cwork(2*n+1),n,cwork(n+1),
1883 $ v,ldv,cwork(2*n+n*nr+nr+1),lwork-2*n-n*nr-nr,ierr)
1886 ELSE IF ( condr2 .LT. cond_ok )
THEN
1892 CALL cgesvj(
'L',
'U',
'N', nr, nr, v, ldv, sva, nr, u,
1893 $ ldu, cwork(2*n+n*nr+nr+1), lwork-2*n-n*nr-nr,
1894 $ rwork, lrwork, info )
1896 numrank = nint(rwork(2))
1898 CALL ccopy( nr, v(1,p), 1, u(1,p), 1 )
1899 CALL csscal( nr, sva(p), u(1,p), 1 )
1901 CALL ctrsm(
'L',
'U',
'N',
'N',nr,nr,cone,cwork(2*n+1),n,
1906 cwork(2*n+n*nr+nr+iwork(n+p)) = u(p,q)
1909 u(p,q) = cwork(2*n+n*nr+nr+p)
1912 IF ( nr .LT. n )
THEN
1913 CALL claset(
'A',n-nr,nr,czero,czero,v(nr+1,1),ldv )
1914 CALL claset(
'A',nr,n-nr,czero,czero,v(1,nr+1),ldv )
1915 CALL claset(
'A',n-nr,n-nr,czero,cone,v(nr+1,nr+1),ldv)
1917 CALL cunmqr(
'L',
'N',n,n,nr,cwork(2*n+1),n,cwork(n+1),
1918 $ v,ldv,cwork(2*n+n*nr+nr+1),lwork-2*n-n*nr-nr,ierr )
1931 CALL cgesvj(
'L',
'U',
'V', nr, nr, v, ldv, sva, nr, u,
1932 $ ldu, cwork(2*n+n*nr+nr+1), lwork-2*n-n*nr-nr,
1933 $ rwork, lrwork, info )
1935 numrank = nint(rwork(2))
1936 IF ( nr .LT. n )
THEN
1937 CALL claset(
'A',n-nr,nr,czero,czero,v(nr+1,1),ldv )
1938 CALL claset(
'A',nr,n-nr,czero,czero,v(1,nr+1),ldv )
1939 CALL claset(
'A',n-nr,n-nr,czero,cone,v(nr+1,nr+1),ldv)
1941 CALL cunmqr(
'L',
'N',n,n,nr,cwork(2*n+1),n,cwork(n+1),
1942 $ v,ldv,cwork(2*n+n*nr+nr+1),lwork-2*n-n*nr-nr,ierr )
1944 CALL cunmlq(
'L',
'C', nr, nr, nr, cwork(2*n+1), n,
1945 $ cwork(2*n+n*nr+1), u, ldu, cwork(2*n+n*nr+nr+1),
1946 $ lwork-2*n-n*nr-nr, ierr )
1949 cwork(2*n+n*nr+nr+iwork(n+p)) = u(p,q)
1952 u(p,q) = cwork(2*n+n*nr+nr+p)
1962 temp1 = sqrt(real(n)) * epsln
1965 cwork(2*n+n*nr+nr+iwork(p)) = v(p,q)
1968 v(p,q) = cwork(2*n+n*nr+nr+p)
1970 xsc = one / scnrm2( n, v(1,q), 1 )
1971 IF ( (xsc .LT. (one-temp1)) .OR. (xsc .GT. (one+temp1)) )
1972 $
CALL csscal( n, xsc, v(1,q), 1 )
1976 IF ( nr .LT. m )
THEN
1977 CALL claset(
'A', m-nr, nr, czero, czero, u(nr+1,1), ldu)
1978 IF ( nr .LT. n1 )
THEN
1979 CALL claset(
'A',nr,n1-nr,czero,czero,u(1,nr+1),ldu)
1980 CALL claset(
'A',m-nr,n1-nr,czero,cone,
1988 CALL cunmqr(
'L',
'N', m, n1, n, a, lda, cwork, u,
1989 $ ldu, cwork(n+1), lwork-n, ierr )
1992 temp1 = sqrt(real(m)) * epsln
1994 xsc = one / scnrm2( m, u(1,p), 1 )
1995 IF ( (xsc .LT. (one-temp1)) .OR. (xsc .GT. (one+temp1)) )
1996 $
CALL csscal( m, xsc, u(1,p), 1 )
2003 $
CALL claswp( n1, u, ldu, 1, m-1, iwork(iwoff+1), -1 )
2010 CALL clacpy(
'U', n, n, a, lda, cwork(n+1), n )
2014 ctemp = xsc * cwork( n + (p-1)*n + p )
2015 DO 5971 q = 1, p - 1
2018 cwork(n+(q-1)*n+p)=-ctemp
2022 CALL claset(
'L',n-1,n-1,czero,czero,cwork(n+2),n )
2025 CALL cgesvj(
'U',
'U',
'N', n, n, cwork(n+1), n, sva,
2026 $ n, u, ldu, cwork(n+n*n+1), lwork-n-n*n, rwork, lrwork,
2030 numrank = nint(rwork(2))
2032 CALL ccopy( n, cwork(n+(p-1)*n+1), 1, u(1,p), 1 )
2033 CALL csscal( n, sva(p), cwork(n+(p-1)*n+1), 1 )
2036 CALL ctrsm(
'L',
'U',
'N',
'N', n, n,
2037 $ cone, a, lda, cwork(n+1), n )
2039 CALL ccopy( n, cwork(n+p), n, v(iwork(p),1), ldv )
2041 temp1 = sqrt(real(n))*epsln
2043 xsc = one / scnrm2( n, v(1,p), 1 )
2044 IF ( (xsc .LT. (one-temp1)) .OR. (xsc .GT. (one+temp1)) )
2045 $
CALL csscal( n, xsc, v(1,p), 1 )
2050 IF ( n .LT. m )
THEN
2051 CALL claset(
'A', m-n, n, czero, czero, u(n+1,1), ldu )
2052 IF ( n .LT. n1 )
THEN
2053 CALL claset(
'A',n, n1-n, czero, czero, u(1,n+1),ldu)
2054 CALL claset(
'A',m-n,n1-n, czero, cone,u(n+1,n+1),ldu)
2057 CALL cunmqr(
'L',
'N', m, n1, n, a, lda, cwork, u,
2058 $ ldu, cwork(n+1), lwork-n, ierr )
2059 temp1 = sqrt(real(m))*epsln
2061 xsc = one / scnrm2( m, u(1,p), 1 )
2062 IF ( (xsc .LT. (one-temp1)) .OR. (xsc .GT. (one+temp1)) )
2063 $
CALL csscal( m, xsc, u(1,p), 1 )
2067 $
CALL claswp( n1, u, ldu, 1, m-1, iwork(iwoff+1), -1 )
2087 CALL ccopy( n-p+1, a(p,p), lda, v(p,p), 1 )
2088 CALL clacgv( n-p+1, v(p,p), 1 )
2092 xsc = sqrt(small/epsln)
2094 ctemp = cmplx(xsc*abs( v(q,q) ),zero)
2096 IF ( ( p .GT. q ) .AND. ( abs(v(p,q)) .LE. temp1 )
2097 $ .OR. ( p .LT. q ) )
2100 IF ( p .LT. q ) v(p,q) = - v(p,q)
2104 CALL claset(
'U', nr-1, nr-1, czero, czero, v(1,2), ldv )
2107 CALL cgeqrf( n, nr, v, ldv, cwork(n+1), cwork(2*n+1),
2109 CALL clacpy(
'L', n, nr, v, ldv, cwork(2*n+1), n )
2112 CALL ccopy( nr-p+1, v(p,p), ldv, u(p,p), 1 )
2113 CALL clacgv( nr-p+1, u(p,p), 1 )
2117 xsc = sqrt(small/epsln)
2119 DO 9971 p = 1, q - 1
2120 ctemp = cmplx(xsc * min(abs(u(p,p)),abs(u(q,q))),
2127 CALL claset(
'U', nr-1, nr-1, czero, czero, u(1,2), ldu )
2130 CALL cgesvj(
'L',
'U',
'V', nr, nr, u, ldu, sva,
2131 $ n, v, ldv, cwork(2*n+n*nr+1), lwork-2*n-n*nr,
2132 $ rwork, lrwork, info )
2134 numrank = nint(rwork(2))
2136 IF ( nr .LT. n )
THEN
2137 CALL claset(
'A',n-nr,nr,czero,czero,v(nr+1,1),ldv )
2138 CALL claset(
'A',nr,n-nr,czero,czero,v(1,nr+1),ldv )
2139 CALL claset(
'A',n-nr,n-nr,czero,cone,v(nr+1,nr+1),ldv )
2142 CALL cunmqr(
'L',
'N',n,n,nr,cwork(2*n+1),n,cwork(n+1),
2143 $ v,ldv,cwork(2*n+n*nr+nr+1),lwork-2*n-n*nr-nr,ierr )
2149 temp1 = sqrt(real(n)) * epsln
2152 cwork(2*n+n*nr+nr+iwork(p)) = v(p,q)
2155 v(p,q) = cwork(2*n+n*nr+nr+p)
2157 xsc = one / scnrm2( n, v(1,q), 1 )
2158 IF ( (xsc .LT. (one-temp1)) .OR. (xsc .GT. (one+temp1)) )
2159 $
CALL csscal( n, xsc, v(1,q), 1 )
2165 IF ( nr .LT. m )
THEN
2166 CALL claset(
'A', m-nr, nr, czero, czero, u(nr+1,1), ldu )
2167 IF ( nr .LT. n1 )
THEN
2168 CALL claset(
'A',nr, n1-nr, czero, czero, u(1,nr+1),ldu)
2169 CALL claset(
'A',m-nr,n1-nr, czero, cone,u(nr+1,nr+1),ldu)
2173 CALL cunmqr(
'L',
'N', m, n1, n, a, lda, cwork, u,
2174 $ ldu, cwork(n+1), lwork-n, ierr )
2177 $
CALL claswp( n1, u, ldu, 1, m-1, iwork(iwoff+1), -1 )
2184 CALL cswap( n, u(1,p), 1, v(1,p), 1 )
2193 IF ( uscal2 .LE. (big/sva(1))*uscal1 )
THEN
2194 CALL slascl(
'G', 0, 0, uscal1, uscal2, nr, 1, sva, n, ierr )
2199 IF ( nr .LT. n )
THEN
2205 rwork(1) = uscal2 * scalem
2207 IF ( errest ) rwork(3) = sconda
2208 IF ( lsvec .AND. rsvec )
THEN
subroutine xerbla(srname, info)
subroutine ccopy(n, cx, incx, cy, incy)
CCOPY
subroutine cgejsv(joba, jobu, jobv, jobr, jobt, jobp, m, n, a, lda, sva, u, ldu, v, ldv, cwork, lwork, rwork, lrwork, iwork, info)
CGEJSV
subroutine cgelqf(m, n, a, lda, tau, work, lwork, info)
CGELQF
subroutine cgeqp3(m, n, a, lda, jpvt, tau, work, lwork, rwork, info)
CGEQP3
subroutine cgeqrf(m, n, a, lda, tau, work, lwork, info)
CGEQRF
subroutine cgesvj(joba, jobu, jobv, m, n, a, lda, sva, mv, v, ldv, cwork, lwork, rwork, lrwork, info)
CGESVJ
subroutine clacgv(n, x, incx)
CLACGV conjugates a complex vector.
subroutine clacpy(uplo, m, n, a, lda, b, ldb)
CLACPY copies all or part of one two-dimensional array to another.
subroutine clapmr(forwrd, m, n, x, ldx, k)
CLAPMR rearranges rows of a matrix as specified by a permutation vector.
subroutine clascl(type, kl, ku, cfrom, cto, m, n, a, lda, info)
CLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
subroutine slascl(type, kl, ku, cfrom, cto, m, n, a, lda, info)
SLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
subroutine claset(uplo, m, n, alpha, beta, a, lda)
CLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
subroutine slassq(n, x, incx, scale, sumsq)
SLASSQ updates a sum of squares represented in scaled form.
subroutine classq(n, x, incx, scale, sumsq)
CLASSQ updates a sum of squares represented in scaled form.
subroutine claswp(n, a, lda, k1, k2, ipiv, incx)
CLASWP performs a series of row interchanges on a general rectangular matrix.
subroutine cpocon(uplo, n, a, lda, anorm, rcond, work, rwork, info)
CPOCON
subroutine csscal(n, sa, cx, incx)
CSSCAL
subroutine sscal(n, sa, sx, incx)
SSCAL
subroutine cswap(n, cx, incx, cy, incy)
CSWAP
subroutine ctrsm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb)
CTRSM
subroutine cungqr(m, n, k, a, lda, tau, work, lwork, info)
CUNGQR
subroutine cunmlq(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMLQ
subroutine cunmqr(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMQR