xand2.c 905 B

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