source: ThirdParty/mpqc_open/src/lib/math/scmat/svd.c@ b7e5b0

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since b7e5b0 was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 53.5 KB
Line 
1
2#include <stdio.h>
3#include <stdlib.h>
4#include <math.h>
5
6typedef double real;
7typedef int integer;
8
9#define r_sign(a,b) ((*b<0.0)?-fabs(*a):fabs(*a))
10#define min(a,b) (((a)<(b))?(a):(b))
11#define max(a,b) (((a)>(b))?(a):(b))
12#define dmax(a,b) (((a)>(b))?(a):(b))
13
14int
15sing_(double *q, int *lq, int *iq, double *s, double *p,
16 int *lp, int *ip, double *a, int *la, int *m, int *n, double *w);
17
18static int
19bidag2_(double *d, double *b, double *q, int *lq, int *iq,
20 double *p, int *lp, int *ip, double *a, int *la, int *m, int *n);
21static int
22hsr1_(double *a, int *la, int *n);
23static int
24hsr2_(double *a, int *la, int *n);
25static int
26hsr3_(double *a, int *la, int *m, int *n);
27static int
28hsr4_(double *a, int *la, int *m, int *n);
29static int
30hsr5_(double *a, int *la, int *m, int *n);
31static int
32singb_(double *d, int *n, double *u, int *iu,
33 double *q, int *lq, int *mq, int *iq,
34 double *p, int *lp, int *mp, int *ip, double *e, double *f);
35static int
36sng0_(double *q, int *lq, int *m, double *p, int *lp, int *n,
37 int *l, int *j, int *k, double *x, double *y);
38static int
39sft_(double *s, double *a, double *b, double *c,
40 double *d, double *e2, double *e1, double *e0, double *f2, double *f1);
41static int
42sng1_(double *q, int *lq, int *m, double *p,
43 int *lp, int *n, int *l, int *j, int *k, double *x, double *y);
44static int
45scl_(double *d, double *u, int *n, double *q,
46 int *lq, int *mq, double *p, int *lp, int *mp,
47 double *e, double *f, double *b,
48 int *j, int *k, int *jl,
49 int *jr);
50static int
51eig3_(double *ea, double *eb, double *a, double *b, double *y, double *z);
52static int
53sort2_(double *x, double *y, double *w, int *n);
54static int
55fgv_(double *x, double *y, double *s, double *p, double *q,
56 double *a, double *b);
57
58#ifdef TEST
59
60main(int argc, char**argv)
61{
62 int i,j;
63 double *tmp;
64
65 int m = atoi(argv[1]);
66 int n = atoi(argv[2]);
67
68 int l = ((m<n)?m:n);
69
70 double *q = (double*)malloc(sizeof(double)*m*m);
71 double *s = (double*)malloc(sizeof(double)*n);
72 double *p = (double*)malloc(sizeof(double)*n*n);
73 double *a = (double*)malloc(sizeof(double)*n*m);
74 double *w = (double*)malloc(sizeof(double)*3*m);
75
76 int lq = m;
77 int lp = n;
78 int iq = 3;
79 int ip = 3;
80 int la = lq;
81
82 tmp = a;
83 for (i=0; i<m; i++) {
84 for (j=0; j<n; j++) {
85 *tmp++ = drand48() * ((drand48()<0.5)?1.0:-1.0);
86 /* *tmp++ = 1.0; */
87 }
88 }
89
90 printf("A:\n");
91 for (i=0; i<m; i++) {
92 for (j=0; j<n; j++) {
93 printf(" % 6.4f", a[j*m + i]);
94 }
95 printf("\n");
96 }
97
98 sing_(q, &lq, &iq, s, p,
99 &lp, &ip, a, &la, &m, &n, w);
100
101 printf("Q:\n");
102 for (i=0; i<m; i++) {
103 for (j=0; j<m; j++) {
104 printf(" % 6.4f",q[j*m+i]);
105 }
106 printf("\n");
107 }
108
109 printf("P:\n");
110 for (i=0; i<n; i++) {
111 for (j=0; j<n; j++) {
112 printf(" % 6.4f",p[j*n+i]);
113 }
114 printf("\n");
115 }
116
117 printf("S:\n");
118 tmp = s;
119 for (j=0; j<l; j++) {
120 printf(" % 6.4f",*tmp++);
121 }
122 printf("\n");
123
124 printf("QQt:\n");
125 for (i=0; i<m; i++) {
126 for (j=0; j<m; j++) {
127 int k;
128 double tmp = 0.0;
129 for (k=0; k<m; k++) {
130 tmp += q[k*m+i]*q[k*m+j];
131 }
132 printf(" % 6.4f",tmp);
133 }
134 printf("\n");
135 }
136
137 printf("QtQ:\n");
138 for (i=0; i<m; i++) {
139 for (j=0; j<m; j++) {
140 int k;
141 double tmp = 0.0;
142 for (k=0; k<m; k++) {
143 tmp += q[i*m+k]*q[j*m+k];
144 }
145 printf(" % 6.4f",tmp);
146 }
147 printf("\n");
148 }
149
150 printf("PPt:\n");
151 for (i=0; i<n; i++) {
152 for (j=0; j<n; j++) {
153 int k;
154 double tmp = 0.0;
155 for (k=0; k<l; k++) {
156 tmp += p[k*n+i]*p[k*n+j];
157 }
158 printf(" % 6.4f",tmp);
159 }
160 printf("\n");
161 }
162
163 printf("PtP:\n");
164 for (i=0; i<n; i++) {
165 for (j=0; j<n; j++) {
166 int k;
167 double tmp = 0.0;
168 for (k=0; k<l; k++) {
169 tmp += p[i*n+k]*p[j*n+k];
170 }
171 printf(" % 6.4f",tmp);
172 }
173 printf("\n");
174 }
175
176 printf("QSPt:\n");
177 for (i=0; i<m; i++) {
178 for (j=0; j<n; j++) {
179 int k;
180 double tmp = 0.0;
181 for (k=0; k<l; k++) {
182 tmp += q[k*m+i]*s[k]*p[k*n+j];
183 }
184 printf(" % 6.4f",tmp);
185 }
186 printf("\n");
187 }
188
189
190 return 0;
191}
192
193#endif /* TEST */
194
195/* ________________________________________________________ */
196/* | | */
197/* |COMPUTE SINGULAR VALUE DECOMPOSITION OF A GENERAL MATRIX| */
198/* | A = Q TIMES DIAGONAL MATRIX TIMES P TRANSPOSE | */
199/* | | */
200/* | INPUT: | */
201/* | | */
202/* | S --ARRAY WITH AT LEAST N ELEMENTS | */
203/* | | */
204/* | LQ --LEADING (ROW) DIMENSION OF ARRAY Q | */
205/* | | */
206/* | IQ --AN INTEGER WHICH INDICATES WHICH COL- | */
207/* | UMNS OF Q TO COMPUTE (= 0 MEANS NONE, | */
208/* | = 1 MEANS FIRST L, = 2 MEANS LAST M-L, | */
209/* | = 3 MEANS ALL M WHERE L = MIN(M,N)) | */
210/* | | */
211/* | LP --LEADING (ROW) DIMENSION OF ARRAY P | */
212/* | | */
213/* | IP --AN INTEGER (LIKE IQ) WHICH INDICATES | */
214/* | WHICH COLUMNS OF P TO COMPUTE | */
215/* | | */
216/* | A --ARRAY CONTAINING COEFFICIENT MATRIX | */
217/* | | */
218/* | LA --LEADING (ROW) DIMENSION OF ARRAY A | */
219/* | | */
220/* | M --ROW DIMENSION OF MATRIX STORED IN A | */
221/* | | */
222/* | N --COLUMN DIMENSION OF MATRIX STORED IN A | */
223/* | | */
224/* | W --WORK ARRAY(LENGTH AT LEAST MAX(M,3L-1))| */
225/* | | */
226/* | OUTPUT: | */
227/* | | */
228/* | Q --Q FACTOR IN THE SINGULAR VALUE DECOMP. | */
229/* | | */
230/* | S --SINGULAR VALUES IN DECREASING ORDER | */
231/* | | */
232/* | P --P FACTOR IN THE SINGULAR VALUE DECOMP. | */
233/* | | */
234/* | A --THE HOUSEHOLDER VECTORS USED IN THE | */
235/* | REDUCTION PROCESS | */
236/* | | */
237/* | NOTE: | */
238/* | | */
239/* | EITHER P OR Q CAN BE IDENTIFIED WITH A BUT NOT | */
240/* | BOTH. WHEN EITHER P OR Q ARE IDENTIFIED WITH A,| */
241/* | THE HOUSEHOLDER VECTORS IN A ARE DESTROYED. IF | */
242/* | IQ = 2, Q MUST HAVE M COLUMNS EVEN THOUGH THE | */
243/* | OUTPUT ARRAY HAS JUST M-L COLUMNS. SIMILARLY IF| */
244/* | IP = 2, P MUST HAVE N COLUMNS EVEN THOUGH THE | */
245/* | OUTPUT ARRAY HAS JUST N-L COLUMNS. | */
246/* | | */
247/* | BUILTIN FUNCTIONS: MIN0 | */
248/* | PACKAGE SUBROUTINES: BIDAG2,EIG3,FGV,HSR1-HSR5,SCL, | */
249/* | SFT,SINGB,SNG0,SNG1,SORT2 | */
250/* |________________________________________________________| */
251
252int
253sing_(real *q, int *lq, int *iq, double *s, double *p,
254 int *lp, int *ip, double *a, int *la, int *m, int *n, double *w)
255{
256 /* System generated locals */
257 integer a_dim1, a_offset, q_dim1, q_offset, p_dim1, p_offset, i__1;
258
259 /* Local variables */
260 static integer i, l;
261 static integer jl, iu, jr;
262
263 /* Parameter adjustments */
264 --w;
265 a_dim1 = *la;
266 a_offset = a_dim1 + 1;
267 a -= a_offset;
268 p_dim1 = *lp;
269 p_offset = p_dim1 + 1;
270 p -= p_offset;
271 --s;
272 q_dim1 = *lq;
273 q_offset = q_dim1 + 1;
274 q -= q_offset;
275
276 /* Function Body */
277 if (*iq >= 0) {
278 goto L20;
279 }
280L10:
281 fprintf(stderr,"ERROR: INPUT PARAMETER IQ FOR SUBROUTINE SING\n");
282 fprintf(stderr,"EITHER LESS THAN 0 OR GREATER THAN 3\n");
283 abort();
284L20:
285 if (*iq > 3) {
286 goto L10;
287 }
288 jl = 0;
289 if (*iq == 0) {
290 goto L30;
291 }
292 if (*iq == 2) {
293 goto L30;
294 }
295 jl = 1;
296L30:
297 if (*ip >= 0) {
298 goto L50;
299 }
300L40:
301 fprintf(stderr,"ERROR: INPUT PARAMETER IP FOR SUBROUTINE SING\n");
302 fprintf(stderr,"EITHER LESS THAN 0 OR GREATER THAN 3\n");
303 abort();
304L50:
305 if (*ip > 3) {
306 goto L40;
307 }
308 jr = 0;
309 if (*ip == 0) {
310 goto L60;
311 }
312 if (*ip == 2) {
313 goto L60;
314 }
315 jr = 1;
316L60:
317 bidag2_(&s[1], &w[1], &q[q_offset], lq, iq, &p[p_offset], lp, ip, &a[
318 a_offset], la, m, n);
319 l = min(*m,*n);
320 if (l > 1) {
321 goto L80;
322 }
323 if (s[1] >= (double)0.) {
324 return 0;
325 }
326 s[1] = -(double)s[1];
327 if ((real) jl == (double)0.) {
328 return 0;
329 }
330 i__1 = *m;
331 for (i = 1; i <= i__1; ++i) {
332/* L70: */
333 q[i + q_dim1] = -(double)q[i + q_dim1];
334 }
335 return 0;
336L80:
337 iu = 0;
338 if (*m >= *n) {
339 goto L90;
340 }
341 iu = 1;
342L90:
343 singb_(&s[1], &l, &w[1], &iu, &q[q_offset], lq, m, &jl, &p[p_offset], lp,
344 n, &jr, &w[l], &w[l + l]);
345 return 0;
346} /* sing_ */
347
348
349/* ________________________________________________________ */
350/* | | */
351/* | REDUCE A GENERAL MATRIX A TO BIDIAGONAL FORM | */
352/* | A = Q TIMES BIDIAGONAL MATRIX TIMES P TRANSPOSE | */
353/* | | */
354/* | INPUT: | */
355/* | | */
356/* | D --ARRAY WITH AT LEAST N ELEMENTS | */
357/* | | */
358/* | B --ARRAY WITH AT LEAST M ELEMENTS | */
359/* | | */
360/* | LQ --LEADING (ROW) DIMENSION OF ARRAY Q | */
361/* | | */
362/* | IQ --AN INTEGER WHICH INDICATES WHICH COL- | */
363/* | UMNS OF Q TO COMPUTE (= 0 MEANS NONE, | */
364/* | = 1 MEANS FIRST L, = 2 MEANS LAST M-L, | */
365/* | = 3 MEANS ALL M WHERE L = MIN(M,N)) | */
366/* | | */
367/* | LP --LEADING (ROW) DIMENSION OF ARRAY P | */
368/* | | */
369/* | IP --AN INTEGER (LIKE IQ) WHICH INDICATES | */
370/* | WHICH COLUMNS OF P TO COMPUTE | */
371/* | | */
372/* | A --ARRAY CONTAINING COEFFICIENT MATRIX | */
373/* | | */
374/* | LA --LEADING (ROW) DIMENSION OF ARRAY A | */
375/* | | */
376/* | M --ROW DIMENSION OF MATRIX STORED IN A | */
377/* | | */
378/* | N --COLUMN DIMENSION OF MATRIX STORED IN A | */
379/* | | */
380/* | OUTPUT: | */
381/* | | */
382/* | D --DIAGONAL OF BIDIAGONAL FORM | */
383/* | | */
384/* | B --SUPERDIAGONAL (IF M .GE. N) OR SUBDIAG-| */
385/* | ONAL (IF M .LT. N) OF BIDIAGONAL FORM | */
386/* | | */
387/* | A --THE HOUSEHOLDER VECTORS USED IN THE | */
388/* | REDUCTION PROCESS | */
389/* | | */
390/* | Q --THE Q FACTOR IN THE BIDIAGONALIZATION | */
391/* | | */
392/* | P --THE P FACTOR IN THE BIDIAGONALIZATION | */
393/* | | */
394/* | NOTE: | */
395/* | | */
396/* | EITHER P OR Q CAN BE IDENTIFIED WITH A BUT NOT | */
397/* | BOTH. WHEN EITHER P OR Q ARE IDENTIFIED WITH A,| */
398/* | THEN THE HOUSEHOLDER VECTORS IN A ARE DESTROYED| */
399/* | | */
400/* | BUILTIN FUNCTIONS: ABS,MIN0,SQRT | */
401/* | PACKAGE SUBROUTINES: HSR1-HSR5 | */
402/* |________________________________________________________| */
403
404static int
405bidag2_(double *d, double *b, double *q, int *lq, int *iq,
406 double *p, int *lp, int *ip, double *a, int *la, int *m, int *n)
407{
408 /* System generated locals */
409 integer a_dim1, a_offset, q_dim1, q_offset, p_dim1, p_offset, i__1, i__2;
410 real r__1;
411
412 /* Local variables */
413 static integer h, i, j, k, l;
414 static real r, s, t, u;
415 static integer jp, jq;
416
417 /* Parameter adjustments */
418 a_dim1 = *la;
419 a_offset = a_dim1 + 1;
420 a -= a_offset;
421 p_dim1 = *lp;
422 p_offset = p_dim1 + 1;
423 p -= p_offset;
424 q_dim1 = *lq;
425 q_offset = q_dim1 + 1;
426 q -= q_offset;
427 --b;
428 --d;
429
430 /* Function Body */
431 l = min(*m,*n);
432 if (*iq >= 0) {
433 goto L20;
434 }
435L10:
436 fprintf(stderr,"ERROR: INPUT PARAMETER IQ FOR SUBROUTINE BIDAG2\n");
437 fprintf(stderr,"EITHER LESS THAN 0 OR GREATER THAN 3\n");
438 abort();
439L20:
440 if (*iq > 3) {
441 goto L10;
442 }
443 jq = *iq;
444 if (*iq <= 1) {
445 goto L30;
446 }
447 if (*iq == 3) {
448 goto L30;
449 }
450 if (*m == l) {
451 jq = 0;
452 }
453L30:
454 if (*ip >= 0) {
455 goto L50;
456 }
457L40:
458 fprintf(stderr,"ERROR: INPUT PARAMETER IP FOR SUBROUTINE BIDAG2\n");
459 fprintf(stderr,"EITHER LESS THAN 0 OR GREATER THAN 3\n");
460 abort();
461L50:
462 if (*ip > 3) {
463 goto L40;
464 }
465 jp = *ip;
466 if (*ip <= 1) {
467 goto L60;
468 }
469 if (*ip == 3) {
470 goto L60;
471 }
472 if (*n == l) {
473 jp = 0;
474 }
475L60:
476 k = 1;
477 h = 2;
478 if (*m < *n) {
479 goto L330;
480 }
481 if (*m > 1) {
482 goto L70;
483 }
484 d[1] = a[a_dim1 + 1];
485 if (*iq > 0) {
486 q[q_dim1 + 1] = (double)1.;
487 }
488 if (*ip > 0) {
489 p[p_dim1 + 1] = (double)1.;
490 }
491 return 0;
492L70:
493 j = k;
494 k = h;
495 i__1 = *m;
496 for (i = k; i <= i__1; ++i) {
497/* L80: */
498 if (a[i + j * a_dim1] != (double)0.) {
499 goto L110;
500 }
501 }
502 d[j] = a[j + j * a_dim1];
503 a[j + j * a_dim1] = (double)0.;
504 i__1 = *n;
505 for (i = k; i <= i__1; ++i) {
506/* L90: */
507 d[i] = a[j + i * a_dim1];
508 }
509 if (jq == 0) {
510 goto L200;
511 }
512 i__1 = *m;
513 for (i = j; i <= i__1; ++i) {
514/* L100: */
515 q[i + j * q_dim1] = (double)0.;
516 }
517 goto L200;
518L110:
519 t = (r__1 = a[j + j * a_dim1], fabs(r__1));
520 if (t != (double)0.) {
521 u = (double)1. / t;
522 }
523 r = (double)1.;
524 i__1 = *m;
525 for (l = i; l <= i__1; ++l) {
526 s = (r__1 = a[l + j * a_dim1], fabs(r__1));
527 if (s <= t) {
528 goto L120;
529 }
530 u = (double)1. / s;
531/* Computing 2nd power */
532 r__1 = t * u;
533 r = r * (r__1 * r__1) + (double)1.;
534 t = s;
535 goto L130;
536L120:
537/* Computing 2nd power */
538 r__1 = s * u;
539 r += r__1 * r__1;
540L130:
541 ;
542 }
543 s = t * sqrt(r);
544 r = a[j + j * a_dim1];
545 u = (double)1. / sqrt(s * (s + fabs(r)));
546 if (r < (double)0.) {
547 s = -(double)s;
548 }
549 d[j] = -(double)s;
550 a[j + j * a_dim1] = u * (r + s);
551 i__1 = *m;
552 for (i = k; i <= i__1; ++i) {
553/* L140: */
554 a[i + j * a_dim1] *= u;
555 }
556 if (jq == 0) {
557 goto L160;
558 }
559 i__1 = *m;
560 for (i = j; i <= i__1; ++i) {
561/* L150: */
562 q[i + j * q_dim1] = a[i + j * a_dim1];
563 }
564L160:
565 if (k > *n) {
566 goto L620;
567 }
568 i__1 = *n;
569 for (l = k; l <= i__1; ++l) {
570 t = (double)0.;
571 i__2 = *m;
572 for (i = j; i <= i__2; ++i) {
573/* L170: */
574 t += a[i + j * a_dim1] * a[i + l * a_dim1];
575 }
576 a[j + l * a_dim1] -= t * a[j + j * a_dim1];
577 d[l] = a[j + l * a_dim1];
578 i__2 = *m;
579 for (i = k; i <= i__2; ++i) {
580/* L180: */
581 a[i + l * a_dim1] -= t * a[i + j * a_dim1];
582 }
583/* L190: */
584 }
585L200:
586 h = k + 1;
587 if (k < *n) {
588 goto L210;
589 }
590 if (k > *n) {
591 goto L620;
592 }
593 if (*m == *n) {
594 goto L610;
595 }
596 b[j] = a[j + *n * a_dim1];
597 goto L70;
598L210:
599 i__1 = *n;
600 for (i = h; i <= i__1; ++i) {
601/* L220: */
602 if (d[i] != (double)0.) {
603 goto L240;
604 }
605 }
606 b[j] = d[k];
607 a[j + k * a_dim1] = (double)0.;
608 if (*ip == 0) {
609 goto L70;
610 }
611 i__1 = *n;
612 for (i = k; i <= i__1; ++i) {
613/* L230: */
614 p[i + j * p_dim1] = (double)0.;
615 }
616 goto L70;
617L240:
618 t = (r__1 = d[k], fabs(r__1));
619 if (t != (double)0.) {
620 u = (double)1. / t;
621 }
622 r = (double)1.;
623 i__1 = *n;
624 for (l = i; l <= i__1; ++l) {
625 s = (r__1 = d[l], fabs(r__1));
626 if (s <= t) {
627 goto L250;
628 }
629 u = (double)1. / s;
630/* Computing 2nd power */
631 r__1 = t * u;
632 r = r * (r__1 * r__1) + (double)1.;
633 t = s;
634 goto L260;
635L250:
636/* Computing 2nd power */
637 r__1 = s * u;
638 r += r__1 * r__1;
639L260:
640 ;
641 }
642 s = t * sqrt(r);
643 r = d[k];
644 u = (double)1. / sqrt(s * (s + fabs(r)));
645 if (r < (double)0.) {
646 s = -(double)s;
647 }
648 d[k] = u * (r + s);
649 i__1 = *n;
650 for (i = h; i <= i__1; ++i) {
651/* L270: */
652 d[i] *= u;
653 }
654 if (*ip == 0) {
655 goto L290;
656 }
657 i__1 = *n;
658 for (i = k; i <= i__1; ++i) {
659/* L280: */
660 p[i + j * p_dim1] = d[i];
661 }
662L290:
663 b[j] = -(double)s;
664 i__1 = *m;
665 for (i = k; i <= i__1; ++i) {
666/* L300: */
667 b[i] = (double)0.;
668 }
669 i__1 = *n;
670 for (l = k; l <= i__1; ++l) {
671 t = d[l];
672 a[j + l * a_dim1] = t;
673 i__2 = *m;
674 for (i = k; i <= i__2; ++i) {
675/* L310: */
676 b[i] += t * a[i + l * a_dim1];
677 }
678 }
679 i__2 = *n;
680 for (l = k; l <= i__2; ++l) {
681 t = d[l];
682 i__1 = *m;
683 for (i = k; i <= i__1; ++i) {
684/* L320: */
685 a[i + l * a_dim1] -= t * b[i];
686 }
687 }
688 goto L70;
689L330:
690 i__1 = *n;
691 for (i = k; i <= i__1; ++i) {
692/* L340: */
693 d[i] = a[k + i * a_dim1];
694 }
695L350:
696 j = k;
697 k = h;
698 i__1 = *n;
699 for (i = k; i <= i__1; ++i) {
700/* L360: */
701 if (d[i] != (double)0.) {
702 goto L370;
703 }
704 }
705 u = d[j];
706 d[j] = (double)0.;
707 goto L440;
708L370:
709 t = (r__1 = d[j], fabs(r__1));
710 if (t != (double)0.) {
711 u = (double)1. / t;
712 }
713 r = (double)1.;
714 i__1 = *n;
715 for (l = i; l <= i__1; ++l) {
716 s = (r__1 = d[l], fabs(r__1));
717 if (s <= t) {
718 goto L380;
719 }
720 u = (double)1. / s;
721/* Computing 2nd power */
722 r__1 = t * u;
723 r = r * (r__1 * r__1) + (double)1.;
724 t = s;
725 goto L390;
726L380:
727/* Computing 2nd power */
728 r__1 = s * u;
729 r += r__1 * r__1;
730L390:
731 ;
732 }
733 s = t * sqrt(r);
734 r = d[j];
735 u = (double)1. / sqrt(s * (s + fabs(r)));
736 if (r < (double)0.) {
737 s = -(double)s;
738 }
739 d[j] = u * (r + s);
740 i__1 = *n;
741 for (i = k; i <= i__1; ++i) {
742/* L400: */
743 d[i] *= u;
744 }
745 u = -(double)s;
746 if (k > *m) {
747 goto L470;
748 }
749 i__1 = *m;
750 for (i = k; i <= i__1; ++i) {
751/* L410: */
752 b[i] = (double)0.;
753 }
754 i__1 = *n;
755 for (l = j; l <= i__1; ++l) {
756 t = d[l];
757 a[j + l * a_dim1] = t;
758 i__2 = *m;
759 for (i = k; i <= i__2; ++i) {
760/* L420: */
761 b[i] += t * a[i + l * a_dim1];
762 }
763 }
764 i__2 = *n;
765 for (l = j; l <= i__2; ++l) {
766 t = d[l];
767 i__1 = *m;
768 for (i = k; i <= i__1; ++i) {
769/* L430: */
770 a[i + l * a_dim1] -= t * b[i];
771 }
772 }
773L440:
774 h = k + 1;
775 if (*ip == 0) {
776 goto L460;
777 }
778 i__1 = *n;
779 for (i = j; i <= i__1; ++i) {
780/* L450: */
781 p[i + j * p_dim1] = d[i];
782 }
783L460:
784 d[j] = u;
785 if (k < *m) {
786 goto L490;
787 }
788 if (k > *m) {
789 goto L620;
790 }
791 b[j] = a[*m + j * a_dim1];
792 goto L330;
793L470:
794 i__1 = *n;
795 for (i = j; i <= i__1; ++i) {
796/* L480: */
797 a[j + i * a_dim1] = d[i];
798 }
799 goto L440;
800L490:
801 i__1 = *m;
802 for (i = h; i <= i__1; ++i) {
803/* L500: */
804 if (a[i + j * a_dim1] != (double)0.) {
805 goto L520;
806 }
807 }
808 b[j] = a[k + j * a_dim1];
809 a[k + j * a_dim1] = (double)0.;
810 if (*iq == 0) {
811 goto L330;
812 }
813 i__1 = *m;
814 for (i = k; i <= i__1; ++i) {
815/* L510: */
816 q[i + j * q_dim1] = (double)0.;
817 }
818 goto L330;
819L520:
820 t = (r__1 = a[k + j * a_dim1], fabs(r__1));
821 if (t != (double)0.) {
822 u = (double)1. / t;
823 }
824 r = (double)1.;
825 i__1 = *m;
826 for (l = i; l <= i__1; ++l) {
827 s = (r__1 = a[l + j * a_dim1], fabs(r__1));
828 if (s <= t) {
829 goto L530;
830 }
831 u = (double)1. / s;
832/* Computing 2nd power */
833 r__1 = t * u;
834 r = r * (r__1 * r__1) + (double)1.;
835 t = s;
836 goto L540;
837L530:
838/* Computing 2nd power */
839 r__1 = s * u;
840 r += r__1 * r__1;
841L540:
842 ;
843 }
844 s = t * sqrt(r);
845 r = a[k + j * a_dim1];
846 u = (double)1. / sqrt(s * (s + fabs(r)));
847 if (r < (double)0.) {
848 s = -(double)s;
849 }
850 b[j] = -(double)s;
851 a[k + j * a_dim1] = u * (r + s);
852 i__1 = *m;
853 for (i = h; i <= i__1; ++i) {
854/* L550: */
855 a[i + j * a_dim1] *= u;
856 }
857 if (*iq == 0) {
858 goto L570;
859 }
860 i__1 = *m;
861 for (i = k; i <= i__1; ++i) {
862/* L560: */
863 q[i + j * q_dim1] = a[i + j * a_dim1];
864 }
865L570:
866 i__1 = *n;
867 for (l = k; l <= i__1; ++l) {
868 t = (double)0.;
869 i__2 = *m;
870 for (i = k; i <= i__2; ++i) {
871/* L580: */
872 t += a[i + j * a_dim1] * a[i + l * a_dim1];
873 }
874 a[k + l * a_dim1] -= t * a[k + j * a_dim1];
875 d[l] = a[k + l * a_dim1];
876 i__2 = *m;
877 for (i = h; i <= i__2; ++i) {
878/* L590: */
879 a[i + l * a_dim1] -= t * a[i + j * a_dim1];
880 }
881/* L600: */
882 }
883 goto L350;
884L610:
885 d[*n] = a[*n + *n * a_dim1];
886 b[*n - 1] = a[*n - 1 + *n * a_dim1];
887L620:
888 if (jq == 0) {
889 goto L650;
890 }
891 if (*n > *m) {
892 goto L640;
893 }
894 if (*n == *m) {
895 goto L630;
896 }
897 if (jq == 1) {
898 hsr3_(&q[q_offset], lq, m, n);
899 }
900 if (jq == 2) {
901 hsr4_(&q[q_offset], lq, m, n);
902 }
903 if (jq == 3) {
904 hsr5_(&q[q_offset], lq, m, n);
905 }
906 goto L650;
907L630:
908 hsr2_(&q[q_offset], lq, m);
909 goto L650;
910L640:
911 hsr1_(&q[q_offset], lq, m);
912L650:
913 if (jp == 0) {
914 return 0;
915 }
916 if (*n <= *m) {
917 goto L660;
918 }
919 if (jp == 1) {
920 hsr3_(&p[p_offset], lp, n, m);
921 }
922 if (jp == 2) {
923 hsr4_(&p[p_offset], lp, n, m);
924 }
925 if (jp == 3) {
926 hsr5_(&p[p_offset], lp, n, m);
927 }
928 return 0;
929L660:
930 hsr1_(&p[p_offset], lp, n);
931 return 0;
932} /* bidag2_ */
933
934
935static int
936hsr1_(double *a, int *la, int *n)
937{
938 /* System generated locals */
939 integer a_dim1, a_offset, i__1;
940
941 /* Local variables */
942 static integer i, j, k, l, m;
943 static real s;
944
945 /* Parameter adjustments */
946 a_dim1 = *la;
947 a_offset = a_dim1 + 1;
948 a -= a_offset;
949
950 /* Function Body */
951 a[a_dim1 + 1] = (double)1.;
952 if (*n == 1) {
953 return 0;
954 }
955 a[(a_dim1 << 1) + 1] = (double)0.;
956 if (*n > 2) {
957 goto L10;
958 }
959 a[a_dim1 + 2] = (double)0.;
960 a[(a_dim1 << 1) + 2] = (double)1.;
961 return 0;
962L10:
963 l = *n - 2;
964 m = *n - 1;
965 k = *n;
966 s = a[k + l * a_dim1];
967 a[*n + *n * a_dim1] = (double)1. - s * a[*n + l * a_dim1];
968 a[m + *n * a_dim1] = -(double)s * a[m + l * a_dim1];
969L20:
970 j = m;
971 m = l;
972 --l;
973 if (l == 0) {
974 goto L50;
975 }
976 s = (double)0.;
977 i__1 = *n;
978 for (i = j; i <= i__1; ++i) {
979/* L30: */
980 s += a[i + l * a_dim1] * a[i + k * a_dim1];
981 }
982 a[m + k * a_dim1] = -(double)s * a[m + l * a_dim1];
983 i__1 = *n;
984 for (i = j; i <= i__1; ++i) {
985/* L40: */
986 a[i + k * a_dim1] -= s * a[i + l * a_dim1];
987 }
988 goto L20;
989L50:
990 a[k * a_dim1 + 1] = (double)0.;
991 --k;
992 m = k;
993 l = k - 1;
994 s = -(double)a[m + l * a_dim1];
995 i__1 = *n;
996 for (i = k; i <= i__1; ++i) {
997/* L60: */
998 a[i + k * a_dim1] = s * a[i + l * a_dim1];
999 }
1000 a[k + k * a_dim1] += (double)1.;
1001 if (l > 1) {
1002 goto L20;
1003 }
1004 i__1 = *n;
1005 for (i = 2; i <= i__1; ++i) {
1006/* L70: */
1007 a[i + a_dim1] = (double)0.;
1008 }
1009 return 0;
1010} /* hsr1_ */
1011
1012static int
1013hsr2_(double *a, int *la, int *n)
1014{
1015 /* System generated locals */
1016 integer a_dim1, a_offset, i__1;
1017
1018 /* Local variables */
1019 static integer i, j, k, l, m;
1020 static real s;
1021
1022 /* Parameter adjustments */
1023 a_dim1 = *la;
1024 a_offset = a_dim1 + 1;
1025 a -= a_offset;
1026
1027 /* Function Body */
1028 if (*n > 1) {
1029 goto L10;
1030 }
1031 a[a_dim1 + 1] = (double)1.;
1032 return 0;
1033L10:
1034 l = *n - 2;
1035 m = *n - 1;
1036 k = *n;
1037 s = a[*n + m * a_dim1];
1038 a[*n + *n * a_dim1] = (double)1. - s * a[*n + m * a_dim1];
1039 a[m + *n * a_dim1] = -(double)s * a[m + m * a_dim1];
1040L20:
1041 j = m;
1042 --m;
1043 if (m == 0) {
1044 goto L50;
1045 }
1046 s = (double)0.;
1047 i__1 = *n;
1048 for (i = j; i <= i__1; ++i) {
1049/* L30: */
1050 s += a[i + m * a_dim1] * a[i + k * a_dim1];
1051 }
1052 a[m + k * a_dim1] = -(double)s * a[m + m * a_dim1];
1053 i__1 = *n;
1054 for (i = j; i <= i__1; ++i) {
1055/* L40: */
1056 a[i + k * a_dim1] -= s * a[i + m * a_dim1];
1057 }
1058 goto L20;
1059L50:
1060 --k;
1061 m = k;
1062 s = -(double)a[k + k * a_dim1];
1063 i__1 = *n;
1064 for (i = k; i <= i__1; ++i) {
1065/* L60: */
1066 a[i + k * a_dim1] = s * a[i + k * a_dim1];
1067 }
1068 a[k + k * a_dim1] += (double)1.;
1069 if (k > 1) {
1070 goto L20;
1071 }
1072 return 0;
1073} /* hsr2_ */
1074
1075static int
1076hsr3_(double *a, int *la, int *m, int *n)
1077{
1078 /* System generated locals */
1079 integer a_dim1, a_offset, i__1;
1080
1081 /* Local variables */
1082 static integer i, j, k, l;
1083 static real s;
1084
1085 /* Parameter adjustments */
1086 a_dim1 = *la;
1087 a_offset = a_dim1 + 1;
1088 a -= a_offset;
1089
1090 /* Function Body */
1091 k = *n;
1092 if (*m >= *n) {
1093 goto L10;
1094 }
1095 fprintf(stderr,"ERROR: ARGUMENT M MUST BE .GE. N IN SUBROUTINE HSR3\n");
1096 abort();
1097L10:
1098 s = -(double)a[k + k * a_dim1];
1099 i__1 = *m;
1100 for (i = k; i <= i__1; ++i) {
1101/* L20: */
1102 a[i + k * a_dim1] = s * a[i + k * a_dim1];
1103 }
1104 a[k + k * a_dim1] += (double)1.;
1105 if (k == 1) {
1106 return 0;
1107 }
1108 l = k;
1109L30:
1110 j = l;
1111 --l;
1112 if (l == 0) {
1113 goto L60;
1114 }
1115 s = (double)0.;
1116 i__1 = *m;
1117 for (i = j; i <= i__1; ++i) {
1118/* L40: */
1119 s += a[i + l * a_dim1] * a[i + k * a_dim1];
1120 }
1121 a[l + k * a_dim1] = -(double)s * a[l + l * a_dim1];
1122 i__1 = *m;
1123 for (i = j; i <= i__1; ++i) {
1124/* L50: */
1125 a[i + k * a_dim1] -= s * a[i + l * a_dim1];
1126 }
1127 goto L30;
1128L60:
1129 --k;
1130 goto L10;
1131} /* hsr3_ */
1132
1133static int
1134hsr4_(double *a, int *la, int *m, int *n)
1135{
1136 /* System generated locals */
1137 integer a_dim1, a_offset, i__1, i__2;
1138
1139 /* Local variables */
1140 static integer i, j, k, l;
1141 static real s;
1142
1143 /* Parameter adjustments */
1144 a_dim1 = *la;
1145 a_offset = a_dim1 + 1;
1146 a -= a_offset;
1147
1148 /* Function Body */
1149 k = *m;
1150 if (*m > *n) {
1151 goto L10;
1152 }
1153 fprintf(stderr,"ERROR: ARGUMENT M MUST BE .GE. N IN SUBROUTINE HSR4\n");
1154 abort();
1155L10:
1156 s = -(double)a[k + *n * a_dim1];
1157 i__1 = *m;
1158 for (i = *n; i <= i__1; ++i) {
1159/* L20: */
1160 a[i + k * a_dim1] = s * a[i + *n * a_dim1];
1161 }
1162 a[k + k * a_dim1] += (double)1.;
1163 l = *n;
1164L30:
1165 j = l;
1166 --l;
1167 if (l == 0) {
1168 goto L60;
1169 }
1170 s = (double)0.;
1171 i__1 = *m;
1172 for (i = j; i <= i__1; ++i) {
1173/* L40: */
1174 s += a[i + l * a_dim1] * a[i + k * a_dim1];
1175 }
1176 a[l + k * a_dim1] = -(double)s * a[l + l * a_dim1];
1177 i__1 = *m;
1178 for (i = j; i <= i__1; ++i) {
1179/* L50: */
1180 a[i + k * a_dim1] -= s * a[i + l * a_dim1];
1181 }
1182 goto L30;
1183L60:
1184 --k;
1185 if (k > *n) {
1186 goto L10;
1187 }
1188 k = *m - *n;
1189 i__1 = k;
1190 for (j = 1; j <= i__1; ++j) {
1191 i__2 = *m;
1192 for (i = 1; i <= i__2; ++i) {
1193/* L70: */
1194 a[i + j * a_dim1] = a[i + (j + *n) * a_dim1];
1195 }
1196 }
1197 return 0;
1198} /* hsr4_ */
1199
1200/* ________________________________________________________ */
1201/* | | */
1202/* | PACKAGE SUBROUTINES: HSR3 | */
1203/* |________________________________________________________| */
1204
1205static int
1206hsr5_(double *a, int *la, int *m, int *n)
1207{
1208 /* System generated locals */
1209 integer a_dim1, a_offset, i__1;
1210
1211 /* Local variables */
1212 static integer i, j, k, l;
1213 static real s;
1214
1215 /* Parameter adjustments */
1216 a_dim1 = *la;
1217 a_offset = a_dim1 + 1;
1218 a -= a_offset;
1219
1220 /* Function Body */
1221 if (*m >= *n) {
1222 goto L10;
1223 }
1224 fprintf(stderr,"ERROR: ARGUMENT M MUST BE .GE. N IN SUBROUTINE HSR5\n");
1225 abort();
1226L10:
1227 if (*m == *n) {
1228 goto L90;
1229 }
1230 k = *m;
1231L20:
1232 s = -(double)a[k + *n * a_dim1];
1233 i__1 = *m;
1234 for (i = *n; i <= i__1; ++i) {
1235/* L30: */
1236 a[i + k * a_dim1] = s * a[i + *n * a_dim1];
1237 }
1238 a[k + k * a_dim1] += (double)1.;
1239 l = *n;
1240L40:
1241 j = l;
1242 --l;
1243 if (l == 0) {
1244 goto L70;
1245 }
1246 s = (double)0.;
1247 i__1 = *m;
1248 for (i = j; i <= i__1; ++i) {
1249/* L50: */
1250 s += a[i + l * a_dim1] * a[i + k * a_dim1];
1251 }
1252 a[l + k * a_dim1] = -(double)s * a[l + l * a_dim1];
1253 i__1 = *m;
1254 for (i = j; i <= i__1; ++i) {
1255/* L60: */
1256 a[i + k * a_dim1] -= s * a[i + l * a_dim1];
1257 }
1258 goto L40;
1259L70:
1260 --k;
1261 if (k > *n) {
1262 goto L20;
1263 }
1264L90:
1265 hsr3_(&a[a_offset], la, m, n);
1266 return 0;
1267} /* hsr5_ */
1268
1269/* ________________________________________________________ */
1270/* | | */
1271/* | COMPUTE SINGULAR VALUE DECOMPOSITION OF A BIDIAGONAL | */
1272/* | MATRIX: A = Q TIMES DIAGONAL MATRIX TIMES P TRANSPOSE | */
1273/* | | */
1274/* | INPUT: | */
1275/* | | */
1276/* | D --DIAGONAL | */
1277/* | | */
1278/* | N --DIMENSION OF BIDIAGONAL MATRIX | */
1279/* | | */
1280/* | U --OFF DIAGONAL | */
1281/* | | */
1282/* | IU --= 0 IF U IS SUPERDIAGONAL AND = 1 IF | */
1283/* | U IS SUBDIAGONAL | */
1284/* | | */
1285/* | Q --EITHER A SEGMENT OF AN IDENTITY MATRIX | */
1286/* | OR A SEGMENT OF THE MATRIX USED TO | */
1287/* | BIDIAGONALIZE THE COEFFICIENT MATRIX | */
1288/* | | */
1289/* | LQ --LEADING (ROW) DIMENSION OF ARRAY Q | */
1290/* | | */
1291/* | MQ --NUMBER OF MATRIX ELEMENTS CONTAINED IN | */
1292/* | EACH COLUMN OF Q | */
1293/* | | */
1294/* | IQ --AN INTEGER WHICH INDICATES WHETHER | */
1295/* | COLUMNS OF Q TO BE PROCESSED (= 0 MEANS| */
1296/* | NO AND = 1 MEANS YES) | */
1297/* | | */
1298/* | LP --LEADING (ROW) DIMENSION OF ARRAY P | */
1299/* | | */
1300/* | MP --NUMBER OF MATRIX ELEMENTS CONTAINED IN | */
1301/* | EACH COLUMN OF P | */
1302/* | | */
1303/* | IP --AN INTEGER DEFINED LIKE IQ | */
1304/* | | */
1305/* | E --WORK ARRAY WITH AT LEAST N ELEMENTS | */
1306/* | | */
1307/* | F --WORK ARRAY WITH AT LEAST N ELEMENTS | */
1308/* | | */
1309/* | OUTPUT: | */
1310/* | | */
1311/* | Q --Q FACTOR IN THE SINGULAR VALUE DECOMP. | */
1312/* | | */
1313/* | D --SINGULAR VALUES IN DECREASING ORDER | */
1314/* | | */
1315/* | P --P FACTOR IN THE SINGULAR VALUE DECOMP. | */
1316/* | | */
1317/* | BUILTIN FUNCTIONS: ABS,AMAX1,SIGN,SQRT | */
1318/* | PACKAGE SUBROUTINES: EIG3,FGV,HSR1-HSR5,SCL,SFT, | */
1319/* | SNG0,SNG1,SORT2 | */
1320/* |________________________________________________________| */
1321
1322static int
1323singb_(double *d, int *n, double *u, int *iu,
1324 double *q, int *lq, int *mq, int *iq,
1325 double *p, int *lp, int *mp, int *ip, double *e, double *f)
1326{
1327 int one = 1;
1328
1329 /* System generated locals */
1330 integer q_dim1, q_offset, p_dim1, p_offset, i__1, i__2;
1331 real r__1, r__2;
1332
1333 /* Local variables */
1334 static real b, c;
1335 static integer g, h, i, j, k, l, m;
1336 static real r, s, t, v, w, x, y, z;
1337 static integer j0, k2, l1;
1338 static real t0, t1, t2, t3;
1339 static integer id, jl, ll, jr, ns;
1340
1341 /* Parameter adjustments */
1342 --f;
1343 --e;
1344 p_dim1 = *lp;
1345 p_offset = p_dim1 + 1;
1346 p -= p_offset;
1347 q_dim1 = *lq;
1348 q_offset = q_dim1 + 1;
1349 q -= q_offset;
1350 --u;
1351 --d;
1352
1353 /* Function Body */
1354 if (*n > 1) {
1355 goto L10;
1356 }
1357 if (*iq == 1) {
1358 q[q_dim1 + 1] = (double)1.;
1359 }
1360 if (*ip == 1) {
1361 p[p_dim1 + 1] = (double)1.;
1362 }
1363 if (d[1] >= (double)0.) {
1364 return 0;
1365 }
1366 d[1] = -(double)d[1];
1367 if (*iq == 1) {
1368 q[q_dim1 + 1] = (double)-1.;
1369 }
1370 return 0;
1371L10:
1372 jl = *iq;
1373 if (jl == 0) {
1374 jl = 3;
1375 }
1376 if (jl != 3) {
1377 jl = 1;
1378 }
1379 jr = *ip;
1380 if (jr == 0) {
1381 jr = 3;
1382 }
1383 if (jr != 3) {
1384 jr = 2;
1385 }
1386 if (*iu == 0) {
1387 goto L20;
1388 }
1389 i = jl;
1390 jl = jr;
1391 jr = i;
1392L20:
1393 j = 0;
1394 l = *n - 1;
1395 k2 = *n - 2;
1396 i__1 = l;
1397 for (i = 1; i <= i__1; ++i) {
1398 e[i] = (double)1.;
1399 f[i] = (double)1.;
1400 if (u[i] == (double)0.) {
1401 j = i;
1402 }
1403/* L30: */
1404 if (d[i] == (double)0.) {
1405 j = i;
1406 }
1407 }
1408 e[*n] = (double)1.;
1409 f[*n] = (double)1.;
1410 b = (double)3.5527136788005009e-15;
1411 t = (double)1.;
1412L40:
1413 t *= (double).5;
1414 s = t + (double)1.;
1415 if (s > (double)1.) {
1416 goto L40;
1417 }
1418 t0 = (double)1. / (t + t);
1419/* Computing 2nd power */
1420 r__1 = t + t;
1421 t2 = r__1 * r__1;
1422 ns = *n * 50;
1423 l1 = 0;
1424 k = *n;
1425 ll = 0;
1426 goto L70;
1427L50:
1428 j = 0;
1429 i__1 = l;
1430 for (i = 1; i <= i__1; ++i) {
1431 if (u[i] == (double)0.) {
1432 j = i;
1433 }
1434/* L60: */
1435 if (d[i] == (double)0.) {
1436 j = i;
1437 }
1438 }
1439L70:
1440 if (j == 0) {
1441 goto L140;
1442 }
1443 if (u[j] == (double)0.) {
1444 goto L140;
1445 }
1446/* ------------------------------- */
1447/* |*** ZERO DIAGONAL ELEMENT ***| */
1448/* ------------------------------- */
1449 i = j;
1450 v = u[j];
1451 u[j] = (double)0.;
1452 s = -(double)v * (r__1 = e[j], fabs(r__1));
1453/* --------------------------- */
1454/* |*** PROCESS LEFT SIDE ***| */
1455/* --------------------------- */
1456L80:
1457 h = i;
1458 ++i;
1459 r = (r__1 = e[i], fabs(r__1)) * d[i];
1460 fgv_(&x, &y, &t, &r, &s, &e[j], &e[i]);
1461 if (t == (double)1.) {
1462 goto L90;
1463 }
1464 d[i] -= y * v;
1465 sng0_(&q[q_offset], lq, mq, &p[p_offset], lp, mp, &jl, &j, &i, &x, &y);
1466 if (i == k) {
1467 goto L100;
1468 }
1469 v = x * u[i];
1470 s = -(double)v * (r__1 = e[j], fabs(r__1));
1471 goto L80;
1472L90:
1473 d[i] = d[i] * y - v;
1474 sng1_(&q[q_offset], lq, mq, &p[p_offset], lp, mp, &jl, &j, &i, &x, &y);
1475 if (i == k) {
1476 goto L100;
1477 }
1478 v = u[i];
1479 u[i] = v * y;
1480 s = -(double)v * (r__1 = e[j], fabs(r__1));
1481 goto L80;
1482L100:
1483 if (j == 1) {
1484 goto L130;
1485 }
1486 i = j - 1;
1487 s = u[i];
1488 u[i] = (double)0.;
1489/* ---------------------------- */
1490/* |*** PROCESS RIGHT SIDE ***| */
1491/* ---------------------------- */
1492L110:
1493 h = i;
1494 --i;
1495 r = d[h];
1496 fgv_(&x, &y, &t, &r, &s, &f[h], &f[j]);
1497 if (t == (double)1.) {
1498 goto L120;
1499 }
1500 d[h] = r + x * s;
1501 sng0_(&q[q_offset], lq, mq, &p[p_offset], lp, mp, &jr, &h, &j, &x, &y);
1502 if (h == 1) {
1503 goto L130;
1504 }
1505 s = -(double)y * u[i];
1506 goto L110;
1507L120:
1508 d[h] = x * r + s;
1509 sng1_(&q[q_offset], lq, mq, &p[p_offset], lp, mp, &jr, &h, &j, &x, &y);
1510 if (h == 1) {
1511 goto L130;
1512 }
1513 s = -(double)u[i];
1514 u[i] = x * u[i];
1515 goto L110;
1516L130:
1517 scl_(&d[1], &u[1], n, &q[q_offset], lq, mq, &p[p_offset], lp, mp, &e[1], &
1518 f[1], &b, &one, &k, &jl, &jr);
1519L140:
1520 ++j;
1521 if (j == k) {
1522 goto L320;
1523 }
1524 s = (double)0.;
1525 t = (double)0.;
1526/* ----------------------------- */
1527/* |*** SET ERROR TOLERANCE ***| */
1528/* ----------------------------- */
1529 i__1 = l;
1530 for (i = j; i <= i__1; ++i) {
1531 x = (r__1 = d[i] * e[i] * (d[i] * f[i]), fabs(r__1));
1532 y = (r__1 = u[i] * e[i] * (u[i] * f[i + 1]), fabs(r__1));
1533/* Computing MAX */
1534 r__1 = max(s,x);
1535 s = dmax(r__1,y);
1536/* L150: */
1537 t = t + x + y;
1538 }
1539 x = (r__1 = e[k] * d[k] * (f[k] * d[k]), fabs(r__1));
1540 s = dmax(s,x);
1541 t3 = s * t2;
1542 t += x;
1543 if (t == (double)0.) {
1544 t = (double)1.;
1545 }
1546 t1 = t0 / t;
1547 goto L280;
1548L160:
1549 ++ll;
1550 if (ll > ns) {
1551 goto L530;
1552 }
1553 if (l > j) {
1554 goto L170;
1555 }
1556 s = (double)0.;
1557 t = (double)0.;
1558 goto L180;
1559L170:
1560 s = u[k2];
1561 t = e[k2];
1562/* ----------------------- */
1563/* |*** COMPUTE SHIFT ***| */
1564/* ----------------------- */
1565L180:
1566 sft_(&c, &d[k], &d[l], &u[l], &s, &e[k], &e[l], &t, &f[k], &f[l]);
1567 v = (r__1 = e[j], fabs(r__1));
1568 w = (r__1 = f[j], fabs(r__1));
1569 t = d[j] * w;
1570 r = t * (d[j] * v) - c;
1571 s = t * (u[j] * v);
1572 id = 1;
1573 j0 = j;
1574 i = j;
1575 h = j - 1;
1576L190:
1577 g = h;
1578 h = i;
1579 ++i;
1580 z = (r__1 = f[i], fabs(r__1));
1581/* ---------------------------- */
1582/* |*** PROCESS RIGHT SIDE ***| */
1583/* ---------------------------- */
1584 fgv_(&x, &y, &t, &r, &s, &f[h], &f[i]);
1585 v = d[h];
1586 if (t == (double)1.) {
1587 goto L210;
1588 }
1589 if (h == j) {
1590 goto L200;
1591 }
1592 t = u[g] + x * s;
1593 u[g] = t;
1594 if ((r__1 = t * e[g] * (t * f[h]), fabs(r__1)) > t3) {
1595 goto L200;
1596 }
1597 j = h;
1598 id = 1;
1599L200:
1600 r = v + x * u[h];
1601 s = x * d[i];
1602 u[h] -= y * v;
1603 sng0_(&q[q_offset], lq, mq, &p[p_offset], lp, mp, &jr, &h, &i, &x, &y);
1604 goto L230;
1605L210:
1606 if (h == j) {
1607 goto L220;
1608 }
1609 t = x * u[g] + s;
1610 u[g] = t;
1611 if ((r__1 = t * e[g] * (t * f[h]), fabs(r__1)) > t3) {
1612 goto L220;
1613 }
1614 j = h;
1615 id = 1;
1616L220:
1617 r = x * v + u[h];
1618 s = d[i];
1619 u[h] = y * u[h] - v;
1620 d[i] = y * s;
1621 sng1_(&q[q_offset], lq, mq, &p[p_offset], lp, mp, &jr, &h, &i, &x, &y);
1622/* --------------------------- */
1623/* |*** PROCESS LEFT SIDE ***| */
1624/* --------------------------- */
1625L230:
1626 fgv_(&x, &y, &t, &r, &s, &e[h], &e[i]);
1627 if (t == (double)1.) {
1628 goto L250;
1629 }
1630 t = r + x * s;
1631 d[h] = t;
1632 if ((r__1 = t * e[h] * (t * f[h]), fabs(r__1)) > t3) {
1633 goto L240;
1634 }
1635 id = 0;
1636 j = h;
1637L240:
1638 r = u[h] + x * d[i];
1639 d[i] -= y * u[h];
1640 u[h] = r;
1641 sng0_(&q[q_offset], lq, mq, &p[p_offset], lp, mp, &jl, &h, &i, &x, &y);
1642 if (i == k) {
1643 goto L270;
1644 }
1645 s = x * u[i];
1646 goto L190;
1647L250:
1648 t = s + x * r;
1649 d[h] = t;
1650 if ((r__1 = t * e[h] * (t * f[h]), fabs(r__1)) > t3) {
1651 goto L260;
1652 }
1653 id = 0;
1654 j = h;
1655L260:
1656 r = d[i] + x * u[h];
1657 d[i] = y * d[i] - u[h];
1658 u[h] = r;
1659 sng1_(&q[q_offset], lq, mq, &p[p_offset], lp, mp, &jl, &h, &i, &x, &y);
1660 if (i == k) {
1661 goto L270;
1662 }
1663 s = u[i];
1664 u[i] = s * y;
1665 goto L190;
1666L270:
1667 scl_(&d[1], &u[1], n, &q[q_offset], lq, mq, &p[p_offset], lp, mp, &e[1], &
1668 f[1], &b, &j0, &k, &jl, &jr);
1669 if (id == 0) {
1670 goto L70;
1671 }
1672L280:
1673 w = e[l];
1674 x = e[k];
1675 y = f[l];
1676 z = f[k];
1677 r = (r__1 = x * d[k] * (z * d[k]), fabs(r__1));
1678 s = (r__1 = w * d[l] * (y * d[l]), fabs(r__1));
1679 t = (r__1 = x * u[l] * (y * u[l]), fabs(r__1));
1680/* ------------------------------ */
1681/* |*** TEST FOR CONVERGENCE ***| */
1682/* ------------------------------ */
1683 if (s * t1 * (t * t1) > (double)1.) {
1684 goto L160;
1685 }
1686 ++l1;
1687 if (l1 > 40) {
1688 goto L290;
1689 }
1690 if (t == (double)0.) {
1691 goto L290;
1692 }
1693 r += t;
1694 if (s / r * (t / r) > t2) {
1695 goto L160;
1696 }
1697L290:
1698 l1 = 0;
1699 if (s > r) {
1700 goto L310;
1701 }
1702 r = -(double)d[k] * fabs(x);
1703 s = u[l] * fabs(w);
1704 fgv_(&w, &y, &t, &r, &s, &e[l], &e[k]);
1705 x = e[k];
1706 if (t == (double)1.) {
1707 goto L300;
1708 }
1709 d[k] -= y * u[l];
1710 sng0_(&q[q_offset], lq, mq, &p[p_offset], lp, mp, &jl, &l, &k, &w, &y);
1711 goto L310;
1712L300:
1713 d[l] *= w;
1714 d[k] = y * d[k] - u[l];
1715 sng1_(&q[q_offset], lq, mq, &p[p_offset], lp, mp, &jl, &l, &k, &w, &y);
1716L310:
1717 r__1 = sqrt((fabs(x)));
1718 r__2 = sqrt((fabs(z)));
1719 t = r_sign(&r__1, &x) * d[k] * r_sign(&r__2, &z);
1720 if (t < (double)0.) {
1721 e[k] = -(double)e[k];
1722 }
1723 d[k] = fabs(t);
1724 k = l;
1725 l = k2;
1726 --k2;
1727 if (k > j) {
1728 goto L280;
1729 }
1730L320:
1731 x = e[k];
1732 z = f[k];
1733 r__1 = sqrt((fabs(x)));
1734 r__2 = sqrt((fabs(z)));
1735 t = r_sign(&r__1, &x) * d[k] * r_sign(&r__2, &z);
1736 if (t < (double)0.) {
1737 e[k] = -(double)e[k];
1738 }
1739 d[k] = fabs(t);
1740 k = l;
1741 l = k2;
1742 --k2;
1743 if (k > 1) {
1744 goto L50;
1745 }
1746 if (k == 0) {
1747 goto L330;
1748 }
1749 goto L320;
1750/* ------------------------- */
1751/* |*** RESCALE P AND Q ***| */
1752/* ------------------------- */
1753L330:
1754 switch ((int)jl) {
1755 case 1: goto L340;
1756 case 2: goto L360;
1757 case 3: goto L380;
1758 }
1759L340:
1760 i__1 = *n;
1761 for (j = 1; j <= i__1; ++j) {
1762 t = e[j];
1763 r__1 = sqrt((fabs(t)));
1764 t = r_sign(&r__1, &t);
1765 i__2 = *mq;
1766 for (i = 1; i <= i__2; ++i) {
1767/* L350: */
1768 q[i + j * q_dim1] *= t;
1769 }
1770 }
1771 goto L380;
1772L360:
1773 i__2 = *n;
1774 for (j = 1; j <= i__2; ++j) {
1775 t = e[j];
1776 r__1 = sqrt((fabs(t)));
1777 t = r_sign(&r__1, &t);
1778 i__1 = *mp;
1779 for (i = 1; i <= i__1; ++i) {
1780/* L370: */
1781 p[i + j * p_dim1] *= t;
1782 }
1783 }
1784L380:
1785 switch ((int)jr) {
1786 case 1: goto L390;
1787 case 2: goto L410;
1788 case 3: goto L430;
1789 }
1790L390:
1791 i__1 = *n;
1792 for (j = 1; j <= i__1; ++j) {
1793 t = f[j];
1794 r__1 = sqrt((fabs(t)));
1795 t = r_sign(&r__1, &t);
1796 i__2 = *mq;
1797 for (i = 1; i <= i__2; ++i) {
1798/* L400: */
1799 q[i + j * q_dim1] *= t;
1800 }
1801 }
1802 goto L430;
1803L410:
1804 i__2 = *n;
1805 for (j = 1; j <= i__2; ++j) {
1806 t = f[j];
1807 r__1 = sqrt((fabs(t)));
1808 t = r_sign(&r__1, &t);
1809 i__1 = *mp;
1810 for (i = 1; i <= i__1; ++i) {
1811/* L420: */
1812 p[i + j * p_dim1] *= t;
1813 }
1814 }
1815/* -------------------------------- */
1816/* |*** REORDER THE EIGENPAIRS ***| */
1817/* -------------------------------- */
1818L430:
1819 sort2_(&d[1], &e[1], &f[1], n);
1820 i__1 = *n;
1821 for (i = 1; i <= i__1; ++i) {
1822 j = e[i];
1823/* L440: */
1824 f[j] = (real) i;
1825 }
1826 m = *n + 1;
1827 i__1 = *n;
1828 for (j = 1; j <= i__1; ++j) {
1829 l = m - j;
1830 k = e[l];
1831 i = f[j];
1832 e[i] = (real) k;
1833 f[k] = (real) i;
1834 t = d[j];
1835 d[j] = d[k];
1836 d[k] = t;
1837 if (jl == 1) {
1838 goto L450;
1839 }
1840 if (jr != 1) {
1841 goto L480;
1842 }
1843L450:
1844 s = (double)0.;
1845 i__2 = *mq;
1846 for (i = 1; i <= i__2; ++i) {
1847 t = q[i + k * q_dim1];
1848 q[i + k * q_dim1] = q[i + j * q_dim1];
1849 q[i + j * q_dim1] = t;
1850/* L460: */
1851 s += t * t;
1852 }
1853 s = (double)1. / sqrt(s);
1854 i__2 = *mq;
1855 for (i = 1; i <= i__2; ++i) {
1856/* L470: */
1857 q[i + j * q_dim1] = s * q[i + j * q_dim1];
1858 }
1859L480:
1860 if (jr == 2) {
1861 goto L490;
1862 }
1863 if (jl != 2) {
1864 goto L520;
1865 }
1866L490:
1867 s = (double)0.;
1868 i__2 = *mp;
1869 for (i = 1; i <= i__2; ++i) {
1870 t = p[i + k * p_dim1];
1871 p[i + k * p_dim1] = p[i + j * p_dim1];
1872 p[i + j * p_dim1] = t;
1873/* L500: */
1874 s += t * t;
1875 }
1876 s = (double)1. / sqrt(s);
1877 i__2 = *mp;
1878 for (i = 1; i <= i__2; ++i) {
1879/* L510: */
1880 p[i + j * p_dim1] = s * p[i + j * p_dim1];
1881 }
1882L520:
1883 ;
1884 }
1885 e[1] = (real) (*n);
1886 return 0;
1887L530:
1888 k = *n - k + 1;
1889 fprintf(stderr,"SINCE THE STOPPING CRITERION NOT SATISFIED\n");
1890 fprintf(stderr,"AFTER %d ITERATIONS, WE STOP WHILE COMPUTING\n", ns);
1891 fprintf(stderr,"EIGENVALUE NUMBER %d", k);
1892 e[1] = (real) k;
1893 return 0;
1894} /* singb_ */
1895
1896/* % */
1897static int
1898fgv_(double *x, double *y, double *s, double *p, double *q,
1899 double *a, double *b)
1900{
1901 /* System generated locals */
1902 real r__1;
1903
1904 /* Local variables */
1905 static real c, r, t;
1906
1907 if (fabs(*p) > fabs(*q)) {
1908 goto L10;
1909 }
1910 if (*q == (double)0.) {
1911 goto L110;
1912 }
1913 r = *a / *b;
1914 *s = *p / *q;
1915 t = fabs(r) * *s * *s;
1916 if (t < (double)1.) {
1917 goto L70;
1918 }
1919 t /= t + (double)1.;
1920 r = *b / *a;
1921 *s = *q / *p;
1922 goto L20;
1923L10:
1924 r = *b / *a;
1925 *s = *q / *p;
1926 t = fabs(r) * *s * *s;
1927 if (t > (double)1.) {
1928 goto L60;
1929 }
1930 t = (double)1. / (t + (double)1.);
1931L20:
1932 r__1 = *a * t;
1933 *a = r_sign(&r__1, p);
1934 if (r_sign(&r, p) == r) {
1935 goto L40;
1936 }
1937 *b = -(double)(r__1 = *b * t, fabs(r__1));
1938 goto L50;
1939L40:
1940 *b = (r__1 = *b * t, fabs(r__1));
1941L50:
1942 *y = *s;
1943 *x = fabs(r) * *s;
1944 *s = (double)0.;
1945 return 0;
1946L60:
1947 t /= t + (double)1.;
1948 r = *a / *b;
1949 *s = *p / *q;
1950 goto L80;
1951L70:
1952 t = (double)1. / (t + (double)1.);
1953L80:
1954 c = *a;
1955 r__1 = *b * t;
1956 *a = r_sign(&r__1, q);
1957 if (r_sign(&r, q) == r) {
1958 goto L90;
1959 }
1960 *b = -(double)(r__1 = c * t, fabs(r__1));
1961 goto L100;
1962L90:
1963 *b = (r__1 = c * t, fabs(r__1));
1964L100:
1965 *y = *s;
1966 *x = fabs(r) * *s;
1967 *s = (double)1.;
1968 return 0;
1969L110:
1970 *x = (double)0.;
1971 *y = (double)0.;
1972 *s = (double)0.;
1973 return 0;
1974} /* fgv_ */
1975
1976/* % */
1977static int
1978sng0_(double *q, int *lq, int *m, double *p, int *lp, int *n,
1979 int *l, int *j, int *k, double *x, double *y)
1980{
1981 /* System generated locals */
1982 integer q_dim1, q_offset, p_dim1, p_offset, i__1;
1983
1984 /* Local variables */
1985 static integer i;
1986 static real s, t;
1987
1988 /* Parameter adjustments */
1989 p_dim1 = *lp;
1990 p_offset = p_dim1 + 1;
1991 p -= p_offset;
1992 q_dim1 = *lq;
1993 q_offset = q_dim1 + 1;
1994 q -= q_offset;
1995
1996 /* Function Body */
1997 switch ((int)*l) {
1998 case 1: goto L10;
1999 case 2: goto L30;
2000 case 3: goto L50;
2001 }
2002L10:
2003 i__1 = *m;
2004 for (i = 1; i <= i__1; ++i) {
2005 t = q[i + *j * q_dim1];
2006 s = q[i + *k * q_dim1];
2007 q[i + *j * q_dim1] = t + *x * s;
2008/* L20: */
2009 q[i + *k * q_dim1] = s - *y * t;
2010 }
2011 return 0;
2012L30:
2013 i__1 = *n;
2014 for (i = 1; i <= i__1; ++i) {
2015 t = p[i + *j * p_dim1];
2016 s = p[i + *k * p_dim1];
2017 p[i + *j * p_dim1] = t + *x * s;
2018/* L40: */
2019 p[i + *k * p_dim1] = s - *y * t;
2020 }
2021L50:
2022 return 0;
2023} /* sng0_ */
2024
2025/* % */
2026static int
2027sng1_(double *q, int *lq, int *m, double *p,
2028 int *lp, int *n, int *l, int *j, int *k, double *x, double *y)
2029{
2030 /* System generated locals */
2031 integer q_dim1, q_offset, p_dim1, p_offset, i__1;
2032
2033 /* Local variables */
2034 static integer i;
2035 static real s, t;
2036
2037 /* Parameter adjustments */
2038 p_dim1 = *lp;
2039 p_offset = p_dim1 + 1;
2040 p -= p_offset;
2041 q_dim1 = *lq;
2042 q_offset = q_dim1 + 1;
2043 q -= q_offset;
2044
2045 /* Function Body */
2046 switch ((int)*l) {
2047 case 1: goto L10;
2048 case 2: goto L30;
2049 case 3: goto L50;
2050 }
2051L10:
2052 i__1 = *m;
2053 for (i = 1; i <= i__1; ++i) {
2054 t = q[i + *j * q_dim1];
2055 s = q[i + *k * q_dim1];
2056 q[i + *j * q_dim1] = *x * t + s;
2057/* L20: */
2058 q[i + *k * q_dim1] = *y * s - t;
2059 }
2060 return 0;
2061L30:
2062 i__1 = *n;
2063 for (i = 1; i <= i__1; ++i) {
2064 t = p[i + *j * p_dim1];
2065 s = p[i + *k * p_dim1];
2066 p[i + *j * p_dim1] = *x * t + s;
2067/* L40: */
2068 p[i + *k * p_dim1] = *y * s - t;
2069 }
2070L50:
2071 return 0;
2072} /* sng1_ */
2073
2074/* % */
2075static int
2076sft_(double *s, double *a, double *b, double *c,
2077 double *d, double *e2, double *e1, double *e0, double *f2, double *f1)
2078{
2079 static real w, x, y, z, g0, g1, g2, h1, h2;
2080
2081 g0 = fabs(*e0);
2082 g1 = fabs(*e1);
2083 g2 = fabs(*e2);
2084 h1 = fabs(*f1);
2085 h2 = fabs(*f2);
2086 w = *a * g2 * (*a * h2) + *c * g1 * (*c * h2);
2087 x = *b * g1 * (*b * h1) + *d * g0 * (*d * h1);
2088 y = *b * g1 * (*c * h1);
2089 z = *b * g1 * (*c * h2);
2090 eig3_(s, s, &x, &w, &y, &z);
2091 return 0;
2092} /* sft_ */
2093
2094/* % */
2095static int
2096scl_(double *d, double *u, int *n, double *q,
2097 int *lq, int *mq, double *p, int *lp, int *mp,
2098 double *e, double *f, double *b,
2099 int *j, int *k, int *jl,
2100 int *jr)
2101{
2102 /* System generated locals */
2103 integer p_dim1, p_offset, q_dim1, q_offset, i__1, i__2;
2104 real r__1, r__2;
2105
2106 /* Local variables */
2107 static integer h, i, l, m;
2108 static real r, s, t, v;
2109
2110 /* Parameter adjustments */
2111 --f;
2112 --e;
2113 p_dim1 = *lp;
2114 p_offset = p_dim1 + 1;
2115 p -= p_offset;
2116 q_dim1 = *lq;
2117 q_offset = q_dim1 + 1;
2118 q -= q_offset;
2119 --u;
2120 --d;
2121
2122 /* Function Body */
2123 t = (double)1.;
2124 i__1 = *k;
2125 for (i = *j; i <= i__1; ++i) {
2126 if ((r__1 = e[i], fabs(r__1)) < t) {
2127 t = (r__2 = e[i], fabs(r__2));
2128 }
2129/* L10: */
2130 if ((r__1 = f[i], fabs(r__1)) < t) {
2131 t = (r__2 = f[i], fabs(r__2));
2132 }
2133 }
2134 if (t > *b) {
2135 return 0;
2136 }
2137/* ---------------------------- */
2138/* |*** RESCALE THE MATRIX ***| */
2139/* ---------------------------- */
2140 r = e[*j];
2141 r__1 = sqrt((fabs(r)));
2142 r = r_sign(&r__1, &r);
2143 e[*j] = (double)1.;
2144 s = f[*j];
2145 r__1 = sqrt((fabs(s)));
2146 s = r_sign(&r__1, &s);
2147 f[*j] = (double)1.;
2148 d[*j] = r * d[*j] * s;
2149 t = r;
2150 if (*jl == 1) {
2151 goto L20;
2152 }
2153 if (*jr != 1) {
2154 goto L40;
2155 }
2156 t = s;
2157L20:
2158 i__1 = *mq;
2159 for (i = 1; i <= i__1; ++i) {
2160/* L30: */
2161 q[i + *j * q_dim1] *= t;
2162 }
2163L40:
2164 t = s;
2165 if (*jr == 2) {
2166 goto L50;
2167 }
2168 if (*jl != 2) {
2169 goto L70;
2170 }
2171 t = r;
2172L50:
2173 i__1 = *mp;
2174 for (i = 1; i <= i__1; ++i) {
2175/* L60: */
2176 p[i + *j * p_dim1] *= t;
2177 }
2178L70:
2179 l = *j + 1;
2180 h = *j;
2181 i__1 = *k;
2182 for (m = l; m <= i__1; ++m) {
2183 t = e[m];
2184 r__1 = sqrt((fabs(t)));
2185 t = r_sign(&r__1, &t);
2186 e[m] = (double)1.;
2187 s = f[m];
2188 r__1 = sqrt((fabs(s)));
2189 s = r_sign(&r__1, &s);
2190 f[m] = (double)1.;
2191 d[m] = s * d[m] * t;
2192 u[h] = r * u[h] * s;
2193 h = m;
2194 r = t;
2195 v = t;
2196 if (*jl == 1) {
2197 goto L80;
2198 }
2199 if (*jr != 1) {
2200 goto L100;
2201 }
2202 v = s;
2203L80:
2204 i__2 = *mq;
2205 for (i = 1; i <= i__2; ++i) {
2206/* L90: */
2207 q[i + m * q_dim1] *= v;
2208 }
2209L100:
2210 v = s;
2211 if (*jr == 2) {
2212 goto L110;
2213 }
2214 if (*jl != 2) {
2215 goto L130;
2216 }
2217 v = t;
2218L110:
2219 i__2 = *mp;
2220 for (i = 1; i <= i__2; ++i) {
2221/* L120: */
2222 p[i + m * p_dim1] *= v;
2223 }
2224L130:
2225 ;
2226 }
2227 return 0;
2228} /* scl_ */
2229
2230static int
2231eig3_(double *ea, double *eb, double *a, double *b, double *y, double *z)
2232{
2233 /* Local variables */
2234 static real c, s, t;
2235
2236 t = (*b - *a) * (double).5;
2237 c = sqrt((fabs(*y))) * sqrt((fabs(*z)));
2238 if (fabs(t) > fabs(c)) {
2239 goto L30;
2240 }
2241 if (c != (double)0.) {
2242 goto L10;
2243 }
2244 *ea = *a;
2245 *eb = *b;
2246 return 0;
2247L10:
2248 t /= fabs(c);
2249 s = fabs(c) / (fabs(t) + sqrt(t * t + (double)1.));
2250 if (t < (double)0.) {
2251 goto L20;
2252 }
2253 *ea = *a - s;
2254 *eb = *b + s;
2255 return 0;
2256L20:
2257 *ea = *a + s;
2258 *eb = *b - s;
2259 return 0;
2260L30:
2261 t = fabs(c) / t;
2262 s = t * fabs(c) / (sqrt(t * t + (double)1.) + (double)1.);
2263 *ea = *a - s;
2264 *eb = *b + s;
2265 return 0;
2266} /* eig3_ */
2267
2268/* ________________________________________________________ */
2269/* | | */
2270/* | SORT AN ARRAY IN INCREASING ORDER | */
2271/* | | */
2272/* | INPUT: | */
2273/* | | */
2274/* | X --ARRAY OF NUMBERS | */
2275/* | | */
2276/* | W --WORKING ARRAY (LENGTH AT LEAST N) | */
2277/* | | */
2278/* | N --NUMBER OF ARRAY ELEMENTS TO SORT | */
2279/* | | */
2280/* | OUTPUT: | */
2281/* | | */
2282/* | X --ORIGINAL ARRAY | */
2283/* | | */
2284/* | Y --INDICES OF X GIVING INCREASING ORDER | */
2285/* |________________________________________________________| */
2286
2287static int
2288sort2_(double *x, double *y, double *w, int *n)
2289{
2290 static integer i, j, k, l, m, p, q;
2291 static real s, t;
2292
2293 /* Parameter adjustments */
2294 --w;
2295 --y;
2296 --x;
2297
2298 /* Function Body */
2299 i = 1;
2300L10:
2301 k = i;
2302L20:
2303 j = i;
2304 y[i] = (real) i;
2305 ++i;
2306 if (j == *n) {
2307 goto L30;
2308 }
2309 if (x[i] >= x[j]) {
2310 goto L20;
2311 }
2312 w[k] = (real) i;
2313 goto L10;
2314L30:
2315 if (k == 1) {
2316 return 0;
2317 }
2318 w[k] = (real) (*n + 1);
2319L40:
2320 m = 1;
2321 l = 1;
2322L50:
2323 i = l;
2324 if (i > *n) {
2325 goto L120;
2326 }
2327 p = y[i];
2328 s = x[p];
2329 j = w[i];
2330 k = j;
2331 if (j > *n) {
2332 goto L100;
2333 }
2334 q = y[j];
2335 t = x[q];
2336 l = w[j];
2337 y[i] = (real) l;
2338L60:
2339 if (s > t) {
2340 goto L70;
2341 }
2342 w[m] = (real) p;
2343 ++m;
2344 ++i;
2345 if (i == k) {
2346 goto L80;
2347 }
2348 p = y[i];
2349 s = x[p];
2350 goto L60;
2351L70:
2352 w[m] = (real) q;
2353 ++m;
2354 ++j;
2355 if (j == l) {
2356 goto L110;
2357 }
2358 q = y[j];
2359 t = x[q];
2360 goto L60;
2361L80:
2362 w[m] = (real) q;
2363 k = m + l - j;
2364 i = j - m;
2365L90:
2366 ++m;
2367 if (m == k) {
2368 goto L50;
2369 }
2370 w[m] = y[m + i];
2371 goto L90;
2372L100:
2373 y[i] = (real) j;
2374 l = j;
2375L110:
2376 w[m] = (real) p;
2377 k = m + k - i;
2378 i -= m;
2379 goto L90;
2380L120:
2381 i = 1;
2382L130:
2383 k = i;
2384 j = y[i];
2385L140:
2386 y[i] = w[i];
2387 ++i;
2388 if (i < j) {
2389 goto L140;
2390 }
2391 w[k] = (real) i;
2392 if (i <= *n) {
2393 goto L130;
2394 }
2395 if (k > 1) {
2396 goto L40;
2397 }
2398 return 0;
2399} /* sort2_ */
2400
Note: See TracBrowser for help on using the repository browser.