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