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

Annotation of /trunk/gadget/otherfood.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "otherfood.h"
2 :     #include "readfunc.h"
3 :     #include "readword.h"
4 :     #include "lengthprey.h"
5 :     #include "errorhandler.h"
6 :     #include "intvector.h"
7 :     #include "popinfo.h"
8 :     #include "popinfovector.h"
9 :     #include "gadget.h"
10 :     #include "global.h"
11 :    
12 :     OtherFood::OtherFood(CommentStream& infile, const char* givenname,
13 :     const AreaClass* const Area, const TimeClass* const TimeInfo, Keeper* const keeper)
14 :     : BaseClass(givenname), prey(0) {
15 :    
16 :     char text[MaxStrLength];
17 :     strncpy(text, "", MaxStrLength);
18 :     ifstream subfile;
19 :     CommentStream subcomment(subfile);
20 :     int tmpint = 0;
21 :     IntVector tmpareas;
22 :     char c;
23 :    
24 :     keeper->addString("otherfood");
25 :     keeper->addString(givenname);
26 :    
27 :     infile >> text >> ws;
28 :     if (strcasecmp(text, "livesonareas") != 0)
29 :     handle.logFileUnexpected(LOGFAIL, "livesonareas", text);
30 :    
31 :     c = infile.peek();
32 :     while (isdigit(c) && !infile.eof()) {
33 :     infile >> tmpint >> ws;
34 :     tmpareas.resize(1, Area->getInnerArea(tmpint));
35 :     c = infile.peek();
36 :     }
37 :     this->storeAreas(tmpareas);
38 :    
39 :     prey = new LengthPrey(infile, this->getName(), areas, TimeInfo, keeper);
40 :    
41 :     infile >> text >> ws;
42 :     if ((strcasecmp(text, "amount") != 0) && (strcasecmp(text, "amounts") != 0))
43 :     handle.logFileUnexpected(LOGFAIL, "amount", text);
44 :    
45 :     infile >> text >> ws;
46 :     subfile.open(text, ios::in);
47 :     handle.checkIfFailure(subfile, text);
48 :     handle.Open(text);
49 :     readAmounts(subcomment, areas, TimeInfo, Area, amount, this->getName());
50 :     amount.Inform(keeper);
51 :     handle.Close();
52 :     subfile.close();
53 :     subfile.clear();
54 :    
55 :     //resize tmpPopulation, and set the weight to 1 since this will never change
56 :     PopInfo tmppop;
57 :     tmppop.W = 1.0;
58 :     tmpPopulation.AddRows(Area->numAreas(), 1, tmppop);
59 :    
60 :     keeper->clearLast();
61 :     keeper->clearLast();
62 :     }
63 :    
64 :     OtherFood::~OtherFood() {
65 :     delete prey;
66 :     }
67 :    
68 :     void OtherFood::checkEat(int area, const TimeClass* const TimeInfo) {
69 :     if (this->isOtherFoodStepArea(area, TimeInfo))
70 :     prey->checkConsumption(area, TimeInfo);
71 :     }
72 :    
73 :     void OtherFood::calcNumbers(int area, const TimeClass* const TimeInfo) {
74 :     if (this->isOtherFoodStepArea(area, TimeInfo))
75 :     prey->Sum(tmpPopulation[this->areaNum(area)], area);
76 :     }
77 :    
78 :     int OtherFood::isOtherFoodStepArea(int area, const TimeClass* const TimeInfo) {
79 :     if (this->isInArea(area) == 0)
80 :     return 0;
81 :     if (amount[TimeInfo->getTime()][this->areaNum(area)] < 0.0)
82 :     handle.logMessage(LOGWARN, "Warning in otherfood - negative amount to be consumed");
83 :     if (isZero(amount[TimeInfo->getTime()][this->areaNum(area)]))
84 :     return 0;
85 :     return 1;
86 :     }
87 :    
88 :     void OtherFood::Print(ofstream& outfile) const {
89 :     outfile << "\nOtherfood " << this->getName() << endl;
90 :     prey->Print(outfile);
91 :     outfile << endl;
92 :     }
93 :    
94 :     void OtherFood::Reset(const TimeClass* const TimeInfo) {
95 :     int i;
96 :     prey->Reset(TimeInfo);
97 :     for (i = 0; i < tmpPopulation.Nrow(); i++)
98 :     if (this->isOtherFoodStepArea(i, TimeInfo))
99 :     tmpPopulation[this->areaNum(i)][0].N = amount[TimeInfo->getTime()][this->areaNum(i)];
100 :     }

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

Powered By FusionForge