001:       SUBROUTINE DTPCON( NORM, UPLO, DIAG, N, AP, RCOND, WORK, IWORK,
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 DLACN2 in place of DLACON, 5 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:       INTEGER            IWORK( * )
018:       DOUBLE PRECISION   AP( * ), WORK( * )
019: *     ..
020: *
021: *  Purpose
022: *  =======
023: *
024: *  DTPCON 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) DOUBLE PRECISION 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) DOUBLE PRECISION array, dimension (3*N)
066: *
067: *  IWORK   (workspace) INTEGER 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: *     ..
085: *     .. Local Arrays ..
086:       INTEGER            ISAVE( 3 )
087: *     ..
088: *     .. External Functions ..
089:       LOGICAL            LSAME
090:       INTEGER            IDAMAX
091:       DOUBLE PRECISION   DLAMCH, DLANTP
092:       EXTERNAL           LSAME, IDAMAX, DLAMCH, DLANTP
093: *     ..
094: *     .. External Subroutines ..
095:       EXTERNAL           DLACN2, DLATPS, DRSCL, XERBLA
096: *     ..
097: *     .. Intrinsic Functions ..
098:       INTRINSIC          ABS, DBLE, MAX
099: *     ..
100: *     .. Executable Statements ..
101: *
102: *     Test the input parameters.
103: *
104:       INFO = 0
105:       UPPER = LSAME( UPLO, 'U' )
106:       ONENRM = NORM.EQ.'1' .OR. LSAME( NORM, 'O' )
107:       NOUNIT = LSAME( DIAG, 'N' )
108: *
109:       IF( .NOT.ONENRM .AND. .NOT.LSAME( NORM, 'I' ) ) THEN
110:          INFO = -1
111:       ELSE IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
112:          INFO = -2
113:       ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
114:          INFO = -3
115:       ELSE IF( N.LT.0 ) THEN
116:          INFO = -4
117:       END IF
118:       IF( INFO.NE.0 ) THEN
119:          CALL XERBLA( 'DTPCON', -INFO )
120:          RETURN
121:       END IF
122: *
123: *     Quick return if possible
124: *
125:       IF( N.EQ.0 ) THEN
126:          RCOND = ONE
127:          RETURN
128:       END IF
129: *
130:       RCOND = ZERO
131:       SMLNUM = DLAMCH( 'Safe minimum' )*DBLE( MAX( 1, N ) )
132: *
133: *     Compute the norm of the triangular matrix A.
134: *
135:       ANORM = DLANTP( NORM, UPLO, DIAG, N, AP, WORK )
136: *
137: *     Continue only if ANORM > 0.
138: *
139:       IF( ANORM.GT.ZERO ) THEN
140: *
141: *        Estimate the norm of the inverse of A.
142: *
143:          AINVNM = ZERO
144:          NORMIN = 'N'
145:          IF( ONENRM ) THEN
146:             KASE1 = 1
147:          ELSE
148:             KASE1 = 2
149:          END IF
150:          KASE = 0
151:    10    CONTINUE
152:          CALL DLACN2( N, WORK( N+1 ), WORK, IWORK, AINVNM, KASE, ISAVE )
153:          IF( KASE.NE.0 ) THEN
154:             IF( KASE.EQ.KASE1 ) THEN
155: *
156: *              Multiply by inv(A).
157: *
158:                CALL DLATPS( UPLO, 'No transpose', DIAG, NORMIN, N, AP,
159:      $                      WORK, SCALE, WORK( 2*N+1 ), INFO )
160:             ELSE
161: *
162: *              Multiply by inv(A').
163: *
164:                CALL DLATPS( UPLO, 'Transpose', DIAG, NORMIN, N, AP,
165:      $                      WORK, SCALE, WORK( 2*N+1 ), INFO )
166:             END IF
167:             NORMIN = 'Y'
168: *
169: *           Multiply by 1/SCALE if doing so will not cause overflow.
170: *
171:             IF( SCALE.NE.ONE ) THEN
172:                IX = IDAMAX( N, WORK, 1 )
173:                XNORM = ABS( WORK( IX ) )
174:                IF( SCALE.LT.XNORM*SMLNUM .OR. SCALE.EQ.ZERO )
175:      $            GO TO 20
176:                CALL DRSCL( N, SCALE, WORK, 1 )
177:             END IF
178:             GO TO 10
179:          END IF
180: *
181: *        Compute the estimate of the reciprocal condition number.
182: *
183:          IF( AINVNM.NE.ZERO )
184:      $      RCOND = ( ONE / ANORM ) / AINVNM
185:       END IF
186: *
187:    20 CONTINUE
188:       RETURN
189: *
190: *     End of DTPCON
191: *
192:       END
193: