Debian Codegraph @

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

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