GRASS 8 Programmer's Manual
8.6.0dev(2026)-ba898e78d7
Loading...
Searching...
No Matches
xlog.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
log(x)
9
log(x,b)
10
11
first form computes the natural log of x = ln(x)
12
second form computes log of x base b = ln(x)/ln(b)
13
14
if x is non-positive, the result is NULL
15
16
if b is non-positive, or 1.0, the result is NULL
17
**********************************************************************/
18
19
int
f_log
(
int
argc
,
const
int
*
argt
,
void
**args)
20
{
21
DCELL
*res = args[0];
22
DCELL
*
arg1
= args[1];
23
DCELL
*
arg2
= (
argc
>= 2) ? args[2] : (
DCELL
*)0;
24
int
i;
25
26
if
(
argc
< 1)
27
return
E_ARG_LO
;
28
29
if
(
argc
> 2)
30
return
E_ARG_HI
;
31
32
if
(
argt
[0] !=
DCELL_TYPE
)
33
return
E_RES_TYPE
;
34
35
if
(
argt
[1] !=
DCELL_TYPE
)
36
return
E_ARG_TYPE
;
37
38
if
(
argc
> 1 &&
argt
[2] !=
DCELL_TYPE
)
39
return
E_ARG_TYPE
;
40
41
for
(i = 0; i <
columns
; i++)
42
if
(
IS_NULL_D
(&
arg1
[i]) || (
arg1
[i] <= 0.0))
43
SET_NULL_D
(&res[i]);
44
else
if
(
argc
> 1 && (
IS_NULL_D
(&
arg2
[i]) || (
arg2
[i] <= 0.0)))
45
SET_NULL_D
(&res[i]);
46
else
47
res[i] = (
argc
> 1) ?
log
(
arg1
[i]) /
log
(
arg2
[i]) :
log
(
arg1
[i]);
48
49
return
0;
50
}
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
AMI_STREAM
Definition
ami_stream.h:153
f_log
func_t f_log
gis.h
DCELL
double DCELL
Definition
gis.h:654
raster.h
DCELL_TYPE
#define DCELL_TYPE
Definition
raster.h:13
lib
calc
xlog.c
Generated on Tue Oct 13 2026 06:57:57 for GRASS 8 Programmer's Manual by
1.9.8