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