EvolvingObjects
eoGnuplot1DMonitor.cpp
00001 //-----------------------------------------------------------------------------
00002 // eoGnuplot1DMonitor.h
00003 // (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
00004 /*
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019    Contact: todos@geneura.ugr.es, http://geneura.ugr.es
00020              Marc.Schoenauer@polytechnique.fr
00021              mkeijzer@dhi.dk
00022  */
00023 //-----------------------------------------------------------------------------
00024 
00025 
00026 #ifdef HAVE_CONFIG_H
00027 #include <config.h>
00028 #endif
00029 
00030 #include <sstream>
00031 
00032 #include "utils/eoGnuplot1DMonitor.h"
00033 #include "utils/eoParam.h"
00034 
00035 
00036 eoMonitor& eoGnuplot1DMonitor::operator() (void)
00037 {
00038     // update file using the eoFileMonitor
00039     eoFileMonitor::operator()();
00040 #ifdef HAVE_GNUPLOT
00041     // sends plot order to gnuplot
00042     // assumes successive plots will have same nb of columns!!!
00043     if (firstTime)
00044     {
00045         FirstPlot();
00046         firstTime = false;
00047     }
00048     else
00049     {
00050         if( gpCom ) {
00051             PipeComSend( gpCom, "replot\n" );
00052         }
00053     }
00054 #endif
00055     return *this;
00056 }
00057 
00058 
00059 
00060 void eoGnuplot1DMonitor::FirstPlot()
00061 {
00062     if (this->vec.size() < 2)
00063     {
00064         throw std::runtime_error("Must have some stats to plot!\n");
00065     }
00066 #ifdef HAVE_GNUPLOT
00067     std::ostringstream os;
00068     os << "plot";
00069     for (unsigned i=1; i<this->vec.size(); i++) {
00070         os << " '" << getFileName().c_str() <<
00071             "' using 1:" << i+1 << " title '" << (this->vec[i])->longName() << "' with lines" ;
00072         if (i<this->vec.size()-1)
00073             os << ", ";
00074     }
00075     os << '\n';
00076     PipeComSend( gpCom, os.str().c_str());
00077 #endif
00078 }
00079 
00080 
00081 
00082 // Local Variables:
00083 // c-file-style: "Stroustrup"
00084 // fill-column: 80
00085 // End:
 All Classes Namespaces Files Functions Variables Typedefs Friends