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