1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#!/bin/sh
# autopkgtest for gnuplot-iostream
# 2014/09/06
#
# (C) 2014 Anton Gladky
set -e
WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR
cat <<EOF > demo.cc
// Demo of sending data via temporary files. The default is to send data to gnuplot directly
// through stdin.
//
// Compile it with:
// g++ -o example-tmpfile example-tmpfile.cc -lboost_iostreams -lboost_filesystem
#include <map>
#include <vector>
#include <cmath>
#include "gnuplot-iostream.h"
int main() {
Gnuplot gp;
std::vector<std::pair<double, double> > xy_pts_A;
for(double x=-2; x<2; x+=0.01) {
double y = x*x*x;
xy_pts_A.push_back(std::make_pair(x, y));
}
std::vector<std::pair<double, double> > xy_pts_B;
for(double alpha=0; alpha<1; alpha+=1.0/24.0) {
double theta = alpha*2.0*3.14159;
xy_pts_B.push_back(std::make_pair(cos(theta), sin(theta)));
}
gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
// Data will be sent via a temporary file. These are erased when you call
// gp.clearTmpfiles() or when gp goes out of scope. If you pass a filename
// (e.g. "gp.file1d(pts, 'mydata.dat')"), then the named file will be created
// and won't be deleted (this is useful when creating a script).
gp << "plot" << gp.file1d(xy_pts_A) << "with lines title 'cubic',"
<< gp.file1d(xy_pts_B) << "with points title 'circle'" << std::endl;
#ifdef _WIN32
// For Windows, prompt for a keystroke before the Gnuplot object goes out of scope so that
// the gnuplot window doesn't get closed.
std::cout << "Press enter to exit." << std::endl;
std::cin.get();
#endif
}
EOF
g++ -o demo demo.cc -lboost_iostreams -lboost_filesystem
echo "build: OK"
[ -x demo ]
touch a
xvfb-run --auth-file=a ./demo
echo "run: OK"
|