6257
|
1 ## Copyright (C) 2005 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 2, or (at your option) |
|
8 ## 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, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} drawnow () |
|
22 ## Display the current graphics. |
|
23 ## @end deftypefn |
|
24 |
|
25 ## Author: jwe |
|
26 |
|
27 function drawnow (term, file) |
|
28 |
6418
|
29 ## If drawnow is cleared, it is possible to register __go_close_all__ |
|
30 ## more than once, but that is not fatal. |
|
31 persistent __go_close_all_registered__; |
6298
|
32 |
6257
|
33 ## Use this instead of calling gcf to avoid creating a figure. |
|
34 |
|
35 h = get (0, "currentfigure"); |
|
36 |
|
37 if (h) |
|
38 |
|
39 f = get (h); |
|
40 |
|
41 plot_stream = f.__plot_stream__; |
|
42 |
|
43 if (isempty (plot_stream)) |
6286
|
44 cmd = gnuplot_binary (); |
|
45 if (gnuplot_use_title_option ()) |
6289
|
46 cmd = sprintf ("%s -title \"Figure %d\"", cmd, h); |
6286
|
47 endif |
|
48 plot_stream = popen (cmd, "w"); |
6405
|
49 if (isempty (__go_close_all_registered__)) |
|
50 atexit ("__go_close_all__"); |
|
51 __go_close_all_registered__ = true; |
6298
|
52 endif |
6257
|
53 if (plot_stream < 0) |
|
54 error ("drawnow: failed to open connection to gnuplot"); |
|
55 else |
|
56 set (h, "__plot_stream__", plot_stream); |
6298
|
57 if (isunix () && isempty (getenv ("DISPLAY"))) |
6257
|
58 fprintf (plot_stream, "set terminal dumb\n;"); |
|
59 endif |
|
60 endif |
|
61 endif |
|
62 |
|
63 if (nargin == 2) |
|
64 fprintf (plot_stream, |
|
65 "set terminal push; set terminal %s; set output '%s'\n", |
|
66 term, file); |
|
67 endif |
|
68 |
|
69 if (nargin == 2 || strcmp (f.visible, "on")) |
6405
|
70 __go_draw_figure__ (f, plot_stream); |
6257
|
71 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 |
|
83 endif |
|
84 |
|
85 endfunction |