File: sort_cell.c

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (65 lines) | stat: -rw-r--r-- 1,230 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdlib.h>

#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/stats.h>

static int ascending(const void *aa, const void *bb)
{
    const DCELL *a = aa, *b = bb;

    if (*a < *b)
        return -1;
    return (*a > *b);

    if (Rast_is_d_null_value((DCELL *)a) && Rast_is_d_null_value((DCELL *)b))
        return 0;

    if (Rast_is_d_null_value((DCELL *)a))
        return 1;

    if (Rast_is_d_null_value((DCELL *)b))
        return -1;

    return (*a < *b) ? -1 : (*a > *b) ? 1 : 0;
}

int sort_cell(DCELL *array, int n)
{
    int i, j;

    j = 0;
    for (i = 0; i < n; i++) {
        if (!Rast_is_d_null_value(&array[i])) {
            array[j] = array[i];
            j++;
        }
    }
    n = j;

    if (n > 0)
        qsort(array, n, sizeof(DCELL), ascending);

    return n;
}

int sort_cell_w(DCELL (*array)[2], int n)
{
    int i, j;

    j = 0;
    for (i = 0; i < n; i++) {
        if (!Rast_is_d_null_value(&array[i][0]) &&
            !Rast_is_d_null_value(&array[i][1])) {
            array[j][0] = array[i][0];
            array[j][1] = array[i][1];
            j++;
        }
    }
    n = j;

    if (n > 0)
        qsort(array, n, 2 * sizeof(DCELL), ascending);

    return n;
}