```001:       REAL FUNCTION SLA_PORCOND( UPLO, N, A, LDA, AF, LDAF, CMODE, C,
002:      \$                           INFO, WORK, IWORK )
003: *
004: *     -- LAPACK routine (version 3.2)                                 --
005: *     -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and --
006: *     -- Jason Riedy of Univ. of California Berkeley.                 --
007: *     -- November 2008                                                --
008: *
009: *     -- LAPACK is a software package provided by Univ. of Tennessee, --
010: *     -- Univ. of California Berkeley and NAG Ltd.                    --
011: *
012:       IMPLICIT NONE
013: *     ..
014: *     .. Scalar Arguments ..
015:       CHARACTER          UPLO
016:       INTEGER            N, LDA, LDAF, INFO, CMODE
017:       REAL               A( LDA, * ), AF( LDAF, * ), WORK( * ),
018:      \$                   C( * )
019: *     ..
020: *     .. Array Arguments ..
021:       INTEGER            IWORK( * )
022: *
023: *     SLA_PORCOND Estimates the Skeel condition number of  op(A) * op2(C)
024: *     where op2 is determined by CMODE as follows
025: *     CMODE =  1    op2(C) = C
026: *     CMODE =  0    op2(C) = I
027: *     CMODE = -1    op2(C) = inv(C)
028: *     The Skeel condition number  cond(A) = norminf( |inv(A)||A| )
029: *     is computed by computing scaling factors R such that
030: *     diag(R)*A*op2(C) is row equilibrated and computing the standard
031: *     infinity-norm condition number.
032: *     WORK is a real workspace of size 3*N, and
033: *     IWORK is an integer workspace of size N.
034: *     ..
035: *     .. Local Scalars ..
036:       INTEGER            KASE, I, J
037:       REAL               AINVNM, TMP
038:       LOGICAL            UP
039: *     ..
040: *     .. Array Arguments ..
041:       INTEGER            ISAVE( 3 )
042: *     ..
043: *     .. External Functions ..
044:       LOGICAL            LSAME
045:       INTEGER            ISAMAX
046:       EXTERNAL           LSAME, ISAMAX
047: *     ..
048: *     .. External Subroutines ..
049:       EXTERNAL           SLACN2, SPOTRS, XERBLA
050: *     ..
051: *     .. Intrinsic Functions ..
052:       INTRINSIC          ABS, MAX
053: *     ..
054: *     .. Executable Statements ..
055: *
056:       SLA_PORCOND = 0.0
057: *
058:       INFO = 0
059:       IF( N.LT.0 ) THEN
060:          INFO = -2
061:       END IF
062:       IF( INFO.NE.0 ) THEN
063:          CALL XERBLA( 'SLA_PORCOND', -INFO )
064:          RETURN
065:       END IF
066:
067:       IF( N.EQ.0 ) THEN
068:          SLA_PORCOND = 1.0
069:          RETURN
070:       END IF
071:       UP = .FALSE.
072:       IF ( LSAME( UPLO, 'U' ) ) UP = .TRUE.
073: *
074: *     Compute the equilibration matrix R such that
075: *     inv(R)*A*C has unit 1-norm.
076: *
077:       IF ( UP ) THEN
078:          DO I = 1, N
079:             TMP = 0.0
080:             IF ( CMODE .EQ. 1 ) THEN
081:                DO J = 1, I
082:                   TMP = TMP + ABS( A( J, I ) * C( J ) )
083:                END DO
084:                DO J = I+1, N
085:                   TMP = TMP + ABS( A( I, J ) * C( J ) )
086:                END DO
087:             ELSE IF ( CMODE .EQ. 0 ) THEN
088:                DO J = 1, I
089:                   TMP = TMP + ABS( A( J, I ) )
090:                END DO
091:                DO J = I+1, N
092:                   TMP = TMP + ABS( A( I, J ) )
093:                END DO
094:             ELSE
095:                DO J = 1, I
096:                   TMP = TMP + ABS( A( J ,I ) / C( J ) )
097:                END DO
098:                DO J = I+1, N
099:                   TMP = TMP + ABS( A( I, J ) / C( J ) )
100:                END DO
101:             END IF
102:             WORK( 2*N+I ) = TMP
103:          END DO
104:       ELSE
105:          DO I = 1, N
106:             TMP = 0.0
107:             IF ( CMODE .EQ. 1 ) THEN
108:                DO J = 1, I
109:                   TMP = TMP + ABS( A( I, J ) * C( J ) )
110:                END DO
111:                DO J = I+1, N
112:                   TMP = TMP + ABS( A( J, I ) * C( J ) )
113:                END DO
114:             ELSE IF ( CMODE .EQ. 0 ) THEN
115:                DO J = 1, I
116:                   TMP = TMP + ABS( A( I, J ) )
117:                END DO
118:                DO J = I+1, N
119:                   TMP = TMP + ABS( A( J, I ) )
120:                END DO
121:             ELSE
122:                DO J = 1, I
123:                   TMP = TMP + ABS( A( I, J ) / C( J ) )
124:                END DO
125:                DO J = I+1, N
126:                   TMP = TMP + ABS( A( J, I ) / C( J ) )
127:                END DO
128:             END IF
129:             WORK( 2*N+I ) = TMP
130:          END DO
131:       ENDIF
132: *
133: *     Estimate the norm of inv(op(A)).
134: *
135:       AINVNM = 0.0
136:
137:       KASE = 0
138:    10 CONTINUE
139:       CALL SLACN2( N, WORK( N+1 ), WORK, IWORK, AINVNM, KASE, ISAVE )
140:       IF( KASE.NE.0 ) THEN
141:          IF( KASE.EQ.2 ) THEN
142: *
143: *           Multiply by R.
144: *
145:             DO I = 1, N
146:                WORK( I ) = WORK( I ) * WORK( 2*N+I )
147:             END DO
148:
149:             IF (UP) THEN
150:                CALL SPOTRS( 'Upper', N, 1, AF, LDAF, WORK, N, INFO )
151:             ELSE
152:                CALL SPOTRS( 'Lower', N, 1, AF, LDAF, WORK, N, INFO )
153:             ENDIF
154: *
155: *           Multiply by inv(C).
156: *
157:             IF ( CMODE .EQ. 1 ) THEN
158:                DO I = 1, N
159:                   WORK( I ) = WORK( I ) / C( I )
160:                END DO
161:             ELSE IF ( CMODE .EQ. -1 ) THEN
162:                DO I = 1, N
163:                   WORK( I ) = WORK( I ) * C( I )
164:                END DO
165:             END IF
166:          ELSE
167: *
168: *           Multiply by inv(C').
169: *
170:             IF ( CMODE .EQ. 1 ) THEN
171:                DO I = 1, N
172:                   WORK( I ) = WORK( I ) / C( I )
173:                END DO
174:             ELSE IF ( CMODE .EQ. -1 ) THEN
175:                DO I = 1, N
176:                   WORK( I ) = WORK( I ) * C( I )
177:                END DO
178:             END IF
179:
180:             IF ( UP ) THEN
181:                CALL SPOTRS( 'Upper', N, 1, AF, LDAF, WORK, N, INFO )
182:             ELSE
183:                CALL SPOTRS( 'Lower', N, 1, AF, LDAF, WORK, N, INFO )
184:             ENDIF
185: *
186: *           Multiply by R.
187: *
188:             DO I = 1, N
189:                WORK( I ) = WORK( I ) * WORK( 2*N+I )
190:             END DO
191:          END IF
192:          GO TO 10
193:       END IF
194: *
195: *     Compute the estimate of the reciprocal condition number.
196: *
197:       IF( AINVNM .NE. 0.0 )
198:      \$   SLA_PORCOND = ( 1.0 / AINVNM )
199: *
200:       RETURN
201: *
202:       END
203: ```