changeset 5115:57372235194b

[project @ 2005-01-24 18:38:45 by jwe]
author jwe
date Mon, 24 Jan 2005 18:38:45 +0000
parents cda8c0a823c5
children 67320fb4ae5c
files scripts/ChangeLog scripts/plot/__plr2__.m scripts/plot/__plr__.m scripts/plot/__plt1__.m scripts/plot/__plt2__.m scripts/plot/__plt2mm__.m scripts/plot/__plt2mv__.m scripts/plot/__plt2ss__.m scripts/plot/__plt2vm__.m scripts/plot/__plt2vv__.m scripts/plot/__plt__.m
diffstat 11 files changed, 174 insertions(+), 120 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Jan 21 17:02:21 2005 +0000
+++ b/scripts/ChangeLog	Mon Jan 24 18:38:45 2005 +0000
@@ -1,3 +1,15 @@
+2005-01-24  John W. Eaton  <jwe@octave.org>
+
+	* plot/__plr2__.m, plot/__plt2__.m: Improve diagnostics.
+
+	* plot/__plr__.m: Use __plt__, not specific __pltXX__ functions.
+	* plot/__plt1__.m, plot/__plt2__.m, plot/__plt2mm__.m,
+	plot/__plt2mv__.m, plot/__plt2ss__.m, plot/__plt2vm__.m,
+	plot/__plt2vv__.m:
+	Return data and gnuplot commands instead of evaluating them.
+	* plot/__plt__.m: Handle evaluation of all gnuplot commands here.
+	Based on changes from Daniel J Sebald <daniel.sebald@ieee.org>.
+
 2005-01-18  John W. Eaton  <jwe@octave.org>
 
 	* linear-algebra/cross.m: Allocate idx1 before use.
--- a/scripts/plot/__plr2__.m	Fri Jan 21 17:02:21 2005 +0000
+++ b/scripts/plot/__plr2__.m	Mon Jan 24 18:38:45 2005 +0000
@@ -41,12 +41,14 @@
     if (isscalar (rho))
       x = rho * cos (theta);
       y = rho * sin (theta);
-      __plt2ss__ (x, y, fmt);
+      __plt__ (x, y, fmt);
+    else
+      error ("__plr2__: invalid data for plotting");
     endif
   elseif (isvector (theta))
     if (isvector (rho))
       if (length (theta) != length (rho))
-        error ("polar: vector lengths must match");
+        error ("__plr2__: vector lengths must match");
       endif
       if (rows (rho) == 1)
         rho = rho';
@@ -56,7 +58,7 @@
       endif
       x = rho .* cos (theta);
       y = rho .* sin (theta);
-      __plt2vv__ (x, y, fmt);
+      __plt__ (x, y, fmt);
     elseif (ismatrix (rho))
       [t_nr, t_nc] = size (theta);
       if (t_nr == 1)
@@ -73,11 +75,13 @@
         r_nc = tmp;
       endif
       if (t_nr != r_nr)
-        error ("polar: vector and matrix sizes must match");
+        error ("__plr2__: vector and matrix sizes must match");
       endif
       x = diag (cos (theta)) * rho;
       y = diag (sin (theta)) * rho;
-      __plt2vm__ (x, y, fmt);
+      __plt__ (x, y, fmt);
+    else
+      error ("__plr2__: invalid data for plotting")
     endif
   elseif (ismatrix (theta))
     if (isvector (rho))
@@ -96,20 +100,24 @@
         t_nc = tmp;
       endif
       if (r_nr != t_nr)
-        error ("polar: vector and matrix sizes must match");
+        error ("__plr2__: vector and matrix sizes must match");
       endif
       diag_r = diag (rho);
       x = diag_r * cos (theta);
       y = diag_r * sin (theta);
-      __plt2mv__ (x, y, fmt);
+      __plt__ (x, y, fmt);
     elseif (ismatrix (rho))
       if (size (rho) != size (theta))
-        error ("polar: matrix dimensions must match");
+        error ("__plr2__: matrix dimensions must match");
       endif
       x = rho .* cos (theta);
       y = rho .* sin (theta);
-      __plt2mm__ (x, y, fmt);
+      __plt__ (x, y, fmt);
+    else
+      error ("__plr2__: invalid data for plotting")
     endif
+  else
+    error ("__plr2__: invalid data for plotting")
   endif
 
 endfunction
--- a/scripts/plot/__plr__.m	Fri Jan 21 17:02:21 2005 +0000
+++ b/scripts/plot/__plr__.m	Mon Jan 24 18:38:45 2005 +0000
@@ -43,6 +43,11 @@
     endif
   endif
 
