# eoGnuplot.cpp

    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 <sstream>
    00028 #include <stdexcept>
    00029
    00030 #include "eoGnuplot.h"
    00031
    00032
    00033 unsigned eoGnuplot::numWindow=0;
    00034
    00035
    00036
    00037 eoGnuplot::eoGnuplot(std::string _title, std::string _extra)
    00038     : firstTime(true)
    00039 {
    00040     initGnuPlot(_title, _extra);
    00041 }
    00042
    00043
    00044
    00045 eoGnuplot::~eoGnuplot()
    00046 {
    00047 #ifdef HAVE_GNUPLOT
    00048     if( gpCom ) {
    00049         PipeComSend( gpCom, "quit\n" );
    00050         PipeComClose( gpCom );
    00051         gpCom =NULL;
    00052     }
    00053 #endif
    00054 }
    00055
    00056
    00057
    00058 void eoGnuplot::gnuplotCommand(const char *_command)
    00059 {
    00060 #ifdef HAVE_GNUPLOT
    00061     if(gpCom) {
    00062         PipeComSend( gpCom, _command );
    00063         PipeComSend( gpCom, "\n" );
    00064     }
    00065 #endif
    00066 }
    00067
    00068
    00069
    00070 void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
    00071 {
    00072 #ifdef HAVE_GNUPLOT
    00073     std::ostringstream os;
    00074     os << "250x150-0+" << 170 * numWindow++;
    00075     char *args[6];
    00076     args[0] = strdup( GNUPLOT_PROGRAM );
    00077     args[1] = strdup( "-geometry" );
    00078     args[2] = strdup( os.str().c_str());
    00079     args[3] = strdup( "-title" );
    00080     args[4] = strdup( _title.c_str() );
    00081     args[5] = 0;
    00082     gpCom = PipeComOpenArgv( GNUPLOT_PROGRAM, args );
    00083     if(! gpCom )
    00084         throw std::runtime_error("Cannot spawn gnuplot\n");
    00085     else {
    00086         PipeComSend( gpCom, "set grid\n" );
    00087         PipeComSend( gpCom, _extra.c_str() );
    00088         PipeComSend( gpCom, "\n" );
    00089     }
    00090 #endif
    00091 }
    00092
    00093
    00094
    00095 // Local Variables:
    00096 // c-file-style: "Stroustrup"
    00097 // fill-column: 80
    00098 // End: