39 #define round( value ) floor( value + 0.5 ) 126 gnuPipe = popen(
"gnuplot -persist -background white",
"w");
168 mouseX = tmp( tmp.
getDim()-2 );
169 mouseY = tmp( tmp.
getDim()-1 );
171 if ( system(
"rm mouse.dat") )
187 check = fopen(
"mouse.dat",
"r" );
193 if (system(
"rm mouse.dat") )
197 fprintf(
gnuPipe,
"pause mouse\n");
199 fprintf(
gnuPipe,
"a = MOUSE_X \n");
201 fprintf(
gnuPipe,
"b = MOUSE_Y \n");
203 fprintf(
gnuPipe,
"save var 'mouse.dat'\n");
224 #ifndef __NO_PLOTTING__ 229 gnuPipe = fopen(
"acado2gnuplot_tmp.dat",
"w" );
231 uint run1, run2, run3, run4;
280 Grid discretizationGrid;
284 string plotDataString;
285 string userDataString;
286 string plotModeString;
287 string plotStyleString;
291 fprintf(
gnuPipe,
"set multiplot;\n" );
294 for( run3 = 0; run3<nRows; run3++ )
296 for( run2 = 0; run2<nCols; run2++ )
300 discretizationGrid.
init( );
303 switch (
operator()(run1).getSubPlotType( ) )
319 dataGrid = dataGridX;
330 dataGrid = dataGridX;
352 dataGrid = dataGridX;
363 dataGrid = dataGridX;
373 dataGrid = dataMatrixGrid;
382 fprintf(
gnuPipe,
" set size %.16e,%.16e;\n", (1.0 /nCols), (1.0 /nRows) );
383 fprintf(
gnuPipe,
" set origin %.16e,%.16e;\n", (
double) run2/((
double) nCols),
384 (
double) (nRows-1-run3)/((
double) nRows) );
387 if (
operator()( run1 ).title.empty() == false )
388 fprintf(
gnuPipe,
" set title '%s'\n",
operator()( run1 ).title.c_str() );
390 fprintf(
gnuPipe,
" set title ' '\n" );
393 if (
operator()( run1 ).xLabel.empty() == false )
394 fprintf(
gnuPipe,
" set xlabel '%s'\n",
operator()( run1 ).xLabel.c_str() );
396 fprintf(
gnuPipe,
" set xlabel ' '\n" );
398 if (
operator()( run1 ).yLabel.empty() == false )
399 fprintf(
gnuPipe,
" set ylabel '%s'\n",
operator()( run1 ).yLabel.c_str() );
401 fprintf(
gnuPipe,
" set ylabel ' '\n" );
406 fprintf(
gnuPipe,
" set xrange [%.16e:%.16e]\n",
operator()( run1 ).xRangeLowerLimit,
operator()( run1 ).xRangeUpperLimit );
410 fprintf(
gnuPipe,
" set autoscale x\n" );
416 fprintf(
gnuPipe,
" set yrange [%.16e:%.16e]\n",
operator()( run1 ).yRangeLowerLimit,
operator()( run1 ).yRangeUpperLimit );
420 if ( (
operator()( run1 ).nLines == 0 ) && (
operator()( run1 ).nData == 0 ) )
422 double lowerLimit, upperLimit;
424 fprintf(
gnuPipe,
" set yrange [%.16e:%.16e]\n", lowerLimit, upperLimit );
428 fprintf(
gnuPipe,
" set autoscale y\n" );
432 if (
operator()( run1 ).getPlotFormat( ) ==
PF_LOG )
433 fprintf(
gnuPipe,
" set logscale y\n" );
435 if (
operator()( run1 ).plot3D ==
BT_FALSE )
441 if (
operator()( run1 ).nLines > 0 )
443 fprintf(
gnuPipe,
"%.16e title '' lt 2 lw 2,\\\n",
operator()( run1 ).lineValues[run4] );
449 switch (
operator()(run1).getSubPlotType( ) )
454 for( run4=0; run4<discretizationGrid.
getNumPoints()-2; ++run4 )
455 fprintf(
gnuPipe,
"'-' using 1:2 title '' with %s %s,\\\n", plotModeString.c_str(),plotStyleString.c_str() );
457 fprintf(
gnuPipe,
"'-' using 1:2 title '' with %s %s", plotModeString.c_str(),plotStyleString.c_str() );
465 for( run4=0; run4<discretizationGrid.
getNumPoints()-2; ++run4 )
466 fprintf(
gnuPipe,
"'-' using 2:3 title '' with %s %s,\\\n", plotModeString.c_str(),plotStyleString.c_str() );
468 fprintf(
gnuPipe,
"'-' using 2:3 title '' with %s %s", plotModeString.c_str(),plotStyleString.c_str() );
475 if(
operator()( run1 ).plot3D ==
BT_FALSE )
480 for( run4=0; run4<discretizationGrid.
getNumPoints()-2; ++run4 )
481 fprintf(
gnuPipe,
"'-' using 1:2 title '' with %s %s,\\\n", plotModeString.c_str(),plotStyleString.c_str() );
483 fprintf(
gnuPipe,
"'-' using 1:2 title '' with %s %s", plotModeString.c_str(),plotStyleString.c_str() );
490 fprintf(
gnuPipe,
"'-' title '' with %s", plotModeString.c_str() );
495 fprintf(
gnuPipe,
"'-' using 1:2 title '' with %s %s", plotModeString.c_str(),plotStyleString.c_str() );
499 if (
operator()(run1).nData > 0 )
506 if( userDataString.empty() == false )
507 fprintf(
gnuPipe,
",\\\n'-' using 1:2 title '' with points lt 3 lw 3\n" );
519 fprintf(
gnuPipe,
"%s", plotDataString.c_str() );
526 dataGridTmp = dataGrid(run4);
531 fprintf(
gnuPipe,
"%s", plotDataString.c_str() );
538 uint startIdx,endIdx;
540 for( run4=0; run4<discretizationGrid.
getNumPoints()-1; ++run4 )
542 startIdx = (
uint)round( discretizationGrid.
getTime( run4 ) );
543 endIdx = (
uint)round( discretizationGrid.
getTime( run4+1 ) ) - 1;
550 fprintf(
gnuPipe,
"%s", plotDataString.c_str() );
555 if (
operator()( run1 ).getPlotFormat( ) ==
PF_LOG )
556 fprintf(
gnuPipe,
" unset logscale y\n" );
566 fprintf(
gnuPipe,
"unset multiplot\n" );
578 #if defined(GNUPLOT_EXECUTABLE) && defined(WIN32) 579 string tmp = string(
"\"") + string( GNUPLOT_EXECUTABLE ) + string(
"\" -p acado2gnuplot_tmp.dat");
581 if ( system( tmp.c_str() ) )
584 if ( system(
"del acado2gnuplot_tmp.dat") )
587 if ( system(
"gnuplot -persist -background white acado2gnuplot_tmp.dat") )
589 if (system(
"rm -rf acado2gnuplot_tmp.dat") )
598 fprintf(
gnuPipe,
"pause mouse\n");
601 fprintf(
gnuPipe,
"a = MOUSE_X \n");
604 fprintf(
gnuPipe,
"b = MOUSE_Y \n");
607 fprintf(
gnuPipe,
"save var 'mouse.dat'\n");
611 #endif // __NO_PLOTTING__ 618 std::string& plotModeString
624 plotModeString =
"lines lw 2.5";
628 plotModeString =
"points pt 2.5";
632 plotModeString =
"lines lw 2.5";
640 std::string& plotStyleString
646 plotStyleString =
"lt -1";
650 plotStyleString =
"lt 4";
654 plotStyleString =
"lt 8";
658 plotStyleString =
"lt 3";
662 plotStyleString =
"lt 5";
666 plotStyleString =
"lt 2";
671 plotStyleString =
"lt 1";
679 std::string& _plotDataString
686 _plotDataString = ss.str();
double getTime(uint pointIdx) const
uint getNumSubplots() const
returnValue getPlotModeString(PlotMode plotMode, std::string &plotModeString) const
returnValue waitForMouseEvent(double &mouseX, double &mouseY)
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Allows to pass back messages to the calling function.
virtual returnValue init()
LogName convertPlotToLogName(PlotName _name) const
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
returnValue getVariableDataGrids(const Expression *const variable, VariableType &_type, VariablesGrid &_dataGrid, Grid &_discretizationGrid)
Allows to conveniently handle (one-dimensional) grids consisting of time points.
virtual PlotWindow * clone() const
#define CLOSE_NAMESPACE_ACADO
returnValue sprint(std::ostream &stream)
returnValue appendValues(const VariablesGrid &arg)
Allows to setup and plot user-specified plot windows for algorithmic outputs.
returnValue getExpressionDataGrids(const Expression *const expression, VariableType &_type, VariablesGrid &_dataGrid, Grid &_discretizationGrid)
PlotWindow & operator=(const PlotWindow &rhs)
Provides a time grid consisting of matrix-valued optimization variables at each grid point...
returnValue waitForMouseEvents()
GnuplotWindow & operator=(const GnuplotWindow &arg)
VariablesGrid getTimeSubGrid(uint startIdx, uint endIdx) const
returnValue init(uint _nPoints=0, const double *const _times=0)
VariableType getYVariableType() const
returnValue obtainPlotDataString(VariablesGrid &_dataGrid, std::string &_plotDataString) const
BooleanType acadoIsFinite(double x, double TOL)
uint getNumPoints() const
#define ACADOWARNING(retval)
#define BEGIN_NAMESPACE_ACADO
returnValue sendDataToGnuplot()
PlotFrequency getPlotFrequency() const
virtual returnValue replot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
returnValue getDataGrids(const VariablesGrid *const variablesGrid, VariableType &_type, VariablesGrid &_dataGrid, Grid &_discretizationGrid)
returnValue getAll(LogName _name, MatrixVariablesGrid &values) const
Provides an interface to Gnuplot for plotting algorithmic outputs.
uint getNumValues() const
BooleanType getMouseEvent(double &mouseX, double &mouseY)
#define ACADOERROR(retval)
PlotWindowSubplot & operator()(uint idx)
returnValue getPlotStyleString(VariableType _type, std::string &plotStyleString) const
virtual returnValue read(std::istream &stream)
returnValue getAutoScaleYLimits(const VariablesGrid &dataGridY, PlotFormat plotFormat, double &lowerLimit, double &upperLimit) const