+  ## Note that we call __plt__ instead of __pltXX__ below, even though
+  ## we know the argument types.  This is so we don't have to duplicate
+  ## the functionality of __plt__ here (the __pltXX__ functions only
+  ## return data and fmtstr now).
+
   if (nargin <= 2)
     if (any (imag (theta)))
       theta = real (theta);
@@ -54,7 +59,7 @@
       if (isscalar (rho))
         x = rho * cos (theta);
         y = rho * sin (theta);
-        __plt2ss__ (x, y, fmt);
+        __plt__ (x, y, fmt);
       endif
     elseif (isvector (theta))
       if (isvector (rho))
@@ -69,7 +74,7 @@
         endif
         x = rho .* cos (theta);
         y = rho .* sin (theta);
-        __plt2vv__ (x, y, fmt);
+        __plt__ (x, y, fmt);
       elseif (ismatrix (rho))
         [t_nr, t_nc] = size (theta);
         if (t_nr == 1)
@@ -90,7 +95,7 @@
         endif
         x = diag (cos (theta)) * rho;
         y = diag (sin (theta)) * rho;
-        __plt2vm__ (x, y, fmt);
+        __plt__ (x, y, fmt);
       endif
     elseif (ismatrix (theta))
       if (isvector (rho))
@@ -114,14 +119,14 @@
         diag_r = diag (r);
         x = diag_r * cos (theta);
         y = diag_r * sin (theta);
-        __plt2mv__ (x, y, fmt);
+        __plt__ (x, y, fmt);
       elseif (ismatrix (rho))
         if (size (rho) != size (theta))
           error ("polar: matrix dimensions must match");
         endif
         x = rho .* cos (theta);
         y = rho .* sin (theta);
-        __plt2mm__ (x, y, fmt);
+        __plt__ (x, y, fmt);
       endif
     endif
   else
