xge.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <grass/gis.h>
  2. #include <grass/raster.h>
  3. #include <grass/calc.h>
  4. /****************************************************************
  5. ge(a,b) = a >= b
  6. ****************************************************************/
  7. int f_ge(int argc, const int *argt, void **args)
  8. {
  9. CELL *res = args[0];
  10. int i;
  11. if (argc < 2)
  12. return E_ARG_LO;
  13. if (argc > 2)
  14. return E_ARG_HI;
  15. switch (argt[1]) {
  16. case CELL_TYPE:
  17. {
  18. CELL *arg1 = args[1];
  19. CELL *arg2 = args[2];
  20. for (i = 0; i < columns; i++) {
  21. if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
  22. SET_NULL_C(&res[i]);
  23. else
  24. res[i] = arg1[i] >= arg2[i];
  25. }
  26. return 0;
  27. }
  28. case FCELL_TYPE:
  29. {
  30. FCELL *arg1 = args[1];
  31. FCELL *arg2 = args[2];
  32. for (i = 0; i < columns; i++) {
  33. if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
  34. SET_NULL_C(&res[i]);
  35. else
  36. res[i] = arg1[i] >= arg2[i];
  37. }
  38. return 0;
  39. }
  40. case DCELL_TYPE:
  41. {
  42. DCELL *arg1 = args[1];
  43. DCELL *arg2 = args[2];
  44. for (i = 0; i < columns; i++) {
  45. if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
  46. SET_NULL_C(&res[i]);
  47. else
  48. res[i] = arg1[i] >= arg2[i];
  49. }
  50. return 0;
  51. }
  52. default:
  53. return E_INV_TYPE;
  54. }
  55. }