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