GRASS GIS 8 Programmer's Manual 8.4.1(2025)-45ca3179ab
Loading...
Searching...
No Matches
sort_cell.c
Go to the documentation of this file.
1#include <stdlib.h>
2
3#include <grass/gis.h>
4#include <grass/raster.h>
5#include <grass/stats.h>
6
7static int ascending(const void *aa, const void *bb)
8{
9 const DCELL *a = aa, *b = bb;
10
11 if (*a < *b)
12 return -1;
13 return (*a > *b);
14
15 if (Rast_is_d_null_value((DCELL *)a) && Rast_is_d_null_value((DCELL *)b))
16 return 0;
17
18 if (Rast_is_d_null_value((DCELL *)a))
19 return 1;
20
21 if (Rast_is_d_null_value((DCELL *)b))
22 return -1;
23
24 return (*a < *b) ? -1 : (*a > *b) ? 1 : 0;
25}
26
27int sort_cell(DCELL *array, int n)
28{
29 int i, j;
30
31 j = 0;
32 for (i = 0; i < n; i++) {
33 if (!Rast_is_d_null_value(&array[i])) {
34 array[j] = array[i];
35 j++;
36 }
37 }
38 n = j;
39
40 if (n > 0)
41 qsort(array, n, sizeof(DCELL), ascending);
42
43 return n;
44}
45
46int sort_cell_w(DCELL (*array)[2], int n)
47{
48 int i, j;
49
50 j = 0;
51 for (i = 0; i < n; i++) {
52 if (!Rast_is_d_null_value(&array[i][0]) &&
53 !Rast_is_d_null_value(&array[i][1])) {
54 array[j][0] = array[i][0];
55 array[j][1] = array[i][1];
56 j++;
57 }
58 }
59 n = j;
60
61 if (n > 0)
62 qsort(array, n, 2 * sizeof(DCELL), ascending);
63
64 return n;
65}
double b
int sort_cell(DCELL *array, int n)
Definition sort_cell.c:27
int sort_cell_w(DCELL(*array)[2], int n)
Definition sort_cell.c:46