1 : |
agomez |
1 |
#include "areatime.h" |
2 : |
|
|
#include "errorhandler.h" |
3 : |
|
|
#include "summaryprinter.h" |
4 : |
|
|
#include "charptrvector.h" |
5 : |
|
|
#include "readword.h" |
6 : |
|
|
#include "gadget.h" |
7 : |
|
|
#include "runid.h" |
8 : |
|
|
#include "global.h" |
9 : |
|
|
|
10 : |
|
|
SummaryPrinter::SummaryPrinter(CommentStream& infile)
|
11 : |
|
|
: Printer(LIKELIHOODSUMMARYPRINTER) {
|
12 : |
|
|
|
13 : |
|
|
char text[MaxStrLength];
|
14 : |
|
|
strncpy(text, "", MaxStrLength);
|
15 : |
|
|
printtimeid = 0;
|
16 : |
|
|
|
17 : |
|
|
//Open the printfile
|
18 : |
|
|
filename = new char[MaxStrLength];
|
19 : |
|
|
strncpy(filename, "", MaxStrLength);
|
20 : |
|
|
readWordAndValue(infile, "printfile", filename);
|
21 : |
|
|
outfile.open(filename, ios::out);
|
22 : |
|
|
handle.checkIfFailure(outfile, filename);
|
23 : |
|
|
|
24 : |
|
|
outfile << "; ";
|
25 : |
|
|
RUNID.Print(outfile);
|
26 : |
|
|
// print header information
|
27 : |
|
|
outfile << "; Summary likelihood information from the current run" << endl
|
28 : |
|
|
<< "; year-step-area-component-weight-likelihood value" << endl;
|
29 : |
|
|
outfile.flush();
|
30 : |
|
|
|
31 : |
|
|
//prepare for next printfile component
|
32 : |
|
|
infile >> ws;
|
33 : |
|
|
if (!infile.eof()) {
|
34 : |
|
|
infile >> text >> ws;
|
35 : |
|
|
if (strcasecmp(text, "[component]") != 0)
|
36 : |
|
|
handle.logFileUnexpected(LOGFAIL, "[component]", text);
|
37 : |
|
|
}
|
38 : |
|
|
}
|
39 : |
|
|
|
40 : |
|
|
SummaryPrinter::~SummaryPrinter() {
|
41 : |
|
|
outfile.close();
|
42 : |
|
|
outfile.clear();
|
43 : |
|
|
}
|
44 : |
|
|
|
45 : |
|
|
void SummaryPrinter::setLikelihood(LikelihoodPtrVector& likevec) {
|
46 : |
|
|
int i;
|
47 : |
|
|
for (i = 0; i < likevec.Size(); i++)
|
48 : |
|
|
like.resize(likevec[i]);
|
49 : |
|
|
|
50 : |
|
|
for (i = 0; i < like.Size(); i++) {
|
51 : |
|
|
switch (like[i]->getType()) {
|
52 : |
|
|
case CATCHDISTRIBUTIONLIKELIHOOD:
|
53 : |
|
|
case CATCHSTATISTICSLIKELIHOOD:
|
54 : |
|
|
case CATCHINKILOSLIKELIHOOD:
|
55 : |
|
|
case SURVEYDISTRIBUTIONLIKELIHOOD:
|
56 : |
|
|
case STOCKDISTRIBUTIONLIKELIHOOD:
|
57 : |
|
|
case STOMACHCONTENTLIKELIHOOD:
|
58 : |
|
|
case SURVEYINDICESLIKELIHOOD:
|
59 : |
|
|
case UNDERSTOCKINGLIKELIHOOD:
|
60 : |
|
|
case BOUNDLIKELIHOOD:
|
61 : |
|
|
case MIGRATIONPENALTYLIKELIHOOD:
|
62 : |
|
|
case MIGRATIONPROPORTIONLIKELIHOOD:
|
63 : |
|
|
break;
|
64 : |
|
|
case TAGLIKELIHOOD:
|
65 : |
|
|
case RECSTATISTICSLIKELIHOOD:
|
66 : |
|
|
handle.logMessage(LOGWARN, "Warning in summaryprinter - printing incomplete for", like[i]->getName());
|
67 : |
|
|
break;
|
68 : |
|
|
default:
|
69 : |
|
|
handle.logMessage(LOGFAIL, "Error in summaryprinter - unrecognised likelihood type", like[i]->getType());
|
70 : |
|
|
break;
|
71 : |
|
|
}
|
72 : |
|
|
}
|
73 : |
|
|
}
|
74 : |
|
|
|
75 : |
|
|
void SummaryPrinter::Print(const TimeClass* const TimeInfo, int printtime) {
|
76 : |
|
|
if ((TimeInfo->getTime() != TimeInfo->numTotalSteps()) || (printtime != printtimeid))
|
77 : |
|
|
return;
|
78 : |
|
|
|
79 : |
|
|
int i;
|
80 : |
|
|
for (i = 0; i < like.Size(); i++)
|
81 : |
|
|
like[i]->printSummary(outfile);
|
82 : |
|
|
outfile.flush();
|
83 : |
|
|
}
|