sum.c 764 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "kappa.h"
  2. #include "local_proto.h"
  3. /* function prototypes */
  4. static int same_cats(int a, int b, int nl);
  5. /* within group totals:
  6. *ns is the first stat
  7. (updated upon return to point to next stat)
  8. nl is the layer number (or level) */
  9. long count_sum(int *ns, int nl)
  10. {
  11. long count;
  12. int k, n;
  13. k = n = *ns;
  14. count = 0;
  15. if (nl >= 0) {
  16. while (n < nstats && same_cats(k, n, nl))
  17. count += Gstats[n++].count;
  18. }
  19. else {
  20. while (n < nstats)
  21. count += Gstats[n++].count;
  22. }
  23. *ns = n;
  24. return count;
  25. }
  26. static int same_cats(int a, int b, int nl)
  27. {
  28. long *cat_a, *cat_b;
  29. cat_a = Gstats[a].cats;
  30. cat_b = Gstats[b].cats;
  31. while (nl-- >= 0)
  32. if (*cat_a++ != *cat_b++)
  33. return 0;
  34. return 1;
  35. }