```001:       SUBROUTINE ZGECON( NORM, N, A, LDA, ANORM, 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          NORM
012:       INTEGER            INFO, LDA, N
013:       DOUBLE PRECISION   ANORM, RCOND
014: *     ..
015: *     .. Array Arguments ..
016:       DOUBLE PRECISION   RWORK( * )
017:       COMPLEX*16         A( LDA, * ), WORK( * )
018: *     ..
019: *
020: *  Purpose
021: *  =======
022: *
023: *  ZGECON estimates the reciprocal of the condition number of a general
024: *  complex matrix A, in either the 1-norm or the infinity-norm, using
025: *  the LU factorization computed by ZGETRF.
026: *
027: *  An estimate is obtained for norm(inv(A)), and the reciprocal of the
028: *  condition number is 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: *  N       (input) INTEGER
041: *          The order of the matrix A.  N >= 0.
042: *
043: *  A       (input) COMPLEX*16 array, dimension (LDA,N)
044: *          The factors L and U from the factorization A = P*L*U
045: *          as computed by ZGETRF.
046: *
047: *  LDA     (input) INTEGER
048: *          The leading dimension of the array A.  LDA >= max(1,N).
049: *
050: *  ANORM   (input) DOUBLE PRECISION
051: *          If NORM = '1' or 'O', the 1-norm of the original matrix A.
052: *          If NORM = 'I', the infinity-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/(norm(A) * norm(inv(A))).
057: *
058: *  WORK    (workspace) COMPLEX*16 array, dimension (2*N)
059: *
060: *  RWORK   (workspace) DOUBLE PRECISION array, dimension (2*N)
061: *
062: *  INFO    (output) INTEGER
063: *          = 0:  successful exit
064: *          < 0:  if INFO = -i, the i-th argument had an illegal value
065: *
066: *  =====================================================================
067: *
068: *     .. Parameters ..
069:       DOUBLE PRECISION   ONE, ZERO
070:       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 )
071: *     ..
072: *     .. Local Scalars ..
073:       LOGICAL            ONENRM
074:       CHARACTER          NORMIN
075:       INTEGER            IX, KASE, KASE1
076:       DOUBLE PRECISION   AINVNM, SCALE, SL, SMLNUM, SU
077:       COMPLEX*16         ZDUM
078: *     ..
079: *     .. Local Arrays ..
080:       INTEGER            ISAVE( 3 )
081: *     ..
082: *     .. External Functions ..
083:       LOGICAL            LSAME
084:       INTEGER            IZAMAX
085:       DOUBLE PRECISION   DLAMCH
086:       EXTERNAL           LSAME, IZAMAX, DLAMCH
087: *     ..
088: *     .. External Subroutines ..
089:       EXTERNAL           XERBLA, ZDRSCL, ZLACN2, ZLATRS
090: *     ..
091: *     .. Intrinsic Functions ..
092:       INTRINSIC          ABS, DBLE, DIMAG, MAX
093: *     ..
094: *     .. Statement Functions ..
095:       DOUBLE PRECISION   CABS1
096: *     ..
097: *     .. Statement Function definitions ..
098:       CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
099: *     ..
100: *     .. Executable Statements ..
101: *
102: *     Test the input parameters.
103: *
104:       INFO = 0
105:       ONENRM = NORM.EQ.'1' .OR. LSAME( NORM, 'O' )
106:       IF( .NOT.ONENRM .AND. .NOT.LSAME( NORM, 'I' ) ) THEN
107:          INFO = -1
108:       ELSE IF( N.LT.0 ) THEN
109:          INFO = -2
110:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
111:          INFO = -4
112:       ELSE IF( ANORM.LT.ZERO ) THEN
113:          INFO = -5
114:       END IF
115:       IF( INFO.NE.0 ) THEN
116:          CALL XERBLA( 'ZGECON', -INFO )
117:          RETURN
118:       END IF
119: *
120: *     Quick return if possible
121: *
122:       RCOND = ZERO
123:       IF( N.EQ.0 ) THEN
124:          RCOND = ONE
125:          RETURN
126:       ELSE IF( ANORM.EQ.ZERO ) THEN
127:          RETURN
128:       END IF
129: *
130:       SMLNUM = DLAMCH( 'Safe minimum' )
131: *
132: *     Estimate the norm of inv(A).
133: *
134:       AINVNM = ZERO
135:       NORMIN = 'N'
136:       IF( ONENRM ) THEN
137:          KASE1 = 1
138:       ELSE
139:          KASE1 = 2
140:       END IF
141:       KASE = 0
142:    10 CONTINUE
143:       CALL ZLACN2( N, WORK( N+1 ), WORK, AINVNM, KASE, ISAVE )
144:       IF( KASE.NE.0 ) THEN
145:          IF( KASE.EQ.KASE1 ) THEN
146: *
147: *           Multiply by inv(L).
148: *
149:             CALL ZLATRS( 'Lower', 'No transpose', 'Unit', NORMIN, N, A,
150:      \$                   LDA, WORK, SL, RWORK, INFO )
151: *
152: *           Multiply by inv(U).
153: *
154:             CALL ZLATRS( 'Upper', 'No transpose', 'Non-unit', NORMIN, N,
155:      \$                   A, LDA, WORK, SU, RWORK( N+1 ), INFO )
156:          ELSE
157: *
158: *           Multiply by inv(U').
159: *
160:             CALL ZLATRS( 'Upper', 'Conjugate transpose', 'Non-unit',
161:      \$                   NORMIN, N, A, LDA, WORK, SU, RWORK( N+1 ),
162:      \$                   INFO )
163: *
164: *           Multiply by inv(L').
165: *
166:             CALL ZLATRS( 'Lower', 'Conjugate transpose', 'Unit', NORMIN,
167:      \$                   N, A, LDA, WORK, SL, RWORK, INFO )
168:          END IF
169: *
170: *        Divide X by 1/(SL*SU) if doing so will not cause overflow.
171: *
172:          SCALE = SL*SU
173:          NORMIN = 'Y'
174:          IF( SCALE.NE.ONE ) THEN
175:             IX = IZAMAX( N, WORK, 1 )
176:             IF( SCALE.LT.CABS1( WORK( IX ) )*SMLNUM .OR. SCALE.EQ.ZERO )
177:      \$         GO TO 20
178:             CALL ZDRSCL( N, SCALE, WORK, 1 )
179:          END IF
180:          GO TO 10
181:       END IF
182: *
183: *     Compute the estimate of the reciprocal condition number.
184: *
185:       IF( AINVNM.NE.ZERO )
186:      \$   RCOND = ( ONE / AINVNM ) / ANORM
187: *
188:    20 CONTINUE
189:       RETURN
190: *
191: *     End of ZGECON
192: *
193:       END
194: ```