001:       SUBROUTINE CLAQHP( UPLO, N, AP, 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            N
010:       REAL               AMAX, SCOND
011: *     ..
012: *     .. Array Arguments ..
013:       REAL               S( * )
014:       COMPLEX            AP( * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  CLAQHP 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: *  AP      (input/output) COMPLEX array, dimension (N*(N+1)/2)
036: *          On entry, the upper or lower triangle of the Hermitian matrix
037: *          A, packed columnwise in a linear array.  The j-th column of A
038: *          is stored in the array AP as follows:
039: *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
040: *          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
041: *
042: *          On exit, the equilibrated matrix:  diag(S) * A * diag(S), in
043: *          the same storage format as A.
044: *
045: *  S       (input) REAL array, dimension (N)
046: *          The scale factors for A.
047: *
048: *  SCOND   (input) REAL
049: *          Ratio of the smallest S(i) to the largest S(i).
050: *
051: *  AMAX    (input) REAL
052: *          Absolute value of largest matrix entry.
053: *
054: *  EQUED   (output) CHARACTER*1
055: *          Specifies whether or not equilibration was done.
056: *          = 'N':  No equilibration.
057: *          = 'Y':  Equilibration was done, i.e., A has been replaced by
058: *                  diag(S) * A * diag(S).
059: *
060: *  Internal Parameters
061: *  ===================
062: *
063: *  THRESH is a threshold value used to decide if scaling should be done
064: *  based on the ratio of the scaling factors.  If SCOND < THRESH,
065: *  scaling is done.
066: *
067: *  LARGE and SMALL are threshold values used to decide if scaling should
068: *  be done based on the absolute size of the largest matrix element.
069: *  If AMAX > LARGE or AMAX < SMALL, scaling is done.
070: *
071: *  =====================================================================
072: *
073: *     .. Parameters ..
074:       REAL               ONE, THRESH
075:       PARAMETER          ( ONE = 1.0E+0, THRESH = 0.1E+0 )
076: *     ..
077: *     .. Local Scalars ..
078:       INTEGER            I, J, JC
079:       REAL               CJ, LARGE, SMALL
080: *     ..
081: *     .. External Functions ..
082:       LOGICAL            LSAME
083:       REAL               SLAMCH
084:       EXTERNAL           LSAME, SLAMCH
085: *     ..
086: *     .. Intrinsic Functions ..
087:       INTRINSIC          REAL
088: *     ..
089: *     .. Executable Statements ..
090: *
091: *     Quick return if possible
092: *
093:       IF( N.LE.0 ) THEN
094:          EQUED = 'N'
095:          RETURN
096:       END IF
097: *
098: *     Initialize LARGE and SMALL.
099: *
100:       SMALL = SLAMCH( 'Safe minimum' ) / SLAMCH( 'Precision' )
101:       LARGE = ONE / SMALL
102: *
103:       IF( SCOND.GE.THRESH .AND. AMAX.GE.SMALL .AND. AMAX.LE.LARGE ) THEN
104: *
105: *        No equilibration
106: *
107:          EQUED = 'N'
108:       ELSE
109: *
110: *        Replace A by diag(S) * A * diag(S).
111: *
112:          IF( LSAME( UPLO, 'U' ) ) THEN
113: *
114: *           Upper triangle of A is stored.
115: *
116:             JC = 1
117:             DO 20 J = 1, N
118:                CJ = S( J )
119:                DO 10 I = 1, J - 1
120:                   AP( JC+I-1 ) = CJ*S( I )*AP( JC+I-1 )
121:    10          CONTINUE
122:                AP( JC+J-1 ) = CJ*CJ*REAL( AP( JC+J-1 ) )
123:                JC = JC + J
124:    20       CONTINUE
125:          ELSE
126: *
127: *           Lower triangle of A is stored.
128: *
129:             JC = 1
130:             DO 40 J = 1, N
131:                CJ = S( J )
132:                AP( JC ) = CJ*CJ*REAL( AP( JC ) )
133:                DO 30 I = J + 1, N
134:                   AP( JC+I-J ) = CJ*S( I )*AP( JC+I-J )
135:    30          CONTINUE
136:                JC = JC + N - J + 1
137:    40       CONTINUE
138:          END IF
139:          EQUED = 'Y'
140:       END IF
141: *
142:       RETURN
143: *
144: *     End of CLAQHP
145: *
146:       END
147: