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