GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71806
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
c_sum2.c
Go to the documentation of this file.
1 /*!
2  \file cluster/c_sum2.c
3 
4  \brief Cluster library - Sum of squares
5 
6  (C) 2001-2009 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Original author CERL
12 */
13 
14 #include <grass/cluster.h>
15 
16 /*!
17  \brief Compute sum of squares for each class
18 
19  \param C pointer to Cluster structure
20 
21  \return 0
22 */
23 int I_cluster_sum2(struct Cluster *C)
24 {
25  int p, band, class;
26  double q;
27 
28  G_debug(3, "I_cluster_sum2(npoints=%d,nclasses=%d,nbands=%d)",
29  C->npoints, C->nclasses, C->nbands);
30 
31  for (class = 0; class < C->nclasses; class++)
32  for (band = 0; band < C->nbands; band++)
33  C->sum2[band][class] = 0;
34 
35  for (p = 0; p < C->npoints; p++) {
36  class = C->class[p];
37  if (class < 0)
38  continue;
39  for (band = 0; band < C->nbands; band++) {
40  q = C->points[band][p];
41  C->sum2[band][class] += q * q;
42  }
43  }
44 
45  return 0;
46 }
int nbands
Definition: cluster.h:9
int nclasses
Definition: cluster.h:27
Definition: cluster.h:7
int npoints
Definition: cluster.h:10
double ** sum2
Definition: cluster.h:23
DCELL ** points
Definition: cluster.h:11
for(cat=0;;cat++)
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: debug.c:65
int I_cluster_sum2(struct Cluster *C)
Compute sum of squares for each class.
Definition: c_sum2.c:23