Ignore:
Timestamp:
Mar 3, 2010, 7:10:36 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
bc46c1
Parents:
f78203
git-author:
Frederik Heber <heber@…> (03/03/10 18:41:03)
git-committer:
Frederik Heber <heber@…> (03/03/10 19:10:36)
Message:

BUGFIX: rounding imprecision let values appear twice in BinMap.

  • we fix this by always converting bin to integer and then back to double when putting into map in BinData()
  • GetBin returns integer

Signed-off-by: Frederik Heber <heber@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/analysis_correlation.hpp

    rf78203 rdd3a80  
    5151CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] );
    5252CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] );
    53 double GetBin ( const double value, const double BinWidth, const double BinStart );
     53int GetBin ( const double value, const double BinWidth, const double BinStart );
    5454void OutputCorrelation( ofstream * const file, const BinPairMap * const map );
    5555void OutputPairCorrelation( ofstream * const file, const BinPairMap * const map );
     
    101101{
    102102  BinPairMap *outmap = new BinPairMap;
    103   double bin = 0.;
     103  int bin = 0;
    104104  double start = 0.;
    105105  double end = 0.;
     
    117117    start = BinStart;
    118118    end = BinEnd;
    119     for (double runner = start; runner <= end; runner += BinWidth)
    120       outmap->insert( pair<double, int> (runner, 0) );
     119    for (int runner = 0; runner <= ceil((end-start)/BinWidth); runner++)
     120      outmap->insert( pair<double, int> ((double)runner*BinWidth+start, 0) );
    121121  }
    122122
    123123  for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
    124124    bin = GetBin (runner->first, BinWidth, start);
    125     BinPairMapInserter = outmap->insert ( pair<double, int> (bin, 1) );
     125    BinPairMapInserter = outmap->insert ( pair<double, int> ((double)bin*BinWidth+start, 1) );
    126126    if (!BinPairMapInserter.second) {  // bin already present, increase
    127127      BinPairMapInserter.first->second += 1;
Note: See TracChangeset for help on using the changeset viewer.