On 13-Mar-2009, Ben Abbott wrote:
| On Mar 13, 2009, at 2:43 PM, John W. Eaton wrote:
|
| > On 13-Mar-2009, Ben Abbott wrote:
| >
| > | I don' t think it matters either way. __gnuplot_get_var__
uses the
| > | stream stored in the figure's "__plot_stream__" which is
opened by
| > | popen2.
| >
| > If there is only one stream (i.e., we are using popen instead of
| > popen2), then the communication can only be one way (from
Octave to
| > gnuplot). So in that case how would you get the information
back from
| > gnuplot without a FIFO file to use as a separate communication
| > channel?
| >
| > jwe
|
|
| The reason is that the figure property __plot_stream__ is opened
using
| popen2, and must exist (I think, so correct me if I'm wrong) when
the
| popen plot stream used for printing is opened.
|
| To verify my understanding, I added the lines below (42-44) to
| gnuplot_drawnow.m
|
| 30 function gnuplot_drawnow (h, term, file, mono, debug_file)
| 31
| 32 if (nargin < 4)
| 33 mono = false;
| 34 endif
| 35
| 36 if (nargin >= 3 && nargin <= 5)
| 37 ## Produce various output formats, or redirect gnuplot
stream
| to a
| 38 ## debug file.
| 39 plot_stream = [];
| 40 fid = [];
| 41 printing = ! output_to_screen (gnuplot_trim_term (term));
| 42 if (printing)
| 43 get (h, "__plot_stream__")
| 44 endif
|
| Typing the following at the prompt results in
|
| close all;
| drawnow
| figure (1); print (gcf, "-dpng", "test.png")
| ans =
|
| 4 5
|
| In addiition, by adding line 111 to gnuplot_drawnow
| (open_gnuplot_stream), it appears to me that the popen2 stream
for the
| display must be open prior to the popen stream used for printing.
|
| 95 function plot_stream = open_gnuplot_stream (npipes, h)
| 96 cmd = gnuplot_binary ();
| 97 if (npipes > 1)
| 98 [plot_stream(1), plot_stream(2), pid] = popen2 (cmd);
| 99 if (pid < 0)
| 100 error ("drawnow: failed to open connection to gnuplot");
| 101 endif
| 102 else
| 103 plot_stream = popen (cmd, "w");
| 104 if (plot_stream < 0)
| 105 error ("drawnow: failed to open connection to gnuplot");
| 106 endif
| 107 endif
| 108 if (! isempty (h))
| 109 set (h, "__plot_stream__", plot_stream);
| 110 endif
| 111 fprintf ("plot_stream = "); disp (plot_stream)
| 112 endfunction
|
| octave:49> close all
| octave:50> drawnow
| octave:51> figure (1); print (gcf, "-dpng", "test.png")
| plot_stream = 4 5
| ans =
|
| 4 5
|
| plot_stream = 6
|
| I have no idea why popen is used instead of popen2.
I think the idea was to avoid using popen2 unless it was actually
needed.
| In any event, is this not working as it is supposed to? ...
meaning is
| it supposed to be possible to open a plot stream for printing and
| avoid opening one for the display?
Yes. What does
figure (1, 'visible', 'off');
plot (...);
print ....
do?