source: trunk/test/gnuplot_pipe.cc @ 26

Last change on this file since 26 was 26, checked in by Jari Häkkinen, 16 years ago

Added a Gnuplot interface class.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1// $Id: gnuplot_pipe.cc 26 2006-01-05 01:36:42Z jari $
2
3#include "gnuplot_i.h"
4
5#include <string>
6#include <iostream>
7
8int main(const int argc,const char* argv[])
9{ 
10  using namespace theplu::svnstat;
11
12  bool ok = true;
13
14  // Jari speaks out: My first thought was to use one pipe to produce
15  // all plots. The idea was to avoid creating pipes since these are
16  // expensive. However, the Gnuplot class will run out of resources
17  // when a lot of data is to be plotted using plot_x() and
18  // plot_xy(). The current limit is 64 plots (plot_equation() and
19  // plot_slope() does not add to this count). Well, if all this is
20  // jibberish for you, never mind - we are going to write our own
21  // Gnuplot pipe using Guha's implementation as inspiration.
22
23  // Until the new implementation, use the last example below (look
24  // for 'Peter, look here') as a template for now.
25
26  Gnuplot gnuplot("steps");
27  std::string command("set output 'test.png'\nset term png");
28  gnuplot.cmd(command.c_str());
29  gnuplot.plot_equation("sin(x)","sine of x");
30
31  std::vector<double> x,y;
32  for (int i=-10; i<=10; ++i) {
33    x.push_back(i);
34    y.push_back(i*i);
35  }
36  command=std::string("set output 'test2.png'");
37  gnuplot.cmd(command.c_str());
38  // Jari, the next line actually does a 'replot' if a 'plot' has
39  // already been issued. See pngs for examples.
40  gnuplot.plot_x(x,"x");  // Jari, shouldn't this be called plot_y?
41
42  command=std::string("set output 'test3.png'");
43  gnuplot.cmd(command.c_str());
44  // Jari, the next line actually does a 'replot' if a 'plot' has
45  // already been issued. See pngs for examples.
46  gnuplot.plot_xy(x,y,"xy");
47
48
49  // Peter, look here.
50  // Jari, Maybe we should stick to this type of stuff until the new
51  // implementation.
52  Gnuplot gnuplot1;
53  gnuplot1.cmd("set output 'test4.png'\nset term png");
54  gnuplot1.cmd("plot sin(x) title 'sine of x' with lines");
55
56  Gnuplot gnuplot2;
57  gnuplot2.cmd("set output 'test5.png'\nset term png");
58  gnuplot2.plot_x(x,"x"); // Jari, shouldn't this be called plot_y?
59
60  Gnuplot gnuplot3;
61  gnuplot3.cmd("set output 'test6.png'\nset term png");
62  gnuplot3.plot_xy(x,y,"xy");
63
64  // Jari, if we want to avoid the above usage of plot_x and plot_xy,
65  // we need to do something like this. Of course 'filename.data'
66  // needs to be created by the user (this is hidden for the user in
67  // plot_x and plot_xy). Note, the below example compiles, but will
68  // fail at run time if 'filename.data' does not, miraculously, exist.
69  Gnuplot gnuplot4;
70  gnuplot4.cmd("set output 'test6.png'\nset term png");
71  gnuplot4.cmd("plot 'filename.data' using 1:2 with linespoints");
72
73  return (ok ? 0 : -1);
74}
Note: See TracBrowser for help on using the repository browser.