1 /* ./src_f77/slatdf.f -- translated by f2c (version 20030320).
2    You must link the resulting object file with the libraries:
3 	-lf2c -lm   (in that order)
4 */
5 
6 #include <punc/vf2c.h>
7 
8 /* Table of constant values */
9 
10 static integer c__1 = 1;
11 static integer c_n1 = -1;
12 static real c_b23 = 1.f;
13 static real c_b37 = -1.f;
14 
slatdf_(integer * ijob,integer * n,real * z__,integer * ldz,real * rhs,real * rdsum,real * rdscal,integer * ipiv,integer * jpiv)15 /* Subroutine */ int slatdf_(integer *ijob, integer *n, real *z__, integer *
16 	ldz, real *rhs, real *rdsum, real *rdscal, integer *ipiv, integer *
17 	jpiv)
18 {
19     /* System generated locals */
20     integer z_dim1, z_offset, i__1, i__2;
21     real r__1;
22 
23     /* Builtin functions */
24     double sqrt(doublereal);
25 
26     /* Local variables */
27     static integer i__, j, k;
28     static real bm, bp, xm[8], xp[8];
29     static integer info;
30     static real temp;
31     extern doublereal sdot_(integer *, real *, integer *, real *, integer *);
32     static real work[32];
33     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
34     static real pmone;
35     extern doublereal sasum_(integer *, real *, integer *);
36     static real sminu;
37     static integer iwork[8];
38     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
39 	    integer *), saxpy_(integer *, real *, real *, integer *, real *,
40 	    integer *);
41     static real splus;
42     extern /* Subroutine */ int sgesc2_(integer *, real *, integer *, real *,
43 	    integer *, integer *, real *), sgecon_(char *, integer *, real *,
44 	    integer *, real *, real *, real *, integer *, integer *, ftnlen),
45 	    slassq_(integer *, real *, integer *, real *, real *), slaswp_(
46 	    integer *, real *, integer *, integer *, integer *, integer *,
47 	    integer *);
48 
49 
50 /*  -- LAPACK auxiliary routine (version 3.0) -- */
51 /*     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
52 /*     Courant Institute, Argonne National Lab, and Rice University */
53 /*     June 30, 1999 */
54 
55 /*     .. Scalar Arguments .. */
56 /*     .. */
57 /*     .. Array Arguments .. */
58 /*     .. */
59 
60 /*  Purpose */
61 /*  ======= */
62 
63 /*  SLATDF uses the LU factorization of the n-by-n matrix Z computed by */
64 /*  SGETC2 and computes a contribution to the reciprocal Dif-estimate */
65 /*  by solving Z * x = b for x, and choosing the r.h.s. b such that */
66 /*  the norm of x is as large as possible. On entry RHS = b holds the */
67 /*  contribution from earlier solved sub-systems, and on return RHS = x. */
68 
69 /*  The factorization of Z returned by SGETC2 has the form Z = P*L*U*Q, */
70 /*  where P and Q are permutation matrices. L is lower triangular with */
71 /*  unit diagonal elements and U is upper triangular. */
72 
73 /*  Arguments */
74 /*  ========= */
75 
76 /*  IJOB    (input) INTEGER */
77 /*          IJOB = 2: First compute an approximative null-vector e */
78 /*              of Z using SGECON, e is normalized and solve for */
79 /*              Zx = +-e - f with the sign giving the greater value */
80 /*              of 2-norm(x). About 5 times as expensive as Default. */
81 /*          IJOB .ne. 2: Local look ahead strategy where all entries of */
82 /*              the r.h.s. b is choosen as either +1 or -1 (Default). */
83 
84 /*  N       (input) INTEGER */
85 /*          The number of columns of the matrix Z. */
86 
87 /*  Z       (input) REAL array, dimension (LDZ, N) */
88 /*          On entry, the LU part of the factorization of the n-by-n */
89 /*          matrix Z computed by SGETC2:  Z = P * L * U * Q */
90 
91 /*  LDZ     (input) INTEGER */
92 /*          The leading dimension of the array Z.  LDA >= max(1, N). */
93 
94 /*  RHS     (input/output) REAL array, dimension N. */
95 /*          On entry, RHS contains contributions from other subsystems. */
96 /*          On exit, RHS contains the solution of the subsystem with */
97 /*          entries acoording to the value of IJOB (see above). */
98 
99 /*  RDSUM   (input/output) REAL */
100 /*          On entry, the sum of squares of computed contributions to */
101 /*          the Dif-estimate under computation by STGSYL, where the */
102 /*          scaling factor RDSCAL (see below) has been factored out. */
103 /*          On exit, the corresponding sum of squares updated with the */
104 /*          contributions from the current sub-system. */
105 /*          If TRANS = 'T' RDSUM is not touched. */
106 /*          NOTE: RDSUM only makes sense when STGSY2 is called by STGSYL. */
107 
108 /*  RDSCAL  (input/output) REAL */
109 /*          On entry, scaling factor used to prevent overflow in RDSUM. */
110 /*          On exit, RDSCAL is updated w.r.t. the current contributions */
111 /*          in RDSUM. */
112 /*          If TRANS = 'T', RDSCAL is not touched. */
113 /*          NOTE: RDSCAL only makes sense when STGSY2 is called by */
114 /*                STGSYL. */
115 
116 /*  IPIV    (input) INTEGER array, dimension (N). */
117 /*          The pivot indices; for 1 <= i <= N, row i of the */
118 /*          matrix has been interchanged with row IPIV(i). */
119 
120 /*  JPIV    (input) INTEGER array, dimension (N). */
121 /*          The pivot indices; for 1 <= j <= N, column j of the */
122 /*          matrix has been interchanged with column JPIV(j). */
123 
124 /*  Further Details */
125 /*  =============== */
126 
127 /*  Based on contributions by */
128 /*     Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
129 /*     Umea University, S-901 87 Umea, Sweden. */
130 
131 /*  This routine is a further developed implementation of algorithm */
132 /*  BSOLVE in [1] using complete pivoting in the LU factorization. */
133 
134 /*  [1] Bo Kagstrom and Lars Westin, */
135 /*      Generalized Schur Methods with Condition Estimators for */
136 /*      Solving the Generalized Sylvester Equation, IEEE Transactions */
137 /*      on Automatic Control, Vol. 34, No. 7, July 1989, pp 745-751. */
138 
139 /*  [2] Peter Poromaa, */
140 /*      On Efficient and Robust Estimators for the Separation */
141 /*      between two Regular Matrix Pairs with Applications in */
142 /*      Condition Estimation. Report IMINF-95.05, Departement of */
143 /*      Computing Science, Umea University, S-901 87 Umea, Sweden, 1995. */
144 
145 /*  ===================================================================== */
146 
147 /*     .. Parameters .. */
148 /*     .. */
149 /*     .. Local Scalars .. */
150 /*     .. */
151 /*     .. Local Arrays .. */
152 /*     .. */
153 /*     .. External Subroutines .. */
154 /*     .. */
155 /*     .. External Functions .. */
156 /*     .. */
157 /*     .. Intrinsic Functions .. */
158 /*     .. */
159 /*     .. Executable Statements .. */
160 
161     /* Parameter adjustments */
162     z_dim1 = *ldz;
163     z_offset = 1 + z_dim1;
164     z__ -= z_offset;
165     --rhs;
166     --ipiv;
167     --jpiv;
168 
169     /* Function Body */
170     if (*ijob != 2) {
171 
172 /*        Apply permutations IPIV to RHS */
173 
174 	i__1 = *n - 1;
175 	slaswp_(&c__1, &rhs[1], ldz, &c__1, &i__1, &ipiv[1], &c__1);
176 
177 /*        Solve for L-part choosing RHS either to +1 or -1. */
178 
179 	pmone = -1.f;
180 
181 	i__1 = *n - 1;
182 	for (j = 1; j <= i__1; ++j) {
183 	    bp = rhs[j] + 1.f;
184 	    bm = rhs[j] - 1.f;
185 	    splus = 1.f;
186 
187 /*           Look-ahead for L-part RHS(1:N-1) = + or -1, SPLUS and */
188 /*           SMIN computed more efficiently than in BSOLVE [1]. */
189 
190 	    i__2 = *n - j;
191 	    splus += sdot_(&i__2, &z__[j + 1 + j * z_dim1], &c__1, &z__[j + 1
192 		    + j * z_dim1], &c__1);
193 	    i__2 = *n - j;
194 	    sminu = sdot_(&i__2, &z__[j + 1 + j * z_dim1], &c__1, &rhs[j + 1],
195 		     &c__1);
196 	    splus *= rhs[j];
197 	    if (splus > sminu) {
198 		rhs[j] = bp;
199 	    } else if (sminu > splus) {
200 		rhs[j] = bm;
201 	    } else {
202 
203 /*              In this case the updating sums are equal and we can */
204 /*              choose RHS(J) +1 or -1. The first time this happens */
205 /*              we choose -1, thereafter +1. This is a simple way to */
206 /*              get good estimates of matrices like Byers well-known */
207 /*              example (see [1]). (Not done in BSOLVE.) */
208 
209 		rhs[j] += pmone;
210 		pmone = 1.f;
211 	    }
212 
213 /*           Compute the remaining r.h.s. */
214 
215 	    temp = -rhs[j];
216 	    i__2 = *n - j;
217 	    saxpy_(&i__2, &temp, &z__[j + 1 + j * z_dim1], &c__1, &rhs[j + 1],
218 		     &c__1);
219 
220 /* L10: */
221 	}
222 
223 /*        Solve for U-part, look-ahead for RHS(N) = +-1. This is not done */
224 /*        in BSOLVE and will hopefully give us a better estimate because */
225 /*        any ill-conditioning of the original matrix is transfered to U */
226 /*        and not to L. U(N, N) is an approximation to sigma_min(LU). */
227 
228 	i__1 = *n - 1;
229 	scopy_(&i__1, &rhs[1], &c__1, xp, &c__1);
230 	xp[*n - 1] = rhs[*n] + 1.f;
231 	rhs[*n] += -1.f;
232 	splus = 0.f;
233 	sminu = 0.f;
234 	for (i__ = *n; i__ >= 1; --i__) {
235 	    temp = 1.f / z__[i__ + i__ * z_dim1];
236 	    xp[i__ - 1] *= temp;
237 	    rhs[i__] *= temp;
238 	    i__1 = *n;
239 	    for (k = i__ + 1; k <= i__1; ++k) {
240 		xp[i__ - 1] -= xp[k - 1] * (z__[i__ + k * z_dim1] * temp);
241 		rhs[i__] -= rhs[k] * (z__[i__ + k * z_dim1] * temp);
242 /* L20: */
243 	    }
244 	    splus += (r__1 = xp[i__ - 1], dabs(r__1));
245 	    sminu += (r__1 = rhs[i__], dabs(r__1));
246 /* L30: */
247 	}
248 	if (splus > sminu) {
249 	    scopy_(n, xp, &c__1, &rhs[1], &c__1);
250 	}
251 
252 /*        Apply the permutations JPIV to the computed solution (RHS) */
253 
254 	i__1 = *n - 1;
255 	slaswp_(&c__1, &rhs[1], ldz, &c__1, &i__1, &jpiv[1], &c_n1);
256 
257 /*        Compute the sum of squares */
258 
259 	slassq_(n, &rhs[1], &c__1, rdscal, rdsum);
260 
261     } else {
262 
263 /*        IJOB = 2, Compute approximate nullvector XM of Z */
264 
265 	sgecon_("I", n, &z__[z_offset], ldz, &c_b23, &temp, work, iwork, &
266 		info, (ftnlen)1);
267 	scopy_(n, &work[*n], &c__1, xm, &c__1);
268 
269 /*        Compute RHS */
270 
271 	i__1 = *n - 1;
272 	slaswp_(&c__1, xm, ldz, &c__1, &i__1, &ipiv[1], &c_n1);
273 	temp = 1.f / sqrt(sdot_(n, xm, &c__1, xm, &c__1));
274 	sscal_(n, &temp, xm, &c__1);
275 	scopy_(n, xm, &c__1, xp, &c__1);
276 	saxpy_(n, &c_b23, &rhs[1], &c__1, xp, &c__1);
277 	saxpy_(n, &c_b37, xm, &c__1, &rhs[1], &c__1);
278 	sgesc2_(n, &z__[z_offset], ldz, &rhs[1], &ipiv[1], &jpiv[1], &temp);
279 	sgesc2_(n, &z__[z_offset], ldz, xp, &ipiv[1], &jpiv[1], &temp);
280 	if (sasum_(n, xp, &c__1) > sasum_(n, &rhs[1], &c__1)) {
281 	    scopy_(n, xp, &c__1, &rhs[1], &c__1);
282 	}
283 
284 /*        Compute the sum of squares */
285 
286 	slassq_(n, &rhs[1], &c__1, rdscal, rdsum);
287 
288     }
289 
290     return 0;
291 
292 /*     End of SLATDF */
293 
294 } /* slatdf_ */
295 
296