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