Actual source code: numsrt.c
1: /* numsrt.f -- translated by f2c (version of 25 March 1992 12:58:56). */
3: #include <../src/mat/color/impls/minpack/color.h>
5: PetscErrorCode MINPACKnumsrt(PetscInt *n, PetscInt *nmax, PetscInt *num, PetscInt *mode, PetscInt *idex, PetscInt *last, PetscInt *next)
6: {
7: /* System generated locals */
8: PetscInt i__1, i__2;
10: /* Local variables */
11: PetscInt jinc, i, j, k, l, jl, ju;
13: /* Given a sequence of integers, this subroutine groups */
14: /* together those indices with the same sequence value */
15: /* and, optionally, sorts the sequence into either */
16: /* ascending or descending order. */
17: /* The sequence of integers is defined by the array num, */
18: /* and it is assumed that the integers are each from the set */
19: /* 0,1,...,nmax. On output the indices k such that num(k) = l */
20: /* for any l = 0,1,...,nmax can be obtained from the arrays */
21: /* last and next as follows. */
22: /* k = last(l) */
23: /* while (k .ne. 0) k = next(k) */
24: /* Optionally, the subroutine produces an array index so that */
25: /* the sequence num(index(i)), i = 1,2,...,n is sorted. */
26: /* The subroutine statement is */
27: /* subroutine numsrt(n,nmax,num,mode,index,last,next) */
28: /* where */
29: /* n is a positive integer input variable. */
30: /* nmax is a positive integer input variable. */
31: /* num is an input array of length n which contains the */
32: /* sequence of integers to be grouped and sorted. It */
33: /* is assumed that the integers are each from the set */
34: /* 0,1,...,nmax. */
35: /* mode is an integer input variable. The sequence num is */
36: /* sorted in ascending order if mode is positive and in */
37: /* descending order if mode is negative. If mode is 0, */
38: /* no sorting is done. */
39: /* index is an integer output array of length n set so */
40: /* that the sequence */
41: /* num(index(i)), i = 1,2,...,n */
42: /* is sorted according to the setting of mode. If mode */
43: /* is 0, index is not referenced. */
44: /* last is an integer output array of length nmax + 1. The */
45: /* index of num for the last occurrence of l is last(l) */
46: /* for any l = 0,1,...,nmax unless last(l) = 0. In */
47: /* this case l does not appear in num. */
48: /* next is an integer output array of length n. If */
49: /* num(k) = l, then the index of num for the previous */
50: /* occurrence of l is next(k) for any l = 0,1,...,nmax */
51: /* unless next(k) = 0. In this case there is no previous */
52: /* occurrence of l in num. */
53: /* Argonne National Laboratory. MINPACK Project. July 1983. */
54: /* Thomas F. Coleman, Burton S. Garbow, Jorge J. More' */
56: /* Parameter adjustments */
57: --next;
58: --idex;
59: --num;
61: i__1 = *nmax;
62: for (i = 0; i <= i__1; ++i) last[i] = 0;
64: i__1 = *n;
65: for (k = 1; k <= i__1; ++k) {
66: l = num[k];
67: next[k] = last[l];
68: last[l] = k;
69: }
70: if (!*mode) return 0;
72: /* Store the pointers to the sorted array in index. */
74: i = 1;
75: if (*mode > 0) {
76: jl = 0;
77: ju = *nmax;
78: jinc = 1;
79: } else {
80: jl = *nmax;
81: ju = 0;
82: jinc = -1;
83: }
84: i__1 = ju;
85: i__2 = jinc;
86: for (j = jl; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
87: k = last[j];
88: L30:
89: if (!k) goto L40;
90: idex[i] = k;
91: ++i;
92: k = next[k];
93: goto L30;
94: L40:;
95: }
96: return 0;
97: }