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