001:       SUBROUTINE SLASD1( NL, NR, SQRE, D, ALPHA, BETA, U, LDU, VT, LDVT,
002:      $                   IDXQ, IWORK, WORK, INFO )
003: *
004: *  -- LAPACK auxiliary routine (version 3.2) --
005: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
006: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
007: *     November 2006
008: *
009: *     .. Scalar Arguments ..
010:       INTEGER            INFO, LDU, LDVT, NL, NR, SQRE
011:       REAL               ALPHA, BETA
012: *     ..
013: *     .. Array Arguments ..
014:       INTEGER            IDXQ( * ), IWORK( * )
015:       REAL               D( * ), U( LDU, * ), VT( LDVT, * ), WORK( * )
016: *     ..
017: *
018: *  Purpose
019: *  =======
020: *
021: *  SLASD1 computes the SVD of an upper bidiagonal N-by-M matrix B,
022: *  where N = NL + NR + 1 and M = N + SQRE. SLASD1 is called from SLASD0.
023: *
024: *  A related subroutine SLASD7 handles the case in which the singular
025: *  values (and the singular vectors in factored form) are desired.
026: *
027: *  SLASD1 computes the SVD as follows:
028: *
029: *                ( D1(in)  0    0     0 )
030: *    B = U(in) * (   Z1'   a   Z2'    b ) * VT(in)
031: *                (   0     0   D2(in) 0 )
032: *
033: *      = U(out) * ( D(out) 0) * VT(out)
034: *
035: *  where Z' = (Z1' a Z2' b) = u' VT', and u is a vector of dimension M
036: *  with ALPHA and BETA in the NL+1 and NL+2 th entries and zeros
037: *  elsewhere; and the entry b is empty if SQRE = 0.
038: *
039: *  The left singular vectors of the original matrix are stored in U, and
040: *  the transpose of the right singular vectors are stored in VT, and the
041: *  singular values are in D.  The algorithm consists of three stages:
042: *
043: *     The first stage consists of deflating the size of the problem
044: *     when there are multiple singular values or when there are zeros in
045: *     the Z vector.  For each such occurence the dimension of the
046: *     secular equation problem is reduced by one.  This stage is
047: *     performed by the routine SLASD2.
048: *
049: *     The second stage consists of calculating the updated
050: *     singular values. This is done by finding the square roots of the
051: *     roots of the secular equation via the routine SLASD4 (as called
052: *     by SLASD3). This routine also calculates the singular vectors of
053: *     the current problem.
054: *
055: *     The final stage consists of computing the updated singular vectors
056: *     directly using the updated singular values.  The singular vectors
057: *     for the current problem are multiplied with the singular vectors
058: *     from the overall problem.
059: *
060: *  Arguments
061: *  =========
062: *
063: *  NL     (input) INTEGER
064: *         The row dimension of the upper block.  NL >= 1.
065: *
066: *  NR     (input) INTEGER
067: *         The row dimension of the lower block.  NR >= 1.
068: *
069: *  SQRE   (input) INTEGER
070: *         = 0: the lower block is an NR-by-NR square matrix.
071: *         = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
072: *
073: *         The bidiagonal matrix has row dimension N = NL + NR + 1,
074: *         and column dimension M = N + SQRE.
075: *
076: *  D      (input/output) REAL array, dimension (NL+NR+1).
077: *         N = NL+NR+1
078: *         On entry D(1:NL,1:NL) contains the singular values of the
079: *         upper block; and D(NL+2:N) contains the singular values of
080: *         the lower block. On exit D(1:N) contains the singular values
081: *         of the modified matrix.
082: *
083: *  ALPHA  (input/output) REAL
084: *         Contains the diagonal element associated with the added row.
085: *
086: *  BETA   (input/output) REAL
087: *         Contains the off-diagonal element associated with the added
088: *         row.
089: *
090: *  U      (input/output) REAL array, dimension (LDU,N)
091: *         On entry U(1:NL, 1:NL) contains the left singular vectors of
092: *         the upper block; U(NL+2:N, NL+2:N) contains the left singular
093: *         vectors of the lower block. On exit U contains the left
094: *         singular vectors of the bidiagonal matrix.
095: *
096: *  LDU    (input) INTEGER
097: *         The leading dimension of the array U.  LDU >= max( 1, N ).
098: *
099: *  VT     (input/output) REAL array, dimension (LDVT,M)
100: *         where M = N + SQRE.
101: *         On entry VT(1:NL+1, 1:NL+1)' contains the right singular
102: *         vectors of the upper block; VT(NL+2:M, NL+2:M)' contains
103: *         the right singular vectors of the lower block. On exit
104: *         VT' contains the right singular vectors of the
105: *         bidiagonal matrix.
106: *
107: *  LDVT   (input) INTEGER
108: *         The leading dimension of the array VT.  LDVT >= max( 1, M ).
109: *
110: *  IDXQ  (output) INTEGER array, dimension (N)
111: *         This contains the permutation which will reintegrate the
112: *         subproblem just solved back into sorted order, i.e.
113: *         D( IDXQ( I = 1, N ) ) will be in ascending order.
114: *
115: *  IWORK  (workspace) INTEGER array, dimension (4*N)
116: *
117: *  WORK   (workspace) REAL array, dimension (3*M**2+2*M)
118: *
119: *  INFO   (output) INTEGER
120: *          = 0:  successful exit.
121: *          < 0:  if INFO = -i, the i-th argument had an illegal value.
122: *          > 0:  if INFO = 1, an singular value did not converge
123: *
124: *  Further Details
125: *  ===============
126: *
127: *  Based on contributions by
128: *     Ming Gu and Huan Ren, Computer Science Division, University of
129: *     California at Berkeley, USA
130: *
131: *  =====================================================================
132: *
133: *     .. Parameters ..
134: *
135:       REAL               ONE, ZERO
136:       PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
137: *     ..
138: *     .. Local Scalars ..
139:       INTEGER            COLTYP, I, IDX, IDXC, IDXP, IQ, ISIGMA, IU2,
140:      $                   IVT2, IZ, K, LDQ, LDU2, LDVT2, M, N, N1, N2
141:       REAL               ORGNRM
142: *     ..
143: *     .. External Subroutines ..
144:       EXTERNAL           SLAMRG, SLASCL, SLASD2, SLASD3, XERBLA
145: *     ..
146: *     .. Intrinsic Functions ..
147:       INTRINSIC          ABS, MAX
148: *     ..
149: *     .. Executable Statements ..
150: *
151: *     Test the input parameters.
152: *
153:       INFO = 0
154: *
155:       IF( NL.LT.1 ) THEN
156:          INFO = -1
157:       ELSE IF( NR.LT.1 ) THEN
158:          INFO = -2
159:       ELSE IF( ( SQRE.LT.0 ) .OR. ( SQRE.GT.1 ) ) THEN
160:          INFO = -3
161:       END IF
162:       IF( INFO.NE.0 ) THEN
163:          CALL XERBLA( 'SLASD1', -INFO )
164:          RETURN
165:       END IF
166: *
167:       N = NL + NR + 1
168:       M = N + SQRE
169: *
170: *     The following values are for bookkeeping purposes only.  They are
171: *     integer pointers which indicate the portion of the workspace
172: *     used by a particular array in SLASD2 and SLASD3.
173: *
174:       LDU2 = N
175:       LDVT2 = M
176: *
177:       IZ = 1
178:       ISIGMA = IZ + M
179:       IU2 = ISIGMA + N
180:       IVT2 = IU2 + LDU2*N
181:       IQ = IVT2 + LDVT2*M
182: *
183:       IDX = 1
184:       IDXC = IDX + N
185:       COLTYP = IDXC + N
186:       IDXP = COLTYP + N
187: *
188: *     Scale.
189: *
190:       ORGNRM = MAX( ABS( ALPHA ), ABS( BETA ) )
191:       D( NL+1 ) = ZERO
192:       DO 10 I = 1, N
193:          IF( ABS( D( I ) ).GT.ORGNRM ) THEN
194:             ORGNRM = ABS( D( I ) )
195:          END IF
196:    10 CONTINUE
197:       CALL SLASCL( 'G', 0, 0, ORGNRM, ONE, N, 1, D, N, INFO )
198:       ALPHA = ALPHA / ORGNRM
199:       BETA = BETA / ORGNRM
200: *
201: *     Deflate singular values.
202: *
203:       CALL SLASD2( NL, NR, SQRE, K, D, WORK( IZ ), ALPHA, BETA, U, LDU,
204:      $             VT, LDVT, WORK( ISIGMA ), WORK( IU2 ), LDU2,
205:      $             WORK( IVT2 ), LDVT2, IWORK( IDXP ), IWORK( IDX ),
206:      $             IWORK( IDXC ), IDXQ, IWORK( COLTYP ), INFO )
207: *
208: *     Solve Secular Equation and update singular vectors.
209: *
210:       LDQ = K
211:       CALL SLASD3( NL, NR, SQRE, K, D, WORK( IQ ), LDQ, WORK( ISIGMA ),
212:      $             U, LDU, WORK( IU2 ), LDU2, VT, LDVT, WORK( IVT2 ),
213:      $             LDVT2, IWORK( IDXC ), IWORK( COLTYP ), WORK( IZ ),
214:      $             INFO )
215:       IF( INFO.NE.0 ) THEN
216:          RETURN
217:       END IF
218: *
219: *     Unscale.
220: *
221:       CALL SLASCL( 'G', 0, 0, ONE, ORGNRM, N, 1, D, N, INFO )
222: *
223: *     Prepare the IDXQ sorting permutation.
224: *
225:       N1 = K
226:       N2 = N - K
227:       CALL SLAMRG( N1, N2, D, 1, -1, IDXQ )
228: *
229:       RETURN
230: *
231: *     End of SLASD1
232: *
233:       END
234: