1 : |
agomez |
1 |
#include "sibyageonstep.h" |
2 : |
|
|
#include "stock.h" |
3 : |
|
|
#include "areatime.h" |
4 : |
|
|
#include "mathfunc.h" |
5 : |
|
|
#include "errorhandler.h" |
6 : |
|
|
#include "gadget.h" |
7 : |
|
|
#include "global.h" |
8 : |
|
|
|
9 : |
|
|
SIByAgeOnStep::SIByAgeOnStep(CommentStream& infile, const IntMatrix& areas,
|
10 : |
|
|
const IntMatrix& ages, const CharPtrVector& areaindex, const CharPtrVector& ageindex,
|
11 : |
|
|
const TimeClass* const TimeInfo, const char* datafilename, const char* givenname, int bio)
|
12 : |
|
|
: SIOnStep(infile, datafilename, areaindex, TimeInfo, areas, ageindex, givenname, bio, SIAGE) {
|
13 : |
|
|
|
14 : |
|
|
Ages = ages;
|
15 : |
|
|
}
|
16 : |
|
|
|
17 : |
|
|
SIByAgeOnStep::~SIByAgeOnStep() {
|
18 : |
|
|
if (aggregator != 0)
|
19 : |
|
|
delete aggregator;
|
20 : |
|
|
}
|
21 : |
|
|
|
22 : |
|
|
void SIByAgeOnStep::setFleetsAndStocks(FleetPtrVector& Fleets, StockPtrVector& Stocks) {
|
23 : |
|
|
int i, j, found, minage, maxage;
|
24 : |
|
|
double minlength, maxlength;
|
25 : |
|
|
|
26 : |
|
|
if (Stocks.Size() == 0)
|
27 : |
|
|
handle.logMessage(LOGFAIL, "Error in surveyindex - failed to initialise stock data");
|
28 : |
|
|
|
29 : |
|
|
minlength = Stocks[0]->getLengthGroupDiv()->minLength();
|
30 : |
|
|
maxlength = Stocks[0]->getLengthGroupDiv()->maxLength();
|
31 : |
|
|
if (Stocks.Size() > 1) {
|
32 : |
|
|
for (i = 1; i < Stocks.Size(); i++) {
|
33 : |
|
|
minlength = min(Stocks[i]->getLengthGroupDiv()->minLength(), minlength);
|
34 : |
|
|
maxlength = max(Stocks[i]->getLengthGroupDiv()->maxLength(), maxlength);
|
35 : |
|
|
}
|
36 : |
|
|
}
|
37 : |
|
|
|
38 : |
|
|
LgrpDiv = new LengthGroupDivision(minlength, maxlength, maxlength - minlength);
|
39 : |
|
|
if (LgrpDiv->Error())
|
40 : |
|
|
handle.logMessage(LOGFAIL, "Error in surveyindex - failed to create length group");
|
41 : |
|
|
|
42 : |
|
|
//check stock ages
|
43 : |
|
|
if (handle.getLogLevel() >= LOGWARN) {
|
44 : |
|
|
minage = 9999;
|
45 : |
|
|
maxage = 0;
|
46 : |
|
|
for (i = 0; i < Ages.Nrow(); i++) {
|
47 : |
|
|
for (j = 0; j < Ages.Ncol(i); j++) {
|
48 : |
|
|
minage = min(Ages[i][j], minage);
|
49 : |
|
|
maxage = max(Ages[i][j], maxage);
|
50 : |
|
|
}
|
51 : |
|
|
}
|
52 : |
|
|
|
53 : |
|
|
found = 0;
|
54 : |
|
|
for (i = 0; i < Stocks.Size(); i++)
|
55 : |
|
|
if (minage >= Stocks[i]->minAge())
|
56 : |
|
|
found++;
|
57 : |
|
|
if (found == 0)
|
58 : |
|
|
handle.logMessage(LOGWARN, "Warning in surveyindex - minimum age less than stock age");
|
59 : |
|
|
|
60 : |
|
|
found = 0;
|
61 : |
|
|
for (i = 0; i < Stocks.Size(); i++)
|
62 : |
|
|
if (maxage <= Stocks[i]->maxAge())
|
63 : |
|
|
found++;
|
64 : |
|
|
if (found == 0)
|
65 : |
|
|
handle.logMessage(LOGWARN, "Warning in surveyindex - maximum age greater than stock age");
|
66 : |
|
|
}
|
67 : |
|
|
|
68 : |
|
|
aggregator = new StockAggregator(Stocks, LgrpDiv, Areas, Ages);
|
69 : |
|
|
}
|
70 : |
|
|
|
71 : |
|
|
void SIByAgeOnStep::Sum(const TimeClass* const TimeInfo) {
|
72 : |
|
|
if (!AAT.atCurrentTime(TimeInfo))
|
73 : |
|
|
return;
|
74 : |
|
|
|
75 : |
|
|
int a, i;
|
76 : |
|
|
timeindex = -1;
|
77 : |
|
|
for (i = 0; i < Years.Size(); i++)
|
78 : |
|
|
if ((Years[i] == TimeInfo->getYear()) && (Steps[i] == TimeInfo->getStep()))
|
79 : |
|
|
timeindex = i;
|
80 : |
|
|
if (timeindex == -1)
|
81 : |
|
|
handle.logMessage(LOGFAIL, "Error in surveyindex - invalid timestep");
|
82 : |
|
|
|
83 : |
|
|
if (handle.getLogLevel() >= LOGMESSAGE)
|
84 : |
|
|
handle.logMessage(LOGMESSAGE, "Calculating index for surveyindex component", this->getName());
|
85 : |
|
|
|
86 : |
|
|
aggregator->Sum();
|
87 : |
|
|
alptr = &aggregator->getSum();
|
88 : |
|
|
//alptr will only have one length group
|
89 : |
|
|
for (a = 0; a < Areas.Nrow(); a++)
|
90 : |
|
|
for (i = 0; i < Ages.Nrow(); i++)
|
91 : |
|
|
(*modelIndex[timeindex])[a][i] = (*alptr)[a][i][0].N;
|
92 : |
|
|
|
93 : |
|
|
if (biomass) //JMB experimental survey index based on the biomass
|
94 : |
|
|
for (a = 0; a < Areas.Nrow(); a++)
|
95 : |
|
|
for (i = 0; i < Ages.Nrow(); i++)
|
96 : |
|
|
(*modelIndex[timeindex])[a][i] *= (*alptr)[a][i][0].W;
|
97 : |
|
|
}
|