xceil.c 1.2 KB

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