001:       SUBROUTINE ZLAQHE( UPLO, N, A, LDA, S, SCOND, AMAX, EQUED )
002: *
003: *  -- LAPACK auxiliary routine (version 3.2) --
004: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
005: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       CHARACTER          EQUED, UPLO
010:       INTEGER            LDA, N
011:       DOUBLE PRECISION   AMAX, SCOND
012: *     ..
013: *     .. Array Arguments ..
014:       DOUBLE PRECISION   S( * )
015:       COMPLEX*16         A( LDA, * )
016: *     ..
017: *
018: *  Purpose
019: *  =======
020: *
021: *  ZLAQHE equilibrates a Hermitian matrix A using the scaling factors
022: *  in the vector S.
023: *
024: *  Arguments
025: *  =========
026: *
027: *  UPLO    (input) CHARACTER*1
028: *          Specifies whether the upper or lower triangular part of the
029: *          Hermitian matrix A is stored.
030: *          = 'U':  Upper triangular
031: *          = 'L':  Lower triangular
032: *
033: *  N       (input) INTEGER
034: *          The order of the matrix A.  N >= 0.
035: *
036: *  A       (input/output) COMPLEX*16 array, dimension (LDA,N)
037: *          On entry, the Hermitian matrix A.  If UPLO = 'U', the leading
038: *          n by n upper triangular part of A contains the upper
039: *          triangular part of the matrix A, and the strictly lower
040: *          triangular part of A is not referenced.  If UPLO = 'L', the
041: *          leading n by n lower triangular part of A contains the lower
042: *          triangular part of the matrix A, and the strictly upper
043: *          triangular part of A is not referenced.
044: *
045: *          On exit, if EQUED = 'Y', the equilibrated matrix:
046: *          diag(S) * A * diag(S).
047: *
048: *  LDA     (input) INTEGER
049: *          The leading dimension of the array A.  LDA >= max(N,1).
050: *
051: *  S       (input) DOUBLE PRECISION array, dimension (N)
052: *          The scale factors for A.
053: *
054: *  SCOND   (input) DOUBLE PRECISION
055: *          Ratio of the smallest S(i) to the largest S(i).
056: *
057: *  AMAX    (input) DOUBLE PRECISION
058: *          Absolute value of largest matrix entry.
059: *
060: *  EQUED   (output) CHARACTER*1
061: *          Specifies whether or not equilibration was done.
062: *          = 'N':  No equilibration.
063: *          = 'Y':  Equilibration was done, i.e., A has been replaced by
064: *                  diag(S) * A * diag(S).
065: *
066: *  Internal Parameters
067: *  ===================
068: *
069: *  THRESH is a threshold value used to decide if scaling should be done
070: *  based on the ratio of the scaling factors.  If SCOND < THRESH,
071: *  scaling is done.
072: *
073: *  LARGE and SMALL are threshold values used to decide if scaling should
074: *  be done based on the absolute size of the largest matrix element.
075: *  If AMAX > LARGE or AMAX < SMALL, scaling is done.
076: *
077: *  =====================================================================
078: *
079: *     .. Parameters ..
080:       DOUBLE PRECISION   ONE, THRESH
081:       PARAMETER          ( ONE = 1.0D+0, THRESH = 0.1D+0 )
082: *     ..
083: *     .. Local Scalars ..
084:       INTEGER            I, J
085:       DOUBLE PRECISION   CJ, LARGE, SMALL
086: *     ..
087: *     .. External Functions ..
088:       LOGICAL            LSAME
089:       DOUBLE PRECISION   DLAMCH
090:       EXTERNAL           LSAME, DLAMCH
091: *     ..
092: *     .. Intrinsic Functions ..
093:       INTRINSIC          DBLE
094: *     ..
095: *     .. Executable Statements ..
096: *
097: *     Quick return if possible
098: *
099:       IF( N.LE.0 ) THEN
100:          EQUED = 'N'
101:          RETURN
102:       END IF
103: *
104: *     Initialize LARGE and SMALL.
105: *
106:       SMALL = DLAMCH( 'Safe minimum' ) / DLAMCH( 'Precision' )
107:       LARGE = ONE / SMALL
108: *
109:       IF( SCOND.GE.THRESH .AND. AMAX.GE.SMALL .AND. AMAX.LE.LARGE ) THEN
110: *
111: *        No equilibration
112: *
113:          EQUED = 'N'
114:       ELSE
115: *
116: *        Replace A by diag(S) * A * diag(S).
117: *
118:          IF( LSAME( UPLO, 'U' ) ) THEN
119: *
120: *           Upper triangle of A is stored.
121: *
122:             DO 20 J = 1, N
123:                CJ = S( J )
124:                DO 10 I = 1, J - 1
125:                   A( I, J ) = CJ*S( I )*A( I, J )
126:    10          CONTINUE
127:                A( J, J ) = CJ*CJ*DBLE( A( J, J ) )
128:    20       CONTINUE
129:          ELSE
130: *
131: *           Lower triangle of A is stored.
132: *
133:             DO 40 J = 1, N
134:                CJ = S( J )
135:                A( J, J ) = CJ*CJ*DBLE( A( J, J ) )
136:                DO 30 I = J + 1, N
137:                   A( I, J ) = CJ*S( I )*A( I, J )
138:    30          CONTINUE
139:    40       CONTINUE
140:          END IF
141:          EQUED = 'Y'
142:       END IF
143: *
144:       RETURN
145: *
146: *     End of ZLAQHE
147: *
148:       END
149: