diff scripts/plot/drawnow.m @ 6257:44c91c5dfe1d

[project @ 2007-01-30 19:16:52 by jwe]
author jwe
date Tue, 30 Jan 2007 19:16:55 +0000
parents
children c6a7b0453f9a
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/scripts/plot/drawnow.m
@@ -0,0 +1,74 @@
+## Copyright (C) 2005 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+## 02110-1301, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} drawnow ()
+## Display the current graphics.
+## @end deftypefn
+
+## Author: jwe
+
+function drawnow (term, file)
+
+  ## Use this instead of calling gcf to avoid creating a figure.
+
+  h = get (0, "currentfigure");
+
+  if (h)
+
+    f = get (h);
+
+    plot_stream = f.__plot_stream__;
+
+    if (isempty (plot_stream))
+      plot_stream = popen (sprintf ("gnuplot -title \"Figure %d\"", h), "w");
+      if (plot_stream < 0)
+	error ("drawnow: failed to open connection to gnuplot");
+      else
+	set (h, "__plot_stream__", plot_stream);
+	if (isempty (getenv ("DISPLAY")))
+	  fprintf (plot_stream, "set terminal dumb\n;");
+	endif
+      endif
+    endif
+
+    if (nargin == 2)
+      fprintf (plot_stream,
+	       "set terminal push; set terminal %s; set output '%s'\n",
+	       term, file);
+    endif
+
+    if (nargin == 2 || strcmp (f.visible, "on"))
+      __uiobject_draw_figure__ (f, plot_stream);
+    endif
+
+    __request_drawnow__ (false);
+
+    if (nargin == 2)
+      fputs (plot_stream, "set terminal pop; set output;\n");
+    endif
+
+  else
+
+    __request_drawnow__ (false);
+
+  endif
+
+
+endfunction