| 1 |
/* ./src_f77/dsortc.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: dsortc */ |
| 12 |
|
| 13 |
/* \Description: */ |
| 14 |
/* Sorts the complex array in XREAL and XIMAG into the order */ |
| 15 |
/* specified by WHICH and optionally applies the permutation to the */ |
| 16 |
/* real array Y. It is assumed that if an element of XIMAG is */ |
| 17 |
/* nonzero, then its negative is also an element. In other words, */ |
| 18 |
/* both members of a complex conjugate pair are to be sorted and the */ |
| 19 |
/* pairs are kept adjacent to each other. */ |
| 20 |
|
| 21 |
/* \Usage: */ |
| 22 |
/* call dsortc */ |
| 23 |
/* ( WHICH, APPLY, N, XREAL, XIMAG, Y ) */ |
| 24 |
|
| 25 |
/* \Arguments */ |
| 26 |
/* WHICH Character*2. (Input) */ |
| 27 |
/* 'LM' -> sort XREAL,XIMAG into increasing order of magnitude. */ |
| 28 |
/* 'SM' -> sort XREAL,XIMAG into decreasing order of magnitude. */ |
| 29 |
/* 'LR' -> sort XREAL into increasing order of algebraic. */ |
| 30 |
/* 'SR' -> sort XREAL into decreasing order of algebraic. */ |
| 31 |
/* 'LI' -> sort XIMAG into increasing order of magnitude. */ |
| 32 |
/* 'SI' -> sort XIMAG into decreasing order of magnitude. */ |
| 33 |
/* NOTE: If an element of XIMAG is non-zero, then its negative */ |
| 34 |
/* is also an element. */ |
| 35 |
|
| 36 |
/* APPLY Logical. (Input) */ |
| 37 |
/* APPLY = .TRUE. -> apply the sorted order to array Y. */ |
| 38 |
/* APPLY = .FALSE. -> do not apply the sorted order to array Y. */ |
| 39 |
|
| 40 |
/* N Integer. (INPUT) */ |
| 41 |
/* Size of the arrays. */ |
| 42 |
|
| 43 |
/* XREAL, Double precision array of length N. (INPUT/OUTPUT) */ |
| 44 |
/* XIMAG Real and imaginary part of the array to be sorted. */ |
| 45 |
|
| 46 |
/* Y Double precision array of length N. (INPUT/OUTPUT) */ |
| 47 |
|
| 48 |
/* \EndDoc */ |
| 49 |
|
| 50 |
/* ----------------------------------------------------------------------- */ |
| 51 |
|
| 52 |
/* \BeginLib */ |
| 53 |
|
| 54 |
/* \Author */ |
| 55 |
/* Danny Sorensen Phuong Vu */ |
| 56 |
/* Richard Lehoucq CRPC / Rice University */ |
| 57 |
/* Dept. of Computational & Houston, Texas */ |
| 58 |
/* Applied Mathematics */ |
| 59 |
/* Rice University */ |
| 60 |
/* Houston, Texas */ |
| 61 |
|
| 62 |
/* \Revision history: */ |
| 63 |
/* xx/xx/92: Version ' 2.1' */ |
| 64 |
/* Adapted from the sort routine in LANSO. */ |
| 65 |
|
| 66 |
/* \SCCS Information: @(#) */ |
| 67 |
/* FILE: sortc.F SID: 2.3 DATE OF SID: 4/20/96 RELEASE: 2 */ |
| 68 |
|
| 69 |
/* \EndLib */ |
| 70 |
|
| 71 |
/* ----------------------------------------------------------------------- */ |
| 72 |
|
| 73 |
/* Subroutine */ int dsortc_(char *which, logical *apply, integer *n, |
| 74 |
doublereal *xreal, doublereal *ximag, doublereal *y, ftnlen which_len) |
| 75 |
{ |
| 76 |
/* System generated locals */ |
| 77 |
integer i__1; |
| 78 |
doublereal d__1, d__2; |
| 79 |
|
| 80 |
/* Builtin functions */ |
| 81 |
integer s_cmp(char *, char *, ftnlen, ftnlen); |
| 82 |
|
| 83 |
/* Local variables */ |
| 84 |
static integer i__, j, igap; |
| 85 |
static doublereal temp, temp1, temp2; |
| 86 |
extern doublereal dlapy2_(doublereal *, doublereal *); |
| 87 |
|
| 88 |
|
| 89 |
/* %------------------% */ |
| 90 |
/* | Scalar Arguments | */ |
| 91 |
/* %------------------% */ |
| 92 |
|
| 93 |
|
| 94 |
/* %-----------------% */ |
| 95 |
/* | Array Arguments | */ |
| 96 |
/* %-----------------% */ |
| 97 |
|
| 98 |
|
| 99 |
/* %---------------% */ |
| 100 |
/* | Local Scalars | */ |
| 101 |
/* %---------------% */ |
| 102 |
|
| 103 |
|
| 104 |
/* %--------------------% */ |
| 105 |
/* | External Functions | */ |
| 106 |
/* %--------------------% */ |
| 107 |
|
| 108 |
|
| 109 |
/* %-----------------------% */ |
| 110 |
/* | Executable Statements | */ |
| 111 |
/* %-----------------------% */ |
| 112 |
|
| 113 |
igap = *n / 2; |
| 114 |
|
| 115 |
if (s_cmp(which, "LM", (ftnlen)2, (ftnlen)2) == 0) { |
| 116 |
|
| 117 |
/* %------------------------------------------------------% */ |
| 118 |
/* | Sort XREAL,XIMAG into increasing order of magnitude. | */ |
| 119 |
/* %------------------------------------------------------% */ |
| 120 |
|
| 121 |
L10: |
| 122 |
if (igap == 0) { |
| 123 |
goto L9000; |
| 124 |
} |
| 125 |
|
| 126 |
i__1 = *n - 1; |
| 127 |
for (i__ = igap; i__ <= i__1; ++i__) { |
| 128 |
j = i__ - igap; |
| 129 |
L20: |
| 130 |
|
| 131 |
if (j < 0) { |
| 132 |
goto L30; |
| 133 |
} |
| 134 |
|
| 135 |
temp1 = dlapy2_(&xreal[j], &ximag[j]); |
| 136 |
temp2 = dlapy2_(&xreal[j + igap], &ximag[j + igap]); |
| 137 |
|
| 138 |
if (temp1 > temp2) { |
| 139 |
temp = xreal[j]; |
| 140 |
xreal[j] = xreal[j + igap]; |
| 141 |
xreal[j + igap] = temp; |
| 142 |
|
| 143 |
temp = ximag[j]; |
| 144 |
ximag[j] = ximag[j + igap]; |
| 145 |
ximag[j + igap] = temp; |
| 146 |
|
| 147 |
if (*apply) { |
| 148 |
temp = y[j]; |
| 149 |
y[j] = y[j + igap]; |
| 150 |
y[j + igap] = temp; |
| 151 |
} |
| 152 |
} else { |
| 153 |
goto L30; |
| 154 |
} |
| 155 |
j -= igap; |
| 156 |
goto L20; |
| 157 |
L30: |
| 158 |
; |
| 159 |
} |
| 160 |
igap /= 2; |
| 161 |
goto L10; |
| 162 |
|
| 163 |
} else if (s_cmp(which, "SM", (ftnlen)2, (ftnlen)2) == 0) { |
| 164 |
|
| 165 |
/* %------------------------------------------------------% */ |
| 166 |
/* | Sort XREAL,XIMAG into decreasing order of magnitude. | */ |
| 167 |
/* %------------------------------------------------------% */ |
| 168 |
|
| 169 |
L40: |
| 170 |
if (igap == 0) { |
| 171 |
goto L9000; |
| 172 |
} |
| 173 |
|
| 174 |
i__1 = *n - 1; |
| 175 |
for (i__ = igap; i__ <= i__1; ++i__) { |
| 176 |
j = i__ - igap; |
| 177 |
L50: |
| 178 |
|
| 179 |
if (j < 0) { |
| 180 |
goto L60; |
| 181 |
} |
| 182 |
|
| 183 |
temp1 = dlapy2_(&xreal[j], &ximag[j]); |
| 184 |
temp2 = dlapy2_(&xreal[j + igap], &ximag[j + igap]); |
| 185 |
|
| 186 |
if (temp1 < temp2) { |
| 187 |
temp = xreal[j]; |
| 188 |
xreal[j] = xreal[j + igap]; |
| 189 |
xreal[j + igap] = temp; |
| 190 |
|
| 191 |
temp = ximag[j]; |
| 192 |
ximag[j] = ximag[j + igap]; |
| 193 |
ximag[j + igap] = temp; |
| 194 |
|
| 195 |
if (*apply) { |
| 196 |
temp = y[j]; |
| 197 |
y[j] = y[j + igap]; |
| 198 |
y[j + igap] = temp; |
| 199 |
} |
| 200 |
} else { |
| 201 |
goto L60; |
| 202 |
} |
| 203 |
j -= igap; |
| 204 |
goto L50; |
| 205 |
L60: |
| 206 |
; |
| 207 |
} |
| 208 |
igap /= 2; |
| 209 |
goto L40; |
| 210 |
|
| 211 |
} else if (s_cmp(which, "LR", (ftnlen)2, (ftnlen)2) == 0) { |
| 212 |
|
| 213 |
/* %------------------------------------------------% */ |
| 214 |
/* | Sort XREAL into increasing order of algebraic. | */ |
| 215 |
/* %------------------------------------------------% */ |
| 216 |
|
| 217 |
L70: |
| 218 |
if (igap == 0) { |
| 219 |
goto L9000; |
| 220 |
} |
| 221 |
|
| 222 |
i__1 = *n - 1; |
| 223 |
for (i__ = igap; i__ <= i__1; ++i__) { |
| 224 |
j = i__ - igap; |
| 225 |
L80: |
| 226 |
|
| 227 |
if (j < 0) { |
| 228 |
goto L90; |
| 229 |
} |
| 230 |
|
| 231 |
if (xreal[j] > xreal[j + igap]) { |
| 232 |
temp = xreal[j]; |
| 233 |
xreal[j] = xreal[j + igap]; |
| 234 |
xreal[j + igap] = temp; |
| 235 |
|
| 236 |
temp = ximag[j]; |
| 237 |
ximag[j] = ximag[j + igap]; |
| 238 |
ximag[j + igap] = temp; |
| 239 |
|
| 240 |
if (*apply) { |
| 241 |
temp = y[j]; |
| 242 |
y[j] = y[j + igap]; |
| 243 |
y[j + igap] = temp; |
| 244 |
} |
| 245 |
} else { |
| 246 |
goto L90; |
| 247 |
} |
| 248 |
j -= igap; |
| 249 |
goto L80; |
| 250 |
L90: |
| 251 |
; |
| 252 |
} |
| 253 |
igap /= 2; |
| 254 |
goto L70; |
| 255 |
|
| 256 |
} else if (s_cmp(which, "SR", (ftnlen)2, (ftnlen)2) == 0) { |
| 257 |
|
| 258 |
/* %------------------------------------------------% */ |
| 259 |
/* | Sort XREAL into decreasing order of algebraic. | */ |
| 260 |
/* %------------------------------------------------% */ |
| 261 |
|
| 262 |
L100: |
| 263 |
if (igap == 0) { |
| 264 |
goto L9000; |
| 265 |
} |
| 266 |
i__1 = *n - 1; |
| 267 |
for (i__ = igap; i__ <= i__1; ++i__) { |
| 268 |
j = i__ - igap; |
| 269 |
L110: |
| 270 |
|
| 271 |
if (j < 0) { |
| 272 |
goto L120; |
| 273 |
} |
| 274 |
|
| 275 |
if (xreal[j] < xreal[j + igap]) { |
| 276 |
temp = xreal[j]; |
| 277 |
xreal[j] = xreal[j + igap]; |
| 278 |
xreal[j + igap] = temp; |
| 279 |
|
| 280 |
temp = ximag[j]; |
| 281 |
ximag[j] = ximag[j + igap]; |
| 282 |
ximag[j + igap] = temp; |
| 283 |
|
| 284 |
if (*apply) { |
| 285 |
temp = y[j]; |
| 286 |
y[j] = y[j + igap]; |
| 287 |
y[j + igap] = temp; |
| 288 |
} |
| 289 |
} else { |
| 290 |
goto L120; |
| 291 |
} |
| 292 |
j -= igap; |
| 293 |
goto L110; |
| 294 |
L120: |
| 295 |
; |
| 296 |
} |
| 297 |
igap /= 2; |
| 298 |
goto L100; |
| 299 |
|
| 300 |
} else if (s_cmp(which, "LI", (ftnlen)2, (ftnlen)2) == 0) { |
| 301 |
|
| 302 |
/* %------------------------------------------------% */ |
| 303 |
/* | Sort XIMAG into increasing order of magnitude. | */ |
| 304 |
/* %------------------------------------------------% */ |
| 305 |
|
| 306 |
L130: |
| 307 |
if (igap == 0) { |
| 308 |
goto L9000; |
| 309 |
} |
| 310 |
i__1 = *n - 1; |
| 311 |
for (i__ = igap; i__ <= i__1; ++i__) { |
| 312 |
j = i__ - igap; |
| 313 |
L140: |
| 314 |
|
| 315 |
if (j < 0) { |
| 316 |
goto L150; |
| 317 |
} |
| 318 |
|
| 319 |
if ((d__1 = ximag[j], abs(d__1)) > (d__2 = ximag[j + igap], abs( |
| 320 |
d__2))) { |
| 321 |
temp = xreal[j]; |
| 322 |
xreal[j] = xreal[j + igap]; |
| 323 |
xreal[j + igap] = temp; |
| 324 |
|
| 325 |
temp = ximag[j]; |
| 326 |
ximag[j] = ximag[j + igap]; |
| 327 |
ximag[j + igap] = temp; |
| 328 |
|
| 329 |
if (*apply) { |
| 330 |
temp = y[j]; |
| 331 |
y[j] = y[j + igap]; |
| 332 |
y[j + igap] = temp; |
| 333 |
} |
| 334 |
} else { |
| 335 |
goto L150; |
| 336 |
} |
| 337 |
j -= igap; |
| 338 |
goto L140; |
| 339 |
L150: |
| 340 |
; |
| 341 |
} |
| 342 |
igap /= 2; |
| 343 |
goto L130; |
| 344 |
|
| 345 |
} else if (s_cmp(which, "SI", (ftnlen)2, (ftnlen)2) == 0) { |
| 346 |
|
| 347 |
/* %------------------------------------------------% */ |
| 348 |
/* | Sort XIMAG into decreasing order of magnitude. | */ |
| 349 |
/* %------------------------------------------------% */ |
| 350 |
|
| 351 |
L160: |
| 352 |
if (igap == 0) { |
| 353 |
goto L9000; |
| 354 |
} |
| 355 |
i__1 = *n - 1; |
| 356 |
for (i__ = igap; i__ <= i__1; ++i__) { |
| 357 |
j = i__ - igap; |
| 358 |
L170: |
| 359 |
|
| 360 |
if (j < 0) { |
| 361 |
goto L180; |
| 362 |
} |
| 363 |
|
| 364 |
if ((d__1 = ximag[j], abs(d__1)) < (d__2 = ximag[j + igap], abs( |
| 365 |
d__2))) { |
| 366 |
temp = xreal[j]; |
| 367 |
xreal[j] = xreal[j + igap]; |
| 368 |
xreal[j + igap] = temp; |
| 369 |
|
| 370 |
temp = ximag[j]; |
| 371 |
ximag[j] = ximag[j + igap]; |
| 372 |
ximag[j + igap] = temp; |
| 373 |
|
| 374 |
if (*apply) { |
| 375 |
temp = y[j]; |
| 376 |
y[j] = y[j + igap]; |
| 377 |
y[j + igap] = temp; |
| 378 |
} |
| 379 |
} else { |
| 380 |
goto L180; |
| 381 |
} |
| 382 |
j -= igap; |
| 383 |
goto L170; |
| 384 |
L180: |
| 385 |
; |
| 386 |
} |
| 387 |
igap /= 2; |
| 388 |
goto L160; |
| 389 |
} |
| 390 |
|
| 391 |
L9000: |
| 392 |
return 0; |
| 393 |
|
| 394 |
/* %---------------% */ |
| 395 |
/* | End of dsortc | */ |
| 396 |
/* %---------------% */ |
| 397 |
|
| 398 |
} /* dsortc_ */ |
| 399 |
|