001:       SUBROUTINE ZTPCON( NORM, UPLO, DIAG, N, AP, RCOND, WORK, RWORK,
002:      $                   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, N
013:       DOUBLE PRECISION   RCOND
014: *     ..
015: *     .. Array Arguments ..
016:       DOUBLE PRECISION   RWORK( * )
017:       COMPLEX*16         AP( * ), WORK( * )
018: *     ..
019: *
020: *  Purpose
021: *  =======
022: *
023: *  ZTPCON estimates the reciprocal of the condition number of a packed
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: *  AP      (input) COMPLEX*16 array, dimension (N*(N+1)/2)
052: *          The upper or lower triangular matrix A, packed columnwise in
053: *          a linear array.  The j-th column of A is stored in the array
054: *          AP as follows:
055: *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
056: *          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
057: *          If DIAG = 'U', the diagonal elements of A are not referenced
058: *          and are assumed to be 1.
059: *
060: *  RCOND   (output) DOUBLE PRECISION
061: *          The reciprocal of the condition number of the matrix A,
062: *          computed as RCOND = 1/(norm(A) * norm(inv(A))).
063: *
064: *  WORK    (workspace) COMPLEX*16 array, dimension (2*N)
065: *
066: *  RWORK   (workspace) DOUBLE PRECISION array, dimension (N)
067: *
068: *  INFO    (output) INTEGER
069: *          = 0:  successful exit
070: *          < 0:  if INFO = -i, the i-th argument had an illegal value
071: *
072: *  =====================================================================
073: *
074: *     .. Parameters ..
075:       DOUBLE PRECISION   ONE, ZERO
076:       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 )
077: *     ..
078: *     .. Local Scalars ..
079:       LOGICAL            NOUNIT, ONENRM, UPPER
080:       CHARACTER          NORMIN
081:       INTEGER            IX, KASE, KASE1
082:       DOUBLE PRECISION   AINVNM, ANORM, SCALE, SMLNUM, XNORM
083:       COMPLEX*16         ZDUM
084: *     ..
085: *     .. Local Arrays ..
086:       INTEGER            ISAVE( 3 )
087: *     ..
088: *     .. External Functions ..
089:       LOGICAL            LSAME
090:       INTEGER            IZAMAX
091:       DOUBLE PRECISION   DLAMCH, ZLANTP
092:       EXTERNAL           LSAME, IZAMAX, DLAMCH, ZLANTP
093: *     ..
094: *     .. External Subroutines ..
095:       EXTERNAL           XERBLA, ZDRSCL, ZLACN2, ZLATPS
096: *     ..
097: *     .. Intrinsic Functions ..
098:       INTRINSIC          ABS, DBLE, DIMAG, MAX
099: *     ..
100: *     .. Statement Functions ..
101:       DOUBLE PRECISION   CABS1
102: *     ..
103: *     .. Statement Function definitions ..
104:       CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
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:       END IF
124:       IF( INFO.NE.0 ) THEN
125:          CALL XERBLA( 'ZTPCON', -INFO )
126:          RETURN
127:       END IF
128: *
129: *     Quick return if possible
130: *
131:       IF( N.EQ.0 ) THEN
132:          RCOND = ONE
133:          RETURN
134:       END IF
135: *
136:       RCOND = ZERO
137:       SMLNUM = DLAMCH( 'Safe minimum' )*DBLE( MAX( 1, N ) )
138: *
139: *     Compute the norm of the triangular matrix A.
140: *
141:       ANORM = ZLANTP( NORM, UPLO, DIAG, N, AP, RWORK )
142: *
143: *     Continue only if ANORM > 0.
144: *
145:       IF( ANORM.GT.ZERO ) THEN
146: *
147: *        Estimate the norm of the inverse of A.
148: *
149:          AINVNM = ZERO
150:          NORMIN = 'N'
151:          IF( ONENRM ) THEN
152:             KASE1 = 1
153:          ELSE
154:             KASE1 = 2
155:          END IF
156:          KASE = 0
157:    10    CONTINUE
158:          CALL ZLACN2( N, WORK( N+1 ), WORK, AINVNM, KASE, ISAVE )
159:          IF( KASE.NE.0 ) THEN
160:             IF( KASE.EQ.KASE1 ) THEN
161: *
162: *              Multiply by inv(A).
163: *
164:                CALL ZLATPS( UPLO, 'No transpose', DIAG, NORMIN, N, AP,
165:      $                      WORK, SCALE, RWORK, INFO )
166:             ELSE
167: *
168: *              Multiply by inv(A').
169: *
170:                CALL ZLATPS( UPLO, 'Conjugate transpose', DIAG, NORMIN,
171:      $                      N, AP, WORK, SCALE, RWORK, INFO )
172:             END IF
173:             NORMIN = 'Y'
174: *
175: *           Multiply by 1/SCALE if doing so will not cause overflow.
176: *
177:             IF( SCALE.NE.ONE ) THEN
178:                IX = IZAMAX( N, WORK, 1 )
179:                XNORM = CABS1( WORK( IX ) )
180:                IF( SCALE.LT.XNORM*SMLNUM .OR. SCALE.EQ.ZERO )
181:      $            GO TO 20
182:                CALL ZDRSCL( N, SCALE, WORK, 1 )
183:             END IF
184:             GO TO 10
185:          END IF
186: *
187: *        Compute the estimate of the reciprocal condition number.
188: *
189:          IF( AINVNM.NE.ZERO )
190:      $      RCOND = ( ONE / ANORM ) / AINVNM
191:       END IF
192: *
193:    20 CONTINUE
194:       RETURN
195: *
196: *     End of ZTPCON
197: *
198:       END
199: