Changeset 36 for trunk/lib/Gnuplot.cc


Ignore:
Timestamp:
Jan 13, 2006, 2:05:53 AM (16 years ago)
Author:
Jari Häkkinen
Message:

Changed Gnuplot interface. Fixed sever bug in Stats::accumulated(void).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Gnuplot.cc

    r31 r36  
    8181
    8282
    83   void Gnuplot::plot_xy(const std::vector<double>& x,
    84                         const std::vector<double>& y, bool replot)
     83  void Gnuplot::plot(const std::vector<double>& y, const std::vector<double>& x,
     84                     const std::string& plotcmd)
    8585  {
    8686    char name[]="/tmp/svnstatXXXXXX";
     
    9292      throw GnuplotException(std::string("Failed to create file: ") + name);
    9393    for (std::vector<double>::size_type i=0; i<y.size(); ++i)
    94       tmp << x[i] << '\t' << y[i] << '\n';
     94      if (x.empty())
     95        tmp << y[i] << '\n';
     96      else
     97        tmp << x[i] << '\t' << y[i] << '\n';
    9598    tmp.close();
    96     std::string cmdstring((replot ? "replot" : "plot"));
    97     cmdstring+=(std::string(" '") + name + "' title '" + linetitle_ + "' with " +
    98                 linestyle_ + "\n");
    99     command(cmdstring);
    100 
    101     // need to keep track of created files since the gnuplot command
    102     // is not executed until pclose on MacOSX, shouldn't the fflush
    103     // fix this in the command() member function?
    104     tempfiles_.push_back(name);
    105   }
    106 
    107 
    108   void Gnuplot::plot_y(const std::vector<double>& y, bool replot)
    109   {
    110     char name[]="/tmp/svnstatXXXXXX";
    111     if (mkstemp(name) == -1)
    112       throw GnuplotException(std::string("Failed to get unique filename: ") +
    113                              name);
    114     std::ofstream tmp(name);
    115     if (tmp.bad())
    116       throw GnuplotException(std::string("Failed to create file: ") + name);
    117     for (std::vector<double>::size_type i=0; i<y.size(); ++i)
    118       tmp << y[i] << '\n';
    119     tmp.close();
    120     std::string cmdstring((replot ? "replot" : "plot"));
    121     cmdstring+=(std::string(" '") + name + "' title '" + linetitle_ + "' with " +
    122                 linestyle_ + "\n");
     99    std::string cmdstring(plotcmd + " '" + name + "' title '" + linetitle_ +
     100                          "' with " + linestyle_ + "\n");
    123101    command(cmdstring);
    124102
Note: See TracChangeset for help on using the changeset viewer.