1 : |
agomez |
1 |
#include "areatime.h" |
2 : |
|
|
#include "errorhandler.h" |
3 : |
|
|
#include "likelihoodprinter.h" |
4 : |
|
|
#include "charptrvector.h" |
5 : |
|
|
#include "readword.h" |
6 : |
|
|
#include "gadget.h" |
7 : |
|
|
#include "runid.h" |
8 : |
|
|
#include "global.h" |
9 : |
|
|
|
10 : |
|
|
|
11 : |
|
|
LikelihoodPrinter::LikelihoodPrinter(CommentStream& infile, const TimeClass* const TimeInfo)
|
12 : |
|
|
: Printer(LIKELIHOODPRINTER) {
|
13 : |
|
|
|
14 : |
|
|
int i = 0;
|
15 : |
|
|
char text[MaxStrLength];
|
16 : |
|
|
strncpy(text, "", MaxStrLength);
|
17 : |
|
|
printtimeid = 0;
|
18 : |
|
|
|
19 : |
|
|
//read in the names of the likelihood components
|
20 : |
|
|
infile >> text >> ws;
|
21 : |
|
|
if (strcasecmp(text, "likelihood") != 0)
|
22 : |
|
|
handle.logFileUnexpected(LOGFAIL, "likelihood", text);
|
23 : |
|
|
infile >> text >> ws;
|
24 : |
|
|
while (!infile.eof() && (strcasecmp(text, "printfile") != 0)) {
|
25 : |
|
|
likenames.resize(new char[strlen(text) + 1]);
|
26 : |
|
|
strcpy(likenames[i++], text);
|
27 : |
|
|
infile >> text >> ws;
|
28 : |
|
|
}
|
29 : |
|
|
if (likenames.Size() == 0)
|
30 : |
|
|
handle.logFileMessage(LOGFAIL, "\nError in likelihoodprinter - failed to read component");
|
31 : |
|
|
|
32 : |
|
|
//read the name of the printfile, and then open the printfile
|
33 : |
|
|
filename = new char[MaxStrLength];
|
34 : |
|
|
strncpy(filename, "", MaxStrLength);
|
35 : |
|
|
|
36 : |
|
|
if (strcasecmp(text, "printfile") != 0)
|
37 : |
|
|
handle.logFileUnexpected(LOGFAIL, "printfile", text);
|
38 : |
|
|
infile >> filename >> ws;
|
39 : |
|
|
outfile.open(filename, ios::out);
|
40 : |
|
|
handle.checkIfFailure(outfile, filename);
|
41 : |
|
|
|
42 : |
|
|
//JMB - removed the need to read in the yearsandsteps data
|
43 : |
|
|
infile >> ws;
|
44 : |
|
|
if (!infile.eof()) {
|
45 : |
|
|
char c = infile.peek();
|
46 : |
|
|
if ((c == 'y') || (c == 'Y')) {
|
47 : |
|
|
infile >> text >> ws;
|
48 : |
|
|
if (strcasecmp(text, "yearsandsteps") == 0) {
|
49 : |
|
|
handle.logMessage(LOGWARN, "Warning in likelihoodprinter - yearsandsteps data ignored");
|
50 : |
|
|
AAT.readFromFile(infile, TimeInfo);
|
51 : |
|
|
}
|
52 : |
|
|
}
|
53 : |
|
|
}
|
54 : |
|
|
|
55 : |
|
|
//prepare for next printfile component
|
56 : |
|
|
infile >> ws;
|
57 : |
|
|
if (!infile.eof()) {
|
58 : |
|
|
infile >> text >> ws;
|
59 : |
|
|
if (strcasecmp(text, "[component]") != 0)
|
60 : |
|
|
handle.logFileUnexpected(LOGFAIL, "[component]", text);
|
61 : |
|
|
}
|
62 : |
|
|
}
|
63 : |
|
|
|
64 : |
|
|
LikelihoodPrinter::~LikelihoodPrinter() {
|
65 : |
|
|
outfile.close();
|
66 : |
|
|
outfile.clear();
|
67 : |
|
|
int i;
|
68 : |
|
|
for (i = 0; i < likenames.Size(); i++)
|
69 : |
|
|
delete[] likenames[i];
|
70 : |
|
|
}
|
71 : |
|
|
|
72 : |
|
|
void LikelihoodPrinter::setLikelihood(LikelihoodPtrVector& likevec) {
|
73 : |
|
|
int i, j;
|
74 : |
|
|
|
75 : |
|
|
for (i = 0; i < likevec.Size(); i++)
|
76 : |
|
|
for (j = 0; j < likenames.Size(); j++)
|
77 : |
|
|
if (strcasecmp(likevec[i]->getName(), likenames[j]) == 0)
|
78 : |
|
|
like.resize(likevec[i]);
|
79 : |
|
|
|
80 : |
|
|
if (like.Size() != likenames.Size()) {
|
81 : |
|
|
handle.logMessage(LOGWARN, "Error in likelihoodprinter - failed to match likelihood components");
|
82 : |
|
|
for (i = 0; i < like.Size(); i++)
|
83 : |
|
|
handle.logMessage(LOGWARN, "Error in likelihoodprinter - found component", like[i]->getName());
|
84 : |
|
|
for (i = 0; i < likenames.Size(); i++)
|
85 : |
|
|
handle.logMessage(LOGWARN, "Error in likelihoodprinter - looking for component", likenames[i]);
|
86 : |
|
|
handle.logMessage(LOGFAIL, ""); //JMB this will exit gadget
|
87 : |
|
|
}
|
88 : |
|
|
|
89 : |
|
|
outfile << "; ";
|
90 : |
|
|
RUNID.Print(outfile);
|
91 : |
|
|
|
92 : |
|
|
for (i = 0; i < like.Size(); i++) {
|
93 : |
|
|
outfile << "; Likelihood output file for the likelihood component " << like[i]->getName();
|
94 : |
|
|
switch (like[i]->getType()) {
|
95 : |
|
|
case CATCHDISTRIBUTIONLIKELIHOOD:
|
96 : |
|
|
outfile << "\n; year-step-area-age-length-number\n";
|
97 : |
|
|
break;
|
98 : |
|
|
case CATCHSTATISTICSLIKELIHOOD:
|
99 : |
|
|
outfile << "\n; year-step-area-age-number-mean[-stddev]\n";
|
100 : |
|
|
break;
|
101 : |
|
|
case CATCHINKILOSLIKELIHOOD:
|
102 : |
|
|
outfile << "\n; year-step-area-fleet-biomass\n";
|
103 : |
|
|
break;
|
104 : |
|
|
case SURVEYDISTRIBUTIONLIKELIHOOD:
|
105 : |
|
|
outfile << "\n; year-step-area-age-length-number\n";
|
106 : |
|
|
break;
|
107 : |
|
|
case STOCKDISTRIBUTIONLIKELIHOOD:
|
108 : |
|
|
outfile << "\n; year-step-area-stock-age-length-number\n";
|
109 : |
|
|
break;
|
110 : |
|
|
case STOMACHCONTENTLIKELIHOOD:
|
111 : |
|
|
outfile << "\n; year-step-area-predator-prey-number\n";
|
112 : |
|
|
break;
|
113 : |
|
|
case SURVEYINDICESLIKELIHOOD:
|
114 : |
|
|
outfile << "\n; year-step-area-label-number\n";
|
115 : |
|
|
break;
|
116 : |
|
|
case TAGLIKELIHOOD:
|
117 : |
|
|
outfile << "\n; tagid-year-step-area-length-number\n";
|
118 : |
|
|
break;
|
119 : |
|
|
case RECSTATISTICSLIKELIHOOD:
|
120 : |
|
|
outfile << "\n; tagid-year-step-area-number-mean[-stddev]\n";
|
121 : |
|
|
break;
|
122 : |
|
|
case MIGRATIONPROPORTIONLIKELIHOOD:
|
123 : |
|
|
outfile << "\n; year-step-area-ratio\n";
|
124 : |
|
|
break;
|
125 : |
|
|
case BOUNDLIKELIHOOD:
|
126 : |
|
|
case UNDERSTOCKINGLIKELIHOOD:
|
127 : |
|
|
case MIGRATIONPENALTYLIKELIHOOD:
|
128 : |
|
|
handle.logMessage(LOGWARN, "Warning in likelihoodprinter - printing not implemented for", like[i]->getName());
|
129 : |
|
|
break;
|
130 : |
|
|
default:
|
131 : |
|
|
handle.logMessage(LOGFAIL, "Error in likelihoodprinter - unrecognised likelihood type", like[i]->getType());
|
132 : |
|
|
break;
|
133 : |
|
|
}
|
134 : |
|
|
}
|
135 : |
|
|
outfile.flush();
|
136 : |
|
|
}
|
137 : |
|
|
|
138 : |
|
|
void LikelihoodPrinter::Print(const TimeClass* const TimeInfo, int printtime) {
|
139 : |
|
|
if (printtime != printtimeid)
|
140 : |
|
|
return;
|
141 : |
|
|
|
142 : |
|
|
int i;
|
143 : |
|
|
for (i = 0; i < like.Size(); i++)
|
144 : |
|
|
like[i]->printLikelihood(outfile, TimeInfo);
|
145 : |
|
|
outfile.flush();
|
146 : |
|
|
}
|