File:  [local] / rpl / lapack / lapack / dgsvj1.f
Revision 1.8: download - view: text, annotated - select for diffs - revision graph
Mon Nov 21 22:19:29 2011 UTC (12 years, 6 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_8, rpl-4_1_7, rpl-4_1_6, rpl-4_1_5, rpl-4_1_4, HEAD
Cohérence

    1: *> \brief \b DGSVJ1
    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 November 2011
  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.0) --
  240: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
  241: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  242: *     November 2011
  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, TWO
  258:       PARAMETER          ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0,
  259:      $                   TWO = 2.0D0 )
  260: *     ..
  261: *     .. Local Scalars ..
  262:       DOUBLE PRECISION   AAPP, AAPP0, AAPQ, AAQQ, APOAQ, AQOAP, BIG,
  263:      $                   BIGTHETA, CS, LARGE, MXAAPQ, MXSINJ, ROOTBIG,
  264:      $                   ROOTEPS, ROOTSFMIN, ROOTTOL, SMALL, SN, T,
  265:      $                   TEMP1, THETA, THSIGN
  266:       INTEGER            BLSKIP, EMPTSW, i, ibr, igl, IERR, IJBLSK,
  267:      $                   ISWROT, jbc, jgl, KBL, MVL, NOTROT, nblc, nblr,
  268:      $                   p, PSKIPPED, q, ROWSKIP, SWBAND
  269:       LOGICAL            APPLV, ROTOK, RSVEC
  270: *     ..
  271: *     .. Local Arrays ..
  272:       DOUBLE PRECISION   FASTR( 5 )
  273: *     ..
  274: *     .. Intrinsic Functions ..
  275:       INTRINSIC          DABS, DMAX1, DBLE, MIN0, DSIGN, DSQRT
  276: *     ..
  277: *     .. External Functions ..
  278:       DOUBLE PRECISION   DDOT, DNRM2
  279:       INTEGER            IDAMAX
  280:       LOGICAL            LSAME
  281:       EXTERNAL           IDAMAX, LSAME, DDOT, DNRM2
  282: *     ..
  283: *     .. External Subroutines ..
  284:       EXTERNAL           DAXPY, DCOPY, DLASCL, DLASSQ, DROTM, DSWAP
  285: *     ..
  286: *     .. Executable Statements ..
  287: *
  288: *     Test the input parameters.
  289: *
  290:       APPLV = LSAME( JOBV, 'A' )
  291:       RSVEC = LSAME( JOBV, 'V' )
  292:       IF( .NOT.( RSVEC .OR. APPLV .OR. LSAME( JOBV, 'N' ) ) ) THEN
  293:          INFO = -1
  294:       ELSE IF( M.LT.0 ) THEN
  295:          INFO = -2
  296:       ELSE IF( ( N.LT.0 ) .OR. ( N.GT.M ) ) THEN
  297:          INFO = -3
  298:       ELSE IF( N1.LT.0 ) THEN
  299:          INFO = -4
  300:       ELSE IF( LDA.LT.M ) THEN
  301:          INFO = -6
  302:       ELSE IF( ( RSVEC.OR.APPLV ) .AND. ( MV.LT.0 ) ) THEN
  303:          INFO = -9
  304:       ELSE IF( ( RSVEC.AND.( LDV.LT.N ) ).OR. 
  305:      $         ( APPLV.AND.( LDV.LT.MV ) )  ) THEN
  306:          INFO = -11
  307:       ELSE IF( TOL.LE.EPS ) THEN
  308:          INFO = -14
  309:       ELSE IF( NSWEEP.LT.0 ) THEN
  310:          INFO = -15
  311:       ELSE IF( LWORK.LT.M ) THEN
  312:          INFO = -17
  313:       ELSE
  314:          INFO = 0
  315:       END IF
  316: *
  317: *     #:(
  318:       IF( INFO.NE.0 ) THEN
  319:          CALL XERBLA( 'DGSVJ1', -INFO )
  320:          RETURN
  321:       END IF
  322: *
  323:       IF( RSVEC ) THEN
  324:          MVL = N
  325:       ELSE IF( APPLV ) THEN
  326:          MVL = MV
  327:       END IF
  328:       RSVEC = RSVEC .OR. APPLV
  329: 
  330:       ROOTEPS = DSQRT( EPS )
  331:       ROOTSFMIN = DSQRT( SFMIN )
  332:       SMALL = SFMIN / EPS
  333:       BIG = ONE / SFMIN
  334:       ROOTBIG = ONE / ROOTSFMIN
  335:       LARGE = BIG / DSQRT( DBLE( M*N ) )
  336:       BIGTHETA = ONE / ROOTEPS
  337:       ROOTTOL = DSQRT( TOL )
  338: *
  339: *     .. Initialize the right singular vector matrix ..
  340: *
  341: *     RSVEC = LSAME( JOBV, 'Y' )
  342: *
  343:       EMPTSW = N1*( N-N1 )
  344:       NOTROT = 0
  345:       FASTR( 1 ) = ZERO
  346: *
  347: *     .. Row-cyclic pivot strategy with de Rijk's pivoting ..
  348: *
  349:       KBL = MIN0( 8, N )
  350:       NBLR = N1 / KBL
  351:       IF( ( NBLR*KBL ).NE.N1 )NBLR = NBLR + 1
  352: 
  353: *     .. the tiling is nblr-by-nblc [tiles]
  354: 
  355:       NBLC = ( N-N1 ) / KBL
  356:       IF( ( NBLC*KBL ).NE.( N-N1 ) )NBLC = NBLC + 1
  357:       BLSKIP = ( KBL**2 ) + 1
  358: *[TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL.
  359: 
  360:       ROWSKIP = MIN0( 5, KBL )
  361: *[TP] ROWSKIP is a tuning parameter.
  362:       SWBAND = 0
  363: *[TP] SWBAND is a tuning parameter. It is meaningful and effective
  364: *     if SGESVJ is used as a computational routine in the preconditioned
  365: *     Jacobi SVD algorithm SGESVJ.
  366: *
  367: *
  368: *     | *   *   * [x] [x] [x]|
  369: *     | *   *   * [x] [x] [x]|    Row-cycling in the nblr-by-nblc [x] blocks.
  370: *     | *   *   * [x] [x] [x]|    Row-cyclic pivoting inside each [x] block.
  371: *     |[x] [x] [x] *   *   * |
  372: *     |[x] [x] [x] *   *   * |
  373: *     |[x] [x] [x] *   *   * |
  374: *
  375: *
  376:       DO 1993 i = 1, NSWEEP
  377: *     .. go go go ...
  378: *
  379:          MXAAPQ = ZERO
  380:          MXSINJ = ZERO
  381:          ISWROT = 0
  382: *
  383:          NOTROT = 0
  384:          PSKIPPED = 0
  385: *
  386:          DO 2000 ibr = 1, NBLR
  387: 
  388:             igl = ( ibr-1 )*KBL + 1
  389: *
  390: *
  391: *........................................................
  392: * ... go to the off diagonal blocks
  393: 
  394:             igl = ( ibr-1 )*KBL + 1
  395: 
  396:             DO 2010 jbc = 1, NBLC
  397: 
  398:                jgl = N1 + ( jbc-1 )*KBL + 1
  399: 
  400: *        doing the block at ( ibr, jbc )
  401: 
  402:                IJBLSK = 0
  403:                DO 2100 p = igl, MIN0( igl+KBL-1, N1 )
  404: 
  405:                   AAPP = SVA( p )
  406: 
  407:                   IF( AAPP.GT.ZERO ) THEN
  408: 
  409:                      PSKIPPED = 0
  410: 
  411:                      DO 2200 q = jgl, MIN0( jgl+KBL-1, N )
  412: *
  413:                         AAQQ = SVA( q )
  414: 
  415:                         IF( AAQQ.GT.ZERO ) THEN
  416:                            AAPP0 = AAPP
  417: *
  418: *     .. M x 2 Jacobi SVD ..
  419: *
  420: *        .. Safe Gram matrix computation ..
  421: *
  422:                            IF( AAQQ.GE.ONE ) THEN
  423:                               IF( AAPP.GE.AAQQ ) THEN
  424:                                  ROTOK = ( SMALL*AAPP ).LE.AAQQ
  425:                               ELSE
  426:                                  ROTOK = ( SMALL*AAQQ ).LE.AAPP
  427:                               END IF
  428:                               IF( AAPP.LT.( BIG / AAQQ ) ) THEN
  429:                                  AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
  430:      $                                  q ), 1 )*D( p )*D( q ) / AAQQ )
  431:      $                                  / AAPP
  432:                               ELSE
  433:                                  CALL DCOPY( M, A( 1, p ), 1, WORK, 1 )
  434:                                  CALL DLASCL( 'G', 0, 0, AAPP, D( p ),
  435:      $                                        M, 1, WORK, LDA, IERR )
  436:                                  AAPQ = DDOT( M, WORK, 1, A( 1, q ),
  437:      $                                  1 )*D( q ) / AAQQ
  438:                               END IF
  439:                            ELSE
  440:                               IF( AAPP.GE.AAQQ ) THEN
  441:                                  ROTOK = AAPP.LE.( AAQQ / SMALL )
  442:                               ELSE
  443:                                  ROTOK = AAQQ.LE.( AAPP / SMALL )
  444:                               END IF
  445:                               IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
  446:                                  AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
  447:      $                                  q ), 1 )*D( p )*D( q ) / AAQQ )
  448:      $                                  / AAPP
  449:                               ELSE
  450:                                  CALL DCOPY( M, A( 1, q ), 1, WORK, 1 )
  451:                                  CALL DLASCL( 'G', 0, 0, AAQQ, D( q ),
  452:      $                                        M, 1, WORK, LDA, IERR )
  453:                                  AAPQ = DDOT( M, WORK, 1, A( 1, p ),
  454:      $                                  1 )*D( p ) / AAPP
  455:                               END IF
  456:                            END IF
  457: 
  458:                            MXAAPQ = DMAX1( MXAAPQ, DABS( AAPQ ) )
  459: 
  460: *        TO rotate or NOT to rotate, THAT is the question ...
  461: *
  462:                            IF( DABS( AAPQ ).GT.TOL ) THEN
  463:                               NOTROT = 0
  464: *           ROTATED  = ROTATED + 1
  465:                               PSKIPPED = 0
  466:                               ISWROT = ISWROT + 1
  467: *
  468:                               IF( ROTOK ) THEN
  469: *
  470:                                  AQOAP = AAQQ / AAPP
  471:                                  APOAQ = AAPP / AAQQ
  472:                                  THETA = -HALF*DABS(AQOAP-APOAQ) / AAPQ
  473:                                  IF( AAQQ.GT.AAPP0 )THETA = -THETA
  474: 
  475:                                  IF( DABS( THETA ).GT.BIGTHETA ) THEN
  476:                                     T = HALF / THETA
  477:                                     FASTR( 3 ) = T*D( p ) / D( q )
  478:                                     FASTR( 4 ) = -T*D( q ) / D( p )
  479:                                     CALL DROTM( M, A( 1, p ), 1,
  480:      $                                          A( 1, q ), 1, FASTR )
  481:                                     IF( RSVEC )CALL DROTM( MVL,
  482:      $                                              V( 1, p ), 1,
  483:      $                                              V( 1, q ), 1,
  484:      $                                              FASTR )
  485:                                     SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
  486:      $                                         ONE+T*APOAQ*AAPQ ) )
  487:                                     AAPP = AAPP*DSQRT( DMAX1( ZERO,
  488:      $                                     ONE-T*AQOAP*AAPQ ) )
  489:                                     MXSINJ = DMAX1( MXSINJ, DABS( T ) )
  490:                                  ELSE
  491: *
  492: *                 .. choose correct signum for THETA and rotate
  493: *
  494:                                     THSIGN = -DSIGN( ONE, AAPQ )
  495:                                     IF( AAQQ.GT.AAPP0 )THSIGN = -THSIGN
  496:                                     T = ONE / ( THETA+THSIGN*
  497:      $                                  DSQRT( ONE+THETA*THETA ) )
  498:                                     CS = DSQRT( ONE / ( ONE+T*T ) )
  499:                                     SN = T*CS
  500:                                     MXSINJ = DMAX1( MXSINJ, DABS( SN ) )
  501:                                     SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
  502:      $                                         ONE+T*APOAQ*AAPQ ) )
  503:                                     AAPP = AAPP*DSQRT( DMAX1( ZERO, 
  504:      $                                    ONE-T*AQOAP*AAPQ ) )
  505: 
  506:                                     APOAQ = D( p ) / D( q )
  507:                                     AQOAP = D( q ) / D( p )
  508:                                     IF( D( p ).GE.ONE ) THEN
  509: *
  510:                                        IF( D( q ).GE.ONE ) THEN
  511:                                           FASTR( 3 ) = T*APOAQ
  512:                                           FASTR( 4 ) = -T*AQOAP
  513:                                           D( p ) = D( p )*CS
  514:                                           D( q ) = D( q )*CS
  515:                                           CALL DROTM( M, A( 1, p ), 1,
  516:      $                                                A( 1, q ), 1,
  517:      $                                                FASTR )
  518:                                           IF( RSVEC )CALL DROTM( MVL,
  519:      $                                        V( 1, p ), 1, V( 1, q ),
  520:      $                                        1, FASTR )
  521:                                        ELSE
  522:                                           CALL DAXPY( M, -T*AQOAP,
  523:      $                                                A( 1, q ), 1,
  524:      $                                                A( 1, p ), 1 )
  525:                                           CALL DAXPY( M, CS*SN*APOAQ,
  526:      $                                                A( 1, p ), 1,
  527:      $                                                A( 1, q ), 1 )
  528:                                           IF( RSVEC ) THEN
  529:                                              CALL DAXPY( MVL, -T*AQOAP,
  530:      $                                                   V( 1, q ), 1,
  531:      $                                                   V( 1, p ), 1 )
  532:                                              CALL DAXPY( MVL,
  533:      $                                                   CS*SN*APOAQ,
  534:      $                                                   V( 1, p ), 1,
  535:      $                                                   V( 1, q ), 1 )
  536:                                           END IF
  537:                                           D( p ) = D( p )*CS
  538:                                           D( q ) = D( q ) / CS
  539:                                        END IF
  540:                                     ELSE
  541:                                        IF( D( q ).GE.ONE ) THEN
  542:                                           CALL DAXPY( M, T*APOAQ,
  543:      $                                                A( 1, p ), 1,
  544:      $                                                A( 1, q ), 1 )
  545:                                           CALL DAXPY( M, -CS*SN*AQOAP,
  546:      $                                                A( 1, q ), 1,
  547:      $                                                A( 1, p ), 1 )
  548:                                           IF( RSVEC ) THEN
  549:                                              CALL DAXPY( MVL, T*APOAQ,
  550:      $                                                   V( 1, p ), 1,
  551:      $                                                   V( 1, q ), 1 )
  552:                                              CALL DAXPY( MVL,
  553:      $                                                   -CS*SN*AQOAP,
  554:      $                                                   V( 1, q ), 1,
  555:      $                                                   V( 1, p ), 1 )
  556:                                           END IF
  557:                                           D( p ) = D( p ) / CS
  558:                                           D( q ) = D( q )*CS
  559:                                        ELSE
  560:                                           IF( D( p ).GE.D( q ) ) THEN
  561:                                              CALL DAXPY( M, -T*AQOAP,
  562:      $                                                   A( 1, q ), 1,
  563:      $                                                   A( 1, p ), 1 )
  564:                                              CALL DAXPY( M, CS*SN*APOAQ,
  565:      $                                                   A( 1, p ), 1,
  566:      $                                                   A( 1, q ), 1 )
  567:                                              D( p ) = D( p )*CS
  568:                                              D( q ) = D( q ) / CS
  569:                                              IF( RSVEC ) THEN
  570:                                                 CALL DAXPY( MVL,
  571:      $                                               -T*AQOAP,
  572:      $                                               V( 1, q ), 1,
  573:      $                                               V( 1, p ), 1 )
  574:                                                 CALL DAXPY( MVL,
  575:      $                                               CS*SN*APOAQ,
  576:      $                                               V( 1, p ), 1,
  577:      $                                               V( 1, q ), 1 )
  578:                                              END IF
  579:                                           ELSE
  580:                                              CALL DAXPY( M, T*APOAQ,
  581:      $                                                   A( 1, p ), 1,
  582:      $                                                   A( 1, q ), 1 )
  583:                                              CALL DAXPY( M,
  584:      $                                                   -CS*SN*AQOAP,
  585:      $                                                   A( 1, q ), 1,
  586:      $                                                   A( 1, p ), 1 )
  587:                                              D( p ) = D( p ) / CS
  588:                                              D( q ) = D( q )*CS
  589:                                              IF( RSVEC ) THEN
  590:                                                 CALL DAXPY( MVL,
  591:      $                                               T*APOAQ, V( 1, p ),
  592:      $                                               1, V( 1, q ), 1 )
  593:                                                 CALL DAXPY( MVL,
  594:      $                                               -CS*SN*AQOAP,
  595:      $                                               V( 1, q ), 1,
  596:      $                                               V( 1, p ), 1 )
  597:                                              END IF
  598:                                           END IF
  599:                                        END IF
  600:                                     END IF
  601:                                  END IF
  602: 
  603:                               ELSE
  604:                                  IF( AAPP.GT.AAQQ ) THEN
  605:                                     CALL DCOPY( M, A( 1, p ), 1, WORK,
  606:      $                                          1 )
  607:                                     CALL DLASCL( 'G', 0, 0, AAPP, ONE,
  608:      $                                           M, 1, WORK, LDA, IERR )
  609:                                     CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
  610:      $                                           M, 1, A( 1, q ), LDA,
  611:      $                                           IERR )
  612:                                     TEMP1 = -AAPQ*D( p ) / D( q )
  613:                                     CALL DAXPY( M, TEMP1, WORK, 1,
  614:      $                                          A( 1, q ), 1 )
  615:                                     CALL DLASCL( 'G', 0, 0, ONE, AAQQ,
  616:      $                                           M, 1, A( 1, q ), LDA,
  617:      $                                           IERR )
  618:                                     SVA( q ) = AAQQ*DSQRT( DMAX1( ZERO,
  619:      $                                         ONE-AAPQ*AAPQ ) )
  620:                                     MXSINJ = DMAX1( MXSINJ, SFMIN )
  621:                                  ELSE
  622:                                     CALL DCOPY( M, A( 1, q ), 1, WORK,
  623:      $                                          1 )
  624:                                     CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
  625:      $                                           M, 1, WORK, LDA, IERR )
  626:                                     CALL DLASCL( 'G', 0, 0, AAPP, ONE,
  627:      $                                           M, 1, A( 1, p ), LDA,
  628:      $                                           IERR )
  629:                                     TEMP1 = -AAPQ*D( q ) / D( p )
  630:                                     CALL DAXPY( M, TEMP1, WORK, 1,
  631:      $                                          A( 1, p ), 1 )
  632:                                     CALL DLASCL( 'G', 0, 0, ONE, AAPP,
  633:      $                                           M, 1, A( 1, p ), LDA,
  634:      $                                           IERR )
  635:                                     SVA( p ) = AAPP*DSQRT( DMAX1( ZERO,
  636:      $                                         ONE-AAPQ*AAPQ ) )
  637:                                     MXSINJ = DMAX1( MXSINJ, SFMIN )
  638:                                  END IF
  639:                               END IF
  640: *           END IF ROTOK THEN ... ELSE
  641: *
  642: *           In the case of cancellation in updating SVA(q)
  643: *           .. recompute SVA(q)
  644:                               IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
  645:      $                            THEN
  646:                                  IF( ( AAQQ.LT.ROOTBIG ) .AND.
  647:      $                               ( AAQQ.GT.ROOTSFMIN ) ) THEN
  648:                                     SVA( q ) = DNRM2( M, A( 1, q ), 1 )*
  649:      $                                         D( q )
  650:                                  ELSE
  651:                                     T = ZERO
  652:                                     AAQQ = ONE
  653:                                     CALL DLASSQ( M, A( 1, q ), 1, T,
  654:      $                                           AAQQ )
  655:                                     SVA( q ) = T*DSQRT( AAQQ )*D( q )
  656:                                  END IF
  657:                               END IF
  658:                               IF( ( AAPP / AAPP0 )**2.LE.ROOTEPS ) THEN
  659:                                  IF( ( AAPP.LT.ROOTBIG ) .AND.
  660:      $                               ( AAPP.GT.ROOTSFMIN ) ) THEN
  661:                                     AAPP = DNRM2( M, A( 1, p ), 1 )*
  662:      $                                     D( p )
  663:                                  ELSE
  664:                                     T = ZERO
  665:                                     AAPP = ONE
  666:                                     CALL DLASSQ( M, A( 1, p ), 1, T,
  667:      $                                           AAPP )
  668:                                     AAPP = T*DSQRT( AAPP )*D( p )
  669:                                  END IF
  670:                                  SVA( p ) = AAPP
  671:                               END IF
  672: *              end of OK rotation
  673:                            ELSE
  674:                               NOTROT = NOTROT + 1
  675: *           SKIPPED  = SKIPPED  + 1
  676:                               PSKIPPED = PSKIPPED + 1
  677:                               IJBLSK = IJBLSK + 1
  678:                            END IF
  679:                         ELSE
  680:                            NOTROT = NOTROT + 1
  681:                            PSKIPPED = PSKIPPED + 1
  682:                            IJBLSK = IJBLSK + 1
  683:                         END IF
  684: 
  685: *      IF ( NOTROT .GE. EMPTSW )  GO TO 2011
  686:                         IF( ( i.LE.SWBAND ) .AND. ( IJBLSK.GE.BLSKIP ) )
  687:      $                      THEN
  688:                            SVA( p ) = AAPP
  689:                            NOTROT = 0
  690:                            GO TO 2011
  691:                         END IF
  692:                         IF( ( i.LE.SWBAND ) .AND.
  693:      $                      ( PSKIPPED.GT.ROWSKIP ) ) THEN
  694:                            AAPP = -AAPP
  695:                            NOTROT = 0
  696:                            GO TO 2203
  697:                         END IF
  698: 
  699: *
  700:  2200                CONTINUE
  701: *        end of the q-loop
  702:  2203                CONTINUE
  703: 
  704:                      SVA( p ) = AAPP
  705: *
  706:                   ELSE
  707:                      IF( AAPP.EQ.ZERO )NOTROT = NOTROT +
  708:      $                   MIN0( jgl+KBL-1, N ) - jgl + 1
  709:                      IF( AAPP.LT.ZERO )NOTROT = 0
  710: ***      IF ( NOTROT .GE. EMPTSW )  GO TO 2011
  711:                   END IF
  712: 
  713:  2100          CONTINUE
  714: *     end of the p-loop
  715:  2010       CONTINUE
  716: *     end of the jbc-loop
  717:  2011       CONTINUE
  718: *2011 bailed out of the jbc-loop
  719:             DO 2012 p = igl, MIN0( igl+KBL-1, N )
  720:                SVA( p ) = DABS( SVA( p ) )
  721:  2012       CONTINUE
  722: ***   IF ( NOTROT .GE. EMPTSW ) GO TO 1994
  723:  2000    CONTINUE
  724: *2000 :: end of the ibr-loop
  725: *
  726: *     .. update SVA(N)
  727:          IF( ( SVA( N ).LT.ROOTBIG ) .AND. ( SVA( N ).GT.ROOTSFMIN ) )
  728:      $       THEN
  729:             SVA( N ) = DNRM2( M, A( 1, N ), 1 )*D( N )
  730:          ELSE
  731:             T = ZERO
  732:             AAPP = ONE
  733:             CALL DLASSQ( M, A( 1, N ), 1, T, AAPP )
  734:             SVA( N ) = T*DSQRT( AAPP )*D( N )
  735:          END IF
  736: *
  737: *     Additional steering devices
  738: *
  739:          IF( ( i.LT.SWBAND ) .AND. ( ( MXAAPQ.LE.ROOTTOL ) .OR.
  740:      $       ( ISWROT.LE.N ) ) )SWBAND = i
  741: 
  742:          IF( ( i.GT.SWBAND+1 ) .AND. ( MXAAPQ.LT.DBLE( N )*TOL ) .AND.
  743:      $       ( DBLE( N )*MXAAPQ*MXSINJ.LT.TOL ) ) THEN
  744:             GO TO 1994
  745:          END IF
  746: 
  747: *
  748:          IF( NOTROT.GE.EMPTSW )GO TO 1994
  749: 
  750:  1993 CONTINUE
  751: *     end i=1:NSWEEP loop
  752: * #:) Reaching this point means that the procedure has completed the given
  753: *     number of sweeps.
  754:       INFO = NSWEEP - 1
  755:       GO TO 1995
  756:  1994 CONTINUE
  757: * #:) Reaching this point means that during the i-th sweep all pivots were
  758: *     below the given threshold, causing early exit.
  759: 
  760:       INFO = 0
  761: * #:) INFO = 0 confirms successful iterations.
  762:  1995 CONTINUE
  763: *
  764: *     Sort the vector D
  765: *
  766:       DO 5991 p = 1, N - 1
  767:          q = IDAMAX( N-p+1, SVA( p ), 1 ) + p - 1
  768:          IF( p.NE.q ) THEN
  769:             TEMP1 = SVA( p )
  770:             SVA( p ) = SVA( q )
  771:             SVA( q ) = TEMP1
  772:             TEMP1 = D( p )
  773:             D( p ) = D( q )
  774:             D( q ) = TEMP1
  775:             CALL DSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
  776:             IF( RSVEC )CALL DSWAP( MVL, V( 1, p ), 1, V( 1, q ), 1 )
  777:          END IF
  778:  5991 CONTINUE
  779: *
  780:       RETURN
  781: *     ..
  782: *     .. END OF DGSVJ1
  783: *     ..
  784:       END

CVSweb interface <joel.bertrand@systella.fr>