xand2.c 950 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <grass/gis.h>
  2. #include <grass/raster.h>
  3. #include "globals.h"
  4. #include "expression.h"
  5. #include "func_proto.h"
  6. /****************************************************************
  7. and2(a,b,c,...) = a && b && c && ...
  8. Differs from and() in that the boolean axioms:
  9. false && x == false
  10. x && false == false
  11. hold even when x is null.
  12. ****************************************************************/
  13. int f_and2(int argc, const int *argt, void **args)
  14. {
  15. CELL *res = args[0];
  16. CELL **argz = (CELL **) args;
  17. int i, j;
  18. if (argc < 1)
  19. return E_ARG_LO;
  20. if (argt[0] != CELL_TYPE)
  21. return E_RES_TYPE;
  22. for (i = 1; i <= argc; i++)
  23. if (argt[i] != CELL_TYPE)
  24. return E_ARG_TYPE;
  25. for (i = 0; i < columns; i++) {
  26. res[i] = 1;
  27. for (j = 1; j <= argc; j++) {
  28. if (!IS_NULL_C(&argz[j][i]) && !argz[j][i]) {
  29. res[i] = 0;
  30. break;
  31. }
  32. if (IS_NULL_C(&argz[j][i]))
  33. SET_NULL_C(&res[i]);
  34. }
  35. }
  36. return 0;
  37. }