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