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

Annotation of /trunk/gadget/stockpreyaggregator.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "stockpreyaggregator.h"
2 :     #include "conversionindex.h"
3 :     #include "stockprey.h"
4 :     #include "mathfunc.h"
5 :     #include "errorhandler.h"
6 :     #include "gadget.h"
7 :     #include "global.h"
8 :    
9 :     StockPreyAggregator::StockPreyAggregator(const PreyPtrVector& Preys,
10 :     const LengthGroupDivision* const LgrpDiv, const IntMatrix& Areas, const IntMatrix& Ages)
11 :     : preys(Preys), areas(Areas), ages(Ages), alptr(0) {
12 :    
13 :     int i;
14 :     for (i = 0; i < preys.Size(); i++) {
15 :     CI.resize(new ConversionIndex(preys[i]->getLengthGroupDiv(), LgrpDiv));
16 :     if (CI[i]->Error())
17 :     handle.logMessage(LOGFAIL, "Error in stockpreyaggregator - error when checking length structure");
18 :    
19 :     //check that the prey is a stock
20 :     if (preys[i]->getType() == LENGTHPREY)
21 :     handle.logMessage(LOGFAIL, "Error in stockpreyaggregator - cannot aggregate prey", preys[i]->getName());
22 :     }
23 :    
24 :     //Resize total using dummy variables tmppop and popmatrix.
25 :     PopInfo tmppop;
26 :     tmppop.N = 1.0;
27 :     PopInfoMatrix popmatrix(ages.Nrow(), LgrpDiv->numLengthGroups(), tmppop);
28 :     total.resize(areas.Nrow(), 0, 0, popmatrix);
29 :     this->Reset();
30 :     }
31 :    
32 :     StockPreyAggregator::~StockPreyAggregator() {
33 :     int i;
34 :     for (i = 0; i < CI.Size(); i++)
35 :     delete CI[i];
36 :     }
37 :    
38 :     void StockPreyAggregator::Print(ofstream& outfile) const {
39 :     int i, j;
40 :     for (i = 0; i < total.Size(); i++) {
41 :     outfile << "\tInternal areas";
42 :     for (j = 0; j < areas.Ncol(i); j++)
43 :     outfile << sep << areas[i][j];
44 :     outfile << endl;
45 :     total[i].printNumbers(outfile);
46 :     }
47 :     outfile.flush();
48 :     }
49 :    
50 :     void StockPreyAggregator::Reset() {
51 :     int i;
52 :     for (i = 0; i < total.Size(); i++)
53 :     total[i].setToZero();
54 :     }
55 :    
56 :     void StockPreyAggregator::Sum() {
57 :     int area, age, i, j, k;
58 :    
59 :     this->Reset();
60 :     //Sum over the appropriate preys, areas, ages and length groups.
61 :     for (i = 0; i < preys.Size(); i++) {
62 :     for (area = 0; area < areas.Nrow(); area++) {
63 :     for (j = 0; j < areas.Ncol(area); j++) {
64 :     if (preys[i]->isPreyArea(areas[area][j])) {
65 :     alptr = &((StockPrey*)preys[i])->getConsumptionALK(areas[area][j]);
66 :     for (age = 0; age < ages.Nrow(); age++) {
67 :     for (k = 0; k < ages.Ncol(age); k++) {
68 :     if ((alptr->minAge() <= ages[age][k]) && (ages[age][k] <= alptr->maxAge()))
69 :     total[area][age].Add((*alptr)[ages[age][k]], *CI[i], preys[i]->getUseRatio(areas[area][j]));
70 :     }
71 :     }
72 :     }
73 :     }
74 :     }
75 :     }
76 :     }

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

Powered By FusionForge