1 /* ../netlib/cggbal.f -- translated by f2c (version 20100827). You must link the resulting object file with libf2c: on Microsoft Windows system, link with libf2c.lib;
2  on Linux or Unix systems, link with .../path/to/libf2c.a -lm or, if you install libf2c.a in a standard place, with -lf2c -lm -- in that order, at the end of the command line, as in cc *.o -lf2c -lm Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., http://www.netlib.org/f2c/libf2c.zip */
3 #include "FLA_f2c.h" /* Table of constant values */
4 static integer c__1 = 1;
5 static real c_b36 = 10.f;
6 static real c_b72 = .5f;
7 /* > \brief \b CGGBAL */
8 /* =========== DOCUMENTATION =========== */
9 /* Online html documentation available at */
10 /* http://www.netlib.org/lapack/explore-html/ */
11 /* > \htmlonly */
12 /* > Download CGGBAL + dependencies */
13 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cggbal. f"> */
14 /* > [TGZ]</a> */
15 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cggbal. f"> */
16 /* > [ZIP]</a> */
17 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cggbal. f"> */
18 /* > [TXT]</a> */
19 /* > \endhtmlonly */
20 /* Definition: */
21 /* =========== */
22 /* SUBROUTINE CGGBAL( JOB, N, A, LDA, B, LDB, ILO, IHI, LSCALE, */
23 /* RSCALE, WORK, INFO ) */
24 /* .. Scalar Arguments .. */
25 /* CHARACTER JOB */
26 /* INTEGER IHI, ILO, INFO, LDA, LDB, N */
27 /* .. */
28 /* .. Array Arguments .. */
29 /* REAL LSCALE( * ), RSCALE( * ), WORK( * ) */
30 /* COMPLEX A( LDA, * ), B( LDB, * ) */
31 /* .. */
32 /* > \par Purpose: */
33 /* ============= */
34 /* > */
35 /* > \verbatim */
36 /* > */
37 /* > CGGBAL balances a pair of general complex matrices (A,B). This */
38 /* > involves, first, permuting A and B by similarity transformations to */
39 /* > isolate eigenvalues in the first 1 to ILO$-$1 and last IHI+1 to N */
40 /* > elements on the diagonal;
41 and second, applying a diagonal similarity */
42 /* > transformation to rows and columns ILO to IHI to make the rows */
43 /* > and columns as close in norm as possible. Both steps are optional. */
44 /* > */
45 /* > Balancing may reduce the 1-norm of the matrices, and improve the */
46 /* > accuracy of the computed eigenvalues and/or eigenvectors in the */
47 /* > generalized eigenvalue problem A*x = lambda*B*x. */
48 /* > \endverbatim */
49 /* Arguments: */
50 /* ========== */
51 /* > \param[in] JOB */
52 /* > \verbatim */
53 /* > JOB is CHARACTER*1 */
54 /* > Specifies the operations to be performed on A and B: */
55 /* > = 'N': none: simply set ILO = 1, IHI = N, LSCALE(I) = 1.0 */
56 /* > and RSCALE(I) = 1.0 for i=1,...,N;
57 */
58 /* > = 'P': permute only;
59 */
60 /* > = 'S': scale only;
61 */
62 /* > = 'B': both permute and scale. */
63 /* > \endverbatim */
64 /* > */
65 /* > \param[in] N */
66 /* > \verbatim */
67 /* > N is INTEGER */
68 /* > The order of the matrices A and B. N >= 0. */
69 /* > \endverbatim */
70 /* > */
71 /* > \param[in,out] A */
72 /* > \verbatim */
73 /* > A is COMPLEX array, dimension (LDA,N) */
74 /* > On entry, the input matrix A. */
75 /* > On exit, A is overwritten by the balanced matrix. */
76 /* > If JOB = 'N', A is not referenced. */
77 /* > \endverbatim */
78 /* > */
79 /* > \param[in] LDA */
80 /* > \verbatim */
81 /* > LDA is INTEGER */
82 /* > The leading dimension of the array A. LDA >= max(1,N). */
83 /* > \endverbatim */
84 /* > */
85 /* > \param[in,out] B */
86 /* > \verbatim */
87 /* > B is COMPLEX array, dimension (LDB,N) */
88 /* > On entry, the input matrix B. */
89 /* > On exit, B is overwritten by the balanced matrix. */
90 /* > If JOB = 'N', B is not referenced. */
91 /* > \endverbatim */
92 /* > */
93 /* > \param[in] LDB */
94 /* > \verbatim */
95 /* > LDB is INTEGER */
96 /* > The leading dimension of the array B. LDB >= max(1,N). */
97 /* > \endverbatim */
98 /* > */
99 /* > \param[out] ILO */
100 /* > \verbatim */
101 /* > ILO is INTEGER */
102 /* > \endverbatim */
103 /* > */
104 /* > \param[out] IHI */
105 /* > \verbatim */
106 /* > IHI is INTEGER */
107 /* > ILO and IHI are set to integers such that on exit */
108 /* > A(i,j) = 0 and B(i,j) = 0 if i > j and */
109 /* > j = 1,...,ILO-1 or i = IHI+1,...,N. */
110 /* > If JOB = 'N' or 'S', ILO = 1 and IHI = N. */
111 /* > \endverbatim */
112 /* > */
113 /* > \param[out] LSCALE */
114 /* > \verbatim */
115 /* > LSCALE is REAL array, dimension (N) */
116 /* > Details of the permutations and scaling factors applied */
117 /* > to the left side of A and B. If P(j) is the index of the */
118 /* > row interchanged with row j, and D(j) is the scaling factor */
119 /* > applied to row j, then */
120 /* > LSCALE(j) = P(j) for J = 1,...,ILO-1 */
121 /* > = D(j) for J = ILO,...,IHI */
122 /* > = P(j) for J = IHI+1,...,N. */
123 /* > The order in which the interchanges are made is N to IHI+1, */
124 /* > then 1 to ILO-1. */
125 /* > \endverbatim */
126 /* > */
127 /* > \param[out] RSCALE */
128 /* > \verbatim */
129 /* > RSCALE is REAL array, dimension (N) */
130 /* > Details of the permutations and scaling factors applied */
131 /* > to the right side of A and B. If P(j) is the index of the */
132 /* > column interchanged with column j, and D(j) is the scaling */
133 /* > factor applied to column j, then */
134 /* > RSCALE(j) = P(j) for J = 1,...,ILO-1 */
135 /* > = D(j) for J = ILO,...,IHI */
136 /* > = P(j) for J = IHI+1,...,N. */
137 /* > The order in which the interchanges are made is N to IHI+1, */
138 /* > then 1 to ILO-1. */
139 /* > \endverbatim */
140 /* > */
141 /* > \param[out] WORK */
142 /* > \verbatim */
143 /* > WORK is REAL array, dimension (lwork) */
144 /* > lwork must be at least max(1,6*N) when JOB = 'S' or 'B', and */
145 /* > at least 1 when JOB = 'N' or 'P'. */
146 /* > \endverbatim */
147 /* > */
148 /* > \param[out] INFO */
149 /* > \verbatim */
150 /* > INFO is INTEGER */
151 /* > = 0: successful exit */
152 /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
153 /* > \endverbatim */
154 /* Authors: */
155 /* ======== */
156 /* > \author Univ. of Tennessee */
157 /* > \author Univ. of California Berkeley */
158 /* > \author Univ. of Colorado Denver */
159 /* > \author NAG Ltd. */
160 /* > \date November 2011 */
161 /* > \ingroup complexGBcomputational */
162 /* > \par Further Details: */
163 /* ===================== */
164 /* > */
165 /* > \verbatim */
166 /* > */
167 /* > See R.C. WARD, Balancing the generalized eigenvalue problem, */
168 /* > SIAM J. Sci. Stat. Comp. 2 (1981), 141-152. */
169 /* > \endverbatim */
170 /* > */
171 /* ===================================================================== */
172 /* Subroutine */
cggbal_(char * job,integer * n,complex * a,integer * lda,complex * b,integer * ldb,integer * ilo,integer * ihi,real * lscale,real * rscale,real * work,integer * info)173 int cggbal_(char *job, integer *n, complex *a, integer *lda, complex *b, integer *ldb, integer *ilo, integer *ihi, real *lscale, real *rscale, real *work, integer *info)
174 {
175     /* System generated locals */
176     integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3, i__4;
177     real r__1, r__2, r__3;
178     /* Builtin functions */
179     double r_lg10(real *), r_imag(complex *), c_abs(complex *), r_sign(real *, real *), pow_ri(real *, integer *);
180     /* Local variables */
181     integer i__, j, k, l, m;
182     real t;
183     integer jc;
184     real ta, tb, tc;
185     integer ir;
186     real ew;
187     integer it, nr, ip1, jp1, lm1;
188     real cab, rab, ewc, cor, sum;
189     integer nrp2, icab, lcab;
190     real beta, coef;
191     integer irab, lrab;
192     real basl, cmax;
193     extern real sdot_(integer *, real *, integer *, real *, integer *);
194     real coef2, coef5, gamma, alpha;
195     extern logical lsame_(char *, char *);
196     extern /* Subroutine */
197     int sscal_(integer *, real *, real *, integer *);
198     real sfmin;
199     extern /* Subroutine */
200     int cswap_(integer *, complex *, integer *, complex *, integer *);
201     real sfmax;
202     integer iflow, kount;
203     extern /* Subroutine */
204     int saxpy_(integer *, real *, real *, integer *, real *, integer *);
205     real pgamma;
206     extern integer icamax_(integer *, complex *, integer *);
207     extern real slamch_(char *);
208     extern /* Subroutine */
209     int csscal_(integer *, real *, complex *, integer *), xerbla_(char *, integer *);
210     integer lsfmin, lsfmax;
211     /* -- LAPACK computational routine (version 3.4.0) -- */
212     /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
213     /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
214     /* November 2011 */
215     /* .. Scalar Arguments .. */
216     /* .. */
217     /* .. Array Arguments .. */
218     /* .. */
219     /* ===================================================================== */
220     /* .. Parameters .. */
221     /* .. */
222     /* .. Local Scalars .. */
223     /* .. */
224     /* .. External Functions .. */
225     /* .. */
226     /* .. External Subroutines .. */
227     /* .. */
228     /* .. Intrinsic Functions .. */
229     /* .. */
230     /* .. Statement Functions .. */
231     /* .. */
232     /* .. Statement Function definitions .. */
233     /* .. */
234     /* .. Executable Statements .. */
235     /* Test the input parameters */
236     /* Parameter adjustments */
237     a_dim1 = *lda;
238     a_offset = 1 + a_dim1;
239     a -= a_offset;
240     b_dim1 = *ldb;
241     b_offset = 1 + b_dim1;
242     b -= b_offset;
243     --lscale;
244     --rscale;
245     --work;
246     /* Function Body */
247     *info = 0;
248     if (! lsame_(job, "N") && ! lsame_(job, "P") && ! lsame_(job, "S") && ! lsame_(job, "B"))
249     {
250         *info = -1;
251     }
252     else if (*n < 0)
253     {
254         *info = -2;
255     }
256     else if (*lda < max(1,*n))
257     {
258         *info = -4;
259     }
260     else if (*ldb < max(1,*n))
261     {
262         *info = -6;
263     }
264     if (*info != 0)
265     {
266         i__1 = -(*info);
267         xerbla_("CGGBAL", &i__1);
268         return 0;
269     }
270     /* Quick return if possible */
271     if (*n == 0)
272     {
273         *ilo = 1;
274         *ihi = *n;
275         return 0;
276     }
277     if (*n == 1)
278     {
279         *ilo = 1;
280         *ihi = *n;
281         lscale[1] = 1.f;
282         rscale[1] = 1.f;
283         return 0;
284     }
285     if (lsame_(job, "N"))
286     {
287         *ilo = 1;
288         *ihi = *n;
289         i__1 = *n;
290         for (i__ = 1;
291                 i__ <= i__1;
292                 ++i__)
293         {
294             lscale[i__] = 1.f;
295             rscale[i__] = 1.f;
296             /* L10: */
297         }
298         return 0;
299     }
300     k = 1;
301     l = *n;
302     if (lsame_(job, "S"))
303     {
304         goto L190;
305     }
306     goto L30;
307     /* Permute the matrices A and B to isolate the eigenvalues. */
308     /* Find row with one nonzero in columns 1 through L */
309 L20:
310     l = lm1;
311     if (l != 1)
312     {
313         goto L30;
314     }
315     rscale[1] = 1.f;
316     lscale[1] = 1.f;
317     goto L190;
318 L30:
319     lm1 = l - 1;
320     for (i__ = l;
321             i__ >= 1;
322             --i__)
323     {
324         i__1 = lm1;
325         for (j = 1;
326                 j <= i__1;
327                 ++j)
328         {
329             jp1 = j + 1;
330             i__2 = i__ + j * a_dim1;
331             i__3 = i__ + j * b_dim1;
332             if (a[i__2].r != 0.f || a[i__2].i != 0.f || (b[i__3].r != 0.f || b[i__3].i != 0.f))
333             {
334                 goto L50;
335             }
336             /* L40: */
337         }
338         j = l;
339         goto L70;
340 L50:
341         i__1 = l;
342         for (j = jp1;
343                 j <= i__1;
344                 ++j)
345         {
346             i__2 = i__ + j * a_dim1;
347             i__3 = i__ + j * b_dim1;
348             if (a[i__2].r != 0.f || a[i__2].i != 0.f || (b[i__3].r != 0.f || b[i__3].i != 0.f))
349             {
350                 goto L80;
351             }
352             /* L60: */
353         }
354         j = jp1 - 1;
355 L70:
356         m = l;
357         iflow = 1;
358         goto L160;
359 L80:
360         ;
361     }
362     goto L100;
363     /* Find column with one nonzero in rows K through N */
364 L90:
365     ++k;
366 L100:
367     i__1 = l;
368     for (j = k;
369             j <= i__1;
370             ++j)
371     {
372         i__2 = lm1;
373         for (i__ = k;
374                 i__ <= i__2;
375                 ++i__)
376         {
377             ip1 = i__ + 1;
378             i__3 = i__ + j * a_dim1;
379             i__4 = i__ + j * b_dim1;
380             if (a[i__3].r != 0.f || a[i__3].i != 0.f || (b[i__4].r != 0.f || b[i__4].i != 0.f))
381             {
382                 goto L120;
383             }
384             /* L110: */
385         }
386         i__ = l;
387         goto L140;
388 L120:
389         i__2 = l;
390         for (i__ = ip1;
391                 i__ <= i__2;
392                 ++i__)
393         {
394             i__3 = i__ + j * a_dim1;
395             i__4 = i__ + j * b_dim1;
396             if (a[i__3].r != 0.f || a[i__3].i != 0.f || (b[i__4].r != 0.f || b[i__4].i != 0.f))
397             {
398                 goto L150;
399             }
400             /* L130: */
401         }
402         i__ = ip1 - 1;
403 L140:
404         m = k;
405         iflow = 2;
406         goto L160;
407 L150:
408         ;
409     }
410     goto L190;
411     /* Permute rows M and I */
412 L160:
413     lscale[m] = (real) i__;
414     if (i__ == m)
415     {
416         goto L170;
417     }
418     i__1 = *n - k + 1;
419     cswap_(&i__1, &a[i__ + k * a_dim1], lda, &a[m + k * a_dim1], lda);
420     i__1 = *n - k + 1;
421     cswap_(&i__1, &b[i__ + k * b_dim1], ldb, &b[m + k * b_dim1], ldb);
422     /* Permute columns M and J */
423 L170:
424     rscale[m] = (real) j;
425     if (j == m)
426     {
427         goto L180;
428     }
429     cswap_(&l, &a[j * a_dim1 + 1], &c__1, &a[m * a_dim1 + 1], &c__1);
430     cswap_(&l, &b[j * b_dim1 + 1], &c__1, &b[m * b_dim1 + 1], &c__1);
431 L180:
432     switch (iflow)
433     {
434     case 1:
435         goto L20;
436     case 2:
437         goto L90;
438     }
439 L190:
440     *ilo = k;
441     *ihi = l;
442     if (lsame_(job, "P"))
443     {
444         i__1 = *ihi;
445         for (i__ = *ilo;
446                 i__ <= i__1;
447                 ++i__)
448         {
449             lscale[i__] = 1.f;
450             rscale[i__] = 1.f;
451             /* L195: */
452         }
453         return 0;
454     }
455     if (*ilo == *ihi)
456     {
457         return 0;
458     }
459     /* Balance the submatrix in rows ILO to IHI. */
460     nr = *ihi - *ilo + 1;
461     i__1 = *ihi;
462     for (i__ = *ilo;
463             i__ <= i__1;
464             ++i__)
465     {
466         rscale[i__] = 0.f;
467         lscale[i__] = 0.f;
468         work[i__] = 0.f;
469         work[i__ + *n] = 0.f;
470         work[i__ + (*n << 1)] = 0.f;
471         work[i__ + *n * 3] = 0.f;
472         work[i__ + (*n << 2)] = 0.f;
473         work[i__ + *n * 5] = 0.f;
474         /* L200: */
475     }
476     /* Compute right side vector in resulting linear equations */
477     basl = r_lg10(&c_b36);
478     i__1 = *ihi;
479     for (i__ = *ilo;
480             i__ <= i__1;
481             ++i__)
482     {
483         i__2 = *ihi;
484         for (j = *ilo;
485                 j <= i__2;
486                 ++j)
487         {
488             i__3 = i__ + j * a_dim1;
489             if (a[i__3].r == 0.f && a[i__3].i == 0.f)
490             {
491                 ta = 0.f;
492                 goto L210;
493             }
494             i__3 = i__ + j * a_dim1;
495             r__3 = (r__1 = a[i__3].r, f2c_abs(r__1)) + (r__2 = r_imag(&a[i__ + j * a_dim1]), f2c_abs(r__2));
496             ta = r_lg10(&r__3) / basl;
497 L210:
498             i__3 = i__ + j * b_dim1;
499             if (b[i__3].r == 0.f && b[i__3].i == 0.f)
500             {
501                 tb = 0.f;
502                 goto L220;
503             }
504             i__3 = i__ + j * b_dim1;
505             r__3 = (r__1 = b[i__3].r, f2c_abs(r__1)) + (r__2 = r_imag(&b[i__ + j * b_dim1]), f2c_abs(r__2));
506             tb = r_lg10(&r__3) / basl;
507 L220:
508             work[i__ + (*n << 2)] = work[i__ + (*n << 2)] - ta - tb;
509             work[j + *n * 5] = work[j + *n * 5] - ta - tb;
510             /* L230: */
511         }
512         /* L240: */
513     }
514     coef = 1.f / (real) (nr << 1);
515     coef2 = coef * coef;
516     coef5 = coef2 * .5f;
517     nrp2 = nr + 2;
518     beta = 0.f;
519     it = 1;
520     /* Start generalized conjugate gradient iteration */
521 L250:
522     gamma = sdot_(&nr, &work[*ilo + (*n << 2)], &c__1, &work[*ilo + (*n << 2)] , &c__1) + sdot_(&nr, &work[*ilo + *n * 5], &c__1, &work[*ilo + * n * 5], &c__1);
523     ew = 0.f;
524     ewc = 0.f;
525     i__1 = *ihi;
526     for (i__ = *ilo;
527             i__ <= i__1;
528             ++i__)
529     {
530         ew += work[i__ + (*n << 2)];
531         ewc += work[i__ + *n * 5];
532         /* L260: */
533     }
534     /* Computing 2nd power */
535     r__1 = ew;
536     /* Computing 2nd power */
537     r__2 = ewc;
538     /* Computing 2nd power */
539     r__3 = ew - ewc;
540     gamma = coef * gamma - coef2 * (r__1 * r__1 + r__2 * r__2) - coef5 * ( r__3 * r__3);
541     if (gamma == 0.f)
542     {
543         goto L350;
544     }
545     if (it != 1)
546     {
547         beta = gamma / pgamma;
548     }
549     t = coef5 * (ewc - ew * 3.f);
550     tc = coef5 * (ew - ewc * 3.f);
551     sscal_(&nr, &beta, &work[*ilo], &c__1);
552     sscal_(&nr, &beta, &work[*ilo + *n], &c__1);
553     saxpy_(&nr, &coef, &work[*ilo + (*n << 2)], &c__1, &work[*ilo + *n], & c__1);
554     saxpy_(&nr, &coef, &work[*ilo + *n * 5], &c__1, &work[*ilo], &c__1);
555     i__1 = *ihi;
556     for (i__ = *ilo;
557             i__ <= i__1;
558             ++i__)
559     {
560         work[i__] += tc;
561         work[i__ + *n] += t;
562         /* L270: */
563     }
564     /* Apply matrix to vector */
565     i__1 = *ihi;
566     for (i__ = *ilo;
567             i__ <= i__1;
568             ++i__)
569     {
570         kount = 0;
571         sum = 0.f;
572         i__2 = *ihi;
573         for (j = *ilo;
574                 j <= i__2;
575                 ++j)
576         {
577             i__3 = i__ + j * a_dim1;
578             if (a[i__3].r == 0.f && a[i__3].i == 0.f)
579             {
580                 goto L280;
581             }
582             ++kount;
583             sum += work[j];
584 L280:
585             i__3 = i__ + j * b_dim1;
586             if (b[i__3].r == 0.f && b[i__3].i == 0.f)
587             {
588                 goto L290;
589             }
590             ++kount;
591             sum += work[j];
592 L290:
593             ;
594         }
595         work[i__ + (*n << 1)] = (real) kount * work[i__ + *n] + sum;
596         /* L300: */
597     }
598     i__1 = *ihi;
599     for (j = *ilo;
600             j <= i__1;
601             ++j)
602     {
603         kount = 0;
604         sum = 0.f;
605         i__2 = *ihi;
606         for (i__ = *ilo;
607                 i__ <= i__2;
608                 ++i__)
609         {
610             i__3 = i__ + j * a_dim1;
611             if (a[i__3].r == 0.f && a[i__3].i == 0.f)
612             {
613                 goto L310;
614             }
615             ++kount;
616             sum += work[i__ + *n];
617 L310:
618             i__3 = i__ + j * b_dim1;
619             if (b[i__3].r == 0.f && b[i__3].i == 0.f)
620             {
621                 goto L320;
622             }
623             ++kount;
624             sum += work[i__ + *n];
625 L320:
626             ;
627         }
628         work[j + *n * 3] = (real) kount * work[j] + sum;
629         /* L330: */
630     }
631     sum = sdot_(&nr, &work[*ilo + *n], &c__1, &work[*ilo + (*n << 1)], &c__1) + sdot_(&nr, &work[*ilo], &c__1, &work[*ilo + *n * 3], &c__1);
632     alpha = gamma / sum;
633     /* Determine correction to current iteration */
634     cmax = 0.f;
635     i__1 = *ihi;
636     for (i__ = *ilo;
637             i__ <= i__1;
638             ++i__)
639     {
640         cor = alpha * work[i__ + *n];
641         if (f2c_abs(cor) > cmax)
642         {
643             cmax = f2c_abs(cor);
644         }
645         lscale[i__] += cor;
646         cor = alpha * work[i__];
647         if (f2c_abs(cor) > cmax)
648         {
649             cmax = f2c_abs(cor);
650         }
651         rscale[i__] += cor;
652         /* L340: */
653     }
654     if (cmax < .5f)
655     {
656         goto L350;
657     }
658     r__1 = -alpha;
659     saxpy_(&nr, &r__1, &work[*ilo + (*n << 1)], &c__1, &work[*ilo + (*n << 2)] , &c__1);
660     r__1 = -alpha;
661     saxpy_(&nr, &r__1, &work[*ilo + *n * 3], &c__1, &work[*ilo + *n * 5], & c__1);
662     pgamma = gamma;
663     ++it;
664     if (it <= nrp2)
665     {
666         goto L250;
667     }
668     /* End generalized conjugate gradient iteration */
669 L350:
670     sfmin = slamch_("S");
671     sfmax = 1.f / sfmin;
672     lsfmin = (integer) (r_lg10(&sfmin) / basl + 1.f);
673     lsfmax = (integer) (r_lg10(&sfmax) / basl);
674     i__1 = *ihi;
675     for (i__ = *ilo;
676             i__ <= i__1;
677             ++i__)
678     {
679         i__2 = *n - *ilo + 1;
680         irab = icamax_(&i__2, &a[i__ + *ilo * a_dim1], lda);
681         rab = c_abs(&a[i__ + (irab + *ilo - 1) * a_dim1]);
682         i__2 = *n - *ilo + 1;
683         irab = icamax_(&i__2, &b[i__ + *ilo * b_dim1], ldb);
684         /* Computing MAX */
685         r__1 = rab;
686         r__2 = c_abs(&b[i__ + (irab + *ilo - 1) * b_dim1]); // , expr subst
687         rab = max(r__1,r__2);
688         r__1 = rab + sfmin;
689         lrab = (integer) (r_lg10(&r__1) / basl + 1.f);
690         ir = lscale[i__] + r_sign(&c_b72, &lscale[i__]);
691         /* Computing MIN */
692         i__2 = max(ir,lsfmin);
693         i__2 = min(i__2,lsfmax);
694         i__3 = lsfmax - lrab; // ; expr subst
695         ir = min(i__2,i__3);
696         lscale[i__] = pow_ri(&c_b36, &ir);
697         icab = icamax_(ihi, &a[i__ * a_dim1 + 1], &c__1);
698         cab = c_abs(&a[icab + i__ * a_dim1]);
699         icab = icamax_(ihi, &b[i__ * b_dim1 + 1], &c__1);
700         /* Computing MAX */
701         r__1 = cab;
702         r__2 = c_abs(&b[icab + i__ * b_dim1]); // , expr subst
703         cab = max(r__1,r__2);
704         r__1 = cab + sfmin;
705         lcab = (integer) (r_lg10(&r__1) / basl + 1.f);
706         jc = rscale[i__] + r_sign(&c_b72, &rscale[i__]);
707         /* Computing MIN */
708         i__2 = max(jc,lsfmin);
709         i__2 = min(i__2,lsfmax);
710         i__3 = lsfmax - lcab; // ; expr subst
711         jc = min(i__2,i__3);
712         rscale[i__] = pow_ri(&c_b36, &jc);
713         /* L360: */
714     }
715     /* Row scaling of matrices A and B */
716     i__1 = *ihi;
717     for (i__ = *ilo;
718             i__ <= i__1;
719             ++i__)
720     {
721         i__2 = *n - *ilo + 1;
722         csscal_(&i__2, &lscale[i__], &a[i__ + *ilo * a_dim1], lda);
723         i__2 = *n - *ilo + 1;
724         csscal_(&i__2, &lscale[i__], &b[i__ + *ilo * b_dim1], ldb);
725         /* L370: */
726     }
727     /* Column scaling of matrices A and B */
728     i__1 = *ihi;
729     for (j = *ilo;
730             j <= i__1;
731             ++j)
732     {
733         csscal_(ihi, &rscale[j], &a[j * a_dim1 + 1], &c__1);
734         csscal_(ihi, &rscale[j], &b[j * b_dim1 + 1], &c__1);
735         /* L380: */
736     }
737     return 0;
738     /* End of CGGBAL */
739 }
740 /* cggbal_ */
741