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