5 #include <grass/raster.h>
6 #include <grass/calc.h>
13 #define SIZE_THRESHOLD 32
15 static int dcmp(
const void *aa,
const void *bb)
27 static double mode(
double *value,
int argc)
38 qsort(value, argc,
sizeof(
double), dcmp);
40 for (i = 0; i < argc;) {
44 for (i++; i < argc; i++) {
60 int f_nmode(
int argc,
const int *argt,
void **args)
63 double *value = stack_value;
64 bool use_heap =
false;
65 int size = argc *
sizeof(double);
71 for (i = 1; i <= argc; i++)
72 if (argt[i] != argt[0])
76 value = G_malloc(size);
83 CELL **argv = (CELL **)&args[1];
88 for (j = 0; j < argc; j++) {
89 if (IS_NULL_C(&argv[j][i]))
91 value[n++] = (double)argv[j][i];
97 res[i] = (CELL)mode(value, n);
105 FCELL *res = args[0];
106 FCELL **argv = (FCELL **)&args[1];
108 for (i = 0; i <
columns; i++) {
111 for (j = 0; j < argc; j++) {
112 if (IS_NULL_F(&argv[j][i]))
114 value[n++] = (double)argv[j][i];
120 res[i] = (FCELL)mode(value, n);
128 DCELL *res = args[0];
129 DCELL **argv = (DCELL **)&args[1];
131 for (i = 0; i <
columns; i++) {
134 for (j = 0; j < argc; j++) {
135 if (IS_NULL_D(&argv[j][i]))
137 value[n++] = (double)argv[j][i];
143 res[i] = (DCELL)mode(value, n);
void G_free(void *buf)
Free allocated memory.
int f_nmode(int argc, const int *argt, void **args)