xge.c 1.2 KB

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