GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
xisnull.c
Go to the documentation of this file.
1 #include <grass/gis.h>
2 #include <grass/raster.h>
3 #include <grass/calc.h>
4 
5 /**********************************************************************
6 isnull(x)
7  return 1 if x is null, 0 otherwise
8 **********************************************************************/
9 
10 int f_isnull(int argc, const int *argt, void **args)
11 {
12  int *res = args[0];
13  int i;
14 
15  if (argc < 1)
16  return E_ARG_LO;
17  if (argc > 1)
18  return E_ARG_HI;
19 
20  if (argt[0] != CELL_TYPE)
21  return E_RES_TYPE;
22 
23  switch (argt[1]) {
24  case CELL_TYPE: {
25  CELL *arg1 = args[1];
26 
27  for (i = 0; i < columns; i++)
28  res[i] = IS_NULL_C(&arg1[i]) ? 1 : 0;
29  return 0;
30  }
31  case FCELL_TYPE: {
32  FCELL *arg1 = args[1];
33 
34  for (i = 0; i < columns; i++)
35  res[i] = IS_NULL_F(&arg1[i]) ? 1 : 0;
36  return 0;
37  }
38  case DCELL_TYPE: {
39  DCELL *arg1 = args[1];
40 
41  for (i = 0; i < columns; i++)
42  res[i] = IS_NULL_D(&arg1[i]) ? 1 : 0;
43  return 0;
44  }
45  default:
46  return E_INV_TYPE;
47  }
48 }
49 
50 int c_isnull(int argc, int *argt)
51 {
52  if (argc < 1)
53  return E_ARG_LO;
54  if (argc > 1)
55  return E_ARG_HI;
56 
57  argt[0] = CELL_TYPE;
58 
59  return 0;
60 }
@ E_INV_TYPE
Definition: calc.h:15
@ E_RES_TYPE
Definition: calc.h:14
@ E_ARG_HI
Definition: calc.h:12
@ E_ARG_LO
Definition: calc.h:11
#define IS_NULL_C(x)
Definition: calc.h:26
int columns
Definition: calc.c:11
#define IS_NULL_F(x)
Definition: calc.h:27
#define IS_NULL_D(x)
Definition: calc.h:28
float FCELL
Definition: gis.h:630
double DCELL
Definition: gis.h:629
int CELL
Definition: gis.h:628
#define FCELL_TYPE
Definition: raster.h:12
#define DCELL_TYPE
Definition: raster.h:13
#define CELL_TYPE
Definition: raster.h:11
int f_isnull(int argc, const int *argt, void **args)
Definition: xisnull.c:10
int c_isnull(int argc, int *argt)
Definition: xisnull.c:50