xshiftr.c 791 B

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