GRASS GIS 7 Programmer's Manual
7.9.dev(2021)-e5379bbd7
xneg.c
Go to the documentation of this file.
1
2
#include <
grass/gis.h
>
3
#include <
grass/raster.h
>
4
#include <
grass/calc.h
>
5
6
/**********************************************************************
7
neg(x) = -x
8
**********************************************************************/
9
10
int
f_neg
(
int
argc,
const
int
*argt,
void
**args)
11
{
12
int
i;
13
14
if
(argc < 1)
15
return
E_ARG_LO
;
16
if
(argc > 1)
17
return
E_ARG_HI
;
18
19
if
(argt[0] != argt[1])
20
return
E_RES_TYPE
;
21
22
switch
(argt[1]) {
23
case
CELL_TYPE
:
24
{
25
CELL
*res = args[0];
26
CELL
*arg1 = args[1];
27
28
for
(i = 0; i <
columns
; i++)
29
if
(
IS_NULL_C
(&arg1[i]))
30
SET_NULL_C
(&res[i]);
31
else
32
res[i] = -arg1[i];
33
return
0;
34
}
35
case
FCELL_TYPE
:
36
{
37
FCELL
*res = args[0];
38
FCELL
*arg1 = args[1];
39
40
for
(i = 0; i <
columns
; i++)
41
if
(
IS_NULL_F
(&arg1[i]))
42
SET_NULL_F
(&res[i]);
43
else
44
res[i] = -arg1[i];
45
return
0;
46
}
47
case
DCELL_TYPE
:
48
{
49
DCELL
*res = args[0];
50
DCELL
*arg1 = args[1];
51
52
for
(i = 0; i <
columns
; i++)
53
if
(
IS_NULL_D
(&arg1[i]))
54
SET_NULL_D
(&res[i]);
55
else
56
res[i] = -arg1[i];
57
return
0;
58
}
59
default
:
60
return
E_INV_TYPE
;
61
}
62
}
CELL_TYPE
#define CELL_TYPE
Definition:
raster.h:11
f_neg
int f_neg(int argc, const int *argt, void **args)
Definition:
xneg.c:10
SET_NULL_C
#define SET_NULL_C(x)
Definition:
calc.h:32
DCELL
double DCELL
Definition:
gis.h:603
IS_NULL_F
#define IS_NULL_F(x)
Definition:
calc.h:29
IS_NULL_C
#define IS_NULL_C(x)
Definition:
calc.h:28
E_ARG_HI
Definition:
calc.h:13
columns
int columns
Definition:
calc.c:12
raster.h
gis.h
DCELL_TYPE
#define DCELL_TYPE
Definition:
raster.h:13
E_ARG_LO
Definition:
calc.h:12
FCELL
float FCELL
Definition:
gis.h:604
IS_NULL_D
#define IS_NULL_D(x)
Definition:
calc.h:30
CELL
int CELL
Definition:
gis.h:602
E_INV_TYPE
Definition:
calc.h:16
FCELL_TYPE
#define FCELL_TYPE
Definition:
raster.h:12
E_RES_TYPE
Definition:
calc.h:15
SET_NULL_F
#define SET_NULL_F(x)
Definition:
calc.h:33
SET_NULL_D
#define SET_NULL_D(x)
Definition:
calc.h:34
calc.h
lib
calc
xneg.c
Generated on Mon May 31 2021 05:21:32 for GRASS GIS 7 Programmer's Manual by
1.8.13