changeset 6179:235a1b456cf4

[project @ 2006-11-17 17:33:09 by jwe]
author jwe
date Fri, 17 Nov 2006 17:33:09 +0000
parents 830235f4984f
children 133e7a4a5565
files scripts/ChangeLog scripts/plot/__render_plot__.m scripts/plot/print.m scripts/plot/replot.m
diffstat 4 files changed, 147 insertions(+), 157 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Nov 17 00:19:18 2006 +0000
+++ b/scripts/ChangeLog	Fri Nov 17 17:33:09 2006 +0000
@@ -1,3 +1,9 @@
+2006-11-17  John W. Eaton  <jwe@octave.org>
+
+	* plot/__render_plot__.m: New args, terminal and output.
+	* plot/print.m: Don't set output and term here.  Instead, call
+	__render_plot__ with terminal and output.
+
 2006-11-16  John W. Eaton  <jwe@octave.org>
 
 	* plot/__render_plot1__.m: New file.
--- a/scripts/plot/__render_plot__.m	Fri Nov 17 00:19:18 2006 +0000
+++ b/scripts/plot/__render_plot__.m	Fri Nov 17 17:33:09 2006 +0000
@@ -17,7 +17,7 @@
 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 ## 02110-1301, USA.
 
-function __render_plot__ ()
+function __render_plot__ (terminal, output)
 
   __plot_globals__;
 
@@ -25,31 +25,57 @@
   mxn = __multiplot_xn__(cf);
   myn = __multiplot_yn__(cf);
 
-  if (__multiplot_mode__(cf))
-    __gnuplot_raw__ ("set size 1, 1;\n");
-    __gnuplot_raw__ ("set origin 0, 0;\n");
-    __gnuplot_raw__ ("set multiplot;\n");
-    for mxi = 1:mxn
-      for myi = 1:myn
+  set_terminal = nargin > 0;
+  set_output = nargin > 1;
+
+  unwind_protect
+
+    if (set_terminal)
+      __gnuplot_raw__ ("set terminal push;\n");
+      __gnuplot_raw__ (sprintf ("set terminal %s;\n", terminal));
+    endif
 
-	columns = __multiplot_xn__(cf);
-	rows = __multiplot_yn__(cf);
-	__gnuplot_raw__ (sprintf ("set size %g, %g;\n",
-				  __multiplot_xsize__(cf),
-				  __multiplot_ysize__(cf)));
+    if (set_output)
+      __gnuplot_raw__ (sprintf ("set output \"%s\";\n", output));
+    endif
+
+    if (__multiplot_mode__(cf))
+      __gnuplot_raw__ ("set size 1, 1;\n");
+      __gnuplot_raw__ ("set origin 0, 0;\n");
+      __gnuplot_raw__ ("set multiplot;\n");
+      for mxi = 1:mxn
+	for myi = 1:myn
 
-	xo = (mxi - 1.0) * __multiplot_xsize__(cf);
-	yo = (rows - myi) * __multiplot_ysize__(cf);
+	  columns = __multiplot_xn__(cf);
+	  rows = __multiplot_yn__(cf);
+	  __gnuplot_raw__ (sprintf ("set size %g, %g;\n",
+				    __multiplot_xsize__(cf),
+				    __multiplot_ysize__(cf)));
 
-	__gnuplot_raw__ (sprintf ("set origin %g, %g;\n", xo, yo));
+	  xo = (mxi - 1.0) * __multiplot_xsize__(cf);
+	  yo = (rows - myi) * __multiplot_ysize__(cf);
 
-	__render_plot1__ (mxi, myi)
+	  __gnuplot_raw__ (sprintf ("set origin %g, %g;\n", xo, yo));
+
+	  __render_plot1__ (mxi, myi)
 
+	endfor
       endfor
-    endfor
-    __gnuplot_raw__ ("unset multiplot;\n");
-  else
-    __render_plot1__ (1, 1);
-  endif
+      __gnuplot_raw__ ("unset multiplot;\n");
+    else
+      __render_plot1__ (1, 1);
+    endif
+
+  unwind_protect_cleanup
+
+    if (set_terminal)
+      __gnuplot_raw__ ("set terminal pop;\n");
+    endif
+
+    if (set_output)
+      __gnuplot_raw__ ("set output;\n")
+    endif
+
+  end_unwind_protect
 
 endfunction
--- a/scripts/plot/print.m	Fri Nov 17 00:19:18 2006 +0000
+++ b/scripts/plot/print.m	Fri Nov 17 17:33:09 2006 +0000
@@ -92,31 +92,6 @@
 ## @end table
 ##
 ## The filename and options can be given in any order.
-##
-## @strong{Note}, the print function does not work with gnuplot's
-## muplitplot mode.  This problem is a known bug, and it will be fixed
-## in a future version of Octave, but there is no simple fix (or it
-## would have been fixed long ago).  You can work around the bug by
-## setting the terminal type and output yourself, then executing the
-## multiplot plotting commands.  For example
-##
-## @example
-## @group
-## __gnuplot_set__ terminal postscript
-## __gnuplot_raw__ ("set output \"foo.ps\"\n");
-## subplot (2, 1, 1);
-## sombrero (21);
-## subplot (2, 1, 2);
-## sombrero (41);
-## oneplot ();
-## __gnuplot_set__ terminal x11
-## __gnuplot_raw__ ("set output\n");
-## @end group
-## @end example
-##
-## will save both figures on a single page in the PostScript file
-## @file{foo.ps}.  All labeling commands should appear before the plot
-## command for each subplot.
 ## @end deftypefn
 
 ## Author: Daniel Heiserer <Daniel.heiserer@physik.tu-muenchen.de>
@@ -218,132 +193,115 @@
     name = strcat (tmpnam, ".eps");
   endif
 
-  unwind_protect
-
-    if (strcmp (dev, "ps") || strcmp (dev, "ps2") ...
-	|| strcmp (dev, "psc")  || strcmp (dev, "psc2")
-	|| strcmp (dev, "epsc") || strcmp (dev, "epsc2")
-	|| strcmp (dev, "eps")  || strcmp (dev, "eps2"))
-      ## Various postscript options
-      if (dev(1) == "e")
-	options = "eps ";
-      else
-	options = strcat (orientation, " ");
-      endif
-      options = strcat (options, "enhanced ");
-
-      if (any (dev == "c") || use_color > 0)
-        if (force_solid < 0)
-	  options = strcat (options, "color dashed ");
-	else
-          options = strcat (options, "color solid ");
-        endif
-      else
-        if (force_solid > 0)
-	  options = strcat (options, "mono solid ");
-	else
-	  options = strcat (options, "mono dashed ");
-        endif
-      endif
-
-      if (! isempty (font))
-	options = strcat (options, "\"", font, "\" ");
-      endif
-      if (! isempty (fontsize))
-	options = strcat (options, " ", fontsize);
-      endif
-
-      new_terminal = strcat ("postscript ", options);
-
-    elseif (strcmp (dev, "aifm") || strcmp (dev, "corel"))
-      ## Adobe Illustrator, CorelDraw
-      if (use_color >= 0)
-	options = " color";
-      else
-	options = " mono";
-      endif
-      if (! isempty (font))
-	options = strcat (options, " \"", font, "\"");
-      endif
-      if (! isempty (fontsize))
-	options = strcat (options, " ", fontsize);
-      endif
-
-      new_terminal = strcat (dev, " ", options);
+  if (strcmp (dev, "ps") || strcmp (dev, "ps2") ...
+      || strcmp (dev, "psc")  || strcmp (dev, "psc2")
+      || strcmp (dev, "epsc") || strcmp (dev, "epsc2")
+      || strcmp (dev, "eps")  || strcmp (dev, "eps2"))
+    ## Various postscript options
+    if (dev(1) == "e")
+      options = "eps ";
+    else
+      options = strcat (orientation, " ");
+    endif
+    options = strcat (options, "enhanced ");
 
-    elseif (strcmp (dev, "fig"))
-      ## XFig
-      options = orientation;
-      if (use_color >= 0)
-	options = " color";
+    if (any (dev == "c") || use_color > 0)
+      if (force_solid < 0)
+	options = strcat (options, "color dashed ");
       else
-	options = " mono";
-      endif
-      if (! isempty (fontsize))
-	options = strcat (options, " fontsize ", fontsize);
+	options = strcat (options, "color solid ");
       endif
-
-      new_terminal = strcat ("fig ", options);
-
-    elseif (strcmp (dev, "emf"))
-      ## Enhanced Metafile format
-      options = " ";
-      if (use_color >= 0)
-	options = " color";
+    else
+      if (force_solid > 0)
+	options = strcat (options, "mono solid ");
       else
-	options = " mono";
-      endif
-      if (force_solid >= 0)
-	options = strcat (options, " solid");
-      endif
-      if (! isempty (font))
-	options = strcat (options, " \"", font, "\"");
+	options = strcat (options, "mono dashed ");
       endif
-      if (! isempty (fontsize))
-	options = strcat (options, " ", fontsize);
-      endif
+    endif
 
