1       SUBROUTINE DLAQSY( UPLO, N, A, LDA, S, SCOND, AMAX, EQUED )
  2 *
  3 *  -- LAPACK auxiliary routine (version 3.2) --
  4 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
  5 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  6 *     November 2006
  7 *
  8 *     .. Scalar Arguments ..
  9       CHARACTER          EQUED, UPLO
 10       INTEGER            LDA, N
 11       DOUBLE PRECISION   AMAX, SCOND
 12 *     ..
 13 *     .. Array Arguments ..
 14       DOUBLE PRECISION   A( LDA, * ), S( * )
 15 *     ..
 16 *
 17 *  Purpose
 18 *  =======
 19 *
 20 *  DLAQSY equilibrates a symmetric matrix A using the scaling factors
 21 *  in the vector S.
 22 *
 23 *  Arguments
 24 *  =========
 25 *
 26 *  UPLO    (input) CHARACTER*1
 27 *          Specifies whether the upper or lower triangular part of the
 28 *          symmetric matrix A is stored.
 29 *          = 'U':  Upper triangular
 30 *          = 'L':  Lower triangular
 31 *
 32 *  N       (input) INTEGER
 33 *          The order of the matrix A.  N >= 0.
 34 *
 35 *  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
 36 *          On entry, the symmetric matrix A.  If UPLO = 'U', the leading
 37 *          n by n upper triangular part of A contains the upper
 38 *          triangular part of the matrix A, and the strictly lower
 39 *          triangular part of A is not referenced.  If UPLO = 'L', the
 40 *          leading n by n lower triangular part of A contains the lower
 41 *          triangular part of the matrix A, and the strictly upper
 42 *          triangular part of A is not referenced.
 43 *
 44 *          On exit, if EQUED = 'Y', the equilibrated matrix:
 45 *          diag(S) * A * diag(S).
 46 *
 47 *  LDA     (input) INTEGER
 48 *          The leading dimension of the array A.  LDA >= max(N,1).
 49 *
 50 *  S       (input) DOUBLE PRECISION array, dimension (N)
 51 *          The scale factors for A.
 52 *
 53 *  SCOND   (input) DOUBLE PRECISION
 54 *          Ratio of the smallest S(i) to the largest S(i).
 55 *
 56 *  AMAX    (input) DOUBLE PRECISION
 57 *          Absolute value of largest matrix entry.
 58 *
 59 *  EQUED   (output) CHARACTER*1
 60 *          Specifies whether or not equilibration was done.
 61 *          = 'N':  No equilibration.
 62 *          = 'Y':  Equilibration was done, i.e., A has been replaced by
 63 *                  diag(S) * A * diag(S).
 64 *
 65 *  Internal Parameters
 66 *  ===================
 67 *
 68 *  THRESH is a threshold value used to decide if scaling should be done
 69 *  based on the ratio of the scaling factors.  If SCOND < THRESH,
 70 *  scaling is done.
 71 *
 72 *  LARGE and SMALL are threshold values used to decide if scaling should
 73 *  be done based on the absolute size of the largest matrix element.
 74 *  If AMAX > LARGE or AMAX < SMALL, scaling is done.
 75 *
 76 *  =====================================================================
 77 *
 78 *     .. Parameters ..
 79       DOUBLE PRECISION   ONE, THRESH
 80       PARAMETER          ( ONE = 1.0D+0, THRESH = 0.1D+0 )
 81 *     ..
 82 *     .. Local Scalars ..
 83       INTEGER            I, J
 84       DOUBLE PRECISION   CJ, LARGE, SMALL
 85 *     ..
 86 *     .. External Functions ..
 87       LOGICAL            LSAME
 88       DOUBLE PRECISION   DLAMCH
 89       EXTERNAL           LSAME, DLAMCH
 90 *     ..
 91 *     .. Executable Statements ..
 92 *
 93 *     Quick return if possible
 94 *
 95       IF( N.LE.0 ) THEN
 96          EQUED = 'N'
 97          RETURN
 98       END IF
 99 *
100 *     Initialize LARGE and SMALL.
101 *
102       SMALL = DLAMCH( 'Safe minimum' ) / DLAMCH( 'Precision' )
103       LARGE = ONE / SMALL
104 *
105       IF( SCOND.GE.THRESH .AND. AMAX.GE.SMALL .AND. AMAX.LE.LARGE ) THEN
106 *
107 *        No equilibration
108 *
109          EQUED = 'N'
110       ELSE
111 *
112 *        Replace A by diag(S) * A * diag(S).
113 *
114          IF( LSAME( UPLO, 'U' ) ) THEN
115 *
116 *           Upper triangle of A is stored.
117 *
118             DO 20 J = 1, N
119                CJ = S( J )
120                DO 10 I = 1, J
121                   A( I, J ) = CJ*S( I )*A( I, J )
122    10          CONTINUE
123    20       CONTINUE
124          ELSE
125 *
126 *           Lower triangle of A is stored.
127 *
128             DO 40 J = 1, N
129                CJ = S( J )
130                DO 30 I = J, N
131                   A( I, J ) = CJ*S( I )*A( I, J )
132    30          CONTINUE
133    40       CONTINUE
134          END IF
135          EQUED = 'Y'
136       END IF
137 *
138       RETURN
139 *
140 *     End of DLAQSY
141 *
142       END