```001:       SUBROUTINE CPPCON( UPLO, N, AP, ANORM, RCOND, WORK, RWORK, INFO )
002: *
003: *  -- LAPACK 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: *     Modified to call CLACN2 in place of CLACON, 10 Feb 03, SJH.
009: *
010: *     .. Scalar Arguments ..
011:       CHARACTER          UPLO
012:       INTEGER            INFO, N
013:       REAL               ANORM, RCOND
014: *     ..
015: *     .. Array Arguments ..
016:       REAL               RWORK( * )
017:       COMPLEX            AP( * ), WORK( * )
018: *     ..
019: *
020: *  Purpose
021: *  =======
022: *
023: *  CPPCON estimates the reciprocal of the condition number (in the
024: *  1-norm) of a complex Hermitian positive definite packed matrix using
025: *  the Cholesky factorization A = U**H*U or A = L*L**H computed by
026: *  CPPTRF.
027: *
028: *  An estimate is obtained for norm(inv(A)), and the reciprocal of the
029: *  condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))).
030: *
031: *  Arguments
032: *  =========
033: *
034: *  UPLO    (input) CHARACTER*1
035: *          = 'U':  Upper triangle of A is stored;
036: *          = 'L':  Lower triangle of A is stored.
037: *
038: *  N       (input) INTEGER
039: *          The order of the matrix A.  N >= 0.
040: *
041: *  AP      (input) COMPLEX array, dimension (N*(N+1)/2)
042: *          The triangular factor U or L from the Cholesky factorization
043: *          A = U**H*U or A = L*L**H, packed columnwise in a linear
044: *          array.  The j-th column of U or L is stored in the array AP
045: *          as follows:
046: *          if UPLO = 'U', AP(i + (j-1)*j/2) = U(i,j) for 1<=i<=j;
047: *          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = L(i,j) for j<=i<=n.
048: *
049: *  ANORM   (input) REAL
050: *          The 1-norm (or infinity-norm) of the Hermitian matrix A.
051: *
052: *  RCOND   (output) REAL
053: *          The reciprocal of the condition number of the matrix A,
054: *          computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an
055: *          estimate of the 1-norm of inv(A) computed in this routine.
056: *
057: *  WORK    (workspace) COMPLEX array, dimension (2*N)
058: *
059: *  RWORK   (workspace) REAL array, dimension (N)
060: *
061: *  INFO    (output) INTEGER
062: *          = 0:  successful exit
063: *          < 0:  if INFO = -i, the i-th argument had an illegal value
064: *
065: *  =====================================================================
066: *
067: *     .. Parameters ..
068:       REAL               ONE, ZERO
069:       PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
070: *     ..
071: *     .. Local Scalars ..
072:       LOGICAL            UPPER
073:       CHARACTER          NORMIN
074:       INTEGER            IX, KASE
075:       REAL               AINVNM, SCALE, SCALEL, SCALEU, SMLNUM
076:       COMPLEX            ZDUM
077: *     ..
078: *     .. Local Arrays ..
079:       INTEGER            ISAVE( 3 )
080: *     ..
081: *     .. External Functions ..
082:       LOGICAL            LSAME
083:       INTEGER            ICAMAX
084:       REAL               SLAMCH
085:       EXTERNAL           LSAME, ICAMAX, SLAMCH
086: *     ..
087: *     .. External Subroutines ..
088:       EXTERNAL           CLACN2, CLATPS, CSRSCL, XERBLA
089: *     ..
090: *     .. Intrinsic Functions ..
091:       INTRINSIC          ABS, AIMAG, REAL
092: *     ..
093: *     .. Statement Functions ..
094:       REAL               CABS1
095: *     ..
096: *     .. Statement Function definitions ..
097:       CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
098: *     ..
099: *     .. Executable Statements ..
100: *
101: *     Test the input parameters.
102: *
103:       INFO = 0
104:       UPPER = LSAME( UPLO, 'U' )
105:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
106:          INFO = -1
107:       ELSE IF( N.LT.0 ) THEN
108:          INFO = -2
109:       ELSE IF( ANORM.LT.ZERO ) THEN
110:          INFO = -4
111:       END IF
112:       IF( INFO.NE.0 ) THEN
113:          CALL XERBLA( 'CPPCON', -INFO )
114:          RETURN
115:       END IF
116: *
117: *     Quick return if possible
118: *
119:       RCOND = ZERO
120:       IF( N.EQ.0 ) THEN
121:          RCOND = ONE
122:          RETURN
123:       ELSE IF( ANORM.EQ.ZERO ) THEN
124:          RETURN
125:       END IF
126: *
127:       SMLNUM = SLAMCH( 'Safe minimum' )
128: *
129: *     Estimate the 1-norm of the inverse.
130: *
131:       KASE = 0
132:       NORMIN = 'N'
133:    10 CONTINUE
134:       CALL CLACN2( N, WORK( N+1 ), WORK, AINVNM, KASE, ISAVE )
135:       IF( KASE.NE.0 ) THEN
136:          IF( UPPER ) THEN
137: *
138: *           Multiply by inv(U').
139: *
140:             CALL CLATPS( 'Upper', 'Conjugate transpose', 'Non-unit',
141:      \$                   NORMIN, N, AP, WORK, SCALEL, RWORK, INFO )
142:             NORMIN = 'Y'
143: *
144: *           Multiply by inv(U).
145: *
146:             CALL CLATPS( 'Upper', 'No transpose', 'Non-unit', NORMIN, N,
147:      \$                   AP, WORK, SCALEU, RWORK, INFO )
148:          ELSE
149: *
150: *           Multiply by inv(L).
151: *
152:             CALL CLATPS( 'Lower', 'No transpose', 'Non-unit', NORMIN, N,
153:      \$                   AP, WORK, SCALEL, RWORK, INFO )
154:             NORMIN = 'Y'
155: *
156: *           Multiply by inv(L').
157: *
158:             CALL CLATPS( 'Lower', 'Conjugate transpose', 'Non-unit',
159:      \$                   NORMIN, N, AP, WORK, SCALEU, RWORK, INFO )
160:          END IF
161: *
162: *        Multiply by 1/SCALE if doing so will not cause overflow.
163: *
164:          SCALE = SCALEL*SCALEU
165:          IF( SCALE.NE.ONE ) THEN
166:             IX = ICAMAX( N, WORK, 1 )
167:             IF( SCALE.LT.CABS1( WORK( IX ) )*SMLNUM .OR. SCALE.EQ.ZERO )
168:      \$         GO TO 20
169:             CALL CSRSCL( N, SCALE, WORK, 1 )
170:          END IF
171:          GO TO 10
172:       END IF
173: *
174: *     Compute the estimate of the reciprocal condition number.
175: *
176:       IF( AINVNM.NE.ZERO )
177:      \$   RCOND = ( ONE / AINVNM ) / ANORM
178: *
179:    20 CONTINUE
180:       RETURN
181: *
182: *     End of CPPCON
183: *
184:       END
185: ```