EvolvingObjects
|
00001 //----------------------------------------------------------------------------- 00002 // (c) Marc Schoenauer, 2001 00003 // Copyright (C) 2005 Jochen Küpper 00004 /* 00005 This library is free software; you can redistribute it and/or modify it under 00006 the terms of the GNU Lesser General Public License as published by the Free 00007 Software Foundation; either version 2 of the License, or (at your option) any 00008 later version. 00009 00010 This library is distributed in the hope that it will be useful, but WITHOUT 00011 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00013 details. 00014 00015 You should have received a copy of the GNU Lesser General Public License 00016 along with this library; if not, write to the Free Software Foundation, Inc., 00017 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 Contact: Marc.Schoenauer@polytechnique.fr 00020 */ 00021 //----------------------------------------------------------------------------- 00022 00023 #ifdef HAVE_CONFIG_H 00024 #include <config.h> 00025 #endif 00026 00027 #include <string.h> 00028 #include <sstream> 00029 #include <stdexcept> 00030 00031 #include "eoGnuplot.h" 00032 00033 00034 unsigned eoGnuplot::numWindow=0; 00035 00036 00037 00038 eoGnuplot::eoGnuplot(std::string _title, std::string _extra) 00039 : firstTime(true) 00040 { 00041 initGnuPlot(_title, _extra); 00042 } 00043 00044 00045 00046 eoGnuplot::~eoGnuplot() 00047 { 00048 #ifdef HAVE_GNUPLOT 00049 if( gpCom ) { 00050 PipeComSend( gpCom, "quit\n" ); 00051 PipeComClose( gpCom ); 00052 gpCom =NULL; 00053 } 00054 #endif 00055 } 00056 00057 00058 00059 void eoGnuplot::gnuplotCommand(const char *_command) 00060 { 00061 #ifdef HAVE_GNUPLOT 00062 if(gpCom) { 00063 PipeComSend( gpCom, _command ); 00064 PipeComSend( gpCom, "\n" ); 00065 } 00066 #endif 00067 } 00068 00069 00070 00071 void eoGnuplot::initGnuPlot(std::string _title, std::string _extra) 00072 { 00073 #ifdef HAVE_GNUPLOT 00074 std::ostringstream os; 00075 os << "250x150-0+" << 170 * numWindow++; 00076 char *args[6]; 00077 args[0] = strdup( GNUPLOT_PROGRAM ); 00078 args[1] = strdup( "-geometry" ); 00079 args[2] = strdup( os.str().c_str()); 00080 args[3] = strdup( "-title" ); 00081 args[4] = strdup( _title.c_str() ); 00082 args[5] = 0; 00083 gpCom = PipeComOpenArgv( GNUPLOT_PROGRAM, args ); 00084 if(! gpCom ) 00085 throw std::runtime_error("Cannot spawn gnuplot\n"); 00086 else { 00087 PipeComSend( gpCom, "set grid\n" ); 00088 PipeComSend( gpCom, _extra.c_str() ); 00089 PipeComSend( gpCom, "\n" ); 00090 } 00091 #endif 00092 } 00093 00094 00095 00096 // Local Variables: 00097 // c-file-style: "Stroustrup" 00098 // fill-column: 80 00099 // End: