Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

probeSG.cpp

Go to the documentation of this file.
00001 #include <fstream>
00002 #include "probeSG.h"
00003 
00010 ProbeSG::ProbeSG( string _theName) :
00011   Sum_S(0), Sum_G(0), StartTime(0), lastTime(0), Probe(_theName, false)
00012 {
00013 }
00014 
00015 void ProbeSG::Reset( void )
00016 {
00017   Sum_S = 0;
00018   Sum_G = 0;
00019   Sum_S_part = 0;
00020   Sum_G_part = 0;
00021   StartTime = 0;
00022   lastTime = 0;
00023   Probe::Reset();
00024 }
00025 
00026 void ProbeSG::Zap( double time )
00027 {
00028   Sum_S = 0;
00029   Sum_G = 0;
00030   Sum_S_part = 0;
00031   Sum_G_part = 0;
00032   StartTime = time;
00033   lastTime = time;
00034 }
00035 
00036 void ProbeSG::Observe_S( double value )
00037 {
00038   Sum_S += value;
00039   Sum_S_part += value;
00040   Sum_G += value;
00041   Sum_G_part += value;
00042 }
00043 
00044 void ProbeSG::Observe_G( double value )
00045 {
00046   Sum_G += value;
00047   Sum_G_part += value;
00048 }
00049 
00050 void ProbeSG::WriteToFile( double time )
00051 {
00052   // output files are not left open, as they are when needed.
00053   // Append is a Probe's internal variable, false when the probe is created.
00054   // You can use it to choose if your file is to create from scratch or just appended.
00055   // Note that NePSing manages the probe renaming from one run to another.
00056   // theRealName.c_str() is the actual name of the output file, after ProbeManager unmangling.
00057   ofstream ofParam(theRealName.c_str(), Append ? ios::app : ios::out);
00058   
00059   Append = true;
00060   
00061   if (!ofParam) {
00062     throw ProbeException("Error opening file: " + theRealName);
00063   }
00064   
00065   ofParam << time << "\t";
00066   if( time == StartTime ) {
00067     // beware of the zero division ! 0/(0-0) is a bad idea even if IEEE numbers are active.
00068     ofParam << "0" << endl;
00069   }
00070   else {
00071     // feel free to use your own output format, but a gnuplot-like one is always good :-P
00072     ofParam << Sum_S/(time-StartTime) << "\t" << Sum_G/(time-StartTime);
00073     ofParam << "\t" << Sum_S_part/(time-lastTime) << "\t" << Sum_G_part/(time-lastTime) << endl;
00074   }
00075   
00076   Sum_S_part = 0;
00077   Sum_G_part = 0;
00078   lastTime = time;
00079 }
00080 

Generated on Wed Dec 22 23:26:43 2004 for NePSing Slotted Aloha example by doxygen 1.3.9.1 ---- Hosted by SourceForge.net Logo