Thursday, May 14, 2009

How to Call Gnuplot from c Using Pipes (Windows)

Try this:

// Open a pipe to gnuplot
FILE *gnuplotPipe = popen("c:\\gnuplot\\bin\\pgnuplot -persist","w");
// If gnuplot is found
if (gnuplotPipe) {
// using fprintf on the gnuplotPipe, we can directly issue commands in gnuplot
fprintf(gnuplotPipe, "set style data lines\n");
fprintf(gnuplotPipe, "cd 'C:\\gnuplot\\bin'\n");
// assuming your data file is placed in the gnuplot bin directory
fprintf(gnuplotPipe, "plot \"data-file.dat\" using 1:2\n");
fflush(gnuplotPipe);
fprintf(stderr,"Press enter to continue...");
fflush(stderr);
getchar();
// exit gnuplot
fprintf(gnuplotPipe,"exit \n");
pclose(gnuplotPipe);
}


Cite as:
Saad, T. "How to Call Gnuplot from c Using Pipes (Windows)." Weblog entry from Please Make A Note. http://pleasemakeanote.blogspot.com/2009/05/how-to-call-gnuplot-from-c-using-pipes.html


Stumble Upon Toolbar

0 comments: