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

View of /trunk/gadget/otherfood.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (download) (annotate)
Mon Feb 10 17:09:07 2014 UTC (10 years, 3 months ago) by agomez
File size: 2905 byte(s)
Initial version based on Gadget 2.2.00
#include "otherfood.h"
#include "readfunc.h"
#include "readword.h"
#include "lengthprey.h"
#include "errorhandler.h"
#include "intvector.h"
#include "popinfo.h"
#include "popinfovector.h"
#include "gadget.h"
#include "global.h"

OtherFood::OtherFood(CommentStream& infile, const char* givenname,
  const AreaClass* const Area, const TimeClass* const TimeInfo, Keeper* const keeper)
  : BaseClass(givenname), prey(0) {

  char text[MaxStrLength];
  strncpy(text, "", MaxStrLength);
  ifstream subfile;
  CommentStream subcomment(subfile);
  int tmpint = 0;
  IntVector tmpareas;
  char c;

  keeper->addString("otherfood");
  keeper->addString(givenname);

  infile >> text >> ws;
  if (strcasecmp(text, "livesonareas") != 0)
    handle.logFileUnexpected(LOGFAIL, "livesonareas", text);

  c = infile.peek();
  while (isdigit(c) && !infile.eof()) {
    infile >> tmpint >> ws;
    tmpareas.resize(1, Area->getInnerArea(tmpint));
    c = infile.peek();
  }
  this->storeAreas(tmpareas);

  prey = new LengthPrey(infile, this->getName(), areas, TimeInfo, keeper);

  infile >> text >> ws;
  if ((strcasecmp(text, "amount") != 0) && (strcasecmp(text, "amounts") != 0))
    handle.logFileUnexpected(LOGFAIL, "amount", text);

  infile >> text >> ws;
  subfile.open(text, ios::in);
  handle.checkIfFailure(subfile, text);
  handle.Open(text);
  readAmounts(subcomment, areas, TimeInfo, Area, amount, this->getName());
  amount.Inform(keeper);
  handle.Close();
  subfile.close();
  subfile.clear();

  //resize tmpPopulation, and set the weight to 1 since this will never change
  PopInfo tmppop;
  tmppop.W = 1.0;
  tmpPopulation.AddRows(Area->numAreas(), 1, tmppop);

  keeper->clearLast();
  keeper->clearLast();
}

OtherFood::~OtherFood() {
  delete prey;
}

void OtherFood::checkEat(int area, const TimeClass* const TimeInfo) {
  if (this->isOtherFoodStepArea(area, TimeInfo))
    prey->checkConsumption(area, TimeInfo);
}

void OtherFood::calcNumbers(int area, const TimeClass* const TimeInfo) {
  if (this->isOtherFoodStepArea(area, TimeInfo))
    prey->Sum(tmpPopulation[this->areaNum(area)], area);
}

int OtherFood::isOtherFoodStepArea(int area, const TimeClass* const TimeInfo) {
  if (this->isInArea(area) == 0)
    return 0;
  if (amount[TimeInfo->getTime()][this->areaNum(area)] < 0.0)
    handle.logMessage(LOGWARN, "Warning in otherfood - negative amount to be consumed");
  if (isZero(amount[TimeInfo->getTime()][this->areaNum(area)]))
    return 0;
  return 1;
}

void OtherFood::Print(ofstream& outfile) const {
  outfile << "\nOtherfood " << this->getName() << endl;
  prey->Print(outfile);
  outfile << endl;
}

void OtherFood::Reset(const TimeClass* const TimeInfo) {
  int i;
  prey->Reset(TimeInfo);
  for (i = 0; i < tmpPopulation.Nrow(); i++)
    if (this->isOtherFoodStepArea(i, TimeInfo))
      tmpPopulation[this->areaNum(i)][0].N = amount[TimeInfo->getTime()][this->areaNum(i)];
}

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

Powered By FusionForge