Mercurial > hg > octave-nkf
comparison scripts/plot/drawnow.m @ 6425:0cc5ca7b1e91
[project @ 2007-03-21 15:57:19 by jwe]
author | jwe |
---|---|
date | Wed, 21 Mar 2007 15:57:19 +0000 |
parents | 73fcbac81f33 |
children | 5bec61ae1576 |
comparison
equal
deleted
inserted
replaced
6424:05a48d6cf163 | 6425:0cc5ca7b1e91 |
---|---|
24 | 24 |
25 ## Author: jwe | 25 ## Author: jwe |
26 | 26 |
27 function drawnow (term, file) | 27 function drawnow (term, file) |
28 | 28 |
29 if (nargin == 2) | |
30 h = get (0, "currentfigure"); | |
31 if (h) | |
32 f = get (h); | |
33 plot_stream = []; | |
34 unwind_protect | |
35 plot_stream = open_gnuplot_stream ([], term, file); | |
36 __go_draw_figure__ (f, plot_stream); | |
37 unwind_protect_cleanup | |
38 if (! isempty (plot_stream)) | |
39 pclose (plot_stream); | |
40 endif | |
41 end_unwind_protect | |
42 else | |
43 error ("drawnow: nothing to draw"); | |
44 endif | |
45 elseif (nargin == 0) | |
46 for h = __go_figure_handles__ () | |
47 if (! (isnan (h) || h == 0)) | |
48 f = get (h); | |
49 plot_stream = f.__plot_stream__; | |
50 figure_is_visible = strcmp (f.visible, "on"); | |
51 if (figure_is_visible) | |
52 if (isempty (plot_stream)) | |
53 plot_stream = open_gnuplot_stream (h); | |
54 endif | |
55 __go_draw_figure__ (f, plot_stream); | |
56 elseif (! isempty (plot_stream)) | |
57 pclose (plot_stream); | |
58 set (h, "__plot_stream__", []); | |
59 endif | |
60 __request_drawnow__ (false); | |
61 endif | |
62 endfor | |
63 else | |
64 print_usage (); | |
65 endif | |
66 | |
67 __request_drawnow__ (false); | |
68 | |
69 endfunction | |
70 | |
71 function plot_stream = open_gnuplot_stream (h, term, file) | |
72 | |
29 ## If drawnow is cleared, it is possible to register __go_close_all__ | 73 ## If drawnow is cleared, it is possible to register __go_close_all__ |
30 ## more than once, but that is not fatal. | 74 ## more than once, but that is not fatal. |
31 persistent __go_close_all_registered__; | 75 persistent __go_close_all_registered__; |
32 | 76 |
33 ## Use this instead of calling gcf to avoid creating a figure. | 77 cmd = gnuplot_binary (); |
34 | 78 |
35 h = get (0, "currentfigure"); | 79 if (! isempty (h) && gnuplot_use_title_option ()) |
80 cmd = sprintf ("%s -title \"Figure %d\"", cmd, h); | |
81 endif | |
36 | 82 |
37 if (h) | 83 plot_stream = popen (cmd, "w"); |
38 | 84 |
39 f = get (h); | 85 if (plot_stream < 0) |
86 error ("drawnow: failed to open connection to gnuplot"); | |
87 else | |
40 | 88 |
41 plot_stream = f.__plot_stream__; | 89 if (! isempty (h)) |
42 | 90 set (h, "__plot_stream__", plot_stream); |
43 if (isempty (plot_stream)) | |
44 cmd = gnuplot_binary (); | |
45 if (gnuplot_use_title_option ()) | |
46 cmd = sprintf ("%s -title \"Figure %d\"", cmd, h); | |
47 endif | |
48 plot_stream = popen (cmd, "w"); | |
49 if (plot_stream < 0) | |
50 error ("drawnow: failed to open connection to gnuplot"); | |
51 else | |
52 set (h, "__plot_stream__", plot_stream); | |
53 if (isunix () && isempty (getenv ("DISPLAY"))) | |
54 fprintf (plot_stream, "set terminal dumb\n;"); | |
55 endif | |
56 if (isempty (__go_close_all_registered__)) | |
57 atexit ("__go_close_all__"); | |
58 __go_close_all_registered__ = true; | |
59 endif | |
60 endif | |
61 endif | 91 endif |
62 | 92 |
63 if (nargin == 2) | 93 if (nargin == 3) |
64 fprintf (plot_stream, | 94 fprintf (plot_stream, "set terminal %s\n;", term); |
65 "set terminal push; set terminal %s; set output '%s'\n", | 95 fprintf (plot_stream, "set output \"%s\"\n;", file); |
66 term, file); | 96 elseif (isunix () && isempty (getenv ("DISPLAY"))) |
97 fprintf (plot_stream, "set terminal dumb\n;"); | |
67 endif | 98 endif |
68 | 99 |
69 if (nargin == 2 || strcmp (f.visible, "on")) | 100 if (isempty (__go_close_all_registered__)) |
70 __go_draw_figure__ (f, plot_stream); | 101 atexit ("__go_close_all__"); |
102 __go_close_all_registered__ = true; | |
71 endif | 103 endif |
72 | |
73 __request_drawnow__ (false); | |
74 | |
75 if (nargin == 2) | |
76 fputs (plot_stream, "set terminal pop; set output;\n"); | |
77 endif | |
78 | |
79 else | |
80 | |
81 __request_drawnow__ (false); | |
82 | 104 |
83 endif | 105 endif |
84 | 106 |
85 endfunction | 107 endfunction |