xbitor.c 750 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <grass/gis.h>
  2. #include <grass/raster.h>
  3. #include <grass/calc.h>
  4. /****************************************************************
  5. bitor(a,b,c,...) = a | b | c | ...
  6. ****************************************************************/
  7. int f_bitor(int argc, const int *argt, void **args)
  8. {
  9. CELL *res = args[0];
  10. CELL **argz = (CELL **) args;
  11. int i, j;
  12. if (argc < 1)
  13. return E_ARG_LO;
  14. if (argt[0] != CELL_TYPE)
  15. return E_RES_TYPE;
  16. for (i = 1; i <= argc; i++)
  17. if (argt[i] != CELL_TYPE)
  18. return E_ARG_TYPE;
  19. for (i = 0; i < columns; i++) {
  20. res[i] = 0;
  21. for (j = 1; j <= argc; j++) {
  22. if (IS_NULL_C(&argz[j][i])) {
  23. SET_NULL_C(&res[i]);
  24. break;
  25. }
  26. res[i] |= argz[j][i];
  27. }
  28. }
  29. return 0;
  30. }