00001 /***************************************************************************
00002 probe.cpp
00003 -----------
00004
00005 begin : Fri Sep 15 12:22:12 CEST 2000
00006 author : (C) 2000 by Michael Peeters
00007 email : Michael.Peeters@vub.ac.be
00008 ***************************************************************************/
00009
00010 /***************************************************************************
00011 * *
00012 * This program is free software; you can redistribute it and/or modify *
00013 * it under the terms of the GNU General Public License as published by *
00014 * the Free Software Foundation; either version 2 of the License, or *
00015 * (at your option) any later version. *
00016 * *
00017 ***************************************************************************/
00018
00019 #include "probe.h"
00020
00021 namespace MODEL
00022 {
00023 using namespace std;
00024
00025 // GenericProbe
00026
00027 GenericProbe::GenericProbe(TimeFrame & T, const string& fn)
00028 : TickTock(T,T.get_dt()), n(fn), out(NULL)
00029 {
00030 }
00031
00032 GenericProbe::GenericProbe(TimeFrame & T, ostream& os)
00033 : TickTock(T,T.get_dt()), out(&os)
00034 {
00035 }
00036
00037 void
00038 GenericProbe::tick()
00039 {
00040 probe();
00041 }
00042
00043 void
00044 GenericProbe::write_data(void)
00045 {
00046 bool no_out=false;
00047 if(no_out=(out==NULL)) out=new ofstream(n.c_str());
00048
00049 // This does not work - doh !
00050 print(*out);
00051
00052 if(no_out) {delete out; out=NULL;} // Make sure it is not used again
00053 }
00054
00055
00056 //Probe
00057
00058 Probe::Probe(TimeFrame & T, const string& fn)
00059 : TickTock(T,T.get_dt()), n(fn), out(NULL)
00060 {
00061 var_data=new data_list;
00062 }
00063
00064 Probe::Probe(TimeFrame & T, ostream& os)
00065 : TickTock(T,T.get_dt()), out(&os), data_is_here(false)
00066 {
00067 var_data=new data_list;
00068 }
00069
00070 Probe::~Probe()
00071 {
00072 bool no_out=false;
00073 if(no_out=(out==NULL)) out=new ofstream(n.c_str());
00074
00075 (*out) << "# Probe Output" <<endl;
00076
00077 for( data_list::iterator printer=var_data->begin();
00078 printer!=var_data->end();
00079 printer++)
00080 {
00081 if (printer->size()>1)
00082 {
00083 for ( data_record::iterator clack=printer->begin();
00084 clack!=(printer->end());
00085 clack++)
00086 (*out) << (*clack) << "\t";
00087 (*out) << endl;
00088 }
00089
00090 }
00091
00092 if(no_out) delete out;
00093 delete var_data;
00094 }
00095
00096 void
00097 Probe::tick()
00098 {
00099 data_is_here=false;
00100 temp_data = new data_record;
00101 temp_data->push_back(get_time());
00102
00103 probe();
00104
00105 // the last element is the time
00106 if(data_is_here)
00107 {var_data->push_back(*temp_data); }
00108 delete temp_data; temp_data=NULL;
00109
00110 }
00111
00112 void
00113 Probe::add_data(const number& d)
00114 {
00115 // As it is always push_back which is used, we just have to
00116 // look at the latest addition
00117 data_is_here=true;
00118 temp_data->push_back(d);
00119 }
00120
00121 } // end namespace
00122
00123 /*********************************************************************
00124 $Id: probe.cpp,v 1.1 2001/05/22 10:54:55 mpeeters Exp $
00125 **********************************************************************
00126
00127 $Log: probe.cpp,v $
00128 Revision 1.1 2001/05/22 10:54:55 mpeeters
00129 Moved sources and headers for libModel to model/ subdirectory, in an attempt to rationalize the source tree. This should make things "netter".
00130
00131 Revision 1.4 2001/05/21 11:53:16 mpeeters
00132 Removed Makefile.in, which is automatically generated anyway.
00133
00134 Revision 1.3 2000/10/09 09:43:44 mpeeters
00135 Added GenericProbe, because Probe was too specialized already.
00136 Probe now only logs data when add_data is called, not at every timepoint.
00137 This caused a huge memory leak, which has been shut now.
00138
00139 Revision 1.2 2000/09/15 10:26:31 mpeeters
00140 Cleaned out header and added CVS tails to files, removed superfuous
00141 @author comments, inserted dates
00142
00143 *********************************************************************/
More Info? Michael Peeters. Also, check our research website: www.alna.vub.ac.be
Last update: June 2002.