comparison scripts/plot/gnuplot_drawnow.m @ 12103:a14e15613509 release-3-2-x

gnuplot_drawnow.m: Support gnuplot's dumb terminal.
author Ben Abbott <bpabbott@mac.com>
date Tue, 24 Nov 2009 08:02:08 +0100
parents 52d8ad5d28d6
children
comparison
equal deleted inserted replaced
12102:52d8ad5d28d6 12103:a14e15613509
85 plot_stream = __gnuplot_open_stream__ (2, h); 85 plot_stream = __gnuplot_open_stream__ (2, h);
86 new_stream = true; 86 new_stream = true;
87 else 87 else
88 new_stream = false; 88 new_stream = false;
89 endif 89 endif
90 enhanced = gnuplot_set_term (plot_stream (1), new_stream, h); 90 term = gnuplot_default_term ();
91 if (strcmp (term, "dumb"))
92 ## popen2 eats stdout of gnuplot, use temporary file instead
93 dumb_tmp_file = tmpnam ();
94 enhanced = gnuplot_set_term (plot_stream (1), new_stream, h, ...
95 term, dumb_tmp_file);
96 else
97 enhanced = gnuplot_set_term (plot_stream (1), new_stream, h, term);
98 end
91 __go_draw_figure__ (h, plot_stream (1), enhanced, mono, 0); 99 __go_draw_figure__ (h, plot_stream (1), enhanced, mono, 0);
92 fflush (plot_stream (1)); 100 fflush (plot_stream (1));
101 if (strcmp (term, "dumb"))
102 fid = -1;
103 while (fid < 0)
104 pause (0.1);
105 fid = fopen (dumb_tmp_file, 'r');
106 endwhile
107 ## reprint the plot on screen
108 [a, count] = fscanf (fid, '%c', Inf);
109 puts (a);
110 fclose (fid);
111 unlink (dumb_tmp_file);
112 endif
93 else 113 else
94 print_usage (); 114 print_usage ();
95 endif 115 endif
96 116
97 endfunction 117 endfunction
141 enh_str = ""; 161 enh_str = "";
142 endif 162 endif
143 163
144 if (! isempty (h) && isfigure (h)) 164 if (! isempty (h) && isfigure (h))
145 165
146 ## Generate gnuoplot title string for backend plot windows. 166 ## Generate gnuplot title string for backend plot windows.
147 if (output_to_screen (term)) 167 if (output_to_screen (term) && ~strcmp (term, "dumb"))
148 fig.numbertitle = get (h, "numbertitle"); 168 fig.numbertitle = get (h, "numbertitle");
149 fig.name = get (h, "name"); 169 fig.name = get (h, "name");
150 if (strcmpi (get (h, "numbertitle"), "on")) 170 if (strcmpi (get (h, "numbertitle"), "on"))
151 title_str = sprintf ("Figure %d", h); 171 title_str = sprintf ("Figure %d", h);
152 else 172 else
237 endif 257 endif
238 endif 258 endif
239 elseif (strncmpi (term, "aqua", 3)) 259 elseif (strncmpi (term, "aqua", 3))
240 ## Aqua has size, but the format is different. 260 ## Aqua has size, but the format is different.
241 size_str = sprintf ("size %d %d", gnuplot_size); 261 size_str = sprintf ("size %d %d", gnuplot_size);
262 elseif (strncmpi (term, "dumb", 3))
263 new_stream = 1;
264 if (~isempty (getenv ("COLUMNS")) && ~isempty (getenv ("LINES")))
265 ## Let dumb use full text screen size.
266 size_str = ["size ", getenv("COLUMNS"), " ", getenv("LINES")];
267 else
268 ## Use the gnuplot default.
269 size_str = "";
270 end
242 elseif (strncmpi (term, "fig", 3)) 271 elseif (strncmpi (term, "fig", 3))
243 ## Fig also has size, but the format is different. 272 ## Fig also has size, but the format is different.
244 size_str = sprintf ("size %.15g %.15g", gnuplot_size); 273 size_str = sprintf ("size %.15g %.15g", gnuplot_size);
245 elseif (any (strncmpi (term, {"corel", "hpgl"}, 3))) 274 elseif (any (strncmpi (term, {"corel", "hpgl"}, 3)))
246 ## The size for corel and hpgl are goes at the end (implicit). 275 ## The size for corel and hpgl are goes at the end (implicit).
288 endif 317 endif
289 ## Work around the gnuplot feature of growing the x11 window and 318 ## Work around the gnuplot feature of growing the x11 window and
290 ## flickering window (x11, windows, & wxt) when the mouse and 319 ## flickering window (x11, windows, & wxt) when the mouse and
291 ## multiplot are set in gnuplot. 320 ## multiplot are set in gnuplot.
292 fputs (plot_stream, "unset multiplot;\n"); 321 fputs (plot_stream, "unset multiplot;\n");
293 flickering_terms = {"x11", "windows", "wxt"}; 322 flickering_terms = {"x11", "windows", "wxt", "dumb"};
294 if (! any (strcmp (term, flickering_terms)) 323 if (! any (strcmp (term, flickering_terms))
295 || numel (findall (h, "type", "axes")) > 1 324 || numel (findall (h, "type", "axes")) > 1
296 || numel (findall (h, "type", "image")) > 0) 325 || numel (findall (h, "type", "image")) > 0)
297 fprintf (plot_stream, "%s\n", term_str); 326 fprintf (plot_stream, "%s\n", term_str);
298 if (nargin == 5) 327 if (nargin == 5)
312 else 341 else
313 ## gnuplot will pick up the GNUTERM environment variable itself 342 ## gnuplot will pick up the GNUTERM environment variable itself
314 ## so no need to set the terminal type if not also setting the 343 ## so no need to set the terminal type if not also setting the
315 ## figure title, enhanced mode, or position. 344 ## figure title, enhanced mode, or position.
316 endif 345 endif
317
318 346
319 endfunction 347 endfunction
320 348
321 function term = gnuplot_default_term () 349 function term = gnuplot_default_term ()
322 term = getenv ("GNUTERM"); 350 term = getenv ("GNUTERM");
327 elseif (! isunix ()) 355 elseif (! isunix ())
328 term = "windows"; 356 term = "windows";
329 elseif (! isempty (getenv ("DISPLAY"))) 357 elseif (! isempty (getenv ("DISPLAY")))
330 term = "x11"; 358 term = "x11";
331 else 359 else
332 term = "unknown"; 360 term = "dumb";
333 endif 361 endif
334 endif 362 endif
335 endfunction 363 endfunction
336 364
337 function [term, opts] = gnuplot_trim_term (string) 365 function [term, opts] = gnuplot_trim_term (string)
361 endif 389 endif
362 have_enhanced = any (strncmp (enhanced_terminals, term, min (numel (term), 3))); 390 have_enhanced = any (strncmp (enhanced_terminals, term, min (numel (term), 3)));
363 endfunction 391 endfunction
364 392
365 function ret = output_to_screen (term) 393 function ret = output_to_screen (term)
366 ret = any (strcmpi ({"aqua", "wxt", "x11", "windows", "pm"}, term)); 394 ret = any (strcmpi ({"aqua", "dumb", "wxt", "x11", "windows", "pm"}, term));
367 endfunction 395 endfunction
368 396
369 function ret = term_units_are_pixels (term) 397 function ret = term_units_are_pixels (term)
370 ret = any (strncmpi ({"emf", "gif", "jpeg", "pbm", "png", "svg"}, term, 3)); 398 ret = any (strncmpi ({"emf", "gif", "jpeg", "pbm", "png", "svg"}, term, 3));
371 endfunction 399 endfunction