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