Mercurial > hg > octave-nkf
comparison scripts/plot/gnuplot_drawnow.m @ 7680:a0ec02774303
Use popen2 for communication with gnuplot
author | David Bateman <dbateman@free.fr> |
---|---|
date | Wed, 02 Apr 2008 13:29:19 -0400 |
parents | 246f905cb984 |
children | 1f429086565c |
comparison
equal
deleted
inserted
replaced
7679:3c16e2414564 | 7680:a0ec02774303 |
---|---|
36 if (nargin >= 3 && nargin <= 5) | 36 if (nargin >= 3 && nargin <= 5) |
37 f = __get__ (h); | 37 f = __get__ (h); |
38 plot_stream = []; | 38 plot_stream = []; |
39 fid = []; | 39 fid = []; |
40 unwind_protect | 40 unwind_protect |
41 [plot_stream, enhanced] = open_gnuplot_stream ([], term, file); | 41 [plot_stream, enhanced] = open_gnuplot_stream (1, [], term, file); |
42 __go_draw_figure__ (f, plot_stream, enhanced, mono); | 42 __go_draw_figure__ (f, plot_stream, enhanced, mono); |
43 if (nargin == 5) | 43 if (nargin == 5) |
44 fid = fopen (debug_file, "wb"); | 44 fid = fopen (debug_file, "wb"); |
45 enhanced = init_plot_stream (fid, [], term, file); | 45 enhanced = init_plot_stream (fid, [], term, file); |
46 __go_draw_figure__ (f, fid, enhanced, mono); | 46 __go_draw_figure__ (f, fid, enhanced, mono); |
55 end_unwind_protect | 55 end_unwind_protect |
56 elseif (nargin == 1) | 56 elseif (nargin == 1) |
57 f = __get__ (h); | 57 f = __get__ (h); |
58 plot_stream = f.__plot_stream__; | 58 plot_stream = f.__plot_stream__; |
59 if (isempty (plot_stream)) | 59 if (isempty (plot_stream)) |
60 [plot_stream, enhanced] = open_gnuplot_stream (h); | 60 [plot_stream, enhanced] = open_gnuplot_stream (2, h); |
61 set (h, "__enhanced__", enhanced); | 61 set (h, "__enhanced__", enhanced); |
62 else | 62 else |
63 enhanced = f.__enhanced__; | 63 enhanced = f.__enhanced__; |
64 endif | 64 endif |
65 __go_draw_figure__ (f, plot_stream, enhanced, mono); | 65 __go_draw_figure__ (f, plot_stream (1), enhanced, mono); |
66 fflush (plot_stream (1)); | |
66 else | 67 else |
67 print_usage (); | 68 print_usage (); |
68 endif | 69 endif |
69 | 70 |
70 endfunction | 71 endfunction |
71 | 72 |
72 function [plot_stream, enhanced] = open_gnuplot_stream (h, varargin) | 73 function [plot_stream, enhanced] = open_gnuplot_stream (npipes, h, varargin) |
73 | 74 |
74 cmd = gnuplot_binary (); | 75 cmd = gnuplot_binary (); |
75 | 76 |
76 plot_stream = popen (cmd, "w"); | 77 if (npipes > 1) |
78 [plot_stream(1), plot_stream(2), pid] = popen2 (cmd); | |
79 if (pid < 0) | |
80 error ("drawnow: failed to open connection to gnuplot"); | |
81 endif | |
82 else | |
83 plot_stream = popen (cmd, "w"); | |
84 if (plot_stream < 0) | |
85 error ("drawnow: failed to open connection to gnuplot"); | |
86 endif | |
87 endif | |
77 | 88 |
78 if (plot_stream < 0) | 89 if (! isempty (h)) |
79 error ("drawnow: failed to open connection to gnuplot"); | 90 set (h, "__plot_stream__", plot_stream); |
80 else | 91 endif |
81 | 92 |
82 if (! isempty (h)) | 93 enhanced = init_plot_stream (plot_stream (1), h, varargin{:}); |
83 set (h, "__plot_stream__", plot_stream); | |
84 endif | |
85 | |
86 enhanced = init_plot_stream (plot_stream, h, varargin{:}); | |
87 | |
88 endif | |
89 | 94 |
90 endfunction | 95 endfunction |
91 | 96 |
92 function enhanced = init_plot_stream (plot_stream, h, term, file) | 97 function enhanced = init_plot_stream (plot_stream, h, term, file) |
93 | 98 |