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