Mercurial > octave-nkf
comparison scripts/plot/gnuplot_drawnow.m @ 7408:246f905cb984
[project @ 2008-01-22 19:42:47 by jwe]
author | jwe |
---|---|
date | Tue, 22 Jan 2008 19:42:48 +0000 |
parents | |
children | a0ec02774303 |
comparison
equal
deleted
inserted
replaced
7407:8433bb7865bd | 7408:246f905cb984 |
---|---|
1 ## Copyright (C) 2005, 2006, 2007 John W. Eaton | |
2 ## | |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} drawnow () | |
21 ## Update and display the current graphics. | |
22 ## | |
23 ## Octave automatically calls drawnow just before printing a prompt, | |
24 ## when @code{sleep} or @code{pause} is called, or while waiting for | |
25 ## command-line input. | |
26 ## @end deftypefn | |
27 | |
28 ## Author: jwe | |
29 | |
30 function gnuplot_drawnow (h, term, file, mono, debug_file) | |
31 | |
32 if (nargin < 4) | |
33 mono = false; | |
34 endif | |
35 | |
36 if (nargin >= 3 && nargin <= 5) | |
37 f = __get__ (h); | |
38 plot_stream = []; | |
39 fid = []; | |
40 unwind_protect | |
41 [plot_stream, enhanced] = open_gnuplot_stream ([], term, file); | |
42 __go_draw_figure__ (f, plot_stream, enhanced, mono); | |
43 if (nargin == 5) | |
44 fid = fopen (debug_file, "wb"); | |
45 enhanced = init_plot_stream (fid, [], term, file); | |
46 __go_draw_figure__ (f, fid, enhanced, mono); | |
47 endif | |
48 unwind_protect_cleanup | |
49 if (! isempty (plot_stream)) | |
50 pclose (plot_stream); | |
51 endif | |
52 if (! isempty (fid)) | |
53 fclose (fid); | |
54 endif | |
55 end_unwind_protect | |
56 elseif (nargin == 1) | |
57 f = __get__ (h); | |
58 plot_stream = f.__plot_stream__; | |
59 if (isempty (plot_stream)) | |
60 [plot_stream, enhanced] = open_gnuplot_stream (h); | |
61 set (h, "__enhanced__", enhanced); | |
62 else | |
63 enhanced = f.__enhanced__; | |
64 endif | |
65 __go_draw_figure__ (f, plot_stream, enhanced, mono); | |
66 else | |
67 print_usage (); | |
68 endif | |
69 | |
70 endfunction | |
71 | |
72 function [plot_stream, enhanced] = open_gnuplot_stream (h, varargin) | |
73 | |
74 cmd = gnuplot_binary (); | |
75 | |
76 plot_stream = popen (cmd, "w"); | |
77 | |
78 if (plot_stream < 0) | |
79 error ("drawnow: failed to open connection to gnuplot"); | |
80 else | |
81 | |
82 if (! isempty (h)) | |
83 set (h, "__plot_stream__", plot_stream); | |
84 endif | |
85 | |
86 enhanced = init_plot_stream (plot_stream, h, varargin{:}); | |
87 | |
88 endif | |
89 | |
90 endfunction | |
91 | |
92 function enhanced = init_plot_stream (plot_stream, h, term, file) | |
93 | |
94 if (nargin == 4) | |
95 enhanced = enhanced_term (term); | |
96 if (! isempty (term)) | |
97 if (enhanced) | |
98 fprintf (plot_stream, "set terminal %s enhanced;\n", term); | |
99 else | |
100 fprintf (plot_stream, "set terminal %s;\n", term); | |
101 endif | |
102 endif | |
103 if (! isempty (file)) | |
104 fprintf (plot_stream, "set output \"%s\";\n", file); | |
105 endif | |
106 else | |
107 | |
108 ## Guess the terminal type. | |
109 term = getenv ("GNUTERM"); | |
110 if (isempty (term)) | |
111 if (! isempty (getenv ("DISPLAY"))) | |
112 term = "x11"; | |
113 elseif (! isunix ()) | |
114 term = "windows"; | |
115 else | |
116 ## This should really be checking for os x before setting | |
117 ## the terminal type to aqua, but nobody will notice because | |
118 ## every other unix will be using x11 and windows will be | |
119 ## using windows. Those diehards still running octave from | |
120 ## a linux console know how to set the GNUTERM variable. | |
121 term = "aqua"; | |
122 endif | |
123 endif | |
124 | |
125 enhanced = enhanced_term (term); | |
126 if (enhanced) | |
127 enh_str = "enhanced"; | |
128 else | |
129 enh_str = ""; | |
130 endif | |
131 | |
132 ## If no 'h' (why not?) then open the terminal as Figure 0. | |
133 if (isempty (h)) | |
134 h = 0; | |
135 endif | |
136 | |
137 if (strcmp (term, "x11")) | |
138 fprintf (plot_stream, "set terminal x11 %s title \"Figure %d\"\n", | |
139 enh_str, h); | |
140 elseif (strcmp (term, "aqua")) | |
141 ## Aqua doesn't understand the 'title' option despite what the | |
142 ## gnuplot 4.2 documentation says. | |
143 fprintf (plot_stream, "set terminal aqua %d %s\n", h, enh_str); | |
144 elseif (strcmp (term, "wxt")) | |
145 fprintf (plot_stream, "set terminal wxt %s title \"Figure %d\"\n", | |
146 enh_str, h); | |
147 | |
148 elseif (enhanced) | |
149 fprintf (plot_stream, "set terminal %s %s\n", term, enh_str); | |
150 endif | |
151 ## gnuplot will pick up the GNUTERM environment variable itself | |
152 ## so no need to set the terminal type if not also setting the | |
153 ## figure title or enhanced mode. | |
154 | |
155 endif | |
156 | |
157 endfunction | |
158 | |
159 function have_enhanced = enhanced_term (term) | |
160 persistent enhanced_terminals; | |
161 | |
162 if (isempty (enhanced_terminals)) | |
163 ## Don't include pstex, pslatex or epslatex here as the TeX commands | |
164 ## should not be interpreted in that case. | |
165 if (compare_versions (__gnuplot_version__ (), "4.0", ">")) | |
166 enhanced_terminals = {"aqua", "dumb", "png", "jpeg", "gif", "pm", ... | |
167 "windows", "wxt", "svg", "postscript", "x11", "pdf"}; | |
168 else | |
169 enhanced_terminals = {"x11", "postscript"}; | |
170 endif | |
171 endif | |
172 | |
173 term = tolower (term); | |
174 | |
175 have_enhanced = false; | |
176 for i = 1 : length (enhanced_terminals) | |
177 t = enhanced_terminals{i}; | |
178 if (strncmp (term, t, min (length (term), length (t)))) | |
179 have_enhanced = true; | |
180 break; | |
181 endif | |
182 endfor | |
183 endfunction |