Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

bin.cpp

00001 /***************************************************************************
00002                           bin.cpp  -  description
00003                              -------------------
00004     begin                : Tue Jul 25 2000
00005     copyright            : (C) 2000 by Michael Peeters
00006     email                : Michael.Peeters@vub.ac.be
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "bin.h"
00019 
00020 namespace MODEL {
00021 
00022   Bin::Bin(number start, number end, counter nobins)
00023         : x0(start),x1(end),N(nobins)
00024   {
00025         dx=(x1-x0)/number(N);
00026         histogram=new vector<counter>(0);
00027         histogram->resize(N+1,0);
00028   }
00029 
00030   Bin::~Bin()
00031   {
00032         delete histogram;
00033   }
00034 
00035   void
00036   Bin::add_value(number added)
00037   {
00038         counter bin;
00039 
00040         if(added<x0) bin=0;
00041         else if(added>=x1) bin=N;
00042         else 
00043           {
00044           added-=x0;
00045           added/=dx; 
00046 
00047           bin=counter(added)+1;
00048           }
00049 
00050         if(bin<1)bin=0;
00051         else if(bin>N)bin=N;
00052         (*histogram)[bin]++;
00053   }
00054 
00055   vector<counter> 
00056   Bin::get_histo(void)
00057   {
00058         return (*histogram);
00059   } 
00060 
00061   vector<number>
00062   Bin::get_bins(void)
00063   {
00064         vector<number> bins(0);
00065         number x=x0-dx;
00066         for(counter i=0;i<N+1;i++)
00067           {
00068                                 bins.push_back(x);
00069                                 x+=dx;
00070           }
00071         return bins;
00072   }
00073 } // end namespace
00074 
00075 /*********************************************************************
00076 $Id: bin.cpp,v 1.1 2001/05/22 10:54:55 mpeeters Exp $
00077 **********************************************************************
00078 
00079 $Log: bin.cpp,v $
00080 Revision 1.1  2001/05/22 10:54:55  mpeeters
00081 Moved sources and headers for libModel to model/ subdirectory, in an attempt to rationalize the source tree. This should make things "netter".
00082 
00083 Revision 1.2  2000/09/15 10:26:31  mpeeters
00084 Cleaned out header and added CVS tails to files, removed superfuous
00085 @author comments, inserted dates
00086 
00087 *********************************************************************/

To get the sources or tarballs, please go to SourceForge or you can use the CVS repository.

More Info? Michael Peeters. Also, check our research website: www.alna.vub.ac.be

Last update: June 2002.


Looking for Open Source? Check out SourceForge Logo !