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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#!/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 vector plot.
// Compile it with:
// g++ -o example-vector example-vector.cc -lboost_iostreams -lboost_filesystem
#include <vector>
#include <cmath>
#include <boost/tuple/tuple.hpp>
#include "gnuplot-iostream.h"
int main() {
Gnuplot gp;
// Create a script which can be manually fed into gnuplot later:
// Gnuplot gp(">script.gp");
// Create script and also feed to gnuplot:
// Gnuplot gp("tee plot.gp | gnuplot -persist");
// Or choose any of those options at runtime by setting the GNUPLOT_IOSTREAM_CMD
// environment variable.
// Gnuplot vectors (i.e. arrows) require four columns: (x,y,dx,dy)
std::vector<boost::tuple<double, double, double, double> > pts_A;
// You can also use a separate container for each column, like so:
std::vector<double> pts_B_x;
std::vector<double> pts_B_y;
std::vector<double> pts_B_dx;
std::vector<double> pts_B_dy;
// You could also use:
// std::vector<std::vector<double> >
// boost::tuple of four std::vector's
// std::vector of std::tuple (if you have C++11)
// arma::mat (with the Armadillo library)
// blitz::Array<blitz::TinyVector<double, 4>, 1> (with the Blitz++ library)
// ... or anything of that sort
for(double alpha=0; alpha<1; alpha+=1.0/24.0) {
double theta = alpha*2.0*3.14159;
pts_A.push_back(boost::make_tuple(
cos(theta),
sin(theta),
-cos(theta)*0.1,
-sin(theta)*0.1
));
pts_B_x .push_back( cos(theta)*0.8);
pts_B_y .push_back( sin(theta)*0.8);
pts_B_dx.push_back( sin(theta)*0.1);
pts_B_dy.push_back(-cos(theta)*0.1);
}
// Don't forget to put "\n" at the end of each line!
gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
// '-' means read from stdin. The send1d() function sends data to gnuplot's stdin.
gp << "plot '-' with vectors title 'pts_A', '-' with vectors title 'pts_B'\n";
gp.send1d(pts_A);
gp.send1d(boost::make_tuple(pts_B_x, pts_B_y, pts_B_dx, pts_B_dy));
}
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"
|