C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / clahef_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]/df(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 complex c_b1 = {1.f,0.f};
516 static integer c__1 = 1;
517
518 /* \brief \b CLAHEF_ROOK computes a partial factorization of a complex Hermitian indefinite matrix using the b
519 ounded Bunch-Kaufman ("rook") diagonal pivoting method (blocked algorithm, calling Level 3 BLAS). */
520
521 /*  =========== DOCUMENTATION =========== */
522
523 /* Online html documentation available at */
524 /*            http://www.netlib.org/lapack/explore-html/ */
525
526 /* > \htmlonly */
527 /* > Download CLAHEF_ROOK + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clahef_
529 rook.f"> */
530 /* > [TGZ]</a> */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clahef_
532 rook.f"> */
533 /* > [ZIP]</a> */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clahef_
535 rook.f"> */
536 /* > [TXT]</a> */
537 /* > \endhtmlonly */
538
539 /*  Definition: */
540 /*  =========== */
541
542 /*       SUBROUTINE CLAHEF_ROOK( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW, INFO ) */
543
544 /*       CHARACTER          UPLO */
545 /*       INTEGER            INFO, KB, LDA, LDW, N, NB */
546 /*       INTEGER            IPIV( * ) */
547 /*       COMPLEX            A( LDA, * ), W( LDW, * ) */
548
549
550 /* > \par Purpose: */
551 /*  ============= */
552 /* > */
553 /* > \verbatim */
554 /* > */
555 /* > CLAHEF_ROOK computes a partial factorization of a complex Hermitian */
556 /* > matrix A using the bounded Bunch-Kaufman ("rook") diagonal pivoting */
557 /* > method. The partial factorization has the form: */
558 /* > */
559 /* > A  =  ( I  U12 ) ( A11  0  ) (  I      0     )  if UPLO = 'U', or: */
560 /* >       ( 0  U22 ) (  0   D  ) ( U12**H U22**H ) */
561 /* > */
562 /* > A  =  ( L11  0 ) (  D   0  ) ( L11**H L21**H )  if UPLO = 'L' */
563 /* >       ( L21  I ) (  0  A22 ) (  0      I     ) */
564 /* > */
565 /* > where the order of D is at most NB. The actual order is returned in */
566 /* > the argument KB, and is either NB or NB-1, or N if N <= NB. */
567 /* > Note that U**H denotes the conjugate transpose of U. */
568 /* > */
569 /* > CLAHEF_ROOK is an auxiliary routine called by CHETRF_ROOK. It uses */
570 /* > blocked code (calling Level 3 BLAS) to update the submatrix */
571 /* > A11 (if UPLO = 'U') or A22 (if UPLO = 'L'). */
572 /* > \endverbatim */
573
574 /*  Arguments: */
575 /*  ========== */
576
577 /* > \param[in] UPLO */
578 /* > \verbatim */
579 /* >          UPLO is CHARACTER*1 */
580 /* >          Specifies whether the upper or lower triangular part of the */
581 /* >          Hermitian matrix A is stored: */
582 /* >          = 'U':  Upper triangular */
583 /* >          = 'L':  Lower triangular */
584 /* > \endverbatim */
585 /* > */
586 /* > \param[in] N */
587 /* > \verbatim */
588 /* >          N is INTEGER */
589 /* >          The order of the matrix A.  N >= 0. */
590 /* > \endverbatim */
591 /* > */
592 /* > \param[in] NB */
593 /* > \verbatim */
594 /* >          NB is INTEGER */
595 /* >          The maximum number of columns of the matrix A that should be */
596 /* >          factored.  NB should be at least 2 to allow for 2-by-2 pivot */
597 /* >          blocks. */
598 /* > \endverbatim */
599 /* > */
600 /* > \param[out] KB */
601 /* > \verbatim */
602 /* >          KB is INTEGER */
603 /* >          The number of columns of A that were actually factored. */
604 /* >          KB is either NB-1 or NB, or N if N <= NB. */
605 /* > \endverbatim */
606 /* > */
607 /* > \param[in,out] A */
608 /* > \verbatim */
609 /* >          A is COMPLEX array, dimension (LDA,N) */
610 /* >          On entry, the Hermitian matrix A.  If UPLO = 'U', the leading */
611 /* >          n-by-n upper triangular part of A contains the upper */
612 /* >          triangular part of the matrix A, and the strictly lower */
613 /* >          triangular part of A is not referenced.  If UPLO = 'L', the */
614 /* >          leading n-by-n lower triangular part of A contains the lower */
615 /* >          triangular part of the matrix A, and the strictly upper */
616 /* >          triangular part of A is not referenced. */
617 /* >          On exit, A contains details of the partial factorization. */
618 /* > \endverbatim */
619 /* > */
620 /* > \param[in] LDA */
621 /* > \verbatim */
622 /* >          LDA is INTEGER */
623 /* >          The leading dimension of the array A.  LDA >= f2cmax(1,N). */
624 /* > \endverbatim */
625 /* > */
626 /* > \param[out] IPIV */
627 /* > \verbatim */
628 /* >          IPIV is INTEGER array, dimension (N) */
629 /* >          Details of the interchanges and the block structure of D. */
630 /* > */
631 /* >          If UPLO = 'U': */
632 /* >             Only the last KB elements of IPIV are set. */
633 /* > */
634 /* >             If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
635 /* >             interchanged and D(k,k) is a 1-by-1 diagonal block. */
636 /* > */
637 /* >             If IPIV(k) < 0 and IPIV(k-1) < 0, then rows and */
638 /* >             columns k and -IPIV(k) were interchanged and rows and */
639 /* >             columns k-1 and -IPIV(k-1) were inerchaged, */
640 /* >             D(k-1:k,k-1:k) is a 2-by-2 diagonal block. */
641 /* > */
642 /* >          If UPLO = 'L': */
643 /* >             Only the first KB elements of IPIV are set. */
644 /* > */
645 /* >             If IPIV(k) > 0, then rows and columns k and IPIV(k) */
646 /* >             were interchanged and D(k,k) is a 1-by-1 diagonal block. */
647 /* > */
648 /* >             If IPIV(k) < 0 and IPIV(k+1) < 0, then rows and */
649 /* >             columns k and -IPIV(k) were interchanged and rows and */
650 /* >             columns k+1 and -IPIV(k+1) were inerchaged, */
651 /* >             D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */
652 /* > \endverbatim */
653 /* > */
654 /* > \param[out] W */
655 /* > \verbatim */
656 /* >          W is COMPLEX array, dimension (LDW,NB) */
657 /* > \endverbatim */
658 /* > */
659 /* > \param[in] LDW */
660 /* > \verbatim */
661 /* >          LDW is INTEGER */
662 /* >          The leading dimension of the array W.  LDW >= f2cmax(1,N). */
663 /* > \endverbatim */
664 /* > */
665 /* > \param[out] INFO */
666 /* > \verbatim */
667 /* >          INFO is INTEGER */
668 /* >          = 0: successful exit */
669 /* >          > 0: if INFO = k, D(k,k) is exactly zero.  The factorization */
670 /* >               has been completed, but the block diagonal matrix D is */
671 /* >               exactly singular. */
672 /* > \endverbatim */
673
674 /*  Authors: */
675 /*  ======== */
676
677 /* > \author Univ. of Tennessee */
678 /* > \author Univ. of California Berkeley */
679 /* > \author Univ. of Colorado Denver */
680 /* > \author NAG Ltd. */
681
682 /* > \date November 2013 */
683
684 /* > \ingroup complexHEcomputational */
685
686 /* > \par Contributors: */
687 /*  ================== */
688 /* > */
689 /* > \verbatim */
690 /* > */
691 /* >  November 2013, Igor Kozachenko, */
692 /* >                  Computer Science Division, */
693 /* >                  University of California, Berkeley */
694 /* > */
695 /* >  September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas, */
696 /* >                  School of Mathematics, */
697 /* >                  University of Manchester */
698 /* > \endverbatim */
699
700 /*  ===================================================================== */
701 /* Subroutine */ int clahef_rook_(char *uplo, integer *n, integer *nb, 
702         integer *kb, complex *a, integer *lda, integer *ipiv, complex *w, 
703         integer *ldw, integer *info)
704 {
705     /* System generated locals */
706     integer a_dim1, a_offset, w_dim1, w_offset, i__1, i__2, i__3, i__4, i__5;
707     real r__1, r__2;
708     complex q__1, q__2, q__3, q__4, q__5;
709
710     /* Local variables */
711     logical done;
712     integer imax, jmax, j, k, p;
713     real t, alpha;
714     extern /* Subroutine */ int cgemm_(char *, char *, integer *, integer *, 
715             integer *, complex *, complex *, integer *, complex *, integer *, 
716             complex *, complex *, integer *);
717     extern logical lsame_(char *, char *);
718     extern /* Subroutine */ int cgemv_(char *, integer *, integer *, complex *
719             , complex *, integer *, complex *, integer *, complex *, complex *
720             , integer *);
721     real sfmin;
722     extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, 
723             complex *, integer *);
724     integer itemp;
725     extern /* Subroutine */ int cswap_(integer *, complex *, integer *, 
726             complex *, integer *);
727     integer kstep;
728     real stemp, r1;
729     complex d11, d21, d22;
730     integer jb, ii, jj, kk, kp;
731     real absakk;
732     extern /* Subroutine */ int clacgv_(integer *, complex *, integer *);
733     integer kw;
734     extern integer icamax_(integer *, complex *, integer *);
735     extern real slamch_(char *);
736     extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer 
737             *);
738     real colmax;
739     integer jp1, jp2;
740     real rowmax;
741     integer kkw;
742
743
744 /*  -- LAPACK computational routine (version 3.5.0) -- */
745 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
746 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
747 /*     November 2013 */
748
749
750 /*  ===================================================================== */
751
752
753     /* Parameter adjustments */
754     a_dim1 = *lda;
755     a_offset = 1 + a_dim1 * 1;
756     a -= a_offset;
757     --ipiv;
758     w_dim1 = *ldw;
759     w_offset = 1 + w_dim1 * 1;
760     w -= w_offset;
761
762     /* Function Body */
763     *info = 0;
764
765 /*     Initialize ALPHA for use in choosing pivot block size. */
766
767     alpha = (sqrt(17.f) + 1.f) / 8.f;
768
769 /*     Compute machine safe minimum */
770
771     sfmin = slamch_("S");
772
773     if (lsame_(uplo, "U")) {
774
775 /*        Factorize the trailing columns of A using the upper triangle */
776 /*        of A and working backwards, and compute the matrix W = U12*D */
777 /*        for use in updating A11 (note that conjg(W) is actually stored) */
778
779 /*        K is the main loop index, decreasing from N in steps of 1 or 2 */
780
781         k = *n;
782 L10:
783
784 /*        KW is the column of W which corresponds to column K of A */
785
786         kw = *nb + k - *n;
787
788 /*        Exit from loop */
789
790         if (k <= *n - *nb + 1 && *nb < *n || k < 1) {
791             goto L30;
792         }
793
794         kstep = 1;
795         p = k;
796
797 /*        Copy column K of A to column KW of W and update it */
798
799         if (k > 1) {
800             i__1 = k - 1;
801             ccopy_(&i__1, &a[k * a_dim1 + 1], &c__1, &w[kw * w_dim1 + 1], &
802                     c__1);
803         }
804         i__1 = k + kw * w_dim1;
805         i__2 = k + k * a_dim1;
806         r__1 = a[i__2].r;
807         w[i__1].r = r__1, w[i__1].i = 0.f;
808         if (k < *n) {
809             i__1 = *n - k;
810             q__1.r = -1.f, q__1.i = 0.f;
811             cgemv_("No transpose", &k, &i__1, &q__1, &a[(k + 1) * a_dim1 + 1],
812                      lda, &w[k + (kw + 1) * w_dim1], ldw, &c_b1, &w[kw * 
813                     w_dim1 + 1], &c__1);
814             i__1 = k + kw * w_dim1;
815             i__2 = k + kw * w_dim1;
816             r__1 = w[i__2].r;
817             w[i__1].r = r__1, w[i__1].i = 0.f;
818         }
819
820 /*        Determine rows and columns to be interchanged and whether */
821 /*        a 1-by-1 or 2-by-2 pivot block will be used */
822
823         i__1 = k + kw * w_dim1;
824         absakk = (r__1 = w[i__1].r, abs(r__1));
825
826 /*        IMAX is the row-index of the largest off-diagonal element in */
827 /*        column K, and COLMAX is its absolute value. */
828 /*        Determine both COLMAX and IMAX. */
829
830         if (k > 1) {
831             i__1 = k - 1;
832             imax = icamax_(&i__1, &w[kw * w_dim1 + 1], &c__1);
833             i__1 = imax + kw * w_dim1;
834             colmax = (r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&w[imax + 
835                     kw * w_dim1]), abs(r__2));
836         } else {
837             colmax = 0.f;
838         }
839
840         if (f2cmax(absakk,colmax) == 0.f) {
841
842 /*           Column K is zero or underflow: set INFO and continue */
843
844             if (*info == 0) {
845                 *info = k;
846             }
847             kp = k;
848             i__1 = k + k * a_dim1;
849             i__2 = k + kw * w_dim1;
850             r__1 = w[i__2].r;
851             a[i__1].r = r__1, a[i__1].i = 0.f;
852             if (k > 1) {
853                 i__1 = k - 1;
854                 ccopy_(&i__1, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1], 
855                         &c__1);
856             }
857         } else {
858
859 /*           ============================================================ */
860
861 /*           BEGIN pivot search */
862
863 /*           Case(1) */
864 /*           Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX */
865 /*           (used to handle NaN and Inf) */
866             if (! (absakk < alpha * colmax)) {
867
868 /*              no interchange, use 1-by-1 pivot block */
869
870                 kp = k;
871
872             } else {
873
874 /*              Lop until pivot found */
875
876                 done = FALSE_;
877
878 L12:
879
880 /*                 BEGIN pivot search loop body */
881
882
883 /*                 Copy column IMAX to column KW-1 of W and update it */
884
885                 if (imax > 1) {
886                     i__1 = imax - 1;
887                     ccopy_(&i__1, &a[imax * a_dim1 + 1], &c__1, &w[(kw - 1) * 
888                             w_dim1 + 1], &c__1);
889                 }
890                 i__1 = imax + (kw - 1) * w_dim1;
891                 i__2 = imax + imax * a_dim1;
892                 r__1 = a[i__2].r;
893                 w[i__1].r = r__1, w[i__1].i = 0.f;
894
895                 i__1 = k - imax;
896                 ccopy_(&i__1, &a[imax + (imax + 1) * a_dim1], lda, &w[imax + 
897                         1 + (kw - 1) * w_dim1], &c__1);
898                 i__1 = k - imax;
899                 clacgv_(&i__1, &w[imax + 1 + (kw - 1) * w_dim1], &c__1);
900
901                 if (k < *n) {
902                     i__1 = *n - k;
903                     q__1.r = -1.f, q__1.i = 0.f;
904                     cgemv_("No transpose", &k, &i__1, &q__1, &a[(k + 1) * 
905                             a_dim1 + 1], lda, &w[imax + (kw + 1) * w_dim1], 
906                             ldw, &c_b1, &w[(kw - 1) * w_dim1 + 1], &c__1);
907                     i__1 = imax + (kw - 1) * w_dim1;
908                     i__2 = imax + (kw - 1) * w_dim1;
909                     r__1 = w[i__2].r;
910                     w[i__1].r = r__1, w[i__1].i = 0.f;
911                 }
912
913 /*                 JMAX is the column-index of the largest off-diagonal */
914 /*                 element in row IMAX, and ROWMAX is its absolute value. */
915 /*                 Determine both ROWMAX and JMAX. */
916
917                 if (imax != k) {
918                     i__1 = k - imax;
919                     jmax = imax + icamax_(&i__1, &w[imax + 1 + (kw - 1) * 
920                             w_dim1], &c__1);
921                     i__1 = jmax + (kw - 1) * w_dim1;
922                     rowmax = (r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&
923                             w[jmax + (kw - 1) * w_dim1]), abs(r__2));
924                 } else {
925                     rowmax = 0.f;
926                 }
927
928                 if (imax > 1) {
929                     i__1 = imax - 1;
930                     itemp = icamax_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1);
931                     i__1 = itemp + (kw - 1) * w_dim1;
932                     stemp = (r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&w[
933                             itemp + (kw - 1) * w_dim1]), abs(r__2));
934                     if (stemp > rowmax) {
935                         rowmax = stemp;
936                         jmax = itemp;
937                     }
938                 }
939
940 /*                 Case(2) */
941 /*                 Equivalent to testing for */
942 /*                 ABS( REAL( W( IMAX,KW-1 ) ) ).GE.ALPHA*ROWMAX */
943 /*                 (used to handle NaN and Inf) */
944
945                 i__1 = imax + (kw - 1) * w_dim1;
946                 if (! ((r__1 = w[i__1].r, abs(r__1)) < alpha * rowmax)) {
947
948 /*                    interchange rows and columns K and IMAX, */
949 /*                    use 1-by-1 pivot block */
950
951                     kp = imax;
952
953 /*                    copy column KW-1 of W to column KW of W */
954
955                     ccopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw * 
956                             w_dim1 + 1], &c__1);
957
958                     done = TRUE_;
959
960 /*                 Case(3) */
961 /*                 Equivalent to testing for ROWMAX.EQ.COLMAX, */
962 /*                 (used to handle NaN and Inf) */
963
964                 } else if (p == jmax || rowmax <= colmax) {
965
966 /*                    interchange rows and columns K-1 and IMAX, */
967 /*                    use 2-by-2 pivot block */
968
969                     kp = imax;
970                     kstep = 2;
971                     done = TRUE_;
972
973 /*                 Case(4) */
974                 } else {
975
976 /*                    Pivot not found: set params and repeat */
977
978                     p = imax;
979                     colmax = rowmax;
980                     imax = jmax;
981
982 /*                    Copy updated JMAXth (next IMAXth) column to Kth of W */
983
984                     ccopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw * 
985                             w_dim1 + 1], &c__1);
986
987                 }
988
989
990 /*                 END pivot search loop body */
991
992                 if (! done) {
993                     goto L12;
994                 }
995
996             }
997
998 /*           END pivot search */
999
1000 /*           ============================================================ */
1001
1002 /*           KK is the column of A where pivoting step stopped */
1003
1004             kk = k - kstep + 1;
1005
1006 /*           KKW is the column of W which corresponds to column KK of A */
1007
1008             kkw = *nb + kk - *n;
1009
1010 /*           Interchange rows and columns P and K. */
1011 /*           Updated column P is already stored in column KW of W. */
1012
1013             if (kstep == 2 && p != k) {
1014
1015 /*              Copy non-updated column K to column P of submatrix A */
1016 /*              at step K. No need to copy element into columns */
1017 /*              K and K-1 of A for 2-by-2 pivot, since these columns */
1018 /*              will be later overwritten. */
1019
1020                 i__1 = p + p * a_dim1;
1021                 i__2 = k + k * a_dim1;
1022                 r__1 = a[i__2].r;
1023                 a[i__1].r = r__1, a[i__1].i = 0.f;
1024                 i__1 = k - 1 - p;
1025                 ccopy_(&i__1, &a[p + 1 + k * a_dim1], &c__1, &a[p + (p + 1) * 
1026                         a_dim1], lda);
1027                 i__1 = k - 1 - p;
1028                 clacgv_(&i__1, &a[p + (p + 1) * a_dim1], lda);
1029                 if (p > 1) {
1030                     i__1 = p - 1;
1031                     ccopy_(&i__1, &a[k * a_dim1 + 1], &c__1, &a[p * a_dim1 + 
1032                             1], &c__1);
1033                 }
1034
1035 /*              Interchange rows K and P in the last K+1 to N columns of A */
1036 /*              (columns K and K-1 of A for 2-by-2 pivot will be */
1037 /*              later overwritten). Interchange rows K and P */
1038 /*              in last KKW to NB columns of W. */
1039
1040                 if (k < *n) {
1041                     i__1 = *n - k;
1042                     cswap_(&i__1, &a[k + (k + 1) * a_dim1], lda, &a[p + (k + 
1043                             1) * a_dim1], lda);
1044                 }
1045                 i__1 = *n - kk + 1;
1046                 cswap_(&i__1, &w[k + kkw * w_dim1], ldw, &w[p + kkw * w_dim1],
1047                          ldw);
1048             }
1049
1050 /*           Interchange rows and columns KP and KK. */
1051 /*           Updated column KP is already stored in column KKW of W. */
1052
1053             if (kp != kk) {
1054
1055 /*              Copy non-updated column KK to column KP of submatrix A */
1056 /*              at step K. No need to copy element into column K */
1057 /*              (or K and K-1 for 2-by-2 pivot) of A, since these columns */
1058 /*              will be later overwritten. */
1059
1060                 i__1 = kp + kp * a_dim1;
1061                 i__2 = kk + kk * a_dim1;
1062                 r__1 = a[i__2].r;
1063                 a[i__1].r = r__1, a[i__1].i = 0.f;
1064                 i__1 = kk - 1 - kp;
1065                 ccopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + (kp + 
1066                         1) * a_dim1], lda);
1067                 i__1 = kk - 1 - kp;
1068                 clacgv_(&i__1, &a[kp + (kp + 1) * a_dim1], lda);
1069                 if (kp > 1) {
1070                     i__1 = kp - 1;
1071                     ccopy_(&i__1, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1 
1072                             + 1], &c__1);
1073                 }
1074
1075 /*              Interchange rows KK and KP in last K+1 to N columns of A */
1076 /*              (columns K (or K and K-1 for 2-by-2 pivot) of A will be */
1077 /*              later overwritten). Interchange rows KK and KP */
1078 /*              in last KKW to NB columns of W. */
1079
1080                 if (k < *n) {
1081                     i__1 = *n - k;
1082                     cswap_(&i__1, &a[kk + (k + 1) * a_dim1], lda, &a[kp + (k 
1083                             + 1) * a_dim1], lda);
1084                 }
1085                 i__1 = *n - kk + 1;
1086                 cswap_(&i__1, &w[kk + kkw * w_dim1], ldw, &w[kp + kkw * 
1087                         w_dim1], ldw);
1088             }
1089
1090             if (kstep == 1) {
1091
1092 /*              1-by-1 pivot block D(k): column kw of W now holds */
1093
1094 /*              W(kw) = U(k)*D(k), */
1095
1096 /*              where U(k) is the k-th column of U */
1097
1098 /*              (1) Store subdiag. elements of column U(k) */
1099 /*              and 1-by-1 block D(k) in column k of A. */
1100 /*              (NOTE: Diagonal element U(k,k) is a UNIT element */
1101 /*              and not stored) */
1102 /*                 A(k,k) := D(k,k) = W(k,kw) */
1103 /*                 A(1:k-1,k) := U(1:k-1,k) = W(1:k-1,kw)/D(k,k) */
1104
1105 /*              (NOTE: No need to use for Hermitian matrix */
1106 /*              A( K, K ) = REAL( W( K, K) ) to separately copy diagonal */
1107 /*              element D(k,k) from W (potentially saves only one load)) */
1108                 ccopy_(&k, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1], &
1109                         c__1);
1110                 if (k > 1) {
1111
1112 /*                 (NOTE: No need to check if A(k,k) is NOT ZERO, */
1113 /*                  since that was ensured earlier in pivot search: */
1114 /*                  case A(k,k) = 0 falls into 2x2 pivot case(3)) */
1115
1116 /*                 Handle division by a small number */
1117
1118                     i__1 = k + k * a_dim1;
1119                     t = a[i__1].r;
1120                     if (abs(t) >= sfmin) {
1121                         r1 = 1.f / t;
1122                         i__1 = k - 1;
1123                         csscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1);
1124                     } else {
1125                         i__1 = k - 1;
1126                         for (ii = 1; ii <= i__1; ++ii) {
1127                             i__2 = ii + k * a_dim1;
1128                             i__3 = ii + k * a_dim1;
1129                             q__1.r = a[i__3].r / t, q__1.i = a[i__3].i / t;
1130                             a[i__2].r = q__1.r, a[i__2].i = q__1.i;
1131 /* L14: */
1132                         }
1133                     }
1134
1135 /*                 (2) Conjugate column W(kw) */
1136
1137                     i__1 = k - 1;
1138                     clacgv_(&i__1, &w[kw * w_dim1 + 1], &c__1);
1139                 }
1140
1141             } else {
1142
1143 /*              2-by-2 pivot block D(k): columns kw and kw-1 of W now hold */
1144
1145 /*              ( W(kw-1) W(kw) ) = ( U(k-1) U(k) )*D(k) */
1146
1147 /*              where U(k) and U(k-1) are the k-th and (k-1)-th columns */
1148 /*              of U */
1149
1150 /*              (1) Store U(1:k-2,k-1) and U(1:k-2,k) and 2-by-2 */
1151 /*              block D(k-1:k,k-1:k) in columns k-1 and k of A. */
1152 /*              (NOTE: 2-by-2 diagonal block U(k-1:k,k-1:k) is a UNIT */
1153 /*              block and not stored) */
1154 /*                 A(k-1:k,k-1:k) := D(k-1:k,k-1:k) = W(k-1:k,kw-1:kw) */
1155 /*                 A(1:k-2,k-1:k) := U(1:k-2,k:k-1:k) = */
1156 /*                 = W(1:k-2,kw-1:kw) * ( D(k-1:k,k-1:k)**(-1) ) */
1157
1158                 if (k > 2) {
1159
1160 /*                 Factor out the columns of the inverse of 2-by-2 pivot */
1161 /*                 block D, so that each column contains 1, to reduce the */
1162 /*                 number of FLOPS when we multiply panel */
1163 /*                 ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1). */
1164
1165 /*                 D**(-1) = ( d11 cj(d21) )**(-1) = */
1166 /*                           ( d21    d22 ) */
1167
1168 /*                 = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) = */
1169 /*                                          ( (-d21) (     d11 ) ) */
1170
1171 /*                 = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) * */
1172
1173 /*                   * ( d21*( d22/d21 ) conj(d21)*(           - 1 ) ) = */
1174 /*                     (     (      -1 )           ( d11/conj(d21) ) ) */
1175
1176 /*                 = 1/(|d21|**2) * 1/(D22*D11-1) * */
1177
1178 /*                   * ( d21*( D11 ) conj(d21)*(  -1 ) ) = */
1179 /*                     (     (  -1 )           ( D22 ) ) */
1180
1181 /*                 = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*(  -1 ) ) = */
1182 /*                                      (     (  -1 )           ( D22 ) ) */
1183
1184 /*                 = ( (T/conj(d21))*( D11 ) (T/d21)*(  -1 ) ) = */
1185 /*                   (               (  -1 )         ( D22 ) ) */
1186
1187 /*                 Handle division by a small number. (NOTE: order of */
1188 /*                 operations is important) */
1189
1190 /*                 = ( T*(( D11 )/conj(D21)) T*((  -1 )/D21 ) ) */
1191 /*                   (   ((  -1 )          )   (( D22 )     ) ), */
1192
1193 /*                 where D11 = d22/d21, */
1194 /*                       D22 = d11/conj(d21), */
1195 /*                       D21 = d21, */
1196 /*                       T = 1/(D22*D11-1). */
1197
1198 /*                 (NOTE: No need to check for division by ZERO, */
1199 /*                  since that was ensured earlier in pivot search: */
1200 /*                  (a) d21 != 0 in 2x2 pivot case(4), */
1201 /*                      since |d21| should be larger than |d11| and |d22|; */
1202 /*                  (b) (D22*D11 - 1) != 0, since from (a), */
1203 /*                      both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.) */
1204
1205                     i__1 = k - 1 + kw * w_dim1;
1206                     d21.r = w[i__1].r, d21.i = w[i__1].i;
1207                     r_cnjg(&q__2, &d21);
1208                     c_div(&q__1, &w[k + kw * w_dim1], &q__2);
1209                     d11.r = q__1.r, d11.i = q__1.i;
1210                     c_div(&q__1, &w[k - 1 + (kw - 1) * w_dim1], &d21);
1211                     d22.r = q__1.r, d22.i = q__1.i;
1212                     q__1.r = d11.r * d22.r - d11.i * d22.i, q__1.i = d11.r * 
1213                             d22.i + d11.i * d22.r;
1214                     t = 1.f / (q__1.r - 1.f);
1215
1216 /*                 Update elements in columns A(k-1) and A(k) as */
1217 /*                 dot products of rows of ( W(kw-1) W(kw) ) and columns */
1218 /*                 of D**(-1) */
1219
1220                     i__1 = k - 2;
1221                     for (j = 1; j <= i__1; ++j) {
1222                         i__2 = j + (k - 1) * a_dim1;
1223                         i__3 = j + (kw - 1) * w_dim1;
1224                         q__4.r = d11.r * w[i__3].r - d11.i * w[i__3].i, 
1225                                 q__4.i = d11.r * w[i__3].i + d11.i * w[i__3]
1226                                 .r;
1227                         i__4 = j + kw * w_dim1;
1228                         q__3.r = q__4.r - w[i__4].r, q__3.i = q__4.i - w[i__4]
1229                                 .i;
1230                         c_div(&q__2, &q__3, &d21);
1231                         q__1.r = t * q__2.r, q__1.i = t * q__2.i;
1232                         a[i__2].r = q__1.r, a[i__2].i = q__1.i;
1233                         i__2 = j + k * a_dim1;
1234                         i__3 = j + kw * w_dim1;
1235                         q__4.r = d22.r * w[i__3].r - d22.i * w[i__3].i, 
1236                                 q__4.i = d22.r * w[i__3].i + d22.i * w[i__3]
1237                                 .r;
1238                         i__4 = j + (kw - 1) * w_dim1;
1239                         q__3.r = q__4.r - w[i__4].r, q__3.i = q__4.i - w[i__4]
1240                                 .i;
1241                         r_cnjg(&q__5, &d21);
1242                         c_div(&q__2, &q__3, &q__5);
1243                         q__1.r = t * q__2.r, q__1.i = t * q__2.i;
1244                         a[i__2].r = q__1.r, a[i__2].i = q__1.i;
1245 /* L20: */
1246                     }
1247                 }
1248
1249 /*              Copy D(k) to A */
1250
1251                 i__1 = k - 1 + (k - 1) * a_dim1;
1252                 i__2 = k - 1 + (kw - 1) * w_dim1;
1253                 a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
1254                 i__1 = k - 1 + k * a_dim1;
1255                 i__2 = k - 1 + kw * w_dim1;
1256                 a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
1257                 i__1 = k + k * a_dim1;
1258                 i__2 = k + kw * w_dim1;
1259                 a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
1260
1261 /*              (2) Conjugate columns W(kw) and W(kw-1) */
1262
1263                 i__1 = k - 1;
1264                 clacgv_(&i__1, &w[kw * w_dim1 + 1], &c__1);
1265                 i__1 = k - 2;
1266                 clacgv_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1);
1267
1268             }
1269
1270         }
1271
1272 /*        Store details of the interchanges in IPIV */
1273
1274         if (kstep == 1) {
1275             ipiv[k] = kp;
1276         } else {
1277             ipiv[k] = -p;
1278             ipiv[k - 1] = -kp;
1279         }
1280
1281 /*        Decrease K and return to the start of the main loop */
1282
1283         k -= kstep;
1284         goto L10;
1285
1286 L30:
1287
1288 /*        Update the upper triangle of A11 (= A(1:k,1:k)) as */
1289
1290 /*        A11 := A11 - U12*D*U12**H = A11 - U12*W**H */
1291
1292 /*        computing blocks of NB columns at a time (note that conjg(W) is */
1293 /*        actually stored) */
1294
1295         i__1 = -(*nb);
1296         for (j = (k - 1) / *nb * *nb + 1; i__1 < 0 ? j >= 1 : j <= 1; j += 
1297                 i__1) {
1298 /* Computing MIN */
1299             i__2 = *nb, i__3 = k - j + 1;
1300             jb = f2cmin(i__2,i__3);
1301
1302 /*           Update the upper triangle of the diagonal block */
1303
1304             i__2 = j + jb - 1;
1305             for (jj = j; jj <= i__2; ++jj) {
1306                 i__3 = jj + jj * a_dim1;
1307                 i__4 = jj + jj * a_dim1;
1308                 r__1 = a[i__4].r;
1309                 a[i__3].r = r__1, a[i__3].i = 0.f;
1310                 i__3 = jj - j + 1;
1311                 i__4 = *n - k;
1312                 q__1.r = -1.f, q__1.i = 0.f;
1313                 cgemv_("No transpose", &i__3, &i__4, &q__1, &a[j + (k + 1) * 
1314                         a_dim1], lda, &w[jj + (kw + 1) * w_dim1], ldw, &c_b1, 
1315                         &a[j + jj * a_dim1], &c__1);
1316                 i__3 = jj + jj * a_dim1;
1317                 i__4 = jj + jj * a_dim1;
1318                 r__1 = a[i__4].r;
1319                 a[i__3].r = r__1, a[i__3].i = 0.f;
1320 /* L40: */
1321             }
1322
1323 /*           Update the rectangular superdiagonal block */
1324
1325             if (j >= 2) {
1326                 i__2 = j - 1;
1327                 i__3 = *n - k;
1328                 q__1.r = -1.f, q__1.i = 0.f;
1329                 cgemm_("No transpose", "Transpose", &i__2, &jb, &i__3, &q__1, 
1330                         &a[(k + 1) * a_dim1 + 1], lda, &w[j + (kw + 1) * 
1331                         w_dim1], ldw, &c_b1, &a[j * a_dim1 + 1], lda);
1332             }
1333 /* L50: */
1334         }
1335
1336 /*        Put U12 in standard form by partially undoing the interchanges */
1337 /*        in of rows in columns k+1:n looping backwards from k+1 to n */
1338
1339         j = k + 1;
1340 L60:
1341
1342 /*           Undo the interchanges (if any) of rows J and JP2 */
1343 /*           (or J and JP2, and J+1 and JP1) at each step J */
1344
1345         kstep = 1;
1346         jp1 = 1;
1347 /*           (Here, J is a diagonal index) */
1348         jj = j;
1349         jp2 = ipiv[j];
1350         if (jp2 < 0) {
1351             jp2 = -jp2;
1352 /*              (Here, J is a diagonal index) */
1353             ++j;
1354             jp1 = -ipiv[j];
1355             kstep = 2;
1356         }
1357 /*           (NOTE: Here, J is used to determine row length. Length N-J+1 */
1358 /*           of the rows to swap back doesn't include diagonal element) */
1359         ++j;
1360         if (jp2 != jj && j <= *n) {
1361             i__1 = *n - j + 1;
1362             cswap_(&i__1, &a[jp2 + j * a_dim1], lda, &a[jj + j * a_dim1], lda)
1363                     ;
1364         }
1365         ++jj;
1366         if (kstep == 2 && jp1 != jj && j <= *n) {
1367             i__1 = *n - j + 1;
1368             cswap_(&i__1, &a[jp1 + j * a_dim1], lda, &a[jj + j * a_dim1], lda)
1369                     ;
1370         }
1371         if (j < *n) {
1372             goto L60;
1373         }
1374
1375 /*        Set KB to the number of columns factorized */
1376
1377         *kb = *n - k;
1378
1379     } else {
1380
1381 /*        Factorize the leading columns of A using the lower triangle */
1382 /*        of A and working forwards, and compute the matrix W = L21*D */
1383 /*        for use in updating A22 (note that conjg(W) is actually stored) */
1384
1385 /*        K is the main loop index, increasing from 1 in steps of 1 or 2 */
1386
1387         k = 1;
1388 L70:
1389
1390 /*        Exit from loop */
1391
1392         if (k >= *nb && *nb < *n || k > *n) {
1393             goto L90;
1394         }
1395
1396         kstep = 1;
1397         p = k;
1398
1399 /*        Copy column K of A to column K of W and update column K of W */
1400
1401         i__1 = k + k * w_dim1;
1402         i__2 = k + k * a_dim1;
1403         r__1 = a[i__2].r;
1404         w[i__1].r = r__1, w[i__1].i = 0.f;
1405         if (k < *n) {
1406             i__1 = *n - k;
1407             ccopy_(&i__1, &a[k + 1 + k * a_dim1], &c__1, &w[k + 1 + k * 
1408                     w_dim1], &c__1);
1409         }
1410         if (k > 1) {
1411             i__1 = *n - k + 1;
1412             i__2 = k - 1;
1413             q__1.r = -1.f, q__1.i = 0.f;
1414             cgemv_("No transpose", &i__1, &i__2, &q__1, &a[k + a_dim1], lda, &
1415                     w[k + w_dim1], ldw, &c_b1, &w[k + k * w_dim1], &c__1);
1416             i__1 = k + k * w_dim1;
1417             i__2 = k + k * w_dim1;
1418             r__1 = w[i__2].r;
1419             w[i__1].r = r__1, w[i__1].i = 0.f;
1420         }
1421
1422 /*        Determine rows and columns to be interchanged and whether */
1423 /*        a 1-by-1 or 2-by-2 pivot block will be used */
1424
1425         i__1 = k + k * w_dim1;
1426         absakk = (r__1 = w[i__1].r, abs(r__1));
1427
1428 /*        IMAX is the row-index of the largest off-diagonal element in */
1429 /*        column K, and COLMAX is its absolute value. */
1430 /*        Determine both COLMAX and IMAX. */
1431
1432         if (k < *n) {
1433             i__1 = *n - k;
1434             imax = k + icamax_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
1435             i__1 = imax + k * w_dim1;
1436             colmax = (r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&w[imax + 
1437                     k * w_dim1]), abs(r__2));
1438         } else {
1439             colmax = 0.f;
1440         }
1441
1442         if (f2cmax(absakk,colmax) == 0.f) {
1443
1444 /*           Column K is zero or underflow: set INFO and continue */
1445
1446             if (*info == 0) {
1447                 *info = k;
1448             }
1449             kp = k;
1450             i__1 = k + k * a_dim1;
1451             i__2 = k + k * w_dim1;
1452             r__1 = w[i__2].r;
1453             a[i__1].r = r__1, a[i__1].i = 0.f;
1454             if (k < *n) {
1455                 i__1 = *n - k;
1456                 ccopy_(&i__1, &w[k + 1 + k * w_dim1], &c__1, &a[k + 1 + k * 
1457                         a_dim1], &c__1);
1458             }
1459         } else {
1460
1461 /*           ============================================================ */
1462
1463 /*           BEGIN pivot search */
1464
1465 /*           Case(1) */
1466 /*           Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX */
1467 /*           (used to handle NaN and Inf) */
1468
1469             if (! (absakk < alpha * colmax)) {
1470
1471 /*              no interchange, use 1-by-1 pivot block */
1472
1473                 kp = k;
1474
1475             } else {
1476
1477                 done = FALSE_;
1478
1479 /*              Loop until pivot found */
1480
1481 L72:
1482
1483 /*                 BEGIN pivot search loop body */
1484
1485
1486 /*                 Copy column IMAX to column k+1 of W and update it */
1487
1488                 i__1 = imax - k;
1489                 ccopy_(&i__1, &a[imax + k * a_dim1], lda, &w[k + (k + 1) * 
1490                         w_dim1], &c__1);
1491                 i__1 = imax - k;
1492                 clacgv_(&i__1, &w[k + (k + 1) * w_dim1], &c__1);
1493                 i__1 = imax + (k + 1) * w_dim1;
1494                 i__2 = imax + imax * a_dim1;
1495                 r__1 = a[i__2].r;
1496                 w[i__1].r = r__1, w[i__1].i = 0.f;
1497
1498                 if (imax < *n) {
1499                     i__1 = *n - imax;
1500                     ccopy_(&i__1, &a[imax + 1 + imax * a_dim1], &c__1, &w[
1501                             imax + 1 + (k + 1) * w_dim1], &c__1);
1502                 }
1503
1504                 if (k > 1) {
1505                     i__1 = *n - k + 1;
1506                     i__2 = k - 1;
1507                     q__1.r = -1.f, q__1.i = 0.f;
1508                     cgemv_("No transpose", &i__1, &i__2, &q__1, &a[k + a_dim1]
1509                             , lda, &w[imax + w_dim1], ldw, &c_b1, &w[k + (k + 
1510                             1) * w_dim1], &c__1);
1511                     i__1 = imax + (k + 1) * w_dim1;
1512                     i__2 = imax + (k + 1) * w_dim1;
1513                     r__1 = w[i__2].r;
1514                     w[i__1].r = r__1, w[i__1].i = 0.f;
1515                 }
1516
1517 /*                 JMAX is the column-index of the largest off-diagonal */
1518 /*                 element in row IMAX, and ROWMAX is its absolute value. */
1519 /*                 Determine both ROWMAX and JMAX. */
1520
1521                 if (imax != k) {
1522                     i__1 = imax - k;
1523                     jmax = k - 1 + icamax_(&i__1, &w[k + (k + 1) * w_dim1], &
1524                             c__1);
1525                     i__1 = jmax + (k + 1) * w_dim1;
1526                     rowmax = (r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&
1527                             w[jmax + (k + 1) * w_dim1]), abs(r__2));
1528                 } else {
1529                     rowmax = 0.f;
1530                 }
1531
1532                 if (imax < *n) {
1533                     i__1 = *n - imax;
1534                     itemp = imax + icamax_(&i__1, &w[imax + 1 + (k + 1) * 
1535                             w_dim1], &c__1);
1536                     i__1 = itemp + (k + 1) * w_dim1;
1537                     stemp = (r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&w[
1538                             itemp + (k + 1) * w_dim1]), abs(r__2));
1539                     if (stemp > rowmax) {
1540                         rowmax = stemp;
1541                         jmax = itemp;
1542                     }
1543                 }
1544
1545 /*                 Case(2) */
1546 /*                 Equivalent to testing for */
1547 /*                 ABS( REAL( W( IMAX,K+1 ) ) ).GE.ALPHA*ROWMAX */
1548 /*                 (used to handle NaN and Inf) */
1549
1550                 i__1 = imax + (k + 1) * w_dim1;
1551                 if (! ((r__1 = w[i__1].r, abs(r__1)) < alpha * rowmax)) {
1552
1553 /*                    interchange rows and columns K and IMAX, */
1554 /*                    use 1-by-1 pivot block */
1555
1556                     kp = imax;
1557
1558 /*                    copy column K+1 of W to column K of W */
1559
1560                     i__1 = *n - k + 1;
1561                     ccopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k + k * 
1562                             w_dim1], &c__1);
1563
1564                     done = TRUE_;
1565
1566 /*                 Case(3) */
1567 /*                 Equivalent to testing for ROWMAX.EQ.COLMAX, */
1568 /*                 (used to handle NaN and Inf) */
1569
1570                 } else if (p == jmax || rowmax <= colmax) {
1571
1572 /*                    interchange rows and columns K+1 and IMAX, */
1573 /*                    use 2-by-2 pivot block */
1574
1575                     kp = imax;
1576                     kstep = 2;
1577                     done = TRUE_;
1578
1579 /*                 Case(4) */
1580                 } else {
1581
1582 /*                    Pivot not found: set params and repeat */
1583
1584                     p = imax;
1585                     colmax = rowmax;
1586                     imax = jmax;
1587
1588 /*                    Copy updated JMAXth (next IMAXth) column to Kth of W */
1589
1590                     i__1 = *n - k + 1;
1591                     ccopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k + k * 
1592                             w_dim1], &c__1);
1593
1594                 }
1595
1596
1597 /*                 End pivot search loop body */
1598
1599                 if (! done) {
1600                     goto L72;
1601                 }
1602
1603             }
1604
1605 /*           END pivot search */
1606
1607 /*           ============================================================ */
1608
1609 /*           KK is the column of A where pivoting step stopped */
1610
1611             kk = k + kstep - 1;
1612
1613 /*           Interchange rows and columns P and K (only for 2-by-2 pivot). */
1614 /*           Updated column P is already stored in column K of W. */
1615
1616             if (kstep == 2 && p != k) {
1617
1618 /*              Copy non-updated column KK-1 to column P of submatrix A */
1619 /*              at step K. No need to copy element into columns */
1620 /*              K and K+1 of A for 2-by-2 pivot, since these columns */
1621 /*              will be later overwritten. */
1622
1623                 i__1 = p + p * a_dim1;
1624                 i__2 = k + k * a_dim1;
1625                 r__1 = a[i__2].r;
1626                 a[i__1].r = r__1, a[i__1].i = 0.f;
1627                 i__1 = p - k - 1;
1628                 ccopy_(&i__1, &a[k + 1 + k * a_dim1], &c__1, &a[p + (k + 1) * 
1629                         a_dim1], lda);
1630                 i__1 = p - k - 1;
1631                 clacgv_(&i__1, &a[p + (k + 1) * a_dim1], lda);
1632                 if (p < *n) {
1633                     i__1 = *n - p;
1634                     ccopy_(&i__1, &a[p + 1 + k * a_dim1], &c__1, &a[p + 1 + p 
1635                             * a_dim1], &c__1);
1636                 }
1637
1638 /*              Interchange rows K and P in first K-1 columns of A */
1639 /*              (columns K and K+1 of A for 2-by-2 pivot will be */
1640 /*              later overwritten). Interchange rows K and P */
1641 /*              in first KK columns of W. */
1642
1643                 if (k > 1) {
1644                     i__1 = k - 1;
1645                     cswap_(&i__1, &a[k + a_dim1], lda, &a[p + a_dim1], lda);
1646                 }
1647                 cswap_(&kk, &w[k + w_dim1], ldw, &w[p + w_dim1], ldw);
1648             }
1649
1650 /*           Interchange rows and columns KP and KK. */
1651 /*           Updated column KP is already stored in column KK of W. */
1652
1653             if (kp != kk) {
1654
1655 /*              Copy non-updated column KK to column KP of submatrix A */
1656 /*              at step K. No need to copy element into column K */
1657 /*              (or K and K+1 for 2-by-2 pivot) of A, since these columns */
1658 /*              will be later overwritten. */
1659
1660                 i__1 = kp + kp * a_dim1;
1661                 i__2 = kk + kk * a_dim1;
1662                 r__1 = a[i__2].r;
1663                 a[i__1].r = r__1, a[i__1].i = 0.f;
1664                 i__1 = kp - kk - 1;
1665                 ccopy_(&i__1, &a[kk + 1 + kk * a_dim1], &c__1, &a[kp + (kk + 
1666                         1) * a_dim1], lda);
1667                 i__1 = kp - kk - 1;
1668                 clacgv_(&i__1, &a[kp + (kk + 1) * a_dim1], lda);
1669                 if (kp < *n) {
1670                     i__1 = *n - kp;
1671                     ccopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + 1 
1672                             + kp * a_dim1], &c__1);
1673                 }
1674
1675 /*              Interchange rows KK and KP in first K-1 columns of A */
1676 /*              (column K (or K and K+1 for 2-by-2 pivot) of A will be */
1677 /*              later overwritten). Interchange rows KK and KP */
1678 /*              in first KK columns of W. */
1679
1680                 if (k > 1) {
1681                     i__1 = k - 1;
1682                     cswap_(&i__1, &a[kk + a_dim1], lda, &a[kp + a_dim1], lda);
1683                 }
1684                 cswap_(&kk, &w[kk + w_dim1], ldw, &w[kp + w_dim1], ldw);
1685             }
1686
1687             if (kstep == 1) {
1688
1689 /*              1-by-1 pivot block D(k): column k of W now holds */
1690
1691 /*              W(k) = L(k)*D(k), */
1692
1693 /*              where L(k) is the k-th column of L */
1694
1695 /*              (1) Store subdiag. elements of column L(k) */
1696 /*              and 1-by-1 block D(k) in column k of A. */
1697 /*              (NOTE: Diagonal element L(k,k) is a UNIT element */
1698 /*              and not stored) */
1699 /*                 A(k,k) := D(k,k) = W(k,k) */
1700 /*                 A(k+1:N,k) := L(k+1:N,k) = W(k+1:N,k)/D(k,k) */
1701
1702 /*              (NOTE: No need to use for Hermitian matrix */
1703 /*              A( K, K ) = REAL( W( K, K) ) to separately copy diagonal */
1704 /*              element D(k,k) from W (potentially saves only one load)) */
1705                 i__1 = *n - k + 1;
1706                 ccopy_(&i__1, &w[k + k * w_dim1], &c__1, &a[k + k * a_dim1], &
1707                         c__1);
1708                 if (k < *n) {
1709
1710 /*                 (NOTE: No need to check if A(k,k) is NOT ZERO, */
1711 /*                  since that was ensured earlier in pivot search: */
1712 /*                  case A(k,k) = 0 falls into 2x2 pivot case(3)) */
1713
1714 /*                 Handle division by a small number */
1715
1716                     i__1 = k + k * a_dim1;
1717                     t = a[i__1].r;
1718                     if (abs(t) >= sfmin) {
1719                         r1 = 1.f / t;
1720                         i__1 = *n - k;
1721                         csscal_(&i__1, &r1, &a[k + 1 + k * a_dim1], &c__1);
1722                     } else {
1723                         i__1 = *n;
1724                         for (ii = k + 1; ii <= i__1; ++ii) {
1725                             i__2 = ii + k * a_dim1;
1726                             i__3 = ii + k * a_dim1;
1727                             q__1.r = a[i__3].r / t, q__1.i = a[i__3].i / t;
1728                             a[i__2].r = q__1.r, a[i__2].i = q__1.i;
1729 /* L74: */
1730                         }
1731                     }
1732
1733 /*                 (2) Conjugate column W(k) */
1734
1735                     i__1 = *n - k;
1736                     clacgv_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
1737                 }
1738
1739             } else {
1740
1741 /*              2-by-2 pivot block D(k): columns k and k+1 of W now hold */
1742
1743 /*              ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */
1744
1745 /*              where L(k) and L(k+1) are the k-th and (k+1)-th columns */
1746 /*              of L */
1747
1748 /*              (1) Store L(k+2:N,k) and L(k+2:N,k+1) and 2-by-2 */
1749 /*              block D(k:k+1,k:k+1) in columns k and k+1 of A. */
1750 /*              NOTE: 2-by-2 diagonal block L(k:k+1,k:k+1) is a UNIT */
1751 /*              block and not stored. */
1752 /*                 A(k:k+1,k:k+1) := D(k:k+1,k:k+1) = W(k:k+1,k:k+1) */
1753 /*                 A(k+2:N,k:k+1) := L(k+2:N,k:k+1) = */
1754 /*                 = W(k+2:N,k:k+1) * ( D(k:k+1,k:k+1)**(-1) ) */
1755
1756                 if (k < *n - 1) {
1757
1758 /*                 Factor out the columns of the inverse of 2-by-2 pivot */
1759 /*                 block D, so that each column contains 1, to reduce the */
1760 /*                 number of FLOPS when we multiply panel */
1761 /*                 ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1). */
1762
1763 /*                 D**(-1) = ( d11 cj(d21) )**(-1) = */
1764 /*                           ( d21    d22 ) */
1765
1766 /*                 = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) = */
1767 /*                                          ( (-d21) (     d11 ) ) */
1768
1769 /*                 = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) * */
1770
1771 /*                   * ( d21*( d22/d21 ) conj(d21)*(           - 1 ) ) = */
1772 /*                     (     (      -1 )           ( d11/conj(d21) ) ) */
1773
1774 /*                 = 1/(|d21|**2) * 1/(D22*D11-1) * */
1775
1776 /*                   * ( d21*( D11 ) conj(d21)*(  -1 ) ) = */
1777 /*                     (     (  -1 )           ( D22 ) ) */
1778
1779 /*                 = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*(  -1 ) ) = */
1780 /*                                      (     (  -1 )           ( D22 ) ) */
1781
1782 /*                 = ( (T/conj(d21))*( D11 ) (T/d21)*(  -1 ) ) = */
1783 /*                   (               (  -1 )         ( D22 ) ) */
1784
1785 /*                 Handle division by a small number. (NOTE: order of */
1786 /*                 operations is important) */
1787
1788 /*                 = ( T*(( D11 )/conj(D21)) T*((  -1 )/D21 ) ) */
1789 /*                   (   ((  -1 )          )   (( D22 )     ) ), */
1790
1791 /*                 where D11 = d22/d21, */
1792 /*                       D22 = d11/conj(d21), */
1793 /*                       D21 = d21, */
1794 /*                       T = 1/(D22*D11-1). */
1795
1796 /*                 (NOTE: No need to check for division by ZERO, */
1797 /*                  since that was ensured earlier in pivot search: */
1798 /*                  (a) d21 != 0 in 2x2 pivot case(4), */
1799 /*                      since |d21| should be larger than |d11| and |d22|; */
1800 /*                  (b) (D22*D11 - 1) != 0, since from (a), */
1801 /*                      both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.) */
1802
1803                     i__1 = k + 1 + k * w_dim1;
1804                     d21.r = w[i__1].r, d21.i = w[i__1].i;
1805                     c_div(&q__1, &w[k + 1 + (k + 1) * w_dim1], &d21);
1806                     d11.r = q__1.r, d11.i = q__1.i;
1807                     r_cnjg(&q__2, &d21);
1808                     c_div(&q__1, &w[k + k * w_dim1], &q__2);
1809                     d22.r = q__1.r, d22.i = q__1.i;
1810                     q__1.r = d11.r * d22.r - d11.i * d22.i, q__1.i = d11.r * 
1811                             d22.i + d11.i * d22.r;
1812                     t = 1.f / (q__1.r - 1.f);
1813
1814 /*                 Update elements in columns A(k) and A(k+1) as */
1815 /*                 dot products of rows of ( W(k) W(k+1) ) and columns */
1816 /*                 of D**(-1) */
1817
1818                     i__1 = *n;
1819                     for (j = k + 2; j <= i__1; ++j) {
1820                         i__2 = j + k * a_dim1;
1821                         i__3 = j + k * w_dim1;
1822                         q__4.r = d11.r * w[i__3].r - d11.i * w[i__3].i, 
1823                                 q__4.i = d11.r * w[i__3].i + d11.i * w[i__3]
1824                                 .r;
1825                         i__4 = j + (k + 1) * w_dim1;
1826                         q__3.r = q__4.r - w[i__4].r, q__3.i = q__4.i - w[i__4]
1827                                 .i;
1828                         r_cnjg(&q__5, &d21);
1829                         c_div(&q__2, &q__3, &q__5);
1830                         q__1.r = t * q__2.r, q__1.i = t * q__2.i;
1831                         a[i__2].r = q__1.r, a[i__2].i = q__1.i;
1832                         i__2 = j + (k + 1) * a_dim1;
1833                         i__3 = j + (k + 1) * w_dim1;
1834                         q__4.r = d22.r * w[i__3].r - d22.i * w[i__3].i, 
1835                                 q__4.i = d22.r * w[i__3].i + d22.i * w[i__3]
1836                                 .r;
1837                         i__4 = j + k * w_dim1;
1838                         q__3.r = q__4.r - w[i__4].r, q__3.i = q__4.i - w[i__4]
1839                                 .i;
1840                         c_div(&q__2, &q__3, &d21);
1841                         q__1.r = t * q__2.r, q__1.i = t * q__2.i;
1842                         a[i__2].r = q__1.r, a[i__2].i = q__1.i;
1843 /* L80: */
1844                     }
1845                 }
1846
1847 /*              Copy D(k) to A */
1848
1849                 i__1 = k + k * a_dim1;
1850                 i__2 = k + k * w_dim1;
1851                 a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
1852                 i__1 = k + 1 + k * a_dim1;
1853                 i__2 = k + 1 + k * w_dim1;
1854                 a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
1855                 i__1 = k + 1 + (k + 1) * a_dim1;
1856                 i__2 = k + 1 + (k + 1) * w_dim1;
1857                 a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
1858
1859 /*              (2) Conjugate columns W(k) and W(k+1) */
1860
1861                 i__1 = *n - k;
1862                 clacgv_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
1863                 i__1 = *n - k - 1;
1864                 clacgv_(&i__1, &w[k + 2 + (k + 1) * w_dim1], &c__1);
1865
1866             }
1867
1868         }
1869
1870 /*        Store details of the interchanges in IPIV */
1871
1872         if (kstep == 1) {
1873             ipiv[k] = kp;
1874         } else {
1875             ipiv[k] = -p;
1876             ipiv[k + 1] = -kp;
1877         }
1878
1879 /*        Increase K and return to the start of the main loop */
1880
1881         k += kstep;
1882         goto L70;
1883
1884 L90:
1885
1886 /*        Update the lower triangle of A22 (= A(k:n,k:n)) as */
1887
1888 /*        A22 := A22 - L21*D*L21**H = A22 - L21*W**H */
1889
1890 /*        computing blocks of NB columns at a time (note that conjg(W) is */
1891 /*        actually stored) */
1892
1893         i__1 = *n;
1894         i__2 = *nb;
1895         for (j = k; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
1896 /* Computing MIN */
1897             i__3 = *nb, i__4 = *n - j + 1;
1898             jb = f2cmin(i__3,i__4);
1899
1900 /*           Update the lower triangle of the diagonal block */
1901
1902             i__3 = j + jb - 1;
1903             for (jj = j; jj <= i__3; ++jj) {
1904                 i__4 = jj + jj * a_dim1;
1905                 i__5 = jj + jj * a_dim1;
1906                 r__1 = a[i__5].r;
1907                 a[i__4].r = r__1, a[i__4].i = 0.f;
1908                 i__4 = j + jb - jj;
1909                 i__5 = k - 1;
1910                 q__1.r = -1.f, q__1.i = 0.f;
1911                 cgemv_("No transpose", &i__4, &i__5, &q__1, &a[jj + a_dim1], 
1912                         lda, &w[jj + w_dim1], ldw, &c_b1, &a[jj + jj * a_dim1]
1913                         , &c__1);
1914                 i__4 = jj + jj * a_dim1;
1915                 i__5 = jj + jj * a_dim1;
1916                 r__1 = a[i__5].r;
1917                 a[i__4].r = r__1, a[i__4].i = 0.f;
1918 /* L100: */
1919             }
1920
1921 /*           Update the rectangular subdiagonal block */
1922
1923             if (j + jb <= *n) {
1924                 i__3 = *n - j - jb + 1;
1925                 i__4 = k - 1;
1926                 q__1.r = -1.f, q__1.i = 0.f;
1927                 cgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, &q__1, 
1928                         &a[j + jb + a_dim1], lda, &w[j + w_dim1], ldw, &c_b1, 
1929                         &a[j + jb + j * a_dim1], lda);
1930             }
1931 /* L110: */
1932         }
1933
1934 /*        Put L21 in standard form by partially undoing the interchanges */
1935 /*        of rows in columns 1:k-1 looping backwards from k-1 to 1 */
1936
1937         j = k - 1;
1938 L120:
1939
1940 /*           Undo the interchanges (if any) of rows J and JP2 */
1941 /*           (or J and JP2, and J-1 and JP1) at each step J */
1942
1943         kstep = 1;
1944         jp1 = 1;
1945 /*           (Here, J is a diagonal index) */
1946         jj = j;
1947         jp2 = ipiv[j];
1948         if (jp2 < 0) {
1949             jp2 = -jp2;
1950 /*              (Here, J is a diagonal index) */
1951             --j;
1952             jp1 = -ipiv[j];
1953             kstep = 2;
1954         }
1955 /*           (NOTE: Here, J is used to determine row length. Length J */
1956 /*           of the rows to swap back doesn't include diagonal element) */
1957         --j;
1958         if (jp2 != jj && j >= 1) {
1959             cswap_(&j, &a[jp2 + a_dim1], lda, &a[jj + a_dim1], lda);
1960         }
1961         --jj;
1962         if (kstep == 2 && jp1 != jj && j >= 1) {
1963             cswap_(&j, &a[jp1 + a_dim1], lda, &a[jj + a_dim1], lda);
1964         }
1965         if (j > 1) {
1966             goto L120;
1967         }
1968
1969 /*        Set KB to the number of columns factorized */
1970
1971         *kb = k - 1;
1972
1973     }
1974     return 0;
1975
1976 /*     End of CLAHEF_ROOK */
1977
1978 } /* clahef_rook__ */
1979