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

Annotation of /trunk/gadget/tags.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "tags.h"
2 :     #include "areatime.h"
3 :     #include "errorhandler.h"
4 :     #include "readfunc.h"
5 :     #include "readword.h"
6 :     #include "stock.h"
7 :     #include "stockprey.h"
8 :     #include "gadget.h"
9 :     #include "global.h"
10 :    
11 :     Tags::Tags(CommentStream& infile, const char* givenname, const AreaClass* const Area,
12 :     const TimeClass* const TimeInfo, Keeper* const keeper, StockPtrVector stockvec)
13 :     : HasName(givenname) {
14 :    
15 :     taggingstock = 0;
16 :     numtagtimesteps = 0;
17 :     char text[MaxStrLength];
18 :     strncpy(text, "", MaxStrLength);
19 :     ifstream subfile;
20 :     CommentStream subcomment(subfile);
21 :    
22 :     keeper->addString("tags");
23 :     keeper->addString(givenname);
24 :    
25 :     //Currently can only have one stock per tagging experiment
26 :     readWordAndValue(infile, "stock", text);
27 :     stocknames.resize(new char[strlen(text) + 1]);
28 :     strcpy(stocknames[0], text);
29 :    
30 :     //Currently can only have one area per tagging experiment
31 :     readWordAndVariable(infile, "tagarea", tagarea);
32 :     tagarea = Area->getInnerArea(tagarea);
33 :    
34 :     infile >> ws;
35 :     char c = infile.peek();
36 :     if ((c == 'e') || (c == 'E'))
37 :     readWordAndVariable(infile, "endyear", endyear);
38 :     else
39 :     endyear = TimeInfo->getLastYear();
40 :    
41 :     int i, found = 0;
42 :     for (i = 0; i < stockvec.Size(); i++) {
43 :     if (strcasecmp(stockvec[i]->getName(), stocknames[0]) == 0) {
44 :     if (found == 0) {
45 :     taggingstock = stockvec[i];
46 :     LgrpDiv = new LengthGroupDivision(*(taggingstock->getLengthGroupDiv()));
47 :     if (LgrpDiv->Error())
48 :     handle.logMessage(LOGFAIL, "Error in tags - failed to create length group");
49 :     tagStocks.resize(taggingstock);
50 :     taggingstock->setTaggedStock();
51 :     }
52 :     found++;
53 :     }
54 :     }
55 :     if (found == 0)
56 :     handle.logMessage(LOGFAIL, "Error in tags - failed to match stock", stocknames[0]);
57 :     if (found > 1)
58 :     handle.logMessage(LOGFAIL, "Error in tags - repeated stock", stocknames[0]);
59 :    
60 :     //Now read in the tagloss information
61 :     readWordAndVariable(infile, "tagloss", tagloss);
62 :     tagloss.Inform(keeper);
63 :    
64 :     //read in the numbers format: tagid - length - number
65 :     readWordAndValue(infile, "numbers", text);
66 :     subfile.open(text, ios::in);
67 :     handle.checkIfFailure(subfile, text);
68 :     handle.Open(text);
69 :     readNumbers(subcomment, givenname, TimeInfo);
70 :     handle.Close();
71 :     subfile.close();
72 :     subfile.clear();
73 :     keeper->clearLast();
74 :     keeper->clearLast();
75 :     }
76 :    
77 :     void Tags::readNumbers(CommentStream& infile, const char* tagname, const TimeClass* const TimeInfo) {
78 :    
79 :     int year, step, count, reject;
80 :     int i, lenid, keepdata, timeid;
81 :     int numlen = LgrpDiv->numLengthGroups();
82 :     double tmplength, tmpnumber;
83 :     char tmpname[MaxStrLength];
84 :     strncpy(tmpname, "", MaxStrLength);
85 :    
86 :     infile >> ws;
87 :     //Check the number of columns in the inputfile
88 :     if (countColumns(infile) != 5)
89 :     handle.logFileMessage(LOGFAIL, "wrong number of columns in inputfile - should be 5");
90 :    
91 :     year = step = count = reject = 0;
92 :     while (!infile.eof()) {
93 :     keepdata = 1;
94 :     infile >> tmpname >> year >> step >> tmplength >> tmpnumber >> ws;
95 :    
96 :     //only keep the data if tmpname matches tagname
97 :     if (strcasecmp(tagname, tmpname) != 0)
98 :     keepdata = 0;
99 :    
100 :     //only keep the data if the length is valid
101 :     lenid = -1;
102 :     for (i = 0; i < numlen; i++)
103 :     if (isEqual(tmplength, LgrpDiv->minLength(i)))
104 :     lenid = i;
105 :    
106 :     //OK the length doesnt match a minimum length so find the length group it is in
107 :     if ((lenid == -1) && (tmplength > LgrpDiv->minLength()) && (tmplength < LgrpDiv->maxLength())) {
108 :     for (i = 1; i < numlen; i++) {
109 :     if (tmplength < LgrpDiv->minLength(i)) {
110 :     lenid = i - 1;
111 :     break;
112 :     }
113 :     }
114 :     if (lenid == -1)
115 :     lenid = numlen - 1; //then this must be the last length group
116 :     }
117 :    
118 :     if (lenid == -1)
119 :     keepdata = 0;
120 :    
121 :     //only keep the data if the number is positive
122 :     if (tmpnumber < 0.0) {
123 :     handle.logMessage(LOGWARN, "Warning in tags - found negative number of tags", tmpnumber);
124 :     keepdata = 0;
125 :     }
126 :    
127 :     timeid = -1;
128 :     if ((TimeInfo->isWithinPeriod(year, step)) && (keepdata == 1)) {
129 :     for (i = 0; i < Years.Size(); i++)
130 :     if ((Years[i] == year) && (Steps[i] == step))
131 :     timeid = i;
132 :    
133 :     if (timeid == -1) {
134 :     Years.resize(1, year);
135 :     Steps.resize(1, step);
136 :     timeid = Years.Size() - 1;
137 :     NumberByLength.resize(new DoubleMatrix(1, numlen, 0.0));
138 :     }
139 :    
140 :     } else
141 :     keepdata = 0;
142 :    
143 :     if (keepdata == 1) {
144 :     count++;
145 :     (*NumberByLength[timeid])[0][lenid] += tmpnumber;
146 :     } else
147 :     reject++; //count number of rejected data points read from file
148 :     }
149 :    
150 :     if (count == 0)
151 :     handle.logMessage(LOGWARN, "Warning in tags - found no data in the data file for", tagname);
152 :     if (reject != 0)
153 :     handle.logMessage(LOGMESSAGE, "Discarded invalid tags data - number of invalid entries", reject);
154 :     handle.logMessage(LOGMESSAGE, "Read tags data file - number of entries", count);
155 :    
156 :     tagyear = 9999;
157 :     tagstep = 9999;
158 :     for (i = 0; i < Years.Size(); i++)
159 :     if ((Years[i] < tagyear) || (Years[i] == tagyear && Steps[i] < tagstep)) {
160 :     tagyear = Years[i];
161 :     tagstep = Steps[i];
162 :     }
163 :    
164 :     timeid = -1;
165 :     for (i = 0; i < Years.Size(); i++)
166 :     if ((Years[i] == tagyear) && (Steps[i] == tagstep))
167 :     timeid = i;
168 :    
169 :     if (timeid == -1)
170 :     handle.logMessage(LOGFAIL, "Error in tags - calculated invalid timestep");
171 :    
172 :     numtagtimesteps = (TimeInfo->numSteps() * (endyear - tagyear)) - tagstep + 1;
173 :     if (endyear == TimeInfo->getLastYear())
174 :     numtagtimesteps += TimeInfo->getLastStep();
175 :     else
176 :     numtagtimesteps += TimeInfo->numSteps();
177 :     }
178 :    
179 :     Tags::~Tags() {
180 :     int i;
181 :     for (i = 0; i < stocknames.Size(); i++)
182 :     delete[] stocknames[i];
183 :     for (i = 0; i < NumberByLength.Size(); i++)
184 :     delete NumberByLength[i];
185 :     for (i = 0; i < CI.Size(); i++)
186 :     delete CI[i];
187 :     while (AgeLengthStock.Nrow() > 0)
188 :     AgeLengthStock.Delete(0);
189 :     while (NumBeforeEating.Nrow() > 0)
190 :     NumBeforeEating.Delete(0);
191 :     delete LgrpDiv;
192 :     }
193 :    
194 :     void Tags::Reset() {
195 :     int i;
196 :     while (AgeLengthStock.Nrow() > 0)
197 :     AgeLengthStock.Delete(0);
198 :     while (NumBeforeEating.Nrow() > 0)
199 :     NumBeforeEating.Delete(0);
200 :     while (CI.Size() > 0) {
201 :     delete CI[0];
202 :     CI.Delete(0);
203 :     }
204 :     for (i = 0; i < preyindex.Size(); i++)
205 :     preyindex[i] = -1;
206 :     for (i = 0; i < updated.Size(); i++)
207 :     updated[i] = 0;
208 :     }
209 :    
210 :     void Tags::setStock(StockPtrVector& Stocks) {
211 :     int i, j, found;
212 :     StockPtrVector tmpStockVector;
213 :     char* stockname;
214 :    
215 :     preyindex.resize(1, -1);
216 :     updated.resize(1, 0);
217 :     if (!(taggingstock->isInArea(tagarea)))
218 :     handle.logMessage(LOGFAIL, "Error in tags - stock isnt defined on tagging area");
219 :    
220 :     if (taggingstock->doesMove()) {
221 :     tmpStockVector = taggingstock->getTransitionStocks();
222 :     for (i = 0; i < tmpStockVector.Size(); i++) {
223 :     transitionStocks.resize(tmpStockVector[i]);
224 :     preyindex.resize(1, -1);
225 :     updated.resize(1, 0);
226 :     tagStocks.resize(tmpStockVector[i]);
227 :     tmpStockVector[i]->setTaggedStock();
228 :     }
229 :     }
230 :    
231 :     if (taggingstock->doesMature()) {
232 :     tmpStockVector = taggingstock->getMatureStocks();
233 :     for (i = 0; i < tmpStockVector.Size(); i++) {
234 :     matureStocks.resize(tmpStockVector[i]);
235 :     found = 0;
236 :     for (j = 0; j < transitionStocks.Size(); j++)
237 :     if (strcasecmp(transitionStocks[j]->getName(), tmpStockVector[i]->getName()) != 0)
238 :     found++;
239 :    
240 :     if (found == 0) {
241 :     preyindex.resize(1, -1);
242 :     updated.resize(1, 0);
243 :     tagStocks.resize(tmpStockVector[i]);
244 :     tmpStockVector[i]->setTaggedStock();
245 :     }
246 :     }
247 :     }
248 :    
249 :     if (taggingstock->doesStray()) {
250 :     tmpStockVector = taggingstock->getStrayStocks();
251 :     for (i = 0; i < tmpStockVector.Size(); i++) {
252 :     strayStocks.resize(tmpStockVector[i]);
253 :     found = 0;
254 :     for (j = 0; j < transitionStocks.Size(); j++)
255 :     if (strcasecmp(transitionStocks[j]->getName(), tmpStockVector[i]->getName()) != 0)
256 :     found++;
257 :    
258 :     for (j = 0; j < matureStocks.Size(); j++)
259 :     if (strcasecmp(matureStocks[j]->getName(), tmpStockVector[i]->getName()) != 0)
260 :     found++;
261 :    
262 :     if (found == 0) {
263 :     preyindex.resize(1, -1);
264 :     updated.resize(1, 0);
265 :     tagStocks.resize(tmpStockVector[i]);
266 :     tmpStockVector[i]->setTaggedStock();
267 :     }
268 :     }
269 :     }
270 :    
271 :     for (i = 1; i < tagStocks.Size(); i++) {
272 :     stockname = new char[strlen(tagStocks[i]->getName()) + 1];
273 :     strcpy(stockname, tagStocks[i]->getName());
274 :     stocknames.resize(stockname);
275 :     }
276 :     }
277 :    
278 :     //Must have set stocks according to stocknames using setStock before calling Update()
279 :     //Now we need to distribute the tagged fish to the same age/length groups as the tagged stock.
280 :     void Tags::Update(int timeid) {
281 :     int i, j;
282 :     PopInfoVector NumberInArea;
283 :     NumberInArea.resizeBlank(LgrpDiv->numLengthGroups());
284 :    
285 :     const AgeBandMatrix* stockPopInArea;
286 :     const LengthGroupDivision* tmpLgrpDiv;
287 :    
288 :     stockPopInArea = &(taggingstock->getCurrentALK(tagarea));
289 :     stockPopInArea->sumColumns(NumberInArea);
290 :    
291 :     //Now we have total number of stock per length in tagarea, N(., l) (NumberInArea) and
292 :     //number of stock per age/length, N(a, l) (stockPopInArea) so we must initialise
293 :     //AgeLengthStock so that it can hold all information of number of tagged stock
294 :     //per area/age/length after endtime. We must make AgeBandMatrixPtrVector same size as
295 :     //the one in stock even though have only one area entry at the beginning
296 :     IntVector stockareas = taggingstock->getAreas();
297 :     int numareas = stockareas.Size();
298 :     int tagareaindex = -1;
299 :     j = 0;
300 :     while (j <= numareas && tagareaindex == -1) {
301 :     if (tagarea == stockareas[j])
302 :     tagareaindex = j;
303 :     j++;
304 :     }
305 :     if (tagareaindex == -1)
306 :     handle.logMessage(LOGFAIL, "Error in tags - invalid area for tagged stock");
307 :    
308 :     int maxage = stockPopInArea->maxAge();
309 :     int minage = stockPopInArea->minAge();
310 :     int numberofagegroups = maxage - minage + 1;
311 :     int upperlgrp, minl, maxl, age, length, stockid;
312 :     double numfishinarea, numstockinarea;
313 :     IntVector lgrpsize(numberofagegroups, 0);
314 :     IntVector lgrpmin(numberofagegroups, 0);
315 :    
316 :     for (i = 0; i < numberofagegroups; i++) {
317 :     lgrpmin[i]= stockPopInArea->minLength(i + minage);
318 :     upperlgrp = stockPopInArea->maxLength(i + minage);
319 :     lgrpsize[i] = upperlgrp - lgrpmin[i];
320 :     }
321 :    
322 :     AgeLengthStock.resize(new AgeBandMatrixPtrVector(numareas, minage, lgrpmin, lgrpsize));
323 :     for (age = minage; age <= maxage; age++) {
324 :     minl = stockPopInArea->minLength(age);
325 :     maxl = stockPopInArea->maxLength(age);
326 :     for (length = minl; length < maxl; length++) {
327 :     numfishinarea = NumberInArea[length].N;
328 :     numstockinarea = (*stockPopInArea)[age][length].N;
329 :     if (numfishinarea > verysmall && numstockinarea > verysmall)
330 :     (*AgeLengthStock[0])[tagareaindex][age][length].N = (*NumberByLength[timeid])[0][length - minl] * numstockinarea / numfishinarea;
331 :     else
332 :     (*AgeLengthStock[0])[tagareaindex][age][length].N = 0.0;
333 :     }
334 :     }
335 :     taggingstock->addTags(AgeLengthStock[0], this, exp(-tagloss));
336 :     updated[0] = 1;
337 :    
338 :     if (taggingstock->isEaten()) {
339 :     tmpLgrpDiv = taggingstock->getPrey()->getLengthGroupDiv();
340 :     lgrpmin.Reset();
341 :     lgrpsize.Reset();
342 :     lgrpmin.resize(numberofagegroups, 0);
343 :     lgrpsize.resize(numberofagegroups, tmpLgrpDiv->numLengthGroups());
344 :     NumBeforeEating.resize(new AgeBandMatrixPtrVector(numareas, minage, lgrpmin, lgrpsize));
345 :     CI.resize(new ConversionIndex(LgrpDiv, tmpLgrpDiv));
346 :     if (CI[CI.Size() - 1]->Error())
347 :     handle.logMessage(LOGFAIL, "Error in tags - error when checking length structure");
348 :    
349 :     stockid = stockIndex(taggingstock->getName());
350 :     if (stockid < 0 || stockid >= preyindex.Size())
351 :     handle.logMessage(LOGFAIL, "Error in tags - invalid stock identifier");
352 :    
353 :     preyindex[stockid] = NumBeforeEating.Nrow() - 1;
354 :     }
355 :    
356 :     for (i = 1; i < tagStocks.Size(); i++) {
357 :     stockPopInArea = &tagStocks[i]->getCurrentALK(tagarea);
358 :     stockareas = tagStocks[i]->getAreas();
359 :     numareas = stockareas.Size();
360 :     maxage = stockPopInArea->maxAge();
361 :     minage = stockPopInArea->minAge();
362 :     numberofagegroups = maxage - minage + 1;
363 :     lgrpmin.Reset();
364 :     lgrpsize.Reset();
365 :     lgrpmin.resize(numberofagegroups, 0);
366 :     lgrpsize.resize(numberofagegroups, 0);
367 :     for (j = 0; j < numberofagegroups; j++) {
368 :     lgrpmin[j] = stockPopInArea->minLength(j + minage);
369 :     upperlgrp = stockPopInArea->maxLength(j + minage);
370 :     lgrpsize[j] = upperlgrp - lgrpmin[j];
371 :     }
372 :    
373 :     AgeLengthStock.resize(new AgeBandMatrixPtrVector(numareas, minage, lgrpmin, lgrpsize));
374 :     if (tagStocks[i]->isEaten()) {
375 :     tmpLgrpDiv = tagStocks[i]->getPrey()->getLengthGroupDiv();
376 :     lgrpmin.Reset();
377 :     lgrpsize.Reset();
378 :     lgrpmin.resize(numberofagegroups, 0);
379 :     lgrpsize.resize(numberofagegroups, tmpLgrpDiv->numLengthGroups());
380 :     NumBeforeEating.resize(new AgeBandMatrixPtrVector(numareas, minage, lgrpmin, lgrpsize));
381 :     CI.resize(new ConversionIndex(LgrpDiv, tmpLgrpDiv));
382 :     if (CI[CI.Size() - 1]->Error())
383 :     handle.logMessage(LOGFAIL, "Error in tags - error when checking length structure");
384 :    
385 :     stockid = stockIndex(tagStocks[i]->getName());
386 :     if (stockid < 0 || stockid >= preyindex.Size())
387 :     handle.logMessage(LOGFAIL, "Error in tags - invalid stock identifier");
388 :    
389 :     preyindex[stockid] = NumBeforeEating.Nrow() - 1;
390 :     }
391 :     }
392 :     }
393 :    
394 :     void Tags::updateTags(int year, int step) {
395 :     int i, timeid;
396 :    
397 :     timeid = -1;
398 :     for (i = 0; i < Years.Size(); i++)
399 :     if (Years[i] == year && Steps[i] == step)
400 :     timeid = i;
401 :    
402 :     if (timeid != -1) {
403 :     if (tagyear == year && tagstep == step)
404 :     this->Update(timeid);
405 :     else
406 :     this->addToTagStock(timeid);
407 :     }
408 :     }
409 :    
410 :     void Tags::deleteStockTags() {
411 :     int i;
412 :     for (i = 0; i < tagStocks.Size(); i++) {
413 :     if (updated[i] == 1) {
414 :     tagStocks[i]->deleteTags(this->getName());
415 :     updated[i] = 2;
416 :     }
417 :     }
418 :     }
419 :    
420 :     void Tags::updateMatureStock(const TimeClass* const TimeInfo) {
421 :     int i, id;
422 :    
423 :     if (endyear <= TimeInfo->getYear())
424 :     handle.logMessage(LOGWARN, "Warning in tags - tagging experiment has finished");
425 :     else {
426 :     for (i = 0; i < matureStocks.Size(); i++) {
427 :     id = stockIndex(matureStocks[i]->getName());
428 :     if (id < 0 || id >= AgeLengthStock.Nrow())
429 :     handle.logMessage(LOGFAIL, "Error in tags - invalid stock identifier");
430 :    
431 :     if (updated[id] == 0) {
432 :     matureStocks[i]->addTags(AgeLengthStock[id], this, exp(-tagloss));
433 :     updated[id] = 1;
434 :     }
435 :     }
436 :     }
437 :     }
438 :    
439 :     void Tags::updateTransitionStock(const TimeClass* const TimeInfo) {
440 :     int i, id;
441 :    
442 :     if (endyear <= TimeInfo->getYear())
443 :     handle.logMessage(LOGWARN, "Warning in tags - tagging experiment has finished");
444 :     else {
445 :     for (i = 0; i < transitionStocks.Size(); i++) {
446 :     id = stockIndex(transitionStocks[i]->getName());
447 :     if (id < 0 || id >= AgeLengthStock.Nrow())
448 :     handle.logMessage(LOGFAIL, "Error in tags - invalid stock identifier");
449 :    
450 :     if (updated[id] == 0) {
451 :     transitionStocks[i]->addTags(AgeLengthStock[id], this, exp(-tagloss));
452 :     updated[id] = 1;
453 :     }
454 :     }
455 :     }
456 :     }
457 :    
458 :     void Tags::updateStrayStock(const TimeClass* const TimeInfo) {
459 :     int i, id;
460 :    
461 :     if (endyear <= TimeInfo->getYear())
462 :     handle.logMessage(LOGWARN, "Warning in tags - tagging experiment has finished");
463 :     else {
464 :     for (i = 0; i < strayStocks.Size(); i++) {
465 :     id = stockIndex(strayStocks[i]->getName());
466 :     if (id < 0 || id >= AgeLengthStock.Nrow())
467 :     handle.logMessage(LOGFAIL, "Error in tags - invalid stock identifier");
468 :    
469 :     if (updated[id] == 0) {
470 :     strayStocks[i]->addTags(AgeLengthStock[id], this, exp(-tagloss));
471 :     updated[id] = 1;
472 :     }
473 :     }
474 :     }
475 :     }
476 :    
477 :     int Tags::stockIndex(const char* stockname) {
478 :     int i;
479 :     for (i = 0; i < tagStocks.Size(); i++)
480 :     if (strcasecmp(stockname, tagStocks[i]->getName()) == 0)
481 :     return i;
482 :    
483 :     return -1;
484 :     }
485 :    
486 :     int Tags::areaIndex(const char* stockname, int area) {
487 :     int i, j;
488 :     for (i = 0; i < tagStocks.Size(); i++) {
489 :     if (strcasecmp(stockname, tagStocks[i]->getName()) == 0) {
490 :     IntVector stockareas = tagStocks[i]->getAreas();
491 :     for (j = 0; j < stockareas.Size(); j++)
492 :     if (stockareas[j] == area)
493 :     return j;
494 :     return -1;
495 :     }
496 :     }
497 :     return -1;
498 :     }
499 :    
500 :     void Tags::storeConsumptionALK(int area, const char* stockname) {
501 :     int stockid, preyid, areaid;
502 :     stockid = stockIndex(stockname);
503 :     if (stockid < 0)
504 :     handle.logMessage(LOGFAIL, "Error in tags - invalid stock identifier");
505 :    
506 :     preyid = preyindex[stockid];
507 :     if (preyid > NumBeforeEating.Nrow() || preyid < 0)
508 :     handle.logMessage(LOGFAIL, "Error in tags - invalid prey identifier");
509 :    
510 :     areaid = areaIndex(stockname, area);
511 :     if (areaid < 0)
512 :     handle.logMessage(LOGFAIL, "Error in tags - invalid area identifier");
513 :    
514 :     (*NumBeforeEating[preyid])[areaid].setToZero();
515 :     (*NumBeforeEating[preyid])[areaid].Add((*AgeLengthStock[stockid])[areaid], *CI[preyid]);
516 :     }
517 :    
518 :     const AgeBandMatrix& Tags::getConsumptionALK(int area, const char* stockname) {
519 :     int stockid, preyid, areaid;
520 :     stockid = stockIndex(stockname);
521 :     if (stockid < 0)
522 :     handle.logMessage(LOGFAIL, "Error in tags - invalid stock identifier");
523 :    
524 :     preyid = preyindex[stockid];
525 :     if (preyid > NumBeforeEating.Nrow() || preyid < 0)
526 :     handle.logMessage(LOGFAIL, "Error in tags - invalid prey identifier");
527 :    
528 :     areaid = areaIndex(stockname, area);
529 :     if (areaid < 0)
530 :     handle.logMessage(LOGFAIL, "Error in tags - invalid area identifier");
531 :    
532 :     return (*NumBeforeEating[preyid])[areaid];
533 :     }
534 :    
535 :     int Tags::isWithinPeriod(int year, int step) {
536 :     if ((year > tagyear || (year == tagyear && step >= tagstep)) && (year <= endyear))
537 :     return 1;
538 :     return 0;
539 :     }
540 :    
541 :     void Tags::addToTagStock(int timeid) {
542 :     int i, tagareaindex;
543 :     PopInfoVector NumberInArea;
544 :     NumberInArea.resizeBlank(LgrpDiv->numLengthGroups());
545 :     const AgeBandMatrix* stockPopInArea;
546 :     stockPopInArea = &(taggingstock->getCurrentALK(tagarea));
547 :     stockPopInArea->sumColumns(NumberInArea);
548 :    
549 :     i = 0;
550 :     tagareaindex = -1;
551 :     IntVector stockareas = taggingstock->getAreas();
552 :     while (i <= stockareas.Size() && tagareaindex == -1) {
553 :     if (tagarea == stockareas[i])
554 :     tagareaindex = i;
555 :     i++;
556 :     }
557 :     if (tagareaindex == -1)
558 :     handle.logMessage(LOGFAIL, "Error in tags - invalid area for tagged stock");
559 :    
560 :     int maxage = stockPopInArea->maxAge();
561 :     int minage = stockPopInArea->minAge();
562 :     int minl, maxl, age, length;
563 :     double numfishinarea, numstockinarea;
564 :    
565 :     for (age = minage; age <= maxage; age++) {
566 :     minl = stockPopInArea->minLength(age);
567 :     maxl = stockPopInArea->maxLength(age);
568 :     for (length = minl; length < maxl; length++) {
569 :     numfishinarea = NumberInArea[length].N;
570 :     numstockinarea = (*stockPopInArea)[age][length].N;
571 :     if (numfishinarea > verysmall && numstockinarea > verysmall)
572 :     (*AgeLengthStock[0])[tagareaindex][age][length].N += (*NumberByLength[timeid])[0][length - minl] * numstockinarea / numfishinarea;
573 :     }
574 :     }
575 :     }
576 :    
577 :     void Tags::Print(ofstream& outfile) const {
578 :     // outfile << "\nTag\nName" << sep << this->getName() << endl;
579 :     }

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

Powered By FusionForge