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

Annotation of /trunk/gadget/recaggregator.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "recaggregator.h"
2 :     #include "areatime.h"
3 :     #include "readfunc.h"
4 :     #include "stock.h"
5 :     #include "stockprey.h"
6 :     #include "poppredator.h"
7 :     #include "fleet.h"
8 :     #include "readword.h"
9 :     #include "errorhandler.h"
10 :     #include "gadget.h"
11 :     #include "global.h"
12 :    
13 :     RecAggregator::RecAggregator(const FleetPtrVector& Fleets,
14 :     const StockPtrVector& Stocks, LengthGroupDivision* const Lgrpdiv,
15 :     const IntMatrix& Areas, const IntMatrix& Ages, Tags* tag)
16 :     : taggingExp(tag), LgrpDiv(Lgrpdiv), areas(Areas), ages(Ages),
17 :     doescatch(Fleets.Size(), Stocks.Size(), 0), suitptr(0), alptr(0) {
18 :    
19 :     int i, j;
20 :     //JMB its simpler to just store pointers to the predators
21 :     //and preys rather than pointers to the fleets and stocks
22 :     for (i = 0; i < Stocks.Size(); i++)
23 :     preys.resize(Stocks[i]->getPrey());
24 :     for (i = 0; i < Fleets.Size(); i++)
25 :     predators.resize(Fleets[i]->getPredator());
26 :    
27 :     for (i = 0; i < preys.Size(); i++) {
28 :     CI.resize(new ConversionIndex(preys[i]->getLengthGroupDiv(), LgrpDiv));
29 :     if (CI[i]->Error())
30 :     handle.logMessage(LOGFAIL, "Error in recaggregator - error when checking length structure");
31 :     }
32 :    
33 :     for (i = 0; i < predators.Size(); i++)
34 :     for (j = 0; j < preys.Size(); j++)
35 :     if (predators[i]->doesEat(preys[j]->getName()))
36 :     doescatch[i][j] = 1;
37 :    
38 :     //Resize total using dummy variables tmppop and popmatrix.
39 :     PopInfo tmppop;
40 :     tmppop.N = 1.0;
41 :     PopInfoMatrix popmatrix(ages.Nrow(), LgrpDiv->numLengthGroups(), tmppop);
42 :     total.resize(areas.Nrow(), 0, 0, popmatrix);
43 :     this->Reset();
44 :     }
45 :    
46 :     RecAggregator::~RecAggregator() {
47 :     int i;
48 :     for (i = 0; i < CI.Size(); i++)
49 :     delete CI[i];
50 :     }
51 :    
52 :     void RecAggregator::Print(ofstream& outfile) const {
53 :     int i, j;
54 :     for (i = 0; i < total.Size(); i++) {
55 :     outfile << "\tInternal areas";
56 :     for (j = 0; j < areas.Ncol(i); j++)
57 :     outfile << sep << areas[i][j];
58 :     outfile << endl;
59 :     total[i].printNumbers(outfile);
60 :     }
61 :     outfile.flush();
62 :     }
63 :    
64 :     void RecAggregator::Reset() {
65 :     int i;
66 :     for (i = 0; i < total.Size(); i++)
67 :     total[i].setToZero();
68 :     }
69 :    
70 :     void RecAggregator::Sum() {
71 :    
72 :     int f, g, h, i, j, k, r;
73 :     int predl = 0; //JMB there is only ever one length group ...
74 :     double ratio;
75 :    
76 :     this->Reset();
77 :     for (f = 0; f < predators.Size(); f++) {
78 :     for (h = 0; h < preys.Size(); h++) {
79 :     if (doescatch[f][h]) {
80 :     for (r = 0; r < areas.Nrow(); r++) {
81 :     for (j = 0; j < areas.Ncol(r); j++) {
82 :     if ((preys[h]->isPreyArea(areas[r][j])) && (predators[f]->isInArea(areas[r][j]))) {
83 :     for (i = 0; i < predators[f]->numPreys(); i++) {
84 :     if (strcasecmp(preys[h]->getName(), predators[f]->getPrey(i)->getName()) == 0) {
85 :    
86 :     //JMB removed the overconsumption stuff
87 :     suitptr = &predators[f]->getSuitability(i)[predl];
88 :     alptr = &taggingExp->getConsumptionALK(areas[r][j], preys[h]->getName());
89 :     ratio = predators[f]->getConsumptionRatio(areas[r][j], i, predl);
90 :     for (g = 0; g < ages.Nrow(); g++)
91 :     for (k = 0; k < ages.Ncol(g); k++)
92 :     if ((alptr->minAge() <= ages[g][k]) && (ages[g][k] <= alptr->maxAge()))
93 :     total[r][g].Add((*alptr)[ages[g][k]], *CI[h], *suitptr, ratio);
94 :     }
95 :     }
96 :     }
97 :     }
98 :     }
99 :     }
100 :     }
101 :     }
102 :     }

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

Powered By FusionForge