```001:       SUBROUTINE ZLAQSP( 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:       DOUBLE PRECISION   AMAX, SCOND
011: *     ..
012: *     .. Array Arguments ..
013:       DOUBLE PRECISION   S( * )
014:       COMPLEX*16         AP( * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  ZLAQSP equilibrates a symmetric 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: *          symmetric 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*16 array, dimension (N*(N+1)/2)
036: *          On entry, the upper or lower triangle of the symmetric 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) DOUBLE PRECISION array, dimension (N)
046: *          The scale factors for A.
047: *
048: *  SCOND   (input) DOUBLE PRECISION
049: *          Ratio of the smallest S(i) to the largest S(i).
050: *
051: *  AMAX    (input) DOUBLE PRECISION
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:       DOUBLE PRECISION   ONE, THRESH
075:       PARAMETER          ( ONE = 1.0D+0, THRESH = 0.1D+0 )
076: *     ..
077: *     .. Local Scalars ..
078:       INTEGER            I, J, JC
079:       DOUBLE PRECISION   CJ, LARGE, SMALL
080: *     ..
081: *     .. External Functions ..
082:       LOGICAL            LSAME
083:       DOUBLE PRECISION   DLAMCH
084:       EXTERNAL           LSAME, DLAMCH
085: *     ..
086: *     .. Executable Statements ..
087: *
088: *     Quick return if possible
089: *
090:       IF( N.LE.0 ) THEN
091:          EQUED = 'N'
092:          RETURN
093:       END IF
094: *
095: *     Initialize LARGE and SMALL.
096: *
097:       SMALL = DLAMCH( 'Safe minimum' ) / DLAMCH( 'Precision' )
098:       LARGE = ONE / SMALL
099: *
100:       IF( SCOND.GE.THRESH .AND. AMAX.GE.SMALL .AND. AMAX.LE.LARGE ) THEN
101: *
102: *        No equilibration
103: *
104:          EQUED = 'N'
105:       ELSE
106: *
107: *        Replace A by diag(S) * A * diag(S).
108: *
109:          IF( LSAME( UPLO, 'U' ) ) THEN
110: *
111: *           Upper triangle of A is stored.
112: *
113:             JC = 1
114:             DO 20 J = 1, N
115:                CJ = S( J )
116:                DO 10 I = 1, J
117:                   AP( JC+I-1 ) = CJ*S( I )*AP( JC+I-1 )
118:    10          CONTINUE
119:                JC = JC + J
120:    20       CONTINUE
121:          ELSE
122: *
123: *           Lower triangle of A is stored.
124: *
125:             JC = 1
126:             DO 40 J = 1, N
127:                CJ = S( J )
128:                DO 30 I = J, N
129:                   AP( JC+I-J ) = CJ*S( I )*AP( JC+I-J )
130:    30          CONTINUE
131:                JC = JC + N - J + 1
132:    40       CONTINUE
133:          END IF
134:          EQUED = 'Y'
135:       END IF
136: *
137:       RETURN
138: *
139: *     End of ZLAQSP
140: *
141:       END
142: ```