GRASS 8 Programmer's Manual
8.6.0dev(2026)-ba898e78d7
Loading...
Searching...
No Matches
xmod.c
Go to the documentation of this file.
1
#include <math.h>
2
3
#include <
grass/gis.h
>
4
#include <
grass/raster.h
>
5
#include <
grass/calc.h
>
6
7
/****************************************************************
8
mod(a,b) = a % b
9
****************************************************************/
10
11
int
f_mod
(
int
argc
,
const
int
*
argt
,
void
**args)
12
{
13
int
i;
14
15
if
(
argc
< 2)
16
return
E_ARG_LO
;
17
if
(
argc
> 2)
18
return
E_ARG_HI
;
19
20
if
(
argt
[1] !=
argt
[0] ||
argt
[2] !=
argt
[0])
21
return
E_ARG_TYPE
;
22
23
switch
(
argt
[0]) {
24
case
CELL_TYPE
: {
25
CELL
*res = args[0];
26
CELL
*
arg1
= args[1];
27
CELL
*
arg2
= args[2];
28
29
for
(i = 0; i <
columns
; i++) {
30
if
(
IS_NULL_C
(&
arg1
[i]) ||
IS_NULL_C
(&
arg2
[i]) ||
arg2
[i] == 0)
31
SET_NULL_C
(&res[i]);
32
else
33
res[i] =
arg1
[i] %
arg2
[i];
34
}
35
return
0;
36
}
37
case
FCELL_TYPE
: {
38
FCELL
*res = args[0];
39
FCELL
*
arg1
= args[1];
40
FCELL
*
arg2
= args[2];
41
42
for
(i = 0; i <
columns
; i++) {
43
if
(
IS_NULL_F
(&
arg1
[i]) ||
IS_NULL_F
(&
arg2
[i]))
44
SET_NULL_F
(&res[i]);
45
else
46
res[i] = (
FCELL
)
fmod
(
arg1
[i],
arg2
[i]);
47
}
48
return
0;
49
}
50
case
DCELL_TYPE
: {
51
DCELL
*res = args[0];
52
DCELL
*
arg1
= args[1];
53
DCELL
*
arg2
= args[2];
54
55
for
(i = 0; i <
columns
; i++) {
56
if
(
IS_NULL_D
(&
arg1
[i]) ||
IS_NULL_D
(&
arg2
[i]))
57
SET_NULL_D
(&res[i]);
58
else
59
res[i] = (
DCELL
)
fmod
(
arg1
[i],
arg2
[i]);
60
}
61
return
0;
62
}
63
default
:
64
return
E_INV_TYPE
;
65
}
66
}
calc.h
E_INV_TYPE
@ E_INV_TYPE
Definition
calc.h:15
E_ARG_TYPE
@ E_ARG_TYPE
Definition
calc.h:13
E_ARG_HI
@ E_ARG_HI
Definition
calc.h:12
E_ARG_LO
@ E_ARG_LO
Definition
calc.h:11
IS_NULL_C
#define IS_NULL_C(x)
Definition
calc.h:26
SET_NULL_D
#define SET_NULL_D(x)
Definition
calc.h:32
columns
int columns
Definition
calc.c:5
SET_NULL_C
#define SET_NULL_C(x)
Definition
calc.h:30
IS_NULL_F
#define IS_NULL_F(x)
Definition
calc.h:27
IS_NULL_D
#define IS_NULL_D(x)
Definition
calc.h:28
SET_NULL_F
#define SET_NULL_F(x)
Definition
calc.h:31
AMI_STREAM
Definition
ami_stream.h:153
f_mod
func_t f_mod
gis.h
FCELL
float FCELL
Definition
gis.h:655
DCELL
double DCELL
Definition
gis.h:654
CELL
int CELL
Definition
gis.h:653
raster.h
FCELL_TYPE
#define FCELL_TYPE
Definition
raster.h:12
DCELL_TYPE
#define DCELL_TYPE
Definition
raster.h:13
CELL_TYPE
#define CELL_TYPE
Definition
raster.h:11
lib
calc
xmod.c
Generated on Tue Oct 13 2026 06:57:57 for GRASS 8 Programmer's Manual by
1.9.8