C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / zhetri_3x.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
514 /* Table of constant values */
515
516 static doublecomplex c_b1 = {1.,0.};
517 static doublecomplex c_b2 = {0.,0.};
518
519 /* > \brief \b ZHETRI_3X */
520
521 /*  =========== DOCUMENTATION =========== */
522
523 /* Online html documentation available at */
524 /*            http://www.netlib.org/lapack/explore-html/ */
525
526 /* > \htmlonly */
527 /* > Download ZHETRI_3X + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetri_
529 3x.f"> */
530 /* > [TGZ]</a> */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetri_
532 3x.f"> */
533 /* > [ZIP]</a> */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetri_
535 3x.f"> */
536 /* > [TXT]</a> */
537 /* > \endhtmlonly */
538
539 /*  Definition: */
540 /*  =========== */
541
542 /*       SUBROUTINE ZHETRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) */
543
544 /*       CHARACTER          UPLO */
545 /*       INTEGER            INFO, LDA, N, NB */
546 /*       INTEGER            IPIV( * ) */
547 /*       COMPLEX*16         A( LDA, * ),  E( * ), WORK( N+NB+1, * ) */
548
549
550 /* > \par Purpose: */
551 /*  ============= */
552 /* > */
553 /* > \verbatim */
554 /* > ZHETRI_3X computes the inverse of a complex Hermitian indefinite */
555 /* > matrix A using the factorization computed by ZHETRF_RK or ZHETRF_BK: */
556 /* > */
557 /* >     A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), */
558 /* > */
559 /* > where U (or L) is unit upper (or lower) triangular matrix, */
560 /* > U**H (or L**H) is the conjugate of U (or L), P is a permutation */
561 /* > matrix, P**T is the transpose of P, and D is Hermitian and block */
562 /* > diagonal with 1-by-1 and 2-by-2 diagonal blocks. */
563 /* > */
564 /* > This is the blocked version of the algorithm, calling Level 3 BLAS. */
565 /* > \endverbatim */
566
567 /*  Arguments: */
568 /*  ========== */
569
570 /* > \param[in] UPLO */
571 /* > \verbatim */
572 /* >          UPLO is CHARACTER*1 */
573 /* >          Specifies whether the details of the factorization are */
574 /* >          stored as an upper or lower triangular matrix. */
575 /* >          = 'U':  Upper triangle of A is stored; */
576 /* >          = 'L':  Lower triangle of A is stored. */
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, diagonal of the block diagonal matrix D and */
589 /* >          factors U or L as computed by ZHETRF_RK and ZHETRF_BK: */
590 /* >            a) ONLY diagonal elements of the Hermitian block diagonal */
591 /* >               matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); */
592 /* >               (superdiagonal (or subdiagonal) elements of D */
593 /* >                should be provided on entry in array E), and */
594 /* >            b) If UPLO = 'U': factor U in the superdiagonal part of A. */
595 /* >               If UPLO = 'L': factor L in the subdiagonal part of A. */
596 /* > */
597 /* >          On exit, if INFO = 0, the Hermitian inverse of the original */
598 /* >          matrix. */
599 /* >             If UPLO = 'U': the upper triangular part of the inverse */
600 /* >             is formed and the part of A below the diagonal is not */
601 /* >             referenced; */
602 /* >             If UPLO = 'L': the lower triangular part of the inverse */
603 /* >             is formed and the part of A above the diagonal is not */
604 /* >             referenced. */
605 /* > \endverbatim */
606 /* > */
607 /* > \param[in] LDA */
608 /* > \verbatim */
609 /* >          LDA is INTEGER */
610 /* >          The leading dimension of the array A.  LDA >= f2cmax(1,N). */
611 /* > \endverbatim */
612 /* > */
613 /* > \param[in] E */
614 /* > \verbatim */
615 /* >          E is COMPLEX*16 array, dimension (N) */
616 /* >          On entry, contains the superdiagonal (or subdiagonal) */
617 /* >          elements of the Hermitian block diagonal matrix D */
618 /* >          with 1-by-1 or 2-by-2 diagonal blocks, where */
619 /* >          If UPLO = 'U': E(i) = D(i-1,i), i=2:N, E(1) not referenced; */
620 /* >          If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) not referenced. */
621 /* > */
622 /* >          NOTE: For 1-by-1 diagonal block D(k), where */
623 /* >          1 <= k <= N, the element E(k) is not referenced in both */
624 /* >          UPLO = 'U' or UPLO = 'L' cases. */
625 /* > \endverbatim */
626 /* > */
627 /* > \param[in] IPIV */
628 /* > \verbatim */
629 /* >          IPIV is INTEGER array, dimension (N) */
630 /* >          Details of the interchanges and the block structure of D */
631 /* >          as determined by ZHETRF_RK or ZHETRF_BK. */
632 /* > \endverbatim */
633 /* > */
634 /* > \param[out] WORK */
635 /* > \verbatim */
636 /* >          WORK is COMPLEX*16 array, dimension (N+NB+1,NB+3). */
637 /* > \endverbatim */
638 /* > */
639 /* > \param[in] NB */
640 /* > \verbatim */
641 /* >          NB is INTEGER */
642 /* >          Block size. */
643 /* > \endverbatim */
644 /* > */
645 /* > \param[out] INFO */
646 /* > \verbatim */
647 /* >          INFO is INTEGER */
648 /* >          = 0: successful exit */
649 /* >          < 0: if INFO = -i, the i-th argument had an illegal value */
650 /* >          > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its */
651 /* >               inverse could not be computed. */
652 /* > \endverbatim */
653
654 /*  Authors: */
655 /*  ======== */
656
657 /* > \author Univ. of Tennessee */
658 /* > \author Univ. of California Berkeley */
659 /* > \author Univ. of Colorado Denver */
660 /* > \author NAG Ltd. */
661
662 /* > \date June 2017 */
663
664 /* > \ingroup complex16HEcomputational */
665
666 /* > \par Contributors: */
667 /*  ================== */
668 /* > \verbatim */
669 /* > */
670 /* >  June 2017,  Igor Kozachenko, */
671 /* >                  Computer Science Division, */
672 /* >                  University of California, Berkeley */
673 /* > */
674 /* > \endverbatim */
675
676 /*  ===================================================================== */
677 /* Subroutine */ int zhetri_3x_(char *uplo, integer *n, doublecomplex *a, 
678         integer *lda, doublecomplex *e, integer *ipiv, doublecomplex *work, 
679         integer *nb, integer *info)
680 {
681     /* System generated locals */
682     integer a_dim1, a_offset, work_dim1, work_offset, i__1, i__2, i__3, i__4, 
683             i__5, i__6;
684     doublereal d__1;
685     doublecomplex z__1, z__2, z__3;
686
687     /* Local variables */
688     integer invd;
689     doublecomplex akkp1;
690     extern /* Subroutine */ int zheswapr_(char *, integer *, doublecomplex *, 
691             integer *, integer *, integer *);
692     doublecomplex d__;
693     integer i__, j, k;
694     doublereal t;
695     extern logical lsame_(char *, char *);
696     extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *, 
697             integer *, doublecomplex *, doublecomplex *, integer *, 
698             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
699             integer *);
700     logical upper;
701     extern /* Subroutine */ int ztrmm_(char *, char *, char *, char *, 
702             integer *, integer *, doublecomplex *, doublecomplex *, integer *,
703              doublecomplex *, integer *);
704     doublereal ak;
705     doublecomplex u01_i_j__;
706     integer u11;
707     doublecomplex u11_i_j__;
708     integer ip;
709     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
710     integer icount;
711     extern /* Subroutine */ int ztrtri_(char *, char *, integer *, 
712             doublecomplex *, integer *, integer *);
713     integer nnb, cut;
714     doublereal akp1;
715     doublecomplex u01_ip1_j__, u11_ip1_j__;
716
717
718 /*  -- LAPACK computational routine (version 3.7.1) -- */
719 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
720 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
721 /*     June 2017 */
722
723
724 /*  ===================================================================== */
725
726
727 /*     Test the input parameters. */
728
729     /* Parameter adjustments */
730     a_dim1 = *lda;
731     a_offset = 1 + a_dim1 * 1;
732     a -= a_offset;
733     --e;
734     --ipiv;
735     work_dim1 = *n + *nb + 1;
736     work_offset = 1 + work_dim1 * 1;
737     work -= work_offset;
738
739     /* Function Body */
740     *info = 0;
741     upper = lsame_(uplo, "U");
742     if (! upper && ! lsame_(uplo, "L")) {
743         *info = -1;
744     } else if (*n < 0) {
745         *info = -2;
746     } else if (*lda < f2cmax(1,*n)) {
747         *info = -4;
748     }
749
750 /*     Quick return if possible */
751
752     if (*info != 0) {
753         i__1 = -(*info);
754         xerbla_("ZHETRI_3X", &i__1, (ftnlen)9);
755         return 0;
756     }
757     if (*n == 0) {
758         return 0;
759     }
760
761 /*     Workspace got Non-diag elements of D */
762
763     i__1 = *n;
764     for (k = 1; k <= i__1; ++k) {
765         i__2 = k + work_dim1;
766         i__3 = k;
767         work[i__2].r = e[i__3].r, work[i__2].i = e[i__3].i;
768     }
769
770 /*     Check that the diagonal matrix D is nonsingular. */
771
772     if (upper) {
773
774 /*        Upper triangular storage: examine D from bottom to top */
775
776         for (*info = *n; *info >= 1; --(*info)) {
777             i__1 = *info + *info * a_dim1;
778             if (ipiv[*info] > 0 && (a[i__1].r == 0. && a[i__1].i == 0.)) {
779                 return 0;
780             }
781         }
782     } else {
783
784 /*        Lower triangular storage: examine D from top to bottom. */
785
786         i__1 = *n;
787         for (*info = 1; *info <= i__1; ++(*info)) {
788             i__2 = *info + *info * a_dim1;
789             if (ipiv[*info] > 0 && (a[i__2].r == 0. && a[i__2].i == 0.)) {
790                 return 0;
791             }
792         }
793     }
794
795     *info = 0;
796
797 /*     Splitting Workspace */
798 /*     U01 is a block ( N, NB+1 ) */
799 /*     The first element of U01 is in WORK( 1, 1 ) */
800 /*     U11 is a block ( NB+1, NB+1 ) */
801 /*     The first element of U11 is in WORK( N+1, 1 ) */
802
803     u11 = *n;
804
805 /*     INVD is a block ( N, 2 ) */
806 /*     The first element of INVD is in WORK( 1, INVD ) */
807
808     invd = *nb + 2;
809     if (upper) {
810
811 /*        Begin Upper */
812
813 /*        invA = P * inv(U**H) * inv(D) * inv(U) * P**T. */
814
815         ztrtri_(uplo, "U", n, &a[a_offset], lda, info);
816
817 /*        inv(D) and inv(D) * inv(U) */
818
819         k = 1;
820         while(k <= *n) {
821             if (ipiv[k] > 0) {
822 /*              1 x 1 diagonal NNB */
823                 i__1 = k + invd * work_dim1;
824                 i__2 = k + k * a_dim1;
825                 d__1 = 1. / a[i__2].r;
826                 work[i__1].r = d__1, work[i__1].i = 0.;
827                 i__1 = k + (invd + 1) * work_dim1;
828                 work[i__1].r = 0., work[i__1].i = 0.;
829             } else {
830 /*              2 x 2 diagonal NNB */
831                 t = z_abs(&work[k + 1 + work_dim1]);
832                 i__1 = k + k * a_dim1;
833                 ak = a[i__1].r / t;
834                 i__1 = k + 1 + (k + 1) * a_dim1;
835                 akp1 = a[i__1].r / t;
836                 i__1 = k + 1 + work_dim1;
837                 z__1.r = work[i__1].r / t, z__1.i = work[i__1].i / t;
838                 akkp1.r = z__1.r, akkp1.i = z__1.i;
839                 d__1 = ak * akp1;
840                 z__2.r = d__1 - 1., z__2.i = 0.;
841                 z__1.r = t * z__2.r, z__1.i = t * z__2.i;
842                 d__.r = z__1.r, d__.i = z__1.i;
843                 i__1 = k + invd * work_dim1;
844                 z__2.r = akp1, z__2.i = 0.;
845                 z_div(&z__1, &z__2, &d__);
846                 work[i__1].r = z__1.r, work[i__1].i = z__1.i;
847                 i__1 = k + 1 + (invd + 1) * work_dim1;
848                 z__2.r = ak, z__2.i = 0.;
849                 z_div(&z__1, &z__2, &d__);
850                 work[i__1].r = z__1.r, work[i__1].i = z__1.i;
851                 i__1 = k + (invd + 1) * work_dim1;
852                 z__2.r = -akkp1.r, z__2.i = -akkp1.i;
853                 z_div(&z__1, &z__2, &d__);
854                 work[i__1].r = z__1.r, work[i__1].i = z__1.i;
855                 i__1 = k + 1 + invd * work_dim1;
856                 d_cnjg(&z__1, &work[k + (invd + 1) * work_dim1]);
857                 work[i__1].r = z__1.r, work[i__1].i = z__1.i;
858                 ++k;
859             }
860             ++k;
861         }
862
863 /*        inv(U**H) = (inv(U))**H */
864
865 /*        inv(U**H) * inv(D) * inv(U) */
866
867         cut = *n;
868         while(cut > 0) {
869             nnb = *nb;
870             if (cut <= nnb) {
871                 nnb = cut;
872             } else {
873                 icount = 0;
874 /*              count negative elements, */
875                 i__1 = cut;
876                 for (i__ = cut + 1 - nnb; i__ <= i__1; ++i__) {
877                     if (ipiv[i__] < 0) {
878                         ++icount;
879                     }
880                 }
881 /*              need a even number for a clear cut */
882                 if (icount % 2 == 1) {
883                     ++nnb;
884                 }
885             }
886             cut -= nnb;
887
888 /*           U01 Block */
889
890             i__1 = cut;
891             for (i__ = 1; i__ <= i__1; ++i__) {
892                 i__2 = nnb;
893                 for (j = 1; j <= i__2; ++j) {
894                     i__3 = i__ + j * work_dim1;
895                     i__4 = i__ + (cut + j) * a_dim1;
896                     work[i__3].r = a[i__4].r, work[i__3].i = a[i__4].i;
897                 }
898             }
899
900 /*           U11 Block */
901
902             i__1 = nnb;
903             for (i__ = 1; i__ <= i__1; ++i__) {
904                 i__2 = u11 + i__ + i__ * work_dim1;
905                 work[i__2].r = 1., work[i__2].i = 0.;
906                 i__2 = i__ - 1;
907                 for (j = 1; j <= i__2; ++j) {
908                     i__3 = u11 + i__ + j * work_dim1;
909                     work[i__3].r = 0., work[i__3].i = 0.;
910                 }
911                 i__2 = nnb;
912                 for (j = i__ + 1; j <= i__2; ++j) {
913                     i__3 = u11 + i__ + j * work_dim1;
914                     i__4 = cut + i__ + (cut + j) * a_dim1;
915                     work[i__3].r = a[i__4].r, work[i__3].i = a[i__4].i;
916                 }
917             }
918
919 /*           invD * U01 */
920
921             i__ = 1;
922             while(i__ <= cut) {
923                 if (ipiv[i__] > 0) {
924                     i__1 = nnb;
925                     for (j = 1; j <= i__1; ++j) {
926                         i__2 = i__ + j * work_dim1;
927                         i__3 = i__ + invd * work_dim1;
928                         i__4 = i__ + j * work_dim1;
929                         z__1.r = work[i__3].r * work[i__4].r - work[i__3].i * 
930                                 work[i__4].i, z__1.i = work[i__3].r * work[
931                                 i__4].i + work[i__3].i * work[i__4].r;
932                         work[i__2].r = z__1.r, work[i__2].i = z__1.i;
933                     }
934                 } else {
935                     i__1 = nnb;
936                     for (j = 1; j <= i__1; ++j) {
937                         i__2 = i__ + j * work_dim1;
938                         u01_i_j__.r = work[i__2].r, u01_i_j__.i = work[i__2]
939                                 .i;
940                         i__2 = i__ + 1 + j * work_dim1;
941                         u01_ip1_j__.r = work[i__2].r, u01_ip1_j__.i = work[
942                                 i__2].i;
943                         i__2 = i__ + j * work_dim1;
944                         i__3 = i__ + invd * work_dim1;
945                         z__2.r = work[i__3].r * u01_i_j__.r - work[i__3].i * 
946                                 u01_i_j__.i, z__2.i = work[i__3].r * 
947                                 u01_i_j__.i + work[i__3].i * u01_i_j__.r;
948                         i__4 = i__ + (invd + 1) * work_dim1;
949                         z__3.r = work[i__4].r * u01_ip1_j__.r - work[i__4].i *
950                                  u01_ip1_j__.i, z__3.i = work[i__4].r * 
951                                 u01_ip1_j__.i + work[i__4].i * u01_ip1_j__.r;
952                         z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
953                         work[i__2].r = z__1.r, work[i__2].i = z__1.i;
954                         i__2 = i__ + 1 + j * work_dim1;
955                         i__3 = i__ + 1 + invd * work_dim1;
956                         z__2.r = work[i__3].r * u01_i_j__.r - work[i__3].i * 
957                                 u01_i_j__.i, z__2.i = work[i__3].r * 
958                                 u01_i_j__.i + work[i__3].i * u01_i_j__.r;
959                         i__4 = i__ + 1 + (invd + 1) * work_dim1;
960                         z__3.r = work[i__4].r * u01_ip1_j__.r - work[i__4].i *
961                                  u01_ip1_j__.i, z__3.i = work[i__4].r * 
962                                 u01_ip1_j__.i + work[i__4].i * u01_ip1_j__.r;
963                         z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
964                         work[i__2].r = z__1.r, work[i__2].i = z__1.i;
965                     }
966                     ++i__;
967                 }
968                 ++i__;
969             }
970
971 /*           invD1 * U11 */
972
973             i__ = 1;
974             while(i__ <= nnb) {
975                 if (ipiv[cut + i__] > 0) {
976                     i__1 = nnb;
977                     for (j = i__; j <= i__1; ++j) {
978                         i__2 = u11 + i__ + j * work_dim1;
979                         i__3 = cut + i__ + invd * work_dim1;
980                         i__4 = u11 + i__ + j * work_dim1;
981                         z__1.r = work[i__3].r * work[i__4].r - work[i__3].i * 
982                                 work[i__4].i, z__1.i = work[i__3].r * work[
983                                 i__4].i + work[i__3].i * work[i__4].r;
984                         work[i__2].r = z__1.r, work[i__2].i = z__1.i;
985                     }
986                 } else {
987                     i__1 = nnb;
988                     for (j = i__; j <= i__1; ++j) {
989                         i__2 = u11 + i__ + j * work_dim1;
990                         u11_i_j__.r = work[i__2].r, u11_i_j__.i = work[i__2]
991                                 .i;
992                         i__2 = u11 + i__ + 1 + j * work_dim1;
993                         u11_ip1_j__.r = work[i__2].r, u11_ip1_j__.i = work[
994                                 i__2].i;
995                         i__2 = u11 + i__ + j * work_dim1;
996                         i__3 = cut + i__ + invd * work_dim1;
997                         i__4 = u11 + i__ + j * work_dim1;
998                         z__2.r = work[i__3].r * work[i__4].r - work[i__3].i * 
999                                 work[i__4].i, z__2.i = work[i__3].r * work[
1000                                 i__4].i + work[i__3].i * work[i__4].r;
1001                         i__5 = cut + i__ + (invd + 1) * work_dim1;
1002                         i__6 = u11 + i__ + 1 + j * work_dim1;
1003                         z__3.r = work[i__5].r * work[i__6].r - work[i__5].i * 
1004                                 work[i__6].i, z__3.i = work[i__5].r * work[
1005                                 i__6].i + work[i__5].i * work[i__6].r;
1006                         z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1007                         work[i__2].r = z__1.r, work[i__2].i = z__1.i;
1008                         i__2 = u11 + i__ + 1 + j * work_dim1;
1009                         i__3 = cut + i__ + 1 + invd * work_dim1;
1010                         z__2.r = work[i__3].r * u11_i_j__.r - work[i__3].i * 
1011                                 u11_i_j__.i, z__2.i = work[i__3].r * 
1012                                 u11_i_j__.i + work[i__3].i * u11_i_j__.r;
1013                         i__4 = cut + i__ + 1 + (invd + 1) * work_dim1;
1014                         z__3.r = work[i__4].r * u11_ip1_j__.r - work[i__4].i *
1015                                  u11_ip1_j__.i, z__3.i = work[i__4].r * 
1016                                 u11_ip1_j__.i + work[i__4].i * u11_ip1_j__.r;
1017                         z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1018                         work[i__2].r = z__1.r, work[i__2].i = z__1.i;
1019                     }
1020                     ++i__;
1021                 }
1022                 ++i__;
1023             }
1024
1025 /*           U11**H * invD1 * U11 -> U11 */
1026
1027             i__1 = *n + *nb + 1;
1028             ztrmm_("L", "U", "C", "U", &nnb, &nnb, &c_b1, &a[cut + 1 + (cut + 
1029                     1) * a_dim1], lda, &work[u11 + 1 + work_dim1], &i__1);
1030
1031             i__1 = nnb;
1032             for (i__ = 1; i__ <= i__1; ++i__) {
1033                 i__2 = nnb;
1034                 for (j = i__; j <= i__2; ++j) {
1035                     i__3 = cut + i__ + (cut + j) * a_dim1;
1036                     i__4 = u11 + i__ + j * work_dim1;
1037                     a[i__3].r = work[i__4].r, a[i__3].i = work[i__4].i;
1038                 }
1039             }
1040
1041 /*           U01**H * invD * U01 -> A( CUT+I, CUT+J ) */
1042
1043             i__1 = *n + *nb + 1;
1044             i__2 = *n + *nb + 1;
1045             zgemm_("C", "N", &nnb, &nnb, &cut, &c_b1, &a[(cut + 1) * a_dim1 + 
1046                     1], lda, &work[work_offset], &i__1, &c_b2, &work[u11 + 1 
1047                     + work_dim1], &i__2);
1048
1049 /*           U11 =  U11**H * invD1 * U11 + U01**H * invD * U01 */
1050
1051             i__1 = nnb;
1052             for (i__ = 1; i__ <= i__1; ++i__) {
1053                 i__2 = nnb;
1054                 for (j = i__; j <= i__2; ++j) {
1055                     i__3 = cut + i__ + (cut + j) * a_dim1;
1056                     i__4 = cut + i__ + (cut + j) * a_dim1;
1057                     i__5 = u11 + i__ + j * work_dim1;
1058                     z__1.r = a[i__4].r + work[i__5].r, z__1.i = a[i__4].i + 
1059                             work[i__5].i;
1060                     a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1061                 }
1062             }
1063
1064 /*           U01 =  U00**H * invD0 * U01 */
1065
1066             i__1 = *n + *nb + 1;
1067             ztrmm_("L", uplo, "C", "U", &cut, &nnb, &c_b1, &a[a_offset], lda, 
1068                     &work[work_offset], &i__1);
1069
1070 /*           Update U01 */
1071
1072             i__1 = cut;
1073             for (i__ = 1; i__ <= i__1; ++i__) {
1074                 i__2 = nnb;
1075                 for (j = 1; j <= i__2; ++j) {
1076                     i__3 = i__ + (cut + j) * a_dim1;
1077                     i__4 = i__ + j * work_dim1;
1078                     a[i__3].r = work[i__4].r, a[i__3].i = work[i__4].i;
1079                 }
1080             }
1081
1082 /*           Next Block */
1083
1084         }
1085
1086 /*        Apply PERMUTATIONS P and P**T: */
1087 /*        P * inv(U**H) * inv(D) * inv(U) * P**T. */
1088 /*        Interchange rows and columns I and IPIV(I) in reverse order */
1089 /*        from the formation order of IPIV vector for Upper case. */
1090
1091 /*        ( We can use a loop over IPIV with increment 1, */
1092 /*        since the ABS value of IPIV(I) represents the row (column) */
1093 /*        index of the interchange with row (column) i in both 1x1 */
1094 /*        and 2x2 pivot cases, i.e. we don't need separate code branches */
1095 /*        for 1x1 and 2x2 pivot cases ) */
1096
1097         i__1 = *n;
1098         for (i__ = 1; i__ <= i__1; ++i__) {
1099             ip = (i__2 = ipiv[i__], abs(i__2));
1100             if (ip != i__) {
1101                 if (i__ < ip) {
1102                     zheswapr_(uplo, n, &a[a_offset], lda, &i__, &ip);
1103                 }
1104                 if (i__ > ip) {
1105                     zheswapr_(uplo, n, &a[a_offset], lda, &ip, &i__);
1106                 }
1107             }
1108         }
1109
1110     } else {
1111
1112 /*        Begin Lower */
1113
1114 /*        inv A = P * inv(L**H) * inv(D) * inv(L) * P**T. */
1115
1116         ztrtri_(uplo, "U", n, &a[a_offset], lda, info);
1117
1118 /*        inv(D) and inv(D) * inv(L) */
1119
1120         k = *n;
1121         while(k >= 1) {
1122             if (ipiv[k] > 0) {
1123 /*              1 x 1 diagonal NNB */
1124                 i__1 = k + invd * work_dim1;
1125                 i__2 = k + k * a_dim1;
1126                 d__1 = 1. / a[i__2].r;
1127                 work[i__1].r = d__1, work[i__1].i = 0.;
1128                 i__1 = k + (invd + 1) * work_dim1;
1129                 work[i__1].r = 0., work[i__1].i = 0.;
1130             } else {
1131 /*              2 x 2 diagonal NNB */
1132                 t = z_abs(&work[k - 1 + work_dim1]);
1133                 i__1 = k - 1 + (k - 1) * a_dim1;
1134                 ak = a[i__1].r / t;
1135                 i__1 = k + k * a_dim1;
1136                 akp1 = a[i__1].r / t;
1137                 i__1 = k - 1 + work_dim1;
1138                 z__1.r = work[i__1].r / t, z__1.i = work[i__1].i / t;
1139                 akkp1.r = z__1.r, akkp1.i = z__1.i;
1140                 d__1 = ak * akp1;
1141                 z__2.r = d__1 - 1., z__2.i = 0.;
1142                 z__1.r = t * z__2.r, z__1.i = t * z__2.i;
1143                 d__.r = z__1.r, d__.i = z__1.i;
1144                 i__1 = k - 1 + invd * work_dim1;
1145                 z__2.r = akp1, z__2.i = 0.;
1146                 z_div(&z__1, &z__2, &d__);
1147                 work[i__1].r = z__1.r, work[i__1].i = z__1.i;
1148                 i__1 = k + invd * work_dim1;
1149                 z__2.r = ak, z__2.i = 0.;
1150                 z_div(&z__1, &z__2, &d__);
1151                 work[i__1].r = z__1.r, work[i__1].i = z__1.i;
1152                 i__1 = k + (invd + 1) * work_dim1;
1153                 z__2.r = -akkp1.r, z__2.i = -akkp1.i;
1154                 z_div(&z__1, &z__2, &d__);
1155                 work[i__1].r = z__1.r, work[i__1].i = z__1.i;
1156                 i__1 = k - 1 + (invd + 1) * work_dim1;
1157                 d_cnjg(&z__1, &work[k + (invd + 1) * work_dim1]);
1158                 work[i__1].r = z__1.r, work[i__1].i = z__1.i;
1159                 --k;
1160             }
1161             --k;
1162         }
1163
1164 /*        inv(L**H) = (inv(L))**H */
1165
1166 /*        inv(L**H) * inv(D) * inv(L) */
1167
1168         cut = 0;
1169         while(cut < *n) {
1170             nnb = *nb;
1171             if (cut + nnb > *n) {
1172                 nnb = *n - cut;
1173             } else {
1174                 icount = 0;
1175 /*              count negative elements, */
1176                 i__1 = cut + nnb;
1177                 for (i__ = cut + 1; i__ <= i__1; ++i__) {
1178                     if (ipiv[i__] < 0) {
1179                         ++icount;
1180                     }
1181                 }
1182 /*              need a even number for a clear cut */
1183                 if (icount % 2 == 1) {
1184                     ++nnb;
1185                 }
1186             }
1187
1188 /*           L21 Block */
1189
1190             i__1 = *n - cut - nnb;
1191             for (i__ = 1; i__ <= i__1; ++i__) {
1192                 i__2 = nnb;
1193                 for (j = 1; j <= i__2; ++j) {
1194                     i__3 = i__ + j * work_dim1;
1195                     i__4 = cut + nnb + i__ + (cut + j) * a_dim1;
1196                     work[i__3].r = a[i__4].r, work[i__3].i = a[i__4].i;
1197                 }
1198             }
1199
1200 /*           L11 Block */
1201
1202             i__1 = nnb;
1203             for (i__ = 1; i__ <= i__1; ++i__) {
1204                 i__2 = u11 + i__ + i__ * work_dim1;
1205                 work[i__2].r = 1., work[i__2].i = 0.;
1206                 i__2 = nnb;
1207                 for (j = i__ + 1; j <= i__2; ++j) {
1208                     i__3 = u11 + i__ + j * work_dim1;
1209                     work[i__3].r = 0., work[i__3].i = 0.;
1210                 }
1211                 i__2 = i__ - 1;
1212                 for (j = 1; j <= i__2; ++j) {
1213                     i__3 = u11 + i__ + j * work_dim1;
1214                     i__4 = cut + i__ + (cut + j) * a_dim1;
1215                     work[i__3].r = a[i__4].r, work[i__3].i = a[i__4].i;
1216                 }
1217             }
1218
1219 /*           invD*L21 */
1220
1221             i__ = *n - cut - nnb;
1222             while(i__ >= 1) {
1223                 if (ipiv[cut + nnb + i__] > 0) {
1224                     i__1 = nnb;
1225                     for (j = 1; j <= i__1; ++j) {
1226                         i__2 = i__ + j * work_dim1;
1227                         i__3 = cut + nnb + i__ + invd * work_dim1;
1228                         i__4 = i__ + j * work_dim1;
1229                         z__1.r = work[i__3].r * work[i__4].r - work[i__3].i * 
1230                                 work[i__4].i, z__1.i = work[i__3].r * work[
1231                                 i__4].i + work[i__3].i * work[i__4].r;
1232                         work[i__2].r = z__1.r, work[i__2].i = z__1.i;
1233                     }
1234                 } else {
1235                     i__1 = nnb;
1236                     for (j = 1; j <= i__1; ++j) {
1237                         i__2 = i__ + j * work_dim1;
1238                         u01_i_j__.r = work[i__2].r, u01_i_j__.i = work[i__2]
1239                                 .i;
1240                         i__2 = i__ - 1 + j * work_dim1;
1241                         u01_ip1_j__.r = work[i__2].r, u01_ip1_j__.i = work[
1242                                 i__2].i;
1243                         i__2 = i__ + j * work_dim1;
1244                         i__3 = cut + nnb + i__ + invd * work_dim1;
1245                         z__2.r = work[i__3].r * u01_i_j__.r - work[i__3].i * 
1246                                 u01_i_j__.i, z__2.i = work[i__3].r * 
1247                                 u01_i_j__.i + work[i__3].i * u01_i_j__.r;
1248                         i__4 = cut + nnb + i__ + (invd + 1) * work_dim1;
1249                         z__3.r = work[i__4].r * u01_ip1_j__.r - work[i__4].i *
1250                                  u01_ip1_j__.i, z__3.i = work[i__4].r * 
1251                                 u01_ip1_j__.i + work[i__4].i * u01_ip1_j__.r;
1252                         z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1253                         work[i__2].r = z__1.r, work[i__2].i = z__1.i;
1254                         i__2 = i__ - 1 + j * work_dim1;
1255                         i__3 = cut + nnb + i__ - 1 + (invd + 1) * work_dim1;
1256                         z__2.r = work[i__3].r * u01_i_j__.r - work[i__3].i * 
1257                                 u01_i_j__.i, z__2.i = work[i__3].r * 
1258                                 u01_i_j__.i + work[i__3].i * u01_i_j__.r;
1259                         i__4 = cut + nnb + i__ - 1 + invd * work_dim1;
1260                         z__3.r = work[i__4].r * u01_ip1_j__.r - work[i__4].i *
1261                                  u01_ip1_j__.i, z__3.i = work[i__4].r * 
1262                                 u01_ip1_j__.i + work[i__4].i * u01_ip1_j__.r;
1263                         z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1264                         work[i__2].r = z__1.r, work[i__2].i = z__1.i;
1265                     }
1266                     --i__;
1267                 }
1268                 --i__;
1269             }
1270
1271 /*           invD1*L11 */
1272
1273             i__ = nnb;
1274             while(i__ >= 1) {
1275                 if (ipiv[cut + i__] > 0) {
1276                     i__1 = nnb;
1277                     for (j = 1; j <= i__1; ++j) {
1278                         i__2 = u11 + i__ + j * work_dim1;
1279                         i__3 = cut + i__ + invd * work_dim1;
1280                         i__4 = u11 + i__ + j * work_dim1;
1281                         z__1.r = work[i__3].r * work[i__4].r - work[i__3].i * 
1282                                 work[i__4].i, z__1.i = work[i__3].r * work[
1283                                 i__4].i + work[i__3].i * work[i__4].r;
1284                         work[i__2].r = z__1.r, work[i__2].i = z__1.i;
1285                     }
1286                 } else {
1287                     i__1 = nnb;
1288                     for (j = 1; j <= i__1; ++j) {
1289                         i__2 = u11 + i__ + j * work_dim1;
1290                         u11_i_j__.r = work[i__2].r, u11_i_j__.i = work[i__2]
1291                                 .i;
1292                         i__2 = u11 + i__ - 1 + j * work_dim1;
1293                         u11_ip1_j__.r = work[i__2].r, u11_ip1_j__.i = work[
1294                                 i__2].i;
1295                         i__2 = u11 + i__ + j * work_dim1;
1296                         i__3 = cut + i__ + invd * work_dim1;
1297                         i__4 = u11 + i__ + j * work_dim1;
1298                         z__2.r = work[i__3].r * work[i__4].r - work[i__3].i * 
1299                                 work[i__4].i, z__2.i = work[i__3].r * work[
1300                                 i__4].i + work[i__3].i * work[i__4].r;
1301                         i__5 = cut + i__ + (invd + 1) * work_dim1;
1302                         z__3.r = work[i__5].r * u11_ip1_j__.r - work[i__5].i *
1303                                  u11_ip1_j__.i, z__3.i = work[i__5].r * 
1304                                 u11_ip1_j__.i + work[i__5].i * u11_ip1_j__.r;
1305                         z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1306                         work[i__2].r = z__1.r, work[i__2].i = z__1.i;
1307                         i__2 = u11 + i__ - 1 + j * work_dim1;
1308                         i__3 = cut + i__ - 1 + (invd + 1) * work_dim1;
1309                         z__2.r = work[i__3].r * u11_i_j__.r - work[i__3].i * 
1310                                 u11_i_j__.i, z__2.i = work[i__3].r * 
1311                                 u11_i_j__.i + work[i__3].i * u11_i_j__.r;
1312                         i__4 = cut + i__ - 1 + invd * work_dim1;
1313                         z__3.r = work[i__4].r * u11_ip1_j__.r - work[i__4].i *
1314                                  u11_ip1_j__.i, z__3.i = work[i__4].r * 
1315                                 u11_ip1_j__.i + work[i__4].i * u11_ip1_j__.r;
1316                         z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1317                         work[i__2].r = z__1.r, work[i__2].i = z__1.i;
1318                     }
1319                     --i__;
1320                 }
1321                 --i__;
1322             }
1323
1324 /*           L11**H * invD1 * L11 -> L11 */
1325
1326             i__1 = *n + *nb + 1;
1327             ztrmm_("L", uplo, "C", "U", &nnb, &nnb, &c_b1, &a[cut + 1 + (cut 
1328                     + 1) * a_dim1], lda, &work[u11 + 1 + work_dim1], &i__1);
1329
1330             i__1 = nnb;
1331             for (i__ = 1; i__ <= i__1; ++i__) {
1332                 i__2 = i__;
1333                 for (j = 1; j <= i__2; ++j) {
1334                     i__3 = cut + i__ + (cut + j) * a_dim1;
1335                     i__4 = u11 + i__ + j * work_dim1;
1336                     a[i__3].r = work[i__4].r, a[i__3].i = work[i__4].i;
1337                 }
1338             }
1339
1340             if (cut + nnb < *n) {
1341
1342 /*              L21**H * invD2*L21 -> A( CUT+I, CUT+J ) */
1343
1344                 i__1 = *n - nnb - cut;
1345                 i__2 = *n + *nb + 1;
1346                 i__3 = *n + *nb + 1;
1347                 zgemm_("C", "N", &nnb, &nnb, &i__1, &c_b1, &a[cut + nnb + 1 + 
1348                         (cut + 1) * a_dim1], lda, &work[work_offset], &i__2, &
1349                         c_b2, &work[u11 + 1 + work_dim1], &i__3);
1350
1351 /*              L11 =  L11**H * invD1 * L11 + U01**H * invD * U01 */
1352
1353                 i__1 = nnb;
1354                 for (i__ = 1; i__ <= i__1; ++i__) {
1355                     i__2 = i__;
1356                     for (j = 1; j <= i__2; ++j) {
1357                         i__3 = cut + i__ + (cut + j) * a_dim1;
1358                         i__4 = cut + i__ + (cut + j) * a_dim1;
1359                         i__5 = u11 + i__ + j * work_dim1;
1360                         z__1.r = a[i__4].r + work[i__5].r, z__1.i = a[i__4].i 
1361                                 + work[i__5].i;
1362                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1363                     }
1364                 }
1365
1366 /*              L01 =  L22**H * invD2 * L21 */
1367
1368                 i__1 = *n - nnb - cut;
1369                 i__2 = *n + *nb + 1;
1370                 ztrmm_("L", uplo, "C", "U", &i__1, &nnb, &c_b1, &a[cut + nnb 
1371                         + 1 + (cut + nnb + 1) * a_dim1], lda, &work[
1372                         work_offset], &i__2);
1373
1374 /*              Update L21 */
1375
1376                 i__1 = *n - cut - nnb;
1377                 for (i__ = 1; i__ <= i__1; ++i__) {
1378                     i__2 = nnb;
1379                     for (j = 1; j <= i__2; ++j) {
1380                         i__3 = cut + nnb + i__ + (cut + j) * a_dim1;
1381                         i__4 = i__ + j * work_dim1;
1382                         a[i__3].r = work[i__4].r, a[i__3].i = work[i__4].i;
1383                     }
1384                 }
1385
1386             } else {
1387
1388 /*              L11 =  L11**H * invD1 * L11 */
1389
1390                 i__1 = nnb;
1391                 for (i__ = 1; i__ <= i__1; ++i__) {
1392                     i__2 = i__;
1393                     for (j = 1; j <= i__2; ++j) {
1394                         i__3 = cut + i__ + (cut + j) * a_dim1;
1395                         i__4 = u11 + i__ + j * work_dim1;
1396                         a[i__3].r = work[i__4].r, a[i__3].i = work[i__4].i;
1397                     }
1398                 }
1399             }
1400
1401 /*           Next Block */
1402
1403             cut += nnb;
1404
1405         }
1406
1407 /*        Apply PERMUTATIONS P and P**T: */
1408 /*        P * inv(L**H) * inv(D) * inv(L) * P**T. */
1409 /*        Interchange rows and columns I and IPIV(I) in reverse order */
1410 /*        from the formation order of IPIV vector for Lower case. */
1411
1412 /*        ( We can use a loop over IPIV with increment -1, */
1413 /*        since the ABS value of IPIV(I) represents the row (column) */
1414 /*        index of the interchange with row (column) i in both 1x1 */
1415 /*        and 2x2 pivot cases, i.e. we don't need separate code branches */
1416 /*        for 1x1 and 2x2 pivot cases ) */
1417
1418         for (i__ = *n; i__ >= 1; --i__) {
1419             ip = (i__1 = ipiv[i__], abs(i__1));
1420             if (ip != i__) {
1421                 if (i__ < ip) {
1422                     zheswapr_(uplo, n, &a[a_offset], lda, &i__, &ip);
1423                 }
1424                 if (i__ > ip) {
1425                     zheswapr_(uplo, n, &a[a_offset], lda, &ip, &i__);
1426                 }
1427             }
1428         }
1429
1430     }
1431
1432     return 0;
1433
1434 /*     End of ZHETRI_3X */
1435
1436 } /* zhetri_3x__ */
1437