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