1 : |
agomez |
1 |
#include "stockaggregator.h" |
2 : |
|
|
#include "conversionindex.h" |
3 : |
|
|
#include "stock.h" |
4 : |
|
|
#include "mathfunc.h" |
5 : |
|
|
#include "errorhandler.h" |
6 : |
|
|
#include "gadget.h" |
7 : |
|
|
#include "global.h" |
8 : |
|
|
|
9 : |
|
|
StockAggregator::StockAggregator(const StockPtrVector& Stocks,
|
10 : |
|
|
const LengthGroupDivision* const LgrpDiv, const IntMatrix& Areas, const IntMatrix& Ages)
|
11 : |
|
|
: stocks(Stocks), areas(Areas), ages(Ages), alptr(0) {
|
12 : |
|
|
|
13 : |
|
|
int i;
|
14 : |
|
|
for (i = 0; i < stocks.Size(); i++) {
|
15 : |
|
|
CI.resize(new ConversionIndex(stocks[i]->getLengthGroupDiv(), LgrpDiv));
|
16 : |
|
|
if (CI[i]->Error())
|
17 : |
|
|
handle.logMessage(LOGFAIL, "Error in stockaggregator - error when checking length structure");
|
18 : |
|
|
}
|
19 : |
|
|
|
20 : |
|
|
//Resize total using dummy variables tmppop and popmatrix.
|
21 : |
|
|
PopInfo tmppop;
|
22 : |
|
|
tmppop.N = 1.0;
|
23 : |
|
|
PopInfoMatrix popmatrix(ages.Nrow(), LgrpDiv->numLengthGroups(), tmppop);
|
24 : |
|
|
total.resize(areas.Nrow(), 0, 0, popmatrix);
|
25 : |
|
|
this->Reset();
|
26 : |
|
|
}
|
27 : |
|
|
|
28 : |
|
|
StockAggregator::~StockAggregator() {
|
29 : |
|
|
int i;
|
30 : |
|
|
for (i = 0; i < CI.Size(); i++)
|
31 : |
|
|
delete CI[i];
|
32 : |
|
|
}
|
33 : |
|
|
|
34 : |
|
|
void StockAggregator::Print(ofstream& outfile) const {
|
35 : |
|
|
int i, j;
|
36 : |
|
|
for (i = 0; i < total.Size(); i++) {
|
37 : |
|
|
outfile << "\tInternal areas";
|
38 : |
|
|
for (j = 0; j < areas.Ncol(i); j++)
|
39 : |
|
|
outfile << sep << areas[i][j];
|
40 : |
|
|
outfile << endl;
|
41 : |
|
|
total[i].printNumbers(outfile);
|
42 : |
|
|
}
|
43 : |
|
|
outfile.flush();
|
44 : |
|
|
}
|
45 : |
|
|
|
46 : |
|
|
void StockAggregator::Reset() {
|
47 : |
|
|
int i;
|
48 : |
|
|
for (i = 0; i < total.Size(); i++)
|
49 : |
|
|
total[i].setToZero();
|
50 : |
|
|
}
|
51 : |
|
|
|
52 : |
|
|
void StockAggregator::Sum() {
|
53 : |
|
|
int area, age, i, j, k;
|
54 : |
|
|
|
55 : |
|
|
this->Reset();
|
56 : |
|
|
//Sum over the appropriate stocks, areas, ages and length groups.
|
57 : |
|
|
for (i = 0; i < stocks.Size(); i++) {
|
58 : |
|
|
for (area = 0; area < areas.Nrow(); area++) {
|
59 : |
|
|
for (j = 0; j < areas.Ncol(area); j++) {
|
60 : |
|
|
if (stocks[i]->isInArea(areas[area][j])) {
|
61 : |
|
|
alptr = &stocks[i]->getCurrentALK(areas[area][j]);
|
62 : |
|
|
for (age = 0; age < ages.Nrow(); age++) {
|
63 : |
|
|
for (k = 0; k < ages.Ncol(age); k++) {
|
64 : |
|
|
if ((alptr->minAge() <= ages[age][k]) && (ages[age][k] <= alptr->maxAge()))
|
65 : |
|
|
total[area][age].Add((*alptr)[ages[age][k]], *CI[i]);
|
66 : |
|
|
}
|
67 : |
|
|
}
|
68 : |
|
|
}
|
69 : |
|
|
}
|
70 : |
|
|
}
|
71 : |
|
|
}
|
72 : |
|
|
}
|