added second part of evaluation in cpp

This commit is contained in:
2018-12-09 20:55:21 +01:00
parent 6c01b76b9c
commit 0a6b6b7d72
168 changed files with 5717 additions and 16 deletions

View File

@@ -11,6 +11,15 @@ set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g") set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3") set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#find_package(Boost REQUIRED COMPONENTS iostreams system filesystem)
find_package(Boost REQUIRED COMPONENTS iostreams system filesystem)
include_directories(${CMAKE_SOURCE_DIR}/gnuplot-iostream)
# Find includes in corresponding build directories # Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed # Instruct CMake to run moc automatically when needed
@@ -58,3 +67,4 @@ add_executable(Rennbahn ${helloworld_SRCS})
# Use the Widgets module from Qt 5 # Use the Widgets module from Qt 5
target_link_libraries(Rennbahn Qt5::Widgets Qt5::Core Qt5::Sql) target_link_libraries(Rennbahn Qt5::Widgets Qt5::Core Qt5::Sql)
target_link_libraries(Rennbahn ${Boost_LIBRARIES})

View File

@@ -1,21 +1,51 @@
#include "evaluation.h" #include "evaluation.h"
#include "result.h" #include "result.h"
#include "ui_evaluation.h" #include "ui_evaluation.h"
#include <QListWidget>
#include <QListWidgetItem>
#include <QStringListModel> #include <QStringListModel>
#include <iostream>
#include <qstring.h>
using std::cout;
using std::endl;
Evaluation::Evaluation(DataBase * db, QWidget * parent) Evaluation::Evaluation(DataBase * db, QWidget * parent)
: QWidget(parent), ui(new Ui::Evaluation) { : QWidget(parent), ui(new Ui::Evaluation) {
ui->setupUi(this); ui->setupUi(this);
this->db = db; this->db = db;
// connectsion
QObject::connect(this->ui->pBClose, SIGNAL(clicked()), this, SLOT(close()));
this->result = this->db->getData2("select date, id from Rennen", 2);
QStringList listOfDates;
for (vector<QString> str : result) {
listOfDates << str.at(0);
// this->ui->lWEvaluation->addItem(new QListWidgetItem(str.at(0)));
}
QStringListModel * model = new QStringListModel(); QStringListModel * model = new QStringListModel();
QStringList list; model->setStringList(listOfDates);
list << "datum 1" this->ui->lWEvaluation->setModel(model);
<< "datum 2" QObject::connect(this->ui->lWEvaluation,
<< "datum 3"; SIGNAL(doubleClicked(const QModelIndex &)), this,
model->setStringList(list); SLOT(listClick(const QModelIndex &)));
this->ui->lVEvaluation->setModel(model);
this->interfaceResult = new Result(this->db); // this->interfaceResult = new Result(this->db);
// this->interfaceResult->show();
}
void Evaluation::listClick(const QModelIndex & ind) {
cout << "list Click" << endl;
// get id to index
unsigned long index = static_cast<unsigned long>(ind.row());
int id = this->result.at(index).at(1).toInt();
this->interfaceResult = new Result(this->db, id);
this->interfaceResult->show(); this->interfaceResult->show();
} }
Evaluation::~Evaluation() { Evaluation::~Evaluation() {

View File

@@ -3,7 +3,12 @@
#include "database.h" #include "database.h"
#include "result.h" #include "result.h"
#include <QListWidgetItem>
#include <QWidget> #include <QWidget>
#include <qstring.h>
#include <vector>
using std::vector;
namespace Ui { namespace Ui {
class Evaluation; class Evaluation;
@@ -20,6 +25,10 @@ class Evaluation : public QWidget {
Ui::Evaluation * ui; Ui::Evaluation * ui;
Result * interfaceResult; Result * interfaceResult;
DataBase * db; DataBase * db;
vector<vector<QString>> result;
public slots:
void listClick(const QModelIndex & index);
}; };
#endif // EVALUATION_H #endif // EVALUATION_H

View File

@@ -17,12 +17,12 @@
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QListView" name="lVEvaluation"/> <widget class="QListView" name="lWEvaluation"/>
</item> </item>
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton"> <widget class="QPushButton" name="pBClose">
<property name="text"> <property name="text">
<string>Schließen</string> <string>Schließen</string>
</property> </property>

23
gnuplot-iostream/.gitignore vendored Normal file
View File

@@ -0,0 +1,23 @@
# compiled stuff
example-data-1d
example-data-2d
example-interactive
example-misc
test-noncopyable
test-outputs
test-empty
*.error.txt
*.o
# Windows compiled stuff
*.exe
*.obj
# cmake stuff
build
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
# output of example scripts and unit tests
my_graph_*.png
unittest-output/

View File

@@ -0,0 +1,15 @@
Updates happen via git with no regular release schedule or versioning.
However, I will bump up the GNUPLOT_IOSTREAM_VERSION macro whenever
something major changes (but note that prior to version 2 this macro is not
defined).
Version 2:
* Major rewrite.
* Nearly every combination of container and tuple types is supported.
* Now you should use send1d() and send2d() rather than just send().
* When the Gnuplot object is constructed with no arguments, an attempt is made to determine
the best gnuplot command and arguments for your operating system.
Version 1:
* Original version.
* The GNUPLOT_IOSTREAM_VERSION macro is not defined prior to version 2.

92
gnuplot-iostream/Makefile Normal file
View File

@@ -0,0 +1,92 @@
# Copyright (c) 2013 Daniel Stahlke
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
###########################################################################
# This Makefile is just for the demos and unit tests. You don't need to compile
# anything to install this package. Just copy the gnuplot-iostream.h header
# somewhere and you are good to go.
###########################################################################
# The -O0 option speeds up the compile, which is good for testing. This should
# never be used for production since the generated code is extremely slow!
CXXFLAGS+=-Wall -Wextra -O0 -g -D_GLIBCXX_DEBUG
LDFLAGS+=-lutil -lboost_iostreams -lboost_system -lboost_filesystem
# This makes the examples and tests more complete, but only works if you have the corresponding
# libraries installed.
#CXXFLAGS+=--std=c++11 -DUSE_ARMA=1 -DUSE_BLITZ=1
ALL_EXAMPLES=example-misc example-data-1d example-data-2d example-interactive
TEST_BINARIES=test-noncopyable test-outputs test-empty
all: $(ALL_EXAMPLES)
%.o: %.cc gnuplot-iostream.h
$(CXX) $(CXXFLAGS) -c $< -o $@
example-misc: example-misc.o
$(CXX) -o $@ $^ $(LDFLAGS)
example-data-1d: example-data-1d.o
$(CXX) -o $@ $^ $(LDFLAGS)
example-data-2d: example-data-2d.o
$(CXX) -o $@ $^ $(LDFLAGS)
example-interactive: example-interactive.o
$(CXX) -o $@ $^ $(LDFLAGS)
test-noncopyable: test-noncopyable.o
$(CXX) -o $@ $^ $(LDFLAGS)
test-outputs: test-outputs.o
$(CXX) -o $@ $^ $(LDFLAGS)
test-empty: test-empty.o
$(CXX) -o $@ $^ $(LDFLAGS)
test-asserts: test-assert-depth.error.txt test-assert-depth-colmajor.error.txt
%.error.txt: %.cc gnuplot-iostream.h
# These are programs that are supposed to *not* compile.
# The "!" causes "make" to throw an error if the compile succeeds.
! $(CXX) $(CXXFLAGS) -c $< -o $<.o 2> $@
grep -q 'container not deep enough\|boost::STATIC_ASSERTION_FAILURE' $@
test: $(TEST_BINARIES) test-asserts
mkdir -p unittest-output
rm -f unittest-output/*
./test-outputs
diff -qr unittest-output unittest-output-good
clean:
rm -f *.o
rm -f *.error.txt
rm -f $(ALL_EXAMPLES) $(TEST_BINARIES)
# Windows compilation
rm -f *.exe *.obj
# files created by demo scripts
rm -f my_graph_*.png external_binary.dat external_binary.gnu external_text.dat external_text.gnu inline_binary.gnu inline_text.gnu
lint:
cpplint.py --filter=-whitespace,-readability/streams,-build/header_guard gnuplot-iostream.h
cppcheck:
cppcheck *.cc *.h --template gcc --enable=all -q

View File

@@ -0,0 +1,62 @@
# Copyright (c) 2013 Daniel Stahlke
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
###########################################################################
# This Makefile is just for my personal use, to test that things work in MSVC.
# It has paths hard-coded for my system. If you know how to make a proper,
# portable build file for Windows, and want to do so, then email me.
###########################################################################
ALL_EXAMPLES=example-misc.exe example-data-1d.exe example-data-2d.exe
TEST_BINARIES=test-noncopyable.exe test-outputs.exe
# Even the Nov 2012 CTP won't compile with C++11 support.
#EXTRA_FLAGS=/DGNUPLOT_ENABLE_CXX11 /DUSE_CXX
#set PATH=C:\Program Files (x86)\Microsoft Visual C++ Compiler Nov 2012 CTP\bin;%PATH%
#set INCLUDE=C:\Program Files (x86)\Microsoft Visual C++ Compiler Nov 2012 CTP\include;%INCLUDE%
all: $(ALL_EXAMPLES)
%.exe: %.cc gnuplot-iostream.h
cl /W3 /EHsc $(EXTRA_FLAGS) /I "C:\Program Files\boost\boost_1_51" $< /link /LIBPATH:"e:\boost_libs_1_51\lib32"
test-asserts: test-assert-depth.error.txt test-assert-depth-colmajor.error.txt
%.error.txt: %.cc gnuplot-iostream.h
# These are programs that are supposed to *not* compile.
# The "!" causes "make" to throw an error if the compile succeeds.
! cl /W3 /EHsc $(EXTRA_FLAGS) /I "C:\Program Files\boost\boost_1_51" $< /link /LIBPATH:"e:\boost_libs_1_51\lib32" > $@
grep -q 'container not deep enough\|boost::STATIC_ASSERTION_FAILURE' $@
test: $(TEST_BINARIES) test-asserts
rm -f unittest-output/*
./test-outputs.exe
dos2unix -q unittest-output/*.txt
diff -qr unittest-output unittest-output-good
clean:
rm -f *.o
rm -f *.error.txt
rm -f $(ALL_EXAMPLES) $(TEST_BINARIES)
# Windows compilation
rm -f *.exe *.obj
# files created by demo scripts
rm -f my_graph_*.png external_binary.dat external_binary.gnu external_text.dat external_text.gnu inline_binary.gnu inline_text.gnu

57
gnuplot-iostream/README Normal file
View File

@@ -0,0 +1,57 @@
**********************************************************
*** Direct questions or suggestions to dan@stahlke.org ***
**********************************************************
Gnuplot-Iostream Interface
==========================
This interface allows gnuplot to be controlled from C++ and is designed to
be the lowest hanging fruit. In other words, if you know how gnuplot works
it should only take 30 seconds to learn this library. Basically it is just
an iostream pipe to gnuplot with some extra functions for pushing data
arrays and getting mouse clicks. Data sources include STL containers (eg.
vector), Blitz++, and armadillo. You can use nested data types like
std::vector<std::vector<std::pair<double, double>>> (as well as even more
exotic types). Support for custom data types is possible.
This is a low level interface, and usage involves manually sending commands
to gnuplot using the "<<" operator (so you need to know gnuplot syntax).
This is in my opinion the easiest way to do it if you are already
comfortable with using gnuplot. If you would like a more high level interface
check out the gnuplot-cpp library (http://code.google.com/p/gnuplot-cpp).
Documentation is available at http://www.stahlke.org/dan/gnuplot-iostream
but also you can look at the example programs (starting with
"example-misc.cc").
Getting the source code
=======================
git clone https://github.com/dstahlke/gnuplot-iostream.git
Usage
=====
See the examples source code for a quick intro. Documentation is at
the project home page http://www.stahlke.org/dan/gnuplot-iostream .
To build examples just type 'make'. There is an option you can edit in the
Makefile to enable extra demos that require optional libraries.
Note for Windows users
======================
Windows support basically works, but there are some troubles. For hints, see:
https://github.com/dstahlke/gnuplot-iostream/wiki/Portability
Contributors
============
Dan Stahlke (dan@stahlke.org)
Jens Mueller
Robbie Morrison
Daniel Di Marco
Sylwester Arabas

View File

@@ -0,0 +1,453 @@
/*
Copyright (c) 2013 Daniel Stahlke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// This demonstrates all sorts of data types that can be plotted using send1d(). It is not
// meant as a first tutorial; for that see example-misc.cc or the project wiki.
#if (__cplusplus >= 201103)
#define USE_CXX
#endif
#include <vector>
#include <complex>
#include <cmath>
#include <boost/tuple/tuple.hpp>
#include <boost/array.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/irange.hpp>
#include <boost/bind.hpp>
#ifdef USE_ARMA
#include <armadillo>
#endif
#ifdef USE_BLITZ
#include <blitz/array.h>
#endif
#include "gnuplot-iostream.h"
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
const int num_steps = 100;
double get_x(int step, double shift) {
double theta = 2.0*M_PI*step/(num_steps-1);
return std::cos(theta) * (1 + 0.3*std::cos(3.0*theta+2.0*M_PI*shift));
}
double get_y(int step, double shift) {
double theta = 2.0*M_PI*step/(num_steps-1);
return std::sin(theta) * (1 + 0.3*std::cos(3.0*theta+2.0*M_PI*shift));
}
double get_z(int step, double shift) {
double theta = 2.0*M_PI*step/(num_steps-1);
return 0.3*std::sin(3.0*theta+2.0*M_PI*shift);
}
// This doesn't have to be a template. It's just a template to show that such things are
// possible.
template <typename T>
struct MyTriple {
MyTriple() : x(0), y(0), z(0) { }
MyTriple(T _x, T _y, T _z) : x(_x), y(_y), z(_z) { }
T x, y, z;
};
// Tells gnuplot-iostream how to print objects of class MyTriple.
namespace gnuplotio {
template<typename T>
struct BinfmtSender<MyTriple<T> > {
static void send(std::ostream &stream) {
BinfmtSender<T>::send(stream);
BinfmtSender<T>::send(stream);
BinfmtSender<T>::send(stream);
}
};
template <typename T>
struct BinarySender<MyTriple<T> > {
static void send(std::ostream &stream, const MyTriple<T> &v) {
BinarySender<T>::send(stream, v.x);
BinarySender<T>::send(stream, v.y);
BinarySender<T>::send(stream, v.z);
}
};
// We don't use text mode in this demo. This is just here to show how it would go.
template<typename T>
struct TextSender<MyTriple<T> > {
static void send(std::ostream &stream, const MyTriple<T> &v) {
TextSender<T>::send(stream, v.x);
stream << " ";
TextSender<T>::send(stream, v.y);
stream << " ";
TextSender<T>::send(stream, v.z);
}
};
}
int main() {
Gnuplot gp;
// for debugging, prints to console
//Gnuplot gp(stdout);
int num_examples = 11;
#ifdef USE_ARMA
num_examples += 4;
#endif
#ifdef USE_BLITZ
num_examples += 3;
#endif
#ifdef USE_CXX
num_examples += 3;
#endif
double shift = 0;
gp << "set zrange [-1:1]\n";
// I use temporary files rather than stdin because the syntax ends up being easier when
// plotting several datasets. With the stdin method you have to give the full plot
// command, then all the data. But I would rather give the portion of the plot command for
// the first dataset, then give the data, then the command for the second dataset, then the
// data, etc.
gp << "splot ";
{
std::vector<std::pair<std::pair<double, double>, double> > pts;
for(int i=0; i<num_steps; i++) {
pts.push_back(std::make_pair(std::make_pair(get_x(i, shift), get_y(i, shift)), get_z(i, shift)));
}
gp << gp.binFile1d(pts, "record") << "with lines title 'vector of nested std::pair'";
}
gp << ", ";
shift += 1.0/num_examples;
{
// complex is treated as if it were a pair
std::vector<std::pair<std::complex<double>, double> > pts;
for(int i=0; i<num_steps; i++) {
pts.push_back(std::make_pair(std::complex<double>(get_x(i, shift), get_y(i, shift)), get_z(i, shift)));
}
gp << gp.binFile1d(pts, "record") << "with lines title 'vector of pair of cplx and double'";
}
gp << ", ";
shift += 1.0/num_examples;
{
std::vector<boost::tuple<double, double, double> > pts;
for(int i=0; i<num_steps; i++) {
pts.push_back(boost::make_tuple(get_x(i, shift), get_y(i, shift), get_z(i, shift)));
}
gp << gp.binFile1d(pts, "record") << "with lines title 'vector of boost::tuple'";
}
gp << ", ";
shift += 1.0/num_examples;
{
std::vector<double> x_pts, y_pts, z_pts;
for(int i=0; i<num_steps; i++) {
x_pts.push_back(get_x(i, shift));
y_pts.push_back(get_y(i, shift));
z_pts.push_back(get_z(i, shift));
}
gp << gp.binFile1d(boost::make_tuple(x_pts, y_pts, z_pts), "record") << "with lines title 'boost::tuple of vector'";
}
gp << ", ";
shift += 1.0/num_examples;
{
std::vector<boost::array<double, 3> > pts(num_steps);
for(int i=0; i<num_steps; i++) {
pts[i][0] = get_x(i, shift);
pts[i][1] = get_y(i, shift);
pts[i][2] = get_z(i, shift);
}
gp << gp.binFile1d(pts, "record") << "with lines title 'vector of boost::array'";
}
gp << ", ";
shift += 1.0/num_examples;
{
std::vector<std::vector<double> > pts(num_steps);
for(int i=0; i<num_steps; i++) {
pts[i].push_back(get_x(i, shift));
pts[i].push_back(get_y(i, shift));
pts[i].push_back(get_z(i, shift));
}
gp << gp.binFile1d(pts, "record") << "with lines title 'vector of vector'";
}
gp << ", ";
shift += 1.0/num_examples;
{
std::vector<std::vector<double> > pts(3);
for(int i=0; i<num_steps; i++) {
pts[0].push_back(get_x(i, shift));
pts[1].push_back(get_y(i, shift));
pts[2].push_back(get_z(i, shift));
}
gp << gp.binFile1d_colmajor(pts, "record") << "with lines title 'vector of vector (colmajor)'";
}
gp << ", ";
shift += 1.0/num_examples;
{
std::vector<MyTriple<double> > pts;
for(int i=0; i<num_steps; i++) {
pts.push_back(MyTriple<double>(get_x(i, shift), get_y(i, shift), get_z(i, shift)));
}
gp << gp.binFile1d(pts, "record") << "with lines title 'vector of MyTriple'";
}
gp << ", ";
shift += 1.0/num_examples;
{
// Note: C style arrays seem to work, but are a bit fragile since they easily decay to
// pointers, causing them to forget their lengths. It is highly recommended that you
// use boost::array or std::array instead. These have the same size and efficiency of
// C style arrays, but act like STL containers.
double pts[num_steps][3];
for(int i=0; i<num_steps; i++) {
pts[i][0] = get_x(i, shift);
pts[i][1] = get_y(i, shift);
pts[i][2] = get_z(i, shift);
}
gp << gp.binFile1d(pts, "record") << "with lines title 'double[N][3]'";
}
gp << ", ";
shift += 1.0/num_examples;
{
// Note: C style arrays seem to work, but are a bit fragile since they easily decay to
// pointers, causing them to forget their lengths. It is highly recommended that you
// use boost::array or std::array instead. These have the same size and efficiency of
// C style arrays, but act like STL containers.
double pts[3][num_steps];
for(int i=0; i<num_steps; i++) {
pts[0][i] = get_x(i, shift);
pts[1][i] = get_y(i, shift);
pts[2][i] = get_z(i, shift);
}
gp << gp.binFile1d_colmajor(pts, "record") << "with lines title 'double[N][3] (colmajor)'";
}
gp << ", ";
shift += 1.0/num_examples;
{
// Note: C style arrays seem to work, but are a bit fragile since they easily decay to
// pointers, causing them to forget their lengths. It is highly recommended that you
// use boost::array or std::array instead. These have the same size and efficiency of
// C style arrays, but act like STL containers.
double x_pts[num_steps];
double y_pts[num_steps];
double z_pts[num_steps];
for(int i=0; i<num_steps; i++) {
x_pts[i] = get_x(i, shift);
y_pts[i] = get_y(i, shift);
z_pts[i] = get_z(i, shift);
}
gp << gp.binFile1d(boost::make_tuple(x_pts, y_pts, z_pts), "record") <<
"with lines title 'boost::tuple of double[N]'";
}
#ifdef USE_ARMA
gp << ", ";
shift += 1.0/num_examples;
{
arma::mat pts(num_steps, 3);
for(int i=0; i<num_steps; i++) {
pts(i, 0) = get_x(i, shift);
pts(i, 1) = get_y(i, shift);
pts(i, 2) = get_z(i, shift);
}
gp << gp.binFile1d(pts, "record") << "with lines title 'armadillo N*3'";
}
gp << ", ";
shift += 1.0/num_examples;
{
arma::mat pts(3, num_steps);
for(int i=0; i<num_steps; i++) {
pts(0, i) = get_x(i, shift);
pts(1, i) = get_y(i, shift);
pts(2, i) = get_z(i, shift);
}
gp << gp.binFile1d_colmajor(pts, "record") << "with lines title 'armadillo 3*N (colmajor)'";
}
gp << ", ";
shift += 1.0/num_examples;
{
arma::Row<double> x_pts(num_steps);
arma::Col<double> y_pts(num_steps);
arma::Col<double> z_pts(num_steps);
for(int i=0; i<num_steps; i++) {
x_pts(i) = get_x(i, shift);
y_pts(i) = get_y(i, shift);
z_pts(i) = get_z(i, shift);
}
gp << gp.binFile1d(boost::make_tuple(x_pts, y_pts, z_pts), "record")
<< "with lines title 'boost tuple of arma Row,Col,Col'";
}
gp << ", ";
shift += 1.0/num_examples;
{
arma::field<boost::tuple<double,double,double> > pts(num_steps);
for(int i=0; i<num_steps; i++) {
pts(i) = boost::make_tuple(
get_x(i, shift),
get_y(i, shift),
get_z(i, shift)
);
}
gp << gp.binFile1d(pts, "record") << "with lines title 'armadillo field of boost tuple'";
}
#endif
#ifdef USE_BLITZ
gp << ", ";
shift += 1.0/num_examples;
{
blitz::Array<blitz::TinyVector<double, 3>, 1> pts(num_steps);
for(int i=0; i<num_steps; i++) {
pts(i)[0] = get_x(i, shift);
pts(i)[1] = get_y(i, shift);
pts(i)[2] = get_z(i, shift);
}
gp << gp.binFile1d(pts, "record") << "with lines title 'blitz::Array<blitz::TinyVector<double, 3>, 1>'";
}
gp << ", ";
shift += 1.0/num_examples;
{
blitz::Array<double, 2> pts(num_steps, 3);
for(int i=0; i<num_steps; i++) {
pts(i, 0) = get_x(i, shift);
pts(i, 1) = get_y(i, shift);
pts(i, 2) = get_z(i, shift);
}
gp << gp.binFile1d(pts, "record") << "with lines title 'blitz<double>(N*3)'";
}
gp << ", ";
shift += 1.0/num_examples;
{
blitz::Array<double, 2> pts(3, num_steps);
for(int i=0; i<num_steps; i++) {
pts(0, i) = get_x(i, shift);
pts(1, i) = get_y(i, shift);
pts(2, i) = get_z(i, shift);
}
gp << gp.binFile1d_colmajor(pts, "record") << "with lines title 'blitz<double>(3*N) (colmajor)'";
}
#endif
#ifdef USE_CXX
gp << ", ";
shift += 1.0/num_examples;
{
std::function<boost::tuple<double,double,double>(int)> f = [&shift](int i) {
return boost::make_tuple(get_x(i, shift), get_y(i, shift), get_z(i, shift)); };
auto pts = boost::irange(0, num_steps) | boost::adaptors::transformed(f);
gp << gp.binFile1d(pts, "record") << "with lines title 'boost transform to tuple'";
}
gp << ", ";
shift += 1.0/num_examples;
{
auto steps = boost::irange(0, num_steps);
gp << gp.binFile1d(boost::make_tuple(
steps | boost::adaptors::transformed(boost::bind(get_x, _1, shift)),
steps | boost::adaptors::transformed(boost::bind(get_y, _1, shift)),
steps | boost::adaptors::transformed(boost::bind(get_z, _1, shift))
), "record") << "with lines title 'tuple of boost transform'";
}
gp << ", ";
shift += 1.0/num_examples;
{
// Note: C style arrays seem to work, but are a bit fragile since they easily decay to
// pointers, causing them to forget their lengths. It is highly recommended that you
// use boost::array or std::array instead. These have the same size and efficiency of
// C style arrays, but act like STL containers.
double x_pts[num_steps];
double y_pts[num_steps];
double z_pts[num_steps];
for(int i=0; i<num_steps; i++) {
x_pts[i] = get_x(i, shift);
y_pts[i] = get_y(i, shift);
z_pts[i] = get_z(i, shift);
}
// Note: std::make_tuple doesn't work here since it makes the arrays decay to pointers,
// and as a result they forget their lengths.
gp << gp.binFile1d(std::tie(x_pts, y_pts, z_pts), "record") <<
"with lines title 'std::tie of double[N]'";
}
#endif
gp << std::endl;
shift += 1.0/num_examples;
//std::cout << shift << std::endl;
assert(std::fabs(shift - 1.0) < 1e-12);
#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
return 0;
}

View File

@@ -0,0 +1,373 @@
/*
Copyright (c) 2013 Daniel Stahlke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// This demonstrates all sorts of data types that can be plotted using send2d(). It is not
// meant as a first tutorial; for that see example-misc.cc or the project wiki.
#define USE_CXX (__cplusplus >= 201103)
#include <vector>
#include <complex>
#include <cmath>
#include <boost/tuple/tuple.hpp>
#include <boost/array.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/irange.hpp>
#include <boost/bind.hpp>
#ifdef USE_ARMA
#include <armadillo>
#endif
#ifdef USE_BLITZ
#include <blitz/array.h>
#endif
#include "gnuplot-iostream.h"
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
// The number of axial points of the torus.
const int num_u = 10;
// The total number of longitudinal points of the torus. This is set at the beginning of
// main().
int num_v_total;
// This doesn't have to be a template. It's just a template to show that such things are
// possible.
template <typename T>
struct MyTriple {
MyTriple() : x(0), y(0), z(0) { }
MyTriple(T _x, T _y, T _z) : x(_x), y(_y), z(_z) { }
T x, y, z;
};
// Tells gnuplot-iostream how to print objects of class MyTriple.
namespace gnuplotio {
template<typename T>
struct BinfmtSender<MyTriple<T> > {
static void send(std::ostream &stream) {
BinfmtSender<T>::send(stream);
BinfmtSender<T>::send(stream);
BinfmtSender<T>::send(stream);
}
};
template <typename T>
struct BinarySender<MyTriple<T> > {
static void send(std::ostream &stream, const MyTriple<T> &v) {
BinarySender<T>::send(stream, v.x);
BinarySender<T>::send(stream, v.y);
BinarySender<T>::send(stream, v.z);
}
};
// We don't use text mode in this demo. This is just here to show how it would go.
template<typename T>
struct TextSender<MyTriple<T> > {
static void send(std::ostream &stream, const MyTriple<T> &v) {
TextSender<T>::send(stream, v.x);
stream << " ";
TextSender<T>::send(stream, v.y);
stream << " ";
TextSender<T>::send(stream, v.z);
}
};
}
MyTriple<double> get_point(int u, int v) {
double a = 2.0*M_PI*u/(num_u-1);
double b = 2.0*M_PI*v/(num_v_total-1);
double z = 0.3*std::cos(a);
double r = 1 + 0.3*std::sin(a);
double x = r * std::cos(b);
double y = r * std::sin(b);
return MyTriple<double>(x, y, z);
}
int main() {
Gnuplot gp;
// for debugging, prints to console
//Gnuplot gp(stdout);
int num_examples = 7;
#ifdef USE_ARMA
num_examples += 3;
#endif
#ifdef USE_BLITZ
num_examples += 3;
#endif
int num_v_each = 50 / num_examples + 1;
num_v_total = (num_v_each-1) * num_examples + 1;
int shift = 0;
gp << "set zrange [-1:1]\n";
gp << "set hidden3d nooffset\n";
// I use temporary files rather than stdin because the syntax ends up being easier when
// plotting several datasets. With the stdin method you have to give the full plot
// command, then all the data. But I would rather give the portion of the plot command for
// the first dataset, then give the data, then the command for the second dataset, then the
// data, etc.
gp << "splot ";
{
std::vector<std::vector<MyTriple<double> > > pts(num_u);
for(int u=0; u<num_u; u++) {
pts[u].resize(num_v_each);
for(int v=0; v<num_v_each; v++) {
pts[u][v] = get_point(u, v+shift);
}
}
gp << gp.binFile2d(pts, "record") << "with lines title 'vec of vec of MyTriple'";
}
gp << ", ";
shift += num_v_each-1;
{
std::vector<std::vector<boost::tuple<double,double,double> > > pts(num_u);
for(int u=0; u<num_u; u++) {
pts[u].resize(num_v_each);
for(int v=0; v<num_v_each; v++) {
pts[u][v] = boost::make_tuple(
get_point(u, v+shift).x,
get_point(u, v+shift).y,
get_point(u, v+shift).z
);
}
}
gp << gp.binFile2d(pts, "record") << "with lines title 'vec of vec of boost::tuple'";
}
gp << ", ";
shift += num_v_each-1;
{
std::vector<std::vector<double> > x_pts(num_u);
std::vector<std::vector<double> > y_pts(num_u);
std::vector<std::vector<double> > z_pts(num_u);
for(int u=0; u<num_u; u++) {
x_pts[u].resize(num_v_each);
y_pts[u].resize(num_v_each);
z_pts[u].resize(num_v_each);
for(int v=0; v<num_v_each; v++) {
x_pts[u][v] = get_point(u, v+shift).x;
y_pts[u][v] = get_point(u, v+shift).y;
z_pts[u][v] = get_point(u, v+shift).z;
}
}
gp << gp.binFile2d(boost::make_tuple(x_pts, y_pts, z_pts), "record") <<
"with lines title 'boost::tuple of vec of vec'";
}
gp << ", ";
shift += num_v_each-1;
{
std::vector<boost::tuple<
std::vector<double>,
std::vector<double>,
std::vector<double>
> > pts;
for(int u=0; u<num_u; u++) {
std::vector<double> x_pts(num_v_each);
std::vector<double> y_pts(num_v_each);
std::vector<double> z_pts(num_v_each);
for(int v=0; v<num_v_each; v++) {
x_pts[v] = get_point(u, v+shift).x;
y_pts[v] = get_point(u, v+shift).y;
z_pts[v] = get_point(u, v+shift).z;
}
pts.push_back(boost::make_tuple(x_pts, y_pts, z_pts));
}
gp << gp.binFile2d(pts, "record") <<
"with lines title 'vec of boost::tuple of vec'";
}
gp << ", ";
shift += num_v_each-1;
{
std::vector<std::vector<double> > x_pts(num_u);
std::vector<std::vector<std::pair<double, double> > > yz_pts(num_u);
for(int u=0; u<num_u; u++) {
x_pts[u].resize(num_v_each);
yz_pts[u].resize(num_v_each);
for(int v=0; v<num_v_each; v++) {
x_pts [u][v] = get_point(u, v+shift).x;
yz_pts[u][v] = std::make_pair(
get_point(u, v+shift).y,
get_point(u, v+shift).z);
}
}
gp << gp.binFile2d(std::make_pair(x_pts, yz_pts), "record") <<
"with lines title 'pair(vec(vec(dbl)),vec(vec(pair(dbl,dbl))))'";
}
gp << ", ";
shift += num_v_each-1;
{
std::vector<std::vector<std::vector<double> > > pts(num_u);
for(int u=0; u<num_u; u++) {
pts[u].resize(num_v_each);
for(int v=0; v<num_v_each; v++) {
pts[u][v].resize(3);
pts[u][v][0] = get_point(u, v+shift).x;
pts[u][v][1] = get_point(u, v+shift).y;
pts[u][v][2] = get_point(u, v+shift).z;
}
}
gp << gp.binFile2d(pts, "record") << "with lines title 'vec vec vec'";
}
gp << ", ";
shift += num_v_each-1;
{
std::vector<std::vector<std::vector<double> > > pts(3);
for(int i=0; i<3; i++) pts[i].resize(num_u);
for(int u=0; u<num_u; u++) {
for(int i=0; i<3; i++) pts[i][u].resize(num_v_each);
for(int v=0; v<num_v_each; v++) {
pts[0][u][v] = get_point(u, v+shift).x;
pts[1][u][v] = get_point(u, v+shift).y;
pts[2][u][v] = get_point(u, v+shift).z;
}
}
gp << gp.binFile2d_colmajor(pts, "record") << "with lines title 'vec vec vec (colmajor)'";
}
#ifdef USE_ARMA
gp << ", ";
shift += num_v_each-1;
{
arma::cube pts(num_u, num_v_each, 3);
for(int u=0; u<num_u; u++) {
for(int v=0; v<num_v_each; v++) {
pts(u, v, 0) = get_point(u, v+shift).x;
pts(u, v, 1) = get_point(u, v+shift).y;
pts(u, v, 2) = get_point(u, v+shift).z;
}
}
gp << gp.file2d(pts) << "with lines title 'arma::cube(U*V*3)'";
}
gp << ", ";
shift += num_v_each-1;
{
arma::cube pts(3, num_u, num_v_each);
for(int u=0; u<num_u; u++) {
for(int v=0; v<num_v_each; v++) {
pts(0, u, v) = get_point(u, v+shift).x;
pts(1, u, v) = get_point(u, v+shift).y;
pts(2, u, v) = get_point(u, v+shift).z;
}
}
gp << gp.binFile2d_colmajor(pts, "record") << "with lines title 'arma::cube(3*U*V) (colmajor)'";
}
gp << ", ";
shift += num_v_each-1;
{
arma::field<MyTriple<double> > pts(num_u, num_v_each);
for(int u=0; u<num_u; u++) {
for(int v=0; v<num_v_each; v++) {
pts(u, v) = get_point(u, v+shift);
}
}
gp << gp.binFile2d(pts, "record") << "with lines title 'arma::field'";
}
#endif
#ifdef USE_BLITZ
gp << ", ";
shift += num_v_each-1;
{
blitz::Array<blitz::TinyVector<double, 3>, 2> pts(num_u, num_v_each);
for(int u=0; u<num_u; u++) {
for(int v=0; v<num_v_each; v++) {
pts(u, v)[0] = get_point(u, v+shift).x;
pts(u, v)[1] = get_point(u, v+shift).y;
pts(u, v)[2] = get_point(u, v+shift).z;
}
}
gp << gp.binFile2d(pts, "record") << "with lines title 'blitz::Array<blitz::TinyVector<double, 3>, 2>'";
}
gp << ", ";
shift += num_v_each-1;
{
blitz::Array<double, 3> pts(num_u, num_v_each, 3);
for(int u=0; u<num_u; u++) {
for(int v=0; v<num_v_each; v++) {
pts(u, v, 0) = get_point(u, v+shift).x;
pts(u, v, 1) = get_point(u, v+shift).y;
pts(u, v, 2) = get_point(u, v+shift).z;
}
}
gp << gp.binFile2d(pts, "record") << "with lines title 'blitz<double>(U*V*3)'";
}
gp << ", ";
shift += num_v_each-1;
{
blitz::Array<double, 3> pts(3, num_u, num_v_each);
for(int u=0; u<num_u; u++) {
for(int v=0; v<num_v_each; v++) {
pts(0, u, v) = get_point(u, v+shift).x;
pts(1, u, v) = get_point(u, v+shift).y;
pts(2, u, v) = get_point(u, v+shift).z;
}
}
gp << gp.binFile2d_colmajor(pts, "record") << "with lines title 'blitz<double>(3*U*V) (colmajor)'";
}
#endif
gp << std::endl;
std::cout << shift+num_v_each << "," << num_v_total << std::endl;
assert(shift+num_v_each == num_v_total);
#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
return 0;
}

View File

@@ -0,0 +1,63 @@
/*
Copyright (c) 2013 Daniel Stahlke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <vector>
#include <cmath>
#include <cstdlib>
#include <boost/tuple/tuple.hpp>
// This must be defined before the first time that "gnuplot-iostream.h" is included.
#define GNUPLOT_ENABLE_PTY
#include "gnuplot-iostream.h"
int main() {
Gnuplot gp;
// Create field of arrows at random locations.
std::vector<boost::tuple<double,double,double,double> > arrows;
for(size_t i=0; i<100; i++) {
double x = rand() / double(RAND_MAX);
double y = rand() / double(RAND_MAX);
arrows.push_back(boost::make_tuple(x, y, 0, 0));
}
double mx=0.5, my=0.5;
int mb=1;
while(mb != 3 && mb >= 0) {
// Make the arrows point towards the mouse click.
for(size_t i=0; i<arrows.size(); i++) {
double x = arrows[i].get<0>();
double y = arrows[i].get<1>();
double dx = (mx-x) * 0.1;
double dy = (my-y) * 0.1;
arrows[i] = boost::make_tuple(x, y, dx, dy);
}
gp << "plot '-' with vectors notitle\n";
gp.send1d(arrows);
gp.getMouse(mx, my, mb, "Left click to aim arrows, right click to exit.");
printf("You pressed mouse button %d at x=%f y=%f\n", mb, mx, my);
if(mb < 0) printf("The gnuplot window was closed.\n");
}
}

View File

@@ -0,0 +1,437 @@
/*
Copyright (c) 2013 Daniel Stahlke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <fstream>
#include <vector>
#include <map>
#include <limits>
#include <cmath>
#include <cstdio>
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp>
// Warn about use of deprecated functions.
#define GNUPLOT_DEPRECATE_WARN
#include "gnuplot-iostream.h"
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
// http://stackoverflow.com/a/1658429
#ifdef _WIN32
#include <windows.h>
inline void mysleep(unsigned millis) {
::Sleep(millis);
}
#else
#include <unistd.h>
inline void mysleep(unsigned millis) {
::usleep(millis * 1000);
}
#endif
void pause_if_needed() {
#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
}
// Tell MSVC to not warn about using fopen.
// http://stackoverflow.com/a/4805353/1048959
#if defined(_MSC_VER) && _MSC_VER >= 1400
#pragma warning(disable:4996)
#endif
void demo_basic() {
Gnuplot gp;
// For debugging or manual editing of commands:
//Gnuplot gp(std::fopen("plot.gnu"));
// or
//Gnuplot gp("tee plot.gnu | gnuplot -persist");
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";
gp << "plot '-' with lines title 'cubic', '-' with points title 'circle'\n";
gp.send1d(xy_pts_A);
gp.send1d(xy_pts_B);
pause_if_needed();
}
void demo_binary() {
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";
gp << "plot '-' binary" << gp.binFmt1d(xy_pts_A, "record") << "with lines title 'cubic',"
<< "'-' binary" << gp.binFmt1d(xy_pts_B, "record") << "with points title 'circle'\n";
gp.sendBinary1d(xy_pts_A);
gp.sendBinary1d(xy_pts_B);
pause_if_needed();
}
void demo_tmpfile() {
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
// (i.e. "gp.file1d(pts, 'mydata.dat')"), then the named file will be created
// and won't be deleted.
//
// Note: you need std::endl here in order to flush the buffer. The send1d()
// function flushes automatically, but we're not using that here.
gp << "plot" << gp.file1d(xy_pts_A) << "with lines title 'cubic',"
<< gp.file1d(xy_pts_B) << "with points title 'circle'" << std::endl;
pause_if_needed();
}
void demo_png() {
Gnuplot gp;
gp << "set terminal png\n";
std::vector<double> y_pts;
for(int i=0; i<1000; i++) {
double y = (i/500.0-1) * (i/500.0-1);
y_pts.push_back(y);
}
std::cout << "Creating my_graph_1.png" << std::endl;
gp << "set output 'my_graph_1.png'\n";
gp << "plot '-' with lines, sin(x/200) with lines\n";
gp.send1d(y_pts);
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)));
}
std::cout << "Creating my_graph_2.png" << std::endl;
gp << "set output 'my_graph_2.png'\n";
gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
gp << "plot '-' with lines title 'cubic', '-' with points title 'circle'\n";
gp.send1d(xy_pts_A);
gp.send1d(xy_pts_B);
}
void demo_vectors() {
Gnuplot gp;
std::vector<boost::tuple<double, double, double, double> > vecs;
for(double alpha=0; alpha<1; alpha+=1.0/24.0) {
double theta = alpha*2.0*3.14159;
vecs.push_back(boost::make_tuple(
cos(theta), sin(theta),
-cos(theta)*0.1, -sin(theta)*0.1
));
}
gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
gp << "plot '-' with vectors title 'circle'\n";
gp.send1d(vecs);
pause_if_needed();
}
std::vector<boost::tuple<double, double, double> > get_trefoil() {
std::vector<boost::tuple<double, double, double> > vecs;
for(double alpha=0; alpha<1; alpha+=1.0/120.0) {
double theta = alpha*2.0*3.14159;
vecs.push_back(boost::make_tuple(
(2+cos(3*theta))*cos(2*theta),
(2+cos(3*theta))*sin(2*theta),
sin(3*theta)
));
}
return vecs;
}
void demo_inline_text() {
std::cout << "Creating inline_text.gnu" << std::endl;
// This file handle will be closed automatically when gp goes out of scope.
Gnuplot gp(std::fopen("inline_text.gnu", "w"));
std::vector<boost::tuple<double, double, double> > vecs = get_trefoil();
gp << "splot '-' with lines notitle\n";
gp.send1d(vecs);
std::cout << "Now run 'gnuplot -persist inline_text.gnu'.\n";
}
void demo_inline_binary() {
std::cout << "Creating inline_binary.gnu" << std::endl;
// This file handle will be closed automatically when gp goes out of scope.
Gnuplot gp(std::fopen("inline_binary.gnu", "wb"));
std::vector<boost::tuple<double, double, double> > vecs = get_trefoil();
gp << "splot '-' binary" << gp.binFmt1d(vecs, "record") << "with lines notitle\n";
gp.sendBinary1d(vecs);
std::cout << "Now run 'gnuplot -persist inline_binary.gnu'.\n";
}
void demo_external_text() {
std::cout << "Creating external_text.gnu" << std::endl;
// This file handle will be closed automatically when gp goes out of scope.
Gnuplot gp(std::fopen("external_text.gnu", "w"));
std::vector<boost::tuple<double, double, double> > vecs = get_trefoil();
std::cout << "Creating external_text.dat" << std::endl;
gp << "splot" << gp.file1d(vecs, "external_text.dat") << "with lines notitle\n";
std::cout << "Now run 'gnuplot -persist external_text.gnu'.\n";
}
void demo_external_binary() {
std::cout << "Creating external_binary.gnu" << std::endl;
// This file handle will be closed automatically when gp goes out of scope.
Gnuplot gp(std::fopen("external_binary.gnu", "w"));
std::vector<boost::tuple<double, double, double> > vecs = get_trefoil();
std::cout << "Creating external_binary.dat" << std::endl;
gp << "splot" << gp.binFile1d(vecs, "record", "external_binary.dat")
<< "with lines notitle\n";
std::cout << "Now run 'gnuplot -persist external_binary.gnu'.\n";
}
void demo_animation() {
#ifdef _WIN32
// No animation demo for Windows. The problem is that every time the plot
// is updated, the gnuplot window grabs focus. So you can't ever focus the
// terminal window to press Ctrl-C. The only way to quit is to right-click
// the terminal window on the task bar and close it from there. Other than
// that, it seems to work.
std::cout << "Sorry, the animation demo doesn't work in Windows." << std::endl;
return;
#endif
Gnuplot gp;
std::cout << "Press Ctrl-C to quit (closing gnuplot window doesn't quit)." << std::endl;
gp << "set yrange [-1:1]\n";
const int N = 1000;
std::vector<double> pts(N);
double theta = 0;
while(1) {
for(int i=0; i<N; i++) {
double alpha = (double(i)/N-0.5) * 10;
pts[i] = sin(alpha*8.0 + theta) * exp(-alpha*alpha/2.0);
}
gp << "plot '-' binary" << gp.binFmt1d(pts, "array") << "with lines notitle\n";
gp.sendBinary1d(pts);
gp.flush();
theta += 0.2;
mysleep(100);
}
}
void demo_NaN() {
// Demo of NaN (not-a-number) usage. Plot a circle that has half the coordinates replaced
// by NaN values.
double nan = std::numeric_limits<double>::quiet_NaN();
Gnuplot gp;
std::vector<std::pair<double, double> > xy_pts;
for(int i=0; i<100; i++) {
double theta = double(i)/100*2*M_PI;
if((i/5)%2) {
xy_pts.push_back(std::make_pair(
std::cos(theta), std::sin(theta)
));
} else {
xy_pts.push_back(std::make_pair(nan, nan));
}
}
// You need to tell gnuplot that 'nan' should be treated as missing data (otherwise it just
// gives an error).
gp << "set datafile missing 'nan'\n";
gp << "plot '-' with linespoints\n";
gp.send1d(xy_pts);
// This works too. But the strange thing is that with text data the segments are joined by
// lines and with binary data the segments are not joined.
//gp << "plot '-' binary" << gp.binFmt1d(xy_pts, "record") << "with linespoints\n";
//gp.sendBinary1d(xy_pts);
pause_if_needed();
}
void demo_segments() {
// Demo of disconnected segments. Plot a circle with some pieces missing.
Gnuplot gp;
std::vector<std::vector<std::pair<double, double> > > all_segments;
for(int j=0; j<10; j++) {
std::vector<std::pair<double, double> > segment;
for(int i=0; i<5; i++) {
double theta = double(j*10+i)/100*2*M_PI;
segment.push_back(std::make_pair(
std::cos(theta), std::sin(theta)
));
}
all_segments.push_back(segment);
}
gp << "plot '-' with linespoints\n";
// NOTE: send2d is used here, rather than send1d. This puts a blank line between segments.
gp.send2d(all_segments);
pause_if_needed();
}
void demo_image() {
// Example of plotting an image. Of course you are free (and encouraged) to
// use Blitz or Armadillo rather than std::vector in these situations.
Gnuplot gp;
std::vector<std::vector<double> > image;
for(int j=0; j<100; j++) {
std::vector<double> row;
for(int i=0; i<100; i++) {
double x = (i-50.0)/5.0;
double y = (j-50.0)/5.0;
double z = std::cos(sqrt(x*x+y*y));
row.push_back(z);
}
image.push_back(row);
}
// It may seem counterintuitive that send1d should be used rather than
// send2d. The explanation is as follows. The "send2d" method puts each
// value on its own line, with blank lines between rows. This is what is
// expected by the splot command. The two "dimensions" here are the lines
// and the blank-line-delimited blocks. The "send1d" method doesn't group
// things into blocks. So the elements of each row are printed as columns,
// as expected by Gnuplot's "matrix with image" command. But images
// typically have lots of pixels, so sending as text is not the most
// efficient (although, it's not really that bad in the case of this
// example). See the binary version below.
//
//gp << "plot '-' matrix with image\n";
//gp.send1d(image);
// To be honest, Gnuplot's documentation for "binary" and for "image" are
// both unclear to me. The following example comes by trial-and-error.
gp << "plot '-' binary" << gp.binFmt2d(image, "array") << "with image\n";
gp.sendBinary2d(image);
pause_if_needed();
}
int main(int argc, char **argv) {
std::map<std::string, void (*)(void)> demos;
demos["basic"] = demo_basic;
demos["binary"] = demo_binary;
demos["tmpfile"] = demo_tmpfile;
demos["png"] = demo_png;
demos["vectors"] = demo_vectors;
demos["script_inline_text"] = demo_inline_text;
demos["script_inline_binary"] = demo_inline_binary;
demos["script_external_text"] = demo_external_text;
demos["script_external_binary"] = demo_external_binary;
demos["animation"] = demo_animation;
demos["nan"] = demo_NaN;
demos["segments"] = demo_segments;
demos["image"] = demo_image;
if(argc < 2) {
printf("Usage: %s <demo_name>\n", argv[0]);
printf("Choose one of the following demos:\n");
typedef std::pair<std::string, void (*)(void)> demo_pair;
BOOST_FOREACH(const demo_pair &pair, demos) {
printf(" %s\n", pair.first.c_str());
}
return 0;
}
std::string arg(argv[1]);
if(!demos.count(arg)) {
printf("No such demo '%s'\n", arg.c_str());
return 1;
}
demos[arg]();
}

File diff suppressed because it is too large Load Diff

5
gnuplot-iostream/legacy/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
# compiled stuff
examples
examples-blitz
examples-interactive
*.o

View File

@@ -0,0 +1,36 @@
CXXFLAGS+=-Wall -Wextra -I.. -O0 -g
# Don't warn about the fact that we use the deprecated send() function.
CXXFLAGS+=-Wno-deprecated-declarations
LDFLAGS+=-lutil -lboost_iostreams -lboost_system -lboost_filesystem
EVERYTHING=examples examples-blitz examples-interactive
all: examples
@echo "Now type 'make blitz' if you have blitz installed, and 'make interactive' if you system has PTY support."
blitz: examples-blitz
interactive: examples-interactive
everything: $(EVERYTHING)
%.o: %.cc gnuplot-iostream.h
$(CXX) $(CXXFLAGS) -c $< -o $@
examples: examples.o
$(CXX) -o $@ $^ $(LDFLAGS)
examples-blitz: examples-blitz.o
$(CXX) -o $@ $^ $(LDFLAGS)
examples-interactive: examples-interactive.o
$(CXX) -o $@ $^ $(LDFLAGS)
clean:
rm -f *.o
rm -f *.error.txt
rm -f examples examples-blitz examples-interactive
# Windows compilation
rm -f *.exe *.obj
# files created by demo scripts
rm -f my_graph_*.png external_binary.dat external_binary.gnu external_text.dat external_text.gnu inline_binary.gnu inline_text.gnu

View File

@@ -0,0 +1,2 @@
These are examples that use the old send() function rather than send1d() and send2d(). They
are here just so I can make sure they still compile.

View File

@@ -0,0 +1,122 @@
/*
Copyright (c) 2013 Daniel Stahlke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <vector>
#include <math.h>
// This must be included before gnuplot-iostream.h in order to support plotting blitz arrays.
#include <blitz/array.h>
#include "gnuplot-iostream.h"
// Yes, I'm including a *.cc file. It contains main().
#include "examples-framework.cc"
void demo_blitz_basic() {
// -persist option makes the window not disappear when your program exits
Gnuplot gp("gnuplot -persist");
blitz::Array<double, 2> arr(100, 100);
{
blitz::firstIndex i;
blitz::secondIndex j;
arr = (i-50) * (j-50);
}
gp << "set pm3d map; set palette" << std::endl;
gp << "splot '-'" << std::endl;
gp.send(arr);
}
void demo_blitz_waves_binary() {
Gnuplot gp("gnuplot -persist");
// example from Blitz manual:
int N = 64, cycles = 3;
double midpoint = (N-1)/2.;
double omega = 2.0 * M_PI * cycles / double(N);
double tau = - 10.0 / N;
blitz::Array<double, 2> F(N, N);
blitz::firstIndex i;
blitz::secondIndex j;
F = cos(omega * sqrt(pow2(i-midpoint) + pow2(j-midpoint)))
* exp(tau * sqrt(pow2(i-midpoint) + pow2(j-midpoint)));
gp << "splot '-' binary" << gp.binfmt(F) << "dx=10 dy=10 origin=(5,5,0) with pm3d notitle" << std::endl;
gp.sendBinary(F);
}
void demo_blitz_sierpinski_binary() {
Gnuplot gp("gnuplot -persist");
int N = 256;
blitz::Array<blitz::TinyVector<uint8_t, 4>, 2> F(N, N);
for(int i=0; i<N; i++)
for(int j=0; j<N; j++) {
F(i, j)[0] = i;
F(i, j)[1] = j;
F(i, j)[2] = 0;
F(i, j)[3] = (i&j) ? 0 : 255;
}
gp << "plot '-' binary" << gp.binfmt(F) << "with rgbalpha notitle" << std::endl;
gp.sendBinary(F);
}
void demo_blitz_waves_binary_file() {
Gnuplot gp("gnuplot -persist");
// example from Blitz manual:
int N = 64, cycles = 3;
double midpoint = (N-1)/2.;
double omega = 2.0 * M_PI * cycles / double(N);
double tau = - 10.0 / N;
blitz::Array<double, 2> F(N, N);
blitz::firstIndex i;
blitz::secondIndex j;
F = cos(omega * sqrt(pow2(i-midpoint) + pow2(j-midpoint)))
* exp(tau * sqrt(pow2(i-midpoint) + pow2(j-midpoint)));
gp << "splot" << gp.binaryFile(F) << "dx=10 dy=10 origin=(5,5,0) with pm3d notitle" << std::endl;
}
void demo_blitz_sierpinski_binary_file() {
Gnuplot gp("gnuplot -persist");
int N = 256;
blitz::Array<blitz::TinyVector<uint8_t, 4>, 2> F(N, N);
for(int i=0; i<N; i++)
for(int j=0; j<N; j++) {
F(i, j)[0] = i;
F(i, j)[1] = j;
F(i, j)[2] = 0;
F(i, j)[3] = (i&j) ? 0 : 255;
}
gp << "plot" << gp.binaryFile(F) << "with rgbalpha notitle" << std::endl;
}
void register_demos() {
register_demo("basic", demo_blitz_basic);
register_demo("waves_binary", demo_blitz_waves_binary);
register_demo("sierpinski_binary", demo_blitz_sierpinski_binary);
register_demo("waves_binary_file", demo_blitz_waves_binary_file);
register_demo("sierpinski_binary_file", demo_blitz_sierpinski_binary_file);
}

View File

@@ -0,0 +1,55 @@
/*
Copyright (c) 2013 Daniel Stahlke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <map>
#include <cstdio>
#include <boost/foreach.hpp>
std::map<std::string, void (*)(void)> demos;
void register_demo(const std::string &label, void (*fn)(void)) {
demos[label] = fn;
}
void register_demos();
int main(int argc, char **argv) {
register_demos();
if(argc < 2) {
printf("Usage: %s <demo_name>\n", argv[0]);
printf("Choose one of the following demos:\n");
typedef std::pair<std::string, void (*)(void)> demo_pair;
BOOST_FOREACH(const demo_pair &pair, demos) {
printf(" %s\n", pair.first.c_str());
}
return 0;
}
std::string arg(argv[1]);
if(!demos.count(arg)) {
printf("No such demo '%s'\n", arg.c_str());
return 1;
}
demos[arg]();
}

View File

@@ -0,0 +1,84 @@
/*
Copyright (c) 2013 Daniel Stahlke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <vector>
#include <math.h>
#define GNUPLOT_ENABLE_PTY
#include "gnuplot-iostream.h"
// Yes, I'm including a *.cc file. It contains main().
#include "examples-framework.cc"
void demo_basic() {
Gnuplot gp;
double mx=0, my=0;
int mb=1;
while(mb != 3 && mb >= 0) {
std::vector<std::pair<double, double> > xy_pts;
xy_pts.push_back(std::make_pair(mx, my));
for(double alpha=0; alpha<1; alpha+=1.0/24.0) {
double theta = alpha*2.0*3.14159;
xy_pts.push_back(std::make_pair(
mx+cos(theta), my+sin(theta)));
}
gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
gp << "plot '-' with points title 'circle'\n";
gp.send(xy_pts);
gp.getMouse(mx, my, mb, "Left click to move circle, right click to exit.");
printf("You pressed mouse button %d at x=%f y=%f\n", mb, mx, my);
if(mb < 0) printf("The gnuplot window was closed.\n");
}
}
void demo_vectors() {
Gnuplot gp;
double mx=0, my=0;
int mb=1;
while(mb != 3 && mb >= 0) {
std::vector<std::vector<float> > vecs(4);
for(double alpha=0; alpha<1; alpha+=1.0/24.0) {
double theta = alpha*2.0*3.14159;
vecs[0].push_back(mx+cos(theta));
vecs[1].push_back(my+sin(theta));
vecs[2].push_back(-cos(theta)*0.1);
vecs[3].push_back(-sin(theta)*0.1);
}
gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
gp << "plot '-' with vectors title 'circle'\n";
gp.send(vecs);
gp.getMouse(mx, my, mb, "Left click to move circle, right click to exit.");
printf("You pressed mouse button %d at x=%f y=%f\n", mb, mx, my);
if(mb < 0) printf("The gnuplot window was closed.\n");
}
}
void register_demos() {
register_demo("basic", demo_basic);
register_demo("vectors", demo_vectors);
}

View File

@@ -0,0 +1,325 @@
/*
Copyright (c) 2013 Daniel Stahlke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <fstream>
#include <vector>
#include <math.h>
#include "gnuplot-iostream.h"
// Yes, I'm including a *.cc file. It contains main().
#include "examples-framework.cc"
// http://stackoverflow.com/a/1658429
#ifdef _WIN32
#include <windows.h>
inline void mysleep(unsigned millis) {
::Sleep(millis);
}
#else
#include <unistd.h>
inline void mysleep(unsigned millis) {
::usleep(millis * 1000);
}
#endif
void demo_basic() {
// -persist option makes the window not disappear when your program exits
Gnuplot gp("gnuplot -persist");
// For debugging or manual editing of commands:
//Gnuplot gp(fopen("plot.gnu"));
// or
//Gnuplot gp("tee plot.gnu | gnuplot -persist");
// NOTE: we can use map here because the X values are intended to be
// sorted. If this was not the case, vector<pair<double,double>> could be
// used instead.
std::map<double, double> xy_pts_A;
for(double x=-2; x<2; x+=0.01) {
double y = x*x*x;
xy_pts_A[x] = y;
}
std::map<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[cos(theta)] = sin(theta);
}
gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
gp << "plot '-' with lines title 'cubic', '-' with points title 'circle'\n";
gp.send(xy_pts_A).send(xy_pts_B);
}
void demo_array() {
// -persist option makes the window not disappear when your program exits
Gnuplot gp("gnuplot -persist");
double arr[] = { 1, 3, 2 };
gp << "plot '-' with lines\n";
gp.send(arr);
}
namespace xyz {
template <typename T>
struct MyTriple {
MyTriple(
T _x,
T _y,
T _z
) : x(_x), y(_y), z(_z) { }
T x, y, z;
};
}
using xyz::MyTriple;
namespace gnuplotio {
template<typename T>
struct BinfmtSender<MyTriple<T> > {
static void send(std::ostream &stream) {
BinfmtSender<T>::send(stream);
BinfmtSender<T>::send(stream);
BinfmtSender<T>::send(stream);
}
};
template <typename T>
struct BinarySender<MyTriple<T> > {
static void send(std::ostream &stream, const MyTriple<T> &v) {
BinarySender<T>::send(stream, v.x);
BinarySender<T>::send(stream, v.y);
BinarySender<T>::send(stream, v.z);
}
};
template<typename T>
struct TextSender<MyTriple<T> > {
static void send(std::ostream &stream, const MyTriple<T> &v) {
TextSender<T>::send(stream, v.x);
stream << " ";
TextSender<T>::send(stream, v.y);
stream << " ";
TextSender<T>::send(stream, v.z);
}
};
}
void demo_tuple() {
// -persist option makes the window not disappear when your program exits
Gnuplot gp("gnuplot -persist");
std::vector<MyTriple<double> > pts;
for(double alpha=0; alpha<1; alpha+=1.0/120.0) {
double theta = alpha*2.0*3.14159;
double x = (2+cos(3*theta))*cos(2*theta);
double y = (2+cos(3*theta))*sin(2*theta);
double z = sin(3*theta);
pts.push_back(MyTriple<double> (x, y, z));
}
gp << "splot '-' binary" << gp.binfmt(pts, "record") << "with lines notitle\n";
gp.sendBinary(pts);
}
void demo_tmpfile() {
// -persist option makes the window not disappear when your program exits
Gnuplot gp("gnuplot -persist");
// NOTE: we can use map here because the X values are intended to be
// sorted. If this was not the case, vector<pair<double,double>> could be
// used instead.
std::map<double, double> xy_pts_A;
for(double x=-2; x<2; x+=0.01) {
double y = x*x*x;
xy_pts_A[x] = y;
}
std::map<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[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
// (i.e. "gp.file(pts, 'mydata.dat')"), then the named file will be created
// and won't be deleted.
gp << "plot" << gp.file(xy_pts_A) << "with lines title 'cubic',"
<< gp.file(xy_pts_B) << "with points title 'circle'\n";
}
void demo_png() {
Gnuplot gp;
gp << "set terminal png\n";
std::vector<double> y_pts;
for(int i=0; i<1000; i++) {
double y = (i/500.0-1) * (i/500.0-1);
y_pts.push_back(y);
}
std::cout << "Creating my_graph_1.png" << std::endl;
gp << "set output 'my_graph_1.png'\n";
gp << "plot '-' with lines, sin(x/200) with lines\n";
gp.send(y_pts);
// NOTE: we can use map here because the X values are intended to be
// sorted. If this was not the case, vector<pair<double,double>> could be
// used instead.
std::map<double, double> xy_pts_A;
for(double x=-2; x<2; x+=0.01) {
double y = x*x*x;
xy_pts_A[x] = y;
}
std::map<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[cos(theta)] = sin(theta);
}
std::cout << "Creating my_graph_2.png" << std::endl;
gp << "set output 'my_graph_2.png'\n";
gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
gp << "plot '-' with lines title 'cubic', '-' with points title 'circle'\n";
gp.send(xy_pts_A).send(xy_pts_B);
}
void demo_vectors() {
// -persist option makes the window not disappear when your program exits
Gnuplot gp("gnuplot -persist");
std::vector<std::vector<double> > vecs(4);
for(double alpha=0; alpha<1; alpha+=1.0/24.0) {
double theta = alpha*2.0*3.14159;
vecs[0].push_back( cos(theta));
vecs[1].push_back( sin(theta));
vecs[2].push_back(-cos(theta)*0.1);
vecs[3].push_back(-sin(theta)*0.1);
}
gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
gp << "plot '-' with vectors title 'circle'\n";
gp.send(vecs);
}
std::vector<std::vector<double> > get_trefoil() {
std::vector<std::vector<double> > vecs(3);
for(double alpha=0; alpha<1; alpha+=1.0/120.0) {
double theta = alpha*2.0*3.14159;
vecs[0].push_back((2+cos(3*theta))*cos(2*theta));
vecs[1].push_back((2+cos(3*theta))*sin(2*theta));
vecs[2].push_back(sin(3*theta));
}
return vecs;
}
void demo_inline_text() {
std::cout << "Creating inline_text.gnu" << std::endl;
// This file handle will be closed automatically when gp goes out of scope.
Gnuplot gp(fopen("inline_text.gnu", "w"));
std::vector<std::vector<double> > vecs = get_trefoil();
gp << "splot '-' with lines notitle\n";
gp.send(vecs);
}
void demo_inline_binary() {
std::cout << "Creating inline_binary.gnu" << std::endl;
// This file handle will be closed automatically when gp goes out of scope.
Gnuplot gp(fopen("inline_binary.gnu", "wb"));
std::vector<std::vector<double> > vecs = get_trefoil();
gp << "splot '-' binary" << gp.binfmt(vecs, "record") << "with lines notitle\n";
gp.sendBinary(vecs);
}
void demo_external_text() {
std::cout << "Creating external_text.gnu" << std::endl;
// This file handle will be closed automatically when gp goes out of scope.
Gnuplot gp(fopen("external_text.gnu", "w"));
std::vector<std::vector<double> > vecs = get_trefoil();
std::cout << "Creating external_text.dat" << std::endl;
gp << "splot" << gp.file(vecs, "external_text.dat") << "with lines notitle\n";
}
void demo_external_binary() {
std::cout << "Creating external_binary.gnu" << std::endl;
// This file handle will be closed automatically when gp goes out of scope.
Gnuplot gp(fopen("external_binary.gnu", "w"));
std::vector<std::vector<double> > vecs = get_trefoil();
std::cout << "Creating external_binary.dat" << std::endl;
gp << "splot" << gp.binaryFile(vecs, "external_binary.dat", "record") << "with lines notitle\n";
}
void demo_animation() {
Gnuplot gp;
std::cout << "Press Ctrl-C to quit (closing gnuplot window doesn't quit)." << std::endl;
gp << "set yrange [-1:1]\n";
const int N = 1000;
std::vector<double> pts(N);
double theta = 0;
while(1) {
for(int i=0; i<N; i++) {
double alpha = (double(i)/N-0.5) * 10;
pts[i] = sin(alpha*8.0 + theta) * exp(-alpha*alpha/2.0);
}
gp << "plot '-' binary" << gp.binfmt(pts) << "with lines notitle\n";
gp.sendBinary(pts);
gp.flush();
theta += 0.2;
mysleep(100);
}
}
void register_demos() {
register_demo("basic", demo_basic);
register_demo("array", demo_array);
register_demo("tuple", demo_tuple);
register_demo("tmpfile", demo_tmpfile);
register_demo("png", demo_png);
register_demo("vectors", demo_vectors);
register_demo("script_inline_text", demo_inline_text);
register_demo("script_inline_binary", demo_inline_binary);
register_demo("script_external_text", demo_external_text);
register_demo("script_external_binary", demo_external_binary);
register_demo("animation", demo_animation);
}

View File

@@ -0,0 +1,39 @@
/*
Copyright (c) 2013 Daniel Stahlke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <vector>
#include "gnuplot-iostream.h"
int main() {
Gnuplot gp;
std::vector<std::vector<int> > pts;
// These should be okay.
gp << gp.sendBinary1d(pts);
gp << gp.sendBinary1d_colmajor(pts);
gp << gp.sendBinary2d(pts);
// This should throw a compilation error.
gp << gp.sendBinary2d_colmajor(pts);
return 0;
}

View File

@@ -0,0 +1,37 @@
/*
Copyright (c) 2013 Daniel Stahlke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <vector>
#include "gnuplot-iostream.h"
int main() {
Gnuplot gp;
std::vector<int> pts;
// This should be okay.
gp << gp.sendBinary1d(pts);
// This should throw a compilation error.
gp << gp.sendBinary2d(pts);
return 0;
}

View File

@@ -0,0 +1,76 @@
/*
Copyright (c) 2013 Daniel Stahlke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// FIXME - Currently this test is not being run and validated by the Makefile.
// I'm waiting to see the outcome of the following bug report:
// https://sourceforge.net/p/gnuplot/bugs/1500/
#include <fstream>
#include <vector>
#if GNUPLOT_ENABLE_CXX11
#include <tuple>
#include <array>
#endif
#include <boost/array.hpp>
#if USE_ARMA
#include <armadillo>
#endif
#if USE_BLITZ
#include <blitz/array.h>
#endif
#include "gnuplot-iostream.h"
using namespace gnuplotio;
const std::string basedir = "unittest-output";
template <typename T>
void go(Gnuplot &gp, const T &data) {
gp << "plot '-' binary" << gp.binFmt1d(data, "record") << std::endl;
gp.sendBinary1d(data);
gp << "plot '-' binary" << gp.binFmt2d(data, "record") << std::endl;
gp.sendBinary2d(data);
gp << "plot '-'\n" << std::endl;
gp.send1d(data);
gp << "plot '-'\n" << std::endl;
gp.send2d(data);
}
int main() {
Gnuplot gp(std::fopen((basedir + "/test-empty.gnu").c_str(), "w"));
std::vector<std::vector<std::vector<std::pair<double, int> > > > data;
go(gp, data);
data.resize(1);
go(gp, data);
data[0].resize(1);
go(gp, data);
data[0][0].push_back(std::make_pair(0.0, 0));
go(gp, data);
}

View File

@@ -0,0 +1,60 @@
/*
Copyright (c) 2013 Daniel Stahlke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <vector>
#include <boost/utility.hpp>
#include <boost/tuple/tuple.hpp>
#include "gnuplot-iostream.h"
#define USE_CXX (__cplusplus >= 201103)
template <typename T>
class NonCopyable : boost::noncopyable, public std::vector<T> {
public:
NonCopyable() { }
};
int main() {
Gnuplot gp;
NonCopyable<double> nc_x, nc_y;
for(int i=0; i<100; i++) {
nc_x.push_back(-i);
nc_y.push_back(i*i);
}
gp << "plot '-', '-'\n";
// These don't work because they make copies.
//gp.send1d(std::make_pair(nc_x, nc_y));
//gp.send1d(boost::make_tuple(nc_x, nc_y));
// These work because they make references:
#if USE_CXX
std::cout << "using std::tie" << std::endl;
gp.send1d(std::tie(nc_y));
gp.send1d(std::forward_as_tuple(nc_x, std::move(nc_y)));
#else
std::cout << "using boost::tie" << std::endl;
gp.send1d(nc_y);
gp.send1d(boost::tie(nc_x, nc_y));
#endif
}

View File

@@ -0,0 +1,275 @@
/*
Copyright (c) 2013 Daniel Stahlke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Include this several times to test delayed loading of armadillo/blitz support.
#include "gnuplot-iostream.h"
#include <fstream>
#include <vector>
#if GNUPLOT_ENABLE_CXX11
#include <tuple>
#include <array>
#endif
#include <boost/array.hpp>
#if USE_ARMA
#include <armadillo>
#endif
#include "gnuplot-iostream.h"
#if USE_BLITZ
#include <blitz/array.h>
#endif
#include "gnuplot-iostream.h"
#include "gnuplot-iostream.h"
using namespace gnuplotio;
Gnuplot gp;
const std::string basedir = "unittest-output";
template <typename T, typename ArrayMode>
void test_given_mode(
std::ostream &log_fh, std::string header, const T &arg,
ArrayMode, boost::mpl::true_
) {
std::string modename = ArrayMode::class_name();
std::string fn_prefix = basedir+"/"+header+"-"+modename;
log_fh << "* " << modename << " -> "
<< gp.binaryFile(arg, fn_prefix+".bin", "record", ArrayMode()) << std::endl;
gp.file(arg, fn_prefix+".txt", ArrayMode());
}
template <typename T, typename ArrayMode>
void test_given_mode(
std::ostream &log_fh, std::string header, const T &arg,
ArrayMode, boost::mpl::false_
) {
std::string modename = ArrayMode::class_name();
std::string fn_prefix = basedir+"/"+header+"-"+modename;
log_fh << "* " << modename << " (skipped binary) " << std::endl;
gp.file(arg, fn_prefix+".txt", ArrayMode());
}
template <typename T, typename DoBinary>
typename boost::enable_if_c<(ArrayTraits<T>::depth == 1)>::type
runtest_inner(std::ostream &log_fh, std::string header, const T &arg) {
test_given_mode<T>(log_fh, header, arg, Mode1D(), DoBinary());
}
template <typename T, typename DoBinary>
typename boost::enable_if_c<(ArrayTraits<T>::depth == 2)>::type
runtest_inner(std::ostream &log_fh, std::string header, const T &arg) {
test_given_mode<T>(log_fh, header, arg, Mode2D(), DoBinary());
test_given_mode<T>(log_fh, header, arg, Mode1DUnwrap(), DoBinary());
}
template <typename T, typename DoBinary>
typename boost::enable_if_c<(ArrayTraits<T>::depth >= 3)>::type
runtest_inner(std::ostream &log_fh, std::string header, const T &arg) {
test_given_mode<T>(log_fh, header, arg, Mode2D(), DoBinary());
test_given_mode<T>(log_fh, header, arg, Mode2DUnwrap(), DoBinary());
}
template <typename T, typename DoBinary>
void runtest_maybe_dobin(std::string header, const T &arg) {
std::ofstream log_fh((basedir+"/"+header+"-log.txt").c_str());
log_fh << "--- " << header << " -------------------------------------" << std::endl;
log_fh << "depth=" << ArrayTraits<T>::depth << std::endl;
log_fh << "ModeAutoDecoder=" << ModeAutoDecoder<T>::mode::class_name() << std::endl;
runtest_inner<T, DoBinary>(log_fh, header, arg);
}
template <typename T>
void runtest(std::string header, const T &arg) {
runtest_maybe_dobin<T, boost::mpl::true_>(header, arg);
}
template <typename T>
void runtest_nobin(std::string header, const T &arg) {
runtest_maybe_dobin<T, boost::mpl::false_>(header, arg);
}
template <typename T, typename DoBinary>
void basic_datatype_test_integral(std::string name) {
std::vector<T> v;
for(int i=0; i<4; i++) {
v.push_back(i);
}
runtest_maybe_dobin<std::vector<T>, DoBinary>(name, v);
}
template <typename T, typename DoBinary>
void basic_datatype_test_float(std::string name) {
std::vector<T> v;
for(int i=0; i<4; i++) {
v.push_back(i + T(0.1234));
}
v.push_back(std::numeric_limits<T>::quiet_NaN());
runtest_maybe_dobin<std::vector<T>, DoBinary>(name, v);
}
int main() {
const int NX=3, NY=4, NZ=2;
std::vector<double> vd;
std::vector<int> vi;
std::vector<float> vf;
std::vector<std::vector<double> > vvd(NX);
std::vector<std::vector<int> > vvi(NX);
std::vector<std::vector<std::vector<int> > > vvvi(NX);
std::vector<std::vector<std::vector<std::pair<double, int> > > > vvvp(NX);
int ai[NX];
boost::array<int, NX> bi;
std::vector<boost::tuple<double, int, int> > v_bt;
#if GNUPLOT_ENABLE_CXX11
std::array<int, NX> si;
std::vector< std::tuple<double, int, int> > v_st;
#endif
for(int x=0; x<NX; x++) {
vd.push_back(x+7.5);
vi.push_back(x+7);
vf.push_back(x+7.2F);
v_bt.push_back(boost::make_tuple(x+0.123, 100+x, 200+x));
#if GNUPLOT_ENABLE_CXX11
v_st.push_back(std::make_tuple(x+0.123, 100+x, 200+x));
si[x] = x+90;
#endif
ai[x] = x+7;
bi[x] = x+70;
for(int y=0; y<NY; y++) {
vvd[x].push_back(100+x*10+y);
vvi[x].push_back(200+x*10+y);
std::vector<int> tup;
tup.push_back(300+x*10+y);
tup.push_back(400+x*10+y);
vvvi[x].push_back(tup);
std::vector<std::pair<double, int> > stuff;
for(int z=0; z<NZ; z++) {
stuff.push_back(std::make_pair(
x*1000+y*100+z+0.5,
x*1000+y*100+z));
}
vvvp[x].push_back(stuff);
}
}
basic_datatype_test_integral<boost:: int8_t, boost::mpl::true_>("vi8");
basic_datatype_test_integral<boost:: uint8_t, boost::mpl::true_>("vu8");
basic_datatype_test_integral<boost:: int16_t, boost::mpl::true_>("vi16");
basic_datatype_test_integral<boost::uint16_t, boost::mpl::true_>("vu16");
basic_datatype_test_integral<boost:: int32_t, boost::mpl::true_>("vi32");
basic_datatype_test_integral<boost::uint32_t, boost::mpl::true_>("vu32");
// these should all print as integers
basic_datatype_test_integral<char, boost::mpl::false_>("vpc");
basic_datatype_test_integral<signed char, boost::mpl::false_>("vsc");
basic_datatype_test_integral<unsigned char, boost::mpl::false_>("vuc");
basic_datatype_test_float<float, boost::mpl::true_>("vf");
basic_datatype_test_float<double, boost::mpl::true_>("vd");
basic_datatype_test_float<long double, boost::mpl::false_>("vld");
runtest("vd,vi,bi", std::make_pair(vd, std::make_pair(vi, bi)));
runtest("vvd", vvd);
runtest("vvd,vvi", std::make_pair(vvd, vvi));
runtest("ai", ai);
runtest("bi", bi);
#if GNUPLOT_ENABLE_CXX11
runtest("si", si);
runtest("tie{si,bi}", boost::tie(si, bi));
runtest("pair{&si,&bi}", std::pair<std::array<int, NX>&, boost::array<int, NX>&>(si, bi));
#endif
// Doesn't work because array gets cast to pointer
//runtest("pair{ai,bi}", std::make_pair(ai, bi));
// However, these work:
runtest("boost_tie{ai,bi}", boost::tie(ai, bi));
#if GNUPLOT_ENABLE_CXX11
runtest("std_tie{ai,bi}", std::tie(ai, bi));
runtest("std_fwd{ai,bi}", std::forward_as_tuple(ai, bi));
#endif
runtest("pair{ai,bi}", std::pair<int(&)[NX], boost::array<int, NX> >(ai, bi));
runtest("vvd,vvi,vvvi", std::make_pair(vvd, std::make_pair(vvi, vvvi)));
runtest("vvvp", vvvp);
#if USE_ARMA
arma::vec armacol(NX);
arma::mat armamat(NX, NY);
for(int x=0; x<NX; x++) {
armacol(x) = x+0.123;
for(int y=0; y<NY; y++) {
armamat(x, y) = x*10+y+0.123;
}
}
runtest("armacol", armacol);
runtest("armamat", armamat);
#endif
#if USE_BLITZ
blitz::Array<double, 1> blitz1d(NX);
blitz::Array<double, 2> blitz2d(NX, NY);
{
blitz::firstIndex i;
blitz::secondIndex j;
blitz1d = i + 0.777;
blitz2d = 100 + i*10 + j;
}
blitz::Array<blitz::TinyVector<double, 2>, 2> blitz2d_tup(NX, NY);
for(int x=0; x<NX; x++) {
for(int y=0; y<NY; y++) {
blitz2d_tup(x, y)[0] = 100+x*10+y;
blitz2d_tup(x, y)[1] = 200+x*10+y;
}
}
runtest("blitz1d", blitz1d);
runtest("blitz1d,vd", std::make_pair(blitz1d, vd));
runtest("blitz2d", blitz2d);
runtest("blitz2d_tup", blitz2d_tup);
runtest("blitz2d,vvi", std::make_pair(blitz2d, vvi));
runtest("blitz2d,vd", std::make_pair(blitz2d, vd));
#endif
runtest("vvvi cols", vvvi);
runtest("pair{vf,btup{vd,pair{vi,vi},vf}}", std::make_pair(vf, boost::make_tuple(vd, std::make_pair(vi, vi), vf)));
#if GNUPLOT_ENABLE_CXX11
runtest("pair{vf,stup{vd,pair{vi,vi},vf}}", std::make_pair(vf, std::make_tuple(vd, std::make_pair(vi, vi), vf)));
runtest("btup{vd,stup{vi,btup{vf},vi},vd}", boost::make_tuple(vd, std::make_tuple(vi, boost::make_tuple(vf), vi), vd));
#endif
runtest("v_bt", v_bt);
#if GNUPLOT_ENABLE_CXX11
runtest("v_st", v_st);
#endif
#if USE_BLITZ
runtest("blitz2d cols", blitz2d);
#endif
}

Binary file not shown.

View File

@@ -0,0 +1,3 @@
7
8
9

View File

@@ -0,0 +1,4 @@
--- ai -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/ai-Mode1D.bin' binary format='%int32' record=(3)

View File

@@ -0,0 +1,3 @@
0.123
1.123
2.123

View File

@@ -0,0 +1,4 @@
--- armacol -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/armacol-Mode1D.bin' binary format='%double' record=(3)

View File

@@ -0,0 +1,4 @@
0.123 10.123 20.123
1.123 11.123 21.123
2.123 12.123 22.123
3.123 13.123 23.123

View File

@@ -0,0 +1,14 @@
0.123
1.123
2.123
3.123
10.123
11.123
12.123
13.123
20.123
21.123
22.123
23.123

View File

@@ -0,0 +1,5 @@
--- armamat -------------------------------------
depth=2
ModeAutoDecoder=Mode2D
* Mode2D -> 'unittest-output/armamat-Mode2D.bin' binary format='%double' record=(4,3)
* Mode1DUnwrap -> 'unittest-output/armamat-Mode1DUnwrap.bin' binary format='%double%double%double' record=(4)

Binary file not shown.

View File

@@ -0,0 +1,3 @@
70
71
72

View File

@@ -0,0 +1,4 @@
--- bi -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/bi-Mode1D.bin' binary format='%int32' record=(3)

View File

@@ -0,0 +1,3 @@
0.777 7.5
1.777 8.5
2.777 9.5

View File

@@ -0,0 +1,4 @@
--- blitz1d,vd -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/blitz1d,vd-Mode1D.bin' binary format='%double%double' record=(3)

View File

@@ -0,0 +1 @@
<EFBFBD>/έθ?<ίO<CEAF>—nό?<3F>ο§ΖK7@

View File

@@ -0,0 +1,3 @@
0.777
1.777
2.777

View File

@@ -0,0 +1,4 @@
--- blitz1d -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/blitz1d-Mode1D.bin' binary format='%double' record=(3)

View File

@@ -0,0 +1,4 @@
100 110 120
101 111 121
102 112 122
103 113 123

View File

@@ -0,0 +1,14 @@
100
101
102
103
110
111
112
113
120
121
122
123

View File

@@ -0,0 +1,5 @@
--- blitz2d cols -------------------------------------
depth=2
ModeAutoDecoder=Mode2D
* Mode2D -> 'unittest-output/blitz2d cols-Mode2D.bin' binary format='%double' record=(4,3)
* Mode1DUnwrap -> 'unittest-output/blitz2d cols-Mode1DUnwrap.bin' binary format='%double%double%double' record=(4)

View File

@@ -0,0 +1,3 @@
100 101 102 103 7.5
110 111 112 113 8.5
120 121 122 123 9.5

View File

@@ -0,0 +1,4 @@
--- blitz2d,vd -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/blitz2d,vd-Mode1D.bin' binary format='%double%double%double%double%double' record=(3)

View File

@@ -0,0 +1,4 @@
100 200 110 210 120 220
101 201 111 211 121 221
102 202 112 212 122 222
103 203 113 213 123 223

View File

@@ -0,0 +1,14 @@
100 200
101 201
102 202
103 203
110 210
111 211
112 212
113 213
120 220
121 221
122 222
123 223

View File

@@ -0,0 +1,5 @@
--- blitz2d,vvi -------------------------------------
depth=2
ModeAutoDecoder=Mode2D
* Mode2D -> 'unittest-output/blitz2d,vvi-Mode2D.bin' binary format='%double%int32' record=(4,3)
* Mode1DUnwrap -> 'unittest-output/blitz2d,vvi-Mode1DUnwrap.bin' binary format='%double%int32%double%int32%double%int32' record=(4)

View File

@@ -0,0 +1,4 @@
100 110 120
101 111 121
102 112 122
103 113 123

View File

@@ -0,0 +1,14 @@
100
101
102
103
110
111
112
113
120
121
122
123

View File

@@ -0,0 +1,5 @@
--- blitz2d -------------------------------------
depth=2
ModeAutoDecoder=Mode2D
* Mode2D -> 'unittest-output/blitz2d-Mode2D.bin' binary format='%double' record=(4,3)
* Mode1DUnwrap -> 'unittest-output/blitz2d-Mode1DUnwrap.bin' binary format='%double%double%double' record=(4)

View File

@@ -0,0 +1,4 @@
100 200 110 210 120 220
101 201 111 211 121 221
102 202 112 212 122 222
103 203 113 213 123 223

View File

@@ -0,0 +1,14 @@
100 200
101 201
102 202
103 203
110 210
111 211
112 212
113 213
120 220
121 221
122 222
123 223

View File

@@ -0,0 +1,5 @@
--- blitz2d_tup -------------------------------------
depth=2
ModeAutoDecoder=Mode2D
* Mode2D -> 'unittest-output/blitz2d_tup-Mode2D.bin' binary format='%double%double' record=(4,3)
* Mode1DUnwrap -> 'unittest-output/blitz2d_tup-Mode1DUnwrap.bin' binary format='%double%double%double%double%double%double' record=(4)

View File

@@ -0,0 +1,3 @@
7 70
8 71
9 72

View File

@@ -0,0 +1,4 @@
--- boost_tie{ai,bi} -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/boost_tie{ai,bi}-Mode1D.bin' binary format='%int32%int32' record=(3)

View File

@@ -0,0 +1,3 @@
7.5 7 7.2 7 7.5
8.5 8 8.2 8 8.5
9.5 9 9.2 9 9.5

View File

@@ -0,0 +1,4 @@
--- btup{vd,stup{vi,btup{vf},vi},vd} -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/btup{vd,stup{vi,btup{vf},vi},vd}-Mode1D.bin' binary format='%double%int32%float%int32%double' record=(3)

View File

@@ -0,0 +1,3 @@
90 70
91 71
92 72

View File

@@ -0,0 +1,4 @@
--- pair{&si,&bi} -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/pair{&si,&bi}-Mode1D.bin' binary format='%int32%int32' record=(3)

View File

@@ -0,0 +1,3 @@
7 70
8 71
9 72

View File

@@ -0,0 +1,4 @@
--- pair{ai,bi} -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/pair{ai,bi}-Mode1D.bin' binary format='%int32%int32' record=(3)

View File

@@ -0,0 +1,3 @@
7.2 7.5 7 7 7.2
8.2 8.5 8 8 8.2
9.2 9.5 9 9 9.2

View File

@@ -0,0 +1,4 @@
--- pair{vf,btup{vd,pair{vi,vi},vf}} -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/pair{vf,btup{vd,pair{vi,vi},vf}}-Mode1D.bin' binary format='%float%double%int32%int32%float' record=(3)

View File

@@ -0,0 +1,3 @@
7.2 7.5 7 7 7.2
8.2 8.5 8 8 8.2
9.2 9.5 9 9 9.2

View File

@@ -0,0 +1,4 @@
--- pair{vf,stup{vd,pair{vi,vi},vf}} -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/pair{vf,stup{vd,pair{vi,vi},vf}}-Mode1D.bin' binary format='%float%double%int32%int32%float' record=(3)

Binary file not shown.

View File

@@ -0,0 +1,3 @@
90
91
92

View File

@@ -0,0 +1,4 @@
--- si -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/si-Mode1D.bin' binary format='%int32' record=(3)

View File

@@ -0,0 +1,3 @@
7 70
8 71
9 72

View File

@@ -0,0 +1,4 @@
--- std_fwd{ai,bi} -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/std_fwd{ai,bi}-Mode1D.bin' binary format='%int32%int32' record=(3)

View File

@@ -0,0 +1,3 @@
7 70
8 71
9 72

View File

@@ -0,0 +1,4 @@
--- std_tie{ai,bi} -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/std_tie{ai,bi}-Mode1D.bin' binary format='%int32%int32' record=(3)

View File

@@ -0,0 +1,3 @@
90 70
91 71
92 72

View File

@@ -0,0 +1,4 @@
--- tie{si,bi} -------------------------------------
depth=1
ModeAutoDecoder=Mode1D
* Mode1D -> 'unittest-output/tie{si,bi}-Mode1D.bin' binary format='%int32%int32' record=(3)

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More