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

View of /trunk/gadget/popstatistics.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: 1322 byte(s)
Initial version based on Gadget 2.2.00
#include "popstatistics.h"
#include "popinfo.h"
#include "errorhandler.h"
#include "gadget.h"
#include "global.h"

void PopStatistics::calcStatistics(const PopInfoIndexVector& pop,
  const LengthGroupDivision* const lgrpdiv, int calcweight) {

  PopInfo sum;
  int i, offset;
  double tmp;

  if (pop.Size() != lgrpdiv->numLengthGroups())
    handle.logMessage(LOGFAIL, "Error in popstatistics - length groups dont match population");

  offset = pop.minCol();
  meanlength = meanweight = totalnumber = sdevlength = 0.0;
  for (i = offset; i < pop.maxCol(); i++) {
    if ((handle.getLogLevel() >= LOGWARN) && calcweight)
      if ((isZero(pop[i].W)) && (!(isZero(pop[i].N))))
        handle.logMessage(LOGWARN, "Warning in popstatistics - non-zero population has zero mean weight");

    if (calcweight)
      sum += pop[i];
    totalnumber += pop[i].N;
    meanlength += pop[i].N * lgrpdiv->meanLength(i - offset);
  }

  if (totalnumber > verysmall) {
    if (calcweight)
      meanweight = sum.W;
    meanlength /= totalnumber;
    for (i = offset; i < pop.maxCol(); i++) {
      tmp = meanlength - lgrpdiv->meanLength(i - offset);
      sdevlength += pop[i].N * tmp * tmp;
    }
    sdevlength = sqrt(sdevlength / totalnumber);
  } else  {
    //JMB reset back to 0
    meanlength = 0.0;
    totalnumber = 0.0;
  }
}

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

Powered By FusionForge