001:       SUBROUTINE ZHPCON( UPLO, N, AP, IPIV, ANORM, RCOND, WORK, INFO )
002: *
003: *  -- LAPACK routine (version 3.2) --
004: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
005: *  -- Univ. of California Berkeley, Univ. of Colorado Denver 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          UPLO
012:       INTEGER            INFO, N
013:       DOUBLE PRECISION   ANORM, RCOND
014: *     ..
015: *     .. Array Arguments ..
016:       INTEGER            IPIV( * )
017:       COMPLEX*16         AP( * ), WORK( * )
018: *     ..
019: *
020: *  Purpose
021: *  =======
022: *
023: *  ZHPCON estimates the reciprocal of the condition number of a complex
024: *  Hermitian packed matrix A using the factorization A = U*D*U**H or
025: *  A = L*D*L**H computed by ZHPTRF.
026: *
027: *  An estimate is obtained for norm(inv(A)), and the reciprocal of the
028: *  condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))).
029: *
030: *  Arguments
031: *  =========
032: *
033: *  UPLO    (input) CHARACTER*1
034: *          Specifies whether the details of the factorization are stored
035: *          as an upper or lower triangular matrix.
036: *          = 'U':  Upper triangular, form is A = U*D*U**H;
037: *          = 'L':  Lower triangular, form is A = L*D*L**H.
038: *
039: *  N       (input) INTEGER
040: *          The order of the matrix A.  N >= 0.
041: *
042: *  AP      (input) COMPLEX*16 array, dimension (N*(N+1)/2)
043: *          The block diagonal matrix D and the multipliers used to
044: *          obtain the factor U or L as computed by ZHPTRF, stored as a
045: *          packed triangular matrix.
046: *
047: *  IPIV    (input) INTEGER array, dimension (N)
048: *          Details of the interchanges and the block structure of D
049: *          as determined by ZHPTRF.
050: *
051: *  ANORM   (input) DOUBLE PRECISION
052: *          The 1-norm of the original matrix A.
053: *
054: *  RCOND   (output) DOUBLE PRECISION
055: *          The reciprocal of the condition number of the matrix A,
056: *          computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an
057: *          estimate of the 1-norm of inv(A) computed in this routine.
058: *
059: *  WORK    (workspace) COMPLEX*16 array, dimension (2*N)
060: *
061: *  INFO    (output) INTEGER
062: *          = 0:  successful exit
063: *          < 0:  if INFO = -i, the i-th argument had an illegal value
064: *
065: *  =====================================================================
066: *
067: *     .. Parameters ..
068:       DOUBLE PRECISION   ONE, ZERO
069:       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 )
070: *     ..
071: *     .. Local Scalars ..
072:       LOGICAL            UPPER
073:       INTEGER            I, IP, KASE
074:       DOUBLE PRECISION   AINVNM
075: *     ..
076: *     .. Local Arrays ..
077:       INTEGER            ISAVE( 3 )
078: *     ..
079: *     .. External Functions ..
080:       LOGICAL            LSAME
081:       EXTERNAL           LSAME
082: *     ..
083: *     .. External Subroutines ..
084:       EXTERNAL           XERBLA, ZHPTRS, ZLACN2
085: *     ..
086: *     .. Executable Statements ..
087: *
088: *     Test the input parameters.
089: *
090:       INFO = 0
091:       UPPER = LSAME( UPLO, 'U' )
092:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
093:          INFO = -1
094:       ELSE IF( N.LT.0 ) THEN
095:          INFO = -2
096:       ELSE IF( ANORM.LT.ZERO ) THEN
097:          INFO = -5
098:       END IF
099:       IF( INFO.NE.0 ) THEN
100:          CALL XERBLA( 'ZHPCON', -INFO )
101:          RETURN
102:       END IF
103: *
104: *     Quick return if possible
105: *
106:       RCOND = ZERO
107:       IF( N.EQ.0 ) THEN
108:          RCOND = ONE
109:          RETURN
110:       ELSE IF( ANORM.LE.ZERO ) THEN
111:          RETURN
112:       END IF
113: *
114: *     Check that the diagonal matrix D is nonsingular.
115: *
116:       IF( UPPER ) THEN
117: *
118: *        Upper triangular storage: examine D from bottom to top
119: *
120:          IP = N*( N+1 ) / 2
121:          DO 10 I = N, 1, -1
122:             IF( IPIV( I ).GT.0 .AND. AP( IP ).EQ.ZERO )
123:      $         RETURN
124:             IP = IP - I
125:    10    CONTINUE
126:       ELSE
127: *
128: *        Lower triangular storage: examine D from top to bottom.
129: *
130:          IP = 1
131:          DO 20 I = 1, N
132:             IF( IPIV( I ).GT.0 .AND. AP( IP ).EQ.ZERO )
133:      $         RETURN
134:             IP = IP + N - I + 1
135:    20    CONTINUE
136:       END IF
137: *
138: *     Estimate the 1-norm of the inverse.
139: *
140:       KASE = 0
141:    30 CONTINUE
142:       CALL ZLACN2( N, WORK( N+1 ), WORK, AINVNM, KASE, ISAVE )
143:       IF( KASE.NE.0 ) THEN
144: *
145: *        Multiply by inv(L*D*L') or inv(U*D*U').
146: *
147:          CALL ZHPTRS( UPLO, N, 1, AP, IPIV, WORK, N, INFO )
148:          GO TO 30
149:       END IF
150: *
151: *     Compute the estimate of the reciprocal condition number.
152: *
153:       IF( AINVNM.NE.ZERO )
154:      $   RCOND = ( ONE / AINVNM ) / ANORM
155: *
156:       RETURN
157: *
158: *     End of ZHPCON
159: *
160:       END
161: