1 : |
agomez |
1 |
#include "readaggregation.h" |
2 : |
|
|
#include "readfunc.h" |
3 : |
|
|
#include "errorhandler.h" |
4 : |
|
|
#include "gadget.h" |
5 : |
|
|
#include "global.h" |
6 : |
|
|
|
7 : |
|
|
int readAggregation(CommentStream& infile, IntMatrix& agg, CharPtrVector& aggindex) {
|
8 : |
|
|
int i, j, tmp;
|
9 : |
|
|
char text[MaxStrLength];
|
10 : |
|
|
strncpy(text, "", MaxStrLength);
|
11 : |
|
|
|
12 : |
|
|
agg.Reset();
|
13 : |
|
|
aggindex.Reset();
|
14 : |
|
|
i = tmp = 0;
|
15 : |
|
|
infile >> ws;
|
16 : |
|
|
while (!infile.eof()) {
|
17 : |
|
|
aggindex.resize(new char[MaxStrLength]);
|
18 : |
|
|
strncpy(aggindex[i], "", MaxStrLength);
|
19 : |
|
|
infile >> aggindex[i];
|
20 : |
|
|
agg.AddRows(1, 0, 0);
|
21 : |
|
|
|
22 : |
|
|
infile.getLine(text, MaxStrLength);
|
23 : |
|
|
if (infile.fail())
|
24 : |
|
|
handle.logFileMessage(LOGFAIL, "failed to read aggregation vector");
|
25 : |
|
|
|
26 : |
|
|
istringstream line(text);
|
27 : |
|
|
line >> ws;
|
28 : |
|
|
while (!line.eof()) {
|
29 : |
|
|
line >> tmp >> ws;
|
30 : |
|
|
if (line.fail() && !line.eof())
|
31 : |
|
|
handle.logFileMessage(LOGFAIL, "failed to read aggregation vector");
|
32 : |
|
|
agg[i].resize(1, tmp);
|
33 : |
|
|
}
|
34 : |
|
|
|
35 : |
|
|
infile >> ws;
|
36 : |
|
|
i++;
|
37 : |
|
|
}
|
38 : |
|
|
|
39 : |
|
|
//check that the labels are unique
|
40 : |
|
|
for (i = 0; i < aggindex.Size(); i++)
|
41 : |
|
|
for (j = 0; j < aggindex.Size(); j++)
|
42 : |
|
|
if ((strcasecmp(aggindex[i], aggindex[j]) == 0) && (i != j))
|
43 : |
|
|
handle.logMessage(LOGFAIL, "Error in aggregation file - repeated label", aggindex[i]);
|
44 : |
|
|
|
45 : |
|
|
handle.logMessage(LOGMESSAGE, "Read aggregation file - number of entries", aggindex.Size());
|
46 : |
|
|
return aggindex.Size();
|
47 : |
|
|
}
|
48 : |
|
|
|
49 : |
|
|
int readAggregation(CommentStream& infile, IntVector& agg, CharPtrVector& aggindex) {
|
50 : |
|
|
int i, j;
|
51 : |
|
|
i = 0;
|
52 : |
|
|
|
53 : |
|
|
agg.Reset();
|
54 : |
|
|
aggindex.Reset();
|
55 : |
|
|
infile >> ws;
|
56 : |
|
|
while (!infile.eof()) {
|
57 : |
|
|
aggindex.resize(new char[MaxStrLength]);
|
58 : |
|
|
strncpy(aggindex[i], "", MaxStrLength);
|
59 : |
|
|
agg.resize(1, 0);
|
60 : |
|
|
infile >> aggindex[i] >> agg[i] >> ws;
|
61 : |
|
|
i++;
|
62 : |
|
|
}
|
63 : |
|
|
|
64 : |
|
|
//check that the labels are unique
|
65 : |
|
|
for (i = 0; i < aggindex.Size(); i++)
|
66 : |
|
|
for (j = 0; j < aggindex.Size(); j++)
|
67 : |
|
|
if ((strcasecmp(aggindex[i], aggindex[j]) == 0) && (i != j))
|
68 : |
|
|
handle.logMessage(LOGFAIL, "Error in aggregation file - repeated label", aggindex[i]);
|
69 : |
|
|
|
70 : |
|
|
handle.logMessage(LOGMESSAGE, "Read aggregation file - number of entries", aggindex.Size());
|
71 : |
|
|
return aggindex.Size();
|
72 : |
|
|
}
|
73 : |
|
|
|
74 : |
|
|
int readLengthAggregation(CommentStream& infile, DoubleVector& lengths, CharPtrVector& lenindex) {
|
75 : |
|
|
int i, j;
|
76 : |
|
|
double dblA, dblB;
|
77 : |
|
|
i = 0;
|
78 : |
|
|
|
79 : |
|
|
lengths.Reset();
|
80 : |
|
|
lenindex.Reset();
|
81 : |
|
|
infile >> ws;
|
82 : |
|
|
while (!infile.eof()) {
|
83 : |
|
|
lenindex.resize(new char[MaxStrLength]);
|
84 : |
|
|
strncpy(lenindex[i], "", MaxStrLength);
|
85 : |
|
|
infile >> lenindex[i] >> dblA >> dblB >> ws;
|
86 : |
|
|
|
87 : |
|
|
if (i == 0)
|
88 : |
|
|
lengths.resize(1, dblA); //first length entry to be read
|
89 : |
|
|
|
90 : |
|
|
if (isEqual(lengths[i], dblA))
|
91 : |
|
|
lengths.resize(1, dblB); //add next length entry
|
92 : |
|
|
else
|
93 : |
|
|
handle.logMessage(LOGFAIL, "Error in length aggregation - lengths not consecutive");
|
94 : |
|
|
|
95 : |
|
|
i++;
|
96 : |
|
|
}
|
97 : |
|
|
|
98 : |
|
|
//check that the labels are unique
|
99 : |
|
|
for (i = 0; i < lenindex.Size(); i++)
|
100 : |
|
|
for (j = 0; j < lenindex.Size(); j++)
|
101 : |
|
|
if ((strcasecmp(lenindex[i], lenindex[j]) == 0) && (i != j))
|
102 : |
|
|
handle.logMessage(LOGFAIL, "Error in length aggregation file - repeated label", lenindex[i]);
|
103 : |
|
|
|
104 : |
|
|
handle.logMessage(LOGMESSAGE, "Read length aggregation file - number of entries", lenindex.Size());
|
105 : |
|
|
return lenindex.Size();
|
106 : |
|
|
}
|
107 : |
|
|
|
108 : |
|
|
int readPreyAggregation(CommentStream& infile, CharPtrMatrix& preynames,
|
109 : |
|
|
DoubleMatrix& preylengths, FormulaMatrix& digestioncoeff,
|
110 : |
|
|
CharPtrVector& preyindex, Keeper* const keeper) {
|
111 : |
|
|
|
112 : |
|
|
int i, j, k;
|
113 : |
|
|
char text[MaxStrLength];
|
114 : |
|
|
strncpy(text, "", MaxStrLength);
|
115 : |
|
|
i = j = 0;
|
116 : |
|
|
|
117 : |
|
|
preylengths.Reset();
|
118 : |
|
|
preyindex.Reset();
|
119 : |
|
|
infile >> ws;
|
120 : |
|
|
while (!infile.eof()) {
|
121 : |
|
|
preyindex.resize(new char[MaxStrLength]);
|
122 : |
|
|
strncpy(preyindex[i], "", MaxStrLength);
|
123 : |
|
|
infile >> preyindex[i];
|
124 : |
|
|
|
125 : |
|
|
j = 0;
|
126 : |
|
|
preynames.resize();
|
127 : |
|
|
infile >> text >> ws;
|
128 : |
|
|
while (!infile.eof() && (strcasecmp(text, "lengths") != 0)) {
|
129 : |
|
|
preynames[i].resize(new char[strlen(text) + 1]);
|
130 : |
|
|
strcpy(preynames[i][j++], text);
|
131 : |
|
|
infile >> text >> ws;
|
132 : |
|
|
}
|
133 : |
|
|
|
134 : |
|
|
if (strcasecmp(text, "lengths") != 0)
|
135 : |
|
|
handle.logFileUnexpected(LOGFAIL, "lengths", text);
|
136 : |
|
|
|
137 : |
|
|
//JMB - changed so that only 2 lengths are read in
|
138 : |
|
|
preylengths.AddRows(1, 2, 0.0);
|
139 : |
|
|
infile >> preylengths[i][0] >> preylengths[i][1] >> text >> ws;
|
140 : |
|
|
|
141 : |
|
|
if (strcasecmp(text, "digestioncoefficients") != 0)
|
142 : |
|
|
handle.logFileUnexpected(LOGFAIL, "digestioncoefficients", text);
|
143 : |
|
|
|
144 : |
|
|
//JMB - changed so that only 3 elements are read in
|
145 : |
|
|
digestioncoeff.AddRows(1, 3, 0);
|
146 : |
|
|
for (k = 0; k < 3; k++)
|
147 : |
|
|
if (!(infile >> digestioncoeff[i][k]))
|
148 : |
|
|
handle.logFileMessage(LOGFAIL, "invalid format for digestion coefficient vector");
|
149 : |
|
|
digestioncoeff[i].Inform(keeper);
|
150 : |
|
|
|
151 : |
|
|
infile >> ws;
|
152 : |
|
|
i++;
|
153 : |
|
|
}
|
154 : |
|
|
|
155 : |
|
|
//check that the labels are unique
|
156 : |
|
|
for (i = 0; i < preyindex.Size(); i++)
|
157 : |
|
|
for (j = 0; j < preyindex.Size(); j++)
|
158 : |
|
|
if ((strcasecmp(preyindex[i], preyindex[j]) == 0) && (i != j))
|
159 : |
|
|
handle.logMessage(LOGFAIL, "Error in prey aggregation file - repeated label", preyindex[i]);
|
160 : |
|
|
|
161 : |
|
|
handle.logMessage(LOGMESSAGE, "Read prey aggregation file - number of entries", preyindex.Size());
|
162 : |
|
|
return preyindex.Size();
|
163 : |
|
|
}
|