GRASS 8 Programmer's Manual
8.6.0dev(2026)-ba898e78d7
Loading...
Searching...
No Matches
xatan.c
Go to the documentation of this file.
1
#include <
stdlib.h
>
2
#include <math.h>
3
4
#include <
grass/gis.h
>
5
#include <
grass/raster.h
>
6
#include <
grass/calc.h
>
7
8
/**********************************************************************
9
atan(x) range [-90,90]
10
atan(x,y) = atan(y/x) range[0,360]
11
12
note: result is in degrees
13
**********************************************************************/
14
15
#define RADIANS_TO_DEGREES (180.0 / M_PI)
16
17
int
f_atan
(
int
argc
,
const
int
*
argt
,
void
**args)
18
{
19
DCELL
*res = args[0];
20
DCELL
*
arg1
= args[1];
21
DCELL
*
arg2
;
22
int
i;
23
24
if
(
argc
< 1)
25
return
E_ARG_LO
;
26
if
(
argc
> 2)
27
return
E_ARG_HI
;
28
29
if
(
argt
[0] !=
DCELL_TYPE
)
30
return
E_RES_TYPE
;
31
32
if
(
argt
[1] !=
DCELL_TYPE
)
33
return
E_ARG_TYPE
;
34
35
if
(
argc
> 1 &&
argt
[2] !=
DCELL_TYPE
)
36
return
E_ARG_TYPE
;
37
38
arg2
= (
argc
> 1) ? args[2] :
NULL
;
39
40
for
(i = 0; i <
columns
; i++)
41
if
(
IS_NULL_D
(&
arg1
[i]))
42
SET_NULL_D
(&res[i]);
43
else
if
(
argc
> 1 &&
IS_NULL_D
(&
arg2
[i]))
44
SET_NULL_D
(&res[i]);
45
46
else
{
47
if
(
argc
== 1)
48
res[i] =
RADIANS_TO_DEGREES
*
atan
(
arg1
[i]);
49
else
{
50
res[i] =
RADIANS_TO_DEGREES
*
atan2
(
arg2
[i],
arg1
[i]);
51
if
(res[i] < 0)
52
res[i] += 360.0;
53
}
54
}
55
56
return
0;
57
}
calc.h
E_RES_TYPE
@ E_RES_TYPE
Definition
calc.h:14
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
SET_NULL_D
#define SET_NULL_D(x)
Definition
calc.h:32
columns
int columns
Definition
calc.c:5
IS_NULL_D
#define IS_NULL_D(x)
Definition
calc.h:28
NULL
#define NULL
Definition
ccmath.h:32
AMI_STREAM
Definition
ami_stream.h:153
f_atan
func_t f_atan
gis.h
DCELL
double DCELL
Definition
gis.h:654
raster.h
DCELL_TYPE
#define DCELL_TYPE
Definition
raster.h:13
stdlib.h
RADIANS_TO_DEGREES
#define RADIANS_TO_DEGREES
Definition
xatan.c:15
lib
calc
xatan.c
Generated on Tue Oct 13 2026 06:57:57 for GRASS 8 Programmer's Manual by
1.9.8