001:       SUBROUTINE CHECON( UPLO, N, A, LDA, IPIV, ANORM, RCOND, WORK,
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 CLACN2 in place of CLACON, 10 Feb 03, SJH.
009: *
010: *     .. Scalar Arguments ..
011:       CHARACTER          UPLO
012:       INTEGER            INFO, LDA, N
013:       REAL               ANORM, RCOND
014: *     ..
015: *     .. Array Arguments ..
016:       INTEGER            IPIV( * )
017:       COMPLEX            A( LDA, * ), WORK( * )
018: *     ..
019: *
020: *  Purpose
021: *  =======
022: *
023: *  CHECON estimates the reciprocal of the condition number of a complex
024: *  Hermitian matrix A using the factorization A = U*D*U**H or
025: *  A = L*D*L**H computed by CHETRF.
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: *  A       (input) COMPLEX array, dimension (LDA,N)
043: *          The block diagonal matrix D and the multipliers used to
044: *          obtain the factor U or L as computed by CHETRF.
045: *
046: *  LDA     (input) INTEGER
047: *          The leading dimension of the array A.  LDA >= max(1,N).
048: *
049: *  IPIV    (input) INTEGER array, dimension (N)
050: *          Details of the interchanges and the block structure of D
051: *          as determined by CHETRF.
052: *
053: *  ANORM   (input) REAL
054: *          The 1-norm of the original matrix A.
055: *
056: *  RCOND   (output) REAL
057: *          The reciprocal of the condition number of the matrix A,
058: *          computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an
059: *          estimate of the 1-norm of inv(A) computed in this routine.
060: *
061: *  WORK    (workspace) COMPLEX array, dimension (2*N)
062: *
063: *  INFO    (output) INTEGER
064: *          = 0:  successful exit
065: *          < 0:  if INFO = -i, the i-th argument had an illegal value
066: *
067: *  =====================================================================
068: *
069: *     .. Parameters ..
070:       REAL               ONE, ZERO
071:       PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
072: *     ..
073: *     .. Local Scalars ..
074:       LOGICAL            UPPER
075:       INTEGER            I, KASE
076:       REAL               AINVNM
077: *     ..
078: *     .. Local Arrays ..
079:       INTEGER            ISAVE( 3 )
080: *     ..
081: *     .. External Functions ..
082:       LOGICAL            LSAME
083:       EXTERNAL           LSAME
084: *     ..
085: *     .. External Subroutines ..
086:       EXTERNAL           CHETRS, CLACN2, XERBLA
087: *     ..
088: *     .. Intrinsic Functions ..
089:       INTRINSIC          MAX
090: *     ..
091: *     .. Executable Statements ..
092: *
093: *     Test the input parameters.
094: *
095:       INFO = 0
096:       UPPER = LSAME( UPLO, 'U' )
097:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
098:          INFO = -1
099:       ELSE IF( N.LT.0 ) THEN
100:          INFO = -2
101:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
102:          INFO = -4
103:       ELSE IF( ANORM.LT.ZERO ) THEN
104:          INFO = -6
105:       END IF
106:       IF( INFO.NE.0 ) THEN
107:          CALL XERBLA( 'CHECON', -INFO )
108:          RETURN
109:       END IF
110: *
111: *     Quick return if possible
112: *
113:       RCOND = ZERO
114:       IF( N.EQ.0 ) THEN
115:          RCOND = ONE
116:          RETURN
117:       ELSE IF( ANORM.LE.ZERO ) THEN
118:          RETURN
119:       END IF
120: *
121: *     Check that the diagonal matrix D is nonsingular.
122: *
123:       IF( UPPER ) THEN
124: *
125: *        Upper triangular storage: examine D from bottom to top
126: *
127:          DO 10 I = N, 1, -1
128:             IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.ZERO )
129:      $         RETURN
130:    10    CONTINUE
131:       ELSE
132: *
133: *        Lower triangular storage: examine D from top to bottom.
134: *
135:          DO 20 I = 1, N
136:             IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.ZERO )
137:      $         RETURN
138:    20    CONTINUE
139:       END IF
140: *
141: *     Estimate the 1-norm of the inverse.
142: *
143:       KASE = 0
144:    30 CONTINUE
145:       CALL CLACN2( N, WORK( N+1 ), WORK, AINVNM, KASE, ISAVE )
146:       IF( KASE.NE.0 ) THEN
147: *
148: *        Multiply by inv(L*D*L') or inv(U*D*U').
149: *
150:          CALL CHETRS( UPLO, N, 1, A, LDA, IPIV, WORK, N, INFO )
151:          GO TO 30
152:       END IF
153: *
154: *     Compute the estimate of the reciprocal condition number.
155: *
156:       IF( AINVNM.NE.ZERO )
157:      $   RCOND = ( ONE / AINVNM ) / ANORM
158: *
159:       RETURN
160: *
161: *     End of CHECON
162: *
163:       END
164: