xeq.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. eq(a,b) = a == b
  8. ****************************************************************/
  9. int f_eq(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. if (argt[0] != CELL_TYPE)
  18. return E_RES_TYPE;
  19. for (i = 2; i <= argc; i++)
  20. if (argt[i] != argt[1])
  21. return E_ARG_TYPE;
  22. switch (argt[1]) {
  23. case CELL_TYPE:
  24. {
  25. CELL *arg1 = args[1];
  26. CELL *arg2 = args[2];
  27. for (i = 0; i < columns; i++) {
  28. if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
  29. SET_NULL_C(&res[i]);
  30. else
  31. res[i] = arg1[i] == arg2[i];
  32. }
  33. return 0;
  34. }
  35. case FCELL_TYPE:
  36. {
  37. FCELL *arg1 = args[1];
  38. FCELL *arg2 = args[2];
  39. for (i = 0; i < columns; i++) {
  40. if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
  41. SET_NULL_C(&res[i]);
  42. else
  43. res[i] = arg1[i] == arg2[i];
  44. }
  45. return 0;
  46. }
  47. case DCELL_TYPE:
  48. {
  49. DCELL *arg1 = args[1];
  50. DCELL *arg2 = args[2];
  51. for (i = 0; i < columns; i++) {
  52. if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
  53. SET_NULL_C(&res[i]);
  54. else
  55. res[i] = arg1[i] == arg2[i];
  56. }
  57. return 0;
  58. }
  59. default:
  60. return E_INV_TYPE;
  61. }
  62. }