c_sum2.c 980 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*!
  2. \file cluster/c_sum2.c
  3. \brief Cluster library - Sum of squares
  4. (C) 2001-2009 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Original author CERL
  8. */
  9. #include <grass/cluster.h>
  10. /*!
  11. \brief Compute sum of squares for each class
  12. \param C pointer to Cluster structure
  13. \return 0
  14. */
  15. int I_cluster_sum2(struct Cluster *C)
  16. {
  17. int p, band, class;
  18. double q;
  19. G_debug(3, "I_cluster_sum2(npoints=%d,nclasses=%d,nbands=%d)",
  20. C->npoints, C->nclasses, C->nbands);
  21. for (class = 0; class < C->nclasses; class++)
  22. for (band = 0; band < C->nbands; band++)
  23. C->sum2[band][class] = 0;
  24. for (p = 0; p < C->npoints; p++) {
  25. class = C->class[p];
  26. if (class < 0)
  27. continue;
  28. for (band = 0; band < C->nbands; band++) {
  29. q = C->points[band][p];
  30. C->sum2[band][class] += q * q;
  31. }
  32. }
  33. return 0;
  34. }