Date: 2016-07-24T16:58:41+00:00

Actual source code: numsrt.c
petsc-3.7.3 2016-07-24
Report Typos and Errors

      1: /* numsrt.f -- translated by f2c (version of 25 March 1992  12:58:56). */

      3: #include <../src/mat/color/impls/minpack/color.h>

      7: PetscErrorCode MINPACKnumsrt(PetscInt *n,PetscInt *nmax,PetscInt *num,PetscInt *mode,PetscInt *idex,PetscInt *last,PetscInt *next)
      8: {
      9:   /* System generated locals */
     10:   PetscInt i__1, i__2;

     12:   /* Local variables */
     13:   PetscInt jinc, i, j, k, l, jl, ju;

     15: /*     Given a sequence of integers, this subroutine groups */
     16: /*     together those indices with the same sequence value */
     17: /*     and, optionally, sorts the sequence into either */
     18: /*     ascending or descending order. */
     19: /*     The sequence of integers is defined by the array num, */
     20: /*     and it is assumed that the integers are each from the set */
     21: /*     0,1,...,nmax. On output the indices k such that num(k) = l */
     22: /*     for any l = 0,1,...,nmax can be obtained from the arrays */
     23: /*     last and next as follows. */
     24: /*           k = last(l) */
     25: /*           while (k .ne. 0) k = next(k) */
     26: /*     Optionally, the subroutine produces an array index so that */
     27: /*     the sequence num(index(i)), i = 1,2,...,n is sorted. */
     28: /*     The subroutine statement is */
     29: /*       subroutine numsrt(n,nmax,num,mode,index,last,next) */
     30: /*     where */
     31: /*       n is a positive integer input variable. */
     32: /*       nmax is a positive integer input variable. */
     33: /*       num is an input array of length n which contains the */
     34: /*         sequence of integers to be grouped and sorted. It */
     35: /*         is assumed that the integers are each from the set */
     36: /*         0,1,...,nmax. */
     37: /*       mode is an integer input variable. The sequence num is */
     38: /*         sorted in ascending order if mode is positive and in */
     39: /*         descending order if mode is negative. If mode is 0, */
     40: /*         no sorting is done. */
     41: /*       index is an integer output array of length n set so */
     42: /*         that the sequence */
     43: /*               num(index(i)), i = 1,2,...,n */
     44: /*         is sorted according to the setting of mode. If mode */
     45: /*         is 0, index is not referenced. */
     46: /*       last is an integer output array of length nmax + 1. The */
     47: /*         index of num for the last occurrence of l is last(l) */
     48: /*         for any l = 0,1,...,nmax unless last(l) = 0. In */
     49: /*         this case l does not appear in num. */
     50: /*       next is an integer output array of length n. If */
     51: /*         num(k) = l, then the index of num for the previous */
     52: /*         occurrence of l is next(k) for any l = 0,1,...,nmax */
     53: /*         unless next(k) = 0. In this case there is no previous */
     54: /*         occurrence of l in num. */
     55: /*     Argonne National Laboratory. MINPACK Project. July 1983. */
     56: /*     Thomas F. Coleman, Burton S. Garbow, Jorge J. More' */

     58:   /* Parameter adjustments */
     60:   --next;
     61:   --idex;
     62:   --num;

     64:   i__1 = *nmax;
     65:   for (i = 0; i <= i__1; ++i) last[i] = 0;

     67:   i__1 = *n;
     68:   for (k = 1; k <= i__1; ++k) {
     69:     l       = num[k];
     70:     next[k] = last[l];
     71:     last[l] = k;
     72:   }
     73:   if (!*mode) return(0);

     75: /*     Store the pointers to the sorted array in index. */

     77:   i = 1;
     78:   if (*mode > 0) {
     79:     jl   = 0;
     80:     ju   = *nmax;
     81:     jinc = 1;
     82:   } else {
     83:     jl   = *nmax;
     84:     ju   = 0;
     85:     jinc = -1;
     86:   }
     87:   i__1 = ju;
     88:   i__2 = jinc;
     89:   for (j = jl; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
     90:     k = last[j];
     91: L30:
     92:     if (!k) goto L40;
     93:     idex[i] = k;
     94:     ++i;
     95:     k = next[k];
     96:     goto L30;
     97: L40:
     98:     ;
     99:   }
    100:   return(0);
    101: }