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

Annotation of /trunk/gadget/sibyfleetonstep.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "sibyfleetonstep.h"
2 :     #include "stock.h"
3 :     #include "areatime.h"
4 :     #include "mathfunc.h"
5 :     #include "errorhandler.h"
6 :     #include "gadget.h"
7 :     #include "global.h"
8 :    
9 :     SIByFleetOnStep::SIByFleetOnStep(CommentStream& infile, const IntMatrix& areas,
10 :     const DoubleVector& lengths, const CharPtrVector& areaindex,
11 :     const CharPtrVector& lenindex, const TimeClass* const TimeInfo,
12 :     const char* datafilename, const char* givenname, int bio)
13 :     : SIOnStep(infile, datafilename, areaindex, TimeInfo, areas, lenindex, givenname, bio, SIFLEET) {
14 :    
15 :     LgrpDiv = new LengthGroupDivision(lengths);
16 :     if (LgrpDiv->Error())
17 :     handle.logMessage(LOGFAIL, "Error in surveyindex - failed to create length group");
18 :     }
19 :    
20 :     SIByFleetOnStep::~SIByFleetOnStep() {
21 :     if (aggregator != 0)
22 :     delete aggregator;
23 :     }
24 :    
25 :     void SIByFleetOnStep::setFleetsAndStocks(FleetPtrVector& Fleets, StockPtrVector& Stocks) {
26 :     int i, found, minage, maxage;
27 :    
28 :     if (Stocks.Size() == 0)
29 :     handle.logMessage(LOGFAIL, "Error in surveyindex - failed to initialise stock data");
30 :     if (Fleets.Size() == 0)
31 :     handle.logMessage(LOGFAIL, "Error in surveyindex - failed to initialise fleet data");
32 :    
33 :     minage = Stocks[0]->minAge();
34 :     maxage = Stocks[0]->maxAge();
35 :     if (Stocks.Size() > 1) {
36 :     for (i = 1; i < Stocks.Size(); i++) {
37 :     minage = min(Stocks[i]->minAge(), minage);
38 :     maxage = max(Stocks[i]->maxAge(), maxage);
39 :     }
40 :     }
41 :    
42 :     Ages.AddRows(1, maxage - minage + 1, 0);
43 :     for (i = 0; i < Ages.Ncol(); i++)
44 :     Ages[0][i] = i + minage;
45 :    
46 :     //check stock lengths
47 :     if (handle.getLogLevel() >= LOGWARN) {
48 :     found = 0;
49 :     for (i = 0; i < Stocks.Size(); i++)
50 :     if (LgrpDiv->maxLength(0) > Stocks[i]->getLengthGroupDiv()->minLength())
51 :     found++;
52 :     if (found == 0)
53 :     handle.logMessage(LOGWARN, "Warning in surveyindex - minimum length group less than stock length");
54 :    
55 :     found = 0;
56 :     for (i = 0; i < Stocks.Size(); i++)
57 :     if (LgrpDiv->minLength(LgrpDiv->numLengthGroups()) < Stocks[i]->getLengthGroupDiv()->maxLength())
58 :     found++;
59 :     if (found == 0)
60 :     handle.logMessage(LOGWARN, "Warning in surveyindex - maximum length group greater than stock length");
61 :     }
62 :    
63 :     aggregator = new FleetPreyAggregator(Fleets, Stocks, LgrpDiv, Areas, Ages, 0);
64 :     }
65 :    
66 :     void SIByFleetOnStep::Sum(const TimeClass* const TimeInfo) {
67 :     if (!AAT.atCurrentTime(TimeInfo))
68 :     return;
69 :    
70 :     int a, i;
71 :     timeindex = -1;
72 :     for (i = 0; i < Years.Size(); i++)
73 :     if ((Years[i] == TimeInfo->getYear()) && (Steps[i] == TimeInfo->getStep()))
74 :     timeindex = i;
75 :     if (timeindex == -1)
76 :     handle.logMessage(LOGFAIL, "Error in surveyindex - invalid timestep");
77 :    
78 :     if (handle.getLogLevel() >= LOGMESSAGE)
79 :     handle.logMessage(LOGMESSAGE, "Calculating index for surveyindex component", this->getName());
80 :    
81 :     aggregator->Sum();
82 :     if ((handle.getLogLevel() >= LOGWARN) && (aggregator->checkCatchData()))
83 :     handle.logMessage(LOGWARN, "Warning in surveyindex - zero catch found");
84 :    
85 :     alptr = &aggregator->getSum();
86 :     //alptr will only have one age group
87 :     for (a = 0; a < Areas.Nrow(); a++)
88 :     for (i = 0; i < LgrpDiv->numLengthGroups(); i++)
89 :     (*modelIndex[timeindex])[a][i] = (*alptr)[a][0][i].N;
90 :    
91 :     if (biomass) //JMB experimental survey index based on the biomass
92 :     for (a = 0; a < Areas.Nrow(); a++)
93 :     for (i = 0; i < LgrpDiv->numLengthGroups(); i++)
94 :     (*modelIndex[timeindex])[a][i] *= (*alptr)[a][0][i].W;
95 :     }

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

Powered By FusionForge