Debian Codegraph @

debian/external_deps/fetk/punc/src/arpack/dsortr.c

raw
1 /* ./src_f77/dsortr.f -- translated by f2c (version 20030320).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include <punc/vf2c.h>
7
8 /* ----------------------------------------------------------------------- */
9 /* \BeginDoc */
10
11 /* \Name: dsortr */
12
13 /* \Description: */
14 /* Sort the array X1 in the order specified by WHICH and optionally */
15 /* applies the permutation to the array X2. */
16
17 /* \Usage: */
18 /* call dsortr */
19 /* ( WHICH, APPLY, N, X1, X2 ) */
20
21 /* \Arguments */
22 /* WHICH Character*2. (Input) */
23 /* 'LM' -> X1 is sorted into increasing order of magnitude. */
24 /* 'SM' -> X1 is sorted into decreasing order of magnitude. */
25 /* 'LA' -> X1 is sorted into increasing order of algebraic. */
26 /* 'SA' -> X1 is sorted into decreasing order of algebraic. */
27
28 /* APPLY Logical. (Input) */
29 /* APPLY = .TRUE. -> apply the sorted order to X2. */
30 /* APPLY = .FALSE. -> do not apply the sorted order to X2. */
31
32 /* N Integer. (INPUT) */
33 /* Size of the arrays. */
34
35 /* X1 Double precision array of length N. (INPUT/OUTPUT) */
36 /* The array to be sorted. */
37
38 /* X2 Double precision array of length N. (INPUT/OUTPUT) */
39 /* Only referenced if APPLY = .TRUE. */
40
41 /* \EndDoc */
42
43 /* ----------------------------------------------------------------------- */
44
45 /* \BeginLib */
46
47 /* \Author */
48 /* Danny Sorensen Phuong Vu */
49 /* Richard Lehoucq CRPC / Rice University */
50 /* Dept. of Computational & Houston, Texas */
51 /* Applied Mathematics */
52 /* Rice University */
53 /* Houston, Texas */
54
55 /* \Revision history: */
56 /* 12/16/93: Version ' 2.1'. */
57 /* Adapted from the sort routine in LANSO. */
58
59 /* \SCCS Information: @(#) */
60 /* FILE: sortr.F SID: 2.3 DATE OF SID: 4/19/96 RELEASE: 2 */
61
62 /* \EndLib */
63
64 /* ----------------------------------------------------------------------- */
65
66 /* Subroutine */ int dsortr_(char *which, logical *apply, integer *n,
67 doublereal *x1, doublereal *x2, ftnlen which_len)
68 {
69 /* System generated locals */
70 integer i__1;
71 doublereal d__1, d__2;
72
73 /* Builtin functions */
74 integer s_cmp(char *, char *, ftnlen, ftnlen);
75
76 /* Local variables */
77 static integer i__, j, igap;
78 static doublereal temp;
79
80
81 /* %------------------% */
82 /* | Scalar Arguments | */
83 /* %------------------% */
84
85
86 /* %-----------------% */
87 /* | Array Arguments | */
88 /* %-----------------% */
89
90
91 /* %---------------% */
92 /* | Local Scalars | */
93 /* %---------------% */
94
95
96 /* %-----------------------% */
97 /* | Executable Statements | */
98 /* %-----------------------% */
99
100 igap = *n / 2;
101
102 if (s_cmp(which, "SA", (ftnlen)2, (ftnlen)2) == 0) {
103
104 /* X1 is sorted into decreasing order of algebraic. */
105
106 L10:
107 if (igap == 0) {
108 goto L9000;
109 }
110 i__1 = *n - 1;
111 for (i__ = igap; i__ <= i__1; ++i__) {
112 j = i__ - igap;
113 L20:
114
115 if (j < 0) {
116 goto L30;
117 }
118
119 if (x1[j] < x1[j + igap]) {
120 temp = x1[j];
121 x1[j] = x1[j + igap];
122 x1[j + igap] = temp;
123 if (*apply) {
124 temp = x2[j];
125 x2[j] = x2[j + igap];
126 x2[j + igap] = temp;
127 }
128 } else {
129 goto L30;
130 }
131 j -= igap;
132 goto L20;
133 L30:
134 ;
135 }
136 igap /= 2;
137 goto L10;
138
139 } else if (s_cmp(which, "SM", (ftnlen)2, (ftnlen)2) == 0) {
140
141 /* X1 is sorted into decreasing order of magnitude. */
142
143 L40:
144 if (igap == 0) {
145 goto L9000;
146 }
147 i__1 = *n - 1;
148 for (i__ = igap; i__ <= i__1; ++i__) {
149 j = i__ - igap;
150 L50:
151
152 if (j < 0) {
153 goto L60;
154 }
155
156 if ((d__1 = x1[j], abs(d__1)) < (d__2 = x1[j + igap], abs(d__2)))
157 {
158 temp = x1[j];
159 x1[j] = x1[j + igap];
160 x1[j + igap] = temp;
161 if (*apply) {
162 temp = x2[j];
163 x2[j] = x2[j + igap];
164 x2[j + igap] = temp;
165 }
166 } else {
167 goto L60;
168 }
169 j -= igap;
170 goto L50;
171 L60:
172 ;
173 }
174 igap /= 2;
175 goto L40;
176
177 } else if (s_cmp(which, "LA", (ftnlen)2, (ftnlen)2) == 0) {
178
179 /* X1 is sorted into increasing order of algebraic. */
180
181 L70:
182 if (igap == 0) {
183 goto L9000;
184 }
185 i__1 = *n - 1;
186 for (i__ = igap; i__ <= i__1; ++i__) {
187 j = i__ - igap;
188 L80:
189
190 if (j < 0) {
191 goto L90;
192 }
193
194 if (x1[j] > x1[j + igap]) {
195 temp = x1[j];
196 x1[j] = x1[j + igap];
197 x1[j + igap] = temp;
198 if (*apply) {
199 temp = x2[j];
200 x2[j] = x2[j + igap];
201 x2[j + igap] = temp;
202 }
203 } else {
204 goto L90;
205 }
206 j -= igap;
207 goto L80;
208 L90:
209 ;
210 }
211 igap /= 2;
212 goto L70;
213
214 } else if (s_cmp(which, "LM", (ftnlen)2, (ftnlen)2) == 0) {
215
216 /* X1 is sorted into increasing order of magnitude. */
217
218 L100:
219 if (igap == 0) {
220 goto L9000;
221 }
222 i__1 = *n - 1;
223 for (i__ = igap; i__ <= i__1; ++i__) {
224 j = i__ - igap;
225 L110:
226
227 if (j < 0) {
228 goto L120;
229 }
230
231 if ((d__1 = x1[j], abs(d__1)) > (d__2 = x1[j + igap], abs(d__2)))
232 {
233 temp = x1[j];
234 x1[j] = x1[j + igap];
235 x1[j + igap] = temp;
236 if (*apply) {
237 temp = x2[j];
238 x2[j] = x2[j + igap];
239 x2[j + igap] = temp;
240 }
241 } else {
242 goto L120;
243 }
244 j -= igap;
245 goto L110;
246 L120:
247 ;
248 }
249 igap /= 2;
250 goto L100;
251 }
252
253 L9000:
254 return 0;
255
256 /* %---------------% */
257 /* | End of dsortr | */
258 /* %---------------% */
259
260 } /* dsortr_ */
261