GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
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 SPDX-FileCopyrightText: 2001-2009 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author Original author CERL
10 */
11
12#include <grass/cluster.h>
13
14/*!
15 \brief Compute sum of squares for each class
16
17 \param C pointer to Cluster structure
18
19 \return 0
20 */
21int I_cluster_sum2(struct Cluster *C)
22{
23 int p, band, class;
24 double q;
25
26 G_debug(3, "I_cluster_sum2(npoints=%d,nclasses=%d,nbands=%d)", C->npoints,
27 C->nclasses, C->nbands);
28
29 for (class = 0; class < C->nclasses; class++)
30 for (band = 0; band < C->nbands; band++)
31 C->sum2[band][class] = 0;
32
33 for (p = 0; p < C->npoints; p++) {
34 class = C->class[p];
35 if (class < 0)
36 continue;
37 for (band = 0; band < C->nbands; band++) {
38 q = C->points[band][p];
39 C->sum2[band][class] += q * q;
40 }
41 }
42
43 return 0;
44}
int I_cluster_sum2(struct Cluster *C)
Compute sum of squares for each class.
Definition c_sum2.c:21
int G_debug(int, const char *,...) __attribute__((format(printf
double ** sum2
Definition cluster.h:22
int npoints
Definition cluster.h:9
int nclasses
Definition cluster.h:26
DCELL ** points
Definition cluster.h:10
int nbands
Definition cluster.h:8