Changeset 107


Ignore:
Timestamp:
Jun 28, 2006, 11:12:38 AM (15 years ago)
Author:
Peter Johansson
Message:

Gnuplot functions returning int and utilizing that in the test. However the warning sent from Gnuplot ref #37 is not caught since there is no problem with the pipe there.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Gnuplot.cc

    r101 r107  
    7979  int Gnuplot::command(const std::string& cmdstr)
    8080  {
     81    std::cout << cmdstr << std::endl;
    8182    int r = fputs(cmdstr.c_str(),pipe_);
    82     if (*(cmdstr.rbegin())!='\n')
    83       fputc('\n',pipe_);
    84     fflush(pipe_);
    85     return r;
     83    if (!r && *(cmdstr.rbegin())!='\n')
     84      r=fputc('\n',pipe_);
     85    return (r ? r : fflush(pipe_));
    8686  }
    8787
  • trunk/lib/Gnuplot.h

    r101 r107  
    3333#include <vector>
    3434
     35
     36#include <iostream>
    3537
    3638namespace theplu {
     
    7072    /// Send arbitrary commands to Gnuplot.
    7173    ///
     74    /// @return 0 if fputs, fputc, and fflush are succesful
     75    ///
    7276    int command(const std::string&);
    7377
     
    9397    /// Gnuplot usage.
    9498    ///
     99    /// @return whatever command() returns
     100    ///
    95101    template <class T1, class T2>
    96     void plot(const std::vector<T1>& y, const std::vector<T2>& x)
    97     { plot(y,x,"plot"); }
     102    int plot(const std::vector<T1>& y, const std::vector<T2>& x)
     103    { return plot(y,x,"plot"); }
    98104
    99105    template <class T1>
    100     void plot(const std::vector<T1>& y,
     106    int plot(const std::vector<T1>& y,
    101107              const std::vector<T1>& x=std::vector<T1>())
    102     { plot(y,x,"plot"); }
     108    { return plot(y,x,"plot"); }
    103109
    104110    ///
     
    107113    /// Gnuplot usage.
    108114    ///
     115    /// @return whatever command() returns
     116    ///
    109117    template <class T1, class T2>
    110     void replot(const std::vector<T1>& y, const std::vector<T2>& x)
    111     { plot(y,x,"replot"); }
     118    int replot(const std::vector<T1>& y, const std::vector<T2>& x)
     119    { return plot(y,x,"replot"); }
    112120
    113121    template <class T1>
    114     void replot(const std::vector<T1>& y,
     122    int replot(const std::vector<T1>& y,
    115123              const std::vector<T1>& x=std::vector<T1>())
    116     { plot(y,x,"replot"); }
     124    { return plot(y,x,"replot"); }
    117125
    118126  private:
     
    128136    ///
    129137    template <class T1, class T2>
    130     void plot(const std::vector<T1>& y, const std::vector<T2>& x,
     138    int plot(const std::vector<T1>& y, const std::vector<T2>& x,
    131139              const std::string& plotcmd)
    132140    {
     
    146154      cmdstring << "e\n";
    147155
    148       command(cmdstring.str());
     156      return command(cmdstring.str());
    149157    }
    150158
  • trunk/lib/Parser.cc

    r103 r107  
    4141      if (where==str.end())
    4242        type_.push_back(empty);
    43       else if (*where=='/' && *(where+1)=='/')
     43      else if (*where=='/' && ((where++)!=str.end()) && *where=='/')
    4444        type_.push_back(comment);
    4545      else
  • trunk/test/gnuplot_pipe.cc

    r84 r107  
    2424#include "Gnuplot.h"
    2525
     26#include <iostream>
    2627#include <vector>
    2728
     
    3940
    4041  svnstat::Gnuplot gnuplot1;
    41   gnuplot1.command("set output 'test1.png'; set term png ; set title 'sine'");
    42   gnuplot1.command("plot sin(x) title 'sine of x' with lines");
     42  //if (gnuplot1.command("set output 'test1.png'; set term png ; set title 'sine'"))
     43  //ok = false;
     44    //if (gnuplot1.command("plot sin(x) title 'sine of x' with lines"))
     45    //ok = false;
    4346
    4447  svnstat::Gnuplot gnuplot2;
    45   gnuplot2.command("set output 'test2.png'; set term png");
    46   gnuplot2.plot(x);
     48  //if (gnuplot2.command("set output 'test2.png'; set term png"))
     49  //gnuplot2.plot(x);
    4750
    4851  svnstat::Gnuplot gnuplot3;
    49   gnuplot3.command("set output 'test3.png'; set term png");
     52  if (gnuplot3.command("set output 'test3.png'; set term png"))
     53    ok=false;
    5054  gnuplot3.linetitle("parabola");
    51   gnuplot3.plot(x,y);
    52 
    53   gnuplot3.command("set output 'test4.png'; set title 'composite'");
     55  if (gnuplot3.plot(x,y))
     56    ok=false;
     57  if (gnuplot3.command("set output 'test4.png'; set title 'composite'"))
     58    ok=false;
    5459  gnuplot3.linestyle("linespoints");
    5560  gnuplot3.linetitle("");
    56   gnuplot3.replot(x);
     61  if (gnuplot3.replot(x))
     62    ok=false;
    5763
    5864  /*
Note: See TracChangeset for help on using the changeset viewer.