001:       SUBROUTINE ZTBCON( NORM, UPLO, DIAG, N, KD, AB, LDAB, RCOND, WORK,
002:      $                   RWORK, 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 ZLACN2 in place of ZLACON, 10 Feb 03, SJH.
009: *
010: *     .. Scalar Arguments ..
011:       CHARACTER          DIAG, NORM, UPLO
012:       INTEGER            INFO, KD, LDAB, N
013:       DOUBLE PRECISION   RCOND
014: *     ..
015: *     .. Array Arguments ..
016:       DOUBLE PRECISION   RWORK( * )
017:       COMPLEX*16         AB( LDAB, * ), WORK( * )
018: *     ..
019: *
020: *  Purpose
021: *  =======
022: *
023: *  ZTBCON 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) COMPLEX*16 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) DOUBLE PRECISION
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) COMPLEX*16 array, dimension (2*N)
072: *
073: *  RWORK   (workspace) DOUBLE PRECISION 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:       DOUBLE PRECISION   ONE, ZERO
083:       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 )
084: *     ..
085: *     .. Local Scalars ..
086:       LOGICAL            NOUNIT, ONENRM, UPPER
087:       CHARACTER          NORMIN
088:       INTEGER            IX, KASE, KASE1
089:       DOUBLE PRECISION   AINVNM, ANORM, SCALE, SMLNUM, XNORM
090:       COMPLEX*16         ZDUM
091: *     ..
092: *     .. Local Arrays ..
093:       INTEGER            ISAVE( 3 )
094: *     ..
095: *     .. External Functions ..
096:       LOGICAL            LSAME
097:       INTEGER            IZAMAX
098:       DOUBLE PRECISION   DLAMCH, ZLANTB
099:       EXTERNAL           LSAME, IZAMAX, DLAMCH, ZLANTB
100: *     ..
101: *     .. External Subroutines ..
102:       EXTERNAL           XERBLA, ZDRSCL, ZLACN2, ZLATBS
103: *     ..
104: *     .. Intrinsic Functions ..
105:       INTRINSIC          ABS, DBLE, DIMAG, MAX
106: *     ..
107: *     .. Statement Functions ..
108:       DOUBLE PRECISION   CABS1
109: *     ..
110: *     .. Statement Function definitions ..
111:       CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
112: *     ..
113: *     .. Executable Statements ..
114: *
115: *     Test the input parameters.
116: *
117:       INFO = 0
118:       UPPER = LSAME( UPLO, 'U' )
119:       ONENRM = NORM.EQ.'1' .OR. LSAME( NORM, 'O' )
120:       NOUNIT = LSAME( DIAG, 'N' )
121: *
122:       IF( .NOT.ONENRM .AND. .NOT.LSAME( NORM, 'I' ) ) THEN
123:          INFO = -1
124:       ELSE IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
125:          INFO = -2
126:       ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
127:          INFO = -3
128:       ELSE IF( N.LT.0 ) THEN
129:          INFO = -4
130:       ELSE IF( KD.LT.0 ) THEN
131:          INFO = -5
132:       ELSE IF( LDAB.LT.KD+1 ) THEN
133:          INFO = -7
134:       END IF
135:       IF( INFO.NE.0 ) THEN
136:          CALL XERBLA( 'ZTBCON', -INFO )
137:          RETURN
138:       END IF
139: *
140: *     Quick return if possible
141: *
142:       IF( N.EQ.0 ) THEN
143:          RCOND = ONE
144:          RETURN
145:       END IF
146: *
147:       RCOND = ZERO
148:       SMLNUM = DLAMCH( 'Safe minimum' )*DBLE( MAX( N, 1 ) )
149: *
150: *     Compute the 1-norm of the triangular matrix A or A'.
151: *
152:       ANORM = ZLANTB( NORM, UPLO, DIAG, N, KD, AB, LDAB, RWORK )
153: *
154: *     Continue only if ANORM > 0.
155: *
156:       IF( ANORM.GT.ZERO ) THEN
157: *
158: *        Estimate the 1-norm of the inverse of A.
159: *
160:          AINVNM = ZERO
161:          NORMIN = 'N'
162:          IF( ONENRM ) THEN
163:             KASE1 = 1
164:          ELSE
165:             KASE1 = 2
166:          END IF
167:          KASE = 0
168:    10    CONTINUE
169:          CALL ZLACN2( N, WORK( N+1 ), WORK, AINVNM, KASE, ISAVE )
170:          IF( KASE.NE.0 ) THEN
171:             IF( KASE.EQ.KASE1 ) THEN
172: *
173: *              Multiply by inv(A).
174: *
175:                CALL ZLATBS( UPLO, 'No transpose', DIAG, NORMIN, N, KD,
176:      $                      AB, LDAB, WORK, SCALE, RWORK, INFO )
177:             ELSE
178: *
179: *              Multiply by inv(A').
180: *
181:                CALL ZLATBS( UPLO, 'Conjugate transpose', DIAG, NORMIN,
182:      $                      N, KD, AB, LDAB, WORK, SCALE, RWORK, INFO )
183:             END IF
184:             NORMIN = 'Y'
185: *
186: *           Multiply by 1/SCALE if doing so will not cause overflow.
187: *
188:             IF( SCALE.NE.ONE ) THEN
189:                IX = IZAMAX( N, WORK, 1 )
190:                XNORM = CABS1( WORK( IX ) )
191:                IF( SCALE.LT.XNORM*SMLNUM .OR. SCALE.EQ.ZERO )
192:      $            GO TO 20
193:                CALL ZDRSCL( N, SCALE, WORK, 1 )
194:             END IF
195:             GO TO 10
196:          END IF
197: *
198: *        Compute the estimate of the reciprocal condition number.
199: *
200:          IF( AINVNM.NE.ZERO )
201:      $      RCOND = ( ONE / ANORM ) / AINVNM
202:       END IF
203: *
204:    20 CONTINUE
205:       RETURN
206: *
207: *     End of ZTBCON
208: *
209:       END
210: