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 11 - (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 :     else
309 :     handle.logFileUnexpected(LOGFAIL, "[hooke], [simann], or [bfgs]", text);
310 :    
311 :     if (!infile.eof()) {
312 :     infile >> text;
313 : ulcessvp 11 optvec[count]->setSeed(seed);
314 : agomez 1 optvec[count]->read(infile, text);
315 :     } else
316 :     handle.logMessage(LOGINFO, "Warning - no parameters specified for optimisation algorithm");
317 :     count++;
318 :     }
319 :    
320 :     delete[] text;
321 :     if (count == 0) {
322 :     handle.logFileMessage(LOGWARN, "no optimisation algorithms found, using default values");
323 :     optvec.resize(new OptInfoHooke());
324 :     }
325 :     }
326 :    
327 :     //
328 :     // The main reading function
329 :     //
330 :     void Ecosystem::readMain(CommentStream& infile, const MainInfo& main) {
331 :    
332 :     int i, j;
333 :     char text[MaxStrLength];
334 :     char filename[MaxStrLength];
335 :     strncpy(text, "", MaxStrLength);
336 :     strncpy(filename, "", MaxStrLength);
337 :    
338 :     ifstream subfile;
339 :     CommentStream subcomment(subfile);
340 :    
341 :     //first, read in the time information
342 :     readWordAndValue(infile, "timefile", filename);
343 :     subfile.open(filename, ios::in);
344 :     handle.checkIfFailure(subfile, filename);
345 :     handle.Open(filename);
346 :     TimeInfo = new TimeClass(subcomment, main.getMaxRatio());
347 :     handle.Close();
348 :     subfile.close();
349 :     subfile.clear();
350 :    
351 :     //second, read in the area information
352 :     readWordAndValue(infile, "areafile", filename);
353 :     subfile.open(filename, ios::in);
354 :     handle.checkIfFailure(subfile, filename);
355 :     handle.Open(filename);
356 :     Area = new AreaClass(subcomment, keeper, TimeInfo);
357 :     handle.Close();
358 :     subfile.close();
359 :     subfile.clear();
360 :    
361 :     //next, read in the printing information
362 :     infile >> text >> ws;
363 :     if ((strcasecmp(text, "printfile") != 0) && (strcasecmp(text, "printfiles") != 0))
364 :     handle.logFileUnexpected(LOGFAIL, "printfiles", text);
365 :    
366 :     //Now we have found the string "printfiles" we can create printer classes
367 :     infile >> text >> ws;
368 :     while ((strcasecmp(text, "[stock]") != 0) && !infile.eof()) {
369 :     //Do not try to read printfile if we dont need it
370 :     if (main.runPrint()) {
371 :     subfile.open(text, ios::in);
372 :     handle.checkIfFailure(subfile, text);
373 :     handle.Open(text);
374 :     this->readPrinters(subcomment);
375 :     handle.Close();
376 :     subfile.close();
377 :     subfile.clear();
378 :     }
379 :     infile >> text >> ws;
380 :     }
381 :    
382 :     //then read in the stock information
383 :     if (strcasecmp(text, "[stock]") != 0)
384 :     handle.logFileUnexpected(LOGFAIL, "[stock]", text);
385 :     infile >> text >> ws;
386 :    
387 :     if (strcasecmp(text, "mortalitymodel") == 0)
388 :     handle.logFileMessage(LOGFAIL, "\nFleksibest-style mortality models are no longer supported\nGadget version 2.0.07 was the last version to allow this functionality");
389 :    
390 :     if (strcasecmp(text, "stockfiles") != 0)
391 :     handle.logFileUnexpected(LOGFAIL, "stockfiles", text);
392 :    
393 :     //Now we have found the string "stockfiles" we can create stock
394 :     infile >> text >> ws;
395 :     while ((strcasecmp(text, "[tagging]") != 0) && !infile.eof()) {
396 :     subfile.open(text, ios::in);
397 :     handle.checkIfFailure(subfile, text);
398 :     handle.Open(text);
399 :     this->readStock(subcomment);
400 :     handle.Close();
401 :     subfile.close();
402 :     subfile.clear();
403 :     infile >> text >> ws;
404 :     }
405 :    
406 :     //Now we read the names of the tagging files
407 :     if (strcasecmp(text, "[tagging]") != 0)
408 :     handle.logFileUnexpected(LOGFAIL, "[tagging]", text);
409 :    
410 :     infile >> text >> ws;
411 :     if (strcasecmp(text, "tagfiles") == 0) {
412 :     //There might not be any tagging files
413 :     infile >> text >> ws;
414 :     while ((strcasecmp(text, "[otherfood]") != 0) && !infile.eof()) {
415 :     subfile.open(text, ios::in);
416 :     handle.checkIfFailure(subfile, text);
417 :     handle.Open(text);
418 :     this->readTagging(subcomment);
419 :     handle.Close();
420 :     subfile.close();
421 :     subfile.clear();
422 :     infile >> text >> ws;
423 :     }
424 :     }
425 :    
426 :     //Now we read the names of the otherfood files
427 :     if (strcasecmp(text, "[otherfood]") != 0)
428 :     handle.logFileUnexpected(LOGFAIL, "[otherfood]", text);
429 :    
430 :     infile >> text >> ws;
431 :     if (strcasecmp(text, "otherfoodfiles") == 0) {
432 :     //There might not be any otherfood files
433 :     infile >> text >> ws;
434 :     while ((strcasecmp(text, "[fleet]") != 0) && !infile.eof()) {
435 :     subfile.open(text, ios::in);
436 :     handle.checkIfFailure(subfile, text);
437 :     handle.Open(text);
438 :     this->readOtherFood(subcomment);
439 :     handle.Close();
440 :     subfile.close();
441 :     subfile.clear();
442 :     infile >> text >> ws;
443 :     }
444 :     }
445 :    
446 :     //Now we read the names of the fleet files
447 :     if (strcasecmp(text, "[fleet]") != 0)
448 :     handle.logFileUnexpected(LOGFAIL, "[fleet]", text);
449 :    
450 :     infile >> text >> ws;
451 :     if (strcasecmp(text, "fleetfiles") == 0) {
452 :     //There might not be any fleet files
453 :     infile >> text >> ws;
454 :     while ((strcasecmp(text, "[likelihood]") != 0) && !infile.eof()) {
455 :     subfile.open(text, ios::in);
456 :     handle.checkIfFailure(subfile, text);
457 :     handle.Open(text);
458 :     this->readFleet(subcomment);
459 :     handle.Close();
460 :     subfile.close();
461 :     subfile.clear();
462 :     infile >> text >> ws;
463 :     }
464 :     }
465 :    
466 :     if (strcasecmp(text, "[likelihood]") != 0)
467 :     handle.logFileUnexpected(LOGFAIL, "[likelihood]", text);
468 :    
469 :     //Now we have either read the word likelihood or reached the end of file
470 :     if (!infile.eof()) {
471 :     infile >> text >> ws;
472 :     if (strcasecmp(text, "likelihoodfiles") == 0) {
473 :     //There might not be any likelihood files
474 :     infile >> text;
475 :     while (!infile.eof()) {
476 :     subfile.open(text, ios::in);
477 :     handle.checkIfFailure(subfile, text);
478 :     handle.Open(text);
479 :     this->readLikelihood(subcomment);
480 :     handle.Close();
481 :     subfile.close();
482 :     subfile.clear();
483 :    
484 :     infile >> ws;
485 :     if (!infile.eof())
486 :     infile >> text;
487 :     }
488 :     }
489 :     }
490 :     }

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

Powered By FusionForge