LAPACK  3.4.2
LAPACK: Linear Algebra PACKage
 All Files Functions Groups
dgsvj1.f
Go to the documentation of this file.
1 *> \brief \b DGSVJ1 pre-processor for the routine sgesvj, applies Jacobi rotations targeting only particular pivots.
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download DGSVJ1 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgsvj1.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgsvj1.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgsvj1.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE DGSVJ1( JOBV, M, N, N1, A, LDA, D, SVA, MV, V, LDV,
22 * EPS, SFMIN, TOL, NSWEEP, WORK, LWORK, INFO )
23 *
24 * .. Scalar Arguments ..
25 * DOUBLE PRECISION EPS, SFMIN, TOL
26 * INTEGER INFO, LDA, LDV, LWORK, M, MV, N, N1, NSWEEP
27 * CHARACTER*1 JOBV
28 * ..
29 * .. Array Arguments ..
30 * DOUBLE PRECISION A( LDA, * ), D( N ), SVA( N ), V( LDV, * ),
31 * $ WORK( LWORK )
32 * ..
33 *
34 *
35 *> \par Purpose:
36 * =============
37 *>
38 *> \verbatim
39 *>
40 *> DGSVJ1 is called from SGESVJ as a pre-processor and that is its main
41 *> purpose. It applies Jacobi rotations in the same way as SGESVJ does, but
42 *> it targets only particular pivots and it does not check convergence
43 *> (stopping criterion). Few tunning parameters (marked by [TP]) are
44 *> available for the implementer.
45 *>
46 *> Further Details
47 *> ~~~~~~~~~~~~~~~
48 *> DGSVJ1 applies few sweeps of Jacobi rotations in the column space of
49 *> the input M-by-N matrix A. The pivot pairs are taken from the (1,2)
50 *> off-diagonal block in the corresponding N-by-N Gram matrix A^T * A. The
51 *> block-entries (tiles) of the (1,2) off-diagonal block are marked by the
52 *> [x]'s in the following scheme:
53 *>
54 *> | * * * [x] [x] [x]|
55 *> | * * * [x] [x] [x]| Row-cycling in the nblr-by-nblc [x] blocks.
56 *> | * * * [x] [x] [x]| Row-cyclic pivoting inside each [x] block.
57 *> |[x] [x] [x] * * * |
58 *> |[x] [x] [x] * * * |
59 *> |[x] [x] [x] * * * |
60 *>
61 *> In terms of the columns of A, the first N1 columns are rotated 'against'
62 *> the remaining N-N1 columns, trying to increase the angle between the
63 *> corresponding subspaces. The off-diagonal block is N1-by(N-N1) and it is
64 *> tiled using quadratic tiles of side KBL. Here, KBL is a tunning parmeter.
65 *> The number of sweeps is given in NSWEEP and the orthogonality threshold
66 *> is given in TOL.
67 *> \endverbatim
68 *
69 * Arguments:
70 * ==========
71 *
72 *> \param[in] JOBV
73 *> \verbatim
74 *> JOBV is CHARACTER*1
75 *> Specifies whether the output from this procedure is used
76 *> to compute the matrix V:
77 *> = 'V': the product of the Jacobi rotations is accumulated
78 *> by postmulyiplying the N-by-N array V.
79 *> (See the description of V.)
80 *> = 'A': the product of the Jacobi rotations is accumulated
81 *> by postmulyiplying the MV-by-N array V.
82 *> (See the descriptions of MV and V.)
83 *> = 'N': the Jacobi rotations are not accumulated.
84 *> \endverbatim
85 *>
86 *> \param[in] M
87 *> \verbatim
88 *> M is INTEGER
89 *> The number of rows of the input matrix A. M >= 0.
90 *> \endverbatim
91 *>
92 *> \param[in] N
93 *> \verbatim
94 *> N is INTEGER
95 *> The number of columns of the input matrix A.
96 *> M >= N >= 0.
97 *> \endverbatim
98 *>
99 *> \param[in] N1
100 *> \verbatim
101 *> N1 is INTEGER
102 *> N1 specifies the 2 x 2 block partition, the first N1 columns are
103 *> rotated 'against' the remaining N-N1 columns of A.
104 *> \endverbatim
105 *>
106 *> \param[in,out] A
107 *> \verbatim
108 *> A is DOUBLE PRECISION array, dimension (LDA,N)
109 *> On entry, M-by-N matrix A, such that A*diag(D) represents
110 *> the input matrix.
111 *> On exit,
112 *> A_onexit * D_onexit represents the input matrix A*diag(D)
113 *> post-multiplied by a sequence of Jacobi rotations, where the
114 *> rotation threshold and the total number of sweeps are given in
115 *> TOL and NSWEEP, respectively.
116 *> (See the descriptions of N1, D, TOL and NSWEEP.)
117 *> \endverbatim
118 *>
119 *> \param[in] LDA
120 *> \verbatim
121 *> LDA is INTEGER
122 *> The leading dimension of the array A. LDA >= max(1,M).
123 *> \endverbatim
124 *>
125 *> \param[in,out] D
126 *> \verbatim
127 *> D is DOUBLE PRECISION array, dimension (N)
128 *> The array D accumulates the scaling factors from the fast scaled
129 *> Jacobi rotations.
130 *> On entry, A*diag(D) represents the input matrix.
131 *> On exit, A_onexit*diag(D_onexit) represents the input matrix
132 *> post-multiplied by a sequence of Jacobi rotations, where the
133 *> rotation threshold and the total number of sweeps are given in
134 *> TOL and NSWEEP, respectively.
135 *> (See the descriptions of N1, A, TOL and NSWEEP.)
136 *> \endverbatim
137 *>
138 *> \param[in,out] SVA
139 *> \verbatim
140 *> SVA is DOUBLE PRECISION array, dimension (N)
141 *> On entry, SVA contains the Euclidean norms of the columns of
142 *> the matrix A*diag(D).
143 *> On exit, SVA contains the Euclidean norms of the columns of
144 *> the matrix onexit*diag(D_onexit).
145 *> \endverbatim
146 *>
147 *> \param[in] MV
148 *> \verbatim
149 *> MV is INTEGER
150 *> If JOBV .EQ. 'A', then MV rows of V are post-multipled by a
151 *> sequence of Jacobi rotations.
152 *> If JOBV = 'N', then MV is not referenced.
153 *> \endverbatim
154 *>
155 *> \param[in,out] V
156 *> \verbatim
157 *> V is DOUBLE PRECISION array, dimension (LDV,N)
158 *> If JOBV .EQ. 'V' then N rows of V are post-multipled by a
159 *> sequence of Jacobi rotations.
160 *> If JOBV .EQ. 'A' then MV rows of V are post-multipled by a
161 *> sequence of Jacobi rotations.
162 *> If JOBV = 'N', then V is not referenced.
163 *> \endverbatim
164 *>
165 *> \param[in] LDV
166 *> \verbatim
167 *> LDV is INTEGER
168 *> The leading dimension of the array V, LDV >= 1.
169 *> If JOBV = 'V', LDV .GE. N.
170 *> If JOBV = 'A', LDV .GE. MV.
171 *> \endverbatim
172 *>
173 *> \param[in] EPS
174 *> \verbatim
175 *> EPS is DOUBLE PRECISION
176 *> EPS = DLAMCH('Epsilon')
177 *> \endverbatim
178 *>
179 *> \param[in] SFMIN
180 *> \verbatim
181 *> SFMIN is DOUBLE PRECISION
182 *> SFMIN = DLAMCH('Safe Minimum')
183 *> \endverbatim
184 *>
185 *> \param[in] TOL
186 *> \verbatim
187 *> TOL is DOUBLE PRECISION
188 *> TOL is the threshold for Jacobi rotations. For a pair
189 *> A(:,p), A(:,q) of pivot columns, the Jacobi rotation is
190 *> applied only if DABS(COS(angle(A(:,p),A(:,q)))) .GT. TOL.
191 *> \endverbatim
192 *>
193 *> \param[in] NSWEEP
194 *> \verbatim
195 *> NSWEEP is INTEGER
196 *> NSWEEP is the number of sweeps of Jacobi rotations to be
197 *> performed.
198 *> \endverbatim
199 *>
200 *> \param[out] WORK
201 *> \verbatim
202 *> WORK is DOUBLE PRECISION array, dimension (LWORK)
203 *> \endverbatim
204 *>
205 *> \param[in] LWORK
206 *> \verbatim
207 *> LWORK is INTEGER
208 *> LWORK is the dimension of WORK. LWORK .GE. M.
209 *> \endverbatim
210 *>
211 *> \param[out] INFO
212 *> \verbatim
213 *> INFO is INTEGER
214 *> = 0 : successful exit.
215 *> < 0 : if INFO = -i, then the i-th argument had an illegal value
216 *> \endverbatim
217 *
218 * Authors:
219 * ========
220 *
221 *> \author Univ. of Tennessee
222 *> \author Univ. of California Berkeley
223 *> \author Univ. of Colorado Denver
224 *> \author NAG Ltd.
225 *
226 *> \date September 2012
227 *
228 *> \ingroup doubleOTHERcomputational
229 *
230 *> \par Contributors:
231 * ==================
232 *>
233 *> Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany)
234 *
235 * =====================================================================
236  SUBROUTINE dgsvj1( JOBV, M, N, N1, A, LDA, D, SVA, MV, V, LDV,
237  $ eps, sfmin, tol, nsweep, work, lwork, info )
238 *
239 * -- LAPACK computational routine (version 3.4.2) --
240 * -- LAPACK is a software package provided by Univ. of Tennessee, --
241 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
242 * September 2012
243 *
244 * .. Scalar Arguments ..
245  DOUBLE PRECISION eps, sfmin, tol
246  INTEGER info, lda, ldv, lwork, m, mv, n, n1, nsweep
247  CHARACTER*1 jobv
248 * ..
249 * .. Array Arguments ..
250  DOUBLE PRECISION a( lda, * ), d( n ), sva( n ), v( ldv, * ),
251  $ work( lwork )
252 * ..
253 *
254 * =====================================================================
255 *
256 * .. Local Parameters ..
257  DOUBLE PRECISION zero, half, one
258  parameter( zero = 0.0d0, half = 0.5d0, one = 1.0d0 )
259 * ..
260 * .. Local Scalars ..
261  DOUBLE PRECISION aapp, aapp0, aapq, aaqq, apoaq, aqoap, big,
262  $ bigtheta, cs, large, mxaapq, mxsinj, rootbig,
263  $ rooteps, rootsfmin, roottol, small, sn, t,
264  $ temp1, theta, thsign
265  INTEGER blskip, emptsw, i, ibr, igl, ierr, ijblsk,
266  $ iswrot, jbc, jgl, kbl, mvl, notrot, nblc, nblr,
267  $ p, pskipped, q, rowskip, swband
268  LOGICAL applv, rotok, rsvec
269 * ..
270 * .. Local Arrays ..
271  DOUBLE PRECISION fastr( 5 )
272 * ..
273 * .. Intrinsic Functions ..
274  INTRINSIC dabs, dmax1, dble, min0, dsign, dsqrt
275 * ..
276 * .. External Functions ..
277  DOUBLE PRECISION ddot, dnrm2
278  INTEGER idamax
279  LOGICAL lsame
280  EXTERNAL idamax, lsame, ddot, dnrm2
281 * ..
282 * .. External Subroutines ..
283  EXTERNAL daxpy, dcopy, dlascl, dlassq, drotm, dswap
284 * ..
285 * .. Executable Statements ..
286 *
287 * Test the input parameters.
288 *
289  applv = lsame( jobv, 'A' )
290  rsvec = lsame( jobv, 'V' )
291  IF( .NOT.( rsvec .OR. applv .OR. lsame( jobv, 'N' ) ) ) THEN
292  info = -1
293  ELSE IF( m.LT.0 ) THEN
294  info = -2
295  ELSE IF( ( n.LT.0 ) .OR. ( n.GT.m ) ) THEN
296  info = -3
297  ELSE IF( n1.LT.0 ) THEN
298  info = -4
299  ELSE IF( lda.LT.m ) THEN
300  info = -6
301  ELSE IF( ( rsvec.OR.applv ) .AND. ( mv.LT.0 ) ) THEN
302  info = -9
303  ELSE IF( ( rsvec.AND.( ldv.LT.n ) ).OR.
304  $ ( applv.AND.( ldv.LT.mv ) ) ) THEN
305  info = -11
306  ELSE IF( tol.LE.eps ) THEN
307  info = -14
308  ELSE IF( nsweep.LT.0 ) THEN
309  info = -15
310  ELSE IF( lwork.LT.m ) THEN
311  info = -17
312  ELSE
313  info = 0
314  END IF
315 *
316 * #:(
317  IF( info.NE.0 ) THEN
318  CALL xerbla( 'DGSVJ1', -info )
319  return
320  END IF
321 *
322  IF( rsvec ) THEN
323  mvl = n
324  ELSE IF( applv ) THEN
325  mvl = mv
326  END IF
327  rsvec = rsvec .OR. applv
328 
329  rooteps = dsqrt( eps )
330  rootsfmin = dsqrt( sfmin )
331  small = sfmin / eps
332  big = one / sfmin
333  rootbig = one / rootsfmin
334  large = big / dsqrt( dble( m*n ) )
335  bigtheta = one / rooteps
336  roottol = dsqrt( tol )
337 *
338 * .. Initialize the right singular vector matrix ..
339 *
340 * RSVEC = LSAME( JOBV, 'Y' )
341 *
342  emptsw = n1*( n-n1 )
343  notrot = 0
344  fastr( 1 ) = zero
345 *
346 * .. Row-cyclic pivot strategy with de Rijk's pivoting ..
347 *
348  kbl = min0( 8, n )
349  nblr = n1 / kbl
350  IF( ( nblr*kbl ).NE.n1 )nblr = nblr + 1
351 
352 * .. the tiling is nblr-by-nblc [tiles]
353 
354  nblc = ( n-n1 ) / kbl
355  IF( ( nblc*kbl ).NE.( n-n1 ) )nblc = nblc + 1
356  blskip = ( kbl**2 ) + 1
357 *[TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL.
358 
359  rowskip = min0( 5, kbl )
360 *[TP] ROWSKIP is a tuning parameter.
361  swband = 0
362 *[TP] SWBAND is a tuning parameter. It is meaningful and effective
363 * if SGESVJ is used as a computational routine in the preconditioned
364 * Jacobi SVD algorithm SGESVJ.
365 *
366 *
367 * | * * * [x] [x] [x]|
368 * | * * * [x] [x] [x]| Row-cycling in the nblr-by-nblc [x] blocks.
369 * | * * * [x] [x] [x]| Row-cyclic pivoting inside each [x] block.
370 * |[x] [x] [x] * * * |
371 * |[x] [x] [x] * * * |
372 * |[x] [x] [x] * * * |
373 *
374 *
375  DO 1993 i = 1, nsweep
376 * .. go go go ...
377 *
378  mxaapq = zero
379  mxsinj = zero
380  iswrot = 0
381 *
382  notrot = 0
383  pskipped = 0
384 *
385  DO 2000 ibr = 1, nblr
386 
387  igl = ( ibr-1 )*kbl + 1
388 *
389 *
390 *........................................................
391 * ... go to the off diagonal blocks
392 
393  igl = ( ibr-1 )*kbl + 1
394 
395  DO 2010 jbc = 1, nblc
396 
397  jgl = n1 + ( jbc-1 )*kbl + 1
398 
399 * doing the block at ( ibr, jbc )
400 
401  ijblsk = 0
402  DO 2100 p = igl, min0( igl+kbl-1, n1 )
403 
404  aapp = sva( p )
405 
406  IF( aapp.GT.zero ) THEN
407 
408  pskipped = 0
409 
410  DO 2200 q = jgl, min0( jgl+kbl-1, n )
411 *
412  aaqq = sva( q )
413 
414  IF( aaqq.GT.zero ) THEN
415  aapp0 = aapp
416 *
417 * .. M x 2 Jacobi SVD ..
418 *
419 * .. Safe Gram matrix computation ..
420 *
421  IF( aaqq.GE.one ) THEN
422  IF( aapp.GE.aaqq ) THEN
423  rotok = ( small*aapp ).LE.aaqq
424  ELSE
425  rotok = ( small*aaqq ).LE.aapp
426  END IF
427  IF( aapp.LT.( big / aaqq ) ) THEN
428  aapq = ( ddot( m, a( 1, p ), 1, a( 1,
429  $ q ), 1 )*d( p )*d( q ) / aaqq )
430  $ / aapp
431  ELSE
432  CALL dcopy( m, a( 1, p ), 1, work, 1 )
433  CALL dlascl( 'G', 0, 0, aapp, d( p ),
434  $ m, 1, work, lda, ierr )
435  aapq = ddot( m, work, 1, a( 1, q ),
436  $ 1 )*d( q ) / aaqq
437  END IF
438  ELSE
439  IF( aapp.GE.aaqq ) THEN
440  rotok = aapp.LE.( aaqq / small )
441  ELSE
442  rotok = aaqq.LE.( aapp / small )
443  END IF
444  IF( aapp.GT.( small / aaqq ) ) THEN
445  aapq = ( ddot( m, a( 1, p ), 1, a( 1,
446  $ q ), 1 )*d( p )*d( q ) / aaqq )
447  $ / aapp
448  ELSE
449  CALL dcopy( m, a( 1, q ), 1, work, 1 )
450  CALL dlascl( 'G', 0, 0, aaqq, d( q ),
451  $ m, 1, work, lda, ierr )
452  aapq = ddot( m, work, 1, a( 1, p ),
453  $ 1 )*d( p ) / aapp
454  END IF
455  END IF
456 
457  mxaapq = dmax1( mxaapq, dabs( aapq ) )
458 
459 * TO rotate or NOT to rotate, THAT is the question ...
460 *
461  IF( dabs( aapq ).GT.tol ) THEN
462  notrot = 0
463 * ROTATED = ROTATED + 1
464  pskipped = 0
465  iswrot = iswrot + 1
466 *
467  IF( rotok ) THEN
468 *
469  aqoap = aaqq / aapp
470  apoaq = aapp / aaqq
471  theta = -half*dabs(aqoap-apoaq) / aapq
472  IF( aaqq.GT.aapp0 )theta = -theta
473 
474  IF( dabs( theta ).GT.bigtheta ) THEN
475  t = half / theta
476  fastr( 3 ) = t*d( p ) / d( q )
477  fastr( 4 ) = -t*d( q ) / d( p )
478  CALL drotm( m, a( 1, p ), 1,
479  $ a( 1, q ), 1, fastr )
480  IF( rsvec )CALL drotm( mvl,
481  $ v( 1, p ), 1,
482  $ v( 1, q ), 1,
483  $ fastr )
484  sva( q ) = aaqq*dsqrt( dmax1( zero,
485  $ one+t*apoaq*aapq ) )
486  aapp = aapp*dsqrt( dmax1( zero,
487  $ one-t*aqoap*aapq ) )
488  mxsinj = dmax1( mxsinj, dabs( t ) )
489  ELSE
490 *
491 * .. choose correct signum for THETA and rotate
492 *
493  thsign = -dsign( one, aapq )
494  IF( aaqq.GT.aapp0 )thsign = -thsign
495  t = one / ( theta+thsign*
496  $ dsqrt( one+theta*theta ) )
497  cs = dsqrt( one / ( one+t*t ) )
498  sn = t*cs
499  mxsinj = dmax1( mxsinj, dabs( sn ) )
500  sva( q ) = aaqq*dsqrt( dmax1( zero,
501  $ one+t*apoaq*aapq ) )
502  aapp = aapp*dsqrt( dmax1( zero,
503  $ one-t*aqoap*aapq ) )
504 
505  apoaq = d( p ) / d( q )
506  aqoap = d( q ) / d( p )
507  IF( d( p ).GE.one ) THEN
508 *
509  IF( d( q ).GE.one ) THEN
510  fastr( 3 ) = t*apoaq
511  fastr( 4 ) = -t*aqoap
512  d( p ) = d( p )*cs
513  d( q ) = d( q )*cs
514  CALL drotm( m, a( 1, p ), 1,
515  $ a( 1, q ), 1,
516  $ fastr )
517  IF( rsvec )CALL drotm( mvl,
518  $ v( 1, p ), 1, v( 1, q ),
519  $ 1, fastr )
520  ELSE
521  CALL daxpy( m, -t*aqoap,
522  $ a( 1, q ), 1,
523  $ a( 1, p ), 1 )
524  CALL daxpy( m, cs*sn*apoaq,
525  $ a( 1, p ), 1,
526  $ a( 1, q ), 1 )
527  IF( rsvec ) THEN
528  CALL daxpy( mvl, -t*aqoap,
529  $ v( 1, q ), 1,
530  $ v( 1, p ), 1 )
531  CALL daxpy( mvl,
532  $ cs*sn*apoaq,
533  $ v( 1, p ), 1,
534  $ v( 1, q ), 1 )
535  END IF
536  d( p ) = d( p )*cs
537  d( q ) = d( q ) / cs
538  END IF
539  ELSE
540  IF( d( q ).GE.one ) THEN
541  CALL daxpy( m, t*apoaq,
542  $ a( 1, p ), 1,
543  $ a( 1, q ), 1 )
544  CALL daxpy( m, -cs*sn*aqoap,
545  $ a( 1, q ), 1,
546  $ a( 1, p ), 1 )
547  IF( rsvec ) THEN
548  CALL daxpy( mvl, t*apoaq,
549  $ v( 1, p ), 1,
550  $ v( 1, q ), 1 )
551  CALL daxpy( mvl,
552  $ -cs*sn*aqoap,
553  $ v( 1, q ), 1,
554  $ v( 1, p ), 1 )
555  END IF
556  d( p ) = d( p ) / cs
557  d( q ) = d( q )*cs
558  ELSE
559  IF( d( p ).GE.d( q ) ) THEN
560  CALL daxpy( m, -t*aqoap,
561  $ a( 1, q ), 1,
562  $ a( 1, p ), 1 )
563  CALL daxpy( m, cs*sn*apoaq,
564  $ a( 1, p ), 1,
565  $ a( 1, q ), 1 )
566  d( p ) = d( p )*cs
567  d( q ) = d( q ) / cs
568  IF( rsvec ) THEN
569  CALL daxpy( mvl,
570  $ -t*aqoap,
571  $ v( 1, q ), 1,
572  $ v( 1, p ), 1 )
573  CALL daxpy( mvl,
574  $ cs*sn*apoaq,
575  $ v( 1, p ), 1,
576  $ v( 1, q ), 1 )
577  END IF
578  ELSE
579  CALL daxpy( m, t*apoaq,
580  $ a( 1, p ), 1,
581  $ a( 1, q ), 1 )
582  CALL daxpy( m,
583  $ -cs*sn*aqoap,
584  $ a( 1, q ), 1,
585  $ a( 1, p ), 1 )
586  d( p ) = d( p ) / cs
587  d( q ) = d( q )*cs
588  IF( rsvec ) THEN
589  CALL daxpy( mvl,
590  $ t*apoaq, v( 1, p ),
591  $ 1, v( 1, q ), 1 )
592  CALL daxpy( mvl,
593  $ -cs*sn*aqoap,
594  $ v( 1, q ), 1,
595  $ v( 1, p ), 1 )
596  END IF
597  END IF
598  END IF
599  END IF
600  END IF
601 
602  ELSE
603  IF( aapp.GT.aaqq ) THEN
604  CALL dcopy( m, a( 1, p ), 1, work,
605  $ 1 )
606  CALL dlascl( 'G', 0, 0, aapp, one,
607  $ m, 1, work, lda, ierr )
608  CALL dlascl( 'G', 0, 0, aaqq, one,
609  $ m, 1, a( 1, q ), lda,
610  $ ierr )
611  temp1 = -aapq*d( p ) / d( q )
612  CALL daxpy( m, temp1, work, 1,
613  $ a( 1, q ), 1 )
614  CALL dlascl( 'G', 0, 0, one, aaqq,
615  $ m, 1, a( 1, q ), lda,
616  $ ierr )
617  sva( q ) = aaqq*dsqrt( dmax1( zero,
618  $ one-aapq*aapq ) )
619  mxsinj = dmax1( mxsinj, sfmin )
620  ELSE
621  CALL dcopy( m, a( 1, q ), 1, work,
622  $ 1 )
623  CALL dlascl( 'G', 0, 0, aaqq, one,
624  $ m, 1, work, lda, ierr )
625  CALL dlascl( 'G', 0, 0, aapp, one,
626  $ m, 1, a( 1, p ), lda,
627  $ ierr )
628  temp1 = -aapq*d( q ) / d( p )
629  CALL daxpy( m, temp1, work, 1,
630  $ a( 1, p ), 1 )
631  CALL dlascl( 'G', 0, 0, one, aapp,
632  $ m, 1, a( 1, p ), lda,
633  $ ierr )
634  sva( p ) = aapp*dsqrt( dmax1( zero,
635  $ one-aapq*aapq ) )
636  mxsinj = dmax1( mxsinj, sfmin )
637  END IF
638  END IF
639 * END IF ROTOK THEN ... ELSE
640 *
641 * In the case of cancellation in updating SVA(q)
642 * .. recompute SVA(q)
643  IF( ( sva( q ) / aaqq )**2.LE.rooteps )
644  $ THEN
645  IF( ( aaqq.LT.rootbig ) .AND.
646  $ ( aaqq.GT.rootsfmin ) ) THEN
647  sva( q ) = dnrm2( m, a( 1, q ), 1 )*
648  $ d( q )
649  ELSE
650  t = zero
651  aaqq = one
652  CALL dlassq( m, a( 1, q ), 1, t,
653  $ aaqq )
654  sva( q ) = t*dsqrt( aaqq )*d( q )
655  END IF
656  END IF
657  IF( ( aapp / aapp0 )**2.LE.rooteps ) THEN
658  IF( ( aapp.LT.rootbig ) .AND.
659  $ ( aapp.GT.rootsfmin ) ) THEN
660  aapp = dnrm2( m, a( 1, p ), 1 )*
661  $ d( p )
662  ELSE
663  t = zero
664  aapp = one
665  CALL dlassq( m, a( 1, p ), 1, t,
666  $ aapp )
667  aapp = t*dsqrt( aapp )*d( p )
668  END IF
669  sva( p ) = aapp
670  END IF
671 * end of OK rotation
672  ELSE
673  notrot = notrot + 1
674 * SKIPPED = SKIPPED + 1
675  pskipped = pskipped + 1
676  ijblsk = ijblsk + 1
677  END IF
678  ELSE
679  notrot = notrot + 1
680  pskipped = pskipped + 1
681  ijblsk = ijblsk + 1
682  END IF
683 
684 * IF ( NOTROT .GE. EMPTSW ) GO TO 2011
685  IF( ( i.LE.swband ) .AND. ( ijblsk.GE.blskip ) )
686  $ THEN
687  sva( p ) = aapp
688  notrot = 0
689  go to 2011
690  END IF
691  IF( ( i.LE.swband ) .AND.
692  $ ( pskipped.GT.rowskip ) ) THEN
693  aapp = -aapp
694  notrot = 0
695  go to 2203
696  END IF
697 
698 *
699  2200 continue
700 * end of the q-loop
701  2203 continue
702 
703  sva( p ) = aapp
704 *
705  ELSE
706  IF( aapp.EQ.zero )notrot = notrot +
707  $ min0( jgl+kbl-1, n ) - jgl + 1
708  IF( aapp.LT.zero )notrot = 0
709 *** IF ( NOTROT .GE. EMPTSW ) GO TO 2011
710  END IF
711 
712  2100 continue
713 * end of the p-loop
714  2010 continue
715 * end of the jbc-loop
716  2011 continue
717 *2011 bailed out of the jbc-loop
718  DO 2012 p = igl, min0( igl+kbl-1, n )
719  sva( p ) = dabs( sva( p ) )
720  2012 continue
721 *** IF ( NOTROT .GE. EMPTSW ) GO TO 1994
722  2000 continue
723 *2000 :: end of the ibr-loop
724 *
725 * .. update SVA(N)
726  IF( ( sva( n ).LT.rootbig ) .AND. ( sva( n ).GT.rootsfmin ) )
727  $ THEN
728  sva( n ) = dnrm2( m, a( 1, n ), 1 )*d( n )
729  ELSE
730  t = zero
731  aapp = one
732  CALL dlassq( m, a( 1, n ), 1, t, aapp )
733  sva( n ) = t*dsqrt( aapp )*d( n )
734  END IF
735 *
736 * Additional steering devices
737 *
738  IF( ( i.LT.swband ) .AND. ( ( mxaapq.LE.roottol ) .OR.
739  $ ( iswrot.LE.n ) ) )swband = i
740 
741  IF( ( i.GT.swband+1 ) .AND. ( mxaapq.LT.dble( n )*tol ) .AND.
742  $ ( dble( n )*mxaapq*mxsinj.LT.tol ) ) THEN
743  go to 1994
744  END IF
745 
746 *
747  IF( notrot.GE.emptsw )go to 1994
748 
749  1993 continue
750 * end i=1:NSWEEP loop
751 * #:) Reaching this point means that the procedure has completed the given
752 * number of sweeps.
753  info = nsweep - 1
754  go to 1995
755  1994 continue
756 * #:) Reaching this point means that during the i-th sweep all pivots were
757 * below the given threshold, causing early exit.
758 
759  info = 0
760 * #:) INFO = 0 confirms successful iterations.
761  1995 continue
762 *
763 * Sort the vector D
764 *
765  DO 5991 p = 1, n - 1
766  q = idamax( n-p+1, sva( p ), 1 ) + p - 1
767  IF( p.NE.q ) THEN
768  temp1 = sva( p )
769  sva( p ) = sva( q )
770  sva( q ) = temp1
771  temp1 = d( p )
772  d( p ) = d( q )
773  d( q ) = temp1
774  CALL dswap( m, a( 1, p ), 1, a( 1, q ), 1 )
775  IF( rsvec )CALL dswap( mvl, v( 1, p ), 1, v( 1, q ), 1 )
776  END IF
777  5991 continue
778 *
779  return
780 * ..
781 * .. END OF DGSVJ1
782 * ..
783  END