comparison scripts/plot/drawnow.m @ 7189:e8d953d03f6a

[project @ 2007-11-26 20:42:09 by dbateman]
author dbateman
date Mon, 26 Nov 2007 20:42:11 +0000
parents a1dbe9d80eee
children b48a21816f2e
comparison
equal deleted inserted replaced
7188:fdd7cd70dc14 7189:e8d953d03f6a
43 if (h) 43 if (h)
44 f = get (h); 44 f = get (h);
45 plot_stream = []; 45 plot_stream = [];
46 fid = []; 46 fid = [];
47 unwind_protect 47 unwind_protect
48 plot_stream = open_gnuplot_stream ([], term, file); 48 [plot_stream, enhanced] = open_gnuplot_stream ([], term, file);
49 __go_draw_figure__ (f, plot_stream); 49 __go_draw_figure__ (f, plot_stream, enhanced);
50 if (nargin == 3) 50 if (nargin == 3)
51 fid = fopen (debug_file, "wb"); 51 fid = fopen (debug_file, "wb");
52 init_plot_stream (fid, [], term, file); 52 enhanced = init_plot_stream (fid, [], term, file);
53 __go_draw_figure__ (f, fid); 53 __go_draw_figure__ (f, fid, enhanced);
54 endif 54 endif
55 unwind_protect_cleanup 55 unwind_protect_cleanup
56 if (! isempty (plot_stream)) 56 if (! isempty (plot_stream))
57 pclose (plot_stream); 57 pclose (plot_stream);
58 endif 58 endif
70 if (f.__modified__) 70 if (f.__modified__)
71 plot_stream = f.__plot_stream__; 71 plot_stream = f.__plot_stream__;
72 figure_is_visible = strcmp (f.visible, "on"); 72 figure_is_visible = strcmp (f.visible, "on");
73 if (figure_is_visible) 73 if (figure_is_visible)
74 if (isempty (plot_stream)) 74 if (isempty (plot_stream))
75 plot_stream = open_gnuplot_stream (h); 75 [plot_stream, enhanced] = open_gnuplot_stream (h);
76 set (h, "__enhanced__", enhanced);
77 else
78 enhanced = f.__enhanced__;
76 endif 79 endif
77 __go_draw_figure__ (f, plot_stream); 80 __go_draw_figure__ (f, plot_stream, enhanced);
78 elseif (! isempty (plot_stream)) 81 elseif (! isempty (plot_stream))
79 pclose (plot_stream); 82 pclose (plot_stream);
80 set (h, "__plot_stream__", []); 83 set (h, "__plot_stream__", []);
84 set (h, "__enhanced__", false);
81 endif 85 endif
82 set (h, "__modified__", false); 86 set (h, "__modified__", false);
83 endif 87 endif
84 endif 88 endif
85 endfor 89 endfor
94 98
95 end_unwind_protect 99 end_unwind_protect
96 100
97 endfunction 101 endfunction
98 102
99 function plot_stream = open_gnuplot_stream (h, varargin) 103 function [plot_stream, enhanced] = open_gnuplot_stream (h, varargin)
100 104
101 ## If drawnow is cleared, it is possible to register __go_close_all__ 105 ## If drawnow is cleared, it is possible to register __go_close_all__
102 ## more than once, but that is not fatal. 106 ## more than once, but that is not fatal.
103 persistent __go_close_all_registered__; 107 persistent __go_close_all_registered__;
104 108
112 116
113 if (! isempty (h)) 117 if (! isempty (h))
114 set (h, "__plot_stream__", plot_stream); 118 set (h, "__plot_stream__", plot_stream);
115 endif 119 endif
116 120
117 init_plot_stream (plot_stream, h, varargin{:}) 121 enhanced = init_plot_stream (plot_stream, h, varargin{:});
118 122
119 if (isempty (__go_close_all_registered__)) 123 if (isempty (__go_close_all_registered__))
120 atexit ("__go_close_all__"); 124 atexit ("__go_close_all__");
121 __go_close_all_registered__ = true; 125 __go_close_all_registered__ = true;
122 endif 126 endif
123 127
124 endif 128 endif
125 129
126 endfunction 130 endfunction
127 131
128 function init_plot_stream (plot_stream, h, term, file) 132 function enhanced = init_plot_stream (plot_stream, h, term, file)
129 133
130 if (nargin == 4) 134 if (nargin == 4)
135 enhanced = enhanced_term (term);
131 if (! isempty (term)) 136 if (! isempty (term))
132 fprintf (plot_stream, "set terminal %s;\n", term); 137 if (enhanced)
138 fprintf (plot_stream, "set terminal %s enhanced;\n", term);
139 else
140 fprintf (plot_stream, "set terminal %s;\n", term);
141 endif
133 endif 142 endif
134 if (! isempty (file)) 143 if (! isempty (file))
135 fprintf (plot_stream, "set output \"%s\";\n", file); 144 fprintf (plot_stream, "set output \"%s\";\n", file);
136 endif 145 endif
137 else 146 else
151 ## a linux console know how to set the GNUTERM variable. 160 ## a linux console know how to set the GNUTERM variable.
152 term = "aqua"; 161 term = "aqua";
153 endif 162 endif
154 endif 163 endif
155 164
165 enhanced = enhanced_term (term);
166 if (enhanced)
167 enh_str = "enhanced";
168 else
169 enh_str = "";
170 endif
171
156 ## If no 'h' (why not?) then open the terminal as Figure 0. 172 ## If no 'h' (why not?) then open the terminal as Figure 0.
157 if (isempty (h)) 173 if (isempty (h))
158 h = 0; 174 h = 0;
159 endif 175 endif
160 176
161 if (strcmp (term, "x11")) 177 if (strcmp (term, "x11"))
162 fprintf (plot_stream, "set terminal x11 title \"Figure %d\"\n", h); 178 fprintf (plot_stream, "set terminal x11 %s title \"Figure %d\"\n",
179 enh_str, h);
163 elseif (strcmp (term, "aqua")) 180 elseif (strcmp (term, "aqua"))
164 ## Aqua doesn't understand the 'title' option despite what the 181 ## Aqua doesn't understand the 'title' option despite what the
165 ## gnuplot 4.2 documentation says. 182 ## gnuplot 4.2 documentation says.
166 fprintf (plot_stream, "set terminal aqua %d\n", h); 183 fprintf (plot_stream, "set terminal aqua %d %s\n", h, enh_str);
167 elseif (strcmp (term, "wxt")) 184 elseif (strcmp (term, "wxt"))
168 fprintf (plot_stream, "set terminal wxt title \"Figure %d\"\n", h); 185 fprintf (plot_stream, "set terminal wxt %s title \"Figure %d\"\n",
186 enh_str, h);
187
188 elseif (enhanced)
189 fprintf (plot_stream "set terminal %s %s\n", term, enh_str);
169 endif 190 endif
170 ## gnuplot will pick up the GNUTERM environment variable itself 191 ## gnuplot will pick up the GNUTERM environment variable itself
171 ## so no need to set the terminal type if not also setting the 192 ## so no need to set the terminal type if not also setting the
172 ## figure title. 193 ## figure title or enhanced mode.
173 194
174 endif 195 endif
175 196
176 endfunction 197 endfunction
198
199 function have_enhanced = enhanced_term (term)
200 persistent enhanced_terminals;
201
202 if (isempty (enhanced_terminals))
203 ## Don't include pstex, pslatex or epslatex here as the TeX commands
204 ## should not be interpreted in that case.
205 if (compare_versions (__gnuplot_version__ (), "4.0", ">"))
206 enhanced_terminals = {"aqua", "dumb", "png", "jpeg", "gif", "pm", ...
207 "windows", "wxt", "svg", "postscript", "x11"};
208 else
209 enhanced_terminals = {"x11", "postscript"};
210 endif
211 endif
212
213 term = tolower (term);
214
215 have_enhanced = false;
216 for i = 1 : length (enhanced_terminals)
217 t = enhanced_terminals{i};
218 if (strncmp (term, t, min (length (term), length(t))))
219 have_enhanced = true;
220 break;
221 endif
222 endfor
223 endfunction