Debian Codegraph @

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

raw
1 /* ./src_f77/ssesrt.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: ssesrt */
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 ssesrt */
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 Real 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 Real 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 /* sswap 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 ssortr */
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 ssesrt_(char *which, logical *apply, integer *n, real *x,
80 integer *na, real *a, integer *lda, ftnlen which_len)
81 {
82 /* System generated locals */
83 integer a_dim1, a_offset, i__1;
84 real r__1, r__2;
85
86 /* Builtin functions */
87 integer s_cmp(char *, char *, ftnlen, ftnlen);
88
89 /* Local variables */
90 static integer i__, j, igap;
91 static real temp;
92 extern /* Subroutine */ int sswap_(integer *, real *, integer *, real *,
93 integer *);
94
95
96 /* %------------------% */
97 /* | Scalar Arguments | */
98 /* %------------------% */
99
100
101 /* %-----------------% */
102 /* | Array Arguments | */
103 /* %-----------------% */
104
105
106 /* %---------------% */
107 /* | Local Scalars | */
108 /* %---------------% */
109
110
111 /* %----------------------% */
112 /* | External Subroutines | */
113 /* %----------------------% */
114
115
116 /* %-----------------------% */
117 /* | Executable Statements | */
118 /* %-----------------------% */
119
120 /* Parameter adjustments */
121 a_dim1 = *lda;
122 a_offset = 1 + a_dim1 * 0;
123 a -= a_offset;
124
125 /* Function Body */
126 igap = *n / 2;
127
128 if (s_cmp(which, "SA", (ftnlen)2, (ftnlen)2) == 0) {
129
130 /* X is sorted into decreasing order of algebraic. */
131
132 L10:
133 if (igap == 0) {
134 goto L9000;
135 }
136 i__1 = *n - 1;
137 for (i__ = igap; i__ <= i__1; ++i__) {
138 j = i__ - igap;
139 L20:
140
141 if (j < 0) {
142 goto L30;
143 }
144
145 if (x[j] < x[j + igap]) {
146 temp = x[j];
147 x[j] = x[j + igap];
148 x[j + igap] = temp;
149 if (*apply) {
150 sswap_(na, &a[j * a_dim1 + 1], &c__1, &a[(j + igap) *
151 a_dim1 + 1], &c__1);
152 }
153 } else {
154 goto L30;
155 }
156 j -= igap;
157 goto L20;
158 L30:
159 ;
160 }
161 igap /= 2;
162 goto L10;
163
164 } else if (s_cmp(which, "SM", (ftnlen)2, (ftnlen)2) == 0) {
165
166 /* X is sorted into decreasing order of magnitude. */
167
168 L40:
169 if (igap == 0) {
170 goto L9000;
171 }
172 i__1 = *n - 1;
173 for (i__ = igap; i__ <= i__1; ++i__) {
174 j = i__ - igap;
175 L50:
176
177 if (j < 0) {
178 goto L60;
179 }
180
181 if ((r__1 = x[j], dabs(r__1)) < (r__2 = x[j + igap], dabs(r__2)))
182 {
183 temp = x[j];
184 x[j] = x[j + igap];
185 x[j + igap] = temp;
186 if (*apply) {
187 sswap_(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 sswap_(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 ((r__1 = x[j], dabs(r__1)) > (r__2 = x[j + igap], dabs(r__2)))
255 {
256 temp = x[j];
257 x[j] = x[j + igap];
258 x[j + igap] = temp;
259 if (*apply) {
260 sswap_(na, &a[j * a_dim1 + 1], &c__1, &a[(j + igap) *
261 a_dim1 + 1], &c__1);
262 }
263 } else {
264 goto L120;
265 }
266 j -= igap;
267 goto L110;
268 L120:
269 ;
270 }
271 igap /= 2;
272 goto L100;
273 }
274
275 L9000:
276 return 0;
277
278 /* %---------------% */
279 /* | End of ssesrt | */
280 /* %---------------% */
281
282 } /* ssesrt_ */
283