GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-ab90c5e5a9
check.c
Go to the documentation of this file.
1 #include <grass/calc.h>
2 
3 int c_int0(int argc, int *argt)
4 {
5  if (argc > 0)
6  return E_ARG_HI;
7 
8  argt[0] = CELL_TYPE;
9 
10  return 0;
11 }
12 
13 int c_double0(int argc, int *argt)
14 {
15  if (argc > 0)
16  return E_ARG_HI;
17 
18  argt[0] = DCELL_TYPE;
19 
20  return 0;
21 }
22 
23 int c_double1(int argc, int *argt)
24 {
25  if (argc < 1)
26  return E_ARG_LO;
27  if (argc > 1)
28  return E_ARG_HI;
29 
30  argt[0] = DCELL_TYPE;
31  argt[1] = DCELL_TYPE;
32 
33  return 0;
34 }
35 
36 int c_double12(int argc, int *argt)
37 {
38  if (argc < 1)
39  return E_ARG_LO;
40 
41  if (argc > 2)
42  return E_ARG_HI;
43 
44  argt[0] = DCELL_TYPE;
45  argt[1] = DCELL_TYPE;
46  if (argc == 2)
47  argt[2] = DCELL_TYPE;
48 
49  return 0;
50 }
51 
52 int c_unop(int argc, int *argt)
53 {
54  if (argc < 1)
55  return E_ARG_LO;
56  if (argc > 1)
57  return E_ARG_HI;
58 
59  argt[0] = argt[1];
60 
61  return 0;
62 }
63 
64 int c_binop(int argc, int *argt)
65 {
66  if (argc < 2)
67  return E_ARG_LO;
68  if (argc > 2)
69  return E_ARG_HI;
70 
71  argt[0] = CELL_TYPE;
72  if (argt[1] == FCELL_TYPE || argt[2] == FCELL_TYPE)
73  argt[0] = FCELL_TYPE;
74  if (argt[1] == DCELL_TYPE || argt[2] == DCELL_TYPE)
75  argt[0] = DCELL_TYPE;
76 
77  argt[1] = argt[0];
78  argt[2] = argt[0];
79 
80  return 0;
81 }
82 
83 int c_varop(int argc, int *argt)
84 {
85  int i;
86 
87  if (argc < 1)
88  return E_ARG_LO;
89 
90  argt[0] = CELL_TYPE;
91 
92  for (i = 1; i <= argc; i++)
93  if (argt[i] == FCELL_TYPE)
94  argt[0] = FCELL_TYPE;
95 
96  for (i = 1; i <= argc; i++)
97  if (argt[i] == DCELL_TYPE)
98  argt[0] = DCELL_TYPE;
99 
100  for (i = 1; i <= argc; i++)
101  argt[i] = argt[0];
102 
103  return 0;
104 }
105 
106 int c_cmpop(int argc, int *argt)
107 {
108  int arg_type;
109 
110  if (argc < 2)
111  return E_ARG_LO;
112  if (argc > 2)
113  return E_ARG_HI;
114 
115  argt[0] = CELL_TYPE;
116 
117  arg_type = CELL_TYPE;
118  if (argt[1] == FCELL_TYPE || argt[2] == FCELL_TYPE)
119  arg_type = FCELL_TYPE;
120  if (argt[1] == DCELL_TYPE || argt[2] == DCELL_TYPE)
121  arg_type = DCELL_TYPE;
122 
123  argt[1] = arg_type;
124  argt[2] = arg_type;
125 
126  return 0;
127 }
128 
129 int c_logop(int argc, int *argt)
130 {
131  int i;
132 
133  if (argc < 1)
134  return E_ARG_LO;
135 
136  for (i = 1; i <= argc; i++)
137  if (argt[i] != CELL_TYPE)
138  return E_ARG_TYPE;
139 
140  argt[0] = CELL_TYPE;
141 
142  return 0;
143 }
144 
145 int c_shiftop(int argc, int *argt)
146 {
147  if (argc < 2)
148  return E_ARG_LO;
149  if (argc > 2)
150  return E_ARG_HI;
151 
152  if (argt[1] != CELL_TYPE || argt[2] != CELL_TYPE)
153  return E_ARG_TYPE;
154 
155  argt[0] = CELL_TYPE;
156 
157  return 0;
158 }
@ E_ARG_TYPE
Definition: calc.h:13
@ E_ARG_HI
Definition: calc.h:12
@ E_ARG_LO
Definition: calc.h:11
int c_varop(int argc, int *argt)
Definition: check.c:83
int c_binop(int argc, int *argt)
Definition: check.c:64
int c_double12(int argc, int *argt)
Definition: check.c:36
int c_int0(int argc, int *argt)
Definition: check.c:3
int c_double1(int argc, int *argt)
Definition: check.c:23
int c_logop(int argc, int *argt)
Definition: check.c:129
int c_double0(int argc, int *argt)
Definition: check.c:13
int c_unop(int argc, int *argt)
Definition: check.c:52
int c_cmpop(int argc, int *argt)
Definition: check.c:106
int c_shiftop(int argc, int *argt)
Definition: check.c:145
#define FCELL_TYPE
Definition: raster.h:12
#define DCELL_TYPE
Definition: raster.h:13
#define CELL_TYPE
Definition: raster.h:11