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