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/initialize.cc
[mareframe] / trunk / gadget / initialize.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/initialize.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "ecosystem.h"
2 :     #include "errorhandler.h"
3 :     #include "predator.h"
4 :     #include "prey.h"
5 :     #include "lengthprey.h"
6 :     #include "stockprey.h"
7 :     #include "preyptrvector.h"
8 :     #include "predatorptrvector.h"
9 :     #include "stockprinter.h"
10 :     #include "stockstdprinter.h"
11 :     #include "stockpreyprinter.h"
12 :     #include "predatorprinter.h"
13 :     #include "predatorpreyprinter.h"
14 :     #include "predatoroverprinter.h"
15 :     #include "preyoverprinter.h"
16 :     #include "stockpreyfullprinter.h"
17 :     #include "stockfullprinter.h"
18 :     #include "likelihoodprinter.h"
19 :     #include "summaryprinter.h"
20 :     #include "surveyindices.h"
21 :     #include "understocking.h"
22 :     #include "catchdistribution.h"
23 :     #include "catchstatistics.h"
24 :     #include "recstatistics.h"
25 :     #include "stomachcontent.h"
26 :     #include "recapture.h"
27 :     #include "stockpredator.h"
28 :     #include "lengthpredator.h"
29 :     #include "stockdistribution.h"
30 :     #include "surveydistribution.h"
31 :     #include "migrationpenalty.h"
32 :     #include "migrationproportion.h"
33 :     #include "catchinkilos.h"
34 :     #include "global.h"
35 :    
36 :     void Ecosystem::Initialise() {
37 :     PreyPtrVector preyvec;
38 :     PredatorPtrVector predvec;
39 :     int i, j, count;
40 :    
41 :     //first check that the names of the components are unique
42 :     for (i = 0; i < fleetvec.Size(); i++)
43 :     for (j = 0; j < fleetvec.Size(); j++)
44 :     if ((strcasecmp(fleetvec[i]->getName(), fleetvec[j]->getName()) == 0) && (i != j))
45 :     handle.logMessage(LOGFAIL, "Error in input files - repeated fleet", fleetvec[i]->getName());
46 :    
47 :     for (i = 0; i < tagvec.Size(); i++)
48 :     for (j = 0; j < tagvec.Size(); j++)
49 :     if ((strcasecmp(tagvec[i]->getName(), tagvec[j]->getName()) == 0) && (i != j))
50 :     handle.logMessage(LOGFAIL, "Error in input files - repeated tagging experiment", tagvec[i]->getName());
51 :    
52 :     for (i = 0; i < otherfoodvec.Size(); i++)
53 :     for (j = 0; j < otherfoodvec.Size(); j++)
54 :     if ((strcasecmp(otherfoodvec[i]->getName(), otherfoodvec[j]->getName()) == 0) && (i != j))
55 :     handle.logMessage(LOGFAIL, "Error in input files - repeated other food", otherfoodvec[i]->getName());
56 :    
57 :     for (i = 0; i < stockvec.Size(); i++)
58 :     for (j = 0; j < stockvec.Size(); j++)
59 :     if ((strcasecmp(stockvec[i]->getName(), stockvec[j]->getName()) == 0) && (i != j))
60 :     handle.logMessage(LOGFAIL, "Error in input files - repeated stock", stockvec[i]->getName());
61 :    
62 :     for (i = 0; i < likevec.Size(); i++)
63 :     for (j = 0; j < likevec.Size(); j++)
64 :     if ((strcasecmp(likevec[i]->getName(), likevec[j]->getName()) == 0) && (i != j))
65 :     handle.logMessage(LOGFAIL, "Error in input files - repeated likelihood component", likevec[i]->getName());
66 :    
67 :     for (i = 0; i < printvec.Size(); i++)
68 :     for (j = 0; j < printvec.Size(); j++)
69 :     if ((strcasecmp(printvec[i]->getFileName(), printvec[j]->getFileName()) == 0) && (i != j))
70 :     handle.logMessage(LOGFAIL, "Error in input files - repeated print file", printvec[i]->getFileName());
71 :    
72 :     //OK, next create a list of all the predators and all the preys
73 :     for (i = 0; i < stockvec.Size(); i++) {
74 :     if (stockvec[i]->isEaten())
75 :     preyvec.resize(stockvec[i]->getPrey());
76 :     if (stockvec[i]->doesEat())
77 :     predvec.resize(stockvec[i]->getPredator());
78 :     }
79 :    
80 :     for (i = 0; i < otherfoodvec.Size(); i++)
81 :     preyvec.resize(otherfoodvec[i]->getPrey());
82 :     for (i = 0; i < fleetvec.Size(); i++)
83 :     predvec.resize(fleetvec[i]->getPredator());
84 :    
85 :     //Now we can start initialising things
86 :     handle.logMessage(LOGMESSAGE, ""); //write blank line to log file
87 :     for (i = 0; i < stockvec.Size(); i++) {
88 :     handle.logMessage(LOGMESSAGE, "Initialising stock", stockvec[i]->getName());
89 :     stockvec[i]->setStock(stockvec);
90 :     }
91 :     for (i = 0; i < predvec.Size(); i++) {
92 :     handle.logMessage(LOGMESSAGE, "Initialising predator", predvec[i]->getName());
93 :     ((PopPredator*)predvec[i])->setPrey(preyvec, keeper);
94 :     }
95 :     for (i = 0; i < tagvec.Size(); i++) {
96 :     handle.logMessage(LOGMESSAGE, "Initialising tagging experiment", tagvec[i]->getName());
97 :     tagvec[i]->setStock(stockvec);
98 :     }
99 :    
100 :     //If there are any tagging experiments we need to resize objects to store them
101 :     //This has to take place last, since some tagged stocks might not be set explicitly
102 :     if (tagvec.Size() != 0)
103 :     for (i = 0; i < stockvec.Size(); i++)
104 :     if (stockvec[i]->isTagged())
105 :     stockvec[i]->setTagged();
106 :    
107 :     for (i = 0; i < stockvec.Size(); i++)
108 :     basevec.resize(stockvec[i]);
109 :     for (i = 0; i < otherfoodvec.Size(); i++)
110 :     basevec.resize(otherfoodvec[i]);
111 :     for (i = 0; i < fleetvec.Size(); i++)
112 :     basevec.resize(fleetvec[i]);
113 :    
114 :     //Next we initialise the likelihood classes
115 :     count = 0; //JMB count the number of understocking classes
116 :     for (i = 0; i < likevec.Size(); i++) {
117 :     handle.logMessage(LOGMESSAGE, "Initialising likelihood component", likevec[i]->getName());
118 :     switch (likevec[i]->getType()) {
119 :     case SURVEYINDICESLIKELIHOOD:
120 :     ((SurveyIndices*)likevec[i])->setFleetsAndStocks(fleetvec, stockvec);
121 :     break;
122 :     case UNDERSTOCKINGLIKELIHOOD:
123 :     ((UnderStocking*)likevec[i])->setPredatorsAndPreys(predvec, preyvec, Area);
124 :     count++;
125 :     break;
126 :     case CATCHDISTRIBUTIONLIKELIHOOD:
127 :     ((CatchDistribution*)likevec[i])->setFleetsAndStocks(fleetvec, stockvec);
128 :     break;
129 :     case CATCHSTATISTICSLIKELIHOOD:
130 :     ((CatchStatistics*)likevec[i])->setFleetsAndStocks(fleetvec, stockvec);
131 :     break;
132 :     case STOMACHCONTENTLIKELIHOOD:
133 :     ((StomachContent*)likevec[i])->setPredatorsAndPreys(predvec, preyvec);
134 :     break;
135 :     case TAGLIKELIHOOD:
136 :     ((Recaptures*)likevec[i])->setFleetsAndStocks(fleetvec, stockvec);
137 :     break;
138 :     case STOCKDISTRIBUTIONLIKELIHOOD:
139 :     ((StockDistribution*)likevec[i])->setFleetsAndStocks(fleetvec, stockvec);
140 :     break;
141 :     case MIGRATIONPENALTYLIKELIHOOD:
142 :     ((MigrationPenalty*)likevec[i])->setFleetsAndStocks(fleetvec, stockvec);
143 :     break;
144 :     case CATCHINKILOSLIKELIHOOD:
145 :     ((CatchInKilos*)likevec[i])->setFleetsAndStocks(fleetvec, stockvec);
146 :     break;
147 :     case RECSTATISTICSLIKELIHOOD:
148 :     ((RecStatistics*)likevec[i])->setFleetsAndStocks(fleetvec, stockvec);
149 :     break;
150 :     case SURVEYDISTRIBUTIONLIKELIHOOD:
151 :     ((SurveyDistribution*)likevec[i])->setFleetsAndStocks(fleetvec, stockvec);
152 :     break;
153 :     case MIGRATIONPROPORTIONLIKELIHOOD:
154 :     ((MigrationProportion*)likevec[i])->setFleetsAndStocks(fleetvec, stockvec);
155 :     break;
156 :     case BOUNDLIKELIHOOD:
157 :     break;
158 :     default:
159 :     handle.logMessage(LOGFAIL, "Error when initialising model - unrecognised likelihood type", likevec[i]->getType());
160 :     break;
161 :     }
162 :     }
163 :    
164 :     if (count == 0)
165 :     handle.logMessage(LOGWARN, "Warning in input files - no understocking likelihood component found");
166 :     if (count > 1)
167 :     handle.logMessage(LOGWARN, "Warning in input files - repeated understocking components found");
168 :    
169 :     //Finally we initialise the printer classes
170 :     for (i = 0; i < printvec.Size(); i++) {
171 :     handle.logMessage(LOGMESSAGE, "Initialising printer for output file", printvec[i]->getFileName());
172 :     switch (printvec[i]->getType()) {
173 :     case STOCKSTDPRINTER:
174 :     ((StockStdPrinter*)printvec[i])->setStock(stockvec, Area);
175 :     break;
176 :     case STOCKPRINTER:
177 :     ((StockPrinter*)printvec[i])->setStock(stockvec, Area);
178 :     break;
179 :     case PREDATORPRINTER:
180 :     ((PredatorPrinter*)printvec[i])->setPredAndPrey(predvec, preyvec, Area);
181 :     break;
182 :     case PREDATOROVERPRINTER:
183 :     ((PredatorOverPrinter*)printvec[i])->setPredator(predvec, Area);
184 :     break;
185 :     case PREYOVERPRINTER:
186 :     ((PreyOverPrinter*)printvec[i])->setPrey(preyvec, Area);
187 :     break;
188 :     case STOCKPREYPRINTER:
189 :     ((StockPreyPrinter*)printvec[i])->setPrey(preyvec, Area);
190 :     break;
191 :     case STOCKPREYFULLPRINTER:
192 :     ((StockPreyFullPrinter*)printvec[i])->setPrey(preyvec, Area);
193 :     break;
194 :     case PREDATORPREYPRINTER:
195 :     ((PredatorPreyPrinter*)printvec[i])->setPredAndPrey(predvec, preyvec, Area);
196 :     break;
197 :     case STOCKFULLPRINTER:
198 :     ((StockFullPrinter*)printvec[i])->setStock(stockvec, Area);
199 :     break;
200 :     case LIKELIHOODPRINTER:
201 :     ((LikelihoodPrinter*)printvec[i])->setLikelihood(likevec);
202 :     break;
203 :     case LIKELIHOODSUMMARYPRINTER:
204 :     ((SummaryPrinter*)printvec[i])->setLikelihood(likevec);
205 :     break;
206 :     default:
207 :     handle.logMessage(LOGFAIL, "Error when initialising model - unrecognised printer type", printvec[i]->getType());
208 :     break;
209 :     }
210 :     }
211 :     }

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

Powered By FusionForge