C++ Gnuplot pipe input from C++ defined variables -


i using c++ pipe commands gnuplot using following code:

file *gnuplotpipe = popen("gnuplot -persist", "w");  // open pipe gnuplot  if (gnuplotpipe) {   // if gnuplot found    fprintf(gnuplotpipe, "reset\n"); //gnuplot commands   fprintf(gnuplotpipe, "n='500'\n");   fprintf(gnuplotpipe, "max='1500'\n");   fprintf(gnuplotpipe, "min='-1500\n");   fprintf(gnuplotpipe, "width=(max-min)/n\n");   fprintf(gnuplotpipe, "hist(x,width)=width*floor(x/width)+width/2.0\n");   fprintf(gnuplotpipe, "set term png #output terminal , file\n");   fprintf(gnuplotpipe, "set output 'observable_histogram.png'\n");   fprintf(gnuplotpipe, "set xrange [min:max]\n");   fprintf(gnuplotpipe, "set yrange [0:]\n");   fprintf(gnuplotpipe, "set offset graph 0.05,0.05,0.05,0.0\n");   fprintf(gnuplotpipe, "set xtics min,(max-min)/5,max\n");   fprintf(gnuplotpipe, "set boxwidth width*0.9\n");   fprintf(gnuplotpipe, "set style fill solid 0.5\n");   fprintf(gnuplotpipe, "set tics out nomirror\n");   fprintf(gnuplotpipe, "set xlabel 'observable'\n");   fprintf(gnuplotpipe, "set ylabel 'counts'\n");   fprintf(gnuplotpipe, "set title 'observable'\n");   fprintf(gnuplotpipe, "plot 'output.txt' u (hist($1,width)):(1.0) smooth freq w boxes lc rgb'green' notitle\n");    fflush(gnuplotpipe); //flush pipe    fprintf(gnuplotpipe,"exit \n");   // exit gnuplot   pclose(gnuplotpipe);    //close pipe  } 

this works perfectly, want able take input defined variables in c++.
example, instead of straight defining n='500', min='-1500', max='1500', etc., want use variables defined (from user input) earlier in code, i.e. int n, int max, int min, string title, string xlabel, etc.

i have tried can think of, such as:

fprintf(gnuplotpipe, "max="); fprintf(gnuplotpipe, 'max'); 

or:

fprintf(gnuplotpipe, "max=" 'max' "\n"); 

and nothing works unfortunately.

does have ideas on how working?

thanks in advance!

the thing want fprintf() for, see manual. here example:

int maximum = 500; // taken user input maybe fprintf(gnuplotpipe, "max=%d\n", maximum); 

you're using fprintf() in way of more simple fputs().


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -