changeset 12103:a14e15613509 release-3-2-x

gnuplot_drawnow.m: Support gnuplot's dumb terminal.
author Ben Abbott <bpabbott@mac.com>
date Tue, 24 Nov 2009 08:02:08 +0100
parents 52d8ad5d28d6
children 69828adba966
files scripts/ChangeLog scripts/plot/gnuplot_drawnow.m
diffstat 2 files changed, 39 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,7 @@
+2009-11-08  Petr Mikulik <mikulik@physics.muni.cz>
+
+	* plot/gnuplot_drawnow.m: Support gnuplot's dumb terminal.
+
 2009-11-02  Stefan Hepp  <stefan@stefant.org>
 
 	* plot/gnuplot_drawnow.m (gnuplot_default_term): Don't set term to
--- a/scripts/plot/gnuplot_drawnow.m
+++ b/scripts/plot/gnuplot_drawnow.m
@@ -87,9 +87,29 @@
     else
       new_stream = false;
     endif
-    enhanced = gnuplot_set_term (plot_stream (1), new_stream, h);
+    term = gnuplot_default_term ();
+    if (strcmp (term, "dumb"))
+      ## popen2 eats stdout of gnuplot, use temporary file instead
+      dumb_tmp_file = tmpnam ();
+      enhanced = gnuplot_set_term (plot_stream (1), new_stream, h, ...
+                                   term, dumb_tmp_file);
+    else
+      enhanced = gnuplot_set_term (plot_stream (1), new_stream, h, term);
+    end
     __go_draw_figure__ (h, plot_stream (1), enhanced, mono, 0);
     fflush (plot_stream (1));
+    if (strcmp (term, "dumb"))
+      fid = -1;
+      while (fid < 0)
+        pause (0.1);
+        fid = fopen (dumb_tmp_file, 'r');
+      endwhile
+      ## reprint the plot on screen
+      [a, count] = fscanf (fid, '%c', Inf);
+      puts (a);
+      fclose (fid);
+      unlink (dumb_tmp_file);
+    endif
   else
     print_usage ();
   endif
@@ -143,8 +163,8 @@
 
     if (! isempty (h) && isfigure (h))
 
-      ## Generate gnuoplot title string for backend plot windows.
-      if (output_to_screen (term))
+      ## Generate gnuplot title string for backend plot windows.
+      if (output_to_screen (term) && ~strcmp (term, "dumb"))
         fig.numbertitle = get (h, "numbertitle");
         fig.name = get (h, "name");
         if (strcmpi (get (h, "numbertitle"), "on"))
@@ -239,6 +259,15 @@
           elseif (strncmpi (term, "aqua", 3))
             ## Aqua has size, but the format is different.
             size_str = sprintf ("size %d %d", gnuplot_size);
+          elseif (strncmpi (term, "dumb", 3))
+            new_stream = 1;
+            if (~isempty (getenv ("COLUMNS")) && ~isempty (getenv ("LINES")))
+              ## Let dumb use full text screen size.
+              size_str = ["size ", getenv("COLUMNS"), " ", getenv("LINES")];
+            else
+	      ## Use the gnuplot default.
+              size_str = "";
+            end
           elseif (strncmpi (term, "fig", 3))
             ## Fig also has size, but the format is different.
             size_str = sprintf ("size %.15g %.15g", gnuplot_size);
@@ -290,7 +319,7 @@
     ## flickering window (x11, windows, & wxt) when the mouse and
     ## multiplot are set in gnuplot.
     fputs (plot_stream, "unset multiplot;\n");
-    flickering_terms = {"x11", "windows", "wxt"};
+    flickering_terms = {"x11", "windows", "wxt", "dumb"};
     if (! any (strcmp (term, flickering_terms))
         || numel (findall (h, "type", "axes")) > 1
         || numel (findall (h, "type", "image")) > 0)
@@ -315,7 +344,6 @@
     ## figure title, enhanced mode, or position.
   endif
 
-
 endfunction
 
 function term = gnuplot_default_term ()
@@ -329,7 +357,7 @@
     elseif (! isempty (getenv ("DISPLAY")))
       term = "x11";
     else
-      term = "unknown";
+      term = "dumb";
     endif
   endif
 endfunction
@@ -363,7 +391,7 @@
 endfunction
 
 function ret = output_to_screen (term)
-  ret = any (strcmpi ({"aqua", "wxt", "x11", "windows", "pm"}, term));
+  ret = any (strcmpi ({"aqua", "dumb", "wxt", "x11", "windows", "pm"}, term));
 endfunction
 
 function ret = term_units_are_pixels (term)