Mercurial > hg > octave-nkf
comparison scripts/plot/gnuplot_drawnow.m @ 9785:ccad98db781b
gnuplot_drawnow.m: Support gnuplot's dumb terminal.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Sun, 08 Nov 2009 17:15:07 -0500 |
parents | 4634a0e9ea1b |
children | b4661b498a7e |
comparison
equal
deleted
inserted
replaced
9784:f786dca09f79 | 9785:ccad98db781b |
---|---|
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 |
239 endif | 259 endif |
240 endif | 260 endif |
241 elseif (strncmpi (term, "aqua", 3)) | 261 elseif (strncmpi (term, "aqua", 3)) |
242 ## Aqua has size, but the format is different. | 262 ## Aqua has size, but the format is different. |
243 size_str = sprintf ("size %d %d", gnuplot_size); | 263 size_str = sprintf ("size %d %d", gnuplot_size); |
264 elseif (strncmpi (term, "dumb", 3)) | |
265 new_stream = 1; | |
266 if (~isempty (getenv ("COLUMNS")) && ~isempty (getenv ("LINES"))) | |
267 ## Let dumb use full text screen size. | |
268 size_str = ["size ", getenv("COLUMNS"), " ", getenv("LINES")]; | |
269 else | |
270 ## Use the gnuplot default. | |
271 size_str = ""; | |
272 end | |
244 elseif (strncmpi (term, "fig", 3)) | 273 elseif (strncmpi (term, "fig", 3)) |
245 ## Fig also has size, but the format is different. | 274 ## Fig also has size, but the format is different. |
246 size_str = sprintf ("size %.15g %.15g", gnuplot_size); | 275 size_str = sprintf ("size %.15g %.15g", gnuplot_size); |
247 elseif (any (strncmpi (term, {"corel", "hpgl"}, 3))) | 276 elseif (any (strncmpi (term, {"corel", "hpgl"}, 3))) |
248 ## The size for corel and hpgl are goes at the end (implicit). | 277 ## The size for corel and hpgl are goes at the end (implicit). |
290 endif | 319 endif |
291 ## Work around the gnuplot feature of growing the x11 window and | 320 ## Work around the gnuplot feature of growing the x11 window and |
292 ## flickering window (x11, windows, & wxt) when the mouse and | 321 ## flickering window (x11, windows, & wxt) when the mouse and |
293 ## multiplot are set in gnuplot. | 322 ## multiplot are set in gnuplot. |
294 fputs (plot_stream, "unset multiplot;\n"); | 323 fputs (plot_stream, "unset multiplot;\n"); |
295 flickering_terms = {"x11", "windows", "wxt"}; | 324 flickering_terms = {"x11", "windows", "wxt", "dumb"}; |
296 if (! any (strcmp (term, flickering_terms)) | 325 if (! any (strcmp (term, flickering_terms)) |
297 || numel (findall (h, "type", "axes")) > 1 | 326 || numel (findall (h, "type", "axes")) > 1 |
298 || numel (findall (h, "type", "image")) > 0) | 327 || numel (findall (h, "type", "image")) > 0) |
299 fprintf (plot_stream, "%s\n", term_str); | 328 fprintf (plot_stream, "%s\n", term_str); |
300 if (nargin == 5) | 329 if (nargin == 5) |
314 else | 343 else |
315 ## gnuplot will pick up the GNUTERM environment variable itself | 344 ## gnuplot will pick up the GNUTERM environment variable itself |
316 ## so no need to set the terminal type if not also setting the | 345 ## so no need to set the terminal type if not also setting the |
317 ## figure title, enhanced mode, or position. | 346 ## figure title, enhanced mode, or position. |
318 endif | 347 endif |
319 | |
320 | 348 |
321 endfunction | 349 endfunction |
322 | 350 |
323 function term = gnuplot_default_term () | 351 function term = gnuplot_default_term () |
324 term = getenv ("GNUTERM"); | 352 term = getenv ("GNUTERM"); |
329 elseif (! isunix ()) | 357 elseif (! isunix ()) |
330 term = "windows"; | 358 term = "windows"; |
331 elseif (! isempty (getenv ("DISPLAY"))) | 359 elseif (! isempty (getenv ("DISPLAY"))) |
332 term = "x11"; | 360 term = "x11"; |
333 else | 361 else |
334 term = "unknown"; | 362 term = "dumb"; |
335 endif | 363 endif |
336 endif | 364 endif |
337 endfunction | 365 endfunction |
338 | 366 |
339 function [term, opts] = gnuplot_trim_term (string) | 367 function [term, opts] = gnuplot_trim_term (string) |
363 endif | 391 endif |
364 have_enhanced = any (strncmp (enhanced_terminals, term, min (numel (term), 3))); | 392 have_enhanced = any (strncmp (enhanced_terminals, term, min (numel (term), 3))); |
365 endfunction | 393 endfunction |
366 | 394 |
367 function ret = output_to_screen (term) | 395 function ret = output_to_screen (term) |
368 ret = any (strcmpi ({"aqua", "wxt", "x11", "windows", "pm"}, term)); | 396 ret = any (strcmpi ({"aqua", "dumb", "wxt", "x11", "windows", "pm"}, term)); |
369 endfunction | 397 endfunction |
370 | 398 |
371 function ret = term_units_are_pixels (term) | 399 function ret = term_units_are_pixels (term) |
372 ret = any (strncmpi ({"emf", "gif", "jpeg", "pbm", "png", "svg"}, term, 3)); | 400 ret = any (strncmpi ({"emf", "gif", "jpeg", "pbm", "png", "svg"}, term, 3)); |
373 endfunction | 401 endfunction |