[mareframe] Annotation of /trunk/gadget/popstatistics.cc
Annotation of /trunk/gadget/popstatistics.cc
Parent Directory
| Revision Log
Revision 1 -
(view)
(download)
1 : |
agomez |
1 |
#include "popstatistics.h" |
2 : |
|
|
#include "popinfo.h" |
3 : |
|
|
#include "errorhandler.h" |
4 : |
|
|
#include "gadget.h" |
5 : |
|
|
#include "global.h" |
6 : |
|
|
|
7 : |
|
|
void PopStatistics::calcStatistics(const PopInfoIndexVector& pop,
|
8 : |
|
|
const LengthGroupDivision* const lgrpdiv, int calcweight) {
|
9 : |
|
|
|
10 : |
|
|
PopInfo sum;
|
11 : |
|
|
int i, offset;
|
12 : |
|
|
double tmp;
|
13 : |
|
|
|
14 : |
|
|
if (pop.Size() != lgrpdiv->numLengthGroups())
|
15 : |
|
|
handle.logMessage(LOGFAIL, "Error in popstatistics - length groups dont match population");
|
16 : |
|
|
|
17 : |
|
|
offset = pop.minCol();
|
18 : |
|
|
meanlength = meanweight = totalnumber = sdevlength = 0.0;
|
19 : |
|
|
for (i = offset; i < pop.maxCol(); i++) {
|
20 : |
|
|
if ((handle.getLogLevel() >= LOGWARN) && calcweight)
|
21 : |
|
|
if ((isZero(pop[i].W)) && (!(isZero(pop[i].N))))
|
22 : |
|
|
handle.logMessage(LOGWARN, "Warning in popstatistics - non-zero population has zero mean weight");
|
23 : |
|
|
|
24 : |
|
|
if (calcweight)
|
25 : |
|
|
sum += pop[i];
|
26 : |
|
|
totalnumber += pop[i].N;
|
27 : |
|
|
meanlength += pop[i].N * lgrpdiv->meanLength(i - offset);
|
28 : |
|
|
}
|
29 : |
|
|
|
30 : |
|
|
if (totalnumber > verysmall) {
|
31 : |
|
|
if (calcweight)
|
32 : |
|
|
meanweight = sum.W;
|
33 : |
|
|
meanlength /= totalnumber;
|
34 : |
|
|
for (i = offset; i < pop.maxCol(); i++) {
|
35 : |
|
|
tmp = meanlength - lgrpdiv->meanLength(i - offset);
|
36 : |
|
|
sdevlength += pop[i].N * tmp * tmp;
|
37 : |
|
|
}
|
38 : |
|
|
sdevlength = sqrt(sdevlength / totalnumber);
|
39 : |
|
|
} else {
|
40 : |
|
|
//JMB reset back to 0
|
41 : |
|
|
meanlength = 0.0;
|
42 : |
|
|
totalnumber = 0.0;
|
43 : |
|
|
}
|
44 : |
|
|
}
|
|