GRASS GIS 8 Programmer's Manual 8.3.2(2024)-exported
Loading...
Searching...
No Matches
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 */
23int 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)", C->npoints,
29 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 I_cluster_sum2(struct Cluster *C)
Compute sum of squares for each class.
Definition c_sum2.c:23
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition debug.c:66