C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / zsytf2_rook.c
1 #include <math.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <complex.h>
6 #ifdef complex
7 #undef complex
8 #endif
9 #ifdef I
10 #undef I
11 #endif
12
13 #if defined(_WIN64)
14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
16 #else
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
19 #endif
20
21 #ifdef LAPACK_ILP64
22 typedef BLASLONG blasint;
23 #if defined(_WIN64)
24 #define blasabs(x) llabs(x)
25 #else
26 #define blasabs(x) labs(x)
27 #endif
28 #else
29 typedef int blasint;
30 #define blasabs(x) abs(x)
31 #endif
32
33 typedef blasint integer;
34
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
38 typedef float real;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
42 #ifdef _MSC_VER
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
47 #else
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52 #endif
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
55 typedef int logical;
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
59
60 #define TRUE_ (1)
61 #define FALSE_ (0)
62
63 /* Extern is for use with -E */
64 #ifndef Extern
65 #define Extern extern
66 #endif
67
68 /* I/O stuff */
69
70 typedef int flag;
71 typedef int ftnlen;
72 typedef int ftnint;
73
74 /*external read, write*/
75 typedef struct
76 {       flag cierr;
77         ftnint ciunit;
78         flag ciend;
79         char *cifmt;
80         ftnint cirec;
81 } cilist;
82
83 /*internal read, write*/
84 typedef struct
85 {       flag icierr;
86         char *iciunit;
87         flag iciend;
88         char *icifmt;
89         ftnint icirlen;
90         ftnint icirnum;
91 } icilist;
92
93 /*open*/
94 typedef struct
95 {       flag oerr;
96         ftnint ounit;
97         char *ofnm;
98         ftnlen ofnmlen;
99         char *osta;
100         char *oacc;
101         char *ofm;
102         ftnint orl;
103         char *oblnk;
104 } olist;
105
106 /*close*/
107 typedef struct
108 {       flag cerr;
109         ftnint cunit;
110         char *csta;
111 } cllist;
112
113 /*rewind, backspace, endfile*/
114 typedef struct
115 {       flag aerr;
116         ftnint aunit;
117 } alist;
118
119 /* inquire */
120 typedef struct
121 {       flag inerr;
122         ftnint inunit;
123         char *infile;
124         ftnlen infilen;
125         ftnint  *inex;  /*parameters in standard's order*/
126         ftnint  *inopen;
127         ftnint  *innum;
128         ftnint  *innamed;
129         char    *inname;
130         ftnlen  innamlen;
131         char    *inacc;
132         ftnlen  inacclen;
133         char    *inseq;
134         ftnlen  inseqlen;
135         char    *indir;
136         ftnlen  indirlen;
137         char    *infmt;
138         ftnlen  infmtlen;
139         char    *inform;
140         ftnint  informlen;
141         char    *inunf;
142         ftnlen  inunflen;
143         ftnint  *inrecl;
144         ftnint  *innrec;
145         char    *inblank;
146         ftnlen  inblanklen;
147 } inlist;
148
149 #define VOID void
150
151 union Multitype {       /* for multiple entry points */
152         integer1 g;
153         shortint h;
154         integer i;
155         /* longint j; */
156         real r;
157         doublereal d;
158         complex c;
159         doublecomplex z;
160         };
161
162 typedef union Multitype Multitype;
163
164 struct Vardesc {        /* for Namelist */
165         char *name;
166         char *addr;
167         ftnlen *dims;
168         int  type;
169         };
170 typedef struct Vardesc Vardesc;
171
172 struct Namelist {
173         char *name;
174         Vardesc **vars;
175         int nvars;
176         };
177 typedef struct Namelist Namelist;
178
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b)   ((a) >> (b) & 1)
186 #define bit_clear(a,b)  ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b)    ((a) |  ((uinteger)1 << (b)))
188
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
192 #ifdef _MSC_VER
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/Cd(b)._Val[1]);}
195 #else
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198 #endif
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) {         ftnlen i, nc, ll; char *f__rp, *lp;     ll = (llp); lp = (lpp);         for(i=0; i < (int)*(np); ++i) {                 nc = ll;                if((rnp)[i] < nc) nc = (rnp)[i];                ll -= nc;               f__rp = (rpp)[i];               while(--nc >= 0) *lp++ = *(f__rp)++;         }  while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle_() continue;
256 #define myceiling_(w) {ceil(w)}
257 #define myhuge_(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc_(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
260
261 /* procedure parameter types for -A and -C++ */
262
263 #define F2C_proc_par_types 1
264 #ifdef __cplusplus
265 typedef logical (*L_fp)(...);
266 #else
267 typedef logical (*L_fp)();
268 #endif
269
270 static float spow_ui(float x, integer n) {
271         float pow=1.0; unsigned long int u;
272         if(n != 0) {
273                 if(n < 0) n = -n, x = 1/x;
274                 for(u = n; ; ) {
275                         if(u & 01) pow *= x;
276                         if(u >>= 1) x *= x;
277                         else break;
278                 }
279         }
280         return pow;
281 }
282 static double dpow_ui(double x, integer n) {
283         double pow=1.0; unsigned long int u;
284         if(n != 0) {
285                 if(n < 0) n = -n, x = 1/x;
286                 for(u = n; ; ) {
287                         if(u & 01) pow *= x;
288                         if(u >>= 1) x *= x;
289                         else break;
290                 }
291         }
292         return pow;
293 }
294 #ifdef _MSC_VER
295 static _Fcomplex cpow_ui(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
328                         if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329                         if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
330                         else break;
331                 }
332         }
333         _Dcomplex p = {pow._Val[0], pow._Val[1]};
334         return p;
335 }
336 #else
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338         _Complex double pow=1.0; unsigned long int u;
339         if(n != 0) {
340                 if(n < 0) n = -n, x = 1/x;
341                 for(u = n; ; ) {
342                         if(u & 01) pow *= x;
343                         if(u >>= 1) x *= x;
344                         else break;
345                 }
346         }
347         return pow;
348 }
349 #endif
350 static integer pow_ii(integer x, integer n) {
351         integer pow; unsigned long int u;
352         if (n <= 0) {
353                 if (n == 0 || x == 1) pow = 1;
354                 else if (x != -1) pow = x == 0 ? 1/x : 0;
355                 else n = -n;
356         }
357         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
358                 u = n;
359                 for(pow = 1; ; ) {
360                         if(u & 01) pow *= x;
361                         if(u >>= 1) x *= x;
362                         else break;
363                 }
364         }
365         return pow;
366 }
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 {
369         double m; integer i, mi;
370         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371                 if (w[i-1]>m) mi=i ,m=w[i-1];
372         return mi-s+1;
373 }
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 {
376         float m; integer i, mi;
377         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378                 if (w[i-1]>m) mi=i ,m=w[i-1];
379         return mi-s+1;
380 }
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382         integer n = *n_, incx = *incx_, incy = *incy_, i;
383 #ifdef _MSC_VER
384         _Fcomplex zdotc = {0.0, 0.0};
385         if (incx == 1 && incy == 1) {
386                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387                         zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388                         zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
389                 }
390         } else {
391                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392                         zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393                         zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
394                 }
395         }
396         pCf(z) = zdotc;
397 }
398 #else
399         _Complex float zdotc = 0.0;
400         if (incx == 1 && incy == 1) {
401                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402                         zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
403                 }
404         } else {
405                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406                         zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
407                 }
408         }
409         pCf(z) = zdotc;
410 }
411 #endif
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413         integer n = *n_, incx = *incx_, incy = *incy_, i;
414 #ifdef _MSC_VER
415         _Dcomplex zdotc = {0.0, 0.0};
416         if (incx == 1 && incy == 1) {
417                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418                         zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419                         zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
420                 }
421         } else {
422                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423                         zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424                         zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
425                 }
426         }
427         pCd(z) = zdotc;
428 }
429 #else
430         _Complex double zdotc = 0.0;
431         if (incx == 1 && incy == 1) {
432                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433                         zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
434                 }
435         } else {
436                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437                         zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
438                 }
439         }
440         pCd(z) = zdotc;
441 }
442 #endif  
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444         integer n = *n_, incx = *incx_, incy = *incy_, i;
445 #ifdef _MSC_VER
446         _Fcomplex zdotc = {0.0, 0.0};
447         if (incx == 1 && incy == 1) {
448                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449                         zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450                         zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
451                 }
452         } else {
453                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454                         zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455                         zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
456                 }
457         }
458         pCf(z) = zdotc;
459 }
460 #else
461         _Complex float zdotc = 0.0;
462         if (incx == 1 && incy == 1) {
463                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464                         zdotc += Cf(&x[i]) * Cf(&y[i]);
465                 }
466         } else {
467                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
469                 }
470         }
471         pCf(z) = zdotc;
472 }
473 #endif
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475         integer n = *n_, incx = *incx_, incy = *incy_, i;
476 #ifdef _MSC_VER
477         _Dcomplex zdotc = {0.0, 0.0};
478         if (incx == 1 && incy == 1) {
479                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480                         zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481                         zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
482                 }
483         } else {
484                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485                         zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486                         zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
487                 }
488         }
489         pCd(z) = zdotc;
490 }
491 #else
492         _Complex double zdotc = 0.0;
493         if (incx == 1 && incy == 1) {
494                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495                         zdotc += Cd(&x[i]) * Cd(&y[i]);
496                 }
497         } else {
498                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
500                 }
501         }
502         pCd(z) = zdotc;
503 }
504 #endif
505 /*  -- translated by f2c (version 20000121).
506    You must link the resulting object file with the libraries:
507         -lf2c -lm   (in that order)
508 */
509
510
511
512
513 /* Table of constant values */
514
515 static doublecomplex c_b1 = {1.,0.};
516 static integer c__1 = 1;
517
518 /* > \brief \b ZSYTF2_ROOK computes the factorization of a complex symmetric indefinite matrix using the bound
519 ed Bunch-Kaufman ("rook") diagonal pivoting method (unblocked algorithm). */
520
521 /*  =========== DOCUMENTATION =========== */
522
523 /* Online html documentation available at */
524 /*            http://www.netlib.org/lapack/explore-html/ */
525
526 /* > \htmlonly */
527 /* > Download ZSYTF2_ROOK + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsytf2_
529 rook.f"> */
530 /* > [TGZ]</a> */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsytf2_
532 rook.f"> */
533 /* > [ZIP]</a> */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsytf2_
535 rook.f"> */
536 /* > [TXT]</a> */
537 /* > \endhtmlonly */
538
539 /*  Definition: */
540 /*  =========== */
541
542 /*       SUBROUTINE ZSYTF2_ROOK( UPLO, N, A, LDA, IPIV, INFO ) */
543
544 /*       CHARACTER          UPLO */
545 /*       INTEGER            INFO, LDA, N */
546 /*       INTEGER            IPIV( * ) */
547 /*       COMPLEX*16         A( LDA, * ) */
548
549
550 /* > \par Purpose: */
551 /*  ============= */
552 /* > */
553 /* > \verbatim */
554 /* > */
555 /* > ZSYTF2_ROOK computes the factorization of a complex symmetric matrix A */
556 /* > using the bounded Bunch-Kaufman ("rook") diagonal pivoting method: */
557 /* > */
558 /* >    A = U*D*U**T  or  A = L*D*L**T */
559 /* > */
560 /* > where U (or L) is a product of permutation and unit upper (lower) */
561 /* > triangular matrices, U**T is the transpose of U, and D is symmetric and */
562 /* > block diagonal with 1-by-1 and 2-by-2 diagonal blocks. */
563 /* > */
564 /* > This is the unblocked version of the algorithm, calling Level 2 BLAS. */
565 /* > \endverbatim */
566
567 /*  Arguments: */
568 /*  ========== */
569
570 /* > \param[in] UPLO */
571 /* > \verbatim */
572 /* >          UPLO is CHARACTER*1 */
573 /* >          Specifies whether the upper or lower triangular part of the */
574 /* >          symmetric matrix A is stored: */
575 /* >          = 'U':  Upper triangular */
576 /* >          = 'L':  Lower triangular */
577 /* > \endverbatim */
578 /* > */
579 /* > \param[in] N */
580 /* > \verbatim */
581 /* >          N is INTEGER */
582 /* >          The order of the matrix A.  N >= 0. */
583 /* > \endverbatim */
584 /* > */
585 /* > \param[in,out] A */
586 /* > \verbatim */
587 /* >          A is COMPLEX*16 array, dimension (LDA,N) */
588 /* >          On entry, the symmetric matrix A.  If UPLO = 'U', the leading */
589 /* >          n-by-n upper triangular part of A contains the upper */
590 /* >          triangular part of the matrix A, and the strictly lower */
591 /* >          triangular part of A is not referenced.  If UPLO = 'L', the */
592 /* >          leading n-by-n lower triangular part of A contains the lower */
593 /* >          triangular part of the matrix A, and the strictly upper */
594 /* >          triangular part of A is not referenced. */
595 /* > */
596 /* >          On exit, the block diagonal matrix D and the multipliers used */
597 /* >          to obtain the factor U or L (see below for further details). */
598 /* > \endverbatim */
599 /* > */
600 /* > \param[in] LDA */
601 /* > \verbatim */
602 /* >          LDA is INTEGER */
603 /* >          The leading dimension of the array A.  LDA >= f2cmax(1,N). */
604 /* > \endverbatim */
605 /* > */
606 /* > \param[out] IPIV */
607 /* > \verbatim */
608 /* >          IPIV is INTEGER array, dimension (N) */
609 /* >          Details of the interchanges and the block structure of D. */
610 /* > */
611 /* >          If UPLO = 'U': */
612 /* >             If IPIV(k) > 0, then rows and columns k and IPIV(k) */
613 /* >             were interchanged and D(k,k) is a 1-by-1 diagonal block. */
614 /* > */
615 /* >             If IPIV(k) < 0 and IPIV(k-1) < 0, then rows and */
616 /* >             columns k and -IPIV(k) were interchanged and rows and */
617 /* >             columns k-1 and -IPIV(k-1) were inerchaged, */
618 /* >             D(k-1:k,k-1:k) is a 2-by-2 diagonal block. */
619 /* > */
620 /* >          If UPLO = 'L': */
621 /* >             If IPIV(k) > 0, then rows and columns k and IPIV(k) */
622 /* >             were interchanged and D(k,k) is a 1-by-1 diagonal block. */
623 /* > */
624 /* >             If IPIV(k) < 0 and IPIV(k+1) < 0, then rows and */
625 /* >             columns k and -IPIV(k) were interchanged and rows and */
626 /* >             columns k+1 and -IPIV(k+1) were inerchaged, */
627 /* >             D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */
628 /* > \endverbatim */
629 /* > */
630 /* > \param[out] INFO */
631 /* > \verbatim */
632 /* >          INFO is INTEGER */
633 /* >          = 0: successful exit */
634 /* >          < 0: if INFO = -k, the k-th argument had an illegal value */
635 /* >          > 0: if INFO = k, D(k,k) is exactly zero.  The factorization */
636 /* >               has been completed, but the block diagonal matrix D is */
637 /* >               exactly singular, and division by zero will occur if it */
638 /* >               is used to solve a system of equations. */
639 /* > \endverbatim */
640
641 /*  Authors: */
642 /*  ======== */
643
644 /* > \author Univ. of Tennessee */
645 /* > \author Univ. of California Berkeley */
646 /* > \author Univ. of Colorado Denver */
647 /* > \author NAG Ltd. */
648
649 /* > \date November 2013 */
650
651 /* > \ingroup complex16SYcomputational */
652
653 /* > \par Further Details: */
654 /*  ===================== */
655 /* > */
656 /* > \verbatim */
657 /* > */
658 /* >  If UPLO = 'U', then A = U*D*U**T, where */
659 /* >     U = P(n)*U(n)* ... *P(k)U(k)* ..., */
660 /* >  i.e., U is a product of terms P(k)*U(k), where k decreases from n to */
661 /* >  1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
662 /* >  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as */
663 /* >  defined by IPIV(k), and U(k) is a unit upper triangular matrix, such */
664 /* >  that if the diagonal block D(k) is of order s (s = 1 or 2), then */
665 /* > */
666 /* >             (   I    v    0   )   k-s */
667 /* >     U(k) =  (   0    I    0   )   s */
668 /* >             (   0    0    I   )   n-k */
669 /* >                k-s   s   n-k */
670 /* > */
671 /* >  If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). */
672 /* >  If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), */
673 /* >  and A(k,k), and v overwrites A(1:k-2,k-1:k). */
674 /* > */
675 /* >  If UPLO = 'L', then A = L*D*L**T, where */
676 /* >     L = P(1)*L(1)* ... *P(k)*L(k)* ..., */
677 /* >  i.e., L is a product of terms P(k)*L(k), where k increases from 1 to */
678 /* >  n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
679 /* >  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as */
680 /* >  defined by IPIV(k), and L(k) is a unit lower triangular matrix, such */
681 /* >  that if the diagonal block D(k) is of order s (s = 1 or 2), then */
682 /* > */
683 /* >             (   I    0     0   )  k-1 */
684 /* >     L(k) =  (   0    I     0   )  s */
685 /* >             (   0    v     I   )  n-k-s+1 */
686 /* >                k-1   s  n-k-s+1 */
687 /* > */
688 /* >  If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). */
689 /* >  If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), */
690 /* >  and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). */
691 /* > \endverbatim */
692
693 /* > \par Contributors: */
694 /*  ================== */
695 /* > */
696 /* > \verbatim */
697 /* > */
698 /* >  November 2013,     Igor Kozachenko, */
699 /* >                  Computer Science Division, */
700 /* >                  University of California, Berkeley */
701 /* > */
702 /* >  September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas, */
703 /* >                  School of Mathematics, */
704 /* >                  University of Manchester */
705 /* > */
706 /* >  01-01-96 - Based on modifications by */
707 /* >    J. Lewis, Boeing Computer Services Company */
708 /* >    A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville abd , USA */
709 /* > \endverbatim */
710
711 /*  ===================================================================== */
712 /* Subroutine */ int zsytf2_rook_(char *uplo, integer *n, doublecomplex *a, 
713         integer *lda, integer *ipiv, integer *info)
714 {
715     /* System generated locals */
716     integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
717     doublereal d__1, d__2;
718     doublecomplex z__1, z__2, z__3, z__4, z__5, z__6;
719
720     /* Local variables */
721     logical done;
722     integer imax, jmax;
723     extern /* Subroutine */ int zsyr_(char *, integer *, doublecomplex *, 
724             doublecomplex *, integer *, doublecomplex *, integer *);
725     integer i__, j, k, p;
726     doublecomplex t;
727     doublereal alpha;
728     extern logical lsame_(char *, char *);
729     doublereal dtemp, sfmin;
730     extern /* Subroutine */ int zscal_(integer *, doublecomplex *, 
731             doublecomplex *, integer *);
732     integer itemp, kstep;
733     logical upper;
734     extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *, 
735             doublecomplex *, integer *);
736     doublecomplex d11, d12, d21, d22;
737     integer ii, kk;
738     extern doublereal dlamch_(char *);
739     integer kp;
740     doublereal absakk;
741     doublecomplex wk;
742     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
743     doublereal colmax;
744     extern integer izamax_(integer *, doublecomplex *, integer *);
745     doublereal rowmax;
746     doublecomplex wkm1, wkp1;
747
748
749 /*  -- LAPACK computational routine (version 3.5.0) -- */
750 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
751 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
752 /*     November 2013 */
753
754
755 /*  ===================================================================== */
756
757
758 /*     Test the input parameters. */
759
760     /* Parameter adjustments */
761     a_dim1 = *lda;
762     a_offset = 1 + a_dim1 * 1;
763     a -= a_offset;
764     --ipiv;
765
766     /* Function Body */
767     *info = 0;
768     upper = lsame_(uplo, "U");
769     if (! upper && ! lsame_(uplo, "L")) {
770         *info = -1;
771     } else if (*n < 0) {
772         *info = -2;
773     } else if (*lda < f2cmax(1,*n)) {
774         *info = -4;
775     }
776     if (*info != 0) {
777         i__1 = -(*info);
778         xerbla_("ZSYTF2_ROOK", &i__1, (ftnlen)11);
779         return 0;
780     }
781
782 /*     Initialize ALPHA for use in choosing pivot block size. */
783
784     alpha = (sqrt(17.) + 1.) / 8.;
785
786 /*     Compute machine safe minimum */
787
788     sfmin = dlamch_("S");
789
790     if (upper) {
791
792 /*        Factorize A as U*D*U**T using the upper triangle of A */
793
794 /*        K is the main loop index, decreasing from N to 1 in steps of */
795 /*        1 or 2 */
796
797         k = *n;
798 L10:
799
800 /*        If K < 1, exit from loop */
801
802         if (k < 1) {
803             goto L70;
804         }
805         kstep = 1;
806         p = k;
807
808 /*        Determine rows and columns to be interchanged and whether */
809 /*        a 1-by-1 or 2-by-2 pivot block will be used */
810
811         i__1 = k + k * a_dim1;
812         absakk = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[k + k * 
813                 a_dim1]), abs(d__2));
814
815 /*        IMAX is the row-index of the largest off-diagonal element in */
816 /*        column K, and COLMAX is its absolute value. */
817 /*        Determine both COLMAX and IMAX. */
818
819         if (k > 1) {
820             i__1 = k - 1;
821             imax = izamax_(&i__1, &a[k * a_dim1 + 1], &c__1);
822             i__1 = imax + k * a_dim1;
823             colmax = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[imax + 
824                     k * a_dim1]), abs(d__2));
825         } else {
826             colmax = 0.;
827         }
828
829         if (f2cmax(absakk,colmax) == 0.) {
830
831 /*           Column K is zero or underflow: set INFO and continue */
832
833             if (*info == 0) {
834                 *info = k;
835             }
836             kp = k;
837         } else {
838
839 /*           Test for interchange */
840
841 /*           Equivalent to testing for (used to handle NaN and Inf) */
842 /*           ABSAKK.GE.ALPHA*COLMAX */
843
844             if (! (absakk < alpha * colmax)) {
845
846 /*              no interchange, */
847 /*              use 1-by-1 pivot block */
848
849                 kp = k;
850             } else {
851
852                 done = FALSE_;
853
854 /*              Loop until pivot found */
855
856 L12:
857
858 /*                 Begin pivot search loop body */
859
860 /*                 JMAX is the column-index of the largest off-diagonal */
861 /*                 element in row IMAX, and ROWMAX is its absolute value. */
862 /*                 Determine both ROWMAX and JMAX. */
863
864                 if (imax != k) {
865                     i__1 = k - imax;
866                     jmax = imax + izamax_(&i__1, &a[imax + (imax + 1) * 
867                             a_dim1], lda);
868                     i__1 = imax + jmax * a_dim1;
869                     rowmax = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&
870                             a[imax + jmax * a_dim1]), abs(d__2));
871                 } else {
872                     rowmax = 0.;
873                 }
874
875                 if (imax > 1) {
876                     i__1 = imax - 1;
877                     itemp = izamax_(&i__1, &a[imax * a_dim1 + 1], &c__1);
878                     i__1 = itemp + imax * a_dim1;
879                     dtemp = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[
880                             itemp + imax * a_dim1]), abs(d__2));
881                     if (dtemp > rowmax) {
882                         rowmax = dtemp;
883                         jmax = itemp;
884                     }
885                 }
886
887 /*                 Equivalent to testing for (used to handle NaN and Inf) */
888 /*                 CABS1( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX */
889
890                 i__1 = imax + imax * a_dim1;
891                 if (! ((d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[imax 
892                         + imax * a_dim1]), abs(d__2)) < alpha * rowmax)) {
893
894 /*                    interchange rows and columns K and IMAX, */
895 /*                    use 1-by-1 pivot block */
896
897                     kp = imax;
898                     done = TRUE_;
899
900 /*                 Equivalent to testing for ROWMAX .EQ. COLMAX, */
901 /*                 used to handle NaN and Inf */
902
903                 } else if (p == jmax || rowmax <= colmax) {
904
905 /*                    interchange rows and columns K+1 and IMAX, */
906 /*                    use 2-by-2 pivot block */
907
908                     kp = imax;
909                     kstep = 2;
910                     done = TRUE_;
911                 } else {
912
913 /*                    Pivot NOT found, set variables and repeat */
914
915                     p = imax;
916                     colmax = rowmax;
917                     imax = jmax;
918                 }
919
920 /*                 End pivot search loop body */
921
922                 if (! done) {
923                     goto L12;
924                 }
925
926             }
927
928 /*           Swap TWO rows and TWO columns */
929
930 /*           First swap */
931
932             if (kstep == 2 && p != k) {
933
934 /*              Interchange rows and column K and P in the leading */
935 /*              submatrix A(1:k,1:k) if we have a 2-by-2 pivot */
936
937                 if (p > 1) {
938                     i__1 = p - 1;
939                     zswap_(&i__1, &a[k * a_dim1 + 1], &c__1, &a[p * a_dim1 + 
940                             1], &c__1);
941                 }
942                 if (p < k - 1) {
943                     i__1 = k - p - 1;
944                     zswap_(&i__1, &a[p + 1 + k * a_dim1], &c__1, &a[p + (p + 
945                             1) * a_dim1], lda);
946                 }
947                 i__1 = k + k * a_dim1;
948                 t.r = a[i__1].r, t.i = a[i__1].i;
949                 i__1 = k + k * a_dim1;
950                 i__2 = p + p * a_dim1;
951                 a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
952                 i__1 = p + p * a_dim1;
953                 a[i__1].r = t.r, a[i__1].i = t.i;
954             }
955
956 /*           Second swap */
957
958             kk = k - kstep + 1;
959             if (kp != kk) {
960
961 /*              Interchange rows and columns KK and KP in the leading */
962 /*              submatrix A(1:k,1:k) */
963
964                 if (kp > 1) {
965                     i__1 = kp - 1;
966                     zswap_(&i__1, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1 
967                             + 1], &c__1);
968                 }
969                 if (kk > 1 && kp < kk - 1) {
970                     i__1 = kk - kp - 1;
971                     zswap_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + (
972                             kp + 1) * a_dim1], lda);
973                 }
974                 i__1 = kk + kk * a_dim1;
975                 t.r = a[i__1].r, t.i = a[i__1].i;
976                 i__1 = kk + kk * a_dim1;
977                 i__2 = kp + kp * a_dim1;
978                 a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
979                 i__1 = kp + kp * a_dim1;
980                 a[i__1].r = t.r, a[i__1].i = t.i;
981                 if (kstep == 2) {
982                     i__1 = k - 1 + k * a_dim1;
983                     t.r = a[i__1].r, t.i = a[i__1].i;
984                     i__1 = k - 1 + k * a_dim1;
985                     i__2 = kp + k * a_dim1;
986                     a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
987                     i__1 = kp + k * a_dim1;
988                     a[i__1].r = t.r, a[i__1].i = t.i;
989                 }
990             }
991
992 /*           Update the leading submatrix */
993
994             if (kstep == 1) {
995
996 /*              1-by-1 pivot block D(k): column k now holds */
997
998 /*              W(k) = U(k)*D(k) */
999
1000 /*              where U(k) is the k-th column of U */
1001
1002                 if (k > 1) {
1003
1004 /*                 Perform a rank-1 update of A(1:k-1,1:k-1) and */
1005 /*                 store U(k) in column k */
1006
1007                     i__1 = k + k * a_dim1;
1008                     if ((d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[k + 
1009                             k * a_dim1]), abs(d__2)) >= sfmin) {
1010
1011 /*                    Perform a rank-1 update of A(1:k-1,1:k-1) as */
1012 /*                    A := A - U(k)*D(k)*U(k)**T */
1013 /*                       = A - W(k)*1/D(k)*W(k)**T */
1014
1015                         z_div(&z__1, &c_b1, &a[k + k * a_dim1]);
1016                         d11.r = z__1.r, d11.i = z__1.i;
1017                         i__1 = k - 1;
1018                         z__1.r = -d11.r, z__1.i = -d11.i;
1019                         zsyr_(uplo, &i__1, &z__1, &a[k * a_dim1 + 1], &c__1, &
1020                                 a[a_offset], lda);
1021
1022 /*                    Store U(k) in column k */
1023
1024                         i__1 = k - 1;
1025                         zscal_(&i__1, &d11, &a[k * a_dim1 + 1], &c__1);
1026                     } else {
1027
1028 /*                    Store L(k) in column K */
1029
1030                         i__1 = k + k * a_dim1;
1031                         d11.r = a[i__1].r, d11.i = a[i__1].i;
1032                         i__1 = k - 1;
1033                         for (ii = 1; ii <= i__1; ++ii) {
1034                             i__2 = ii + k * a_dim1;
1035                             z_div(&z__1, &a[ii + k * a_dim1], &d11);
1036                             a[i__2].r = z__1.r, a[i__2].i = z__1.i;
1037 /* L16: */
1038                         }
1039
1040 /*                    Perform a rank-1 update of A(k+1:n,k+1:n) as */
1041 /*                    A := A - U(k)*D(k)*U(k)**T */
1042 /*                       = A - W(k)*(1/D(k))*W(k)**T */
1043 /*                       = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T */
1044
1045                         i__1 = k - 1;
1046                         z__1.r = -d11.r, z__1.i = -d11.i;
1047                         zsyr_(uplo, &i__1, &z__1, &a[k * a_dim1 + 1], &c__1, &
1048                                 a[a_offset], lda);
1049                     }
1050                 }
1051
1052             } else {
1053
1054 /*              2-by-2 pivot block D(k): columns k and k-1 now hold */
1055
1056 /*              ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */
1057
1058 /*              where U(k) and U(k-1) are the k-th and (k-1)-th columns */
1059 /*              of U */
1060
1061 /*              Perform a rank-2 update of A(1:k-2,1:k-2) as */
1062
1063 /*              A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T */
1064 /*                 = A - ( ( A(k-1)A(k) )*inv(D(k)) ) * ( A(k-1)A(k) )**T */
1065
1066 /*              and store L(k) and L(k+1) in columns k and k+1 */
1067
1068                 if (k > 2) {
1069
1070                     i__1 = k - 1 + k * a_dim1;
1071                     d12.r = a[i__1].r, d12.i = a[i__1].i;
1072                     z_div(&z__1, &a[k - 1 + (k - 1) * a_dim1], &d12);
1073                     d22.r = z__1.r, d22.i = z__1.i;
1074                     z_div(&z__1, &a[k + k * a_dim1], &d12);
1075                     d11.r = z__1.r, d11.i = z__1.i;
1076                     z__3.r = d11.r * d22.r - d11.i * d22.i, z__3.i = d11.r * 
1077                             d22.i + d11.i * d22.r;
1078                     z__2.r = z__3.r - 1., z__2.i = z__3.i + 0.;
1079                     z_div(&z__1, &c_b1, &z__2);
1080                     t.r = z__1.r, t.i = z__1.i;
1081
1082                     for (j = k - 2; j >= 1; --j) {
1083
1084                         i__1 = j + (k - 1) * a_dim1;
1085                         z__3.r = d11.r * a[i__1].r - d11.i * a[i__1].i, 
1086                                 z__3.i = d11.r * a[i__1].i + d11.i * a[i__1]
1087                                 .r;
1088                         i__2 = j + k * a_dim1;
1089                         z__2.r = z__3.r - a[i__2].r, z__2.i = z__3.i - a[i__2]
1090                                 .i;
1091                         z__1.r = t.r * z__2.r - t.i * z__2.i, z__1.i = t.r * 
1092                                 z__2.i + t.i * z__2.r;
1093                         wkm1.r = z__1.r, wkm1.i = z__1.i;
1094                         i__1 = j + k * a_dim1;
1095                         z__3.r = d22.r * a[i__1].r - d22.i * a[i__1].i, 
1096                                 z__3.i = d22.r * a[i__1].i + d22.i * a[i__1]
1097                                 .r;
1098                         i__2 = j + (k - 1) * a_dim1;
1099                         z__2.r = z__3.r - a[i__2].r, z__2.i = z__3.i - a[i__2]
1100                                 .i;
1101                         z__1.r = t.r * z__2.r - t.i * z__2.i, z__1.i = t.r * 
1102                                 z__2.i + t.i * z__2.r;
1103                         wk.r = z__1.r, wk.i = z__1.i;
1104
1105                         for (i__ = j; i__ >= 1; --i__) {
1106                             i__1 = i__ + j * a_dim1;
1107                             i__2 = i__ + j * a_dim1;
1108                             z_div(&z__4, &a[i__ + k * a_dim1], &d12);
1109                             z__3.r = z__4.r * wk.r - z__4.i * wk.i, z__3.i = 
1110                                     z__4.r * wk.i + z__4.i * wk.r;
1111                             z__2.r = a[i__2].r - z__3.r, z__2.i = a[i__2].i - 
1112                                     z__3.i;
1113                             z_div(&z__6, &a[i__ + (k - 1) * a_dim1], &d12);
1114                             z__5.r = z__6.r * wkm1.r - z__6.i * wkm1.i, 
1115                                     z__5.i = z__6.r * wkm1.i + z__6.i * 
1116                                     wkm1.r;
1117                             z__1.r = z__2.r - z__5.r, z__1.i = z__2.i - 
1118                                     z__5.i;
1119                             a[i__1].r = z__1.r, a[i__1].i = z__1.i;
1120 /* L20: */
1121                         }
1122
1123 /*                    Store U(k) and U(k-1) in cols k and k-1 for row J */
1124
1125                         i__1 = j + k * a_dim1;
1126                         z_div(&z__1, &wk, &d12);
1127                         a[i__1].r = z__1.r, a[i__1].i = z__1.i;
1128                         i__1 = j + (k - 1) * a_dim1;
1129                         z_div(&z__1, &wkm1, &d12);
1130                         a[i__1].r = z__1.r, a[i__1].i = z__1.i;
1131
1132 /* L30: */
1133                     }
1134
1135                 }
1136
1137             }
1138         }
1139
1140 /*        Store details of the interchanges in IPIV */
1141
1142         if (kstep == 1) {
1143             ipiv[k] = kp;
1144         } else {
1145             ipiv[k] = -p;
1146             ipiv[k - 1] = -kp;
1147         }
1148
1149 /*        Decrease K and return to the start of the main loop */
1150
1151         k -= kstep;
1152         goto L10;
1153
1154     } else {
1155
1156 /*        Factorize A as L*D*L**T using the lower triangle of A */
1157
1158 /*        K is the main loop index, increasing from 1 to N in steps of */
1159 /*        1 or 2 */
1160
1161         k = 1;
1162 L40:
1163
1164 /*        If K > N, exit from loop */
1165
1166         if (k > *n) {
1167             goto L70;
1168         }
1169         kstep = 1;
1170         p = k;
1171
1172 /*        Determine rows and columns to be interchanged and whether */
1173 /*        a 1-by-1 or 2-by-2 pivot block will be used */
1174
1175         i__1 = k + k * a_dim1;
1176         absakk = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[k + k * 
1177                 a_dim1]), abs(d__2));
1178
1179 /*        IMAX is the row-index of the largest off-diagonal element in */
1180 /*        column K, and COLMAX is its absolute value. */
1181 /*        Determine both COLMAX and IMAX. */
1182
1183         if (k < *n) {
1184             i__1 = *n - k;
1185             imax = k + izamax_(&i__1, &a[k + 1 + k * a_dim1], &c__1);
1186             i__1 = imax + k * a_dim1;
1187             colmax = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[imax + 
1188                     k * a_dim1]), abs(d__2));
1189         } else {
1190             colmax = 0.;
1191         }
1192
1193         if (f2cmax(absakk,colmax) == 0.) {
1194
1195 /*           Column K is zero or underflow: set INFO and continue */
1196
1197             if (*info == 0) {
1198                 *info = k;
1199             }
1200             kp = k;
1201         } else {
1202
1203 /*           Test for interchange */
1204
1205 /*           Equivalent to testing for (used to handle NaN and Inf) */
1206 /*           ABSAKK.GE.ALPHA*COLMAX */
1207
1208             if (! (absakk < alpha * colmax)) {
1209
1210 /*              no interchange, use 1-by-1 pivot block */
1211
1212                 kp = k;
1213             } else {
1214
1215                 done = FALSE_;
1216
1217 /*              Loop until pivot found */
1218
1219 L42:
1220
1221 /*                 Begin pivot search loop body */
1222
1223 /*                 JMAX is the column-index of the largest off-diagonal */
1224 /*                 element in row IMAX, and ROWMAX is its absolute value. */
1225 /*                 Determine both ROWMAX and JMAX. */
1226
1227                 if (imax != k) {
1228                     i__1 = imax - k;
1229                     jmax = k - 1 + izamax_(&i__1, &a[imax + k * a_dim1], lda);
1230                     i__1 = imax + jmax * a_dim1;
1231                     rowmax = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&
1232                             a[imax + jmax * a_dim1]), abs(d__2));
1233                 } else {
1234                     rowmax = 0.;
1235                 }
1236
1237                 if (imax < *n) {
1238                     i__1 = *n - imax;
1239                     itemp = imax + izamax_(&i__1, &a[imax + 1 + imax * a_dim1]
1240                             , &c__1);
1241                     i__1 = itemp + imax * a_dim1;
1242                     dtemp = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[
1243                             itemp + imax * a_dim1]), abs(d__2));
1244                     if (dtemp > rowmax) {
1245                         rowmax = dtemp;
1246                         jmax = itemp;
1247                     }
1248                 }
1249
1250 /*                 Equivalent to testing for (used to handle NaN and Inf) */
1251 /*                 CABS1( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX */
1252
1253                 i__1 = imax + imax * a_dim1;
1254                 if (! ((d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[imax 
1255                         + imax * a_dim1]), abs(d__2)) < alpha * rowmax)) {
1256
1257 /*                    interchange rows and columns K and IMAX, */
1258 /*                    use 1-by-1 pivot block */
1259
1260                     kp = imax;
1261                     done = TRUE_;
1262
1263 /*                 Equivalent to testing for ROWMAX .EQ. COLMAX, */
1264 /*                 used to handle NaN and Inf */
1265
1266                 } else if (p == jmax || rowmax <= colmax) {
1267
1268 /*                    interchange rows and columns K+1 and IMAX, */
1269 /*                    use 2-by-2 pivot block */
1270
1271                     kp = imax;
1272                     kstep = 2;
1273                     done = TRUE_;
1274                 } else {
1275
1276 /*                    Pivot NOT found, set variables and repeat */
1277
1278                     p = imax;
1279                     colmax = rowmax;
1280                     imax = jmax;
1281                 }
1282
1283 /*                 End pivot search loop body */
1284
1285                 if (! done) {
1286                     goto L42;
1287                 }
1288
1289             }
1290
1291 /*           Swap TWO rows and TWO columns */
1292
1293 /*           First swap */
1294
1295             if (kstep == 2 && p != k) {
1296
1297 /*              Interchange rows and column K and P in the trailing */
1298 /*              submatrix A(k:n,k:n) if we have a 2-by-2 pivot */
1299
1300                 if (p < *n) {
1301                     i__1 = *n - p;
1302                     zswap_(&i__1, &a[p + 1 + k * a_dim1], &c__1, &a[p + 1 + p 
1303                             * a_dim1], &c__1);
1304                 }
1305                 if (p > k + 1) {
1306                     i__1 = p - k - 1;
1307                     zswap_(&i__1, &a[k + 1 + k * a_dim1], &c__1, &a[p + (k + 
1308                             1) * a_dim1], lda);
1309                 }
1310                 i__1 = k + k * a_dim1;
1311                 t.r = a[i__1].r, t.i = a[i__1].i;
1312                 i__1 = k + k * a_dim1;
1313                 i__2 = p + p * a_dim1;
1314                 a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
1315                 i__1 = p + p * a_dim1;
1316                 a[i__1].r = t.r, a[i__1].i = t.i;
1317             }
1318
1319 /*           Second swap */
1320
1321             kk = k + kstep - 1;
1322             if (kp != kk) {
1323
1324 /*              Interchange rows and columns KK and KP in the trailing */
1325 /*              submatrix A(k:n,k:n) */
1326
1327                 if (kp < *n) {
1328                     i__1 = *n - kp;
1329                     zswap_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + 1 
1330                             + kp * a_dim1], &c__1);
1331                 }
1332                 if (kk < *n && kp > kk + 1) {
1333                     i__1 = kp - kk - 1;
1334                     zswap_(&i__1, &a[kk + 1 + kk * a_dim1], &c__1, &a[kp + (
1335                             kk + 1) * a_dim1], lda);
1336                 }
1337                 i__1 = kk + kk * a_dim1;
1338                 t.r = a[i__1].r, t.i = a[i__1].i;
1339                 i__1 = kk + kk * a_dim1;
1340                 i__2 = kp + kp * a_dim1;
1341                 a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
1342                 i__1 = kp + kp * a_dim1;
1343                 a[i__1].r = t.r, a[i__1].i = t.i;
1344                 if (kstep == 2) {
1345                     i__1 = k + 1 + k * a_dim1;
1346                     t.r = a[i__1].r, t.i = a[i__1].i;
1347                     i__1 = k + 1 + k * a_dim1;
1348                     i__2 = kp + k * a_dim1;
1349                     a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
1350                     i__1 = kp + k * a_dim1;
1351                     a[i__1].r = t.r, a[i__1].i = t.i;
1352                 }
1353             }
1354
1355 /*           Update the trailing submatrix */
1356
1357             if (kstep == 1) {
1358
1359 /*              1-by-1 pivot block D(k): column k now holds */
1360
1361 /*              W(k) = L(k)*D(k) */
1362
1363 /*              where L(k) is the k-th column of L */
1364
1365                 if (k < *n) {
1366
1367 /*              Perform a rank-1 update of A(k+1:n,k+1:n) and */
1368 /*              store L(k) in column k */
1369
1370                     i__1 = k + k * a_dim1;
1371                     if ((d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[k + 
1372                             k * a_dim1]), abs(d__2)) >= sfmin) {
1373
1374 /*                    Perform a rank-1 update of A(k+1:n,k+1:n) as */
1375 /*                    A := A - L(k)*D(k)*L(k)**T */
1376 /*                       = A - W(k)*(1/D(k))*W(k)**T */
1377
1378                         z_div(&z__1, &c_b1, &a[k + k * a_dim1]);
1379                         d11.r = z__1.r, d11.i = z__1.i;
1380                         i__1 = *n - k;
1381                         z__1.r = -d11.r, z__1.i = -d11.i;
1382                         zsyr_(uplo, &i__1, &z__1, &a[k + 1 + k * a_dim1], &
1383                                 c__1, &a[k + 1 + (k + 1) * a_dim1], lda);
1384
1385 /*                    Store L(k) in column k */
1386
1387                         i__1 = *n - k;
1388                         zscal_(&i__1, &d11, &a[k + 1 + k * a_dim1], &c__1);
1389                     } else {
1390
1391 /*                    Store L(k) in column k */
1392
1393                         i__1 = k + k * a_dim1;
1394                         d11.r = a[i__1].r, d11.i = a[i__1].i;
1395                         i__1 = *n;
1396                         for (ii = k + 1; ii <= i__1; ++ii) {
1397                             i__2 = ii + k * a_dim1;
1398                             z_div(&z__1, &a[ii + k * a_dim1], &d11);
1399                             a[i__2].r = z__1.r, a[i__2].i = z__1.i;
1400 /* L46: */
1401                         }
1402
1403 /*                    Perform a rank-1 update of A(k+1:n,k+1:n) as */
1404 /*                    A := A - L(k)*D(k)*L(k)**T */
1405 /*                       = A - W(k)*(1/D(k))*W(k)**T */
1406 /*                       = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T */
1407
1408                         i__1 = *n - k;
1409                         z__1.r = -d11.r, z__1.i = -d11.i;
1410                         zsyr_(uplo, &i__1, &z__1, &a[k + 1 + k * a_dim1], &
1411                                 c__1, &a[k + 1 + (k + 1) * a_dim1], lda);
1412                     }
1413                 }
1414
1415             } else {
1416
1417 /*              2-by-2 pivot block D(k): columns k and k+1 now hold */
1418
1419 /*              ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */
1420
1421 /*              where L(k) and L(k+1) are the k-th and (k+1)-th columns */
1422 /*              of L */
1423
1424
1425 /*              Perform a rank-2 update of A(k+2:n,k+2:n) as */
1426
1427 /*              A := A - ( L(k) L(k+1) ) * D(k) * ( L(k) L(k+1) )**T */
1428 /*                 = A - ( ( A(k)A(k+1) )*inv(D(k) ) * ( A(k)A(k+1) )**T */
1429
1430 /*              and store L(k) and L(k+1) in columns k and k+1 */
1431
1432                 if (k < *n - 1) {
1433
1434                     i__1 = k + 1 + k * a_dim1;
1435                     d21.r = a[i__1].r, d21.i = a[i__1].i;
1436                     z_div(&z__1, &a[k + 1 + (k + 1) * a_dim1], &d21);
1437                     d11.r = z__1.r, d11.i = z__1.i;
1438                     z_div(&z__1, &a[k + k * a_dim1], &d21);
1439                     d22.r = z__1.r, d22.i = z__1.i;
1440                     z__3.r = d11.r * d22.r - d11.i * d22.i, z__3.i = d11.r * 
1441                             d22.i + d11.i * d22.r;
1442                     z__2.r = z__3.r - 1., z__2.i = z__3.i + 0.;
1443                     z_div(&z__1, &c_b1, &z__2);
1444                     t.r = z__1.r, t.i = z__1.i;
1445
1446                     i__1 = *n;
1447                     for (j = k + 2; j <= i__1; ++j) {
1448
1449 /*                    Compute  D21 * ( W(k)W(k+1) ) * inv(D(k)) for row J */
1450
1451                         i__2 = j + k * a_dim1;
1452                         z__3.r = d11.r * a[i__2].r - d11.i * a[i__2].i, 
1453                                 z__3.i = d11.r * a[i__2].i + d11.i * a[i__2]
1454                                 .r;
1455                         i__3 = j + (k + 1) * a_dim1;
1456                         z__2.r = z__3.r - a[i__3].r, z__2.i = z__3.i - a[i__3]
1457                                 .i;
1458                         z__1.r = t.r * z__2.r - t.i * z__2.i, z__1.i = t.r * 
1459                                 z__2.i + t.i * z__2.r;
1460                         wk.r = z__1.r, wk.i = z__1.i;
1461                         i__2 = j + (k + 1) * a_dim1;
1462                         z__3.r = d22.r * a[i__2].r - d22.i * a[i__2].i, 
1463                                 z__3.i = d22.r * a[i__2].i + d22.i * a[i__2]
1464                                 .r;
1465                         i__3 = j + k * a_dim1;
1466                         z__2.r = z__3.r - a[i__3].r, z__2.i = z__3.i - a[i__3]
1467                                 .i;
1468                         z__1.r = t.r * z__2.r - t.i * z__2.i, z__1.i = t.r * 
1469                                 z__2.i + t.i * z__2.r;
1470                         wkp1.r = z__1.r, wkp1.i = z__1.i;
1471
1472 /*                    Perform a rank-2 update of A(k+2:n,k+2:n) */
1473
1474                         i__2 = *n;
1475                         for (i__ = j; i__ <= i__2; ++i__) {
1476                             i__3 = i__ + j * a_dim1;
1477                             i__4 = i__ + j * a_dim1;
1478                             z_div(&z__4, &a[i__ + k * a_dim1], &d21);
1479                             z__3.r = z__4.r * wk.r - z__4.i * wk.i, z__3.i = 
1480                                     z__4.r * wk.i + z__4.i * wk.r;
1481                             z__2.r = a[i__4].r - z__3.r, z__2.i = a[i__4].i - 
1482                                     z__3.i;
1483                             z_div(&z__6, &a[i__ + (k + 1) * a_dim1], &d21);
1484                             z__5.r = z__6.r * wkp1.r - z__6.i * wkp1.i, 
1485                                     z__5.i = z__6.r * wkp1.i + z__6.i * 
1486                                     wkp1.r;
1487                             z__1.r = z__2.r - z__5.r, z__1.i = z__2.i - 
1488                                     z__5.i;
1489                             a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1490 /* L50: */
1491                         }
1492
1493 /*                    Store L(k) and L(k+1) in cols k and k+1 for row J */
1494
1495                         i__2 = j + k * a_dim1;
1496                         z_div(&z__1, &wk, &d21);
1497                         a[i__2].r = z__1.r, a[i__2].i = z__1.i;
1498                         i__2 = j + (k + 1) * a_dim1;
1499                         z_div(&z__1, &wkp1, &d21);
1500                         a[i__2].r = z__1.r, a[i__2].i = z__1.i;
1501
1502 /* L60: */
1503                     }
1504
1505                 }
1506
1507             }
1508         }
1509
1510 /*        Store details of the interchanges in IPIV */
1511
1512         if (kstep == 1) {
1513             ipiv[k] = kp;
1514         } else {
1515             ipiv[k] = -p;
1516             ipiv[k + 1] = -kp;
1517         }
1518
1519 /*        Increase K and return to the start of the main loop */
1520
1521         k += kstep;
1522         goto L40;
1523
1524     }
1525
1526 L70:
1527
1528     return 0;
1529
1530 /*     End of ZSYTF2_ROOK */
1531
1532 } /* zsytf2_rook__ */
1533