```001:       SUBROUTINE SLACON( N, V, X, ISGN, EST, KASE )
002: *
003: *  -- LAPACK auxiliary routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       INTEGER            KASE, N
009:       REAL               EST
010: *     ..
011: *     .. Array Arguments ..
012:       INTEGER            ISGN( * )
013:       REAL               V( * ), X( * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  SLACON estimates the 1-norm of a square, real matrix A.
020: *  Reverse communication is used for evaluating matrix-vector products.
021: *
022: *  Arguments
023: *  =========
024: *
025: *  N      (input) INTEGER
026: *         The order of the matrix.  N >= 1.
027: *
028: *  V      (workspace) REAL array, dimension (N)
029: *         On the final return, V = A*W,  where  EST = norm(V)/norm(W)
030: *         (W is not returned).
031: *
032: *  X      (input/output) REAL array, dimension (N)
033: *         On an intermediate return, X should be overwritten by
034: *               A * X,   if KASE=1,
035: *               A' * X,  if KASE=2,
036: *         and SLACON must be re-called with all the other parameters
037: *         unchanged.
038: *
039: *  ISGN   (workspace) INTEGER array, dimension (N)
040: *
041: *  EST    (input/output) REAL
042: *         On entry with KASE = 1 or 2 and JUMP = 3, EST should be
043: *         unchanged from the previous call to SLACON.
044: *         On exit, EST is an estimate (a lower bound) for norm(A).
045: *
046: *  KASE   (input/output) INTEGER
047: *         On the initial call to SLACON, KASE should be 0.
048: *         On an intermediate return, KASE will be 1 or 2, indicating
049: *         whether X should be overwritten by A * X  or A' * X.
050: *         On the final return from SLACON, KASE will again be 0.
051: *
052: *  Further Details
053: *  ======= =======
054: *
055: *  Contributed by Nick Higham, University of Manchester.
056: *  Originally named SONEST, dated March 16, 1988.
057: *
058: *  Reference: N.J. Higham, "FORTRAN codes for estimating the one-norm of
059: *  a real or complex matrix, with applications to condition estimation",
060: *  ACM Trans. Math. Soft., vol. 14, no. 4, pp. 381-396, December 1988.
061: *
062: *  =====================================================================
063: *
064: *     .. Parameters ..
065:       INTEGER            ITMAX
066:       PARAMETER          ( ITMAX = 5 )
067:       REAL               ZERO, ONE, TWO
068:       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0 )
069: *     ..
070: *     .. Local Scalars ..
071:       INTEGER            I, ITER, J, JLAST, JUMP
072:       REAL               ALTSGN, ESTOLD, TEMP
073: *     ..
074: *     .. External Functions ..
075:       INTEGER            ISAMAX
076:       REAL               SASUM
077:       EXTERNAL           ISAMAX, SASUM
078: *     ..
079: *     .. External Subroutines ..
080:       EXTERNAL           SCOPY
081: *     ..
082: *     .. Intrinsic Functions ..
083:       INTRINSIC          ABS, NINT, REAL, SIGN
084: *     ..
085: *     .. Save statement ..
086:       SAVE
087: *     ..
088: *     .. Executable Statements ..
089: *
090:       IF( KASE.EQ.0 ) THEN
091:          DO 10 I = 1, N
092:             X( I ) = ONE / REAL( N )
093:    10    CONTINUE
094:          KASE = 1
095:          JUMP = 1
096:          RETURN
097:       END IF
098: *
099:       GO TO ( 20, 40, 70, 110, 140 )JUMP
100: *
101: *     ................ ENTRY   (JUMP = 1)
102: *     FIRST ITERATION.  X HAS BEEN OVERWRITTEN BY A*X.
103: *
104:    20 CONTINUE
105:       IF( N.EQ.1 ) THEN
106:          V( 1 ) = X( 1 )
107:          EST = ABS( V( 1 ) )
108: *        ... QUIT
109:          GO TO 150
110:       END IF
111:       EST = SASUM( N, X, 1 )
112: *
113:       DO 30 I = 1, N
114:          X( I ) = SIGN( ONE, X( I ) )
115:          ISGN( I ) = NINT( X( I ) )
116:    30 CONTINUE
117:       KASE = 2
118:       JUMP = 2
119:       RETURN
120: *
121: *     ................ ENTRY   (JUMP = 2)
122: *     FIRST ITERATION.  X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X.
123: *
124:    40 CONTINUE
125:       J = ISAMAX( N, X, 1 )
126:       ITER = 2
127: *
128: *     MAIN LOOP - ITERATIONS 2,3,...,ITMAX.
129: *
130:    50 CONTINUE
131:       DO 60 I = 1, N
132:          X( I ) = ZERO
133:    60 CONTINUE
134:       X( J ) = ONE
135:       KASE = 1
136:       JUMP = 3
137:       RETURN
138: *
139: *     ................ ENTRY   (JUMP = 3)
140: *     X HAS BEEN OVERWRITTEN BY A*X.
141: *
142:    70 CONTINUE
143:       CALL SCOPY( N, X, 1, V, 1 )
144:       ESTOLD = EST
145:       EST = SASUM( N, V, 1 )
146:       DO 80 I = 1, N
147:          IF( NINT( SIGN( ONE, X( I ) ) ).NE.ISGN( I ) )
148:      \$      GO TO 90
149:    80 CONTINUE
150: *     REPEATED SIGN VECTOR DETECTED, HENCE ALGORITHM HAS CONVERGED.
151:       GO TO 120
152: *
153:    90 CONTINUE
154: *     TEST FOR CYCLING.
155:       IF( EST.LE.ESTOLD )
156:      \$   GO TO 120
157: *
158:       DO 100 I = 1, N
159:          X( I ) = SIGN( ONE, X( I ) )
160:          ISGN( I ) = NINT( X( I ) )
161:   100 CONTINUE
162:       KASE = 2
163:       JUMP = 4
164:       RETURN
165: *
166: *     ................ ENTRY   (JUMP = 4)
167: *     X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X.
168: *
169:   110 CONTINUE
170:       JLAST = J
171:       J = ISAMAX( N, X, 1 )
172:       IF( ( X( JLAST ).NE.ABS( X( J ) ) ) .AND. ( ITER.LT.ITMAX ) ) THEN
173:          ITER = ITER + 1
174:          GO TO 50
175:       END IF
176: *
177: *     ITERATION COMPLETE.  FINAL STAGE.
178: *
179:   120 CONTINUE
180:       ALTSGN = ONE
181:       DO 130 I = 1, N
182:          X( I ) = ALTSGN*( ONE+REAL( I-1 ) / REAL( N-1 ) )
183:          ALTSGN = -ALTSGN
184:   130 CONTINUE
185:       KASE = 1
186:       JUMP = 5
187:       RETURN
188: *
189: *     ................ ENTRY   (JUMP = 5)
190: *     X HAS BEEN OVERWRITTEN BY A*X.
191: *
192:   140 CONTINUE
193:       TEMP = TWO*( SASUM( N, X, 1 ) / REAL( 3*N ) )
194:       IF( TEMP.GT.EST ) THEN
195:          CALL SCOPY( N, X, 1, V, 1 )
196:          EST = TEMP
197:       END IF
198: *
199:   150 CONTINUE
200:       KASE = 0
201:       RETURN
202: *
203: *     End of SLACON
204: *
205:       END
206: ```