564 SUBROUTINE zgejsv( JOBA, JOBU, JOBV, JOBR, JOBT, JOBP,
565 $ M, N, A, LDA, SVA, U, LDU, V, LDV,
566 $ CWORK, LWORK, RWORK, LRWORK, IWORK, INFO )
574 INTEGER INFO, LDA, LDU, LDV, LWORK, LRWORK, M, N
577 COMPLEX*16 A( LDA, * ), U( LDU, * ), V( LDV, * ),
579 DOUBLE PRECISION SVA( N ), RWORK( LRWORK )
581 CHARACTER*1 JOBA, JOBP, JOBR, JOBT, JOBU, JOBV
587 DOUBLE PRECISION ZERO, ONE
588 PARAMETER ( ZERO = 0.0d0, one = 1.0d0 )
589 COMPLEX*16 CZERO, CONE
590 parameter( czero = ( 0.0d0, 0.0d0 ), cone = ( 1.0d0, 0.0d0 ) )
594 DOUBLE PRECISION AAPP, AAQQ, AATMAX, AATMIN, BIG, BIG1,
595 $ cond_ok, condr1, condr2, entra, entrat, epsln,
596 $ maxprj, scalem, sconda, sfmin, small, temp1,
597 $ uscal1, uscal2, xsc
598 INTEGER IERR, N1, NR, NUMRANK, p, q, WARNING
599 LOGICAL ALMORT, DEFR, ERREST, GOSCAL, JRACC, KILL, LQUERY,
600 $ lsvec, l2aber, l2kill, l2pert, l2rank, l2tran, noscal,
601 $ rowpiv, rsvec, transp
603 INTEGER OPTWRK, MINWRK, MINRWRK, MINIWRK
604 INTEGER LWCON, LWLQF, LWQP3, LWQRF, LWUNMLQ, LWUNMQR, LWUNMQRM,
605 $ lwsvdj, lwsvdjv, lrwqp3, lrwcon, lrwsvdj, iwoff
606 INTEGER LWRK_ZGELQF, LWRK_ZGEQP3, LWRK_ZGEQP3N, LWRK_ZGEQRF,
607 $ LWRK_ZGESVJ, LWRK_ZGESVJV, LWRK_ZGESVJU, LWRK_ZUNMLQ,
608 $ lwrk_zunmqr, lwrk_zunmqrm
612 DOUBLE PRECISION RDUMMY(1)
615 INTRINSIC abs, dcmplx, conjg, dlog, max, min, dble, nint, sqrt
618 DOUBLE PRECISION DLAMCH, DZNRM2
619 INTEGER IDAMAX, IZAMAX
621 EXTERNAL idamax, izamax, lsame, dlamch, dznrm2
634 lsvec = lsame( jobu,
'U' ) .OR. lsame( jobu,
'F' )
635 jracc = lsame( jobv,
'J' )
636 rsvec = lsame( jobv,
'V' ) .OR. jracc
637 rowpiv = lsame( joba,
'F' ) .OR. lsame( joba,
'G' )
638 l2rank = lsame( joba,
'R' )
639 l2aber = lsame( joba,
'A' )
640 errest = lsame( joba,
'E' ) .OR. lsame( joba,
'G' )
641 l2tran = lsame( jobt,
'T' ) .AND. ( m .EQ. n )
642 l2kill = lsame( jobr,
'R' )
643 defr = lsame( jobr,
'N' )
644 l2pert = lsame( jobp,
'P' )
646 lquery = ( lwork .EQ. -1 ) .OR. ( lrwork .EQ. -1 )
648 IF ( .NOT.(rowpiv .OR. l2rank .OR. l2aber .OR.
649 $ errest .OR. lsame( joba,
'C' ) ))
THEN
651 ELSE IF ( .NOT.( lsvec .OR. lsame( jobu,
'N' ) .OR.
652 $ ( lsame( jobu,
'W' ) .AND. rsvec .AND. l2tran ) ) )
THEN
654 ELSE IF ( .NOT.( rsvec .OR. lsame( jobv,
'N' ) .OR.
655 $ ( lsame( jobv,
'W' ) .AND. lsvec .AND. l2tran ) ) )
THEN
657 ELSE IF ( .NOT. ( l2kill .OR. defr ) )
THEN
659 ELSE IF ( .NOT. ( lsame(jobt,
'T') .OR.
660 $ lsame(jobt,
'N') ) )
THEN
662 ELSE IF ( .NOT. ( l2pert .OR. lsame( jobp,
'N' ) ) )
THEN
664 ELSE IF ( m .LT. 0 )
THEN
666 ELSE IF ( ( n .LT. 0 ) .OR. ( n .GT. m ) )
THEN
668 ELSE IF ( lda .LT. m )
THEN
670 ELSE IF ( lsvec .AND. ( ldu .LT. m ) )
THEN
672 ELSE IF ( rsvec .AND. ( ldv .LT. n ) )
THEN
679 IF ( info .EQ. 0 )
THEN
693 lwunmlq = max( 1, n )
694 lwunmqr = max( 1, n )
695 lwunmqrm = max( 1, m )
700 lwsvdj = max( 2 * n, 1 )
701 lwsvdjv = max( 2 * n, 1 )
707 CALL zgeqp3( m, n, a, lda, iwork, cdummy, cdummy, -1,
709 lwrk_zgeqp3 = int( cdummy(1) )
710 CALL zgeqrf( n, n, a, lda, cdummy, cdummy,-1, ierr )
711 lwrk_zgeqrf = int( cdummy(1) )
712 CALL zgelqf( n, n, a, lda, cdummy, cdummy,-1, ierr )
713 lwrk_zgelqf = int( cdummy(1) )
718 IF ( .NOT. (lsvec .OR. rsvec ) )
THEN
722 minwrk = max( n+lwqp3, n**2+lwcon, n+lwqrf, lwsvdj )
724 minwrk = max( n+lwqp3, n+lwqrf, lwsvdj )
727 CALL zgesvj(
'L',
'N',
'N', n, n, a, lda, sva, n,
729 $ ldv, cdummy, -1, rdummy, -1, ierr )
730 lwrk_zgesvj = int( cdummy(1) )
732 optwrk = max( n+lwrk_zgeqp3, n**2+lwcon,
733 $ n+lwrk_zgeqrf, lwrk_zgesvj )
735 optwrk = max( n+lwrk_zgeqp3, n+lwrk_zgeqrf,
739 IF ( l2tran .OR. rowpiv )
THEN
741 minrwrk = max( 7, 2*m, lrwqp3, lrwcon, lrwsvdj )
743 minrwrk = max( 7, 2*m, lrwqp3, lrwsvdj )
747 minrwrk = max( 7, lrwqp3, lrwcon, lrwsvdj )
749 minrwrk = max( 7, lrwqp3, lrwsvdj )
752 IF ( rowpiv .OR. l2tran ) miniwrk = miniwrk + m
753 ELSE IF ( rsvec .AND. (.NOT.lsvec) )
THEN
757 minwrk = max( n+lwqp3, lwcon, lwsvdj, n+lwlqf,
758 $ 2*n+lwqrf, n+lwsvdj, n+lwunmlq )
760 minwrk = max( n+lwqp3, lwsvdj, n+lwlqf, 2*n+lwqrf,
761 $ n+lwsvdj, n+lwunmlq )
764 CALL zgesvj(
'L',
'U',
'N', n,n, u, ldu, sva, n, a,
765 $ lda, cdummy, -1, rdummy, -1, ierr )
766 lwrk_zgesvj = int( cdummy(1) )
767 CALL zunmlq(
'L',
'C', n, n, n, a, lda, cdummy,
768 $ v, ldv, cdummy, -1, ierr )
769 lwrk_zunmlq = int( cdummy(1) )
771 optwrk = max( n+lwrk_zgeqp3, lwcon, lwrk_zgesvj,
772 $ n+lwrk_zgelqf, 2*n+lwrk_zgeqrf,
773 $ n+lwrk_zgesvj, n+lwrk_zunmlq )
775 optwrk = max( n+lwrk_zgeqp3, lwrk_zgesvj,n+lwrk_zgelqf,
776 $ 2*n+lwrk_zgeqrf, n+lwrk_zgesvj,
780 IF ( l2tran .OR. rowpiv )
THEN
782 minrwrk = max( 7, 2*m, lrwqp3, lrwsvdj, lrwcon )
784 minrwrk = max( 7, 2*m, lrwqp3, lrwsvdj )
788 minrwrk = max( 7, lrwqp3, lrwsvdj, lrwcon )
790 minrwrk = max( 7, lrwqp3, lrwsvdj )
793 IF ( rowpiv .OR. l2tran ) miniwrk = miniwrk + m
794 ELSE IF ( lsvec .AND. (.NOT.rsvec) )
THEN
798 minwrk = n + max( lwqp3,lwcon,n+lwqrf,lwsvdj,lwunmqrm )
800 minwrk = n + max( lwqp3, n+lwqrf, lwsvdj, lwunmqrm )
803 CALL zgesvj(
'L',
'U',
'N', n,n, u, ldu, sva, n, a,
804 $ lda, cdummy, -1, rdummy, -1, ierr )
805 lwrk_zgesvj = int( cdummy(1) )
806 CALL zunmqr(
'L',
'N', m, n, n, a, lda, cdummy, u,
807 $ ldu, cdummy, -1, ierr )
808 lwrk_zunmqrm = int( cdummy(1) )
810 optwrk = n + max( lwrk_zgeqp3, lwcon, n+lwrk_zgeqrf,
811 $ lwrk_zgesvj, lwrk_zunmqrm )
813 optwrk = n + max( lwrk_zgeqp3, n+lwrk_zgeqrf,
814 $ lwrk_zgesvj, lwrk_zunmqrm )
817 IF ( l2tran .OR. rowpiv )
THEN
819 minrwrk = max( 7, 2*m, lrwqp3, lrwsvdj, lrwcon )
821 minrwrk = max( 7, 2*m, lrwqp3, lrwsvdj )
825 minrwrk = max( 7, lrwqp3, lrwsvdj, lrwcon )
827 minrwrk = max( 7, lrwqp3, lrwsvdj )
830 IF ( rowpiv .OR. l2tran ) miniwrk = miniwrk + m
834 IF ( .NOT. jracc )
THEN
836 minwrk = max( n+lwqp3, n+lwcon, 2*n+n**2+lwcon,
837 $ 2*n+lwqrf, 2*n+lwqp3,
838 $ 2*n+n**2+n+lwlqf, 2*n+n**2+n+n**2+lwcon,
839 $ 2*n+n**2+n+lwsvdj, 2*n+n**2+n+lwsvdjv,
840 $ 2*n+n**2+n+lwunmqr,2*n+n**2+n+lwunmlq,
841 $ n+n**2+lwsvdj, n+lwunmqrm )
843 minwrk = max( n+lwqp3, 2*n+n**2+lwcon,
844 $ 2*n+lwqrf, 2*n+lwqp3,
845 $ 2*n+n**2+n+lwlqf, 2*n+n**2+n+n**2+lwcon,
846 $ 2*n+n**2+n+lwsvdj, 2*n+n**2+n+lwsvdjv,
847 $ 2*n+n**2+n+lwunmqr,2*n+n**2+n+lwunmlq,
848 $ n+n**2+lwsvdj, n+lwunmqrm )
850 miniwrk = miniwrk + n
851 IF ( rowpiv .OR. l2tran ) miniwrk = miniwrk + m
854 minwrk = max( n+lwqp3, n+lwcon, 2*n+lwqrf,
855 $ 2*n+n**2+lwsvdjv, 2*n+n**2+n+lwunmqr,
858 minwrk = max( n+lwqp3, 2*n+lwqrf,
859 $ 2*n+n**2+lwsvdjv, 2*n+n**2+n+lwunmqr,
862 IF ( rowpiv .OR. l2tran ) miniwrk = miniwrk + m
865 CALL zunmqr(
'L',
'N', m, n, n, a, lda, cdummy, u,
866 $ ldu, cdummy, -1, ierr )
867 lwrk_zunmqrm = int( cdummy(1) )
868 CALL zunmqr(
'L',
'N', n, n, n, a, lda, cdummy, u,
869 $ ldu, cdummy, -1, ierr )
870 lwrk_zunmqr = int( cdummy(1) )
871 IF ( .NOT. jracc )
THEN
872 CALL zgeqp3( n,n, a, lda, iwork, cdummy,cdummy,
875 lwrk_zgeqp3n = int( cdummy(1) )
876 CALL zgesvj(
'L',
'U',
'N', n, n, u, ldu, sva,
877 $ n, v, ldv, cdummy, -1, rdummy, -1, ierr )
878 lwrk_zgesvj = int( cdummy(1) )
879 CALL zgesvj(
'U',
'U',
'N', n, n, u, ldu, sva,
880 $ n, v, ldv, cdummy, -1, rdummy, -1, ierr )
881 lwrk_zgesvju = int( cdummy(1) )
882 CALL zgesvj(
'L',
'U',
'V', n, n, u, ldu, sva,
883 $ n, v, ldv, cdummy, -1, rdummy, -1, ierr )
884 lwrk_zgesvjv = int( cdummy(1) )
885 CALL zunmlq(
'L',
'C', n, n, n, a, lda, cdummy,
886 $ v, ldv, cdummy, -1, ierr )
887 lwrk_zunmlq = int( cdummy(1) )
889 optwrk = max( n+lwrk_zgeqp3, n+lwcon,
890 $ 2*n+n**2+lwcon, 2*n+lwrk_zgeqrf,
892 $ 2*n+n**2+n+lwrk_zgelqf,
893 $ 2*n+n**2+n+n**2+lwcon,
894 $ 2*n+n**2+n+lwrk_zgesvj,
895 $ 2*n+n**2+n+lwrk_zgesvjv,
896 $ 2*n+n**2+n+lwrk_zunmqr,
897 $ 2*n+n**2+n+lwrk_zunmlq,
898 $ n+n**2+lwrk_zgesvju,
901 optwrk = max( n+lwrk_zgeqp3,
902 $ 2*n+n**2+lwcon, 2*n+lwrk_zgeqrf,
904 $ 2*n+n**2+n+lwrk_zgelqf,
905 $ 2*n+n**2+n+n**2+lwcon,
906 $ 2*n+n**2+n+lwrk_zgesvj,
907 $ 2*n+n**2+n+lwrk_zgesvjv,
908 $ 2*n+n**2+n+lwrk_zunmqr,
909 $ 2*n+n**2+n+lwrk_zunmlq,
910 $ n+n**2+lwrk_zgesvju,
914 CALL zgesvj(
'L',
'U',
'V', n, n, u, ldu, sva,
915 $ n, v, ldv, cdummy, -1, rdummy, -1, ierr )
916 lwrk_zgesvjv = int( cdummy(1) )
917 CALL zunmqr(
'L',
'N', n, n, n, cdummy, n,
919 $ v, ldv, cdummy, -1, ierr )
920 lwrk_zunmqr = int( cdummy(1) )
921 CALL zunmqr(
'L',
'N', m, n, n, a, lda, cdummy,
923 $ ldu, cdummy, -1, ierr )
924 lwrk_zunmqrm = int( cdummy(1) )
926 optwrk = max( n+lwrk_zgeqp3, n+lwcon,
927 $ 2*n+lwrk_zgeqrf, 2*n+n**2,
928 $ 2*n+n**2+lwrk_zgesvjv,
929 $ 2*n+n**2+n+lwrk_zunmqr,n+lwrk_zunmqrm )
931 optwrk = max( n+lwrk_zgeqp3, 2*n+lwrk_zgeqrf,
932 $ 2*n+n**2, 2*n+n**2+lwrk_zgesvjv,
933 $ 2*n+n**2+n+lwrk_zunmqr,
938 IF ( l2tran .OR. rowpiv )
THEN
939 minrwrk = max( 7, 2*m, lrwqp3, lrwsvdj, lrwcon )
941 minrwrk = max( 7, lrwqp3, lrwsvdj, lrwcon )
944 minwrk = max( 2, minwrk )
945 optwrk = max( minwrk, optwrk )
946 IF ( lwork .LT. minwrk .AND. (.NOT.lquery) ) info = - 17
947 IF ( lrwork .LT. minrwrk .AND. (.NOT.lquery) ) info = - 19
950 IF ( info .NE. 0 )
THEN
952 CALL xerbla(
'ZGEJSV', - info )
954 ELSE IF ( lquery )
THEN
958 iwork(1) = max( 4, miniwrk )
964 IF ( ( m .EQ. 0 ) .OR. ( n .EQ. 0 ) )
THEN
974 IF ( lsame( jobu,
'F' ) ) n1 = m
981 epsln = dlamch(
'Epsilon')
982 sfmin = dlamch(
'SafeMinimum')
983 small = sfmin / epsln
993 scalem = one / sqrt(dble(m)*dble(n))
999 CALL zlassq( m, a(1,p), 1, aapp, aaqq )
1000 IF ( aapp .GT. big )
THEN
1002 CALL xerbla(
'ZGEJSV', -info )
1006 IF ( ( aapp .LT. (big / aaqq) ) .AND. noscal )
THEN
1007 sva(p) = aapp * aaqq
1010 sva(p) = aapp * ( aaqq * scalem )
1013 CALL dscal( p-1, scalem, sva, 1 )
1018 IF ( noscal ) scalem = one
1023 aapp = max( aapp, sva(p) )
1024 IF ( sva(p) .NE. zero ) aaqq = min( aaqq, sva(p) )
1029 IF ( aapp .EQ. zero )
THEN
1030 IF ( lsvec )
CALL zlaset(
'G', m, n1, czero, cone, u, ldu )
1031 IF ( rsvec )
CALL zlaset(
'G', n, n, czero, cone, v, ldv )
1034 IF ( errest ) rwork(3) = one
1035 IF ( lsvec .AND. rsvec )
THEN
1055 IF ( aaqq .LE. sfmin )
THEN
1063 IF ( n .EQ. 1 )
THEN
1066 CALL zlascl(
'G',0,0,sva(1),scalem, m,1,a(1,1),lda,ierr )
1067 CALL zlacpy(
'A', m, 1, a, lda, u, ldu )
1069 IF ( n1 .NE. n )
THEN
1070 CALL zgeqrf( m, n, u,ldu, cwork, cwork(n+1),lwork-n,
1072 CALL zungqr( m,n1,1, u,ldu,cwork,cwork(n+1),lwork-n,
1074 CALL zcopy( m, a(1,1), 1, u(1,1), 1 )
1080 IF ( sva(1) .LT. (big*scalem) )
THEN
1081 sva(1) = sva(1) / scalem
1084 rwork(1) = one / scalem
1086 IF ( sva(1) .NE. zero )
THEN
1088 IF ( ( sva(1) / scalem) .GE. sfmin )
THEN
1099 IF ( errest ) rwork(3) = one
1100 IF ( lsvec .AND. rsvec )
THEN
1116 IF ( rowpiv .OR. l2tran )
THEN
1127 CALL zlassq( n, a(p,1), lda, xsc, temp1 )
1130 rwork(m+p) = xsc * scalem
1131 rwork(p) = xsc * (scalem*sqrt(temp1))
1132 aatmax = max( aatmax, rwork(p) )
1133 IF (rwork(p) .NE. zero)
1134 $ aatmin = min(aatmin,rwork(p))
1138 rwork(m+p) = scalem*abs( a(p,izamax(n,a(p,1),lda)) )
1139 aatmax = max( aatmax, rwork(m+p) )
1140 aatmin = min( aatmin, rwork(m+p) )
1159 CALL dlassq( n, sva, 1, xsc, temp1 )
1164 big1 = ( ( sva(p) / xsc )**2 ) * temp1
1165 IF ( big1 .NE. zero ) entra = entra + big1 * dlog(big1)
1167 entra = - entra / dlog(dble(n))
1177 big1 = ( ( rwork(p) / xsc )**2 ) * temp1
1178 IF ( big1 .NE. zero ) entrat = entrat + big1 * dlog(big1)
1180 entrat = - entrat / dlog(dble(m))
1185 transp = ( entrat .LT. entra )
1192 DO 1115 p = 1, n - 1
1193 a(p,p) = conjg(a(p,p))
1194 DO 1116 q = p + 1, n
1195 ctemp = conjg(a(q,p))
1196 a(q,p) = conjg(a(p,q))
1200 a(n,n) = conjg(a(n,n))
1236 temp1 = sqrt( big / dble(n) )
1239 CALL dlascl(
'G', 0, 0, aapp, temp1, n, 1, sva, n, ierr )
1240 IF ( aaqq .GT. (aapp * sfmin) )
THEN
1241 aaqq = ( aaqq / aapp ) * temp1
1243 aaqq = ( aaqq * temp1 ) / aapp
1245 temp1 = temp1 * scalem
1246 CALL zlascl(
'G', 0, 0, aapp, temp1, m, n, a, lda, ierr )
1270 IF ( ( aaqq.LT.sqrt(sfmin) ) .AND. lsvec .AND. rsvec )
THEN
1275 IF ( aaqq .LT. xsc )
THEN
1277 IF ( sva(p) .LT. xsc )
THEN
1278 CALL zlaset(
'A', m, 1, czero, czero, a(1,p), lda )
1292 IF ( ( lsvec .AND. rsvec ) .AND. .NOT.( jracc ) )
THEN
1297 DO 1952 p = 1, m - 1
1298 q = idamax( m-p+1, rwork(m+p), 1 ) + p - 1
1300 IF ( p .NE. q )
THEN
1302 rwork(m+p) = rwork(m+q)
1306 CALL zlaswp( n, a, lda, 1, m-1, iwork(iwoff+1), 1 )
1328 CALL zgeqp3( m, n, a, lda, iwork, cwork, cwork(n+1), lwork-n,
1345 temp1 = sqrt(dble(n))*epsln
1347 IF ( abs(a(p,p)) .GE. (temp1*abs(a(1,1))) )
THEN
1354 ELSE IF ( l2rank )
THEN
1360 IF ( ( abs(a(p,p)) .LT. (epsln*abs(a(p-1,p-1))) ) .OR.
1361 $ ( abs(a(p,p)) .LT. small ) .OR.
1362 $ ( l2kill .AND. (abs(a(p,p)) .LT. temp1) ) )
GO TO 3402
1377 IF ( ( abs(a(p,p)) .LT. small ) .OR.
1378 $ ( l2kill .AND. (abs(a(p,p)) .LT. temp1) ) )
GO TO 3302
1386 IF ( nr .EQ. n )
THEN
1389 temp1 = abs(a(p,p)) / sva(iwork(p))
1390 maxprj = min( maxprj, temp1 )
1392 IF ( maxprj**2 .GE. one - dble(n)*epsln ) almort = .true.
1401 IF ( n .EQ. nr )
THEN
1404 CALL zlacpy(
'U', n, n, a, lda, v, ldv )
1406 temp1 = sva(iwork(p))
1407 CALL zdscal( p, one/temp1, v(1,p), 1 )
1410 CALL zpocon(
'U', n, v, ldv, one, temp1,
1411 $ cwork(n+1), rwork, ierr )
1413 CALL zpocon(
'U', n, v, ldv, one, temp1,
1414 $ cwork, rwork, ierr )
1417 ELSE IF ( lsvec )
THEN
1419 CALL zlacpy(
'U', n, n, a, lda, u, ldu )
1421 temp1 = sva(iwork(p))
1422 CALL zdscal( p, one/temp1, u(1,p), 1 )
1424 CALL zpocon(
'U', n, u, ldu, one, temp1,
1425 $ cwork(n+1), rwork, ierr )
1427 CALL zlacpy(
'U', n, n, a, lda, cwork, n )
1432 temp1 = sva(iwork(p))
1434 CALL zdscal( p, one/temp1, cwork((p-1)*n+1), 1 )
1439 CALL zpocon(
'U', n, cwork, n, one, temp1,
1440 $ cwork(n*n+1), rwork, ierr )
1443 IF ( temp1 .NE. zero )
THEN
1444 sconda = one / sqrt(temp1)
1455 l2pert = l2pert .AND. ( abs( a(1,1)/a(nr,nr) ) .GT. sqrt(big1) )
1460 IF ( .NOT. ( rsvec .OR. lsvec ) )
THEN
1465 DO 1946 p = 1, min( n-1, nr )
1466 CALL zcopy( n-p, a(p,p+1), lda, a(p+1,p), 1 )
1467 CALL zlacgv( n-p+1, a(p,p), 1 )
1469 IF ( nr .EQ. n ) a(n,n) = conjg(a(n,n))
1483 IF ( .NOT. almort )
THEN
1487 xsc = epsln / dble(n)
1489 ctemp = dcmplx(xsc*abs(a(q,q)),zero)
1491 IF ( ( (p.GT.q) .AND. (abs(a(p,q)).LE.temp1) )
1492 $ .OR. ( p .LT. q ) )
1498 CALL zlaset(
'U', nr-1,nr-1, czero,czero, a(1,2),lda )
1503 CALL zgeqrf( n,nr, a,lda, cwork, cwork(n+1),lwork-n,
1507 DO 1948 p = 1, nr - 1
1508 CALL zcopy( nr-p, a(p,p+1), lda, a(p+1,p), 1 )
1509 CALL zlacgv( nr-p+1, a(p,p), 1 )
1520 xsc = epsln / dble(n)
1522 ctemp = dcmplx(xsc*abs(a(q,q)),zero)
1524 IF ( ( (p.GT.q) .AND. (abs(a(p,q)).LE.temp1) )
1525 $ .OR. ( p .LT. q ) )
1531 CALL zlaset(
'U', nr-1, nr-1, czero, czero, a(1,2),
1539 CALL zgesvj(
'L',
'N',
'N', nr, nr, a, lda, sva,
1540 $ n, v, ldv, cwork, lwork, rwork, lrwork, info )
1543 numrank = nint(rwork(2))
1546 ELSE IF ( ( rsvec .AND. ( .NOT. lsvec ) .AND. ( .NOT. jracc ) )
1548 $ ( jracc .AND. ( .NOT. lsvec ) .AND. ( nr .NE. n ) ) )
THEN
1556 CALL zcopy( n-p+1, a(p,p), lda, v(p,p), 1 )
1557 CALL zlacgv( n-p+1, v(p,p), 1 )
1559 CALL zlaset(
'U', nr-1,nr-1, czero, czero, v(1,2), ldv )
1561 CALL zgesvj(
'L',
'U',
'N', n, nr, v, ldv, sva, nr, a, lda,
1562 $ cwork, lwork, rwork, lrwork, info )
1564 numrank = nint(rwork(2))
1571 CALL zlaset(
'L', nr-1,nr-1, czero, czero, a(2,1), lda )
1572 CALL zgelqf( nr,n, a, lda, cwork, cwork(n+1), lwork-n,
1574 CALL zlacpy(
'L', nr, nr, a, lda, v, ldv )
1575 CALL zlaset(
'U', nr-1,nr-1, czero, czero, v(1,2), ldv )
1576 CALL zgeqrf( nr, nr, v, ldv, cwork(n+1), cwork(2*n+1),
1579 CALL zcopy( nr-p+1, v(p,p), ldv, v(p,p), 1 )
1580 CALL zlacgv( nr-p+1, v(p,p), 1 )
1582 CALL zlaset(
'U', nr-1, nr-1, czero, czero, v(1,2), ldv)
1584 CALL zgesvj(
'L',
'U',
'N', nr, nr, v,ldv, sva, nr, u,
1585 $ ldu, cwork(n+1), lwork-n, rwork, lrwork, info )
1587 numrank = nint(rwork(2))
1588 IF ( nr .LT. n )
THEN
1589 CALL zlaset(
'A',n-nr, nr, czero,czero, v(nr+1,1),
1591 CALL zlaset(
'A',nr, n-nr, czero,czero, v(1,nr+1),
1593 CALL zlaset(
'A',n-nr,n-nr,czero,cone, v(nr+1,nr+1),
1597 CALL zunmlq(
'L',
'C', n, n, nr, a, lda, cwork,
1598 $ v, ldv, cwork(n+1), lwork-n, ierr )
1606 CALL zlapmr( .false., n, n, v, ldv, iwork )
1609 CALL zlacpy(
'A', n, n, v, ldv, u, ldu )
1612 ELSE IF ( jracc .AND. (.NOT. lsvec) .AND. ( nr.EQ. n ) )
THEN
1614 CALL zlaset(
'L', n-1,n-1, czero, czero, a(2,1), lda )
1616 CALL zgesvj(
'U',
'N',
'V', n, n, a, lda, sva, n, v, ldv,
1617 $ cwork, lwork, rwork, lrwork, info )
1619 numrank = nint(rwork(2))
1620 CALL zlapmr( .false., n, n, v, ldv, iwork )
1622 ELSE IF ( lsvec .AND. ( .NOT. rsvec ) )
THEN
1629 CALL zcopy( n-p+1, a(p,p), lda, u(p,p), 1 )
1630 CALL zlacgv( n-p+1, u(p,p), 1 )
1632 CALL zlaset(
'U', nr-1, nr-1, czero, czero, u(1,2), ldu )
1634 CALL zgeqrf( n, nr, u, ldu, cwork(n+1), cwork(2*n+1),
1637 DO 1967 p = 1, nr - 1
1638 CALL zcopy( nr-p, u(p,p+1), ldu, u(p+1,p), 1 )
1639 CALL zlacgv( n-p+1, u(p,p), 1 )
1641 CALL zlaset(
'U', nr-1, nr-1, czero, czero, u(1,2), ldu )
1643 CALL zgesvj(
'L',
'U',
'N', nr,nr, u, ldu, sva, nr, a,
1644 $ lda, cwork(n+1), lwork-n, rwork, lrwork, info )
1646 numrank = nint(rwork(2))
1648 IF ( nr .LT. m )
THEN
1649 CALL zlaset(
'A', m-nr, nr,czero, czero, u(nr+1,1),
1651 IF ( nr .LT. n1 )
THEN
1652 CALL zlaset(
'A',nr, n1-nr, czero, czero, u(1,nr+1),
1654 CALL zlaset(
'A',m-nr,n1-nr,czero,cone,u(nr+1,nr+1),
1659 CALL zunmqr(
'L',
'N', m, n1, n, a, lda, cwork, u,
1660 $ ldu, cwork(n+1), lwork-n, ierr )
1663 $
CALL zlaswp( n1, u, ldu, 1, m-1, iwork(iwoff+1), -1 )
1666 xsc = one / dznrm2( m, u(1,p), 1 )
1667 CALL zdscal( m, xsc, u(1,p), 1 )
1671 CALL zlacpy(
'A', n, n, u, ldu, v, ldv )
1678 IF ( .NOT. jracc )
THEN
1680 IF ( .NOT. almort )
THEN
1690 CALL zcopy( n-p+1, a(p,p), lda, v(p,p), 1 )
1691 CALL zlacgv( n-p+1, v(p,p), 1 )
1709 ctemp = dcmplx(xsc*abs( v(q,q) ),zero)
1711 IF ( ( p .GT. q ) .AND. ( abs(v(p,q)) .LE. temp1 )
1712 $ .OR. ( p .LT. q ) )
1715 IF ( p .LT. q ) v(p,q) = - v(p,q)
1719 CALL zlaset(
'U', nr-1, nr-1, czero, czero, v(1,2),
1727 CALL zlacpy(
'L', nr, nr, v, ldv, cwork(2*n+1), nr )
1729 temp1 = dznrm2(nr-p+1,cwork(2*n+(p-1)*nr+p),1)
1730 CALL zdscal(nr-p+1,one/temp1,cwork(2*n+(p-1)*nr+p),1)
1732 CALL zpocon(
'L',nr,cwork(2*n+1),nr,one,temp1,
1733 $ cwork(2*n+nr*nr+1),rwork,ierr)
1734 condr1 = one / sqrt(temp1)
1740 cond_ok = sqrt(sqrt(dble(nr)))
1743 IF ( condr1 .LT. cond_ok )
THEN
1748 CALL zgeqrf( n, nr, v, ldv, cwork(n+1), cwork(2*n+1),
1752 xsc = sqrt(small)/epsln
1754 DO 3958 q = 1, p - 1
1755 ctemp=dcmplx(xsc*min(abs(v(p,p)),abs(v(q,q))),
1757 IF ( abs(v(q,p)) .LE. temp1 )
1765 $
CALL zlacpy(
'A', n, nr, v, ldv, cwork(2*n+1), n )
1769 DO 1969 p = 1, nr - 1
1770 CALL zcopy( nr-p, v(p,p+1), ldv, v(p+1,p), 1 )
1771 CALL zlacgv(nr-p+1, v(p,p), 1 )
1773 v(nr,nr)=conjg(v(nr,nr))
1790 CALL zgeqp3( n, nr, v, ldv, iwork(n+1), cwork(n+1),
1791 $ cwork(2*n+1), lwork-2*n, rwork, ierr )
1797 DO 3968 q = 1, p - 1
1798 ctemp=dcmplx(xsc*min(abs(v(p,p)),abs(v(q,q))),
1800 IF ( abs(v(q,p)) .LE. temp1 )
1807 CALL zlacpy(
'A', n, nr, v, ldv, cwork(2*n+1), n )
1812 DO 8971 q = 1, p - 1
1813 ctemp=dcmplx(xsc*min(abs(v(p,p)),abs(v(q,q))),
1820 CALL zlaset(
'L',nr-1,nr-1,czero,czero,v(2,1),ldv )
1823 CALL zgelqf( nr, nr, v, ldv, cwork(2*n+n*nr+1),
1824 $ cwork(2*n+n*nr+nr+1), lwork-2*n-n*nr-nr, ierr )
1826 CALL zlacpy(
'L',nr,nr,v,ldv,cwork(2*n+n*nr+nr+1),nr )
1828 temp1 = dznrm2( p, cwork(2*n+n*nr+nr+p), nr )
1829 CALL zdscal( p, one/temp1, cwork(2*n+n*nr+nr+p),
1832 CALL zpocon(
'L',nr,cwork(2*n+n*nr+nr+1),nr,one,temp1,
1833 $ cwork(2*n+n*nr+nr+nr*nr+1),rwork,ierr )
1834 condr2 = one / sqrt(temp1)
1837 IF ( condr2 .GE. cond_ok )
THEN
1842 CALL zlacpy(
'U', nr, nr, v, ldv, cwork(2*n+1), n )
1852 ctemp = xsc * v(q,q)
1853 DO 4969 p = 1, q - 1
1859 CALL zlaset(
'U', nr-1,nr-1, czero,czero, v(1,2),
1869 IF ( condr1 .LT. cond_ok )
THEN
1871 CALL zgesvj(
'L',
'U',
'N',nr,nr,v,ldv,sva,nr,u, ldu,
1872 $ cwork(2*n+n*nr+nr+1),lwork-2*n-n*nr-nr,rwork,
1875 numrank = nint(rwork(2))
1877 CALL zcopy( nr, v(1,p), 1, u(1,p), 1 )
1878 CALL zdscal( nr, sva(p), v(1,p), 1 )
1883 IF ( nr .EQ. n )
THEN
1888 CALL ztrsm(
'L',
'U',
'N',
'N', nr,nr,cone, a,lda, v,
1895 CALL ztrsm(
'L',
'U',
'C',
'N',nr,nr,cone,cwork(2*n+1),
1897 IF ( nr .LT. n )
THEN
1898 CALL zlaset(
'A',n-nr,nr,czero,czero,v(nr+1,1),ldv)
1899 CALL zlaset(
'A',nr,n-nr,czero,czero,v(1,nr+1),ldv)
1900 CALL zlaset(
'A',n-nr,n-nr,czero,cone,v(nr+1,nr+1),
1903 CALL zunmqr(
'L',
'N',n,n,nr,cwork(2*n+1),n,
1905 $ v,ldv,cwork(2*n+n*nr+nr+1),lwork-2*n-n*nr-nr,ierr)
1908 ELSE IF ( condr2 .LT. cond_ok )
THEN
1914 CALL zgesvj(
'L',
'U',
'N', nr, nr, v, ldv, sva, nr,
1916 $ ldu, cwork(2*n+n*nr+nr+1), lwork-2*n-n*nr-nr,
1917 $ rwork, lrwork, info )
1919 numrank = nint(rwork(2))
1921 CALL zcopy( nr, v(1,p), 1, u(1,p), 1 )
1922 CALL zdscal( nr, sva(p), u(1,p), 1 )
1924 CALL ztrsm(
'L',
'U',
'N',
'N',nr,nr,cone,cwork(2*n+1),n,
1929 cwork(2*n+n*nr+nr+iwork(n+p)) = u(p,q)
1932 u(p,q) = cwork(2*n+n*nr+nr+p)
1935 IF ( nr .LT. n )
THEN
1936 CALL zlaset(
'A',n-nr,nr,czero,czero,v(nr+1,1),
1938 CALL zlaset(
'A',nr,n-nr,czero,czero,v(1,nr+1),
1940 CALL zlaset(
'A',n-nr,n-nr,czero,cone,v(nr+1,nr+1),
1943 CALL zunmqr(
'L',
'N',n,n,nr,cwork(2*n+1),n,cwork(n+1),
1944 $ v,ldv,cwork(2*n+n*nr+nr+1),lwork-2*n-n*nr-nr,ierr )
1957 CALL zgesvj(
'L',
'U',
'V', nr, nr, v, ldv, sva, nr,
1959 $ ldu, cwork(2*n+n*nr+nr+1), lwork-2*n-n*nr-nr,
1960 $ rwork, lrwork, info )
1962 numrank = nint(rwork(2))
1963 IF ( nr .LT. n )
THEN
1964 CALL zlaset(
'A',n-nr,nr,czero,czero,v(nr+1,1),
1966 CALL zlaset(
'A',nr,n-nr,czero,czero,v(1,nr+1),
1968 CALL zlaset(
'A',n-nr,n-nr,czero,cone,v(nr+1,nr+1),
1971 CALL zunmqr(
'L',
'N',n,n,nr,cwork(2*n+1),n,cwork(n+1),
1972 $ v,ldv,cwork(2*n+n*nr+nr+1),lwork-2*n-n*nr-nr,ierr )
1974 CALL zunmlq(
'L',
'C', nr, nr, nr, cwork(2*n+1), n,
1975 $ cwork(2*n+n*nr+1), u, ldu, cwork(2*n+n*nr+nr+1),
1976 $ lwork-2*n-n*nr-nr, ierr )
1979 cwork(2*n+n*nr+nr+iwork(n+p)) = u(p,q)
1982 u(p,q) = cwork(2*n+n*nr+nr+p)
1992 temp1 = sqrt(dble(n)) * epsln
1995 cwork(2*n+n*nr+nr+iwork(p)) = v(p,q)
1998 v(p,q) = cwork(2*n+n*nr+nr+p)
2000 xsc = one / dznrm2( n, v(1,q), 1 )
2001 IF ( (xsc .LT. (one-temp1)) .OR. (xsc .GT. (one+temp1)) )
2002 $
CALL zdscal( n, xsc, v(1,q), 1 )
2006 IF ( nr .LT. m )
THEN
2007 CALL zlaset(
'A', m-nr, nr, czero, czero, u(nr+1,1),
2009 IF ( nr .LT. n1 )
THEN
2010 CALL zlaset(
'A',nr,n1-nr,czero,czero,u(1,nr+1),ldu)
2011 CALL zlaset(
'A',m-nr,n1-nr,czero,cone,
2019 CALL zunmqr(
'L',
'N', m, n1, n, a, lda, cwork, u,
2020 $ ldu, cwork(n+1), lwork-n, ierr )
2023 temp1 = sqrt(dble(m)) * epsln
2025 xsc = one / dznrm2( m, u(1,p), 1 )
2026 IF ( (xsc .LT. (one-temp1)) .OR. (xsc .GT. (one+temp1)) )
2027 $
CALL zdscal( m, xsc, u(1,p), 1 )
2034 $
CALL zlaswp( n1, u, ldu, 1, m-1, iwork(iwoff+1), -1 )
2041 CALL zlacpy(
'U', n, n, a, lda, cwork(n+1), n )
2045 ctemp = xsc * cwork( n + (p-1)*n + p )
2046 DO 5971 q = 1, p - 1
2049 cwork(n+(q-1)*n+p)=-ctemp
2053 CALL zlaset(
'L',n-1,n-1,czero,czero,cwork(n+2),n )
2056 CALL zgesvj(
'U',
'U',
'N', n, n, cwork(n+1), n, sva,
2057 $ n, u, ldu, cwork(n+n*n+1), lwork-n-n*n, rwork, lrwork,
2061 numrank = nint(rwork(2))
2063 CALL zcopy( n, cwork(n+(p-1)*n+1), 1, u(1,p), 1 )
2064 CALL zdscal( n, sva(p), cwork(n+(p-1)*n+1), 1 )
2067 CALL ztrsm(
'L',
'U',
'N',
'N', n, n,
2068 $ cone, a, lda, cwork(n+1), n )
2070 CALL zcopy( n, cwork(n+p), n, v(iwork(p),1), ldv )
2072 temp1 = sqrt(dble(n))*epsln
2074 xsc = one / dznrm2( n, v(1,p), 1 )
2075 IF ( (xsc .LT. (one-temp1)) .OR. (xsc .GT. (one+temp1)) )
2076 $
CALL zdscal( n, xsc, v(1,p), 1 )
2081 IF ( n .LT. m )
THEN
2082 CALL zlaset(
'A', m-n, n, czero, czero, u(n+1,1),
2084 IF ( n .LT. n1 )
THEN
2085 CALL zlaset(
'A',n, n1-n, czero, czero, u(1,n+1),
2087 CALL zlaset(
'A',m-n,n1-n, czero, cone,u(n+1,n+1),
2091 CALL zunmqr(
'L',
'N', m, n1, n, a, lda, cwork, u,
2092 $ ldu, cwork(n+1), lwork-n, ierr )
2093 temp1 = sqrt(dble(m))*epsln
2095 xsc = one / dznrm2( m, u(1,p), 1 )
2096 IF ( (xsc .LT. (one-temp1)) .OR. (xsc .GT. (one+temp1)) )
2097 $
CALL zdscal( m, xsc, u(1,p), 1 )
2101 $
CALL zlaswp( n1, u, ldu, 1, m-1, iwork(iwoff+1), -1 )
2121 CALL zcopy( n-p+1, a(p,p), lda, v(p,p), 1 )
2122 CALL zlacgv( n-p+1, v(p,p), 1 )
2126 xsc = sqrt(small/epsln)
2128 ctemp = dcmplx(xsc*abs( v(q,q) ),zero)
2130 IF ( ( p .GT. q ) .AND. ( abs(v(p,q)) .LE. temp1 )
2131 $ .OR. ( p .LT. q ) )
2134 IF ( p .LT. q ) v(p,q) = - v(p,q)
2138 CALL zlaset(
'U', nr-1, nr-1, czero, czero, v(1,2), ldv )
2141 CALL zgeqrf( n, nr, v, ldv, cwork(n+1), cwork(2*n+1),
2143 CALL zlacpy(
'L', n, nr, v, ldv, cwork(2*n+1), n )
2146 CALL zcopy( nr-p+1, v(p,p), ldv, u(p,p), 1 )
2147 CALL zlacgv( nr-p+1, u(p,p), 1 )
2151 xsc = sqrt(small/epsln)
2153 DO 9971 p = 1, q - 1
2154 ctemp = dcmplx(xsc * min(abs(u(p,p)),abs(u(q,q))),
2161 CALL zlaset(
'U', nr-1, nr-1, czero, czero, u(1,2), ldu )
2164 CALL zgesvj(
'L',
'U',
'V', nr, nr, u, ldu, sva,
2165 $ n, v, ldv, cwork(2*n+n*nr+1), lwork-2*n-n*nr,
2166 $ rwork, lrwork, info )
2168 numrank = nint(rwork(2))
2170 IF ( nr .LT. n )
THEN
2171 CALL zlaset(
'A',n-nr,nr,czero,czero,v(nr+1,1),ldv )
2172 CALL zlaset(
'A',nr,n-nr,czero,czero,v(1,nr+1),ldv )
2173 CALL zlaset(
'A',n-nr,n-nr,czero,cone,v(nr+1,nr+1),ldv )
2176 CALL zunmqr(
'L',
'N',n,n,nr,cwork(2*n+1),n,cwork(n+1),
2177 $ v,ldv,cwork(2*n+n*nr+nr+1),lwork-2*n-n*nr-nr,ierr )
2183 temp1 = sqrt(dble(n)) * epsln
2186 cwork(2*n+n*nr+nr+iwork(p)) = v(p,q)
2189 v(p,q) = cwork(2*n+n*nr+nr+p)
2191 xsc = one / dznrm2( n, v(1,q), 1 )
2192 IF ( (xsc .LT. (one-temp1)) .OR. (xsc .GT. (one+temp1)) )
2193 $
CALL zdscal( n, xsc, v(1,q), 1 )
2199 IF ( nr .LT. m )
THEN
2200 CALL zlaset(
'A', m-nr, nr, czero, czero, u(nr+1,1),
2202 IF ( nr .LT. n1 )
THEN
2203 CALL zlaset(
'A',nr, n1-nr, czero, czero, u(1,nr+1),
2205 CALL zlaset(
'A',m-nr,n1-nr, czero, cone,u(nr+1,nr+1),
2210 CALL zunmqr(
'L',
'N', m, n1, n, a, lda, cwork, u,
2211 $ ldu, cwork(n+1), lwork-n, ierr )
2214 $
CALL zlaswp( n1, u, ldu, 1, m-1, iwork(iwoff+1), -1 )
2221 CALL zswap( n, u(1,p), 1, v(1,p), 1 )
2230 IF ( uscal2 .LE. (big/sva(1))*uscal1 )
THEN
2231 CALL dlascl(
'G', 0, 0, uscal1, uscal2, nr, 1, sva, n,
2237 IF ( nr .LT. n )
THEN
2243 rwork(1) = uscal2 * scalem
2245 IF ( errest ) rwork(3) = sconda
2246 IF ( lsvec .AND. rsvec )
THEN