001:       SUBROUTINE STPCON( NORM, UPLO, DIAG, N, AP, 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          DIAG, NORM, UPLO
012:       INTEGER            INFO, N
013:       REAL               RCOND
014: *     ..
015: *     .. Array Arguments ..
016:       INTEGER            IWORK( * )
017:       REAL               AP( * ), WORK( * )
018: *     ..
019: *
020: *  Purpose
021: *  =======
022: *
023: *  STPCON estimates the reciprocal of the condition number of a packed
024: *  triangular matrix A, in either the 1-norm or the infinity-norm.
025: *
026: *  The norm of A is computed and an estimate is obtained for
027: *  norm(inv(A)), then the reciprocal of the condition number is
028: *  computed as
029: *     RCOND = 1 / ( norm(A) * norm(inv(A)) ).
030: *
031: *  Arguments
032: *  =========
033: *
034: *  NORM    (input) CHARACTER*1
035: *          Specifies whether the 1-norm condition number or the
036: *          infinity-norm condition number is required:
037: *          = '1' or 'O':  1-norm;
038: *          = 'I':         Infinity-norm.
039: *
040: *  UPLO    (input) CHARACTER*1
041: *          = 'U':  A is upper triangular;
042: *          = 'L':  A is lower triangular.
043: *
044: *  DIAG    (input) CHARACTER*1
045: *          = 'N':  A is non-unit triangular;
046: *          = 'U':  A is unit triangular.
047: *
048: *  N       (input) INTEGER
049: *          The order of the matrix A.  N >= 0.
050: *
051: *  AP      (input) REAL array, dimension (N*(N+1)/2)
052: *          The upper or lower triangular matrix A, packed columnwise in
053: *          a linear array.  The j-th column of A is stored in the array
054: *          AP as follows:
055: *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
056: *          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
057: *          If DIAG = 'U', the diagonal elements of A are not referenced
058: *          and are assumed to be 1.
059: *
060: *  RCOND   (output) REAL
061: *          The reciprocal of the condition number of the matrix A,
062: *          computed as RCOND = 1/(norm(A) * norm(inv(A))).
063: *
064: *  WORK    (workspace) REAL array, dimension (3*N)
065: *
066: *  IWORK   (workspace) INTEGER array, dimension (N)
067: *
068: *  INFO    (output) INTEGER
069: *          = 0:  successful exit
070: *          < 0:  if INFO = -i, the i-th argument had an illegal value
071: *
072: *  =====================================================================
073: *
074: *     .. Parameters ..
075:       REAL               ONE, ZERO
076:       PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
077: *     ..
078: *     .. Local Scalars ..
079:       LOGICAL            NOUNIT, ONENRM, UPPER
080:       CHARACTER          NORMIN
081:       INTEGER            IX, KASE, KASE1
082:       REAL               AINVNM, ANORM, SCALE, SMLNUM, XNORM
083: *     ..
084: *     .. Local Arrays ..
085:       INTEGER            ISAVE( 3 )
086: *     ..
087: *     .. External Functions ..
088:       LOGICAL            LSAME
089:       INTEGER            ISAMAX
090:       REAL               SLAMCH, SLANTP
091:       EXTERNAL           LSAME, ISAMAX, SLAMCH, SLANTP
092: *     ..
093: *     .. External Subroutines ..
094:       EXTERNAL           SLACN2, SLATPS, SRSCL, XERBLA
095: *     ..
096: *     .. Intrinsic Functions ..
097:       INTRINSIC          ABS, MAX, REAL
098: *     ..
099: *     .. Executable Statements ..
100: *
101: *     Test the input parameters.
102: *
103:       INFO = 0
104:       UPPER = LSAME( UPLO, 'U' )
105:       ONENRM = NORM.EQ.'1' .OR. LSAME( NORM, 'O' )
106:       NOUNIT = LSAME( DIAG, 'N' )
107: *
108:       IF( .NOT.ONENRM .AND. .NOT.LSAME( NORM, 'I' ) ) THEN
109:          INFO = -1
110:       ELSE IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
111:          INFO = -2
112:       ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
113:          INFO = -3
114:       ELSE IF( N.LT.0 ) THEN
115:          INFO = -4
116:       END IF
117:       IF( INFO.NE.0 ) THEN
118:          CALL XERBLA( 'STPCON', -INFO )
119:          RETURN
120:       END IF
121: *
122: *     Quick return if possible
123: *
124:       IF( N.EQ.0 ) THEN
125:          RCOND = ONE
126:          RETURN
127:       END IF
128: *
129:       RCOND = ZERO
130:       SMLNUM = SLAMCH( 'Safe minimum' )*REAL( MAX( 1, N ) )
131: *
132: *     Compute the norm of the triangular matrix A.
133: *
134:       ANORM = SLANTP( NORM, UPLO, DIAG, N, AP, WORK )
135: *
136: *     Continue only if ANORM > 0.
137: *
138:       IF( ANORM.GT.ZERO ) THEN
139: *
140: *        Estimate the norm of the inverse of A.
141: *
142:          AINVNM = ZERO
143:          NORMIN = 'N'
144:          IF( ONENRM ) THEN
145:             KASE1 = 1
146:          ELSE
147:             KASE1 = 2
148:          END IF
149:          KASE = 0
150:    10    CONTINUE
151:          CALL SLACN2( N, WORK( N+1 ), WORK, IWORK, AINVNM, KASE, ISAVE )
152:          IF( KASE.NE.0 ) THEN
153:             IF( KASE.EQ.KASE1 ) THEN
154: *
155: *              Multiply by inv(A).
156: *
157:                CALL SLATPS( UPLO, 'No transpose', DIAG, NORMIN, N, AP,
158:      $                      WORK, SCALE, WORK( 2*N+1 ), INFO )
159:             ELSE
160: *
161: *              Multiply by inv(A').
162: *
163:                CALL SLATPS( UPLO, 'Transpose', DIAG, NORMIN, N, AP,
164:      $                      WORK, SCALE, WORK( 2*N+1 ), INFO )
165:             END IF
166:             NORMIN = 'Y'
167: *
168: *           Multiply by 1/SCALE if doing so will not cause overflow.
169: *
170:             IF( SCALE.NE.ONE ) THEN
171:                IX = ISAMAX( N, WORK, 1 )
172:                XNORM = ABS( WORK( IX ) )
173:                IF( SCALE.LT.XNORM*SMLNUM .OR. SCALE.EQ.ZERO )
174:      $            GO TO 20
175:                CALL SRSCL( N, SCALE, WORK, 1 )
176:             END IF
177:             GO TO 10
178:          END IF
179: *
180: *        Compute the estimate of the reciprocal condition number.
181: *
182:          IF( AINVNM.NE.ZERO )
183:      $      RCOND = ( ONE / ANORM ) / AINVNM
184:       END IF
185: *
186:    20 CONTINUE
187:       RETURN
188: *
189: *     End of STPCON
190: *
191:       END
192: