xbitor.c 795 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. bitor(a,b,c,...) = a | b | c | ...
  8. ****************************************************************/
  9. int f_bitor(int argc, const int *argt, void **args)
  10. {
  11. CELL *res = args[0];
  12. CELL **argz = (CELL **) args;
  13. int i, j;
  14. if (argc < 1)
  15. return E_ARG_LO;
  16. if (argt[0] != CELL_TYPE)
  17. return E_RES_TYPE;
  18. for (i = 1; i <= argc; i++)
  19. if (argt[i] != CELL_TYPE)
  20. return E_ARG_TYPE;
  21. for (i = 0; i < columns; i++) {
  22. res[i] = 0;
  23. for (j = 1; j <= argc; j++) {
  24. if (IS_NULL_C(&argz[j][i])) {
  25. SET_NULL_C(&res[i]);
  26. break;
  27. }
  28. res[i] |= argz[j][i];
  29. }
  30. }
  31. return 0;
  32. }