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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:07