Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / dlamrg.c
1 #include "clapack.h"
2
3 /* Subroutine */ int dlamrg_(integer *n1, integer *n2, doublereal *a, integer 
4         *dtrd1, integer *dtrd2, integer *index)
5 {
6     /* System generated locals */
7     integer i__1;
8
9     /* Local variables */
10     integer i__, ind1, ind2, n1sv, n2sv;
11
12
13 /*  -- LAPACK routine (version 3.1) -- */
14 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
15 /*     November 2006 */
16
17 /*     .. Scalar Arguments .. */
18 /*     .. */
19 /*     .. Array Arguments .. */
20 /*     .. */
21
22 /*  Purpose */
23 /*  ======= */
24
25 /*  DLAMRG will create a permutation list which will merge the elements */
26 /*  of A (which is composed of two independently sorted sets) into a */
27 /*  single set which is sorted in ascending order. */
28
29 /*  Arguments */
30 /*  ========= */
31
32 /*  N1     (input) INTEGER */
33 /*  N2     (input) INTEGER */
34 /*         These arguements contain the respective lengths of the two */
35 /*         sorted lists to be merged. */
36
37 /*  A      (input) DOUBLE PRECISION array, dimension (N1+N2) */
38 /*         The first N1 elements of A contain a list of numbers which */
39 /*         are sorted in either ascending or descending order.  Likewise */
40 /*         for the final N2 elements. */
41
42 /*  DTRD1  (input) INTEGER */
43 /*  DTRD2  (input) INTEGER */
44 /*         These are the strides to be taken through the array A. */
45 /*         Allowable strides are 1 and -1.  They indicate whether a */
46 /*         subset of A is sorted in ascending (DTRDx = 1) or descending */
47 /*         (DTRDx = -1) order. */
48
49 /*  INDEX  (output) INTEGER array, dimension (N1+N2) */
50 /*         On exit this array will contain a permutation such that */
51 /*         if B( I ) = A( INDEX( I ) ) for I=1,N1+N2, then B will be */
52 /*         sorted in ascending order. */
53
54 /*  ===================================================================== */
55
56 /*     .. Local Scalars .. */
57 /*     .. */
58 /*     .. Executable Statements .. */
59
60     /* Parameter adjustments */
61     --index;
62     --a;
63
64     /* Function Body */
65     n1sv = *n1;
66     n2sv = *n2;
67     if (*dtrd1 > 0) {
68         ind1 = 1;
69     } else {
70         ind1 = *n1;
71     }
72     if (*dtrd2 > 0) {
73         ind2 = *n1 + 1;
74     } else {
75         ind2 = *n1 + *n2;
76     }
77     i__ = 1;
78 /*     while ( (N1SV > 0) & (N2SV > 0) ) */
79 L10:
80     if (n1sv > 0 && n2sv > 0) {
81         if (a[ind1] <= a[ind2]) {
82             index[i__] = ind1;
83             ++i__;
84             ind1 += *dtrd1;
85             --n1sv;
86         } else {
87             index[i__] = ind2;
88             ++i__;
89             ind2 += *dtrd2;
90             --n2sv;
91         }
92         goto L10;
93     }
94 /*     end while */
95     if (n1sv == 0) {
96         i__1 = n2sv;
97         for (n1sv = 1; n1sv <= i__1; ++n1sv) {
98             index[i__] = ind2;
99             ++i__;
100             ind2 += *dtrd2;
101 /* L20: */
102         }
103     } else {
104 /*     N2SV .EQ. 0 */
105         i__1 = n1sv;
106         for (n2sv = 1; n2sv <= i__1; ++n2sv) {
107             index[i__] = ind1;
108             ++i__;
109             ind1 += *dtrd1;
110 /* L30: */
111         }
112     }
113
114     return 0;
115
116 /*     End of DLAMRG */
117
118 } /* dlamrg_ */