totals.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /****************************************************************************
  2. *
  3. * MODULE: r.coin
  4. *
  5. * AUTHOR(S): Michael O'Shea - CERL
  6. * Michael Shapiro - CERL
  7. *
  8. * PURPOSE: Calculates the coincidence of two raster map layers.
  9. *
  10. * COPYRIGHT: (C) 2006 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. ***************************************************************************/
  17. #include "coin.h"
  18. int row_total(int row, int with_no_data, long *count, double *area)
  19. {
  20. int col;
  21. struct stats_table *x;
  22. x = table + row * ncat1;
  23. *count = 0;
  24. *area = 0.0;
  25. for (col = 0; col < ncat1; col++) {
  26. if (with_no_data || (col != no_data1)) {
  27. *count += x->count;
  28. *area += x->area;
  29. }
  30. x += 1;
  31. }
  32. return 0;
  33. }
  34. int col_total(int col, int with_no_data, long *count, double *area)
  35. {
  36. int row;
  37. struct stats_table *x;
  38. x = table + col;
  39. *count = 0;
  40. *area = 0.0;
  41. for (row = 0; row < ncat2; row++) {
  42. if (with_no_data || (row != no_data2)) {
  43. *count += x->count;
  44. *area += x->area;
  45. }
  46. x += ncat1;
  47. }
  48. return 0;
  49. }