mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-01-17 12:43:01 +00:00
Simplify gnuplot interface usage in tests
This commit is contained in:
parent
785d6185c3
commit
0164d6725d
@ -3,7 +3,7 @@
|
||||
* \brief A C++ interface to gnuplot.
|
||||
* \author Carles Fernandez-Prades, 2017. cfernandez(at)cttc.es
|
||||
*
|
||||
* Source code found at https://code.google.com/archive/p/gnuplot-cpp/
|
||||
* Original source code found at https://code.google.com/archive/p/gnuplot-cpp/
|
||||
* by Jeremy Conlin jeremit0(at)gmail.com
|
||||
*
|
||||
* Version history:
|
||||
@ -16,6 +16,8 @@
|
||||
* 3. some member functions added, corrections for Win32 and Linux
|
||||
* compatibility
|
||||
* by M. Burgis (10/03/08)
|
||||
* 4. Some fixes and improvements for Linux and macOS
|
||||
* by C. Fernandez (22/10/17)
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 2013-2017 (see AUTHORS file for a list of contributors)
|
||||
@ -120,7 +122,8 @@ private:
|
||||
///
|
||||
/// \return <-- void
|
||||
// ---------------------------------------------------
|
||||
void init();
|
||||
void init();
|
||||
|
||||
// ---------------------------------------------------
|
||||
///\brief creates tmpfile and returns its name
|
||||
///
|
||||
@ -128,7 +131,7 @@ private:
|
||||
///
|
||||
/// \return <-- the name of the tempfile
|
||||
// ---------------------------------------------------
|
||||
std::string create_tmpfile(std::ofstream &tmp);
|
||||
std::string create_tmpfile(std::ofstream &tmp);
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
///\brief gnuplot path found?
|
||||
@ -137,7 +140,7 @@ private:
|
||||
///
|
||||
/// \return <-- found the gnuplot path (yes == true, no == false)
|
||||
// ---------------------------------------------------------------------------------
|
||||
static bool get_program_path();
|
||||
static bool get_program_path();
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
///\brief checks if file is available
|
||||
@ -157,7 +160,7 @@ private:
|
||||
///
|
||||
/// \return file exists (yes == true, no == false)
|
||||
// ---------------------------------------------------------------------------------
|
||||
static bool file_exists(const std::string &filename, int mode=0);
|
||||
static bool file_exists(const std::string &filename, int mode=0);
|
||||
|
||||
public:
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -228,7 +231,8 @@ public:
|
||||
///
|
||||
/// \return <-- a reference to the gnuplot object
|
||||
// ---------------------------------------------------------------------------------
|
||||
inline Gnuplot& operator<<(const std::string &cmdstr){
|
||||
inline Gnuplot& operator<<(const std::string &cmdstr)
|
||||
{
|
||||
cmd(cmdstr);
|
||||
return(*this);
|
||||
}
|
||||
@ -270,9 +274,9 @@ public:
|
||||
Gnuplot& set_pointsize(const double pointsize = 1.0);
|
||||
|
||||
/// turns grid on/off
|
||||
inline Gnuplot& set_grid() {cmd("set grid");return *this;};
|
||||
inline Gnuplot& set_grid() {cmd("set grid"); return *this;};
|
||||
/// grid is not set by default
|
||||
inline Gnuplot& unset_grid(){cmd("unset grid");return *this;};
|
||||
inline Gnuplot& unset_grid(){cmd("unset grid"); return *this;};
|
||||
|
||||
// -----------------------------------------------
|
||||
/// set the mulitplot mode
|
||||
@ -281,7 +285,7 @@ public:
|
||||
///
|
||||
/// \return <-- reference to the gnuplot object
|
||||
// -----------------------------------------------
|
||||
inline Gnuplot& set_multiplot(){cmd("set multiplot") ;return *this;};
|
||||
inline Gnuplot& set_multiplot(){cmd("set multiplot") ; return *this;};
|
||||
|
||||
// -----------------------------------------------
|
||||
/// unsets the mulitplot mode
|
||||
@ -290,7 +294,7 @@ public:
|
||||
///
|
||||
/// \return <-- reference to the gnuplot object
|
||||
// -----------------------------------------------
|
||||
inline Gnuplot& unset_multiplot(){cmd("unset multiplot");return *this;};
|
||||
inline Gnuplot& unset_multiplot(){cmd("unset multiplot"); return *this;};
|
||||
|
||||
/// set sampling rate of functions, or for interpolating data
|
||||
Gnuplot& set_samples(const int samples = 100);
|
||||
@ -304,7 +308,7 @@ public:
|
||||
///
|
||||
/// \return <-- reference to the gnuplot object
|
||||
// --------------------------------------------------------------------------
|
||||
Gnuplot& set_hidden3d(){cmd("set hidden3d");return *this;};
|
||||
Gnuplot& set_hidden3d(){cmd("set hidden3d"); return *this;};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/// hidden3d is not set by default
|
||||
@ -325,7 +329,7 @@ public:
|
||||
///
|
||||
/// \return <-- reference to the gnuplot object
|
||||
// ------------------------------------------------------------------
|
||||
inline Gnuplot& unset_contour(){cmd("unset contour");return *this;};
|
||||
inline Gnuplot& unset_contour(){cmd("unset contour"); return *this;};
|
||||
|
||||
// ------------------------------------------------------------
|
||||
/// enables/disables the display of surfaces (for 3d plot)
|
||||
@ -334,7 +338,7 @@ public:
|
||||
///
|
||||
/// \return <-- reference to the gnuplot object
|
||||
// ------------------------------------------------------------------
|
||||
inline Gnuplot& set_surface(){cmd("set surface");return *this;};
|
||||
inline Gnuplot& set_surface(){cmd("set surface"); return *this;};
|
||||
|
||||
// ----------------------------------------------------------
|
||||
/// surface is set by default,
|
||||
@ -386,7 +390,7 @@ public:
|
||||
///
|
||||
/// \return <-- reference to the gnuplot object
|
||||
// ---------------------------------------------------------------------------------
|
||||
inline Gnuplot& unset_title(){this->set_title();return *this;}
|
||||
inline Gnuplot& unset_title(){this->set_title(); return *this;}
|
||||
|
||||
/// set x axis label
|
||||
Gnuplot& set_ylabel(const std::string &label = "x");
|
||||
@ -396,21 +400,19 @@ public:
|
||||
Gnuplot& set_zlabel(const std::string &label = "z");
|
||||
|
||||
/// set axis - ranges
|
||||
Gnuplot& set_xrange(const double iFrom,
|
||||
const double iTo);
|
||||
Gnuplot& set_xrange(const double iFrom, const double iTo);
|
||||
/// set y-axis - ranges
|
||||
Gnuplot& set_yrange(const double iFrom,
|
||||
const double iTo);
|
||||
Gnuplot& set_yrange(const double iFrom, const double iTo);
|
||||
/// set z-axis - ranges
|
||||
Gnuplot& set_zrange(const double iFrom,
|
||||
const double iTo);
|
||||
Gnuplot& set_zrange(const double iFrom, const double iTo);
|
||||
|
||||
/// autoscale axis (set by default) of xaxis
|
||||
///
|
||||
/// \param ---
|
||||
///
|
||||
/// \return <-- reference to the gnuplot object
|
||||
// -----------------------------------------------
|
||||
inline Gnuplot& set_xautoscale(){cmd("set xrange restore");cmd("set autoscale x");return *this;};
|
||||
inline Gnuplot& set_xautoscale(){cmd("set xrange restore"); cmd("set autoscale x"); return *this;};
|
||||
|
||||
// -----------------------------------------------
|
||||
/// autoscale axis (set by default) of yaxis
|
||||
@ -419,7 +421,7 @@ public:
|
||||
///
|
||||
/// \return <-- reference to the gnuplot object
|
||||
// -----------------------------------------------
|
||||
inline Gnuplot& set_yautoscale(){cmd("set yrange restore");cmd("set autoscale y");return *this;};
|
||||
inline Gnuplot& set_yautoscale(){cmd("set yrange restore"); cmd("set autoscale y"); return *this;};
|
||||
|
||||
// -----------------------------------------------
|
||||
/// autoscale axis (set by default) of zaxis
|
||||
@ -428,7 +430,7 @@ public:
|
||||
///
|
||||
/// \return <-- reference to the gnuplot object
|
||||
// -----------------------------------------------
|
||||
inline Gnuplot& set_zautoscale(){cmd("set zrange restore");cmd("set autoscale z");return *this;};
|
||||
inline Gnuplot& set_zautoscale(){cmd("set zrange restore"); cmd("set autoscale z"); return *this;};
|
||||
|
||||
/// turns on/off log scaling for the specified xaxis (logscale is not set by default)
|
||||
Gnuplot& set_xlogscale(const double base = 10);
|
||||
@ -531,13 +533,11 @@ public:
|
||||
/// special functions: erf(x), erfc(x), inverf(x), gamma(x), igamma(a,x), lgamma(x), ibeta(p,q,x),
|
||||
/// besj0(x), besj1(x), besy0(x), besy1(x), lambertw(x)
|
||||
/// statistical fuctions: norm(x), invnorm(x)
|
||||
Gnuplot& plot_equation(const std::string &equation,
|
||||
const std::string &title = "");
|
||||
Gnuplot& plot_equation(const std::string &equation, const std::string &title = "");
|
||||
|
||||
/// plot an equation supplied as a std::string z=f(x,y), write only the function f(x,y) not z=
|
||||
/// the independent variables have to be x and y
|
||||
Gnuplot& plot_equation3d(const std::string &equation,
|
||||
const std::string &title = "");
|
||||
Gnuplot& plot_equation3d(const std::string &equation, const std::string &title = "");
|
||||
|
||||
/// plot image
|
||||
Gnuplot& plot_image(const unsigned char *ucPicBuf,
|
||||
@ -554,7 +554,7 @@ public:
|
||||
///
|
||||
/// \return ---
|
||||
//----------------------------------------------------------------------------------
|
||||
inline Gnuplot& replot(void){if (nplots > 0) cmd("replot");return *this;};
|
||||
inline Gnuplot& replot(void){if (nplots > 0) cmd("replot"); return *this;};
|
||||
|
||||
/// resets a gnuplot session (next plot will erase previous ones)
|
||||
Gnuplot& reset_plot();
|
||||
@ -604,7 +604,7 @@ std::string Gnuplot::terminal_std = "aqua";
|
||||
// constructor: set a style during construction
|
||||
//
|
||||
inline Gnuplot::Gnuplot(const std::string &style)
|
||||
:gnucmd(NULL) ,valid(false) ,two_dim(false) ,nplots(0)
|
||||
:gnucmd(NULL), valid(false), two_dim(false), nplots(0)
|
||||
|
||||
{
|
||||
init();
|
||||
@ -621,7 +621,7 @@ inline Gnuplot::Gnuplot(const std::vector<double> &x,
|
||||
const std::string &style,
|
||||
const std::string &labelx,
|
||||
const std::string &labely)
|
||||
:gnucmd(NULL) ,valid(false) ,two_dim(false) ,nplots(0)
|
||||
:gnucmd(NULL), valid(false), two_dim(false), nplots(0)
|
||||
{
|
||||
init();
|
||||
|
||||
@ -643,7 +643,7 @@ inline Gnuplot::Gnuplot(const std::vector<double> &x,
|
||||
const std::string &style,
|
||||
const std::string &labelx,
|
||||
const std::string &labely)
|
||||
:gnucmd(NULL) ,valid(false) ,two_dim(false) ,nplots(0)
|
||||
:gnucmd(NULL), valid(false), two_dim(false), nplots(0)
|
||||
{
|
||||
init();
|
||||
|
||||
@ -667,7 +667,7 @@ inline Gnuplot::Gnuplot(const std::vector<double> &x,
|
||||
const std::string &labelx,
|
||||
const std::string &labely,
|
||||
const std::string &labelz)
|
||||
:gnucmd(NULL) ,valid(false) ,two_dim(false) ,nplots(0)
|
||||
:gnucmd(NULL), valid(false), two_dim(false), nplots(0)
|
||||
{
|
||||
init();
|
||||
|
||||
@ -844,7 +844,6 @@ Gnuplot& Gnuplot::plot_xyz(const X &x,
|
||||
//
|
||||
bool Gnuplot::set_GNUPlotPath(const std::string &path)
|
||||
{
|
||||
|
||||
std::string tmp = path + "/" + Gnuplot::m_sGNUPlotFileName;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
|
||||
|
42
src/tests/common-files/test_flags.h
Normal file
42
src/tests/common-files/test_flags.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*!
|
||||
* \file test_flags.h
|
||||
* \brief Helper file for unit testing
|
||||
* \author Carles Fernandez-Prades, 2017. cfernandez(at)cttc.es
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors)
|
||||
*
|
||||
* GNSS-SDR is a software defined Global Navigation
|
||||
* Satellite Systems receiver
|
||||
*
|
||||
* This file is part of GNSS-SDR.
|
||||
*
|
||||
* GNSS-SDR is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GNSS-SDR is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef GNSS_SDR_TEST_FLAGS_H_
|
||||
#define GNSS_SDR_TEST_FLAGS_H_
|
||||
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
#if defined GNUPLOT_EXECUTABLE
|
||||
DEFINE_string(gnuplot_executable, std::string(GNUPLOT_EXECUTABLE), "Gnuplot binary path");
|
||||
#elif !defined GNUPLOT_EXECUTABLE
|
||||
DEFINE_string(gnuplot_executable, "", "Gnuplot binary path");
|
||||
#endif
|
||||
|
||||
#endif
|
@ -35,14 +35,8 @@
|
||||
#include <random>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <gnuradio/fft/fft.h>
|
||||
|
||||
|
||||
#if defined GNUPLOT_EXECUTABLE
|
||||
#include "gnuplot_i.h"
|
||||
const bool exists_gnuplot_fft_test_length = true;
|
||||
#elif !defined GNUPLOT_EXECUTABLE
|
||||
const bool exists_gnuplot_fft_test_length = false;
|
||||
#endif
|
||||
#include "gnuplot_i.h"
|
||||
#include "test_flags.h"
|
||||
|
||||
|
||||
DEFINE_int32(fft_iterations_test, 1000, "Number of averaged iterations in FFT length timing test");
|
||||
@ -108,7 +102,8 @@ TEST(FFTLengthTest, MeasureExecutionTime)
|
||||
|
||||
if(FLAGS_plot_fft_length_test == true)
|
||||
{
|
||||
if(!exists_gnuplot_fft_test_length)
|
||||
const std::string gnuplot_executable(FLAGS_gnuplot_executable);
|
||||
if(gnuplot_executable.empty())
|
||||
{
|
||||
std::cout << "WARNING: Although the flag plot_fft_length_test has been set to TRUE," << std::endl;
|
||||
std::cout << "gnuplot has not been found in your system." << std::endl;
|
||||
@ -116,10 +111,8 @@ TEST(FFTLengthTest, MeasureExecutionTime)
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined GNUPLOT_EXECUTABLE
|
||||
try
|
||||
{
|
||||
std::string gnuplot_executable = std::string(GNUPLOT_EXECUTABLE);
|
||||
boost::filesystem::path p(gnuplot_executable);
|
||||
boost::filesystem::path dir = p.parent_path();
|
||||
std::string gnuplot_path = dir.native();
|
||||
@ -150,7 +143,6 @@ TEST(FFTLengthTest, MeasureExecutionTime)
|
||||
{
|
||||
std::cout << ge.what() << std::endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user