-      new_terminal = strcat ("emf ", options);
+    if (! isempty (font))
+      options = strcat (options, "\"", font, "\" ");
+    endif
+    if (! isempty (fontsize))
+      options = strcat (options, " ", fontsize);
+    endif
 
-    elseif (strcmp (dev, "png") || strcmp (dev, "pbm"))
-      ## Portable network graphics, PBMplus
+    new_terminal = strcat ("postscript ", options);
 
-      ## FIXME -- New PNG interface takes color as "xRRGGBB"
-      ## where x is the literal character 'x' and 'RRGGBB' are the red,
-      ## green and blue components in hex.  For now we just ignore it
-      ## and use default.  The png terminal now is so rich with options,
-      ## that one perhaps has to write a separate printpng.m function.
-      ## DAS
-
-      ## if (use_color >= 0)
-      ##	eval (sprintf ("__gnuplot_set__ term %s color medium", dev));
-      ##else
-      ##eval (sprintf ("__gnuplot_set__ term %s mono medium", dev));
-      ##endif
-
-      new_terminal = "png large";
-
-    elseif (strcmp (dev, "dxf") || strcmp (dev, "mf") || strcmp (dev, "hpgl"))
-      ## AutoCad DXF, METAFONT, HPGL
-      new_terminal = dev;
+  elseif (strcmp (dev, "aifm") || strcmp (dev, "corel"))
+    ## Adobe Illustrator, CorelDraw
+    if (use_color >= 0)
+      options = " color";
+    else
+      options = " mono";
+    endif
+    if (! isempty (font))
+      options = strcat (options, " \"", font, "\"");
+    endif
+    if (! isempty (fontsize))
+      options = strcat (options, " ", fontsize);
     endif
 
-    __gnuplot_raw__ ("set terminal push;\n");
-    __gnuplot_raw__ (sprintf ("set terminal %s;\n", new_terminal));
+    new_terminal = strcat (dev, " ", options);
 
-    ## Gnuplot expects " around output file name
-    __gnuplot_raw__ (sprintf ("set output \"%s\";\n", name));
+  elseif (strcmp (dev, "fig"))
+    ## XFig
+    options = orientation;
+    if (use_color >= 0)
+      options = " color";
+    else
+      options = " mono";
+    endif
+    if (! isempty (fontsize))
+      options = strcat (options, " fontsize ", fontsize);
+    endif
 
-    replot ();
+    new_terminal = strcat ("fig ", options);
 
-  unwind_protect_cleanup
+  elseif (strcmp (dev, "emf"))
+    ## Enhanced Metafile format
+    options = " ";
+    if (use_color >= 0)
+      options = " color";
+    else
+      options = " mono";
+    endif
+    if (force_solid >= 0)
+      options = strcat (options, " solid");
+    endif
+    if (! isempty (font))
+      options = strcat (options, " \"", font, "\"");
+    endif
+    if (! isempty (fontsize))
+      options = strcat (options, " ", fontsize);
+    endif
+
+    new_terminal = strcat ("emf ", options);
 
-    __gnuplot_raw__ ("set terminal pop;\n");
-    __gnuplot_raw__ ("set output;\n")
+  elseif (strcmp (dev, "png") || strcmp (dev, "pbm"))
+    ## Portable network graphics, PBMplus
+
+    ## FIXME -- New PNG interface takes color as "xRRGGBB"
+    ## where x is the literal character 'x' and 'RRGGBB' are the red,
+    ## green and blue components in hex.  For now we just ignore it
+    ## and use default.  The png terminal now is so rich with options,
+    ## that one perhaps has to write a separate printpng.m function.
+    ## DAS
 
-    replot ();
+    ## if (use_color >= 0)
+    ##	eval (sprintf ("__gnuplot_set__ term %s color medium", dev));
+    ##else
+    ##eval (sprintf ("__gnuplot_set__ term %s mono medium", dev));
+    ##endif
 
-  end_unwind_protect
+    new_terminal = "png large";
+
+  elseif (strcmp (dev, "dxf") || strcmp (dev, "mf") || strcmp (dev, "hpgl"))
+    ## AutoCad DXF, METAFONT, HPGL
+    new_terminal = dev;
+  endif
+
+  __render_plot__ (new_terminal, name);
 
   if (! isempty (convertname))
     command = sprintf ("convert '%s' '%s'", name, convertname);
--- a/scripts/plot/replot.m	Fri Nov 17 00:19:18 2006 +0000
+++ b/scripts/plot/replot.m	Fri Nov 17 17:33:09 2006 +0000
@@ -25,7 +25,7 @@
 ## Author: jwe
 
 function replot ()
-
+  
   if (nargin == 0)
     __render_plot__ ();
   else