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