Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/readmain.cc
[mareframe] / trunk / gadget / readmain.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/readmain.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (view) (download)

1 : agomez 1 #include "ecosystem.h"
2 :     #include "keeper.h"
3 :     #include "stockstdprinter.h"
4 :     #include "stockprinter.h"
5 :     #include "predatorprinter.h"
6 :     #include "predatorpreyprinter.h"
7 :     #include "predatoroverprinter.h"
8 :     #include "preyoverprinter.h"
9 :     #include "stockpreyfullprinter.h"
10 :     #include "stockpreyprinter.h"
11 :     #include "stockfullprinter.h"
12 :     #include "likelihoodprinter.h"
13 :     #include "summaryprinter.h"
14 :     #include "surveyindices.h"
15 :     #include "understocking.h"
16 :     #include "catchdistribution.h"
17 :     #include "stockdistribution.h"
18 :     #include "catchstatistics.h"
19 :     #include "recstatistics.h"
20 :     #include "stomachcontent.h"
21 :     #include "recapture.h"
22 :     #include "migrationpenalty.h"
23 :     #include "catchinkilos.h"
24 :     #include "boundlikelihood.h"
25 :     #include "surveydistribution.h"
26 :     #include "migrationproportion.h"
27 :     #include "readword.h"
28 :     #include "gadget.h"
29 :     #include "global.h"
30 :    
31 :     //
32 :     // A function to read fleet information
33 :     //
34 :     void Ecosystem::readFleet(CommentStream& infile) {
35 :     char text[MaxStrLength];
36 :     char value[MaxStrLength];
37 :     strncpy(text, "", MaxStrLength);
38 :     strncpy(value, "", MaxStrLength);
39 :    
40 :     while (!infile.eof()) {
41 :     infile >> text >> ws;
42 :     if ((strcasecmp(text, "[fleetcomponent]") != 0) && (strcasecmp(text, "[component]") != 0))
43 :     handle.logFileUnexpected(LOGFAIL, "[component]", text);
44 :    
45 :     infile >> text >> value;
46 :     if (strcasecmp(text, "totalfleet") == 0)
47 :     fleetvec.resize(new Fleet(infile, value, Area, TimeInfo, keeper, TOTALFLEET));
48 :     else if (strcasecmp(text, "linearfleet") == 0)
49 :     fleetvec.resize(new Fleet(infile, value, Area, TimeInfo, keeper, LINEARFLEET));
50 :     else if (strcasecmp(text, "numberfleet") == 0)
51 :     fleetvec.resize(new Fleet(infile, value, Area, TimeInfo, keeper, NUMBERFLEET));
52 :     else if (strcasecmp(text, "effortfleet") == 0)
53 :     fleetvec.resize(new Fleet(infile, value, Area, TimeInfo, keeper, EFFORTFLEET));
54 :     else if (strcasecmp(text, "quotafleet") == 0)
55 :     fleetvec.resize(new Fleet(infile, value, Area, TimeInfo, keeper, QUOTAFLEET));
56 :     else if (strcasecmp(text, "mortalityfleet") == 0)
57 :     handle.logFileMessage(LOGFAIL, "\nThe mortalityfleet fleet type is no longer supported");
58 :     else
59 :     handle.logFileMessage(LOGFAIL, "unrecognised fleet class", text);
60 :    
61 :     handle.logMessage(LOGMESSAGE, "Read fleet OK - created fleet", value);
62 :     }
63 :     }
64 :    
65 :     //
66 :     // A function to read tagging information
67 :     //
68 :     void Ecosystem::readTagging(CommentStream& infile) {
69 :     char text[MaxStrLength];
70 :     strncpy(text, "", MaxStrLength);
71 :    
72 :     while (!infile.eof()) {
73 :     infile >> text >> ws;
74 :     if ((strcasecmp(text, "[tagcomponent]") != 0) && (strcasecmp(text, "[component]") != 0))
75 :     handle.logFileUnexpected(LOGFAIL, "[component]", text);
76 :    
77 :     readWordAndValue(infile, "tagid", text);
78 :     tagvec.resize(new Tags(infile, text, Area, TimeInfo, keeper, stockvec));
79 :     handle.logMessage(LOGMESSAGE, "Read tagging experiment OK - created tag", text);
80 :     }
81 :     }
82 :    
83 :     //
84 :     // A function to read otherfood information
85 :     //
86 :     void Ecosystem::readOtherFood(CommentStream& infile) {
87 :     char text[MaxStrLength];
88 :     strncpy(text, "", MaxStrLength);
89 :    
90 :     while (!infile.eof()) {
91 :     infile >> text >> ws;
92 :     if ((strcasecmp(text, "[foodcomponent]") != 0) && (strcasecmp(text, "[component]") != 0))
93 :     handle.logFileUnexpected(LOGFAIL, "[component]", text);
94 :    
95 :     readWordAndValue(infile, "foodname", text);
96 :     otherfoodvec.resize(new OtherFood(infile, text, Area, TimeInfo, keeper));
97 :     handle.logMessage(LOGMESSAGE, "Read otherfood OK - created otherfood", text);
98 :     }
99 :     }
100 :    
101 :     //
102 :     // A function to read stock information
103 :     // Note: there is only ever one stock in each file
104 :     //
105 :     void Ecosystem::readStock(CommentStream& infile) {
106 :     char text[MaxStrLength];
107 :     strncpy(text, "", MaxStrLength);
108 :    
109 :     readWordAndValue(infile, "stockname", text);
110 :     stockvec.resize(new Stock(infile, text, Area, TimeInfo, keeper));
111 :     handle.logMessage(LOGMESSAGE, "Read stock OK - created stock", text);
112 :     }
113 :    
114 :     //
115 :     // A function to read information on printing
116 :     //
117 :     void Ecosystem::readPrinters(CommentStream& infile) {
118 :     char text[MaxStrLength];
119 :     char type[MaxStrLength];
120 :     strncpy(text, "", MaxStrLength);
121 :     strncpy(type, "", MaxStrLength);
122 :    
123 :     if (!infile.eof())
124 :     infile >> text >> ws;
125 :    
126 :     if (strcasecmp(text, "[component]") != 0)
127 :     handle.logFileUnexpected(LOGFAIL, "[component]", text);
128 :    
129 :     while (!infile.eof()) {
130 :     readWordAndValue(infile, "type", type);
131 :    
132 :     if (strcasecmp(type, "stockstdprinter") == 0)
133 :     printvec.resize(new StockStdPrinter(infile, TimeInfo));
134 :     else if (strcasecmp(type, "stockfullprinter") == 0)
135 :     printvec.resize(new StockFullPrinter(infile, TimeInfo));
136 :     else if (strcasecmp(type, "stockprinter") == 0)
137 :     printvec.resize(new StockPrinter(infile, TimeInfo));
138 :     else if (strcasecmp(type, "predatorprinter") == 0)
139 :     printvec.resize(new PredatorPrinter(infile, TimeInfo));
140 :     else if (strcasecmp(type, "predatoroverprinter") == 0)
141 :     printvec.resize(new PredatorOverPrinter(infile, TimeInfo));
142 :     else if (strcasecmp(type, "preyoverprinter") == 0)
143 :     printvec.resize(new PreyOverPrinter(infile, TimeInfo));
144 :     else if (strcasecmp(type, "stockpreyprinter") == 0)
145 :     printvec.resize(new StockPreyPrinter(infile, TimeInfo));
146 :     else if (strcasecmp(type, "stockpreyfullprinter") == 0)
147 :     printvec.resize(new StockPreyFullPrinter(infile, TimeInfo));
148 :     else if (strcasecmp(type, "predatorpreyprinter") == 0)
149 :     printvec.resize(new PredatorPreyPrinter(infile, TimeInfo));
150 :     else if (strcasecmp(type, "likelihoodprinter") == 0)
151 :     printvec.resize(new LikelihoodPrinter(infile, TimeInfo));
152 :     else if (strcasecmp(type, "likelihoodsummaryprinter") == 0)
153 :     printvec.resize(new SummaryPrinter(infile));
154 :    
155 :     else if (strcasecmp(type, "formatedstockprinter") == 0)
156 :     handle.logFileMessage(LOGFAIL, "\nThe formatedstockprinter printer class is no longer supported");
157 :     else if (strcasecmp(type, "formatedchatprinter") == 0)
158 :     handle.logFileMessage(LOGFAIL, "\nThe formatedchatprinter printer class is no longer supported");
159 :     else if (strcasecmp(type, "formatedpreyprinter") == 0)
160 :     handle.logFileMessage(LOGFAIL, "\nThe formatedpreyprinter printer class is no longer supported");
161 :     else if (strcasecmp(type, "mortprinter") == 0)
162 :     handle.logFileMessage(LOGFAIL, "\nThe mortprinter printer class is no longer supported");
163 :     else if (strcasecmp(type, "biomassprinter") == 0)
164 :     handle.logFileMessage(LOGFAIL, "\nThe biomassprinter printer class is no longer supported");
165 :     else if (strcasecmp(type, "formatedcatchprinter") == 0)
166 :     handle.logFileMessage(LOGFAIL, "\nThe formatedcatchprinter printer class is no longer supported");
167 :     else if (strcasecmp(type, "predpreystdlengthprinter") == 0)
168 :     handle.logFileMessage(LOGFAIL, "\nThe predpreystdlengthprinter printer class is no longer supported");
169 :     else if (strcasecmp(type, "predpreystdageprinter") == 0)
170 :     handle.logFileMessage(LOGFAIL, "\nThe predpreystdageprinter printer class is no longer supported");
171 :    
172 :     else
173 :     handle.logFileMessage(LOGFAIL, "unrecognised printer class", type);
174 :    
175 :     handle.logMessage(LOGMESSAGE, "Read printer OK - created printer class", type);
176 :     }
177 :     }
178 :    
179 :     //
180 :     // A function to read likelihood information
181 :     //
182 :     void Ecosystem::readLikelihood(CommentStream& infile) {
183 :     double weight = 0.0;
184 :     char text[MaxStrLength];
185 :     char type[MaxStrLength];
186 :     char name[MaxStrLength];
187 :     char datafilename[MaxStrLength];
188 :     strncpy(text, "", MaxStrLength);
189 :     strncpy(type, "", MaxStrLength);
190 :     strncpy(name, "", MaxStrLength);
191 :     strncpy(datafilename, "", MaxStrLength);
192 :    
193 :     ifstream datafile;
194 :     CommentStream subdata(datafile);
195 :    
196 :     if (!infile.eof())
197 :     infile >> text >> ws;
198 :    
199 :     if (strcasecmp(text, "[component]") != 0)
200 :     handle.logFileUnexpected(LOGFAIL, "[component]", text);
201 :    
202 :     while (!infile.eof()) {
203 :     readWordAndValue(infile, "name", name);
204 :     readWordAndVariable(infile, "weight", weight);
205 :     readWordAndValue(infile, "type", type);
206 :    
207 :     if (strcasecmp(type, "penalty") == 0) {
208 :     readWordAndValue(infile, "datafile", datafilename);
209 :     datafile.open(datafilename, ios::in);
210 :     handle.checkIfFailure(datafile, datafilename);
211 :     handle.Open(datafilename);
212 :     likevec.resize(new BoundLikelihood(subdata, Area, TimeInfo, keeper, weight, name));
213 :     handle.Close();
214 :     datafile.close();
215 :     datafile.clear();
216 :    
217 :     //prepare for next likelihood component
218 :     infile >> ws;
219 :     if (!infile.eof()) {
220 :     infile >> text >> ws;
221 :     if (strcasecmp(text, "[component]") != 0)
222 :     handle.logFileUnexpected(LOGFAIL, "[component]", text);
223 :     }
224 :    
225 :     } else if (strcasecmp(type, "understocking") == 0) {
226 :     likevec.resize(new UnderStocking(infile, Area, TimeInfo, weight, name));
227 :    
228 :     } else if (strcasecmp(type, "catchstatistics") == 0) {
229 :     likevec.resize(new CatchStatistics(infile, Area, TimeInfo, weight, name));
230 :    
231 :     } else if (strcasecmp(type, "catchdistribution") == 0) {
232 :     likevec.resize(new CatchDistribution(infile, Area, TimeInfo, keeper, weight, name));
233 :    
234 :     } else if (strcasecmp(type, "stockdistribution") == 0) {
235 :     likevec.resize(new StockDistribution(infile, Area, TimeInfo, weight, name));
236 :    
237 :     } else if (strcasecmp(type, "surveyindices") == 0) {
238 :     likevec.resize(new SurveyIndices(infile, Area, TimeInfo, weight, name));
239 :    
240 :     } else if (strcasecmp(type, "surveydistribution") == 0) {
241 :     likevec.resize(new SurveyDistribution(infile, Area, TimeInfo, keeper, weight, name));
242 :    
243 :     } else if (strcasecmp(type, "stomachcontent") == 0) {
244 :     likevec.resize(new StomachContent(infile, Area, TimeInfo, keeper, weight, name));
245 :    
246 :     } else if (strcasecmp(type, "recaptures") == 0) {
247 :     likevec.resize(new Recaptures(infile, Area, TimeInfo, weight, tagvec, name));
248 :    
249 :     } else if ((strcasecmp(type, "catchintons") == 0) || (strcasecmp(type, "catchinkilos") == 0)) {
250 :     likevec.resize(new CatchInKilos(infile, Area, TimeInfo, weight, name));
251 :    
252 :     } else if (strcasecmp(type, "migrationpenalty") == 0) {
253 :     likevec.resize(new MigrationPenalty(infile, weight, name));
254 :    
255 :     } else if (strcasecmp(type, "recstatistics") == 0) {
256 :     likevec.resize(new RecStatistics(infile, Area, TimeInfo, weight, tagvec, name));
257 :    
258 :     } else if (strcasecmp(type, "migrationproportion") == 0) {
259 :     likevec.resize(new MigrationProportion(infile, Area, TimeInfo, weight, name));
260 :    
261 :     } else if (strcasecmp(type, "predatorindices") == 0) {
262 :     handle.logFileMessage(LOGFAIL, "\nThe predatorindices likelihood component is no longer supported\nUse the sibyfleet surveyindices likelihood component instead\nThis is done by setting the sitype to 'fleets' in the likelihood file");
263 :    
264 :     } else if (strcasecmp(type, "logcatch") == 0) {
265 :     handle.logFileMessage(LOGFAIL, "\nThe logcatch likelihood component is no longer supported\nUse the log function from the catchdistribution likelihood component instead");
266 :    
267 :     } else if (strcasecmp(type, "logsurveyindices") == 0) {
268 :     handle.logFileMessage(LOGFAIL, "\nThe logsurveyindices likelihood component is no longer supported\nUse the log function from the surveyindices likelihood component instead");
269 :    
270 :     } else {
271 :     handle.logFileMessage(LOGFAIL, "unrecognised likelihood class", type);
272 :     }
273 :    
274 :     handle.logMessage(LOGMESSAGE, "Read likelihood OK - created likelihood component", name);
275 :     }
276 :     }
277 :    
278 :     //
279 :     // A function to read optimisation information
280 :     //
281 : ulcessvp 11 void Ecosystem::readOptimisation(CommentStream& infile, unsigned* seed) {
282 : agomez 1 char* text = new char[MaxStrLength];
283 :     strncpy(text, "", MaxStrLength);
284 :     handle.logMessage(LOGMESSAGE, "Reading optimisation information");
285 :    
286 :     infile >> ws;
287 :     if (!infile.eof())
288 :     infile >> text;
289 :    
290 :     int count = 0;
291 :     while (!infile.eof()) {
292 :     infile >> ws; //trim whitespace from infile
293 :     if (strcasecmp(text, "seed") == 0) {
294 :     int seed = 0;
295 :     infile >> seed >> ws;
296 :     handle.logMessage(LOGMESSAGE, "Initialising random number generator with", seed);
297 :     srand(seed);
298 :     if (!infile.eof())
299 :     infile >> text;
300 :     }
301 :    
302 :     if (strcasecmp(text, "[hooke]") == 0)
303 :     optvec.resize(new OptInfoHooke());
304 :     else if (strcasecmp(text, "[simann]") == 0)
305 :     optvec.resize(new OptInfoSimann());
306 :     else if (strcasecmp(text, "[bfgs]") == 0)
307 :     optvec.resize(new OptInfoBFGS());
308 : agomez 20 else if (strcasecmp(text, "[pso]") == 0)
309 :     optvec.resize(new OptInfoPso());
310 : agomez 1 else
311 : agomez 20 handle.logFileUnexpected(LOGFAIL, "[hooke], [simann], [bfgs], or [pso]", text);
312 : agomez 1
313 :     if (!infile.eof()) {
314 :     infile >> text;
315 : ulcessvp 11 optvec[count]->setSeed(seed);
316 : agomez 1 optvec[count]->read(infile, text);
317 :     } else
318 :     handle.logMessage(LOGINFO, "Warning - no parameters specified for optimisation algorithm");
319 :     count++;
320 :     }
321 :    
322 :     delete[] text;
323 :     if (count == 0) {
324 :     handle.logFileMessage(LOGWARN, "no optimisation algorithms found, using default values");
325 :     optvec.resize(new OptInfoHooke());
326 :     }
327 :     }
328 :    
329 :     //
330 :     // The main reading function
331 :     //
332 :     void Ecosystem::readMain(CommentStream& infile, const MainInfo& main) {
333 :    
334 :     int i, j;
335 :     char text[MaxStrLength];
336 :     char filename[MaxStrLength];
337 :     strncpy(text, "", MaxStrLength);
338 :     strncpy(filename, "", MaxStrLength);
339 :    
340 :     ifstream subfile;
341 :     CommentStream subcomment(subfile);
342 :    
343 :     //first, read in the time information
344 :     readWordAndValue(infile, "timefile", filename);
345 :     subfile.open(filename, ios::in);
346 :     handle.checkIfFailure(subfile, filename);
347 :     handle.Open(filename);
348 :     TimeInfo = new TimeClass(subcomment, main.getMaxRatio());
349 :     handle.Close();
350 :     subfile.close();
351 :     subfile.clear();
352 :    
353 :     //second, read in the area information
354 :     readWordAndValue(infile, "areafile", filename);
355 :     subfile.open(filename, ios::in);
356 :     handle.checkIfFailure(subfile, filename);
357 :     handle.Open(filename);
358 :     Area = new AreaClass(subcomment, keeper, TimeInfo);
359 :     handle.Close();
360 :     subfile.close();
361 :     subfile.clear();
362 :    
363 :     //next, read in the printing information
364 :     infile >> text >> ws;
365 :     if ((strcasecmp(text, "printfile") != 0) && (strcasecmp(text, "printfiles") != 0))
366 :     handle.logFileUnexpected(LOGFAIL, "printfiles", text);
367 :    
368 :     //Now we have found the string "printfiles" we can create printer classes
369 :     infile >> text >> ws;
370 :     while ((strcasecmp(text, "[stock]") != 0) && !infile.eof()) {
371 :     //Do not try to read printfile if we dont need it
372 :     if (main.runPrint()) {
373 :     subfile.open(text, ios::in);
374 :     handle.checkIfFailure(subfile, text);
375 :     handle.Open(text);
376 :     this->readPrinters(subcomment);
377 :     handle.Close();
378 :     subfile.close();
379 :     subfile.clear();
380 :     }
381 :     infile >> text >> ws;
382 :     }
383 :    
384 :     //then read in the stock information
385 :     if (strcasecmp(text, "[stock]") != 0)
386 :     handle.logFileUnexpected(LOGFAIL, "[stock]", text);
387 :     infile >> text >> ws;
388 :    
389 :     if (strcasecmp(text, "mortalitymodel") == 0)
390 :     handle.logFileMessage(LOGFAIL, "\nFleksibest-style mortality models are no longer supported\nGadget version 2.0.07 was the last version to allow this functionality");
391 :    
392 :     if (strcasecmp(text, "stockfiles") != 0)
393 :     handle.logFileUnexpected(LOGFAIL, "stockfiles", text);
394 :    
395 :     //Now we have found the string "stockfiles" we can create stock
396 :     infile >> text >> ws;
397 :     while ((strcasecmp(text, "[tagging]") != 0) && !infile.eof()) {
398 :     subfile.open(text, ios::in);
399 :     handle.checkIfFailure(subfile, text);
400 :     handle.Open(text);
401 :     this->readStock(subcomment);
402 :     handle.Close();
403 :     subfile.close();
404 :     subfile.clear();
405 :     infile >> text >> ws;
406 :     }
407 :    
408 :     //Now we read the names of the tagging files
409 :     if (strcasecmp(text, "[tagging]") != 0)
410 :     handle.logFileUnexpected(LOGFAIL, "[tagging]", text);
411 :    
412 :     infile >> text >> ws;
413 :     if (strcasecmp(text, "tagfiles") == 0) {
414 :     //There might not be any tagging files
415 :     infile >> text >> ws;
416 :     while ((strcasecmp(text, "[otherfood]") != 0) && !infile.eof()) {
417 :     subfile.open(text, ios::in);
418 :     handle.checkIfFailure(subfile, text);
419 :     handle.Open(text);
420 :     this->readTagging(subcomment);
421 :     handle.Close();
422 :     subfile.close();
423 :     subfile.clear();
424 :     infile >> text >> ws;
425 :     }
426 :     }
427 :    
428 :     //Now we read the names of the otherfood files
429 :     if (strcasecmp(text, "[otherfood]") != 0)
430 :     handle.logFileUnexpected(LOGFAIL, "[otherfood]", text);
431 :    
432 :     infile >> text >> ws;
433 :     if (strcasecmp(text, "otherfoodfiles") == 0) {
434 :     //There might not be any otherfood files
435 :     infile >> text >> ws;
436 :     while ((strcasecmp(text, "[fleet]") != 0) && !infile.eof()) {
437 :     subfile.open(text, ios::in);
438 :     handle.checkIfFailure(subfile, text);
439 :     handle.Open(text);
440 :     this->readOtherFood(subcomment);
441 :     handle.Close();
442 :     subfile.close();
443 :     subfile.clear();
444 :     infile >> text >> ws;
445 :     }
446 :     }
447 :    
448 :     //Now we read the names of the fleet files
449 :     if (strcasecmp(text, "[fleet]") != 0)
450 :     handle.logFileUnexpected(LOGFAIL, "[fleet]", text);
451 :    
452 :     infile >> text >> ws;
453 :     if (strcasecmp(text, "fleetfiles") == 0) {
454 :     //There might not be any fleet files
455 :     infile >> text >> ws;
456 :     while ((strcasecmp(text, "[likelihood]") != 0) && !infile.eof()) {
457 :     subfile.open(text, ios::in);
458 :     handle.checkIfFailure(subfile, text);
459 :     handle.Open(text);
460 :     this->readFleet(subcomment);
461 :     handle.Close();
462 :     subfile.close();
463 :     subfile.clear();
464 :     infile >> text >> ws;
465 :     }
466 :     }
467 :    
468 :     if (strcasecmp(text, "[likelihood]") != 0)
469 :     handle.logFileUnexpected(LOGFAIL, "[likelihood]", text);
470 :    
471 :     //Now we have either read the word likelihood or reached the end of file
472 :     if (!infile.eof()) {
473 :     infile >> text >> ws;
474 :     if (strcasecmp(text, "likelihoodfiles") == 0) {
475 :     //There might not be any likelihood files
476 :     infile >> text;
477 :     while (!infile.eof()) {
478 :     subfile.open(text, ios::in);
479 :     handle.checkIfFailure(subfile, text);
480 :     handle.Open(text);
481 :     this->readLikelihood(subcomment);
482 :     handle.Close();
483 :     subfile.close();
484 :     subfile.clear();
485 :    
486 :     infile >> ws;
487 :     if (!infile.eof())
488 :     infile >> text;
489 :     }
490 :     }
491 :     }
492 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge