dgesvj.c
Go to the documentation of this file.
00001 /* dgesvj.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static doublereal c_b17 = 0.;
00019 static doublereal c_b18 = 1.;
00020 static integer c__1 = 1;
00021 static integer c__0 = 0;
00022 static integer c__2 = 2;
00023 
00024 /* Subroutine */ int dgesvj_(char *joba, char *jobu, char *jobv, integer *m, 
00025         integer *n, doublereal *a, integer *lda, doublereal *sva, integer *mv, 
00026          doublereal *v, integer *ldv, doublereal *work, integer *lwork, 
00027         integer *info)
00028 {
00029     /* System generated locals */
00030     integer a_dim1, a_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4, i__5;
00031     doublereal d__1, d__2;
00032 
00033     /* Builtin functions */
00034     double sqrt(doublereal), d_sign(doublereal *, doublereal *);
00035 
00036     /* Local variables */
00037     doublereal bigtheta;
00038     integer pskipped, i__, p, q;
00039     doublereal t;
00040     integer n2, n4;
00041     doublereal rootsfmin;
00042     integer n34;
00043     doublereal cs, sn;
00044     integer ir1, jbc;
00045     doublereal big;
00046     integer kbl, igl, ibr, jgl, nbl;
00047     doublereal tol;
00048     integer mvl;
00049     doublereal aapp, aapq, aaqq;
00050     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *, 
00051             integer *);
00052     doublereal ctol;
00053     integer ierr;
00054     doublereal aapp0;
00055     extern doublereal dnrm2_(integer *, doublereal *, integer *);
00056     doublereal temp1;
00057     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00058             integer *);
00059     doublereal scale, large, apoaq, aqoap;
00060     extern logical lsame_(char *, char *);
00061     doublereal theta, small, sfmin;
00062     logical lsvec;
00063     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00064             doublereal *, integer *);
00065     doublereal fastr[5];
00066     extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *, 
00067             doublereal *, integer *);
00068     logical applv, rsvec;
00069     extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *, 
00070             integer *, doublereal *, integer *);
00071     logical uctol;
00072     extern /* Subroutine */ int drotm_(integer *, doublereal *, integer *, 
00073             doublereal *, integer *, doublereal *);
00074     logical lower, upper, rotok;
00075     extern /* Subroutine */ int dgsvj0_(char *, integer *, integer *, 
00076             doublereal *, integer *, doublereal *, doublereal *, integer *, 
00077             doublereal *, integer *, doublereal *, doublereal *, doublereal *, 
00078              integer *, doublereal *, integer *, integer *), dgsvj1_(
00079             char *, integer *, integer *, integer *, doublereal *, integer *, 
00080             doublereal *, doublereal *, integer *, doublereal *, integer *, 
00081             doublereal *, doublereal *, doublereal *, integer *, doublereal *, 
00082              integer *, integer *);
00083     extern doublereal dlamch_(char *);
00084     extern /* Subroutine */ int dlascl_(char *, integer *, integer *, 
00085             doublereal *, doublereal *, integer *, integer *, doublereal *, 
00086             integer *, integer *);
00087     extern integer idamax_(integer *, doublereal *, integer *);
00088     extern /* Subroutine */ int dlaset_(char *, integer *, integer *, 
00089             doublereal *, doublereal *, doublereal *, integer *), 
00090             xerbla_(char *, integer *);
00091     integer ijblsk, swband, blskip;
00092     doublereal mxaapq;
00093     extern /* Subroutine */ int dlassq_(integer *, doublereal *, integer *, 
00094             doublereal *, doublereal *);
00095     doublereal thsign, mxsinj;
00096     integer emptsw, notrot, iswrot, lkahead;
00097     logical goscale, noscale;
00098     doublereal rootbig, epsilon, rooteps;
00099     integer rowskip;
00100     doublereal roottol;
00101 
00102 
00103 /*  -- LAPACK routine (version 3.2)                                    -- */
00104 
00105 /*  -- Contributed by Zlatko Drmac of the University of Zagreb and     -- */
00106 /*  -- Kresimir Veselic of the Fernuniversitaet Hagen                  -- */
00107 /*  -- November 2008                                                   -- */
00108 
00109 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
00110 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
00111 
00112 /* This routine is also part of SIGMA (version 1.23, October 23. 2008.) */
00113 /* SIGMA is a library of algorithms for highly accurate algorithms for */
00114 /* computation of SVD, PSVD, QSVD, (H,K)-SVD, and for solution of the */
00115 /* eigenvalue problems Hx = lambda M x, H M x = lambda x with H, M > 0. */
00116 
00117 /*     -#- Scalar Arguments -#- */
00118 
00119 
00120 /*     -#- Array Arguments -#- */
00121 
00122 /*     .. */
00123 
00124 /*  Purpose */
00125 /*  ~~~~~~~ */
00126 /*  DGESVJ computes the singular value decomposition (SVD) of a real */
00127 /*  M-by-N matrix A, where M >= N. The SVD of A is written as */
00128 /*                                     [++]   [xx]   [x0]   [xx] */
00129 /*               A = U * SIGMA * V^t,  [++] = [xx] * [ox] * [xx] */
00130 /*                                     [++]   [xx] */
00131 /*  where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal */
00132 /*  matrix, and V is an N-by-N orthogonal matrix. The diagonal elements */
00133 /*  of SIGMA are the singular values of A. The columns of U and V are the */
00134 /*  left and the right singular vectors of A, respectively. */
00135 
00136 /*  Further Details */
00137 /*  ~~~~~~~~~~~~~~~ */
00138 /*  The orthogonal N-by-N matrix V is obtained as a product of Jacobi plane */
00139 /*  rotations. The rotations are implemented as fast scaled rotations of */
00140 /*  Anda and Park [1]. In the case of underflow of the Jacobi angle, a */
00141 /*  modified Jacobi transformation of Drmac [4] is used. Pivot strategy uses */
00142 /*  column interchanges of de Rijk [2]. The relative accuracy of the computed */
00143 /*  singular values and the accuracy of the computed singular vectors (in */
00144 /*  angle metric) is as guaranteed by the theory of Demmel and Veselic [3]. */
00145 /*  The condition number that determines the accuracy in the full rank case */
00146 /*  is essentially min_{D=diag} kappa(A*D), where kappa(.) is the */
00147 /*  spectral condition number. The best performance of this Jacobi SVD */
00148 /*  procedure is achieved if used in an  accelerated version of Drmac and */
00149 /*  Veselic [5,6], and it is the kernel routine in the SIGMA library [7]. */
00150 /*  Some tunning parameters (marked with [TP]) are available for the */
00151 /*  implementer. */
00152 /*  The computational range for the nonzero singular values is the  machine */
00153 /*  number interval ( UNDERFLOW , OVERFLOW ). In extreme cases, even */
00154 /*  denormalized singular values can be computed with the corresponding */
00155 /*  gradual loss of accurate digits. */
00156 
00157 /*  Contributors */
00158 /*  ~~~~~~~~~~~~ */
00159 /*  Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany) */
00160 
00161 /*  References */
00162 /*  ~~~~~~~~~~ */
00163 /* [1] A. A. Anda and H. Park: Fast plane rotations with dynamic scaling. */
00164 /*     SIAM J. matrix Anal. Appl., Vol. 15 (1994), pp. 162-174. */
00165 /* [2] P. P. M. De Rijk: A one-sided Jacobi algorithm for computing the */
00166 /*     singular value decomposition on a vector computer. */
00167 /*     SIAM J. Sci. Stat. Comp., Vol. 10 (1998), pp. 359-371. */
00168 /* [3] J. Demmel and K. Veselic: Jacobi method is more accurate than QR. */
00169 /* [4] Z. Drmac: Implementation of Jacobi rotations for accurate singular */
00170 /*     value computation in floating point arithmetic. */
00171 /*     SIAM J. Sci. Comp., Vol. 18 (1997), pp. 1200-1222. */
00172 /* [5] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm I. */
00173 /*     SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1322-1342. */
00174 /*     LAPACK Working note 169. */
00175 /* [6] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm II. */
00176 /*     SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1343-1362. */
00177 /*     LAPACK Working note 170. */
00178 /* [7] Z. Drmac: SIGMA - mathematical software library for accurate SVD, PSV, */
00179 /*     QSVD, (H,K)-SVD computations. */
00180 /*     Department of Mathematics, University of Zagreb, 2008. */
00181 
00182 /*  Bugs, Examples and Comments */
00183 /*  ~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
00184 /*  Please report all bugs and send interesting test examples and comments to */
00185 /*  drmac@math.hr. Thank you. */
00186 
00187 /*  Arguments */
00188 /*  ~~~~~~~~~ */
00189 
00190 /*  JOBA    (input) CHARACTER* 1 */
00191 /*          Specifies the structure of A. */
00192 /*          = 'L': The input matrix A is lower triangular; */
00193 /*          = 'U': The input matrix A is upper triangular; */
00194 /*          = 'G': The input matrix A is general M-by-N matrix, M >= N. */
00195 
00196 /*  JOBU    (input) CHARACTER*1 */
00197 /*          Specifies whether to compute the left singular vectors */
00198 /*          (columns of U): */
00199 
00200 /*          = 'U': The left singular vectors corresponding to the nonzero */
00201 /*                 singular values are computed and returned in the leading */
00202 /*                 columns of A. See more details in the description of A. */
00203 /*                 The default numerical orthogonality threshold is set to */
00204 /*                 approximately TOL=CTOL*EPS, CTOL=DSQRT(M), EPS=DLAMCH('E'). */
00205 /*          = 'C': Analogous to JOBU='U', except that user can control the */
00206 /*                 level of numerical orthogonality of the computed left */
00207 /*                 singular vectors. TOL can be set to TOL = CTOL*EPS, where */
00208 /*                 CTOL is given on input in the array WORK. */
00209 /*                 No CTOL smaller than ONE is allowed. CTOL greater */
00210 /*                 than 1 / EPS is meaningless. The option 'C' */
00211 /*                 can be used if M*EPS is satisfactory orthogonality */
00212 /*                 of the computed left singular vectors, so CTOL=M could */
00213 /*                 save few sweeps of Jacobi rotations. */
00214 /*                 See the descriptions of A and WORK(1). */
00215 /*          = 'N': The matrix U is not computed. However, see the */
00216 /*                 description of A. */
00217 
00218 /*  JOBV    (input) CHARACTER*1 */
00219 /*          Specifies whether to compute the right singular vectors, that */
00220 /*          is, the matrix V: */
00221 /*          = 'V' : the matrix V is computed and returned in the array V */
00222 /*          = 'A' : the Jacobi rotations are applied to the MV-by-N */
00223 /*                  array V. In other words, the right singular vector */
00224 /*                  matrix V is not computed explicitly, instead it is */
00225 /*                  applied to an MV-by-N matrix initially stored in the */
00226 /*                  first MV rows of V. */
00227 /*          = 'N' : the matrix V is not computed and the array V is not */
00228 /*                  referenced */
00229 
00230 /*  M       (input) INTEGER */
00231 /*          The number of rows of the input matrix A.  M >= 0. */
00232 
00233 /*  N       (input) INTEGER */
00234 /*          The number of columns of the input matrix A. */
00235 /*          M >= N >= 0. */
00236 
00237 /*  A       (input/output) REAL array, dimension (LDA,N) */
00238 /*          On entry, the M-by-N matrix A. */
00239 /*          On exit, */
00240 /*          If JOBU .EQ. 'U' .OR. JOBU .EQ. 'C': */
00241 /*          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
00242 /*                 If INFO .EQ. 0, */
00243 /*                 ~~~~~~~~~~~~~~~ */
00244 /*                 RANKA orthonormal columns of U are returned in the */
00245 /*                 leading RANKA columns of the array A. Here RANKA <= N */
00246 /*                 is the number of computed singular values of A that are */
00247 /*                 above the underflow threshold DLAMCH('S'). The singular */
00248 /*                 vectors corresponding to underflowed or zero singular */
00249 /*                 values are not computed. The value of RANKA is returned */
00250 /*                 in the array WORK as RANKA=NINT(WORK(2)). Also see the */
00251 /*                 descriptions of SVA and WORK. The computed columns of U */
00252 /*                 are mutually numerically orthogonal up to approximately */
00253 /*                 TOL=DSQRT(M)*EPS (default); or TOL=CTOL*EPS (JOBU.EQ.'C'), */
00254 /*                 see the description of JOBU. */
00255 /*                 If INFO .GT. 0, */
00256 /*                 ~~~~~~~~~~~~~~~ */
00257 /*                 the procedure DGESVJ did not converge in the given number */
00258 /*                 of iterations (sweeps). In that case, the computed */
00259 /*                 columns of U may not be orthogonal up to TOL. The output */
00260 /*                 U (stored in A), SIGMA (given by the computed singular */
00261 /*                 values in SVA(1:N)) and V is still a decomposition of the */
00262 /*                 input matrix A in the sense that the residual */
00263 /*                 ||A-SCALE*U*SIGMA*V^T||_2 / ||A||_2 is small. */
00264 
00265 /*          If JOBU .EQ. 'N': */
00266 /*          ~~~~~~~~~~~~~~~~~ */
00267 /*                 If INFO .EQ. 0 */
00268 /*                 ~~~~~~~~~~~~~~ */
00269 /*                 Note that the left singular vectors are 'for free' in the */
00270 /*                 one-sided Jacobi SVD algorithm. However, if only the */
00271 /*                 singular values are needed, the level of numerical */
00272 /*                 orthogonality of U is not an issue and iterations are */
00273 /*                 stopped when the columns of the iterated matrix are */
00274 /*                 numerically orthogonal up to approximately M*EPS. Thus, */
00275 /*                 on exit, A contains the columns of U scaled with the */
00276 /*                 corresponding singular values. */
00277 /*                 If INFO .GT. 0, */
00278 /*                 ~~~~~~~~~~~~~~~ */
00279 /*                 the procedure DGESVJ did not converge in the given number */
00280 /*                 of iterations (sweeps). */
00281 
00282 /*  LDA     (input) INTEGER */
00283 /*          The leading dimension of the array A.  LDA >= max(1,M). */
00284 
00285 /*  SVA     (workspace/output) REAL array, dimension (N) */
00286 /*          On exit, */
00287 /*          If INFO .EQ. 0, */
00288 /*          ~~~~~~~~~~~~~~~ */
00289 /*          depending on the value SCALE = WORK(1), we have: */
00290 /*                 If SCALE .EQ. ONE: */
00291 /*                 ~~~~~~~~~~~~~~~~~~ */
00292 /*                 SVA(1:N) contains the computed singular values of A. */
00293 /*                 During the computation SVA contains the Euclidean column */
00294 /*                 norms of the iterated matrices in the array A. */
00295 /*                 If SCALE .NE. ONE: */
00296 /*                 ~~~~~~~~~~~~~~~~~~ */
00297 /*                 The singular values of A are SCALE*SVA(1:N), and this */
00298 /*                 factored representation is due to the fact that some of the */
00299 /*                 singular values of A might underflow or overflow. */
00300 
00301 /*          If INFO .GT. 0, */
00302 /*          ~~~~~~~~~~~~~~~ */
00303 /*          the procedure DGESVJ did not converge in the given number of */
00304 /*          iterations (sweeps) and SCALE*SVA(1:N) may not be accurate. */
00305 
00306 /*  MV      (input) INTEGER */
00307 /*          If JOBV .EQ. 'A', then the product of Jacobi rotations in DGESVJ */
00308 /*          is applied to the first MV rows of V. See the description of JOBV. */
00309 
00310 /*  V       (input/output) REAL array, dimension (LDV,N) */
00311 /*          If JOBV = 'V', then V contains on exit the N-by-N matrix of */
00312 /*                         the right singular vectors; */
00313 /*          If JOBV = 'A', then V contains the product of the computed right */
00314 /*                         singular vector matrix and the initial matrix in */
00315 /*                         the array V. */
00316 /*          If JOBV = 'N', then V is not referenced. */
00317 
00318 /*  LDV     (input) INTEGER */
00319 /*          The leading dimension of the array V, LDV .GE. 1. */
00320 /*          If JOBV .EQ. 'V', then LDV .GE. max(1,N). */
00321 /*          If JOBV .EQ. 'A', then LDV .GE. max(1,MV) . */
00322 
00323 /*  WORK    (input/workspace/output) REAL array, dimension max(4,M+N). */
00324 /*          On entry, */
00325 /*          If JOBU .EQ. 'C', */
00326 /*          ~~~~~~~~~~~~~~~~~ */
00327 /*          WORK(1) = CTOL, where CTOL defines the threshold for convergence. */
00328 /*                    The process stops if all columns of A are mutually */
00329 /*                    orthogonal up to CTOL*EPS, EPS=DLAMCH('E'). */
00330 /*                    It is required that CTOL >= ONE, i.e. it is not */
00331 /*                    allowed to force the routine to obtain orthogonality */
00332 /*                    below EPSILON. */
00333 /*          On exit, */
00334 /*          WORK(1) = SCALE is the scaling factor such that SCALE*SVA(1:N) */
00335 /*                    are the computed singular vcalues of A. */
00336 /*                    (See description of SVA().) */
00337 /*          WORK(2) = NINT(WORK(2)) is the number of the computed nonzero */
00338 /*                    singular values. */
00339 /*          WORK(3) = NINT(WORK(3)) is the number of the computed singular */
00340 /*                    values that are larger than the underflow threshold. */
00341 /*          WORK(4) = NINT(WORK(4)) is the number of sweeps of Jacobi */
00342 /*                    rotations needed for numerical convergence. */
00343 /*          WORK(5) = max_{i.NE.j} |COS(A(:,i),A(:,j))| in the last sweep. */
00344 /*                    This is useful information in cases when DGESVJ did */
00345 /*                    not converge, as it can be used to estimate whether */
00346 /*                    the output is stil useful and for post festum analysis. */
00347 /*          WORK(6) = the largest absolute value over all sines of the */
00348 /*                    Jacobi rotation angles in the last sweep. It can be */
00349 /*                    useful for a post festum analysis. */
00350 
00351 /*  LWORK   length of WORK, WORK >= MAX(6,M+N) */
00352 
00353 /*  INFO    (output) INTEGER */
00354 /*          = 0 : successful exit. */
00355 /*          < 0 : if INFO = -i, then the i-th argument had an illegal value */
00356 /*          > 0 : DGESVJ did not converge in the maximal allowed number (30) */
00357 /*                of sweeps. The output may still be useful. See the */
00358 /*                description of WORK. */
00359 
00360 /*     Local Parameters */
00361 
00362 
00363 /*     Local Scalars */
00364 
00365 
00366 /*     Local Arrays */
00367 
00368 
00369 /*     Intrinsic Functions */
00370 
00371 
00372 /*     External Functions */
00373 /*     .. from BLAS */
00374 /*     .. from LAPACK */
00375 
00376 /*     External Subroutines */
00377 /*     .. from BLAS */
00378 /*     .. from LAPACK */
00379 
00380 
00381 /*     Test the input arguments */
00382 
00383     /* Parameter adjustments */
00384     --sva;
00385     a_dim1 = *lda;
00386     a_offset = 1 + a_dim1;
00387     a -= a_offset;
00388     v_dim1 = *ldv;
00389     v_offset = 1 + v_dim1;
00390     v -= v_offset;
00391     --work;
00392 
00393     /* Function Body */
00394     lsvec = lsame_(jobu, "U");
00395     uctol = lsame_(jobu, "C");
00396     rsvec = lsame_(jobv, "V");
00397     applv = lsame_(jobv, "A");
00398     upper = lsame_(joba, "U");
00399     lower = lsame_(joba, "L");
00400 
00401     if (! (upper || lower || lsame_(joba, "G"))) {
00402         *info = -1;
00403     } else if (! (lsvec || uctol || lsame_(jobu, "N"))) 
00404             {
00405         *info = -2;
00406     } else if (! (rsvec || applv || lsame_(jobv, "N"))) 
00407             {
00408         *info = -3;
00409     } else if (*m < 0) {
00410         *info = -4;
00411     } else if (*n < 0 || *n > *m) {
00412         *info = -5;
00413     } else if (*lda < *m) {
00414         *info = -7;
00415     } else if (*mv < 0) {
00416         *info = -9;
00417     } else if (rsvec && *ldv < *n || applv && *ldv < *mv) {
00418         *info = -11;
00419     } else if (uctol && work[1] <= 1.) {
00420         *info = -12;
00421     } else /* if(complicated condition) */ {
00422 /* Computing MAX */
00423         i__1 = *m + *n;
00424         if (*lwork < max(i__1,6)) {
00425             *info = -13;
00426         } else {
00427             *info = 0;
00428         }
00429     }
00430 
00431 /*     #:( */
00432     if (*info != 0) {
00433         i__1 = -(*info);
00434         xerbla_("DGESVJ", &i__1);
00435         return 0;
00436     }
00437 
00438 /* #:) Quick return for void matrix */
00439 
00440     if (*m == 0 || *n == 0) {
00441         return 0;
00442     }
00443 
00444 /*     Set numerical parameters */
00445 /*     The stopping criterion for Jacobi rotations is */
00446 
00447 /*     max_{i<>j}|A(:,i)^T * A(:,j)|/(||A(:,i)||*||A(:,j)||) < CTOL*EPS */
00448 
00449 /*     where EPS is the round-off and CTOL is defined as follows: */
00450 
00451     if (uctol) {
00452 /*        ... user controlled */
00453         ctol = work[1];
00454     } else {
00455 /*        ... default */
00456         if (lsvec || rsvec || applv) {
00457             ctol = sqrt((doublereal) (*m));
00458         } else {
00459             ctol = (doublereal) (*m);
00460         }
00461     }
00462 /*     ... and the machine dependent parameters are */
00463 /* [!]  (Make sure that DLAMCH() works properly on the target machine.) */
00464 
00465     epsilon = dlamch_("Epsilon");
00466     rooteps = sqrt(epsilon);
00467     sfmin = dlamch_("SafeMinimum");
00468     rootsfmin = sqrt(sfmin);
00469     small = sfmin / epsilon;
00470     big = dlamch_("Overflow");
00471 /*     BIG         = ONE    / SFMIN */
00472     rootbig = 1. / rootsfmin;
00473     large = big / sqrt((doublereal) (*m * *n));
00474     bigtheta = 1. / rooteps;
00475 
00476     tol = ctol * epsilon;
00477     roottol = sqrt(tol);
00478 
00479     if ((doublereal) (*m) * epsilon >= 1.) {
00480         *info = -5;
00481         i__1 = -(*info);
00482         xerbla_("DGESVJ", &i__1);
00483         return 0;
00484     }
00485 
00486 /*     Initialize the right singular vector matrix. */
00487 
00488     if (rsvec) {
00489         mvl = *n;
00490         dlaset_("A", &mvl, n, &c_b17, &c_b18, &v[v_offset], ldv);
00491     } else if (applv) {
00492         mvl = *mv;
00493     }
00494     rsvec = rsvec || applv;
00495 
00496 /*     Initialize SVA( 1:N ) = ( ||A e_i||_2, i = 1:N ) */
00497 /* (!)  If necessary, scale A to protect the largest singular value */
00498 /*     from overflow. It is possible that saving the largest singular */
00499 /*     value destroys the information about the small ones. */
00500 /*     This initial scaling is almost minimal in the sense that the */
00501 /*     goal is to make sure that no column norm overflows, and that */
00502 /*     DSQRT(N)*max_i SVA(i) does not overflow. If INFinite entries */
00503 /*     in A are detected, the procedure returns with INFO=-6. */
00504 
00505     scale = 1. / sqrt((doublereal) (*m) * (doublereal) (*n));
00506     noscale = TRUE_;
00507     goscale = TRUE_;
00508 
00509     if (lower) {
00510 /*        the input matrix is M-by-N lower triangular (trapezoidal) */
00511         i__1 = *n;
00512         for (p = 1; p <= i__1; ++p) {
00513             aapp = 0.;
00514             aaqq = 0.;
00515             i__2 = *m - p + 1;
00516             dlassq_(&i__2, &a[p + p * a_dim1], &c__1, &aapp, &aaqq);
00517             if (aapp > big) {
00518                 *info = -6;
00519                 i__2 = -(*info);
00520                 xerbla_("DGESVJ", &i__2);
00521                 return 0;
00522             }
00523             aaqq = sqrt(aaqq);
00524             if (aapp < big / aaqq && noscale) {
00525                 sva[p] = aapp * aaqq;
00526             } else {
00527                 noscale = FALSE_;
00528                 sva[p] = aapp * (aaqq * scale);
00529                 if (goscale) {
00530                     goscale = FALSE_;
00531                     i__2 = p - 1;
00532                     for (q = 1; q <= i__2; ++q) {
00533                         sva[q] *= scale;
00534 /* L1873: */
00535                     }
00536                 }
00537             }
00538 /* L1874: */
00539         }
00540     } else if (upper) {
00541 /*        the input matrix is M-by-N upper triangular (trapezoidal) */
00542         i__1 = *n;
00543         for (p = 1; p <= i__1; ++p) {
00544             aapp = 0.;
00545             aaqq = 0.;
00546             dlassq_(&p, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
00547             if (aapp > big) {
00548                 *info = -6;
00549                 i__2 = -(*info);
00550                 xerbla_("DGESVJ", &i__2);
00551                 return 0;
00552             }
00553             aaqq = sqrt(aaqq);
00554             if (aapp < big / aaqq && noscale) {
00555                 sva[p] = aapp * aaqq;
00556             } else {
00557                 noscale = FALSE_;
00558                 sva[p] = aapp * (aaqq * scale);
00559                 if (goscale) {
00560                     goscale = FALSE_;
00561                     i__2 = p - 1;
00562                     for (q = 1; q <= i__2; ++q) {
00563                         sva[q] *= scale;
00564 /* L2873: */
00565                     }
00566                 }
00567             }
00568 /* L2874: */
00569         }
00570     } else {
00571 /*        the input matrix is M-by-N general dense */
00572         i__1 = *n;
00573         for (p = 1; p <= i__1; ++p) {
00574             aapp = 0.;
00575             aaqq = 0.;
00576             dlassq_(m, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
00577             if (aapp > big) {
00578                 *info = -6;
00579                 i__2 = -(*info);
00580                 xerbla_("DGESVJ", &i__2);
00581                 return 0;
00582             }
00583             aaqq = sqrt(aaqq);
00584             if (aapp < big / aaqq && noscale) {
00585                 sva[p] = aapp * aaqq;
00586             } else {
00587                 noscale = FALSE_;
00588                 sva[p] = aapp * (aaqq * scale);
00589                 if (goscale) {
00590                     goscale = FALSE_;
00591                     i__2 = p - 1;
00592                     for (q = 1; q <= i__2; ++q) {
00593                         sva[q] *= scale;
00594 /* L3873: */
00595                     }
00596                 }
00597             }
00598 /* L3874: */
00599         }
00600     }
00601 
00602     if (noscale) {
00603         scale = 1.;
00604     }
00605 
00606 /*     Move the smaller part of the spectrum from the underflow threshold */
00607 /* (!)  Start by determining the position of the nonzero entries of the */
00608 /*     array SVA() relative to ( SFMIN, BIG ). */
00609 
00610     aapp = 0.;
00611     aaqq = big;
00612     i__1 = *n;
00613     for (p = 1; p <= i__1; ++p) {
00614         if (sva[p] != 0.) {
00615 /* Computing MIN */
00616             d__1 = aaqq, d__2 = sva[p];
00617             aaqq = min(d__1,d__2);
00618         }
00619 /* Computing MAX */
00620         d__1 = aapp, d__2 = sva[p];
00621         aapp = max(d__1,d__2);
00622 /* L4781: */
00623     }
00624 
00625 /* #:) Quick return for zero matrix */
00626 
00627     if (aapp == 0.) {
00628         if (lsvec) {
00629             dlaset_("G", m, n, &c_b17, &c_b18, &a[a_offset], lda);
00630         }
00631         work[1] = 1.;
00632         work[2] = 0.;
00633         work[3] = 0.;
00634         work[4] = 0.;
00635         work[5] = 0.;
00636         work[6] = 0.;
00637         return 0;
00638     }
00639 
00640 /* #:) Quick return for one-column matrix */
00641 
00642     if (*n == 1) {
00643         if (lsvec) {
00644             dlascl_("G", &c__0, &c__0, &sva[1], &scale, m, &c__1, &a[a_dim1 + 
00645                     1], lda, &ierr);
00646         }
00647         work[1] = 1. / scale;
00648         if (sva[1] >= sfmin) {
00649             work[2] = 1.;
00650         } else {
00651             work[2] = 0.;
00652         }
00653         work[3] = 0.;
00654         work[4] = 0.;
00655         work[5] = 0.;
00656         work[6] = 0.;
00657         return 0;
00658     }
00659 
00660 /*     Protect small singular values from underflow, and try to */
00661 /*     avoid underflows/overflows in computing Jacobi rotations. */
00662 
00663     sn = sqrt(sfmin / epsilon);
00664     temp1 = sqrt(big / (doublereal) (*n));
00665     if (aapp <= sn || aaqq >= temp1 || sn <= aaqq && aapp <= temp1) {
00666 /* Computing MIN */
00667         d__1 = big, d__2 = temp1 / aapp;
00668         temp1 = min(d__1,d__2);
00669 /*         AAQQ  = AAQQ*TEMP1 */
00670 /*         AAPP  = AAPP*TEMP1 */
00671     } else if (aaqq <= sn && aapp <= temp1) {
00672 /* Computing MIN */
00673         d__1 = sn / aaqq, d__2 = big / (aapp * sqrt((doublereal) (*n)));
00674         temp1 = min(d__1,d__2);
00675 /*         AAQQ  = AAQQ*TEMP1 */
00676 /*         AAPP  = AAPP*TEMP1 */
00677     } else if (aaqq >= sn && aapp >= temp1) {
00678 /* Computing MAX */
00679         d__1 = sn / aaqq, d__2 = temp1 / aapp;
00680         temp1 = max(d__1,d__2);
00681 /*         AAQQ  = AAQQ*TEMP1 */
00682 /*         AAPP  = AAPP*TEMP1 */
00683     } else if (aaqq <= sn && aapp >= temp1) {
00684 /* Computing MIN */
00685         d__1 = sn / aaqq, d__2 = big / (sqrt((doublereal) (*n)) * aapp);
00686         temp1 = min(d__1,d__2);
00687 /*         AAQQ  = AAQQ*TEMP1 */
00688 /*         AAPP  = AAPP*TEMP1 */
00689     } else {
00690         temp1 = 1.;
00691     }
00692 
00693 /*     Scale, if necessary */
00694 
00695     if (temp1 != 1.) {
00696         dlascl_("G", &c__0, &c__0, &c_b18, &temp1, n, &c__1, &sva[1], n, &
00697                 ierr);
00698     }
00699     scale = temp1 * scale;
00700     if (scale != 1.) {
00701         dlascl_(joba, &c__0, &c__0, &c_b18, &scale, m, n, &a[a_offset], lda, &
00702                 ierr);
00703         scale = 1. / scale;
00704     }
00705 
00706 /*     Row-cyclic Jacobi SVD algorithm with column pivoting */
00707 
00708     emptsw = *n * (*n - 1) / 2;
00709     notrot = 0;
00710     fastr[0] = 0.;
00711 
00712 /*     A is represented in factored form A = A * diag(WORK), where diag(WORK) */
00713 /*     is initialized to identity. WORK is updated during fast scaled */
00714 /*     rotations. */
00715 
00716     i__1 = *n;
00717     for (q = 1; q <= i__1; ++q) {
00718         work[q] = 1.;
00719 /* L1868: */
00720     }
00721 
00722 
00723     swband = 3;
00724 /* [TP] SWBAND is a tuning parameter [TP]. It is meaningful and effective */
00725 /*     if DGESVJ is used as a computational routine in the preconditioned */
00726 /*     Jacobi SVD algorithm DGESVJ. For sweeps i=1:SWBAND the procedure */
00727 /*     works on pivots inside a band-like region around the diagonal. */
00728 /*     The boundaries are determined dynamically, based on the number of */
00729 /*     pivots above a threshold. */
00730 
00731     kbl = min(8,*n);
00732 /* [TP] KBL is a tuning parameter that defines the tile size in the */
00733 /*     tiling of the p-q loops of pivot pairs. In general, an optimal */
00734 /*     value of KBL depends on the matrix dimensions and on the */
00735 /*     parameters of the computer's memory. */
00736 
00737     nbl = *n / kbl;
00738     if (nbl * kbl != *n) {
00739         ++nbl;
00740     }
00741 
00742 /* Computing 2nd power */
00743     i__1 = kbl;
00744     blskip = i__1 * i__1;
00745 /* [TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL. */
00746 
00747     rowskip = min(5,kbl);
00748 /* [TP] ROWSKIP is a tuning parameter. */
00749 
00750     lkahead = 1;
00751 /* [TP] LKAHEAD is a tuning parameter. */
00752 
00753 /*     Quasi block transformations, using the lower (upper) triangular */
00754 /*     structure of the input matrix. The quasi-block-cycling usually */
00755 /*     invokes cubic convergence. Big part of this cycle is done inside */
00756 /*     canonical subspaces of dimensions less than M. */
00757 
00758 /* Computing MAX */
00759     i__1 = 64, i__2 = kbl << 2;
00760     if ((lower || upper) && *n > max(i__1,i__2)) {
00761 /* [TP] The number of partition levels and the actual partition are */
00762 /*     tuning parameters. */
00763         n4 = *n / 4;
00764         n2 = *n / 2;
00765         n34 = n4 * 3;
00766         if (applv) {
00767             q = 0;
00768         } else {
00769             q = 1;
00770         }
00771 
00772         if (lower) {
00773 
00774 /*     This works very well on lower triangular matrices, in particular */
00775 /*     in the framework of the preconditioned Jacobi SVD (xGEJSV). */
00776 /*     The idea is simple: */
00777 /*     [+ 0 0 0]   Note that Jacobi transformations of [0 0] */
00778 /*     [+ + 0 0]                                       [0 0] */
00779 /*     [+ + x 0]   actually work on [x 0]              [x 0] */
00780 /*     [+ + x x]                    [x x].             [x x] */
00781 
00782             i__1 = *m - n34;
00783             i__2 = *n - n34;
00784             i__3 = *lwork - *n;
00785             dgsvj0_(jobv, &i__1, &i__2, &a[n34 + 1 + (n34 + 1) * a_dim1], lda, 
00786                      &work[n34 + 1], &sva[n34 + 1], &mvl, &v[n34 * q + 1 + (
00787                     n34 + 1) * v_dim1], ldv, &epsilon, &sfmin, &tol, &c__2, &
00788                     work[*n + 1], &i__3, &ierr);
00789 
00790             i__1 = *m - n2;
00791             i__2 = n34 - n2;
00792             i__3 = *lwork - *n;
00793             dgsvj0_(jobv, &i__1, &i__2, &a[n2 + 1 + (n2 + 1) * a_dim1], lda, &
00794                     work[n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (n2 + 1)
00795                      * v_dim1], ldv, &epsilon, &sfmin, &tol, &c__2, &work[*n 
00796                     + 1], &i__3, &ierr);
00797 
00798             i__1 = *m - n2;
00799             i__2 = *n - n2;
00800             i__3 = *lwork - *n;
00801             dgsvj1_(jobv, &i__1, &i__2, &n4, &a[n2 + 1 + (n2 + 1) * a_dim1], 
00802                     lda, &work[n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (
00803                     n2 + 1) * v_dim1], ldv, &epsilon, &sfmin, &tol, &c__1, &
00804                     work[*n + 1], &i__3, &ierr);
00805 
00806             i__1 = *m - n4;
00807             i__2 = n2 - n4;
00808             i__3 = *lwork - *n;
00809             dgsvj0_(jobv, &i__1, &i__2, &a[n4 + 1 + (n4 + 1) * a_dim1], lda, &
00810                     work[n4 + 1], &sva[n4 + 1], &mvl, &v[n4 * q + 1 + (n4 + 1)
00811                      * v_dim1], ldv, &epsilon, &sfmin, &tol, &c__1, &work[*n 
00812                     + 1], &i__3, &ierr);
00813 
00814             i__1 = *lwork - *n;
00815             dgsvj0_(jobv, m, &n4, &a[a_offset], lda, &work[1], &sva[1], &mvl, 
00816                     &v[v_offset], ldv, &epsilon, &sfmin, &tol, &c__1, &work[*
00817                     n + 1], &i__1, &ierr);
00818 
00819             i__1 = *lwork - *n;
00820             dgsvj1_(jobv, m, &n2, &n4, &a[a_offset], lda, &work[1], &sva[1], &
00821                     mvl, &v[v_offset], ldv, &epsilon, &sfmin, &tol, &c__1, &
00822                     work[*n + 1], &i__1, &ierr);
00823 
00824 
00825         } else if (upper) {
00826 
00827 
00828             i__1 = *lwork - *n;
00829             dgsvj0_(jobv, &n4, &n4, &a[a_offset], lda, &work[1], &sva[1], &
00830                     mvl, &v[v_offset], ldv, &epsilon, &sfmin, &tol, &c__2, &
00831                     work[*n + 1], &i__1, &ierr);
00832 
00833             i__1 = *lwork - *n;
00834             dgsvj0_(jobv, &n2, &n4, &a[(n4 + 1) * a_dim1 + 1], lda, &work[n4 
00835                     + 1], &sva[n4 + 1], &mvl, &v[n4 * q + 1 + (n4 + 1) * 
00836                     v_dim1], ldv, &epsilon, &sfmin, &tol, &c__1, &work[*n + 1]
00837 , &i__1, &ierr);
00838 
00839             i__1 = *lwork - *n;
00840             dgsvj1_(jobv, &n2, &n2, &n4, &a[a_offset], lda, &work[1], &sva[1], 
00841                      &mvl, &v[v_offset], ldv, &epsilon, &sfmin, &tol, &c__1, &
00842                     work[*n + 1], &i__1, &ierr);
00843 
00844             i__1 = n2 + n4;
00845             i__2 = *lwork - *n;
00846             dgsvj0_(jobv, &i__1, &n4, &a[(n2 + 1) * a_dim1 + 1], lda, &work[
00847                     n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (n2 + 1) * 
00848                     v_dim1], ldv, &epsilon, &sfmin, &tol, &c__1, &work[*n + 1]
00849 , &i__2, &ierr);
00850         }
00851 
00852     }
00853 
00854 /*     -#- Row-cyclic pivot strategy with de Rijk's pivoting -#- */
00855 
00856     for (i__ = 1; i__ <= 30; ++i__) {
00857 
00858 /*     .. go go go ... */
00859 
00860         mxaapq = 0.;
00861         mxsinj = 0.;
00862         iswrot = 0;
00863 
00864         notrot = 0;
00865         pskipped = 0;
00866 
00867 /*     Each sweep is unrolled using KBL-by-KBL tiles over the pivot pairs */
00868 /*     1 <= p < q <= N. This is the first step toward a blocked implementation */
00869 /*     of the rotations. New implementation, based on block transformations, */
00870 /*     is under development. */
00871 
00872         i__1 = nbl;
00873         for (ibr = 1; ibr <= i__1; ++ibr) {
00874 
00875             igl = (ibr - 1) * kbl + 1;
00876 
00877 /* Computing MIN */
00878             i__3 = lkahead, i__4 = nbl - ibr;
00879             i__2 = min(i__3,i__4);
00880             for (ir1 = 0; ir1 <= i__2; ++ir1) {
00881 
00882                 igl += ir1 * kbl;
00883 
00884 /* Computing MIN */
00885                 i__4 = igl + kbl - 1, i__5 = *n - 1;
00886                 i__3 = min(i__4,i__5);
00887                 for (p = igl; p <= i__3; ++p) {
00888 
00889 /*     .. de Rijk's pivoting */
00890 
00891                     i__4 = *n - p + 1;
00892                     q = idamax_(&i__4, &sva[p], &c__1) + p - 1;
00893                     if (p != q) {
00894                         dswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 
00895                                 1], &c__1);
00896                         if (rsvec) {
00897                             dswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
00898                                     v_dim1 + 1], &c__1);
00899                         }
00900                         temp1 = sva[p];
00901                         sva[p] = sva[q];
00902                         sva[q] = temp1;
00903                         temp1 = work[p];
00904                         work[p] = work[q];
00905                         work[q] = temp1;
00906                     }
00907 
00908                     if (ir1 == 0) {
00909 
00910 /*        Column norms are periodically updated by explicit */
00911 /*        norm computation. */
00912 /*        Caveat: */
00913 /*        Unfortunately, some BLAS implementations compute DNRM2(M,A(1,p),1) */
00914 /*        as DSQRT(DDOT(M,A(1,p),1,A(1,p),1)), which may cause the result to */
00915 /*        overflow for ||A(:,p)||_2 > DSQRT(overflow_threshold), and to */
00916 /*        underflow for ||A(:,p)||_2 < DSQRT(underflow_threshold). */
00917 /*        Hence, DNRM2 cannot be trusted, not even in the case when */
00918 /*        the true norm is far from the under(over)flow boundaries. */
00919 /*        If properly implemented DNRM2 is available, the IF-THEN-ELSE */
00920 /*        below should read "AAPP = DNRM2( M, A(1,p), 1 ) * WORK(p)". */
00921 
00922                         if (sva[p] < rootbig && sva[p] > rootsfmin) {
00923                             sva[p] = dnrm2_(m, &a[p * a_dim1 + 1], &c__1) * 
00924                                     work[p];
00925                         } else {
00926                             temp1 = 0.;
00927                             aapp = 0.;
00928                             dlassq_(m, &a[p * a_dim1 + 1], &c__1, &temp1, &
00929                                     aapp);
00930                             sva[p] = temp1 * sqrt(aapp) * work[p];
00931                         }
00932                         aapp = sva[p];
00933                     } else {
00934                         aapp = sva[p];
00935                     }
00936 
00937                     if (aapp > 0.) {
00938 
00939                         pskipped = 0;
00940 
00941 /* Computing MIN */
00942                         i__5 = igl + kbl - 1;
00943                         i__4 = min(i__5,*n);
00944                         for (q = p + 1; q <= i__4; ++q) {
00945 
00946                             aaqq = sva[q];
00947 
00948                             if (aaqq > 0.) {
00949 
00950                                 aapp0 = aapp;
00951                                 if (aaqq >= 1.) {
00952                                     rotok = small * aapp <= aaqq;
00953                                     if (aapp < big / aaqq) {
00954                                         aapq = ddot_(m, &a[p * a_dim1 + 1], &
00955                                                 c__1, &a[q * a_dim1 + 1], &
00956                                                 c__1) * work[p] * work[q] / 
00957                                                 aaqq / aapp;
00958                                     } else {
00959                                         dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
00960                                                 work[*n + 1], &c__1);
00961                                         dlascl_("G", &c__0, &c__0, &aapp, &
00962                                                 work[p], m, &c__1, &work[*n + 
00963                                                 1], lda, &ierr);
00964                                         aapq = ddot_(m, &work[*n + 1], &c__1, 
00965                                                 &a[q * a_dim1 + 1], &c__1) * 
00966                                                 work[q] / aaqq;
00967                                     }
00968                                 } else {
00969                                     rotok = aapp <= aaqq / small;
00970                                     if (aapp > small / aaqq) {
00971                                         aapq = ddot_(m, &a[p * a_dim1 + 1], &
00972                                                 c__1, &a[q * a_dim1 + 1], &
00973                                                 c__1) * work[p] * work[q] / 
00974                                                 aaqq / aapp;
00975                                     } else {
00976                                         dcopy_(m, &a[q * a_dim1 + 1], &c__1, &
00977                                                 work[*n + 1], &c__1);
00978                                         dlascl_("G", &c__0, &c__0, &aaqq, &
00979                                                 work[q], m, &c__1, &work[*n + 
00980                                                 1], lda, &ierr);
00981                                         aapq = ddot_(m, &work[*n + 1], &c__1, 
00982                                                 &a[p * a_dim1 + 1], &c__1) * 
00983                                                 work[p] / aapp;
00984                                     }
00985                                 }
00986 
00987 /* Computing MAX */
00988                                 d__1 = mxaapq, d__2 = abs(aapq);
00989                                 mxaapq = max(d__1,d__2);
00990 
00991 /*        TO rotate or NOT to rotate, THAT is the question ... */
00992 
00993                                 if (abs(aapq) > tol) {
00994 
00995 /*           .. rotate */
00996 /* [RTD]      ROTATED = ROTATED + ONE */
00997 
00998                                     if (ir1 == 0) {
00999                                         notrot = 0;
01000                                         pskipped = 0;
01001                                         ++iswrot;
01002                                     }
01003 
01004                                     if (rotok) {
01005 
01006                                         aqoap = aaqq / aapp;
01007                                         apoaq = aapp / aaqq;
01008                                         theta = (d__1 = aqoap - apoaq, abs(
01009                                                 d__1)) * -.5 / aapq;
01010 
01011                                         if (abs(theta) > bigtheta) {
01012 
01013                                             t = .5 / theta;
01014                                             fastr[2] = t * work[p] / work[q];
01015                                             fastr[3] = -t * work[q] / work[p];
01016                                             drotm_(m, &a[p * a_dim1 + 1], &
01017                                                     c__1, &a[q * a_dim1 + 1], 
01018                                                     &c__1, fastr);
01019                                             if (rsvec) {
01020                           drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
01021                                   v_dim1 + 1], &c__1, fastr);
01022                                             }
01023 /* Computing MAX */
01024                                             d__1 = 0., d__2 = t * apoaq * 
01025                                                     aapq + 1.;
01026                                             sva[q] = aaqq * sqrt((max(d__1,
01027                                                     d__2)));
01028                                             aapp *= sqrt(1. - t * aqoap * 
01029                                                     aapq);
01030 /* Computing MAX */
01031                                             d__1 = mxsinj, d__2 = abs(t);
01032                                             mxsinj = max(d__1,d__2);
01033 
01034                                         } else {
01035 
01036 /*                 .. choose correct signum for THETA and rotate */
01037 
01038                                             thsign = -d_sign(&c_b18, &aapq);
01039                                             t = 1. / (theta + thsign * sqrt(
01040                                                     theta * theta + 1.));
01041                                             cs = sqrt(1. / (t * t + 1.));
01042                                             sn = t * cs;
01043 
01044 /* Computing MAX */
01045                                             d__1 = mxsinj, d__2 = abs(sn);
01046                                             mxsinj = max(d__1,d__2);
01047 /* Computing MAX */
01048                                             d__1 = 0., d__2 = t * apoaq * 
01049                                                     aapq + 1.;
01050                                             sva[q] = aaqq * sqrt((max(d__1,
01051                                                     d__2)));
01052 /* Computing MAX */
01053                                             d__1 = 0., d__2 = 1. - t * aqoap *
01054                                                      aapq;
01055                                             aapp *= sqrt((max(d__1,d__2)));
01056 
01057                                             apoaq = work[p] / work[q];
01058                                             aqoap = work[q] / work[p];
01059                                             if (work[p] >= 1.) {
01060                           if (work[q] >= 1.) {
01061                               fastr[2] = t * apoaq;
01062                               fastr[3] = -t * aqoap;
01063                               work[p] *= cs;
01064                               work[q] *= cs;
01065                               drotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q * 
01066                                       a_dim1 + 1], &c__1, fastr);
01067                               if (rsvec) {
01068                                   drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
01069                                           q * v_dim1 + 1], &c__1, fastr);
01070                               }
01071                           } else {
01072                               d__1 = -t * aqoap;
01073                               daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
01074                                       p * a_dim1 + 1], &c__1);
01075                               d__1 = cs * sn * apoaq;
01076                               daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
01077                                       q * a_dim1 + 1], &c__1);
01078                               work[p] *= cs;
01079                               work[q] /= cs;
01080                               if (rsvec) {
01081                                   d__1 = -t * aqoap;
01082                                   daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
01083                                           c__1, &v[p * v_dim1 + 1], &c__1);
01084                                   d__1 = cs * sn * apoaq;
01085                                   daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
01086                                           c__1, &v[q * v_dim1 + 1], &c__1);
01087                               }
01088                           }
01089                                             } else {
01090                           if (work[q] >= 1.) {
01091                               d__1 = t * apoaq;
01092                               daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
01093                                       q * a_dim1 + 1], &c__1);
01094                               d__1 = -cs * sn * aqoap;
01095                               daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
01096                                       p * a_dim1 + 1], &c__1);
01097                               work[p] /= cs;
01098                               work[q] *= cs;
01099                               if (rsvec) {
01100                                   d__1 = t * apoaq;
01101                                   daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
01102                                           c__1, &v[q * v_dim1 + 1], &c__1);
01103                                   d__1 = -cs * sn * aqoap;
01104                                   daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
01105                                           c__1, &v[p * v_dim1 + 1], &c__1);
01106                               }
01107                           } else {
01108                               if (work[p] >= work[q]) {
01109                                   d__1 = -t * aqoap;
01110                                   daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, 
01111                                           &a[p * a_dim1 + 1], &c__1);
01112                                   d__1 = cs * sn * apoaq;
01113                                   daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, 
01114                                           &a[q * a_dim1 + 1], &c__1);
01115                                   work[p] *= cs;
01116                                   work[q] /= cs;
01117                                   if (rsvec) {
01118                                       d__1 = -t * aqoap;
01119                                       daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], 
01120                                               &c__1, &v[p * v_dim1 + 1], &
01121                                               c__1);
01122                                       d__1 = cs * sn * apoaq;
01123                                       daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], 
01124                                               &c__1, &v[q * v_dim1 + 1], &
01125                                               c__1);
01126                                   }
01127                               } else {
01128                                   d__1 = t * apoaq;
01129                                   daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, 
01130                                           &a[q * a_dim1 + 1], &c__1);
01131                                   d__1 = -cs * sn * aqoap;
01132                                   daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, 
01133                                           &a[p * a_dim1 + 1], &c__1);
01134                                   work[p] /= cs;
01135                                   work[q] *= cs;
01136                                   if (rsvec) {
01137                                       d__1 = t * apoaq;
01138                                       daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], 
01139                                               &c__1, &v[q * v_dim1 + 1], &
01140                                               c__1);
01141                                       d__1 = -cs * sn * aqoap;
01142                                       daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], 
01143                                               &c__1, &v[p * v_dim1 + 1], &
01144                                               c__1);
01145                                   }
01146                               }
01147                           }
01148                                             }
01149                                         }
01150 
01151                                     } else {
01152 /*              .. have to use modified Gram-Schmidt like transformation */
01153                                         dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
01154                                                 work[*n + 1], &c__1);
01155                                         dlascl_("G", &c__0, &c__0, &aapp, &
01156                                                 c_b18, m, &c__1, &work[*n + 1]
01157 , lda, &ierr);
01158                                         dlascl_("G", &c__0, &c__0, &aaqq, &
01159                                                 c_b18, m, &c__1, &a[q * 
01160                                                 a_dim1 + 1], lda, &ierr);
01161                                         temp1 = -aapq * work[p] / work[q];
01162                                         daxpy_(m, &temp1, &work[*n + 1], &
01163                                                 c__1, &a[q * a_dim1 + 1], &
01164                                                 c__1);
01165                                         dlascl_("G", &c__0, &c__0, &c_b18, &
01166                                                 aaqq, m, &c__1, &a[q * a_dim1 
01167                                                 + 1], lda, &ierr);
01168 /* Computing MAX */
01169                                         d__1 = 0., d__2 = 1. - aapq * aapq;
01170                                         sva[q] = aaqq * sqrt((max(d__1,d__2)))
01171                                                 ;
01172                                         mxsinj = max(mxsinj,sfmin);
01173                                     }
01174 /*           END IF ROTOK THEN ... ELSE */
01175 
01176 /*           In the case of cancellation in updating SVA(q), SVA(p) */
01177 /*           recompute SVA(q), SVA(p). */
01178 
01179 /* Computing 2nd power */
01180                                     d__1 = sva[q] / aaqq;
01181                                     if (d__1 * d__1 <= rooteps) {
01182                                         if (aaqq < rootbig && aaqq > 
01183                                                 rootsfmin) {
01184                                             sva[q] = dnrm2_(m, &a[q * a_dim1 
01185                                                     + 1], &c__1) * work[q];
01186                                         } else {
01187                                             t = 0.;
01188                                             aaqq = 0.;
01189                                             dlassq_(m, &a[q * a_dim1 + 1], &
01190                                                     c__1, &t, &aaqq);
01191                                             sva[q] = t * sqrt(aaqq) * work[q];
01192                                         }
01193                                     }
01194                                     if (aapp / aapp0 <= rooteps) {
01195                                         if (aapp < rootbig && aapp > 
01196                                                 rootsfmin) {
01197                                             aapp = dnrm2_(m, &a[p * a_dim1 + 
01198                                                     1], &c__1) * work[p];
01199                                         } else {
01200                                             t = 0.;
01201                                             aapp = 0.;
01202                                             dlassq_(m, &a[p * a_dim1 + 1], &
01203                                                     c__1, &t, &aapp);
01204                                             aapp = t * sqrt(aapp) * work[p];
01205                                         }
01206                                         sva[p] = aapp;
01207                                     }
01208 
01209                                 } else {
01210 /*        A(:,p) and A(:,q) already numerically orthogonal */
01211                                     if (ir1 == 0) {
01212                                         ++notrot;
01213                                     }
01214 /* [RTD]      SKIPPED  = SKIPPED  + 1 */
01215                                     ++pskipped;
01216                                 }
01217                             } else {
01218 /*        A(:,q) is zero column */
01219                                 if (ir1 == 0) {
01220                                     ++notrot;
01221                                 }
01222                                 ++pskipped;
01223                             }
01224 
01225                             if (i__ <= swband && pskipped > rowskip) {
01226                                 if (ir1 == 0) {
01227                                     aapp = -aapp;
01228                                 }
01229                                 notrot = 0;
01230                                 goto L2103;
01231                             }
01232 
01233 /* L2002: */
01234                         }
01235 /*     END q-LOOP */
01236 
01237 L2103:
01238 /*     bailed out of q-loop */
01239 
01240                         sva[p] = aapp;
01241 
01242                     } else {
01243                         sva[p] = aapp;
01244                         if (ir1 == 0 && aapp == 0.) {
01245 /* Computing MIN */
01246                             i__4 = igl + kbl - 1;
01247                             notrot = notrot + min(i__4,*n) - p;
01248                         }
01249                     }
01250 
01251 /* L2001: */
01252                 }
01253 /*     end of the p-loop */
01254 /*     end of doing the block ( ibr, ibr ) */
01255 /* L1002: */
01256             }
01257 /*     end of ir1-loop */
01258 
01259 /* ... go to the off diagonal blocks */
01260 
01261             igl = (ibr - 1) * kbl + 1;
01262 
01263             i__2 = nbl;
01264             for (jbc = ibr + 1; jbc <= i__2; ++jbc) {
01265 
01266                 jgl = (jbc - 1) * kbl + 1;
01267 
01268 /*        doing the block at ( ibr, jbc ) */
01269 
01270                 ijblsk = 0;
01271 /* Computing MIN */
01272                 i__4 = igl + kbl - 1;
01273                 i__3 = min(i__4,*n);
01274                 for (p = igl; p <= i__3; ++p) {
01275 
01276                     aapp = sva[p];
01277                     if (aapp > 0.) {
01278 
01279                         pskipped = 0;
01280 
01281 /* Computing MIN */
01282                         i__5 = jgl + kbl - 1;
01283                         i__4 = min(i__5,*n);
01284                         for (q = jgl; q <= i__4; ++q) {
01285 
01286                             aaqq = sva[q];
01287                             if (aaqq > 0.) {
01288                                 aapp0 = aapp;
01289 
01290 /*     -#- M x 2 Jacobi SVD -#- */
01291 
01292 /*        Safe Gram matrix computation */
01293 
01294                                 if (aaqq >= 1.) {
01295                                     if (aapp >= aaqq) {
01296                                         rotok = small * aapp <= aaqq;
01297                                     } else {
01298                                         rotok = small * aaqq <= aapp;
01299                                     }
01300                                     if (aapp < big / aaqq) {
01301                                         aapq = ddot_(m, &a[p * a_dim1 + 1], &
01302                                                 c__1, &a[q * a_dim1 + 1], &
01303                                                 c__1) * work[p] * work[q] / 
01304                                                 aaqq / aapp;
01305                                     } else {
01306                                         dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
01307                                                 work[*n + 1], &c__1);
01308                                         dlascl_("G", &c__0, &c__0, &aapp, &
01309                                                 work[p], m, &c__1, &work[*n + 
01310                                                 1], lda, &ierr);
01311                                         aapq = ddot_(m, &work[*n + 1], &c__1, 
01312                                                 &a[q * a_dim1 + 1], &c__1) * 
01313                                                 work[q] / aaqq;
01314                                     }
01315                                 } else {
01316                                     if (aapp >= aaqq) {
01317                                         rotok = aapp <= aaqq / small;
01318                                     } else {
01319                                         rotok = aaqq <= aapp / small;
01320                                     }
01321                                     if (aapp > small / aaqq) {
01322                                         aapq = ddot_(m, &a[p * a_dim1 + 1], &
01323                                                 c__1, &a[q * a_dim1 + 1], &
01324                                                 c__1) * work[p] * work[q] / 
01325                                                 aaqq / aapp;
01326                                     } else {
01327                                         dcopy_(m, &a[q * a_dim1 + 1], &c__1, &
01328                                                 work[*n + 1], &c__1);
01329                                         dlascl_("G", &c__0, &c__0, &aaqq, &
01330                                                 work[q], m, &c__1, &work[*n + 
01331                                                 1], lda, &ierr);
01332                                         aapq = ddot_(m, &work[*n + 1], &c__1, 
01333                                                 &a[p * a_dim1 + 1], &c__1) * 
01334                                                 work[p] / aapp;
01335                                     }
01336                                 }
01337 
01338 /* Computing MAX */
01339                                 d__1 = mxaapq, d__2 = abs(aapq);
01340                                 mxaapq = max(d__1,d__2);
01341 
01342 /*        TO rotate or NOT to rotate, THAT is the question ... */
01343 
01344                                 if (abs(aapq) > tol) {
01345                                     notrot = 0;
01346 /* [RTD]      ROTATED  = ROTATED + 1 */
01347                                     pskipped = 0;
01348                                     ++iswrot;
01349 
01350                                     if (rotok) {
01351 
01352                                         aqoap = aaqq / aapp;
01353                                         apoaq = aapp / aaqq;
01354                                         theta = (d__1 = aqoap - apoaq, abs(
01355                                                 d__1)) * -.5 / aapq;
01356                                         if (aaqq > aapp0) {
01357                                             theta = -theta;
01358                                         }
01359 
01360                                         if (abs(theta) > bigtheta) {
01361                                             t = .5 / theta;
01362                                             fastr[2] = t * work[p] / work[q];
01363                                             fastr[3] = -t * work[q] / work[p];
01364                                             drotm_(m, &a[p * a_dim1 + 1], &
01365                                                     c__1, &a[q * a_dim1 + 1], 
01366                                                     &c__1, fastr);
01367                                             if (rsvec) {
01368                           drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
01369                                   v_dim1 + 1], &c__1, fastr);
01370                                             }
01371 /* Computing MAX */
01372                                             d__1 = 0., d__2 = t * apoaq * 
01373                                                     aapq + 1.;
01374                                             sva[q] = aaqq * sqrt((max(d__1,
01375                                                     d__2)));
01376 /* Computing MAX */
01377                                             d__1 = 0., d__2 = 1. - t * aqoap *
01378                                                      aapq;
01379                                             aapp *= sqrt((max(d__1,d__2)));
01380 /* Computing MAX */
01381                                             d__1 = mxsinj, d__2 = abs(t);
01382                                             mxsinj = max(d__1,d__2);
01383                                         } else {
01384 
01385 /*                 .. choose correct signum for THETA and rotate */
01386 
01387                                             thsign = -d_sign(&c_b18, &aapq);
01388                                             if (aaqq > aapp0) {
01389                           thsign = -thsign;
01390                                             }
01391                                             t = 1. / (theta + thsign * sqrt(
01392                                                     theta * theta + 1.));
01393                                             cs = sqrt(1. / (t * t + 1.));
01394                                             sn = t * cs;
01395 /* Computing MAX */
01396                                             d__1 = mxsinj, d__2 = abs(sn);
01397                                             mxsinj = max(d__1,d__2);
01398 /* Computing MAX */
01399                                             d__1 = 0., d__2 = t * apoaq * 
01400                                                     aapq + 1.;
01401                                             sva[q] = aaqq * sqrt((max(d__1,
01402                                                     d__2)));
01403                                             aapp *= sqrt(1. - t * aqoap * 
01404                                                     aapq);
01405 
01406                                             apoaq = work[p] / work[q];
01407                                             aqoap = work[q] / work[p];
01408                                             if (work[p] >= 1.) {
01409 
01410                           if (work[q] >= 1.) {
01411                               fastr[2] = t * apoaq;
01412                               fastr[3] = -t * aqoap;
01413                               work[p] *= cs;
01414                               work[q] *= cs;
01415                               drotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q * 
01416                                       a_dim1 + 1], &c__1, fastr);
01417                               if (rsvec) {
01418                                   drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
01419                                           q * v_dim1 + 1], &c__1, fastr);
01420                               }
01421                           } else {
01422                               d__1 = -t * aqoap;
01423                               daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
01424                                       p * a_dim1 + 1], &c__1);
01425                               d__1 = cs * sn * apoaq;
01426                               daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
01427                                       q * a_dim1 + 1], &c__1);
01428                               if (rsvec) {
01429                                   d__1 = -t * aqoap;
01430                                   daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
01431                                           c__1, &v[p * v_dim1 + 1], &c__1);
01432                                   d__1 = cs * sn * apoaq;
01433                                   daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
01434                                           c__1, &v[q * v_dim1 + 1], &c__1);
01435                               }
01436                               work[p] *= cs;
01437                               work[q] /= cs;
01438                           }
01439                                             } else {
01440                           if (work[q] >= 1.) {
01441                               d__1 = t * apoaq;
01442                               daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
01443                                       q * a_dim1 + 1], &c__1);
01444                               d__1 = -cs * sn * aqoap;
01445                               daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
01446                                       p * a_dim1 + 1], &c__1);
01447                               if (rsvec) {
01448                                   d__1 = t * apoaq;
01449                                   daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
01450                                           c__1, &v[q * v_dim1 + 1], &c__1);
01451                                   d__1 = -cs * sn * aqoap;
01452                                   daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
01453                                           c__1, &v[p * v_dim1 + 1], &c__1);
01454                               }
01455                               work[p] /= cs;
01456                               work[q] *= cs;
01457                           } else {
01458                               if (work[p] >= work[q]) {
01459                                   d__1 = -t * aqoap;
01460                                   daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, 
01461                                           &a[p * a_dim1 + 1], &c__1);
01462                                   d__1 = cs * sn * apoaq;
01463                                   daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, 
01464                                           &a[q * a_dim1 + 1], &c__1);
01465                                   work[p] *= cs;
01466                                   work[q] /= cs;
01467                                   if (rsvec) {
01468                                       d__1 = -t * aqoap;
01469                                       daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], 
01470                                               &c__1, &v[p * v_dim1 + 1], &
01471                                               c__1);
01472                                       d__1 = cs * sn * apoaq;
01473                                       daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], 
01474                                               &c__1, &v[q * v_dim1 + 1], &
01475                                               c__1);
01476                                   }
01477                               } else {
01478                                   d__1 = t * apoaq;
01479                                   daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, 
01480                                           &a[q * a_dim1 + 1], &c__1);
01481                                   d__1 = -cs * sn * aqoap;
01482                                   daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, 
01483                                           &a[p * a_dim1 + 1], &c__1);
01484                                   work[p] /= cs;
01485                                   work[q] *= cs;
01486                                   if (rsvec) {
01487                                       d__1 = t * apoaq;
01488                                       daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], 
01489                                               &c__1, &v[q * v_dim1 + 1], &
01490                                               c__1);
01491                                       d__1 = -cs * sn * aqoap;
01492                                       daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], 
01493                                               &c__1, &v[p * v_dim1 + 1], &
01494                                               c__1);
01495                                   }
01496                               }
01497                           }
01498                                             }
01499                                         }
01500 
01501                                     } else {
01502                                         if (aapp > aaqq) {
01503                                             dcopy_(m, &a[p * a_dim1 + 1], &
01504                                                     c__1, &work[*n + 1], &
01505                                                     c__1);
01506                                             dlascl_("G", &c__0, &c__0, &aapp, 
01507                                                     &c_b18, m, &c__1, &work[*
01508                                                     n + 1], lda, &ierr);
01509                                             dlascl_("G", &c__0, &c__0, &aaqq, 
01510                                                     &c_b18, m, &c__1, &a[q * 
01511                                                     a_dim1 + 1], lda, &ierr);
01512                                             temp1 = -aapq * work[p] / work[q];
01513                                             daxpy_(m, &temp1, &work[*n + 1], &
01514                                                     c__1, &a[q * a_dim1 + 1], 
01515                                                     &c__1);
01516                                             dlascl_("G", &c__0, &c__0, &c_b18, 
01517                                                      &aaqq, m, &c__1, &a[q * 
01518                                                     a_dim1 + 1], lda, &ierr);
01519 /* Computing MAX */
01520                                             d__1 = 0., d__2 = 1. - aapq * 
01521                                                     aapq;
01522                                             sva[q] = aaqq * sqrt((max(d__1,
01523                                                     d__2)));
01524                                             mxsinj = max(mxsinj,sfmin);
01525                                         } else {
01526                                             dcopy_(m, &a[q * a_dim1 + 1], &
01527                                                     c__1, &work[*n + 1], &
01528                                                     c__1);
01529                                             dlascl_("G", &c__0, &c__0, &aaqq, 
01530                                                     &c_b18, m, &c__1, &work[*
01531                                                     n + 1], lda, &ierr);
01532                                             dlascl_("G", &c__0, &c__0, &aapp, 
01533                                                     &c_b18, m, &c__1, &a[p * 
01534                                                     a_dim1 + 1], lda, &ierr);
01535                                             temp1 = -aapq * work[q] / work[p];
01536                                             daxpy_(m, &temp1, &work[*n + 1], &
01537                                                     c__1, &a[p * a_dim1 + 1], 
01538                                                     &c__1);
01539                                             dlascl_("G", &c__0, &c__0, &c_b18, 
01540                                                      &aapp, m, &c__1, &a[p * 
01541                                                     a_dim1 + 1], lda, &ierr);
01542 /* Computing MAX */
01543                                             d__1 = 0., d__2 = 1. - aapq * 
01544                                                     aapq;
01545                                             sva[p] = aapp * sqrt((max(d__1,
01546                                                     d__2)));
01547                                             mxsinj = max(mxsinj,sfmin);
01548                                         }
01549                                     }
01550 /*           END IF ROTOK THEN ... ELSE */
01551 
01552 /*           In the case of cancellation in updating SVA(q) */
01553 /*           .. recompute SVA(q) */
01554 /* Computing 2nd power */
01555                                     d__1 = sva[q] / aaqq;
01556                                     if (d__1 * d__1 <= rooteps) {
01557                                         if (aaqq < rootbig && aaqq > 
01558                                                 rootsfmin) {
01559                                             sva[q] = dnrm2_(m, &a[q * a_dim1 
01560                                                     + 1], &c__1) * work[q];
01561                                         } else {
01562                                             t = 0.;
01563                                             aaqq = 0.;
01564                                             dlassq_(m, &a[q * a_dim1 + 1], &
01565                                                     c__1, &t, &aaqq);
01566                                             sva[q] = t * sqrt(aaqq) * work[q];
01567                                         }
01568                                     }
01569 /* Computing 2nd power */
01570                                     d__1 = aapp / aapp0;
01571                                     if (d__1 * d__1 <= rooteps) {
01572                                         if (aapp < rootbig && aapp > 
01573                                                 rootsfmin) {
01574                                             aapp = dnrm2_(m, &a[p * a_dim1 + 
01575                                                     1], &c__1) * work[p];
01576                                         } else {
01577                                             t = 0.;
01578                                             aapp = 0.;
01579                                             dlassq_(m, &a[p * a_dim1 + 1], &
01580                                                     c__1, &t, &aapp);
01581                                             aapp = t * sqrt(aapp) * work[p];
01582                                         }
01583                                         sva[p] = aapp;
01584                                     }
01585 /*              end of OK rotation */
01586                                 } else {
01587                                     ++notrot;
01588 /* [RTD]      SKIPPED  = SKIPPED  + 1 */
01589                                     ++pskipped;
01590                                     ++ijblsk;
01591                                 }
01592                             } else {
01593                                 ++notrot;
01594                                 ++pskipped;
01595                                 ++ijblsk;
01596                             }
01597 
01598                             if (i__ <= swband && ijblsk >= blskip) {
01599                                 sva[p] = aapp;
01600                                 notrot = 0;
01601                                 goto L2011;
01602                             }
01603                             if (i__ <= swband && pskipped > rowskip) {
01604                                 aapp = -aapp;
01605                                 notrot = 0;
01606                                 goto L2203;
01607                             }
01608 
01609 /* L2200: */
01610                         }
01611 /*        end of the q-loop */
01612 L2203:
01613 
01614                         sva[p] = aapp;
01615 
01616                     } else {
01617 
01618                         if (aapp == 0.) {
01619 /* Computing MIN */
01620                             i__4 = jgl + kbl - 1;
01621                             notrot = notrot + min(i__4,*n) - jgl + 1;
01622                         }
01623                         if (aapp < 0.) {
01624                             notrot = 0;
01625                         }
01626 
01627                     }
01628 
01629 /* L2100: */
01630                 }
01631 /*     end of the p-loop */
01632 /* L2010: */
01633             }
01634 /*     end of the jbc-loop */
01635 L2011:
01636 /* 2011 bailed out of the jbc-loop */
01637 /* Computing MIN */
01638             i__3 = igl + kbl - 1;
01639             i__2 = min(i__3,*n);
01640             for (p = igl; p <= i__2; ++p) {
01641                 sva[p] = (d__1 = sva[p], abs(d__1));
01642 /* L2012: */
01643             }
01644 /* ** */
01645 /* L2000: */
01646         }
01647 /* 2000 :: end of the ibr-loop */
01648 
01649 /*     .. update SVA(N) */
01650         if (sva[*n] < rootbig && sva[*n] > rootsfmin) {
01651             sva[*n] = dnrm2_(m, &a[*n * a_dim1 + 1], &c__1) * work[*n];
01652         } else {
01653             t = 0.;
01654             aapp = 0.;
01655             dlassq_(m, &a[*n * a_dim1 + 1], &c__1, &t, &aapp);
01656             sva[*n] = t * sqrt(aapp) * work[*n];
01657         }
01658 
01659 /*     Additional steering devices */
01660 
01661         if (i__ < swband && (mxaapq <= roottol || iswrot <= *n)) {
01662             swband = i__;
01663         }
01664 
01665         if (i__ > swband + 1 && mxaapq < sqrt((doublereal) (*n)) * tol && (
01666                 doublereal) (*n) * mxaapq * mxsinj < tol) {
01667             goto L1994;
01668         }
01669 
01670         if (notrot >= emptsw) {
01671             goto L1994;
01672         }
01673 
01674 /* L1993: */
01675     }
01676 /*     end i=1:NSWEEP loop */
01677 
01678 /* #:( Reaching this point means that the procedure has not converged. */
01679     *info = 29;
01680     goto L1995;
01681 
01682 L1994:
01683 /* #:) Reaching this point means numerical convergence after the i-th */
01684 /*     sweep. */
01685 
01686     *info = 0;
01687 /* #:) INFO = 0 confirms successful iterations. */
01688 L1995:
01689 
01690 /*     Sort the singular values and find how many are above */
01691 /*     the underflow threshold. */
01692 
01693     n2 = 0;
01694     n4 = 0;
01695     i__1 = *n - 1;
01696     for (p = 1; p <= i__1; ++p) {
01697         i__2 = *n - p + 1;
01698         q = idamax_(&i__2, &sva[p], &c__1) + p - 1;
01699         if (p != q) {
01700             temp1 = sva[p];
01701             sva[p] = sva[q];
01702             sva[q] = temp1;
01703             temp1 = work[p];
01704             work[p] = work[q];
01705             work[q] = temp1;
01706             dswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 1], &c__1);
01707             if (rsvec) {
01708                 dswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * v_dim1 + 1], &
01709                         c__1);
01710             }
01711         }
01712         if (sva[p] != 0.) {
01713             ++n4;
01714             if (sva[p] * scale > sfmin) {
01715                 ++n2;
01716             }
01717         }
01718 /* L5991: */
01719     }
01720     if (sva[*n] != 0.) {
01721         ++n4;
01722         if (sva[*n] * scale > sfmin) {
01723             ++n2;
01724         }
01725     }
01726 
01727 /*     Normalize the left singular vectors. */
01728 
01729     if (lsvec || uctol) {
01730         i__1 = n2;
01731         for (p = 1; p <= i__1; ++p) {
01732             d__1 = work[p] / sva[p];
01733             dscal_(m, &d__1, &a[p * a_dim1 + 1], &c__1);
01734 /* L1998: */
01735         }
01736     }
01737 
01738 /*     Scale the product of Jacobi rotations (assemble the fast rotations). */
01739 
01740     if (rsvec) {
01741         if (applv) {
01742             i__1 = *n;
01743             for (p = 1; p <= i__1; ++p) {
01744                 dscal_(&mvl, &work[p], &v[p * v_dim1 + 1], &c__1);
01745 /* L2398: */
01746             }
01747         } else {
01748             i__1 = *n;
01749             for (p = 1; p <= i__1; ++p) {
01750                 temp1 = 1. / dnrm2_(&mvl, &v[p * v_dim1 + 1], &c__1);
01751                 dscal_(&mvl, &temp1, &v[p * v_dim1 + 1], &c__1);
01752 /* L2399: */
01753             }
01754         }
01755     }
01756 
01757 /*     Undo scaling, if necessary (and possible). */
01758     if (scale > 1. && sva[1] < big / scale || scale < 1. && sva[n2] > sfmin / 
01759             scale) {
01760         i__1 = *n;
01761         for (p = 1; p <= i__1; ++p) {
01762             sva[p] = scale * sva[p];
01763 /* L2400: */
01764         }
01765         scale = 1.;
01766     }
01767 
01768     work[1] = scale;
01769 /*     The singular values of A are SCALE*SVA(1:N). If SCALE.NE.ONE */
01770 /*     then some of the singular values may overflow or underflow and */
01771 /*     the spectrum is given in this factored representation. */
01772 
01773     work[2] = (doublereal) n4;
01774 /*     N4 is the number of computed nonzero singular values of A. */
01775 
01776     work[3] = (doublereal) n2;
01777 /*     N2 is the number of singular values of A greater than SFMIN. */
01778 /*     If N2<N, SVA(N2:N) contains ZEROS and/or denormalized numbers */
01779 /*     that may carry some information. */
01780 
01781     work[4] = (doublereal) i__;
01782 /*     i is the index of the last sweep before declaring convergence. */
01783 
01784     work[5] = mxaapq;
01785 /*     MXAAPQ is the largest absolute value of scaled pivots in the */
01786 /*     last sweep */
01787 
01788     work[6] = mxsinj;
01789 /*     MXSINJ is the largest absolute value of the sines of Jacobi angles */
01790 /*     in the last sweep */
01791 
01792     return 0;
01793 /*     .. */
01794 /*     .. END OF DGESVJ */
01795 /*     .. */
01796 } /* dgesvj_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:44