|
From: Bret F. <bre...@or...> - 2004-10-05 21:34:47
|
I did something similar from PERL. The hitch is that the pipe is buffered.
You can flush the pipe, but that only flushes the pipe's input, not it's
output. So gnuplot waits forever. My workaround was to call gnuplot in a
mode where it exits when it's done, using a file for the data and most of
the commands, rather than piping everything in. This requires a temp file,
of course, but you can re-use the same one if you don't plan on multiple
users of your app.
Bret
-----Original Message-----
From: gnu...@li...
[mailto:gnu...@li...]On Behalf Of Levinthal,
David A
Sent: Tuesday, October 05, 2004 2:20 PM
To: gnu...@li...
Subject: [Gnuplot-info] How do I get gnuplot to exit, when it has been
opened through a pipe from within an application?
I can't figure out how to get the gnuplot process to terminate at the end
of my application..The x window remains open and the process hangs at the
end.. the fprintf's to stderr seem to imply all is well..but the xwindow is
persistant and the application cannot exit
Note: that I need to have the plots stay there during execution, without
having to put the application in a sleep state..(The display is of a
numerical solution converging..)
??
d
Gnuplot is being invoked with:
if((gplot == 1) && (current_processor == 0)){
// Gnuplot initialization
fgnuplot = popen("/usr/bin/gnuplot -persist",
"w");
if (fgnuplot == NULL) {
fprintf(stderr, "popen call failed!, unable
to start gnuplot");
} else {
// initial settings
fprintf(fgnuplot, "set data style
lines\n");
fprintf(fgnuplot, "set hidden3d\n");
fprintf(fgnuplot, "set contour
base\n");
fprintf(fgnuplot, "set
zrange[-20:20]\n");
fflush(fgnuplot);
}
}
And then all sorts of attempts at killing it off seem to fail???
if ((gplot == 1) && fgnuplot) {
// Gather results
for(iproc=0; iproc <
number_of_processors; iproc++)
for ( i = 0 ; i < plrows ; i++ )
for ( j = 0 ; j < PLOTDIM
; j++ )
plot[i +
iproc*plrows][j] = result[i*iplstride+iplstart[0]+nrows*iproc][j*jplstride +
jplstart];
fprintf(stderr,"gathered plot\n");
save2DArray(plot, PLOTDIM,PLOTDIM, 1,
1, "fout.dat");
fprintf(fgnuplot, "set title
\"Converged in %d iterations\"\n", k);
fprintf(fgnuplot, "splot 'fout.dat'
matrix\n");
fflush(fgnuplot);
// wait for gnuplot to exit
fclose(fgnuplot);
// wait(&rc);
printf("root node: finished\n");
}
Or
if ((gplot == 1) && fgnuplot) {
printf(" in plotting section on root
node\n");
// Gather results
for(iproc=0; iproc <
number_of_processors; iproc++)
for ( i = 0 ; i < plrows ; i++ )
for ( j = 0 ; j < PLOTDIM
; j++ )
plot[i +
iproc*plrows][j] = result[i*iplstride+iplstart[0]+nrows*iproc][j*jplstride +
jplstart];
fprintf(stderr,"gathered plot\n");
save2DArray(plot, PLOTDIM,PLOTDIM, 1,
1, "fout.dat");
fprintf(fgnuplot, "set title
\"Converged in %d iterations\"\n", k);
fprintf(fgnuplot, "splot 'fout.dat'
matrix\n");
fprintf(stderr, "finished final
fprintf(fgnuplot \n");
fflush(fgnuplot);
fprintf(stderr, "finished final
fflush\n");
fprintf(fgnuplot, " quit\n");
fprintf(fgnuplot, " exit\n");
// wait for gnuplot to exit
wait(&rc);
fprintf(stderr, "finished wait =
%i\n", rc);
pstatus = pclose(fgnuplot);
fprintf(stderr, "finished plcose =
%i\n", pstatus);
printf("root node: finished\n");
}
|