missing pdf terminal; was --> [changeset] print.m (matlab compatibility)

Ben Abbott bpabbott at mac.com
Sat Mar 21 12:38:15 CDT 2009


On Mar 13, 2009, at 5:26 AM, Ben Abbott wrote:

> On Mar 13, 2009, at 3:58 PM, Ben Abbott wrote:
>
>> On Mar 13, 2009, at 3:41 PM, John W. Eaton wrote:
>>
>>> 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?
>>
>> Ok, that is a problem.
>>
>> octave:62> close all
>> octave:63> figure (1); axes (); set (gcf, "visible", "off"); print  
>> (gcf, "-dpng", "test.png")
>> ans = [](0x0)
>> plot_stream =  4
>>
>> How to proceed?
>>
>> Shall the  check that the device/terminal availability only be made  
>> when numel(__plot_stream__) == 2?
>>
>> or, should we just use popen2 in all cases, and add the terminal  
>> check immediately after opening it?
>>
>> Ben
>
> John/others,
>
> Does this work for you?
>
> If your gnuplot was built without pdf support, the line below should  
> throw an error.
>
> 	close all; figure (1); axes (); print (gcf, "-dpdf", "test.pdf")
>
> But this one should work
>
> 	close all; figure (1); axes (); print (gcf, "-dpng", "test.png")
>
> and the one below should produce the png without displaying the  
> figure.
>
> 	close all; figure (1, "visible", "off"); axes (); print (gcf, "- 
> dpng", "test.png")
>
> Ben
>
> <changeset-gp_get_var-and-check_for_term.patch>

As I've not encountered any trouble with these changes, and intend to  
use the new function __gnuplot_get_var__ for other purposes, I've  
pushed this changeset (with some small modication).

Next, I'll attempt to handle a proper substitution for fonts named "*".

Ben



More information about the Octave-maintainers mailing list