--- a/scripts/plot/__plt1__.m	Fri Jan 21 17:02:21 2005 +0000
+++ b/scripts/plot/__plt1__.m	Mon Jan 24 18:38:45 2005 +0000
@@ -18,15 +18,15 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt1__ (@var{x1}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt1__ (@var{x1}, @var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt1__ (x1, fmt)
+function [data, fmtstr] = __plt1__ (x1, fmt)
 
-  if (nargin < 1 || nargin > 2)
-    usage ("__plt1__ (x1, fmt)");
+  if (nargin < 1 || nargin > 2 || nargout != 2)
+    usage ("[data, fmtstr] = __plt1__ (x1, fmt)");
   endif
 
   if (nargin == 1)
@@ -53,6 +53,6 @@
     x1 = (1:nr)';
   endif
 
-  __plt2__ (x1, x2, fmt);
+  [data, fmtstr] = __plt2__ (x1, x2, fmt);
 
 endfunction
--- a/scripts/plot/__plt2__.m	Fri Jan 21 17:02:21 2005 +0000
+++ b/scripts/plot/__plt2__.m	Mon Jan 24 18:38:45 2005 +0000
@@ -18,15 +18,15 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2__ (@var{x1}, @var{x2}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt2__ (@var{x1}, @var{x2}, @var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt2__ (x1, x2, fmt)
+function [data, fmtstr] = __plt2__ (x1, x2, fmt)
 
-  if (nargin < 2 || nargin > 3)
-    usage ("__plt2__ (x1, x2, fmt)");
+  if (nargin < 2 || nargin > 3 || nargout != 2)
+    usage ("[data, fmtstr] = __plt2__ (x1, x2, fmt)");
   endif
 
   if (nargin == 2)
@@ -40,25 +40,35 @@
   if (any (any (imag (x1))))
     x1 = real (x1);
   endif
+
   if (any (any (imag (x2))))
     x2 = real (x2);
   endif
+
   if (isscalar (x1))
     if (isscalar (x2))
-      __plt2ss__ (x1, x2, fmt);
+      [data, fmtstr] = __plt2ss__ (x1, x2, fmt);
+    else
+      error ("__plt2__: invalid data for plotting");
     endif
   elseif (isvector (x1))
     if (isvector (x2))
-      __plt2vv__ (x1, x2, fmt);
+      [data, fmtstr] = __plt2vv__ (x1, x2, fmt);
     elseif (ismatrix (x2))
-      __plt2vm__ (x1, x2, fmt);
+      [data, fmtstr] = __plt2vm__ (x1, x2, fmt);
+    else
+      error ("__plt2__: invalid data for plotting");
     endif
   elseif (ismatrix (x1))
     if (isvector (x2))
-      __plt2mv__ (x1, x2, fmt);
+      [data, fmtstr] = __plt2mv__ (x1, x2, fmt);
     elseif (ismatrix (x2))
-      __plt2mm__ (x1, x2, fmt);
+      [data, fmtstr] = __plt2mm__ (x1, x2, fmt);
+    else
+      error ("__plt2__: invalid data for plotting");
     endif
+  else
+    error ("__plt2__: invalid data for plotting");
   endif
 
 endfunction
--- a/scripts/plot/__plt2mm__.m	Fri Jan 21 17:02:21 2005 +0000
+++ b/scripts/plot/__plt2mm__.m	Mon Jan 24 18:38:45 2005 +0000
@@ -18,18 +18,16 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2mm__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt2mm__ (@var{x}, @var{y}, @var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt2mm__ (x, y, fmt)
+function [data, fmtstr] = __plt2mm__ (x, y, fmt)
 
-  if (nargin < 2 || nargin > 3)
-    msg = sprintf ("__plt2mm__ (x, y)\n");
-    msg = sprintf ("%s              __plt2mm__ (x, y, fmt)", msg);
-    usage (msg);
-  elseif (nargin == 2 || fmt == "")
+  if (nargin < 2 || nargin > 3 || nargout != 2)
+    usage ("[data, fmtstr] = __plt2mm__ (x, y, fmt)");
+  elseif (nargin == 2 || isempty (fmt))
     fmt = " ";  ## Yes, this is intentionally not an empty string!
   endif
 
@@ -40,20 +38,18 @@
   fmt_nr = rows (fmt);
   if (x_nr == y_nr && x_nc == y_nc)
     if (x_nc > 0)
-      tmp = [x, y];
-      cmd = sprintf ("gplot tmp(:,%d:%d:%d) %s", 1, x_nc, x_nc+1,
-                     deblank (fmt (k, :)));
-      if (k < fmt_nr)
-        k++;
+      if (rows (fmt) == 1)
+	fmt = repmat (fmt, x_nc, 1);
       endif
-      for i = 2:x_nc
-        cmd = sprintf ("%s, tmp(:,%d:%d:%d) %s", cmd, i, x_nc, x_nc+i,
-                       deblank (fmt (k, :)));
-        if (k < fmt_nr)
-          k++;
-        endif
+      tmp = [x, y];
+      dtmp = cell (x_nc, 1);
+      ftmp = cell (x_nc, 1);
+      for i = 1:x_nc
+	dtmp{i} = tmp(:,[i,x_nc+i]);
+	ftmp{i} = deblank (fmt(i,:));
       endfor
-      eval (cmd);
+      data = dtmp;
+      fmtstr = ftmp;
     else
       error ("__plt2mm__: arguments must be a matrices");
     endif
--- a/scripts/plot/__plt2mv__.m	Fri Jan 21 17:02:21 2005 +0000
+++ b/scripts/plot/__plt2mv__.m	Mon Jan 24 18:38:45 2005 +0000
@@ -18,18 +18,16 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2mv__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt2mv__ (@var{x}, @var{y}, @var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt2mv__ (x, y, fmt)
+function [data, fmtstr] = __plt2mv__ (x, y, fmt)
 
-  if (nargin < 2 || nargin > 3)
-    msg = sprintf ("__plt2mv__ (x, y)\n");
-    msg = sprintf ("%s              __plt2mv__ (x, y, fmt)", msg);
-    usage (msg);
-  elseif (nargin == 2 || fmt == "")
+  if (nargin < 2 || nargin > 3 || nargout != 2)
+    usage ("[data, fmtstr] = __plt2mv__ (x, y, fmt)");
+  elseif (nargin == 2 || isempty (fmt))
     fmt = " ";  ## Yes, this is intentionally not an empty string!
   endif
 
@@ -54,23 +52,19 @@
     error ("__plt2mv__: matrix dimensions must match");
   endif
 
-  k = 1;
-  fmt_nr = rows (fmt);
   if (x_nc > 0)
-    tmp = [x, y];
-    cmd = sprintf ("gplot tmp(:,%d:%d:%d) %s", 1, x_nc, x_nc+1,
-                   deblank (fmt (k, :)));
-    if (k < fmt_nr)
-      k++;
+    if (rows (fmt) == 1)
+      fmt = repmat (fmt, x_nc, 1);
     endif
-    for i = 2:x_nc
-      cmd = sprintf ("%s, tmp(:,%d:%d:%d) %s", cmd, i, x_nc-i+1, x_nc+1,
-                     deblank (fmt (k, :)));
-      if (k < fmt_nr)
-        k++;
-      endif
+    tmp = [x, y];
+    dtmp = cell (x_nc, 1);
+    ftmp = cell (x_nc, 1);
+    for i = 1:x_nc
+      dtmp{i} = tmp(:,[i,x_nc+1]);
+      ftmp{i} = deblank (fmt(i,:));
     endfor
-    eval (cmd);
+    data = dtmp;
+    fmtstr = ftmp;
   else
     error ("__plt2mv__: arguments must be a matrices");
   endif
--- a/scripts/plot/__plt2ss__.m	Fri Jan 21 17:02:21 2005 +0000
+++ b/scripts/plot/__plt2ss__.m	Mon Jan 24 18:38:45 2005 +0000
@@ -18,17 +18,15 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2ss__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt2ss__ (@var{x}, @var{y}, @var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt2ss__ (x, y, fmt)
+function [data, fmtstr] = __plt2ss__ (x, y, fmt)
 
-  if (nargin < 2 || nargin > 3)
-    msg = sprintf ("__plt2ss__ (x, y)");
-    msg = sprintf ("%s              __plt2ss__ (x, y, fmt)", msg);
-    usage (msg);
+  if (nargin < 2 || nargin > 3 || nargout != 2)
+    usage ("[data, fmtstr] = __plt2ss__ (x, y, fmt)");
   elseif (nargin == 2)
     fmt = "";
   elseif (rows (fmt) > 1)
@@ -40,8 +38,8 @@
 
   if (x_nr == 1 && x_nr == y_nr && x_nc == 1 && x_nc == y_nc)
     tmp = [x, y];
-    cmd = sprintf ("gplot tmp %s", fmt);
-    eval (cmd);
+    data = tmp;
+    fmtstr = fmt;
   else
     error ("__plt2ss__: arguments must be scalars");
   endif
--- a/scripts/plot/__plt2vm__.m	Fri Jan 21 17:02:21 2005 +0000
+++ b/scripts/plot/__plt2vm__.m	Mon Jan 24 18:38:45 2005 +0000
@@ -18,18 +18,16 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2vm__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt2vm__ (@var{x}, @var{y}, @var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt2vm__ (x, y, fmt)
+function [data, fmtstr] = __plt2vm__ (x, y, fmt)
 
-  if (nargin < 2 || nargin > 3)
-    msg = sprintf ("__plt2vm__ (x, y)\n");
-    msg = sprintf ("%s              __plt2vm__ (x, y, fmt)", msg);
-    usage (msg);
-  elseif (nargin == 2 || fmt == "")
+  if (nargin < 2 || nargin > 3 || nargout != 2)
+    usage ("[data, fmtstr] = __plt2vm__ (x, y, fmt)");
+  elseif (nargin == 2 || isempty (fmt))
     fmt = " ";  ## Yes, this is intentionally not an empty string!
   endif
 
@@ -54,23 +52,19 @@
     error ("__plt2vm__: matrix dimensions must match");
   endif
 
-  k = 1;
-  fmt_nr = rows (fmt);
   if (y_nc > 0)
-    tmp = [x, y];
-    cmd = sprintf ("gplot tmp(:,%d:%d:%d) %s", 1, x_nc, x_nc+1,
-                   deblank (fmt (k, :)));
-    if (k < fmt_nr)
-      k++;
+    if (rows (fmt) == 1)
+      fmt = repmat (fmt, y_nc, 1);
     endif
-    for i = 2:y_nc
-      cmd = sprintf ("%s, tmp(:,%d:%d:%d) %s", cmd, 1, i, i+1,
-                     deblank (fmt (k, :)));
-      if (k < fmt_nr)
-        k++;
-      endif
+    tmp = [x, y];
+    dtmp = cell (y_nc, 1);
+    ftmp = cell (y_nc, 1);
+    for i = 1:y_nc
+      dtmp{i} = tmp(:,[1,i+1]);
+      ftmp{i} = deblank (fmt(i,:));
     endfor
-    eval (cmd);
+    data = dtmp;
+    fmtstr = ftmp;
   else
     error ("__plt2vm__: arguments must be a matrices");
   endif
--- a/scripts/plot/__plt2vv__.m	Fri Jan 21 17:02:21 2005 +0000
+++ b/scripts/plot/__plt2vv__.m	Mon Jan 24 18:38:45 2005 +0000
@@ -18,17 +18,15 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2vv__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt2vv__ (@var{x}, @var{y}, @var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt2vv__ (x, y, fmt)
+function [data, fmtstr] = __plt2vv__ (x, y, fmt)
 
-  if (nargin < 2 || nargin > 3)
-    msg = sprintf ("__plt2vv__ (x, y)\n");
-    msg = sprintf ("%s              __plt2vv__ (x, y, fmt)", msg);
-    usage (msg);
+  if (nargin < 2 || nargin > 3 || nargout != 2)
+    usage ("[data, fmtstr] = __plt2vv__ (x, y, fmt)");
   elseif (nargin == 2)
     fmt = "";
   elseif (rows (fmt) > 1)
@@ -56,8 +54,7 @@
     error ("__plt2vv__: vector lengths must match");
   endif
 
-  tmp = [x, y];
-  cmd = sprintf ("gplot tmp %s", fmt);
-  eval (cmd);
+  data = [x, y];
+  fmtstr = fmt;
 
 endfunction
--- a/scripts/plot/__plt__.m	Fri Jan 21 17:02:21 2005 +0000
+++ b/scripts/plot/__plt__.m	Mon Jan 24 18:38:45 2005 +0000
@@ -27,11 +27,7 @@
 
   nargs = nargin ();
 
-  if (nargs == 2)
-
-    __plt1__ (varargin{1}, "");
-
-  elseif (nargs > 2)
+  if (nargs >= 2)
 
     first_plot = 1;
     hold_state = ishold ();
@@ -39,35 +35,64 @@
     unwind_protect
 
       k = 1;
+      j = 1;
       x = varargin{k++};
       nargs -= 2;
       x_set = 1;
       y_set = 0;
+      gp_cmd = "gplot";
+      have_gp_cmd = false;
 
-      ## Gather arguments, decode format, and plot lines.
+      ## Gather arguments, decode format, gather plot strings, and plot lines.
 
       while (nargs-- > 0)
 
         fmt = "";
         new = varargin{k++};
 
+        if (j > 1)
+          sep = ",\\\n";
+        else
+          sep = "";
+        endif
+
         if (isstr (new))
           if (! x_set)
             error ("plot: no data to plot");
           endif
           fmt = __pltopt__ (caller, new);
           if (! y_set)
-            __plt1__ (x, fmt);
+            [data{j}, fmtstr] = __plt1__ (x, fmt);
           else
-            __plt2__ (x, y, fmt);
+            [data{j}, fmtstr] = __plt2__ (x, y, fmt);
           endif
-          hold on;
+	  if (iscell (data{j}))
+	    for i = 1:length (data{j})
+	      gp_cmd = sprintf ("%s%s data{%d}{%d} %s", gp_cmd, sep,
+				j, i, fmtstr{i});
+	      sep = ",\\\n";
+	      have_gp_cmd = true;
+	    endfor
+	  else
+            gp_cmd = sprintf ("%s%s data{%d} %s", gp_cmd, sep, j++, fmtstr);
+	    have_gp_cmd = true;
+          endif
           x_set = 0;
           y_set = 0;
         elseif (x_set)
           if (y_set)
-            __plt2__ (x, y, fmt);
-            hold on;
+            [data{j}, fmtstr] = __plt2__ (x, y, fmt);
+	    if (iscell (data{j}))
+	      for i = 1:length (data{j})
+		gp_cmd = sprintf ("%s%s data{%d}{%d} %s", gp_cmd, sep,
+				  j, i, fmtstr{i});
+		sep = ",\\\n";
+		have_gp_cmd = true;
+	      endfor
+	    else
+	      gp_cmd = sprintf ("%s%s data{%d} %s", gp_cmd, sep, j++, fmtstr);
+	      have_gp_cmd = true;
+	    endif
             x = new;
             y_set = 0;
           else
@@ -83,12 +108,27 @@
 
       ## Handle last plot.
 
-      if  (x_set)
+      if (x_set)
         if (y_set)
-          __plt2__ (x, y, fmt);
+          [data{j}, fmtstr] = __plt2__ (x, y, fmt);
         else
-          __plt1__ (x, fmt);
+          [data{j}, fmtstr] = __plt1__ (x, fmt);
         endif
+	if (iscell (data{j}))
+	  for i = 1:length (data{j})
+	    gp_cmd = sprintf ("%s%s data{%d}{%d} %s", gp_cmd, sep,
+			      j, i, fmtstr{i});
+	    sep = ",\\\n";
+	    have_gp_cmd = true;
+	  endfor
+	else
+	  gp_cmd = sprintf ("%s%s data{%d} %s", gp_cmd, sep, j++, fmtstr);
+	  have_gp_cmd = true;
+        endif
+      endif
+
+      if (have_gp_cmd)
+        eval (gp_cmd);
       endif
 
     unwind_protect_cleanup