xneg.c 1.1 KB

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