changeset 6257:44c91c5dfe1d

[project @ 2007-01-30 19:16:52 by jwe]
author jwe
date Tue, 30 Jan 2007 19:16:55 +0000
parents 83949ae13b2c
children ea3a7e8469e9
files doc/ChangeLog doc/interpreter/sparseimages.m scripts/ChangeLog scripts/image/__img_gnuplot__.m scripts/image/__img_via_file__.m scripts/image/colormap.m scripts/image/gray.m scripts/image/image.m scripts/image/image_viewer.m scripts/image/ocean.m scripts/miscellaneous/delete.m scripts/move-if-change scripts/plot/Makefile.in scripts/plot/__axis_label__.m scripts/plot/__default_colormap__.m scripts/plot/__do_legend__.m scripts/plot/__errcomm__.m scripts/plot/__errplot__.m scripts/plot/__gnuplot_version__.m scripts/plot/__init_plot_vars__.m scripts/plot/__make_using_clause__.m scripts/plot/__plot_globals__.m scripts/plot/__plr1__.m 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/__plt3__.m scripts/plot/__plt__.m scripts/plot/__plt_get_axis_arg__.m scripts/plot/__render_plot1__.m scripts/plot/__render_plot__.m scripts/plot/__setup_plot__.m scripts/plot/__uiobject_adopt__.m scripts/plot/__uiobject_alloc__.in scripts/plot/__uiobject_axes_ctor__.m scripts/plot/__uiobject_axes_dtor__.m scripts/plot/__uiobject_axes_init__.in scripts/plot/__uiobject_axes_setr__.m scripts/plot/__uiobject_delete__.m scripts/plot/__uiobject_draw_axes__.m scripts/plot/__uiobject_draw_figure__.m scripts/plot/__uiobject_figure_ctor__.m scripts/plot/__uiobject_figures__.in scripts/plot/__uiobject_free__.in scripts/plot/__uiobject_get_handle__.in scripts/plot/__uiobject_globals__.m scripts/plot/__uiobject_grow_list__.in scripts/plot/__uiobject_handle2idx__.in scripts/plot/__uiobject_image_ctor__.m scripts/plot/__uiobject_init_figure__.in scripts/plot/__uiobject_init_root_figure__.in scripts/plot/__uiobject_line_ctor__.m scripts/plot/__uiobject_make_handle__.in scripts/plot/__uiobject_root_figure_ctor__.m scripts/plot/__uiobject_surface_ctor__.m scripts/plot/__uiobject_text_ctor__.m scripts/plot/axes.m scripts/plot/axis.m scripts/plot/box.m scripts/plot/clf.m scripts/plot/close.m scripts/plot/closereq.m scripts/plot/contour.m scripts/plot/contourc.m scripts/plot/drawnow.m scripts/plot/errorbar.m scripts/plot/figure.m scripts/plot/gca.m scripts/plot/gcf.m scripts/plot/get.in scripts/plot/grid.m scripts/plot/hold.m scripts/plot/include-globals.awk scripts/plot/isfigure.m scripts/plot/ishandle.m scripts/plot/ishold.m scripts/plot/legend.m scripts/plot/line.m scripts/plot/loglog.m scripts/plot/loglogerr.m scripts/plot/mesh.m scripts/plot/mplot.m scripts/plot/multiplot.m scripts/plot/newplot.m scripts/plot/oneplot.m scripts/plot/orient.m scripts/plot/plot.m scripts/plot/plot3.m scripts/plot/plot_border.m scripts/plot/polar.m scripts/plot/print.m scripts/plot/replot.m scripts/plot/semilogx.m scripts/plot/semilogxerr.m scripts/plot/semilogy.m scripts/plot/semilogyerr.m scripts/plot/set.in scripts/plot/shg.m scripts/plot/stairs.m scripts/plot/subplot.m scripts/plot/subwindow.m scripts/plot/text.m scripts/plot/title.m scripts/plot/view.m scripts/plot/xlabel.m scripts/plot/ylabel.m scripts/plot/zlabel.m src/ChangeLog src/DLD-FUNCTIONS/__contourc__.cc src/Makefile.in src/input.cc src/ls-oct-ascii.cc src/pt-id.cc src/symtab.cc src/symtab.h src/variables.cc test/ChangeLog test/Makefile.in test/fntests.m
diffstat 125 files changed, 4534 insertions(+), 2314 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Tue Jan 30 18:45:59 2007 +0000
+++ b/doc/ChangeLog	Tue Jan 30 19:16:55 2007 +0000
@@ -1,3 +1,7 @@
+2007-01-25  John W. Eaton  <jwe@octave.org>
+
+	* interpreter/sparseimages.m: Don't call __gnuplot_x__ functions.
+
 2006-11-17  John W. Eaton  <jwe@octave.org>
 
 	* interpreter/sparseimages.m: Fix call to __plt3__.
--- a/doc/interpreter/sparseimages.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/doc/interpreter/sparseimages.m	Tue Jan 30 19:16:55 2007 +0000
@@ -23,12 +23,8 @@
 ## print since print() resets output to stdout (unfortunately, gnpulot
 ## can't pop output as it can the terminal type).
 function bury_output ()
-  automatic_replot (0);
-  __gnuplot_set__ term dumb
-  [status, dummy] = fileattrib ("/dev/null");
-  if (status)
-    __gnuplot_raw__ ("set output \"/dev/null\"\n");
-  endif
+  f = figure (1);
+  set (f, "visible", "off");
 endfunction
 
 function gplotimages (nm, typ)
@@ -209,8 +205,8 @@
 
     sz = size(xelems,2);
 
-    __gnuplot_raw__ ("set view 80,10;\n")
     plot3 (xelems, yelems, velems);
+    view (10, 10);
     print(strcat(nm,".",typ),strcat("-d",typ))
     bury_output ();
   endif
@@ -236,28 +232,9 @@
     [xx, yy] = meshgrid (x, y);
     r = sqrt (xx .^ 2 + yy .^ 2) + eps;
     z = sin (r) ./ r;
-    xlen = length (x);
-    ylen = length (y);
-    len = 3 * xlen;
-    zz = zeros (ylen, len);
-    k = 1;
-    for i = 1:3:len
-      zz(:,i)   = x(k) * ones (ylen, 1);
-      zz(:,i+1) = y;
-      zz(:,i+2) = z(:,k);
-      k++;
-    endfor
     unwind_protect
-      __gnuplot_raw__ ("set hidden3d;\n");
-      __gnuplot_raw__ ("set data style lines;\n");
-      __gnuplot_raw__ ("set surface;\n");
-      __gnuplot_raw__ ("set nocontour;\n");
-      __gnuplot_raw__ ("set nologscale;\n");
-      __gnuplot_raw__ ("set view 60, 30, 1, 1;\n");
-      __gnuplot_raw__ ("set nokey;\n");
-      __gnuplot_raw__ ("set nocolorbox;\n");
-      __gnuplot_raw__ ("set title \"Sorry, graphics not available because octave was\\ncompiled without the sparse matrix implementation.\";\n");
-      __plt3__ (zz, true, "", "", "", "");
+      mesh (x, y, z);
+      title ("Sorry, graphics not available because octave was\\ncompiled without the sparse matrix implementation.");
     unwind_protect_cleanup
       print (strcat (nm, ".", typ), strcat ("-d", typ));
       bury_output ();
--- a/scripts/ChangeLog	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/ChangeLog	Tue Jan 30 19:16:55 2007 +0000
@@ -1,3 +1,4 @@
+<<<<<<< ChangeLog
 2007-01-24  David Bateman  <dbateman@free.fr>
 
 	* pkg/pkg.m: Install ChangeLog file if it exists.
@@ -79,6 +80,231 @@
 
 	* sparse/normest.m: New file.
 
+=======
+2007-01-29  John W. Eaton  <jwe@octave.org>
+
+	* plot/subplot.m: Set nextplot property of current figure to "add".
+
+	* plot/__uiobject_draw_axes__.m: Only handle outerposition
+	property if it exists.
+
+2007-01-26  John W. Eaton  <jwe@octave.org>
+
+	* plot/__uiobject_draw_axes__.m: Move initialization of max and
+	min values outside of loop over child objects.
+
+	* plot/contour.m, plot/contourc.m: New files.
+	* plot/Makefile.in (SOURCES_M): Add them to the list.
+
+	* image/image_viewer.m: Set view_fcn to "gnuplot_internal" if we
+	find a gnuplot version newer than 4.0.
+	* image/__img_gnuplot__.m: Delete.
+	* image/image.m: Create image graphics object.
+	Call newplot to setup and drawnow to finish.
+	Eliminate ZOOM arg.
+
+	* plot/__uiobject_draw_axes__.m: Handle image data.
+
+	* plot/legend.m: Eliminate useless variable "warned".
+
+	* plot/__uiobject_image_ctor__.m: New file.
+	* plot/Makefile.in (SOURCES_M): Add it to the list.
+
+	* plot/gcf.m: Also create new figure if currentfigure is 0.
+	* plot/drawnow.m: Use get (0, "currentfigure") instead of gcf.
+
+	* plot/__uiobject_root_figure_ctor__.m: Set visible property.
+
+	* plot/__default_colormap__.m: New file.
+	* plot/Makefile.in (SOURCES_M): Add it to the list.
+	* plot/__uiobject_figure_ctor__.m: Use it to set default colormap
+	property.
+	* image/colormap.m: Use colormap property of current figure
+	to store colormap instead of using persistent variable.
+	Call __default_colormap__ to get default map value.
+	* image/ocean.m, image/gray.m: Set colormap for current figure.
+
+	* plot/__uiobject_draw_axes__.m: Handle aspect ratio property.
+	Handle some tick mark options.
+
+	* plot/__uiobject_axes_setr__.m: If we see xtick, ytick, or ztick,
+	set corresponding *mode to "manual".  If we set dataaspectratio,
+	set dataaspectratiomode to "manual".
+
+	* plot/__uiobject_axes_init__.m: Include *tick, *tickmode,
+	*ticklabelmode, dataaspectratio, dataaspectratiomode properties.
+
+	* plot/axis.m: New file.
+	* plot/Makefile.in (SOURCES_M): Include it in the list.
+
+	* plot/__uiobject_axes_setr__.m: If we see xlim, ylim, or zlim,
+	set corresponding *limmode to "manual".
+	* plot/__uiobject_draw_axes__.m	(get_axis_limits): New subfunction.
+	Use it to compute autosclaled limits.
+	Arg is now handle, not object.  Change all callers.
+	Compute data limits.
+
+2007-01-25  John W. Eaton  <jwe@octave.org>
+
+	* plot/drawnow: Fix visibility check for zero args.
+
+	* plot/text.m: New file.
+	* plot/Makefile.in (SOURCES_M): Add it to the list.
+	* plot/__uiobject_draw_axes__.m: Handle text objects.
+	* plot/__uiobject_text_ctor__.m: Include units, position, and
+	horizontalalignment properties.
+
+	* plot/figure.m: Set options for f we just constructed or were
+	given as an argument, not gcf.  Only return handle if nargout > 0.	
+
+	* plot/drawnow.m: Handle visible field for figure here.
+	* plot/__uiobject_figure_ctor__.m: Set default visible field.
+
+	* plot/__uiobject_draw_axes__.m: Call undo_string_escapes on
+	title and axis labels.
+
+	* plot/plot3.m, plot/mesh.m: Set default 3-d view here.
+	* plot/__uiobject_draw_axes__.m: Handle view for 3-d plots.
+	* plot/__uiobject_axes_init__.in: Set default view field for object.
+	* plot/view.m: New file.
+	* plot/Makefile.in (SOURCES_M): Add it to the list.
+
+	* plot/__uiobject_make_handle__.in, plot/set.m, plot/drawnow.m:
+	Call __request_drawnow__.
+
+	* plot/newplot.m: For "replace" action, call __uiobject_axes_init__.
+
+	* plot/__uiobject_axes_ctor__.m, plot/__uiobject_text_ctor__.m:
+	Call set to set properties.  Return handle instead of structure.
+	Change all callers.
+
+	* plot/__uiobject_axes_setr__.m: New file.
+	* plot/set.in: Check for __setter__ field.
+
+	* plot/__uiobject_axes_init__.in:
+	Rename from plot/__uiobject_axes_init__.m.
+	Include __uiobject_globals__.
+	Accept handle as arg instead of structure
+	* plot/Makefile.in (SOURCES_M): Remove __uiobject_axes_init__.m
+	from the list.
+	(SOURCES_IN): Add __uiobject_axes_init__.in to the list.
+
+2007-01-24  John W. Eaton  <jwe@octave.org>
+
+	* plot/Makefile.in ($(GEN_M)): Depend on __uiobject_globals__.m.
+
+	* plot/__uiobject_globals__.m: Call __lock_global__ when
+	initializing each global variable.
+
+2007-01-18  John W. Eaton  <jwe@octave.org>
+
+	* plot/__uiobject_globals__.m (__uiobject_handles_free_list__,
+	__uiobject_figure_handles_free_list__): New global variables.
+	* plot/__uiobject_get_handle__.m, plot/__uiobject_free__.m:
+	Place unused handles on the free list.
+
+	* plot/__uiobject_get_figure_handle__.in: Delete.
+	* plot/Makefile.in: Delete it from the SOURCES_IN list.
+
+	* plot/__uiobject_init_figure__.in: Perform allocation of figure
+	handles here.  Return figure handle.
+	* plot/figure.m: Call __uiobject_init_figure__ to allocate handle.
+
+2007-01-11  John W. Eaton  <jwe@octave.org>
+
+	* plot/__uiobject_draw_axes__.m: Use "%g", not "%.4g" when writing
+	data for gnuplot.
+
+	* plot/Makefile.in (SOURCES_M, SOURCES_IN, GEN_M): New lists of
+	files.
+	(SOURCES): Include $(SOURCES_M) and $(SOURCES_M) in the list.
+	(DISTFILES): Include include-globals.awk in the list.
+	(FCN_FILES): Define using $(SOURCES_M) and $(GEN_M).
+	($(GEN_M) : %.m : %.in): New rule.
+
+	* include-globals.awk: New file.
+
+	* plot/__uiobject_alloc__.in, plot/__uiobject_figures__.in, 
+	plot/__uiobject_free__.in, plot/__uiobject_get_figure_handle__.in, 
+	plot/__uiobject_get_handle__.in, plot/__uiobject_grow_list__.in, 
+	plot/__uiobject_handle2idx__.in, plot/__uiobject_init_figure__.in, 
+	plot/__uiobject_init_root_figure__.in,
+	plot/__uiobject_make_handle__.in,  plot/get.in, plot/set.in:
+	Rename from corresponding .m files.
+
+	* move-if-change: New file.
+
+	* plot/__uiobject_delete__.m: New file.
+	* plot/delete.m, plot/__uiobject_delete_children__.m,
+	plot/__uiobject_delete_child__.m: Delete.
+	* miscellaneous/delete.m: Forward to __uiobject_delete__ if arg is
+	not a character string.
+	* plot/__plt2mm__.m, plot/__plt2mv__.m, plot/__plt2vm__.m:
+	Fix assignment to tmp key value in loop.
+	* plot/__uiobject_axes_dtor__.m: No need to Call __uiobject_free__
+	for obj.title, obj.xlabel, obj.ylabel, obj.zlabel.
+	* plot/__uiobject_axes_dtor__.m, plot/__uiobject_axis_init__.m:
+	Inline code to delete children.
+	* plot/__uiobject_free__.m: Arg is now handle, not index into
+	__uiobject_list__.
+	* plot/clf.m, plot/closereq.m, plot/newplot.m: No need to remove
+	and free child.
+
+2006-12-08  John W. Eaton  <jwe@octave.org>
+
+	* plot/gcf.m: Check if the root figure object's currentfigure
+	handle is empty, not 0.
+	* plot/__uiobject_root_figure_ctor__.m:
+	Set currentfigure to [], not 0.
+
+	* plot/stairs.m: Handle matrix arguments.  Improve compatibility.
+
+2006-12-07  John W. Eaton  <jwe@octave.org>
+
+	* plot/__plt_get_axis_arg__.m, plot/__uiobject_adopt__.m,
+	plot/__uiobject_alloc__.m, plot/__uiobject_axes_ctor__.m,
+	plot/__uiobject_axes_dtor__.m, plot/__uiobject_axes_init__.m,
+	plot/__uiobject_delete_children__.m,
+	plot/__uiobject_draw_axes__.m, plot/__uiobject_draw_figure__.m,
+	plot/__uiobject_figure_ctor__.m, plot/__uiobject_figures__.m,
+	plot/__uiobject_free__.m, plot/__uiobject_get_figure_handle__.m,
+	plot/__uiobject_get_handle__.m, plot/__uiobject_globals__.m,
+	plot/__uiobject_grow_list__.m, plot/__uiobject_handle2idx__.m,
+	plot/__uiobject_init_figure__.m,
+	plot/__uiobject_init_root_figure__.m,
+	plot/__uiobject_line_ctor__.m, plot/__uiobject_make_handle__.m,
+	plot/__uiobject_remove_child__.m,
+	plot/__uiobject_root_figure_ctor__.m,
+	plot/__uiobject_surface_ctor__.m, plot/__uiobject_text_ctor__.m,
+	plot/axes.m, plot/box.m, plot/closereq.m, plot/delete.m,
+	plot/drawnow.m, plot/gca.m, plot/gcf.m, plot/get.m,
+	plot/isfigure.m, plot/ishandle.m, plot/line.m, plot/newplot.m,
+	plot/set.m: New files.
+
+	* plot/__plt3__.m, plot/errorbar.m, plot/__axis_label__.m,
+	plot/__plr1__.m, plot/__errcomm__.m, plot/print.m, plot/zlabel.m,
+	plot/__plt1__.m, plot/__plt2__.m, plot/sombrero.m, plot/shg.m,
+	plot/fplot.m, plot/ndgrid.m, plot/clf.m, plot/hold.m,
+	plot/ishold.m, plot/meshdom.m, plot/ylabel.m, plot/__plt2ss__.m,
+	plot/__plt2vv__.m, plot/__plr2__.m, plot/__plt2mm__.m,
+	plot/__pltopt1__.m, plot/meshgrid.m, plot/__plt2mv__.m,
+	plot/figure.m, plot/xlabel.m, plot/stairs.m, plot/__plt2vm__.m,
+	plot/bar.m, plot/__errplot__.m, plot/semilogx.m, plot/semilogy.m,
+	plot/loglog.m, plot/polar.m, plot/legend.m, plot/orient.m,
+	plot/title.m, plot/__pltopt__.m, plot/grid.m, plot/hist.m,
+	plot/subplot.m, plot/plot.m, plot/mesh.m, plot/__plt__.m,
+	plot/close.m, plot/loglogerr.m, plot/plot3.m, plot/semilogxerr.m,
+	plot/semilogyerr.m, plot/replot.m:
+	Adapt to new graphics data structure.
+
+	* plot/__do_legend__.m, plot/__gnuplot_version__.m,
+	plot/__init_plot_vars__.m, plot/__make_using_clause__.m,
+	plot/__plot_globals__.m, plot/__plr__.m, plot/__render_plot1__.m,
+	plot/__render_plot__.m, plot/__setup_plot__.m, plot/axis.m,
+	plot/contour.m, plot/mplot.m, plot/multiplot.m, plot/oneplot.m,
+	plot/plot_border.m, plot/subwindow.m: Delete.
+
+>>>>>>> 1.656.2.18
 2006-12-06  Michael Goffioul  <michael.goffioul@swing.be>.
 
 	* miscellaneous/copyfile.m, miscellaneous/movefile.m:
--- a/scripts/image/__img_gnuplot__.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,96 +0,0 @@
-## Copyright (C) 2006 Daniel Sebald
-##
-## 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, 59 Temple Place - Suite 330, Boston, MA
-## 02111-1307, USA.
-
-## -*- texinfo -*-
-## @deftypefn {Function File} {} __img_gnuplot__ (@var{x}, @var{y}, @var{A})
-## Display an image using @code{gnuplot}, where vectors @var{x} and
-## @var{y} define the axes and the matrix @var{A} contains the image
-## data.
-## @end deftypefn
-
-function __img_gnuplot__ (x, y, A, zoom)
-
-  ## ZOOM is ignored.
-
-  __plot_globals__;
-
-  cf = __current_figure__;
-  mxi = __multiplot_xi__(cf);
-  myi = __multiplot_yi__(cf);
-
-  __setup_plot__ ("plot");
-
-  if (nargin < 3)
-    print_usage ();
-  endif
-
-  if (isempty (A))
-    error ("__img_gnuplot__: matrix is empty");
-  endif
-
-  ## Use the newly added mode of "plot" called "with image".
-  if (isempty (x))
-    x = [1, columns(A)];
-    y = [1, rows(A)];
-  endif
-
-  ## Force rectangular grid by using only end points of
-  ## first row (column) if x (y) is a matrix or vector.
-  if (columns (x) > 1)
-    x = x(1,:)';
-  endif
-  if (abs (x(end) - x(1)) < 10*eps)
-    error ("__img_gnuplot__: end points in x dimension must not be equal");
-  else
-    x_dim = size (A, 2);
-    if (x_dim > 1)
-      dx = abs (x(end)-x(1))/(x_dim-1);
-    else
-      dx = 1;
-    endif
-  endif
-  if (rows (y) > 1)
-    y = y(:,1)';
-  endif
-  if (abs (y(end) - y(1)) < 10*eps)
-    error ("__img_gnuplot__: end points in y dimension must not be equal");
-  else
-    y_dim = size (A, 1);
-    if (y_dim > 1)
-      dy = abs (y(end)-y(1))/(y_dim-1);
-    else
-      dy = 1;
-    endif
-  endif
-
-  x_origin = min (x(1), x(end));
-  y_origin = min (y(1), y(end));
-
-  j = __plot_data_offset__{cf}(mxi,myi);
-
-  __plot_data__{cf}{mxi,myi}{j}{1} = A;
-  __plot_data_type__{cf}{mxi,myi}(j) = 1;
-  __plot_key_labels__{cf}{mxi,myi}{j}{1} = "";
-  __plot_image_colormap__{cf}{mxi,myi} = colormap ();
-  __plot_image_dims__{cf}{mxi,myi}{j}{1} ...
-      = [x_dim, y_dim, x_origin, y_origin, dx, dy];
-
-  __plot_data_offset__{cf}(mxi,myi) = ++j;
-
-  __render_plot__ ();
-
-endfunction
--- a/scripts/image/__img_via_file__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/image/__img_via_file__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -40,7 +40,7 @@
     ## Different image viewer commands.
     xv = sprintf ("xv -raw -expand %f \"%s\"", zoom, ppm_name);
     xloadimage = sprintf ("xloadimage -zoom %f \"%s\"", zoom*100, ppm_name);
-    im_display = sprintf ("display -geometry %f%% \"%s\"", zoom*100, ppm_name);
+    im_display = sprintf ("display -resize %f%% \"%s\"", zoom*100, ppm_name);
   
     ## Need to let the shell clean up the tmp file because we are putting
     ## the viewer in the background.
@@ -53,7 +53,7 @@
     else
       command = sprintf (command, ppm_name);
     endif
-    status = system (sprintf ("( %s && %s) > /dev/null 2>&1 &", command, rm));
+    status = system (sprintf ("( %s && %s) > /dev/null 2>&1 &", command, rm))
   endif
   
   ## Did the system call fail?
--- a/scripts/image/colormap.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/image/colormap.m	Tue Jan 30 19:16:55 2007 +0000
@@ -39,8 +39,6 @@
 
 function cmap = colormap (map)
 
-  persistent current_color_map = gray ();
-
   if (nargin > 1)
     print_usage ();
   endif
@@ -49,9 +47,9 @@
 
     if (ischar (map))
       if (strcmp (map, "default"))
-        map = gray ();
+        map = __default_colormap__ ();
       else
-        map = eval (map);
+        map = feval (map);
       endif
     endif
 
@@ -63,12 +61,12 @@
         error ("colormap: map must have values in [0,1]");
       endif
       ## Set the new color map
-      current_color_map = map;
+      set (gcf (), "colormap", map);
     endif
 
   endif
 
   ## Return current color map.
-  cmap = current_color_map;
+  cmap = get (gcf (), "colormap");
 
 endfunction
--- a/scripts/image/gray.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/image/gray.m	Tue Jan 30 19:16:55 2007 +0000
@@ -38,6 +38,6 @@
 
   gr = [0:(number-1)]';
 
-  map = [ gr, gr, gr ] / (number - 1);
+  map = colormap ([ gr, gr, gr ] / (number - 1));
 
 endfunction
--- a/scripts/image/image.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/image/image.m	Tue Jan 30 19:16:55 2007 +0000
@@ -18,12 +18,11 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} image (@var{x}, @var{zoom})
-## @deftypefnx {Function File} {} image (@var{x}, @var{y}, @var{A}, @var{zoom})
+## @deftypefn {Function File} {} image (@var{img})
+## @deftypefnx {Function File} {} image (@var{x}, @var{y}, @var{img})
 ## Display a matrix as a color image.  The elements of @var{x} are indices
 ## into the current colormap and should have values between 1 and the
-## length of the colormap.  If @var{zoom} is omitted, the image will be
-## scaled to fit within 600x350 (to a max of 4).
+## length of the colormap.
 ##
 ## It first tries to use @code{gnuplot}, then @code{display} from 
 ## @code{ImageMagick}, then @code{xv}, and then @code{xloadimage}.
@@ -40,42 +39,53 @@
 ## Created: July 1994
 ## Adapted-By: jwe
 
-function image (x, y, A, zoom)
+function image (x, y, img)
+
+  newplot ();
 
   if (nargin == 0)
     ## Load Bobbie Jo Richardson (Born 3/16/94)
-    A = loadimage ("default.img");
-    zoom = 2;
+    img = loadimage ("default.img");
     x = y = [];
   elseif (nargin == 1)
-    A = x;
-    zoom = [];
+    img = x;
     x = y = [];
-  elseif (nargin == 2)
-    A = x;
-    zoom = y;
-    x = y = [];
-  elseif (nargin == 3)
-    zoom = [];
-  elseif (nargin > 4)
-    usage ("image (matrix, zoom) or image (x, y, matrix, zoom)");
+  elseif (nargin > 3)
+    print_usage ();
+  endif
+
+  if (isempty (img))
+    error ("image: matrix is empty");
+  endif
+
+  ## Use the newly added mode of "plot" called "with image".
+  if (isempty (x))
+    x = [1, columns(img)];
+  endif
+
+  if (isempty (y))
+    y = [1, rows(img)];
   endif
 
-  if (isempty (zoom))
-    ## Find an integer scale factor which sets the image to
-    ## approximately the size of the screen.
-    zoom = min ([350/rows(A), 600/columns(A), 4]);
-    if (zoom >= 1)
-      zoom = floor (zoom);
-    else
-      zoom = 1 / ceil (1/zoom);
-    endif
+  ca = gca ();
+
+  s = __uiobject_image_ctor__ (ca);
+
+  s.cdata = img;
+
+  tmp = __uiobject_make_handle__ (s);
+
+  __uiobject_adopt__ (ca, tmp);
+
+  xlim = [x(1), x(end)];
+  ylim = [y(1), y(end)];
+
+  set (ca, "view", [0, 90], "xlim", xlim, "ylim", ylim);
+
+  if (nargout > 0)
+    h = tmp;
   endif
 
-  ## Get the image viewer.
-  [view_cmd, view_fcn, view_zoom] = image_viewer ();
-
-  ## Show the image.
-  view_fcn (x, y, A, zoom*view_zoom, view_cmd);
+  drawnow ();
 
 endfunction
--- a/scripts/image/image_viewer.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/image/image_viewer.m	Tue Jan 30 19:16:55 2007 +0000
@@ -72,7 +72,7 @@
   if (isempty (view_fcn))
     if (isempty (view_cmd)
 	&& compare_versions (__gnuplot_version__ (), "4.0", ">"))
-      view_fcn = @__img_gnuplot__;
+      view_fcn = "gnuplot_internal";
     else
       view_fcn = @__img_via_file__;
     endif
--- a/scripts/image/ocean.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/image/ocean.m	Tue Jan 30 19:16:55 2007 +0000
@@ -51,6 +51,6 @@
 
   b = [0:(number-1)]';
 
-  map = [ r, g, b ] / (number - 1);
+  map = colormap ([ r, g, b ] / (number - 1));
 
 endfunction
--- a/scripts/miscellaneous/delete.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/miscellaneous/delete.m	Tue Jan 30 19:16:55 2007 +0000
@@ -18,18 +18,23 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} delete (file)
-## Delete the named file.  Delete is a wrapper for @code{unlink}.
+## @deftypefn {Function File} {} delete (@var{file})
+## @deftypefnx {Function File} {} delete (@var{h})
+## Delete the named file or figure handle.
 ## @end deftypefn
 
 ## PKG_ADD: mark_as_command delete
 
 ## Author: jwe
 
-function delete (file)
+function delete (arg)
 
   if (nargin == 1)
-    unlink (file);
+    if (ischar (arg))
+      unlink (arg);
+    else
+      __uiobject_delete__ (arg);
+    endif
   else
     print_usage ();
   endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/move-if-change	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,15 @@
+#!/bin/sh
+#
+# Like mv $1 $2, but if the files are the same, just delete $1.
+# Status is 0 if $2 is changed, 1 otherwise.
+
+if test -r $2; then
+  if cmp $1 $2 > /dev/null; then
+    echo $2 is unchanged
+    rm -f $1
+  else
+    mv -f $1 $2
+  fi
+else
+  mv -f $1 $2
+fi
--- a/scripts/plot/Makefile.in	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/Makefile.in	Tue Jan 30 19:16:55 2007 +0000
@@ -20,14 +20,113 @@
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
 INSTALL_DATA = @INSTALL_DATA@
 
-SOURCES = *.m
+SOURCES_M = \
+  __axis_label__.m \
+  __errcomm__.m \
+  __default_colormap__.m \
+  __errplot__.m \
+  __plr1__.m \
+  __plr2__.m \
+  __plt1__.m \
+  __plt2__.m \
+  __plt2mm__.m \
+  __plt2mv__.m \
+  __plt2ss__.m \
+  __plt2vm__.m \
+  __plt2vv__.m \
+  __plt3__.m \
+  __plt__.m \
+  __plt_get_axis_arg__.m \
+  __pltopt1__.m \
+  __pltopt__.m \
+  __uiobject_adopt__.m \
+  __uiobject_axes_ctor__.m \
+  __uiobject_axes_dtor__.m \
+  __uiobject_delete__.m \
+  __uiobject_draw_axes__.m \
+  __uiobject_draw_figure__.m \
+  __uiobject_figure_ctor__.m \
+  __uiobject_globals__.m \
+  __uiobject_image_ctor__.m \
+  __uiobject_line_ctor__.m \
+  __uiobject_root_figure_ctor__.m \
+  __uiobject_surface_ctor__.m \
+  __uiobject_text_ctor__.m \
+  axes.m \
+  axis.m \
+  bar.m \
+  box.m \
+  clf.m \
+  close.m \
+  closereq.m \
+  contour.m \
+  contourc.m \
+  drawnow.m \
+  errorbar.m \
+  figure.m \
+  fplot.m \
+  gca.m \
+  gcf.m \
+  grid.m \
+  hist.m \
+  hold.m \
+  isfigure.m \
+  ishandle.m \
+  ishold.m \
+  legend.m \
+  line.m \
+  loglog.m \
+  loglogerr.m \
+  mesh.m \
+  meshdom.m \
+  meshgrid.m \
+  ndgrid.m \
+  newplot.m \
+  orient.m \
+  plot.m \
+  plot3.m \
+  polar.m \
+  print.m \
+  replot.m \
+  semilogx.m \
+  semilogxerr.m \
+  semilogy.m \
+  semilogyerr.m \
+  shg.m \
+  sombrero.m \
+  stairs.m \
+  subplot.m \
+  text.m \
+  title.m \
+  view.m \
+  xlabel.m \
+  ylabel.m \
+  zlabel.m
 
-DISTFILES = Makefile.in $(SOURCES)
+SOURCES_IN = \
+  __uiobject_alloc__.in \
+  __uiobject_axes_init__.in \
+  __uiobject_figures__.in \
+  __uiobject_free__.in \
+  __uiobject_get_handle__.in \
+  __uiobject_grow_list__.in \
+  __uiobject_handle2idx__.in \
+  __uiobject_init_figure__.in \
+  __uiobject_init_root_figure__.in \
+  __uiobject_make_handle__.in \
+  get.in \
+  set.in
 
-FCN_FILES = $(wildcard $(srcdir)/*.m)
+GEN_M = $(SOURCES_IN:.in=.m)
+
+SOURCES = $(SOURCES_M) $(SOURCES_IN)
+
+DISTFILES = Makefile.in include-globals.awk $(SOURCES)
+
+FCN_FILES = $(addprefix $(srcdir)/, $(SOURCES_M)) $(GEN_M)
 FCN_FILES_NO_DIR = $(notdir $(FCN_FILES))
 
-all: PKG_ADD
+all: $(GEN_M) PKG_ADD
 .PHONY: all
 
 install install-strip:
@@ -65,3 +164,7 @@
 dist:
 	ln $(DISTFILES) ../../`cat ../../.fname`/scripts/plot
 .PHONY: dist
+
+$(GEN_M) : %.m : %.in __uiobject_globals__.m
+	$(AWK) -f $(srcdir)/include-globals.awk file=$(srcdir)/__uiobject_globals__.m $< > $@-t
+	$(simple-move-if-change-rule)
--- a/scripts/plot/__axis_label__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__axis_label__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -24,30 +24,21 @@
 
 ## Author: jwe
 
-function h = __axis_label__ (caller, text)
+function retval = __axis_label__ (caller, txt)
+
+  ## If we have an even number of arguments, they should be
+  ## property-value pirs.
 
-  if (nargin == 0)
-    print_usage ();
-  elseif (nargin == 2)
-    if (ischar (text))
-      __gnuplot_raw__ (sprintf ("set %s \"%s\";\n", caller,
-				undo_string_escapes (text)));
-      if (automatic_replot)
-	replot ();
+  if (nargin == 2)
+    if (ischar (txt))
+      ca = gca ();
+      set (ca, caller, txt);
+      if (nargout > 0)
+	retval = get (ca, caller);
       endif
-    else
-      error ("%s: text must be a string", caller);
     endif
   else
-    usage ("%s (text)", caller);
-  endif
-
-  ## FIXME -- eventually, we will return a graphics handle.  For
-  ## now, return something, so that calls that expect a handle won't
-  ## fail (at least immediately).
-
-  if (nargout > 0)
-    h = -1;
+    print_usage ();
   endif
 
 endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__default_colormap__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,33 @@
+## Copyright (C) 2007 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} {} __default_colormap__ ()
+## Return the default colormap.
+## @end deftypefn
+
+## Author: jwe
+
+function cmap = __default_colormap__ ()
+
+  gr = [0:63]';
+
+  cmap = [ gr, gr, gr ] / 63;
+
+endfunction
--- a/scripts/plot/__do_legend__.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-## Copyright (C) 2006 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.
-
-function __do_legend__ ()
-
-  __plot_globals__;
-
-  cf = __current_figure__;
-  mxi = __multiplot_xi__(cf);
-  myi = __multiplot_yi__(cf);
-
-  props = __plot_key_properties__{cf}{mxi,myi};
-
-  if (isstruct (props))
-    if (isfield (props, "visible"))
-      visible = props.visible;
-    else
-      error ("__do_legend__: missing field \"visible\"");
-    endif
-    if (isfield (props, "box"))
-      box = props.box;
-    else
-      error ("__do_legend__: missing field \"box\"");
-    endif
-    if (isfield (props, "position"))
-      position = props.position;
-    else
-      error ("__do_legend__: missing field \"position\"");
-    endif
-    if (visible)
-      switch (position)
-	case 1
-	  __gnuplot_raw__ ("set  key right top;\n")
-	case 2
-	  __gnuplot_raw__ ("set  key left top;\n")
-	case 3
-	  __gnuplot_raw__ ("set  key left bottom;\n")
-	case 4
-	  __gnuplot_raw__ ("set  key right bottom;\n")
-	case -1
-	  __gnuplot_raw__ ("set  key right top outside;\n")
-	case -2
-	  __gnuplot_raw__ ("set  key right bottom outside;\n")
-	case -3
-	  __gnuplot_raw__ ("set  key below;\n")
-      endswitch
-      if (box)
-        __gnuplot_raw__ ("set key box;\n")
-      else
-        __gnuplot_raw__ ("set key nobox;\n")
-      endif
-    else
-      __gnuplot_raw__ ("unset key;\n")
-    endif
-  else
-    error ("__do_legend__: expecting properties to be a struct");
-  endif
-
-endfunction
--- a/scripts/plot/__errcomm__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__errcomm__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -28,62 +28,54 @@
 ## Author: Teemu Ikonen <tpikonen@pcu.helsinki.fi>
 ## Keywords: errorbar, plotting
 
-function __errcomm__ (caller, varargin)
+function __errcomm__ (caller, h, varargin)
 
-  if (nargin < 3)
-    usage ("%s (x, y, dy, \"fmt\", ...)", caller);
+  if (nargin < 4)
+    print_usage ();
   endif
 
   nargs = length (varargin);
-  save_hold = ishold;
-  unwind_protect
-    if (! ishold)
-      clg
+
+  k = 1;
+  data = cell(6,1);
+  while (k <= nargs)
+    a = varargin{k++};
+    if (isvector (a))
+      a = a(:);
+    elseif (ismatrix (a))
+      ;
+    else
+      usage ("%s (...)", caller);
     endif
-    hold on;
-    k = 1;
-    data = cell(6,1);
+    sz = size (a);
+    ndata = 1;
+    data{ndata} = a;
     while (k <= nargs)
       a = varargin{k++};
-      if (isvector (a))
-        a = a(:);
+      if (ischar (a) || iscellstr (a))
+	__errplot__ (a, h, data{1:ndata});
+	break;
+      elseif (isvector (a))
+	a = a(:);
       elseif (ismatrix (a))
-        ;
+	;
       else
-        usage ("%s (...)", caller);
+	error ("wrong argument types");
+      endif
+      if (size (a) != sz)
+	error ("argument sizes do not match");
       endif
-      sz = size (a);
-      ndata = 1;
-      data{ndata} = a;
-      while (k <= nargs)
-	a = varargin{k++};
-	if (ischar (a) || iscellstr (a))
-	  __errplot__ (a, data{1:ndata});
-	  break;
-	elseif (isvector (a))
-	  a = a(:);
-	elseif (ismatrix (a))
-	  ;
-	else
-	  error ("wrong argument types");
-	endif
-	if (size (a) != sz)
-	  error ("argument sizes do not match");
-	endif
-	data{++ndata} = a;
-	if (ndata > 6)
-	  error ("too many arguments to a plot");
-	endif
-      endwhile
+      data{++ndata} = a;
+      if (ndata > 6)
+	error ("too many arguments to a plot");
+      endif
     endwhile
+  endwhile
 
-    if (! (ischar (a) || iscellstr (a)))
-      __errplot__ ("~", data{1:ndata});
-    endif
-  unwind_protect_cleanup
-    if (! save_hold)
-      hold off;
-    endif
-  end_unwind_protect
+  if (! (ischar (a) || iscellstr (a)))
+    __errplot__ ("~", h, data{1:ndata});
+  endif
+
+  drawnow ();
 
 endfunction
--- a/scripts/plot/__errplot__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__errplot__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -33,61 +33,59 @@
 ## Author: Teemu Ikonen <tpikonen@pcu.helsinki.fi>
 ## Keywords: errorbar, plotting
 
-function __errplot__ (fstr, a1, a2, a3, a4, a5, a6)
-
-  __plot_globals__;
+function __errplot__ (fstr, h, a1, a2, a3, a4, a5, a6)
 
-  cf = __current_figure__;
-  mxi = __multiplot_xi__(cf);
-  myi = __multiplot_yi__(cf);
-
-  __setup_plot__ ("__gnuplot_plot__");
-
-  if (nargin < 3 || nargin > 7) # at least three data arguments needed
+  if (nargin < 4 || nargin > 8) # at least two data arguments needed
     print_usage ();
   endif
 
-  j = __plot_data_offset__{cf}(mxi,myi);
-
   [fmt, key] = __pltopt__ ("__errplot__", fstr);
 
   [len, nplots] = size (a1);
 
   for i = 1:nplots
     ifmt = fmt{1+mod(i-1,numel(fmt))};
-    switch (nargin - 1)
+    s = __uiobject_line_ctor__ (h);
+    switch (nargin - 2)
       case 2
-	tmp = [(1:len)', a1(:,i), a2(:,i)];
+	s.xdata = (1:len)';
+	s.ydata = a1(:,i);
+	s.ldata = a2(:,i);
+	s.udata = a2(:,i);
       case 3
-	tmp = [a1(:,i), a2(:,i), a3(:,i)];
+	s.xdata = a1(:,i);
+	s.ydata = a2(:,i);
+	s.ldata = a3(:,i);
+	s.udata = a3(:,i);
       case 4
+	s.xdata = a1(:,i);
+	s.ydata = a2(:,i);
+
 	if (index (ifmt, "boxxy") || index (ifmt, "xyerr"))
-	  tmp = [a1(:,i), a2(:,i), a3(:,i), a4(:,i)];
+	  s.xldata = a3(:,i);
+	  s.xudata = a3(:,i);
+	  s.ldata = a4(:,i);
+	  s.udata = a4(:,i);
 	elseif (index (ifmt, "xerr"))
-	  tmp = [a1(:,i), a2(:,i), a1(:,i)-a3(:,i), a1(:,i)+a4(:,i)];
+	  s.xldata = a3(:,i);
+	  s.xudata = a4(:,i);
 	else
-	  tmp = [a1(:,i), a2(:,i), a2(:,i)-a3(:,i), a2(:,i)+a4(:,i)];
+	  s.ldata = a3(:,i);
+	  s.udata = a4(:,i);
 	endif
       case 5
 	error ("error plot requires 2, 3, 4 or 6 columns");
-	## tmp = [a1(:,i), a2(:,i), a3(:,i), a4(:,i), a5(:,i)];
       case 6
-	tmp = [a1(:,i), a2(:,i), ...
-	       a1(:,i)-a3(:,i), a1(:,i)+a4(:,i), ...
-	       a2(:,i)-a5(:,i), a2(:,i)+a6(:,i)];
+	s.xdata = a1(:,i);
+	s.ydata = a2(:,i);
+	s.xldata = a3(:,i);
+	s.xudata = a4(:,i);
+	s.ldata = a5(:,i);
+	s.udata = a6(:,i);
     endswitch
 
-    __plot_data__{cf}{mxi,myi}{j}{i} = tmp;
-    __plot_data_type__{cf}{mxi,myi}(j) = 2;
-    __plot_fmtstr__{cf}{mxi,myi}{j}{i} = ifmt;
-    __plot_key_labels__{cf}{mxi,myi}{j} = key;
-    __plot_usingstr__{cf}{mxi,myi}{j}{i} = "";
-    __plot_withstr__{cf}{mxi,myi}{j}{i} = "";
+    __uiobject_adopt__ (h, __uiobject_make_handle__ (s));
 
   endfor
 
-  __plot_data_offset__{cf}(mxi,myi) = ++j;
-
-  __render_plot__ ();
-
 endfunction
--- a/scripts/plot/__gnuplot_version__.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-## Copyright (C) 2006 Daniel Sebald
-##
-## 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, 59 Temple Place - Suite 330, Boston, MA
-## 02111-1307, USA.
-
-## -*- texinfo -*-
-## @deftypefn {Function File} {@var{version} =} __gnuplot_version__ (@var{gplt_exe})
-## Return the version of gnuplot we are using.  Note that we do not
-## attempt to handle the case of the user switching to different
-## versions of gnuplot during the same session.
-## @end deftypefn
-
-function version = __gnuplot_version__ ()
-
-  persistent __version__ = "";
-
-  if (isempty (__version__))
-    [status, output] = system (sprintf ("%s --version", gnuplot_binary ()));
-    pattern = "^[^\\s]*\\s*([0-9]+\\.[0-9]+)\\s*[^\\s]*\\s*([^\\s]*)";
-    [d1, d2, d3, d4, matches] = regexp (output, pattern);
-    if (iscell (matches) && numel (matches) > 0 && iscellstr (matches{1}))
-      __version__ = matches{1}{1};
-    endif
-  endif
-
-  version = __version__;
-
-endfunction
-
--- a/scripts/plot/__init_plot_vars__.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-## Copyright (C) 2006 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.
-
-function __init_plot_vars__ (clear_data)
-
-  __plot_globals__;
-
-  cf = __current_figure__;
-  mxi = __multiplot_xi__(cf);
-  myi = __multiplot_yi__(cf);
-
-  if (nargin < 1)
-    clear_data = true;
-  endif
-
-  if (clear_data)
-    __plot_data__{cf}{mxi,myi} = [];
-    __plot_data_offset__{cf}(mxi,myi) = 1;
-    __plot_data_type__{cf}{mxi,myi} = [];
-    __plot_data_parametric__{cf}{mxi,myi} = [];
-    __plot_image_colormap__{cf}{mxi,myi} = [];
-    __plot_image_dims__{cf}{mxi,myi} = [];
-    __plot_fmtstr__{cf}{mxi,myi} = [];
-    __plot_usingstr__{cf}{mxi,myi} = [];
-    __plot_withstr__{cf}{mxi,myi} = [];
-  endif
-
-endfunction
--- a/scripts/plot/__make_using_clause__.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-## Copyright (C) 2006 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.
-
-function usingstr = __make_using_clause__ (x)
-  cols = columns (x);
-  if (cols > 0)
-    usingstr = strcat (gnuplot_command_using, " ($1)");
-    for k = 2:cols
-      usingstr = sprintf ("%s:($%d)", usingstr, k);
-    endfor
-  else
-    usingstr = "";
-  endif
-endfunction
--- a/scripts/plot/__plot_globals__.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-## 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.
-
-global __current_figure__;
-global __plot_data_offset__;
-global __plot_data__;
-global __plot_data_type__;
-global __plot_data_parametric__;
-global __plot_image_colormap__;
-global __plot_image_dims__;
-global __plot_fmtstr__;
-global __plot_usingstr__;
-global __plot_withstr__;
-global __plot_key_labels__;
-global __plot_key_properties__;
-global __multiplot_mode__;
-global __multiplot_xsize__;
-global __multiplot_ysize__;
-global __multiplot_xn__;
-global __multiplot_yn__;
-global __multiplot_xi__;
-global __multiplot_yi__;
-
-if (isempty (__current_figure__))
-  __current_figure__ = 1;
-endif
-
-if (length (__multiplot_mode__) < __current_figure__)
-  __multiplot_mode__(__current_figure__) = false;
-endif
-
-if (length (__multiplot_xsize__) < __current_figure__)
-  __multiplot_xsize__(__current_figure__) = 1;
-endif
-
-if (length (__multiplot_ysize__) < __current_figure__)
-  __multiplot_ysize__(__current_figure__) = 1;
-endif
-
-if (length (__multiplot_xn__) < __current_figure__)
-  __multiplot_xn__(__current_figure__) = 1;
-endif
-
-if (length (__multiplot_yn__) < __current_figure__)
-  __multiplot_yn__(__current_figure__) = 1;
-endif
-
-if (length (__multiplot_xi__) < __current_figure__)
-  __multiplot_xi__(__current_figure__) = 1;
-endif
-
-if (length (__multiplot_yi__) < __current_figure__)
-  __multiplot_yi__(__current_figure__) = 1;
-endif
-
-if (length (__plot_data_offset__) < __current_figure__
-    || any (size (__plot_data_offset__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
-
-  __plot_data_offset__{__current_figure__}(__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)) = 1;
-endif
-
-if (length (__plot_data__) < __current_figure__
-    || any (size (__plot_data__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
-  __plot_data__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
-endif
-
-if (length (__plot_data_type__) < __current_figure__
-    || any (size (__plot_data_type__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
-  __plot_data_type__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
-endif
-
-if (length (__plot_data_parametric__) < __current_figure__
-    || any (size (__plot_data_parametric__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
-  __plot_data_parametric__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
-endif
-
-if (length (__plot_image_colormap__) < __current_figure__
-    || any (size (__plot_image_colormap__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
-  __plot_image_colormap__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
-endif
-
-if (length (__plot_image_dims__) < __current_figure__
-    || any (size (__plot_image_dims__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
-  __plot_image_dims__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
-endif
-
-if (length (__plot_fmtstr__) < __current_figure__
-    || any (size (__plot_fmtstr__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
-  __plot_fmtstr__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
-endif
-
-if (length (__plot_usingstr__) < __current_figure__
-    || any (size (__plot_usingstr__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
-  __plot_usingstr__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
-endif
-
-if (length (__plot_withstr__) < __current_figure__
-    || any (size (__plot_withstr__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
-  __plot_withstr__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
-endif
-
-if (length (__plot_key_labels__) < __current_figure__
-    || any (size (__plot_key_labels__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
-  __plot_key_labels__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
-endif
-
-if (length (__plot_key_properties__) < __current_figure__
-    || any (size (__plot_key_properties__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
-  __plot_key_properties__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yi__(__current_figure__)} = struct ("visible", true, "box", false, "position", 0);
-endif
--- a/scripts/plot/__plr1__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__plr1__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -18,14 +18,14 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plr1__ (@var{theta}, @var{fmt})
+## @deftypefn {Function File} {} __plr1__ (@var{h}, @var{theta}, @var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plr1__ (theta, fmt)
+function __plr1__ (h, theta, fmt)
 
-  if (nargin != 2)
+  if (nargin != 3)
     print_usage ();
   endif
 
@@ -45,6 +45,6 @@
     theta = (1:nr)';
   endif
 
-  __plr2__ (theta, rho, fmt);
+  __plr2__ (h, theta, rho, fmt);
 
 endfunction
--- a/scripts/plot/__plr2__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__plr2__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -18,14 +18,14 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plr2__ (@var{theta}, @var{rho}, @var{fmt})
+## @deftypefn {Function File} {} __plr2__ (@var{h}, @var{theta}, @var{rho}, @var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plr2__ (theta, rho, fmt)
+function __plr2__ (h, theta, rho, fmt)
 
-  if (nargin != 3)
+  if (nargin != 4)
     print_usage ();
   endif
 
@@ -41,7 +41,7 @@
     if (isscalar (rho))
       x = rho * cos (theta);
       y = rho * sin (theta);
-      __plt__ ("polar", x, y, fmt);
+      __plt__ ("polar", h, x, y, fmt);
     else
       error ("__plr2__: invalid data for plotting");
     endif
@@ -58,7 +58,7 @@
       endif
       x = rho .* cos (theta);
       y = rho .* sin (theta);
-      __plt__ ("polar", x, y, fmt);
+      __plt__ ("polar", h, x, y, fmt);
     elseif (ismatrix (rho))
       [t_nr, t_nc] = size (theta);
       if (t_nr == 1)
@@ -79,7 +79,7 @@
       endif
       x = diag (cos (theta)) * rho;
       y = diag (sin (theta)) * rho;
-      __plt__ ("polar", x, y, fmt);
+      __plt__ ("polar", h, x, y, fmt);
     else
       error ("__plr2__: invalid data for plotting")
     endif
@@ -105,14 +105,14 @@
       diag_r = diag (rho);
       x = diag_r * cos (theta);
       y = diag_r * sin (theta);
-      __plt__ ("polar", x, y, fmt);
+      __plt__ ("polar", h, x, y, fmt);
     elseif (ismatrix (rho))
       if (! size_equal (rho, theta))
         error ("__plr2__: matrix dimensions must match");
       endif
       x = rho .* cos (theta);
       y = rho .* sin (theta);
-      __plt__ ("polar", x, y, fmt);
+      __plt__ ("polar", h, x, y, fmt);
     else
       error ("__plr2__: invalid data for plotting")
     endif
--- a/scripts/plot/__plr__.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-## Copyright (C) 1996, 1997 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} {} __plr__ (@var{theta}, @var{rho}, @var{fmt})
-## @end deftypefn
-
-## Author: jwe
-
-function __plr__ (theta, rho, fmt)
-
-  if (nargin == 1)
-    [nr, nc] = size (theta);
-    if (nr == 1)
-      theta = theta.';
-      tmp = nr;
-      nr = nc;
-      nc = tmp;
-    endif
-    theta_i = imag (theta);
-    if (any (theta_i))
-      rho = theta_i;
-      theta = real (theta);
-    else
-      rho = theta;
-      theta = (1:nr)';
-    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);
-    endif
-    if (any (imag (rho)))
-      rho = real (rho);
-    endif
-    if (isscalar (theta))
-      if (isscalar (rho))
-        x = rho * cos (theta);
-        y = rho * sin (theta);
-        __plt__ ("polar", x, y, fmt);
-      endif
-    elseif (isvector (theta))
-      if (isvector (rho))
-        if (length (theta) != length (rho))
-          error ("polar: vector lengths must match");
-        endif
-        if (rows (rho) == 1)
-          rho = rho.';
-        endif
-        if (rows (theta) == 1)
-          theta = theta.';
-        endif
-        x = rho .* cos (theta);
-        y = rho .* sin (theta);
-        __plt__ ("polar", x, y, fmt);
-      elseif (ismatrix (rho))
-        [t_nr, t_nc] = size (theta);
-        if (t_nr == 1)
-          theta = theta.';
-          tmp = t_nr;
-          t_nr = t_nc;
-          t_nc = tmp;
-        endif
-        [r_nr, r_nc] = size (rho);
-        if (t_nr != r_nr)
-          rho = rho.';
-          tmp = r_nr;
-          r_nr = r_nc;
-          r_nc = tmp;
-        endif
-        if (t_nr != r_nr)
-          error ("polar: vector and matrix sizes must match");
-        endif
-        x = diag (cos (theta)) * rho;
-        y = diag (sin (theta)) * rho;
-        __plt__ ("polar", x, y, fmt);
-      endif
-    elseif (ismatrix (theta))
-      if (isvector (rho))
-        [r_nr, r_nc] = size (rho);
-        if (r_nr == 1)
-          rho = rho.';
-          tmp = r_nr;
-          r_nr = r_nc;
-          r_nc = tmp;
-        endif
-        [t_nr, t_nc] = size (theta);
-        if (r_nr != t_nr)
-          theta = rho.';
-          tmp = t_nr;
-          t_nr = t_nc;
-          t_nc = tmp;
-        endif
-        if (r_nr != t_nr)
-          error ("polar: vector and matrix sizes must match");
-        endif
-        diag_r = diag (r);
-        x = diag_r * cos (theta);
-        y = diag_r * sin (theta);
-        __plt__ ("polar", x, y, fmt);
-      elseif (ismatrix (rho))
-        if (! size_equal (rho, theta))
-          error ("polar: matrix dimensions must match");
-        endif
-        x = rho .* cos (theta);
-        y = rho .* sin (theta);
-        __plt__ ("polar", x, y, fmt);
-      endif
-    endif
-  else
-    print_usage ();
-  endif
-
-endfunction
--- a/scripts/plot/__plt1__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__plt1__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -18,30 +18,30 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {[data, fmtstr] =} __plt1__ (@var{x1}, @var{fmt})
+## @deftypefn {Function File} {} __plt1__ (@var{h}, @var{x1}, @var{fmt}, @var{key})
 ## @end deftypefn
 
 ## Author: jwe
 
-function [data, fmtstr, key] = __plt1__ (x1, fmt, keystr)
+function __plt1__ (h, x1, fmt, key)
 
-  if (nargin < 1 || nargin > 3 || nargout < 2 || nargout > 3)
+  if (nargin < 2 || nargin > 4)
     print_usage ();
   endif
 
-  if (nargin < 2)
+  if (nargin < 3 || isempty (fmt))
     fmt = {""};
   endif
 
-  if (nargin < 3)
-    keystr = {""};
+  if (nargin < 4 || isempty (key))
+    key = {""};
   endif
 
   if (! iscellstr (fmt))
     error ("__plt1__: fmt must be a cell array of character strings");
   endif
 
-  if (! iscell (keystr))
+  if (! iscell (key))
     error ("__plt1__: fmt must be a cell array");
   endif
 
@@ -61,6 +61,6 @@
     x1 = (1:nr)';
   endif
 
-  [data, fmtstr, key] = __plt2__ (x1, x2, fmt, keystr);
+  __plt2__ (h, x1, x2, fmt, key);
 
 endfunction
--- a/scripts/plot/__plt2__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__plt2__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -18,30 +18,30 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {[data, fmtstr] =} __plt2__ (@var{x1}, @var{x2}, @var{fmt})
+## @deftypefn {Function File} {} __plt2__ (@var{h}, @var{x1}, @var{x2}, @var{fmt}, @var{key})
 ## @end deftypefn
 
 ## Author: jwe
 
-function [data, fmtstr, key] = __plt2__ (x1, x2, fmt, keystr)
+function __plt2__ (h, x1, x2, fmt, key)
 
-  if (nargin < 2 || nargin > 4 || nargout < 2 || nargout > 3)
+  if (nargin < 3 || nargin > 5)
     print_usage ();
   endif
 
-  if (nargin < 3)
+  if (nargin < 4 || isempty (fmt))
     fmt = {""};
   endif
 
-  if (nargin < 4)
-    keystr = {""};
+  if (nargin < 5 || isempty (key))
+    key = {""};
   endif
 
   if (! iscellstr (fmt))
     error ("__plt1__: fmt must be a cell array of character strings");
   endif
 
-  if (! iscell (keystr))
+  if (! iscell (key))
     error ("__plt1__: fmt must be a cell array");
   endif
 
@@ -55,30 +55,29 @@
 
   if (isscalar (x1))
     if (isscalar (x2))
-      [data, fmtstr, key] = __plt2ss__ (x1, x2, fmt, keystr);
+      __plt2ss__ (h, x1, x2, fmt, key);
     else
       error ("__plt2__: invalid data for plotting");
     endif
   elseif (isvector (x1))
     if (isvector (x2))
-      [data, fmtstr, key] = __plt2vv__ (x1, x2, fmt, keystr);
+      __plt2vv__ (h, x1, x2, fmt, key);
     elseif (ismatrix (x2))
-      [data, fmtstr, key] = __plt2vm__ (x1, x2, fmt, keystr);
+      __plt2vm__ (h, x1, x2, fmt, key);
     else
       error ("__plt2__: invalid data for plotting");
     endif
   elseif (ismatrix (x1))
     if (isvector (x2))
-      [data, fmtstr, key] = __plt2mv__ (x1, x2, fmt, keystr);
+      __plt2mv__ (h, x1, x2, fmt, key);
     elseif (ismatrix (x2))
-      [data, fmtstr, key] = __plt2mm__ (x1, x2, fmt, keystr);
+      __plt2mm__ (h, x1, x2, fmt, key);
     else
       error ("__plt2__: invalid data for plotting");
     endif
   elseif (isempty (x1) && isempty (x2))
-    data = {};
-    fmtstr = {};
-    key = {};
+    ## FIXME -- should we do nothing, or should we create a line object
+    ## with empty xdata and ydata properties?
   else
     error ("__plt2__: invalid data for plotting");
   endif
--- a/scripts/plot/__plt2mm__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__plt2mm__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -18,23 +18,23 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {[data, fmtstr] =} __plt2mm__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {} __plt2mm__ (@var{h}, @var{x}, @var{y}, @var{fmt}, @var{key})
 ## @end deftypefn
 
 ## Author: jwe
 
-function [data, fmtstr, key] = __plt2mm__ (x, y, fmt, keystr)
+function __plt2mm__ (h, x, y, fmt, key)
 
-  if (nargin < 2 || nargin > 4 || nargout < 2 || nargout > 3)
+  if (nargin < 3 || nargin > 5)
     print_usage ();
   endif
 
-  if (nargin < 3 || isempty (fmt))
+  if (nargin < 4 || isempty (fmt))
     fmt = {""};
   endif
 
-  if (nargin < 4 || isempty (keystr))
-    keystr = {""};
+  if (nargin < 5 || isempty (key))
+    key = {""};
   endif
 
   [x_nr, x_nc] = size (x);
@@ -47,21 +47,17 @@
       if (rows (fmt) == 1)
 	fmt = repmat (fmt, x_nc, 1);
       endif
-      if (rows (keystr) == 1)
-	keystr = repmat (keystr, x_nc, 1);
+      if (rows (key) == 1)
+	key = repmat (key, x_nc, 1);
       endif
-      tmp = [x, y];
-      dtmp = cell (x_nc, 1);
-      ftmp = cell (x_nc, 1);
-      ktmp = cell (x_nc, 1);
       for i = 1:x_nc
-	dtmp{i} = tmp(:,[i,x_nc+i]);
-	ftmp{i} = deblank (fmt{i});
-	ktmp{i} = deblank (keystr{i});
+	## FIXME -- need to handle labels and line format.
+	tkey = key{i};
+	if (! isempty (tkey))
+	  set (h, "key", "on");
+	endif
+	line (x(:,i), y(:,i), "keylabel", tkey);
       endfor
-      data = dtmp;
-      fmtstr = ftmp;
-      key = ktmp;
     else
       error ("__plt2mm__: arguments must be a matrices");
     endif
--- a/scripts/plot/__plt2mv__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__plt2mv__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -18,23 +18,23 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {[data, fmtstr] =} __plt2mv__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {} __plt2mv__ (@var{h}, @var{x}, @var{y}, @var{fmt}, @var{key})
 ## @end deftypefn
 
 ## Author: jwe
 
-function [data, fmtstr, key] = __plt2mv__ (x, y, fmt, keystr)
+function __plt2mv__ (h, x, y, fmt, key)
 
-  if (nargin < 2 || nargin > 4 || nargout < 2 || nargou > 3)
+  if (nargin < 3 || nargin > 5)
     print_usage ();
   endif
 
-  if (nargin < 3 || isempty (fmt))
+  if (nargin < 4 || isempty (fmt))
     fmt = {""};
   endif
 
-  if (nargin < 3 || isempty (keystr))
-    keystr = {""};
+  if (nargin < 5 || isempty (key))
+    key = {""};
   endif
 
   [x_nr, x_nc] = size (x);
@@ -62,21 +62,17 @@
     if (rows (fmt) == 1)
       fmt = repmat (fmt, x_nc, 1);
     endif
-    if (rows (keystr) == 1)
-      keystr = repmat (keystr, x_nc, 1);
+    if (rows (key) == 1)
+      key = repmat (key, x_nc, 1);
     endif
-    tmp = [x, y];
-    dtmp = cell (x_nc, 1);
-    ftmp = cell (x_nc, 1);
-    ktmp = cell (x_nc, 1);
     for i = 1:x_nc
-      dtmp{i} = tmp(:,[i,x_nc+1]);
-      ftmp{i} = deblank (fmt{i});
-      ktmp{i} = deblank (keystr{i});
+      ## FIXME -- need to handle labels and line format.
+      tkey = key{i};
+      if (! isempty (tkey))
+	set (h, "key", "on");
+      endif
+      line (x(:,i), y, "keylabel", tkey);
     endfor
-    data = dtmp;
-    fmtstr = ftmp;
-    key = ktmp;
   else
     error ("__plt2mv__: arguments must be a matrices");
   endif
--- a/scripts/plot/__plt2ss__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__plt2ss__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -18,40 +18,43 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {[data, fmtstr] =} __plt2ss__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {} __plt2ss__ (@var{h}, @var{x}, @var{y}, @var{fmt}, @var{key})
 ## @end deftypefn
 
 ## Author: jwe
 
-function [data, fmtstr, key] = __plt2ss__ (x, y, fmt, keystr)
+function __plt2ss__ (h, x, y, fmt, key)
 
-  if (nargin < 2 || nargin > 4 || nargout < 2 || nargout > 3)
+  if (nargin < 3 || nargin > 5)
     print_usage ();
   endif
 
-  if (nargin < 3)
+  if (nargin < 4 || isempty (fmt))
     fmt = {""};
   endif
 
-  if (nargin < 4)
-    keystr = {""};
+  if (nargin < 5 || isempty (key))
+    key = {""};
   endif
 
   if (rows (fmt) > 1)
     fmt = fmt(1);
   endif
 
-  if (rows (keystr) > 1)
-    keystr = keystr(1);
+  if (rows (key) > 1)
+    key = key(1);
   endif
 
   [x_nr, x_nc] = size (x);
   [y_nr, y_nc] = size (y);
 
   if (x_nr == 1 && x_nr == y_nr && x_nc == 1 && x_nc == y_nc)
-    data = {[x, y]};
-    fmtstr = fmt;
-    key = keystr;
+    key = key{1};
+    if (! isempty (key))
+      set (h, "key", "on");
+    endif
+    ## FIXME -- need to handle labels and line format.
+    line (x, y, "keylabel", key);
   else
     error ("__plt2ss__: arguments must be scalars");
   endif
--- a/scripts/plot/__plt2vm__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__plt2vm__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -18,23 +18,23 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {[data, fmtstr] =} __plt2vm__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {} __plt2vm__ (@var{h}, @var{x}, @var{y}, @var{fmt}, @var{key})
 ## @end deftypefn
 
 ## Author: jwe
 
-function [data, fmtstr, key] = __plt2vm__ (x, y, fmt, keystr)
+function __plt2vm__ (h, x, y, fmt, key)
 
-  if (nargin < 2 || nargin > 4 || nargout < 2 || nargout > 3)
+  if (nargin < 3 || nargin > 5)
     print_usage ();
   endif
 
-  if (nargin < 3 || isempty (fmt))
+  if (nargin < 4 || isempty (fmt))
     fmt = {""};
   endif
 
-  if (nargin < 4 || isempty (keystr))
-    keystr = {""};
+  if (nargin < 5 || isempty (key))
+    key = {""};
   endif
 
   [x_nr, x_nc] = size (x);
@@ -62,21 +62,17 @@
     if (rows (fmt) == 1)
       fmt = repmat (fmt, y_nc, 1);
     endif
-    if (rows (keystr) == 1)
-      keystr = repmat (keystr, y_nc, 1);
+    if (rows (key) == 1)
+      key = repmat (key, y_nc, 1);
     endif
-    tmp = [x, y];
-    dtmp = cell (y_nc, 1);
-    ftmp = cell (y_nc, 1);
-    ktmp = cell (y_nc, 1);
     for i = 1:y_nc
-      dtmp{i} = tmp(:,[1,i+1]);
-      ftmp{i} = deblank (fmt{i});
-      ktmp{i} = deblank (keystr{i});
+      tkey = key{i};
+      if (! isempty (tkey))
+	set (h, "key", "on");
+      endif
+      ## FIXME -- need to handle labels and line format.
+      line (x, y(:,i), "keylabel", tkey);
     endfor
-    data = dtmp;
-    fmtstr = ftmp;
-    key = ktmp;
   else
     error ("__plt2vm__: arguments must be a matrices");
   endif
--- a/scripts/plot/__plt2vv__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__plt2vv__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -18,31 +18,31 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {[data, fmtstr] =} __plt2vv__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {} __plt2vv__ (@var{h}, @var{x}, @var{y}, @var{fmt}, @var{key})
 ## @end deftypefn
 
 ## Author: jwe
 
-function [data, fmtstr, key] = __plt2vv__ (x, y, fmt, keystr)
+function __plt2vv__ (h, x, y, fmt, key)
 
-  if (nargin < 2 || nargin > 4 || nargout < 2 || nargout > 3)
+  if (nargin < 3 || nargin > 5)
     print_usage ();
   endif
 
-  if (nargin < 3)
+  if (nargin < 4 || isempty (fmt))
     fmt = {""};
   endif
 
-  if (nargin < 4)
-    keystr = {""};
+  if (nargin < 5 || isempty (key))
+    key = {""};
   endif
 
   if (rows (fmt) > 1)
     fmt = fmt(1);
   endif
 
-  if (rows (keystr) > 1)
-    keystr = keystr(1);
+  if (rows (key) > 1)
+    key = key(1);
   endif
 
   [x_nr, x_nc] = size (x);
@@ -62,12 +62,15 @@
     y_nc = tmp;
   endif
 
-  if (x_nr != y_nr)
+  if (x_nr == y_nr)
+    key = key{1};
+    if (! isempty (key))
+      set (h, "key", "on");
+    endif
+    ## FIXME -- need to handle labels and line format.
+    line (x, y, "keylabel", key);
+  else
     error ("__plt2vv__: vector lengths must match");
   endif
 
-  data = {[x, y]};
-  fmtstr = fmt;
-  key = keystr;
-
 endfunction
--- a/scripts/plot/__plt3__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__plt3__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -33,24 +33,21 @@
 ## David Bateman <dbateman@free.fr>
 ## May 25, 2006
 
-function __plt3__ (x, parametric, usingstr, fmtstr, keystr, withstr)
+function __plt3__ (x, usingstr, fmt, key, withstr)
 
   if (nargin < 2)
-    parametric = false;
-  endif
-  if (nargin < 3)
     have_usingstr = false;
     usingstr = "";
   else
     have_usingstr = true;
   endif
-  if (nargin < 4)
-    fmtstr = "";
+  if (nargin < 3 || isempty (fmt))
+    fmt = "";
+  endif
+  if (nargin < 4 || isempty (key))
+    key = "";
   endif
   if (nargin < 5)
-    keystr = "";
-  endif
-  if (nargin < 6)
     withstr = "";
   endif
 
--- a/scripts/plot/__plt__.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/__plt__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -23,29 +23,20 @@
 
 ## Author: jwe
 
-function __plt__ (caller, varargin)
-
-  __plot_globals__;
+function __plt__ (caller, h, varargin)
 
-  cf = __current_figure__;
-  mxi = __multiplot_xi__(cf);
-  myi = __multiplot_yi__(cf);
+  nargs = nargin - 2;
 
-  __setup_plot__ ("plot");
-
-  nargs = nargin ();
-
-  if (nargs > 1)
+  if (nargs > 0)
 
     k = 1;
-    j = __plot_data_offset__{cf}(mxi,myi);
 
     x_set = false;
     y_set = false;
 
     ## Gather arguments, decode format, gather plot strings, and plot lines.
 
-    while (--nargs > 0 || x_set)
+    while (nargs > 0 || x_set)
 
       if (nargs == 0)
 	## Force the last plot when input variables run out.
@@ -54,25 +45,15 @@
 	next_arg = varargin{k++};
       endif
 
+      nargs--;
+
       if (ischar (next_arg) || iscellstr (next_arg))
 	if (x_set)
-	  [fmt, keystr] = __pltopt__ (caller, next_arg);
+	  [fmt, key] = __pltopt__ (caller, next_arg);
 	  if (y_set)
-	    [tdata, tfmtstr, key] = __plt2__ (x, y, fmt, keystr);
+	    __plt2__ (h, x, y, fmt, key);
 	  else
-	    [tdata, tfmtstr, key] = __plt1__ (x, fmt, keystr);
-	  endif
-	  if (! isempty (tdata))
-	    for i = 1:numel (tdata)
-	      __plot_usingstr__{cf}{mxi,myi}{j}{i} ...
-		  = __make_using_clause__ (tdata{i});
-	      __plot_withstr__{cf}{mxi,myi}{j}{i} = "";
-	    endfor
-	    __plot_data__{cf}{mxi,myi}{j} = tdata;
-	    __plot_data_type__{cf}{mxi,myi}(j) = 2;
-	    __plot_fmtstr__{cf}{mxi,myi}{j} = tfmtstr;
-	    __plot_key_labels__{cf}{mxi,myi}{j} = key;
-	    j++;
+	    __plt1__ (h, x, fmt, key);
 	  endif
 	  x_set = false;
 	  y_set = false;
@@ -81,20 +62,8 @@
 	endif
       elseif (x_set)
 	if (y_set)
-	  [fmt, keystr] = __pltopt__ (caller, {""});
-	  [tdata, tfmtstr, key] = __plt2__ (x, y, fmt, keystr);
-	  if (! isempty (tdata))
-	    for i = 1:numel (tdata)
-	      __plot_usingstr__{cf}{mxi,myi}{j}{i} ...
-		  = __make_using_clause__ (tdata{i});
-	      __plot_withstr__{cf}{mxi,myi}{j}{i} = "";
-	    endfor
-	    __plot_data__{cf}{mxi,myi}{j} = tdata;
-	    __plot_data_type__{cf}{mxi,myi}(j) = 2;
-	    __plot_fmtstr__{cf}{mxi,myi}{j} = tfmtstr;
-	    __plot_key_labels__{cf}{mxi,myi}{j} = key;
-	    j++;
-	  endif
+	  [fmt, key] = __pltopt__ (caller, {""});
+	  __plt2__ (h, x, y, fmt, key);
 	  x = next_arg;
 	  y_set = false;
 	else
@@ -108,9 +77,7 @@
 
     endwhile
 
-    __plot_data_offset__{cf}(mxi,myi) = j;
-
-    __render_plot__ ();
+    drawnow ();
 
   else
     msg = sprintf ("%s (y)\n", caller);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__plt_get_axis_arg__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,47 @@
+## Copyright (C) 1996, 1997 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} {[@var{h}, @var{remaining_args}} plot (@var{args})
+## @end deftypefn
+
+## Author: jwe
+
+function [h, varargin] = __plt_get_axis_arg__ (caller, varargin)
+
+
+  if (nargin > 1)
+    tmp = varargin{1};
+    if (ishandle (tmp))
+      obj = get (tmp);
+      if (strcmp (obj.type, "axes"))
+	h = tmp;
+	varargin(1) = [];
+	if (isempty (varargin))
+	  varargin = {};
+	endif
+      else
+	error ("%s: expecting first argument to be axes handle", caller);
+      endif
+    else
+      h = gca ();
+    endif
+  endif
+
+endfunction
--- a/scripts/plot/__render_plot1__.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,154 +0,0 @@
-## Copyright (C) 2006 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.
-
-function __render_plot1__ (mxi, myi)
-
-  __plot_globals__;
-
-  cf = __current_figure__;
-
-  if (! isempty (__plot_data__{cf}{mxi,myi}))
-
-    have_image = false;
-
-    for j = 1:length (__plot_data__{cf}{mxi,myi})
-      if (__plot_data_type__{cf}{mxi,myi}(j) == 1)
-	have_image = true;
-      endif
-      ## Do this check before sending any commands to gnuplot so that if
-      ## there is an error, we don't leave things in a bad state.
-      if (j == 1)
-	first_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j);
-	this_plot_data_type = first_plot_data_type;
-      else
-	this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j);
-	if ((first_plot_data_type != 3 && this_plot_data_type == 3)
-	    || (first_plot_data_type == 3 && this_plot_data_type != 3))
-	  error ("can't mix 2-d and 3-d data in the same plot");
-	endif
-      endif
-    endfor
-
-    if (have_image)
-      __gnuplot_raw__ ("set size ratio -1;\n");
-
-      cmap = __plot_image_colormap__{cf}{mxi,myi};
-
-      palette_size = rows (cmap);
-      __gnuplot_raw__ (sprintf ("set palette positive color model RGB maxcolors %i\n",
-				palette_size));
-
-      __gnuplot_raw__ ("set palette file \"-\"\n");
-      tmp = round (1000 * cmap) / 1000;
-      tmp_rows = rows (tmp);
-      idx = (0:tmp_rows-1)';
-      __gnuplot_raw__ (sprintf ("%d %.4g %.4g %.4g\n", [idx, tmp]'));
-      __gnuplot_raw__("e\n");
-
-      __gnuplot_raw__ ("set yrange [:] reverse;\n");
-      __gnuplot_raw__ ("set autoscale fix\n"); # "fix" is helpful for "a" hotkey
-      __gnuplot_raw__ ("set tics out\n");
-    endif
-
-    first = true;
-
-    for j = 1:length (__plot_data__{cf}{mxi,myi})
-
-      this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j);
-
-      for i = 1:length (__plot_data__{cf}{mxi,myi}{j})
-
-	if (first)
-	  first = false;
-	  __do_legend__ ();
-	  if (first_plot_data_type == 3)
-	    cmd = gnuplot_command_splot;
-	  else
-	    cmd = gnuplot_command_plot;
-	  endif
-	  __gnuplot_raw__ (sprintf ("%s ", cmd));
-	else
-	  __gnuplot_raw__ (",\\\n");
-	endif
-
-	if (this_plot_data_type == 1)
-	  label = undo_string_escapes (__plot_key_labels__{cf}{mxi,myi}{j}{i});
-
-	  tmp = __plot_image_dims__{cf}{mxi,myi}{j}{i};
-
-	  x_dim = tmp(1);
-	  y_dim = tmp(2);
-	  x_origin = tmp(3);
-	  y_origin = tmp(4);
-	  dx = tmp(5);
-	  dy = tmp(6);
-
-	  A = __plot_data__{cf}{mxi,myi}{j}{i};
-
-	  ## Let the file be deleted when Octave exits or
-	  ## `purge_tmp_files' is called.
-	  [fid, binary_file_name, msg] ...
-	      = mkstemp (strcat (P_tmpdir, "/gpimageXXXXXX"), 1);
-
-	  ## Gnuplot reads binary files very quickly.  However, the
-	  ## 'fwrite' below is much slower than using the current
-	  ## '__gnuplot_plot__' command.
-	  fwrite (fid, A(:), "float");
-	  fclose (fid);
-
-	  __gnuplot_raw__ (sprintf ("\"%s\" binary array=%dx%d scan=yx flipy origin=(%g,%g) dx=%g dy=%g using 1 %s '%s' with image",
-				    binary_file_name, x_dim, y_dim, x_origin,
-				    y_origin, dx, dy,
-				    gnuplot_command_title, label));
-	else
-	  usingstr = __plot_usingstr__{cf}{mxi,myi}{j}{i};
-	  fmtstr = __plot_fmtstr__{cf}{mxi,myi}{j}{i};
-	  withstr = __plot_withstr__{cf}{mxi,myi}{j}{i};
-
-	  label = undo_string_escapes (__plot_key_labels__{cf}{mxi,myi}{j}{i});
-
-	  __gnuplot_raw__ (sprintf ("'-' %s %s '%s' %s %s %s", usingstr,
-				    gnuplot_command_title, label, fmtstr,
-				    withstr));
-	endif
-      endfor
-    endfor
-
-    for j = 1:length (__plot_data__{cf}{mxi,myi})
-      for i = 1:length (__plot_data__{cf}{mxi,myi}{j})
-	this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j);
-	if (this_plot_data_type != 1)
-	  if (this_plot_data_type == 3)
-	    parametric = __plot_data_parametric__{cf}{mxi,myi}{j}{i};
-	  else
-	    parametric = false;
-	  endif
-	  __gnuplot_send_inline_data__ (__plot_data__{cf}{mxi,myi}{j}{i},
-					this_plot_data_type, parametric);
-	endif
-      endfor
-    endfor
-
-    if (! first)
-      __gnuplot_raw__ ("\n");
-    endif
-
-  endif
-
-endfunction
--- a/scripts/plot/__render_plot__.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-## Copyright (C) 2006 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.
-
-function __render_plot__ (terminal, output)
-
-  __plot_globals__;
-
-  cf = __current_figure__;
-  mxn = __multiplot_xn__(cf);
-  myn = __multiplot_yn__(cf);
-
-  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
-
-    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
-
-	  columns = __multiplot_xn__(cf);
-	  rows = __multiplot_yn__(cf);
-	  __gnuplot_raw__ (sprintf ("set size %g, %g;\n",
-				    __multiplot_xsize__(cf),
-				    __multiplot_ysize__(cf)));
-
-	  xo = (mxi - 1.0) * __multiplot_xsize__(cf);
-	  yo = (rows - myi) * __multiplot_ysize__(cf);
-
-	  __gnuplot_raw__ (sprintf ("set origin %g, %g;\n", xo, yo));
-
-	  __render_plot1__ (mxi, myi)
-
-	endfor
-      endfor
-      __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/__setup_plot__.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-## 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.
-
-function __setup_plot__ (plotcmd)
-
-  __init_plot_vars__ (! ishold ());
-
-endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_adopt__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,45 @@
+## 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} {} __uiobject_adopt__ (@var{parent}, @var{child})
+## Add @var{child} to the list of children in @var{parent}.
+## @end deftypefn
+
+## Author: jwe
+
+function s = __uiobject_adopt__ (parent, child)
+
+  if (nargin == 2)
+    obj = get (parent);
+    if (! isempty (obj))
+      kids = obj.children;
+      ## Put this child at the end of the list.  If it is already in
+      ## the list, move it.
+      kids(kids == child) = [];
+      kids = [kids, child];
+      set (parent, "children", kids);
+    else
+      error ("__uiobject_adopt__: expecting parent to be a handle");
+    endif
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_alloc__.in	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,42 @@
+## 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} {} __uiobject_alloc__ ()
+## Return an index that points to an unused element of
+## @code{__uiobject_list__}.
+## @end deftypefn
+
+## Author: jwe
+
+function idx = __uiobject_alloc__ ()
+
+  __uiobject_globals__;
+
+  if (nargin == 0)
+    if (! __uiobject_head__)
+      __uiobject_grow_list__ ();
+    endif
+    idx = __uiobject_head__;
+    __uiobject_list__(__uiobject_head__).in_use = true;
+    __uiobject_head__ = __uiobject_list__(__uiobject_head__).next;
+  else
+    print_usage ();
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_axes_ctor__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,45 @@
+## 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} {} __uiobject_axes_ctor__ (p)
+## Create an axes object with parent @var{p}.
+## @end deftypefn
+
+## Author: jwe
+
+function h = __uiobject_axes_ctor__ (p, varargin)
+
+  if (nargin > 0)
+    s.type = "axes";
+    s.__dtor__ = @__uiobject_axes_dtor__;
+    s.parent = p;
+    s.children = [];
+    s.position = [];
+
+    h = __uiobject_make_handle__ (s);
+
+    __uiobject_axes_init__ (h);
+
+    set (h, varargin{:});
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_axes_dtor__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,47 @@
+## 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} {} __uiobject_axes_dtor__ (@var{obj})
+## Delete an axes object @var{obj}.
+## @end deftypefn
+
+## Author: jwe
+
+function __uiobject_axes_dtor__ (obj)
+
+  if (nargin == 1)
+    delete (obj.title);
+    delete (obj.xlabel);
+    delete (obj.ylabel);
+    delete (obj.zlabel);
+
+    obj.title = [];
+    obj.xlabel = [];
+    obj.ylabel = [];
+    obj.zlabel = [];
+
+    for child = obj.children
+      delete (child);
+    endfor
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_axes_init__.in	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,116 @@
+## 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} {@var{s}} __uiobject_axes_init__ (@var{s})
+## Initialize axes object.
+## @end deftypefn
+
+## Author: jwe
+
+function h = __uiobject_axes_init__ (h)
+
+  __uiobject_globals__;
+
+  if (nargin == 1)
+
+    s = get (h);
+
+    s.__setter__ = @__uiobject_axes_setr__;
+
+    s.title = __uiobject_text_ctor__ (h);
+
+    s.box = "on";
+    s.key = "off";
+    s.keybox = "off";
+    s.keypos = 1;
+
+    s.dataaspectratio = [1, 1, 1];
+    s.dataaspectratiomode = "auto";
+
+    s.xlim = [0, 1];
+    s.ylim = [0, 1];
+    s.zlim = [0, 1];
+
+    s.xlimmode = "auto";
+    s.ylimmode = "auto";
+    s.zlimmode = "auto";
+
+    s.xlabel = __uiobject_text_ctor__ (h);
+    s.ylabel = __uiobject_text_ctor__ (h);
+    s.zlabel = __uiobject_text_ctor__ (h);
+
+    s.xgrid = "off";
+    s.ygrid = "off";
+    s.zgrid = "off";
+
+    s.xminorgrid = "off";
+    s.yminorgrid = "off";
+    s.zminorgrid = "off";
+
+    s.xtick = [];
+    s.ytick = [];
+    s.ztick = [];
+
+    s.xtickmode = "auto";
+    s.ytickmode = "auto";
+    s.ztickmode = "auto";
+
+    s.xticklabel = [];
+    s.yticklabel = [];
+    s.zticklabel = [];
+
+    s.xticklabelmode = "auto";
+    s.yticklabelmode = "auto";
+    s.zticklabelmode = "auto";
+
+    s.xscale = "linear";
+    s.yscale = "linear";
+    s.zscale = "linear";
+
+    s.xdir = "normal";
+    s.ydir = "normal";
+    s.zdir = "normal";
+
+    s.view = [0, 90];
+
+    s.nextplot = "replace";
+
+    s.outerposition = [0, 0, 1, 1];
+
+    s.dataaspectratio = [];
+    s.dataaspectratiomode = "auto";
+
+    for child = s.children
+      delete (child);
+    endfor
+
+    s.children = [];
+
+    ## XXX FIXME XXX -- need to intialize all properties to default
+    ## values here.
+
+    idx = __uiobject_handle2idx__ (h);
+    __uiobject_list__(idx).object = s;
+
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_axes_setr__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,78 @@
+## 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} {@var{s}} __uiobject_axes_setr__ (@var{p}, @var{v}, @dots{}))
+## Set properties for axes objects.
+## @end deftypefn
+
+## Author: jwe
+
+function obj = __uiobject_axes_setr__ (h, varargin)
+
+  obj = get (h);
+
+  if (rem (nargin-1, 2) == 0)
+    if (isstruct (obj))
+      for i = 1:2:nargin-1
+	property = varargin{i};
+	if (ischar (property))
+	  key = tolower (property);
+	  if (isfield (obj, key))
+	    val = varargin{i+1};
+	    if (isfield (obj, "__validators__"))
+	      validators = obj.__validators__;
+	      if (isfield (validators, key))
+		feval (validators.(key), val);
+	      endif
+	    endif
+	    switch (key)
+	      case {"title", "xlabel", "ylabel", "zlabel"}
+		val = __uiobject_text_ctor__ (h, "string", val);
+
+	      case {"xlim", "ylim", "zlim"}
+		obj.(strcat (key, "mode")) = "manual";
+
+	      case "dataaspectratio"
+		obj.dataaspectratiomode = "manual";
+
+	      case {"xtick", "ytick", "ztick"}
+		obj.(strcat (key, "mode")) = "manual";
+
+	      case {"xticklabel", "yticklabel", "zticklabel"}
+		obj.(strcat (key, "mode")) = "manual";
+
+	    endswitch
+	    obj.(key) = val;
+	  else
+	    warning ("set: unrecognized property `%s' for uiobject `%s'",
+		     property, obj.type);
+	  endif
+	else
+	  error ("set: expecting property name to be a character string");
+	endif
+      endfor
+    else
+      error ("__uiobject_axes_setr__: expecting axes object as first arg");
+    endif
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_delete__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,60 @@
+## 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} {} delete (@var{h})
+## Delete the graphics object @var{h}
+## @end deftypefn
+
+## Author: jwe
+
+function __uiobject_delete__ (h)
+
+  if (nargin == 1)
+    if (ishandle (h))
+      obj = get (h);
+      if (strcmp (obj.type, "figure"))
+	ps = obj.__plot_stream__;
+	if (any (ps == fopen ("all")))
+	  pclose (ps);
+	endif
+      endif
+      if (isfield (obj, "__dtor__"))
+	feval (obj.__dtor__, obj);
+      else
+	for child = obj.children
+	  delete (child);
+	endfor
+      endif
+      ## Also remove this object from its parent's list of children.
+      if (isfield (obj, "parent"))
+	parent = obj.parent;
+	kids = get (parent, "children");
+	kids(kids == h) = [];
+	set (parent, "children", kids);
+      endif
+      __uiobject_free__ (h);
+    else
+      error ("delete: expecting argument to be a graphics object");
+    endif
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_draw_axes__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,656 @@
+## 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} {} __uiobject_draw_axes__ (@var{axis_obj}, @var{plot_stream})
+## Display the axes @var{axis_obj} on @var{plot_stream}.
+## @end deftypefn
+
+## Author: jwe
+
+function __uiobject_draw_axes__ (h, plot_stream)
+
+  if (nargin == 2)
+
+    axis_obj = get (h);
+
+    ## Set axis properties here?
+
+    if (! isempty (axis_obj.outerposition))
+      pos = axis_obj.outerposition;
+      fprintf (plot_stream, "set origin %g, %g;\n", pos(1), pos(2));
+      fprintf (plot_stream, "set size %g, %g;\n", pos(3), pos(4));
+    endif
+
+    if (! isempty (axis_obj.position))
+      pos = axis_obj.position;
+      fprintf (plot_stream, "set origin %g, %g;\n", pos(1), pos(2));
+      fprintf (plot_stream, "set size %g, %g;\n", pos(3), pos(4));
+    endif
+
+    if (strcmp (axis_obj.dataaspectratiomode, "manual"))
+      r = axis_obj.dataaspectratio
+      fprintf (plot_stream, "set size ratio %g;\n", -r(2)/r(1));
+    else
+      fputs (plot_stream, "set size noratio;\n");
+    endif
+
+    if (! isempty (axis_obj.title))
+      t = get (axis_obj.title);
+      if (isempty (t.string))
+	fputs (plot_stream, "unset title;\n");
+      else
+	fprintf (plot_stream, "set title \"%s\";\n",
+		 undo_string_escapes (t.string));
+      endif
+    endif
+
+    if (! isempty (axis_obj.xlabel))
+      t = get (axis_obj.xlabel);
+      if (isempty (t.string))
+	fputs (plot_stream, "unset xlabel;\n");
+      else
+	fprintf (plot_stream, "set xlabel \"%s\";\n",
+		 undo_string_escapes (t.string));
+      endif
+    endif
+
+    if (! isempty (axis_obj.ylabel))
+      t = get (axis_obj.ylabel);
+      if (isempty (t.string))
+	fputs (plot_stream, "unset ylabel;\n");
+      else
+	fprintf (plot_stream, "set ylabel \"%s\";\n",
+		 undo_string_escapes (t.string));
+      endif
+    endif
+
+    if (! isempty (axis_obj.zlabel))
+      t = get (axis_obj.zlabel);
+      if (isempty (t.string))
+	fputs (plot_stream, "unset zlabel;\n");
+      else
+	fprintf (plot_stream, "set zlabel \"%s\";\n",
+		 undo_string_escapes (t.string));
+      endif
+    endif
+
+    if (strcmp (axis_obj.xgrid, "on"))
+      fputs (plot_stream, "set grid xtics;\n");
+    else
+      fputs (plot_stream, "set grid noxtics;\n");
+    endif
+
+    if (strcmp (axis_obj.ygrid, "on"))
+      fputs (plot_stream, "set grid ytics;\n");
+    else
+      fputs (plot_stream, "set grid noytics;\n");
+    endif
+
+    if (strcmp (axis_obj.zgrid, "on"))
+      fputs (plot_stream, "set grid ztics;\n");
+    else
+      fputs (plot_stream, "set grid ztics;\n");
+    endif
+
+    if (strcmp (axis_obj.xminorgrid, "on"))
+      fputs (plot_stream, "set mxtics 5;\n");
+      fputs (plot_stream, "set grid mxtics;\n");
+    else
+      fputs (plot_stream, "set grid nomxtics;\n");
+    endif
+
+    if (strcmp (axis_obj.yminorgrid, "on"))
+      fputs (plot_stream, "set mytics 5;\n");
+      fputs (plot_stream, "set grid mytics;\n");
+    else
+      fputs (plot_stream, "set grid nomytics;\n");
+    endif
+
+    if (strcmp (axis_obj.zminorgrid, "on"))
+      fputs (plot_stream, "set mztics 5;\n");
+      fputs (plot_stream, "set grid mztics;\n");
+    else
+      fputs (plot_stream, "set grid nomztics;\n");
+    endif
+
+    if (strcmp (axis_obj.xtickmode, "manual"))
+      xtic = axis_obj.xtick;
+      if (isempty (xtic))
+	fputs (plot_stream, "unset xtics;\n");
+      else
+	## FIXME
+      endif
+    else
+      fputs (plot_stream, "set xtics;\n");
+    endif
+
+    if (strcmp (axis_obj.ytickmode, "manual"))
+      ytic = axis_obj.ytick;
+      if (isempty (ytic))
+	fputs (plot_stream, "unset ytics;\n");
+      else
+	## FIXME
+      endif
+    else
+      fputs (plot_stream, "set ytics;\n");
+    endif
+
+    if (strcmp (axis_obj.ztickmode, "manual"))
+      ztic = axis_obj.ztick;
+      if (isempty (ztic))
+	fputs (plot_stream, "unset ztics;\n");
+      else
+	## FIXME
+      endif
+    else
+      fputs (plot_stream, "set ztics;\n");
+    endif
+
+    if (strcmp (axis_obj.xticklabelmode, "manual"))
+      ## FIXME -- we should be able to specify the actual tick labels,
+      ## not just the format.
+      xticlabel = axis_obj.xticklabel;
+      fprintf (plot_stream, "set format x \"%s\";\n", xticlabel);
+    else
+      fputs (plot_stream, "set xtics;\n");
+    endif
+
+    if (strcmp (axis_obj.yticklabelmode, "manual"))
+      ## FIXME -- we should be able to specify the actual tick labels,
+      ## not just the format.
+      yticlabel = axis_obj.yticklabel;
+      fprintf (plot_stream, "set format y \"%s\";\n", yticlabel);
+    else
+      fputs (plot_stream, "set ytics;\n");
+    endif
+
+    if (strcmp (axis_obj.zticklabelmode, "manual"))
+      ## FIXME -- we should be able to specify the actual tick labels,
+      ## not just the format.
+      zticlabel = axis_obj.zticklabel;
+      fprintf (plot_stream, "set format z \"%s\";\n", zticlabel);
+    else
+      fputs (plot_stream, "set ztics;\n");
+    endif
+
+    xlogscale = strcmp (axis_obj.xscale, "log");
+    if (xlogscale)
+      fputs (plot_stream, "set logscale x;\n");
+    else
+      fputs (plot_stream, "unset logscale x;\n");
+    endif
+
+    ylogscale = strcmp (axis_obj.yscale, "log");
+    if (ylogscale)
+      fputs (plot_stream, "set logscale y;\n");
+    else
+      fputs (plot_stream, "unset logscale y;\n");
+    endif
+
+    zlogscale = strcmp (axis_obj.zscale, "log");
+    if (zlogscale)
+      fputs (plot_stream, "set logscale z;\n");
+    else
+      fputs (plot_stream, "unset logscale z;\n");
+    endif
+
+    xautoscale = strcmp (axis_obj.xlimmode, "auto");
+    yautoscale = strcmp (axis_obj.ylimmode, "auto");
+    zautoscale = strcmp (axis_obj.zlimmode, "auto");
+
+    kids = axis_obj.children;
+
+    nd = 0;
+    data_idx = 0;
+    data = cell ();
+
+    have_img_data = false;
+    img_data = [];
+
+    xminp = yminp = zminp = Inf;
+    xmax = ymax = zmax = -Inf;
+    xmin = ymin = zmin = Inf;
+
+    for i = 1:length (kids)
+
+      obj = get (kids(i));
+
+      switch (obj.type)
+	case "image"
+	  if (have_img_data)
+	    warning ("an axis can only display one image");
+	  endif
+	  have_img_data = true;
+	  img_data = obj.cdata;
+
+
+	case "line"
+	  data_idx++;
+	  if (isempty (obj.keylabel))
+	    titlespec{data_idx} = "";
+	  else
+	    titlespec{data_idx} = strcat ("title \"", obj.keylabel, "\"");
+	  endif
+	  usingclause{data_idx} = "";
+	  withclause{data_idx} = "";
+	  parametric(i) = true;
+	  if (! isempty (obj.zdata))
+	    nd = 3;
+	    xdat = obj.xdata(:);
+	    ydat = obj.ydata(:);
+	    zdat = obj.zdata(:);
+	    if (xautoscale)
+	      xmin = min (xmin, min (xdat));
+	      xmax = max (xmax, max (xdat));
+	      xminp = min (xminp, min (xdat(xdat>0)));
+	    endif
+	    if (yautoscale)
+	      ymin = min (ymin, min (ydat));
+	      ymax = max (ymax, max (ydat));
+	      yminp = min (yminp, min (ydat(ydat>0)));
+	    endif
+	    if (zautoscale)
+	      zmin = min (zmin, min (zdat));
+	      zmax = max (zmax, max (zdat));
+	      zminp = min (zminp, min (zdat(ydat>0)));
+	    endif
+	    data{data_idx} = [xdat, ydat, zdat]';
+	    usingclause{data_idx} = "using ($1):($2):($3)";
+	    fputs (plot_stream, "set parametric;\n");
+	    fputs (plot_stream, "unset hidden3d;\n");
+	    fputs (plot_stream, "set style data lines;\n");
+	    fputs (plot_stream, "set surface;\n");
+	    fputs (plot_stream, "unset contour;\n");
+	  else
+	    nd = 2;
+	    xdat = obj.xdata(:);
+	    ydat = obj.ydata(:);
+	    ldat = obj.ldata;
+	    yerr = xerr = false;
+	    if (! isempty (ldat))
+	      yerr = true;
+	      ldat = ldat(:);
+	    endif
+	    udat = obj.udata;
+	    if (! isempty (udat))
+	      udat = udat(:);
+	    endif
+	    xldat = obj.xldata;
+	    if (! isempty (xldat))
+	      xerr = true;
+	      xldat = xldat(:);
+	    endif
+	    xudat = obj.xudata;
+	    if (! isempty (xudat))
+	      xudat = xudat(:);
+	    endif
+	    if (yerr)
+	      ylo = ydat-ldat;
+	      yhi = ydat+udat;
+	      if (yautoscale)
+		ty = [ydat; ylo; yhi];
+		ymin = min (ymin, min (ty));
+		ymax = max (ymax, max (ty));
+		yminp = min (yminp, min (ty(ty>0)));
+	      endif
+	      if (xerr)
+		xlo = xdat-xldat;
+		xhi = xdat+xudat;
+		if (xautoscale)
+		  tx = [xdat; xlo; xhi];
+		  xmin = min (xmin, min (tx));
+		  xmax = max (xmax, max (tx));
+		  xminp = min (xminp, min (tx(tx>0)));
+		endif
+		data{data_idx} = [xdat, ydat, xlo, xhi, ylo, yhi]';
+		usingclause{data_idx} = "using ($1):($2):($3):($4):($5):($6)";
+		withclause{data_idx} = "with xyerrorbars";
+	      else
+		if (xautoscale)
+		  xmin = min (xmin, min (xdat));
+		  xmax = max (xmax, max (xdat));
+		  xminp = min (xminp, min (tx(tx>0)));
+		endif
+		data{data_idx} = [xdat, ydat, ylo, yhi]';
+		usingclause{data_idx} = "using ($1):($2):($3):($4)";
+		withclause{data_idx} = "with yerrorbars";
+	      endif
+	    elseif (xerr)
+	      xlo = xdat-xldat;
+	      xhi = xdat+xudat;
+	      if (xautoscale)
+		tx = [xdat; xlo; xhi];
+		xmin = min (xmin, min (tx));
+		xmax = max (xmax, max (tx));
+		xminp = min (xminp, min (tx(tx>0)));
+	      endif
+	      if (yautoscale)
+		ymin = min (ymin, min (ydat));
+		ymax = max (ymax, max (ydat));
+		yminp = min (yminp, min (ty(ty>0)));
+	      endif
+	      data{data_idx} = [xdat, ydat, xlo, xhi]';
+	      usingclause{data_idx} = "using ($1):($2):($3):($4)";
+	      withclause{data_idx} = "with xerrorbars";
+	    else
+	      if (xautoscale)
+		xmin = min (xmin, min (xdat));
+		xmax = max (xmax, max (xdat));
+		xminp = min (xminp, min (xdat(xdat>0)));
+	      endif
+	      if (yautoscale)
+		ymin = min (ymin, min (ydat));
+		ymax = max (ymax, max (ydat));
+		yminp = min (yminp, min (ydat(ydat>0)));
+	      endif
+	      data{data_idx} = [xdat, ydat]';
+	      usingclause{data_idx} = "using ($1):($2)";
+	    endif
+	  endif
+
+	case "surface"
+	  data_idx++;
+	  if (isempty (obj.keylabel))
+	    titlespec{data_idx} = "";
+	  else
+	    titlespec{data_idx} = strcat ("title \"", obj.keylabel, "\"");
+	  endif
+	  usingclause{data_idx} = "";
+	  withclause{data_idx} = "";
+	  parametric(i) = false;
+	  nd = 3;
+	  xdat = obj.xdata;
+	  ydat = obj.ydata;
+	  zdat = obj.zdata;
+	  if (xautoscale)
+	    tx = xdat(:);
+	    xmin = min (xmin, min (tx));
+	    xmax = max (xmax, max (tx));
+	    xminp = min (xminp, min (tx(tx>0)));
+	  endif
+	  if (yautoscale)
+	    ty = ydat(:);
+	    ymin = min (ymin, min (ty));
+	    ymax = max (ymax, max (ty));
+	    yminp = min (yminp, min (ty(ty>0)));
+	  endif
+	  if (zautoscale)
+	    tz = xdat(:);
+	    zmin = min (ymin, min (tz));
+	    zmax = max (ymax, max (tz));
+	    zminp = min (zminp, min (tz(tz>0)));
+	  endif
+	  err = false;
+	  if (isvector (xdat) && isvector (ydat) && ismatrix (zdat))
+	    if (rows (zdat) == length (ydat) && columns (zdat) == length (xdat))
+              [xdat, ydat] = meshgrid (xdat, ydat);
+	    else
+              err = true;
+	    endif
+	  elseif (ismatrix (xdat) && ismatrix (ydat) && ismatrix (zdat))
+	    if (! (size_equal (xdat, ydat) && size_equal (xdat, zdat)))
+              err = true;
+	    endif
+	  else
+	    err = true;
+	  endif
+	  if (err)
+	    error ("__uiobject_draw_axes__: invalid grid data");
+	  endif
+	  xlen = columns (zdat);
+	  ylen = rows (zdat);
+	  if (xlen == columns (xdat) && xlen == columns (ydat)
+	      && ylen == rows (xdat) && ylen == rows (ydat))
+	    len = 3 * xlen;
+	    zz = zeros (ylen, len);
+	    k = 1;
+	    for kk = 1:3:len
+	      zz(:,kk)   = xdat(:,k);
+	      zz(:,kk+1) = ydat(:,k);
+	      zz(:,kk+2) = zdat(:,k);
+	      k++;
+	    endfor
+	    data{data_idx} = zz;
+	    h = __gnuplot_save_data__ (zz, 3, false);
+	  endif
+	  usingclause{data_idx} = "using ($1):($2):($3)";
+	  withclause{data_idx} = "with line palette";
+
+	  fputs (plot_stream, "unset parametric;\n");
+	  fputs (plot_stream, "set hidden3d;\n");
+	  fputs (plot_stream, "set style data lines;\n");
+	  fputs (plot_stream, "set surface;\n");
+	  fputs (plot_stream, "unset contour;\n");
+	  fputs (plot_stream, "set palette defined (0 \"dark-blue\", 1 \"blue\", 2 \"cyan\", 3 \"yellow\", 4 \"red\" , 5 \"dark-red\");\n");
+	  fputs (plot_stream, "unset colorbox;\n");
+
+	case "text"
+	  lpos = obj.position;
+	  label = obj.string;
+	  halign = obj.horizontalalignment;
+	  if (nd == 3)
+	    fprintf (plot_stream, "set label \"%s\" at %d,%d,%d %s;\n",
+		     undo_string_escapes (label),
+		     lpos(1), lpos(2), lpos(3), halign);
+	  else
+	    fprintf (plot_stream, "set label \"%s\" at %d,%d %s;\n",
+		     undo_string_escapes (label),
+		     lpos(1), lpos(2), halign);
+	  endif
+
+	otherwise
+	  error ("__uiobject_draw_axes__: unknown object class, %s",
+		 obj.type);
+      endswitch
+
+    endfor
+
+    if (xautoscale)
+      xlim = get_axis_limits (xmin, xmax, xminp, xlogscale);
+      set (h, "xlim", xlim);
+    else
+      xlim = axis_obj.xlim;
+    endif
+    fprintf (plot_stream, "set xrange [%g:%g];\n", xlim);
+
+    if (yautoscale)
+      ylim = get_axis_limits (ymin, ymax, yminp, ylogscale);
+      set (h, "ylim", ylim);
+    else
+      ylim = axis_obj.ylim;
+    endif
+    fprintf (plot_stream, "set yrange [%g:%g];\n", ylim);
+
+    if (nd == 3)
+      if (zautoscale)
+	zlim = get_axis_limits (zmin, zmax, zminp, zlogscale);
+	set (h, "zlim", zlim);
+      else
+	zlim = axis_obj.zlim;
+      endif
+      fprintf (plot_stream, "set zrange [%g:%g];\n", zlim);
+    endif
+
+    if (strcmp (axis_obj.box, "on"))
+      if (nd == 3)
+	fputs (plot_stream, "set border 4095;\n");
+      else
+	fputs (plot_stream, "set border 431;\n");
+      endif
+    else
+      if (nd == 3)
+	fputs (plot_stream, "set border 895;\n");
+      else
+	fputs (plot_stream, "set border 3;\n");
+	fputs (plot_stream, "set xtics nomirror; set ytics nomirror;\n");
+      endif
+    endif
+
+    if (strcmp (axis_obj.key, "on"))
+      if (strcmp (axis_obj.keybox, "on"))
+	fputs (plot_stream, "set key box;\n");
+      else
+	fputs (plot_stream, "set key nobox;\n");
+      endif
+    else
+      fputs (plot_stream, "unset key;\n");
+    endif
+
+    fputs (plot_stream, "set style data lines;\n");
+    fflush (plot_stream);
+
+    if (nd == 2)
+      plot_cmd = "plot";
+    else
+      plot_cmd = "splot";
+    endif
+
+    have_data = false;
+
+    if (have_img_data)
+      [view_cmd, view_fcn, view_zoom] = image_viewer ();
+      if (ischar (view_fcn) && strcmp (view_fcn, "gnuplot_internal"))
+	have_data = true;
+
+	[y_dim, x_dim] = size (img_data);
+	if (x_dim > 1)
+	  dx = abs (xlim(2)-xlim(1))/(x_dim-1);
+	else
+	  dx = 1;
+	endif
+	if (y_dim > 1)
+	  dy = abs (ylim(2)-ylim(1))/(y_dim-1);
+	else
+	  dy = 1;
+	endif
+	x_origin = min (xlim);
+	y_origin = min (ylim);
+
+	## Let the file be deleted when Octave exits or `purge_tmp_files'
+	## is called.
+	[fid, fname] = mkstemp (strcat (P_tmpdir, "/gpimageXXXXXX"), 1);
+	fwrite (fid, img_data(:), "float");
+	fclose (fid);
+
+	fprintf (plot_stream, "plot \"%s\" binary array=%dx%d scan=yx flipy origin=(%g,%g) dx=%g dy=%g using 1 with image",
+		 fname, x_dim, y_dim, x_origin, y_origin, dx, dy);
+
+	plot_cmd = ",";
+      else
+	view_fcn (xlim, ylim, img_data, view_zoom, view_cmd);
+      endif
+    endif
+
+    if (! isempty (data))
+      have_data = true;
+
+      if (nd == 2)
+	fprintf (plot_stream, "%s '-' %s %s %s", plot_cmd,
+		 usingclause{1}, titlespec{1}, withclause{1});
+      else
+	rot_x = 90 - axis_obj.view(2);
+	rot_z = axis_obj.view(1);
+	while (rot_z < 0)
+	  rot_z += 360;
+	endwhile
+	fprintf (plot_stream, "set view %g, %g;\n", rot_x, rot_z);
+
+	fprintf (plot_stream, "%s '-' %s %s %s", plot_cmd,
+		 usingclause{i}, titlespec{1}, withclause{1});
+      endif
+      for i = 2:data_idx
+	fprintf (plot_stream, ", '-' %s %s %s", usingclause{i},
+		 titlespec{i}, withclause{i});
+      endfor
+      for i = 1:data_idx
+	fputs (plot_stream, "\n");
+	if (nd == 2)
+	  fprintf (plot_stream,
+		   strcat (repmat ("%g ", 1, rows (data{i})), "\n"),
+		   data{i});
+	else
+	  if (parametric(i))
+	    fprintf (plot_stream, "%g %g %g\n", data{i});
+	  else
+	    tmp = data{i};
+	    nc = columns (tmp);
+	    for j = 1:3:nc
+	      fprintf (plot_stream, "%g %g %g\n", tmp(:,j:j+2)');
+	      fputs (plot_stream, "\n");
+	    endfor
+	  endif
+	endif
+	fputs (plot_stream, "e");
+	fflush (plot_stream);
+      endfor
+    endif
+
+    if (have_data)
+      fputs (plot_stream, "\n");
+      fflush (plot_stream);
+    endif
+
+  else
+    print_usage ();
+  endif    
+
+endfunction
+
+function lim = get_axis_limits (min_val, max_val, min_pos, logscale)
+
+  ## FIXME -- this needs to make "nice" limits from the actual max and
+  ## min of the data.  For log plots, we will also need the smallest
+  ## strictly positive value, which we aren't currently computing and
+  ## caching above.
+
+  if (logscale)
+    if (isinf (min_pos))
+      warning ("axis: logscale with no positive values to plot");
+    endif
+    if (min_val < 0)
+      min_val = min_pos;
+      if (max_val < 0)
+	max_val = min_pos;
+      endif
+      warning ("axis: omitting negative data in log plot");
+    endif
+    if (min_val == max_val)
+      min_val = 0.9 * min_val;
+      max_val = 1.1 * max_val;
+    endif
+    min_val = 10 ^ floor (log10 (min_val));
+    max_val = 10 ^ ceil (log10 (max_val));
+  else
+    if (min_val == 0 && max_val == 0)
+      min_val = -1;
+      max_val = 1;
+    elseif (min_val == max_val)
+      min_val = 0.9 * min_val;
+      max_val = 1.1 * max_val;
+    endif
+    ## FIXME -- to do a better job, we should consider the tic spacing.
+    scale = 10 ^ floor (log10 (max_val - min_val) - 1);
+    min_val = scale * floor (min_val / scale);
+    max_val = scale * ceil (max_val / scale);
+  endif
+
+  lim = [min_val, max_val];
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_draw_figure__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,81 @@
+## 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} {} __uiobject_draw_figure__ (f)
+## Display the figure @var{f}.
+## @end deftypefn
+
+## Author: jwe
+
+function __uiobject_draw_figure__ (f, plot_stream)
+
+  if (nargin == 2)
+    if (strcmp (f.type, "figure"))
+
+      ## Set figure properties here?
+
+      kids = f.children;
+      nkids = length (kids);
+
+      if (nkids > 0)
+	axes_count = 0;
+	for i = 1:nkids
+	  obj = get (kids(i));
+	  switch (obj.type)
+	    case "axes"
+	      axes_count++;
+	  endswitch
+	endfor
+
+	multiplot_mode = axes_count > 1;
+
+	if (multiplot_mode)
+	  fputs (plot_stream, "reset; set multiplot;\n");
+	endif
+
+	for i = 1:nkids
+	  obj = get (kids(i));
+	  switch (obj.type)
+	    case "axes"
+	      __uiobject_draw_axes__ (kids(i), plot_stream);
+
+	    otherwise
+	      error ("__uiobject_draw_figure__: unknown object class, %s",
+		     obj.type);
+	  endswitch
+	endfor
+
+	if (multiplot_mode)
+	  fputs (plot_stream, "unset multiplot;\n");
+	endif
+      else
+	fputs (plot_stream, "reset; clear;\n");
+	fflush (plot_stream);
+      endif
+    else
+      error ("__uiobject_draw_figure__: expecting figure object, found `%s'",
+	     f.type);
+    endif
+  else
+    print_usage ();
+  endif    
+
+endfunction
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_figure_ctor__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,47 @@
+## 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} {} __uiobject_figure_ctor__ ()
+## Create a figure object with default properties.
+## @end deftypefn
+
+## Author: jwe
+
+function s = __uiobject_figure_ctor__ ()
+
+  if (nargin == 0)
+    ## XXX FIXME XXX -- need to intialize all properties to default
+    ## values here.
+    s.type = "figure";
+    s.__plot_stream__ = [];
+    ## ??? Are all figures children of the root figure?
+    s.parent = 0;
+    s.children = [];
+    s.nextplot = "replace";
+    s.closerequestfcn = @closereq;
+    s.currentaxes = [];
+    s.colormap = __default_colormap__ ();
+    s.visible = "on";
+    s.paperorientation = "portrait";
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_figures__.in	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,41 @@
+## 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} {} __uiobject_figures__ ()
+## Return a mstrix containing the handles of all figures (excluding the
+## root figure).
+## @end deftypefn
+
+## Author: jwe
+
+function retval = __uiobject_figures__ ()
+
+  __uiobject_globals__;
+
+  if (nargin == 0)
+    ## Ensure that we have a root figure object.
+    __uiobject_init_root_figure__ ();
+    handles = [__uiobject_list__.handle];
+    retval = handles(handles > 0);
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_free__.in	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,56 @@
+## 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} {} __uiobject_free__ (@var{h})
+## Clear the contents of the element of the @code{__uiobject_list__}
+## corresponding to the handle @var{h} and return the element to the
+## free list.
+## @end deftypefn
+
+## Author: jwe
+
+function __uiobject_free__ (h)
+
+  __uiobject_globals__;
+
+  if (nargin == 1)
+    idx = __uiobject_handle2idx__ (h);
+    if (! isempty (idx))
+      if (! isempty (__uiobject_list__) && __uiobject_list__(idx).in_use)
+	h = __uiobject_list__(idx).handle;
+	__uiobject_handles__ = complement (h, __uiobject_handles__);
+	__uiobject_list__(idx).next = __uiobject_head__;
+	__uiobject_list__(idx).in_use = false;
+	__uiobject_list__(idx).handle = NaN;
+	__uiobject_list__(idx).object = NaN;
+	__uiobject_head__ = idx;
+	if (h < 0)
+	  __uiobject_handles_free_list__(end+1) = h;
+        elseif (h > 0)
+          __uiobject_figure_handles_free_list__(end+1) = h;
+        endif
+      else
+	error ("__uiobject_free__: attempt to free unallocated element");
+      endif
+    endif
+  else
+    print_usage ();
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_get_handle__.in	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,40 @@
+## 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} {} __uiobject_get_handle__ ()
+## Return an unused uiobject handle.
+## @end deftypefn
+
+## Author: jwe
+
+function h = __uiobject_get_handle__ ()
+
+  __uiobject_globals__;
+
+  if (isempty (__uiobject_handles_free_list__))
+    h = min (__uiobject_handles__) - 1;
+  else
+    h = __uiobject_handles_free_list__(1);
+    __uiobject_handles_free_list__(1) = [];
+  endif
+
+  __uiobject_handles__ = union (__uiobject_handles__, h);
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_globals__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,78 @@
+
+  ## Any function that includes these variables should not be cleared.
+
+  mlock ();
+
+  ## The collection of current figure handles.  We need this to be able to
+  ## allocate the next unused figure number.
+
+  global __uiobject_figure_handles__;
+
+  if (isempty (__uiobject_figure_handles__))
+    __uiobject_figure_handles__ = create_set (0);
+    __lock_global__ ("__uiobject_figure_handles__");
+  endif
+
+  ## The collection of current handles to other graphics objects.  We need
+  ## this to be able to allocate the next unused handle.  Zero means we
+  ## don't have any objects yet.
+
+  global __uiobject_handles__;
+
+  if (isempty (__uiobject_handles__))
+    __uiobject_handles__ = create_set (0);
+    __lock_global__ ("__uiobject_handles__");
+  endif
+
+  ## A structure array of UI objects.  Allocating and freeing elements
+  ## from the array is handled by __uiobject_alloc__ and
+  ## __uiobject_free__.
+  ##
+  ## Each element in the array contains the fields 
+  ##
+  ##   next    Index of next free element
+  ##
+  ##   in_use  True if allocated, false otherwise
+  ##
+  ## An object in the list that has been initialized (by a function like
+  ## figure, axes, line, etc.) will also have the following fields:
+  ##
+  ##   handle  Integer graphics "handle".  For figure objects, this is
+  ##           non-negative integer (the "root" figure is 0).  For other
+  ##           objects, the handle is a negative integer.  You are not
+  ##           supposed to care about the specific value of the handle.
+  ##
+  ##   object  Structure containing the actual UI object (figure, axes,
+  ##           line, etc).
+
+  global __uiobject_list__;
+
+  if (isempty (__uiobject_list__))
+    __lock_global__ ("__uiobject_list__");
+  endif
+
+  ## Index of the first free object in __uiobject_list__.  If this is
+  ## zero, it means the list has not been created.
+
+  global __uiobject_head__;
+
+  if (isempty (__uiobject_head__))
+    __uiobject_head__ = 0;
+    __lock_global__ ("__uiobject_head__");
+  endif
+
+  ## A list of available figure handles
+
+  global __uiobject_figure_handles_free_list__;
+
+  if (isempty (__uiobject_figure_handles_free_list__))
+    __lock_global__ ("__uiobject_figure_handles_free_list__");
+  endif
+
+  ## A list of available uiobject handles
+
+  global __uiobject_handles_free_list__;
+
+  if (isempty (__uiobject_handles_free_list__))
+    __lock_global__ ("__uiobject_handles_free_list__");
+  endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_grow_list__.in	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,55 @@
+## 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} {} __uiobject_grow_list__ ()
+## Create or increase the size of @code{__uiobject_list__}.
+## @end deftypefn
+
+## Author: jwe
+
+function __uiobject_grow_list__ ()
+
+  __uiobject_globals__;
+
+  if (nargin == 0)
+    static grow_size = 100;
+    curr_size = length (__uiobject_list__);
+    new_size = curr_size + grow_size;
+    __uiobject_list__(new_size).next = 0;
+    __uiobject_list__(new_size).in_use = false;
+    __uiobject_list__(new_size).handle = NaN;
+    __uiobject_list__(new_size).object = NaN;
+    if (curr_size)
+      __uiobject_list__(curr_size).next = curr_size+1;
+      __uiobject_list__(curr_size).in_use = false;
+      __uiobject_list__(curr_size).handle = NaN;
+      __uiobject_list__(curr_size).object = NaN;
+    endif
+    for i = new_size-1:-1:curr_size+1
+      __uiobject_list__(i).next = i+1;
+      __uiobject_list__(i).in_use = false;
+      __uiobject_list__(i).handle = NaN;
+      __uiobject_list__(i).object = NaN;
+    endfor
+    __uiobject_head__ = curr_size+1;
+  else
+    print_usage ();
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_handle2idx__.in	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,38 @@
+## 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} {} __uiobject_handle2idx__ (@var{h})
+## Return the index in the __uiobject_list__ corresponding to the handle
+## @var{h}.
+## @end deftypefn
+
+## Author: jwe
+
+function idx = __uiobject_handle2idx__ (h)
+
+  __uiobject_globals__;
+
+  if (nargin == 1)
+    idx = find ([__uiobject_list__.handle] == h);
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_image_ctor__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,42 @@
+## 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} {} __uiobject_line_ctor__ (@var{p})
+## Create an image object with parent @var{p}.
+## @end deftypefn
+
+## Author: jwe
+
+function s = __uiobject_image_ctor__ (p)
+
+  if (nargin == 1)
+    s.type = "image";
+    s.parent = p;
+    s.children = [];
+
+    s.cdata = [];
+
+    ## XXX FIXME XXX -- need to intialize all properties to default
+    ## values here.
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_init_figure__.in	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,58 @@
+## 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} {@var{f} =} __uiobject_init_figure__ (@var{f})
+## Create figure in __uiobject_list__ and make it the current figure.
+## If @var{f} already exists, make it the current figure but don't
+## reinitialize it.  If @var{f} is not specified, allocate a new
+## figure handle and initialize it.
+## @end deftypefn
+
+## Author: jwe
+
+function f = __uiobject_init_figure__ (f)
+
+  __uiobject_globals__;
+
+  if (nargin == 0 || nargin == 1)
+
+    if (nargin == 0)
+      if (isempty (__uiobject_figure_handles_free_list__))
+	f = max (__uiobject_handles__) + 1;
+      else
+	f = __uiobject_figure_handles_free_list__(1);
+	__uiobject_figure_handles_free_list__(1) = [];
+      endif
+    endif
+
+    __uiobject_handles__ = union (__uiobject_handles__, f);
+
+    if (! ishandle (f))
+      idx = __uiobject_alloc__ ();
+      __uiobject_list__(idx).handle = f;
+      __uiobject_list__(idx).object = __uiobject_figure_ctor__ ();
+      __uiobject_adopt__ (0, f);
+    endif
+    set (0, "currentfigure", f);
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_init_root_figure__.in	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,41 @@
+## 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} {} __uiobject_init_root_figure__ ()
+## Create the root figure object, if it doesn't already exist.
+## @end deftypefn
+
+## Author: jwe
+
+function __uiobject_init_root_figure__ ()
+
+  __uiobject_globals__;
+
+  if (nargin == 0)
+    if (isempty (__uiobject_list__))
+      idx = __uiobject_alloc__ ();
+      __uiobject_list__(idx).handle = 0;
+      __uiobject_list__(idx).object = __uiobject_root_figure_ctor__ ();
+    endif
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_line_ctor__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,54 @@
+## 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} {} __uiobject_line_ctor__ (@var{p})
+## Create a line object with parent @var{p}.
+## @end deftypefn
+
+## Author: jwe
+
+function s = __uiobject_line_ctor__ (p)
+
+  if (nargin == 1)
+    s.type = "line";
+    s.parent = p;
+    s.children = [];
+
+    s.xdata = [];
+    s.ydata = [];
+    s.zdata = [];
+
+    s.ldata = [];
+    s.udata = [];
+
+    s.xldata = [];
+    s.xudata = [];
+
+    s.color = [];
+
+    s.keylabel = "";
+
+    ## XXX FIXME XXX -- need to intialize all properties to default
+    ## values here.
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_make_handle__.in	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,41 @@
+## 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} {@var{h} =} __uiobject_make_handle__ (@var{object})
+## Create handle for @var{object}.
+## @end deftypefn
+
+## Author: jwe
+
+function h = __uiobject_make_handle__ (s)
+
+  __uiobject_globals__;
+
+  if (nargin == 1)
+    idx = __uiobject_alloc__ ();
+    h = __uiobject_get_handle__ ();
+    __uiobject_list__(idx).handle = h;
+    __uiobject_list__(idx).object = s;
+    __request_drawnow__ ();
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_root_figure_ctor__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,42 @@
+## 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} {} __uiobject_root_figure_ctor__ ()
+## Create the root figure object with default properties.
+## @end deftypefn
+
+## Author: jwe
+
+function s = __uiobject_root_figure_ctor__ ()
+
+  if (nargin == 0)
+    ## XXX FIXME XXX -- need to intialize all properties to default
+    ## values here.
+    s.type = "root figure";
+    s.__plot_stream__ = [];
+    s.currentaxes = [];
+    s.currentfigure = [];
+    s.children = [];
+    s.visible = "on";
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_surface_ctor__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,46 @@
+## 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} {} __uiobject_surface_ctor__ (@var{p})
+## Create a surface object with parent @var{p}.
+## @end deftypefn
+
+## Author: jwe
+
+function s = __uiobject_surface_ctor__ (p)
+
+  if (nargin == 1)
+    s.type = "surface";
+    s.parent = p;
+    s.children = [];
+
+    s.xdata = [];
+    s.ydata = [];
+    s.zdata = [];
+
+    s.keylabel = "";
+
+    ## XXX FIXME XXX -- need to intialize all properties to default
+    ## values here.
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__uiobject_text_ctor__.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,50 @@
+## 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} {} __uiobject_text_ctor__ (p)
+## Create a text object with parent @var{p}.
+## @end deftypefn
+
+## Author: jwe
+
+function h = __uiobject_text_ctor__ (p, varargin)
+
+  if (nargin > 0)
+    ## XXX FIXME XXX -- need to intialize all properties to default
+    ## values here.
+    s.type = "text";
+    s.parent = p;
+    s.children = [];
+    s.string = "";
+
+    s.units = "data";
+    s.position = [0, 0, 0];
+    s.horizontalalignment = "left";
+
+    s.__validators__.string = @ischar;
+
+    h = __uiobject_make_handle__ (s);
+
+    set (h, varargin{:});
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/axes.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,58 @@
+## 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} {} axes ()
+## @deftypefnx {Function File} {} axes (@var{property}, @var{value}, @dots{})
+## @deftypefnx {Function File} {} axes (@var{h})
+## Create an axes object and return a handle to it.
+## @end deftypefn
+
+## Author: jwe
+
+function h = axes (varargin)
+
+  if (nargin == 0 || nargin > 1)
+    ## make default axes object, and make it the current axes for the
+    ## current figure.
+    cf = gcf ();
+    tmp = __uiobject_axes_ctor__ (cf, varargin{:});
+    __uiobject_adopt__ (cf, tmp);
+    set (cf, "currentaxes", tmp);
+  elseif (nargin == 1)
+    ## arg is axes handle, make it the current axes for the current
+    ## figure.
+    tmp = varargin{1};
+    obj = get (tmp);
+    if (! isempty (obj) && strcmp (obj.type, "axes"))
+      cf = gcf ();
+      __uiobject_adopt__ (cf, tmp);
+      set (cf, "currentaxes", tmp);
+    else
+      error ("axes: expecting argument to be axes handle");
+    endif
+  else
+    print_usage ();
+  endif
+
+  if (nargout > 0)
+    h = tmp;
+  endif
+
+endfunction
--- a/scripts/plot/axis.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/axis.m	Tue Jan 30 19:16:55 2007 +0000
@@ -117,23 +117,16 @@
 
 function curr_axis = axis (ax, varargin)
 
-  ## This may not be correct if someone has used the gnuplot interface
-  ## directly...
-
-  global __current_axis__ = [-10, 10, -10, 10];
-
-  ## To return curr_axis properly, octave needs to take control of scaling.
-  ## It isn't hard to compute good axis limits:
-  ##   scale = 10 ^ floor (log10 (max - min) - 1);
-  ##   r = scale * [floor (min / scale), ceil (max / scale)];
-  ## However, with axis("manual") there is little need to know the current
-  ## limits.
+  ca = gca ();
 
   if (nargin == 0)
     if (nargout == 0)
-      __gnuplot_raw__ ("set autoscale;\n");
+      set (ca, "xlimmode", "auto", "ylimmode", "auto", "zlimmode", "auto");
     else
-      curr_axis = __current_axis__;
+      xlim = get (ca, "xlim");
+      ylim = get (ca, "ylim");
+      zlim = get (ca, "zlim");
+      curr_axis = [xlim, ylim, zlim];
     endif
 
   elseif (ischar (ax))
@@ -142,96 +135,87 @@
 
     ## 'matrix mode' to reverse the y-axis
     if (strcmp (ax, "ij"))
-      __gnuplot_raw__ ("set yrange [] reverse;\n"); 
+      set (ca, "ydir", "reverse");
     elseif (strcmp (ax, "xy"))
-      __gnuplot_raw__ ("set yrange [] noreverse;\n");
+      set (ca, "ydir", "normal");
 
       ## aspect ratio
     elseif (strcmp (ax, "image"))
-      __gnuplot_raw__ ("set size ratio -1;\n"); 
-      __gnuplot_raw__ ("set autoscale;\n"); ## FIXME should be the same as "tight"
-    elseif (strcmp (ax, "equal"))
-      __gnuplot_raw__ ("set size ratio -1;\n");
-    elseif (strcmp (ax, "square"))
-      __gnuplot_raw__ ("set size ratio 1;\n");
+      set (ca, "dataaspectratio", [1, 1, 1]);
+      ## FIXME should be the same as "tight"
+      set (ca, "xlimmode", "auto", "ylimmode", "auto", "zlimmode", "auto");
+    elseif (strcmp (ax, "equal") || strcmp (ax, "square"))
+      set (ca, "dataaspectratio", [1, 1, 1]);
     elseif (strcmp (ax, "normal"))
-      __gnuplot_raw__ ("set size noratio;\n");
-
+      set (ca, "dataaspectratiomode", "auto");
 
       ## axis limits
     elseif (len >= 4 && strcmp (ax(1:4), "auto"))
       if (len > 4)
-      	__gnuplot_raw__ (sprintf ("set autoscale %s;\n", ax(5:len)));
+	if (any (ax == "x"))
+	  set (ca, "xlimmode", "auto");
+	endif
+	if (any (ax == "y"))
+	  set (ca, "ylimmode", "auto");
+	endif
+	if (any (ax == "z"))
+	  set (ca, "zlimmode", "auto");
+	endif
       else
-	__gnuplot_raw__ ("set autoscale;\n");
+	set (ca, "xlimmode", "auto", "ylimmode", "auto", "zlimmode", "auto");
       endif
     elseif (strcmp (ax, "manual"))
       ## fixes the axis limits, like axis(axis) should;
-      __gnuplot_raw__ ("set xrange [] writeback;\n");
-      __gnuplot_raw__ ("set yrange [] writeback;\n");
-      __gnuplot_raw__ ("set zrange [] writeback;\n");
-      ## FIXME if writeback were set in plot, no need to replot here.
-      ## No semicolon (see replot.m).
-      replot ();
-      __gnuplot_raw__ ("set noautoscale x;\n");
-      __gnuplot_raw__ ("set noautoscale y;\n");
-      __gnuplot_raw__ ("set noautoscale z;\n");
+      set (ca, "xlimmode", "manual", "ylimmode", "manual", "zlimmode", "manual");
     elseif (strcmp (ax, "tight"))
       ## FIXME if tight, plot must set ranges to limits of the
       ## all the data on the current plot, even if from a previous call.
       ## Instead, just let gnuplot do as it likes.
-      __gnuplot_raw__ ("set autoscale;\n");
-
+      set (ca, "xlimmode", "auto", "ylimmode", "auto", "zlimmode", "auto");
 
       ## tic marks
-    elseif (strcmp (ax, "on"))
-      __gnuplot_raw__ ("set xtics;\n");
-      __gnuplot_raw__ ("set ytics;\n");
-      __gnuplot_raw__ ("set ztics;\n");
-      __gnuplot_raw__ ("set format;\n");
+    elseif (strcmp (ax, "on") || strcmp (ax, "tic"))
+      set (ca, "xtickmode", "auto", "ytickmode", "auto", "ztickmode", "auto");
+      set (ca, "xticklabelmode", "auto", "yticklabelmode", "auto",
+	   "zticklabelmode", "auto");
     elseif (strcmp (ax, "off"))
-      __gnuplot_raw__ ("set noxtics;\n");
-      __gnuplot_raw__ ("set noytics;\n");
-      __gnuplot_raw__ ("set noztics;\n");
-    elseif (strcmp (ax, "tic"))
-      __gnuplot_raw__ ("set xtics;\n");
-      __gnuplot_raw__ ("set ytics;\n");
-      __gnuplot_raw__ ("set ztics;\n");
+      set (ca, "xtick", [], "ytick", [], "ztick", []);
     elseif (len > 3 && strcmp (ax(1:3), "tic"))
       if (any (ax == "x"))
-	__gnuplot_raw__ ("set xtics;\n");
+	set (ca, "xtickmode", "auto");
       else
-	__gnuplot_raw__ ("set noxtics;\n");
+	set (ca, "xtick", []);
       endif
       if (any (ax == "y"))
-	__gnuplot_raw__ ("set ytics;\n");
+	set (ca, "ytickmode", "auto");
       else
-	__gnuplot_raw__ ("set noytics;\n");
+	set (ca, "ytick", []);
       endif
       if (any (ax == "z"))
-	__gnuplot_raw__ ("set ztics;\n");
+	set (ca, "ztickmode", "auto");
       else
-	__gnuplot_raw__ ("set noztics;\n");
+	set (ca, "ztick", []);
       endif
     elseif (strcmp (ax, "label"))
-      __gnuplot_raw__ ("set format;\n");
+      set (ca, "xticklabelmode", "auto", "yticklabelmode", "auto",
+	   "zticklabelmode", "auto");
     elseif (strcmp (ax, "nolabel"))
-      __gnuplot_raw__ ("set format \"\\0\";\n");
+      set (ca, "xticklabel", "", "yticklabel", "", "zticklabel", "");
     elseif (len > 5 && strcmp (ax(1:5), "label"))
       if (any (ax == "x"))
-	__gnuplot_raw__ ("set format x;\n");
+	set (ca, "xticklabelmode", "auto");
       else
-	__gnuplot_raw__ ("set format x \"\\0\";\n");
+	set (ca, "xticklabel", "");
       endif
       if (any (ax == "y"))
-	__gnuplot_raw__ ("set format y;\n");
+	set (ca, "yticklabelmode", "auto");
       else
-	__gnuplot_raw__ ("set format y \"\\0\";\n");
+	set (ca, "yticklabel", "");
       endif
       if (any (ax == "z"))
-	__gnuplot_raw__ ("set format z;\n");
+	set (ca, "zticklabelmode", "auto");
       else
-	__gnuplot_raw__ ("set format z \"\\0\";\n");
+	set (ca, "zticklabel", "");
       endif
 
     else
@@ -252,18 +236,16 @@
       endif
     endfor
 
-    __current_axis__ = reshape (ax, 1, len);
-
     if (len > 1)
-      __gnuplot_raw__ (sprintf ("set xrange [%.16g:%.16g];\n", ax(1), ax(2)));
+      set (ca, "xlim", [ax(1), ax(2)]);
     endif
 
     if (len > 3)
-      __gnuplot_raw__ (sprintf ("set yrange [%.16g:%.16g];\n", ax(3), ax(4)));
+      set (ca, "ylim", [ax(3), ax(4)]);
     endif
 
     if (len > 5)
-      __gnuplot_raw__ (sprintf ("set zrange [%.16g:%.16g];\n", ax(5), ax(6)));
+      set (ca, "zlim", [ax(5), ax(6)]);
     endif
 
   else
--- a/scripts/plot/box.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/box.m	Tue Jan 30 19:16:55 2007 +0000
@@ -23,8 +23,6 @@
 ## Control the display of a border around the plot.
 ## The argument may be either @code{"on"} or @code{"off"}.  If it is
 ## omitted, the the current box state is toggled.
-##
-## Note, this function currently has no effect.
 ## @seealso{grid}
 ## @end deftypefn
 
@@ -32,6 +30,40 @@
 
 ## PKG_ADD: mark_as_command box
 
-function box ()
+function box (varargin)
+
+  ## [h, varargin] = __plt_get_axis_arg__ ("box", varargin{:});
+  h = gca ();
+
+  box_state = get (h, "box");
+
+  nargs = numel (varargin);
+
+  if (nargs == 0)
+    if (strcmp (box_state, "on"))
+      box_state = "off";
+    else
+      box_state = "on";
+    endif
+  elseif (nargs == 1)
+    state = varargin{1};
+    if (ischar (state))
+      if (strcmp ("off", state))
+	box_state = "off";
+      elseif (strcmp ("on", state))
+	box_state = "on";
+      else
+	print_usage ();
+      endif
+    endif
+  else
+    print_usage ();
+  endif
+
+  set (h, "box", box_state);
 
 endfunction
+
+  
+
+endfunction
--- a/scripts/plot/clf.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/clf.m	Tue Jan 30 19:16:55 2007 +0000
@@ -18,17 +18,24 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} clf
-## Clear the plot window and any titles or axis labels.  This function
-## is equivalent to @code{clearplot}.
+## @deftypefn {Function File} {} clf ()
+## Clear the current figure.
 ## @end deftypefn
 
+## Author: jwe
+
 function clf ()
 
-  __clear_plot_window__ ();
-
-  hold ("off");
-
-  __init_plot_vars__ ();
+  if (nargin == 0)
+    f = gcf ();
+    obj = get (f);
+    for child = obj.children
+      delete (child);
+    endfor
+    set (f, "currentaxes", []);
+    drawnow ();
+  else
+    print_usage ();
+  endif
 
 endfunction
--- a/scripts/plot/close.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/close.m	Tue Jan 30 19:16:55 2007 +0000
@@ -19,7 +19,9 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Command} {} close
+## @deftypefnx {Command} {} close (@var{n})
 ## @deftypefnx {Command} {} close all
+## @deftypefnx {Command} {} close all hidden
 ## Close the plot window(s).
 ## @end deftypefn
 
@@ -29,40 +31,31 @@
 
 function retval = close (arg1, arg2)
 
-  static warned_all = false;
-  static warned_name = false;
-  static warned_handle = false;
-
   if (nargin == 0)
-    if (! warned_all)
-      warned_all = true;
-      warning ("close: unable to close only current plot window");
-    endif
-    closeplot;
+    ## Close current figure.
+    figs = gcf ();
   elseif (nargin == 1)
-    if (ischar (arg1))
-      if (strcmp (arg1, "all"))
-	closeplot;
-      else
-	if (! warned_name)
-	  warned_name = true;
-	  warning ("close: unable to close plot windows by name");
-	endif
-      endif
+    if (ischar (arg1) && strcmp (arg1, "all"))
+      ## Close all figures.
+      figs = __uiobject_figures__ ();
+    elseif (isfigure (arg1))
+      figs = arg1;
     else
-      if (! warned_handle)
-	warned_handle = true;
-	warning ("close: unable to close plot windows by handle");
-      endif
+      error ("close: expecting argument to be \"all\" or a figure handle");
     endif
   elseif (nargin == 2
 	  && ischar (arg1) && strcmp (arg1, "all")
 	  && ischar (arg2) && strcmp (arg2, "hidden"))
-    closeplot;
+    figs = __uiobject_figures__ ();
   else
     print_usage ();
   endif
 
+  for h = figs
+    set (0, "currentfigure", h);
+    feval (get (h, "closerequestfcn"));
+  endfor
+
   if (nargout > 0)
     retval = 1;
   endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/closereq.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,44 @@
+## 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} {} closereq ()
+## Close the current figure.
+## @end deftypefn
+
+## Author: jwe
+
+function closereq ()
+
+  if (nargin == 0)
+    cf = get (0, "currentfigure");
+    if (cf != 0)
+      delete (cf);
+      figs = __uiobject_figures__ ();
+      if (isempty (figs))
+	set (0, "currentfigure", 0);
+      else
+	set (0, "currentfigure", figs(1));
+      endif
+    endif
+  else
+    print_usage ();
+  endif
+
+endfunction
--- a/scripts/plot/contour.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/contour.m	Tue Jan 30 19:16:55 2007 +0000
@@ -1,130 +1,85 @@
-## Copyright (C) 1996, 1997, 2002 John W. Eaton
+## Copyright (C) 2003 Shai Ayal
 ##
-## This file is part of Octave.
-##
-## Octave is free software; you can redistribute it and/or modify it
+## This program 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
+## OctPlot 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.
+## along with OctPlot; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} contour (@var{z}, @var{n})
-## @deftypefnx {Function File} {} contour (@var{x}, @var{y}, @var{z}, @var{n})
-## Make a contour plot of the three-dimensional surface described by
-## @var{z}.  Someone needs to improve @code{gnuplot}'s contour routines
-## before this will be very useful.
-## @seealso{plot, mesh, meshgrid}
+## @deftypefn {Function File} {} {@var{c}} = contour (@var{x},@var{y},@var{z},@var{vv})
+## Compute isolines (countour lines) of the matrix @var{z}. 
+## parameters @var{x}, @var{y} and @var{vn} are optional.
+##
+## The return value @var{c} is a 2 by @var{n} matrix containing the
+## contour lines in the following format
+##
+## @example
+## @var{c} = [lev1 , x1 , x2 , ... , levn , x1 , x2 , ... 
+##      len1   , y1 , y2 , ... , lenn   , y1 , y2 , ...  ]
+## @end example
+##
+## @noindent
+## in which contour line @var{n} has a level (height) of @var{levn} and
+## length of @var{lenn}.
+## 
+## If @var{x} and @var{y} are omitted they are taken as the row/column 
+## index of @var{z}.  @var{vn} is either a scalar denoting the number of
+## lines to compute or a vector containing the values of the lines.  If
+## only one value is wanted, set @code{@var{vn} = [val, val]}.  If
+## @var{vn} is omitted it defaults to 10.
+##
+## @example
+## @var{c}=contourc (@var{x}, @var{y}, @var{z}, linspace(0,2*pi,10))
+## @end example
+## @seealso{contourc,line,plot}
 ## @end deftypefn
 
-## Author: jwe
 
-function contour (x, y, z, n)
+## Author: shaia
+
+function retval = contour (varargin)
 
-  __plot_globals__;
+  [c, lev] = contourc (varargin{:});
 
-  cf = __current_figure__;
-  mxi = __multiplot_xi__(cf);
-  myi = __multiplot_yi__(cf);
+  cmap = get (gcf(), "colormap");
+  
+  levx = linspace (min (lev), max (lev), size (cmap, 1));
+
+  newplot ();
 
-  if (nargin == 1 || nargin == 2)
-    z = x;
-    if (nargin == 1) 
-      n = 10;
-    else
-      n = y; 
-    endif
-    if (ismatrix (z))
-      __gnuplot_raw__ ("set nosurface;\n");
-      __gnuplot_raw__ ("set contour;\n");
-      __gnuplot_raw__ ("set cntrparam bspline;\n");
-      if (isscalar (n))
-	command = sprintf ("set cntrparam levels %d;\n", n);
-      elseif (isvector (n))
-	tmp = sprintf ("%f", n(1));
-	for i = 2:length (n)
-	  tmp = sprintf ("%s, %f", tmp, n(i));
-	endfor
-	command = sprintf ("set cntrparam levels discrete %s;\n", tmp);
-      else
-	error ("contour: levels must be a scalar or vector") ;
-      endif
-      __gnuplot_raw__ (command);
-      __gnuplot_raw__ ("set view 0, 0, 1, 1;\n");
-      __plt3__ (z, true, "", "", "", [gnuplot_command_with, " l 1"]);
-    else
-      error ("contour: z of contour (z, levels) must be a matrix");
-    endif
-  elseif (nargin == 3 || nargin == 4)
-    if (nargin == 3)
-      n = 10;
-    endif
-    if (ismatrix (z))
-      size_msg = ["contour: columns(z) must be the same as length(x) and\n" \
-		  "rows(z) must be the same as length(y),\n" \
-		  "or x, y, and z must be matrices with the same size"];
-      if (isvector (x) && isvector (y))
-	xlen = length (x);
-	ylen = length (y);
-	if (xlen == columns (z) && ylen == rows (z))
-          if (rows (x) == 1)
-            x = x';
-          endif
-          len = 3 * ylen;
-          zz = zeros (xlen, len);
-          k = 1;
-          for i = 1:3:len
-            zz(:,i)   = x;
-            zz(:,i+1) = y(k) * ones (xlen, 1);
-            zz(:,i+2) = z(k,:)';
-            k++;
-          endfor
-	else
-          error (size_msg);
-	endif
-      else
-	z_size = size (z);
-	if (size_equal (z, x) && size_equal (z, y))
-	  nc = 3*z_size(1);
-	  zz = zeros (z_size(2), nc);
-	  zz(:,1:3:nc) = x';
-	  zz(:,2:3:nc) = y';
-	  zz(:,3:3:nc) = z';
-	else
-	  error (size_msg);
-	endif
-      endif
-      __gnuplot_raw__ ("set nosurface;\n");
-      __gnuplot_raw__ ("set contour;\n");
-      __gnuplot_raw__ ("set cntrparam bspline;\n");
-      if (isscalar (n))
-	command = sprintf ("set cntrparam levels %d;\n", n);
-      elseif (isvector (n))
-	tmp = sprintf ("%f", n(1));
-	for i = 2:length (n)
-	  tmp = sprintf ("%s, %f", tmp, n(i));
-	endfor
-	command = sprintf ("set cntrparam levels discrete %s;\n", tmp);
-      else
-	error ("contour: levels must be a scalar or vector") ;
-      endif
-      __gnuplot_raw__ (command);
-      __gnuplot_raw__ ("set view 0, 0, 1, 1;\n");
-      __plt3__ (zz, true, "", "", "", [gnuplot_command_with, " l 1"]);
-    else
-      error ("contour: x and y must be vectors and z must be a matrix");
-    endif
-  else
-    print_usage ();
+  ## decode contourc output format
+  i1 = 1;
+  while (i1 < length (c))
+    clev = c(1,i1);
+    clen = c(2,i1);
+
+    ccr = interp1 (levx, cmap(:,1), clev);
+    ccg = interp1 (levx, cmap(:,2), clev);
+    ccb = interp1 (levx, cmap(:,3), clev);
+
+    ii = i1+1:i1+clen;
+    line (c(1,ii), c(2,ii), "color", [ccr, ccg, ccb, 1]);
+
+    i1 += c(2,i1)+1;
+  endwhile
+  
+  drawnow ();
+
+  ## folowing DM's suggestion to surpress output if none asked for
+  if (nargout > 0)
+    retval = c;
   endif
 
 endfunction
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/contourc.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,105 @@
+## Copyright (C) 2003 Shai Ayal
+##
+## This program 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.
+##
+## OctPlot 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 OctPlot; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} [@var{c}, @var{lev}] =  contourc (@var{x}, @var{y}, @var{z}, @var{vv})
+## Compute isolines (countour lines) of the matrix @var{z}. 
+## Parameters @var{x}, @var{y} and @var{vn} are optional.
+##
+## The return value @var{lev} is a vector of the contour levels.
+## The return value @var{c} is a 2 by @var{n} matrix containing the
+## contour lines in the following format
+##
+## @example
+## @var{c} = [lev1 , x1 , x2 , ... , levn , x1 , x2 , ... 
+##      len1   , y1 , y2 , ... , lenn   , y1 , y2 , ...  ]
+## @end example
+##
+## @noindent
+## in which contour line @var{n} has a level (height) of @var{levn} and
+## length of @var{lenn}.
+## 
+## If @var{x} and @var{y} are omitted they are taken as the row/column 
+## index of @var{z}.  @var{vn} is either a scalar denoting the number of lines 
+## to compute or a vector containing the values of the lines. If only one 
+## value is wanted, set @code{@var{vn} = [val, val]};
+## If @var{vn} is omitted it defaults to 10.
+##
+## @example
+## @var{c}=contourc (@var{x}, @var{y}, @var{z}, linspace(0,2*pi,10))
+## @end example
+## @seealso{contour}
+## @end deftypefn
+
+## Author: shaia
+
+function [c, lev] = contourc (varargin)
+
+  if (nargin == 1)
+    vn = 10;
+    z = varargin{1};
+    x = 1:size(z,1);
+    y = 1:size(z,2);
+  elseif (nargin == 2)
+    vn = varargin{2};
+    z = varargin{1};
+    x = 1:size(z,1);
+    y = 1:size(z,2);
+  elseif (nargin == 3)
+    vn = 10;
+    x = varargin{1};
+    y = varargin{2};
+    z = varargin{3};
+  elseif (nargin == 4)
+    vn = varargin{4};
+    x = varargin{1};
+    y = varargin{2};
+    z = varargin{3};
+  else
+    print_usage ();
+  endif
+
+  if (isscalar (vn))
+    vv = linspace (min (z(:)), max (z(:)), vn+2)(2:end-1);
+  else
+    vv = unique (sort (vn));
+  endif
+
+  ## Vectorize the x,y vectors, assuming they are output from meshgrid.
+  if (! isvector (x))
+    x = x(1,:);
+  endif
+
+  if (! isvector (y))
+    y = y(:,1);
+  endif
+
+  ## Make everyone the right dimensions.
+  if (size (x, 2) == 1)
+    x = x';
+  endif
+  if (size (y, 2) == 1)
+    y = y';
+  endif
+
+  ## Now call __contourc__ for the real work...
+  c=__contourc__(x,y,z,vv);
+  if nargout==2,
+    lev = vv;
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/drawnow.m	Tue Jan 30 19:16:55 2007 +0000
@@ -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
--- a/scripts/plot/errorbar.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/errorbar.m	Tue Jan 30 19:16:55 2007 +0000
@@ -111,14 +111,11 @@
 
 function errorbar (varargin)
 
-  if (nargin < 2)
-    print_usage ();
-  endif
+  newplot ();
 
-  __gnuplot_raw__ ("set nologscale x;\n");
-  __gnuplot_raw__ ("set nologscale y;\n");
-  __gnuplot_raw__ ("set nopolar;\n");
+  ## [h, varargin] = __plt_get_axis_arg__ ("errorbar", varargin{:});
+  h = gca ();
 
-  __errcomm__ ("errorbar", varargin{:});
+  __errcomm__ ("errorbar", h, varargin{:});
 
 endfunction
--- a/scripts/plot/figure.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/figure.m	Tue Jan 30 19:16:55 2007 +0000
@@ -19,39 +19,45 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} figure (@var{n})
-## Set the current plot window to plot window @var{n}.  This function
-## currently requires X11 and a version of gnuplot that supports multiple
-## frames.  If @var{n} is not specified, the next available window
-## number is chosen.
+## Set the current plot window to plot window @var{n}.  If @var{n} is
+## not specified, the next available window number is chosen.
 ## @end deftypefn
 
-## Author: jwe
+## Author: jwe, Bill Denney
 
-function f = figure (n)
+function h = figure (varargin)
 
-  __plot_globals__;
+  nargs = nargin;
 
-  static figure_list = create_set (0);
-  static figure_called = 0;
-
-  if (nargin == 0)
-    f = max (figure_list) + 1;
-  else
-    f = n;
+  if (nargs == 0)
+    f = __uiobject_init_figure__ ();
+  elseif (mod (nargs, 2) == 1)
+    tmp = varargin{1};
+    if (ishandle (tmp) && strcmp (get (tmp, "type"), "figure"))
+      f = tmp;
+      varargin(1) = [];
+      nargs--;
+    elseif (isnumeric (tmp) && tmp > 0 && round (tmp) == tmp)
+      f = tmp;
+      __uiobject_init_figure__ (f);
+      varargin(1) = [];
+      nargs--;
+    else
+      error ("figure: expecting figure handle or figure number");
+    endif
   endif
 
-  if (nargin < 2)
-    if (isnumeric (f) && f > 0 && round (f) == f)
-      __current_figure__ = f;
-    else
-      error ("figure: expecting positive integer");
+  if (nargout > 0)
+    h = f;
+  endif
+
+  if (rem (nargs, 2) == 0)
+    if (nargs > 0)
+      set (f, varargin{:});
     endif
-    figure_list = union (figure_list, f);
-  elseif (rem (nargin, 2) == 0)
-    if (! figure_called)
-      figure_called = 1;
-      warning ("figure: setting figure properties is unsupported");
-    endif
+    __uiobject_adopt__ (0, f);
+    set (0, "currentfigure", f);
+    drawnow ();
   else
     print_usage ();
   endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/gca.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,38 @@
+## 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} {} gca ()
+## Return the current axis handle.
+## @end deftypefn
+
+## Author: jwe
+
+function h = gca ()
+
+  if (nargin == 0)
+    h = get (gcf (), "currentaxes");
+    if (isempty (h))
+      h = axes ();
+    endif
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/gcf.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,40 @@
+## 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} {} gcf ()
+## Return the current figure handle.
+## @end deftypefn
+
+## Author: jwe, Bill Denney
+
+function h = gcf ()
+
+  if (nargin == 0)
+    h = get (0, "currentfigure");
+    if (isempty (h) || h == 0)
+      ## We only have a root figure object, so create a new figure
+      ## object and make it the current figure.
+      h = figure (1);
+    endif
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/get.in	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,57 @@
+## 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} {} get (@var{h}, @var{p})
+## Return the named property @var{p} from the graphics handle @var{h}.
+## If @var{p} is omitted, return the complete property list for @var{h}.
+## @end deftypefn
+
+## Author: jwe
+
+function retval = get (h, property)
+
+  __uiobject_globals__;
+
+  if (nargin == 1 || nargin == 2)
+    if (ishandle (h))
+      idx = __uiobject_handle2idx__ (h);
+      obj = __uiobject_list__(idx).object;
+      if (nargin == 2)
+	if (ischar (property))
+	  key = tolower (property);
+	  if (isfield (obj, key))
+	    retval = obj.(key);
+	  else
+	    error ("get: object has no property named `%s'", property);
+	  endif
+	else
+	  error ("get: expecting property to be a character string");
+	endif
+      else
+	retval = obj;
+      endif
+    else
+      error ("get: invalid handle = %d", h);
+    endif
+  else
+    print_usage ();
+  endif
+
+endfunction
--- a/scripts/plot/grid.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/grid.m	Tue Jan 30 19:16:55 2007 +0000
@@ -20,15 +20,14 @@
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} grid (@var{arg})
 ## @deftypefnx {Function File} {} grid ("minor", @var{arg2})
-## For two-dimensional plotting, force the display of a grid on the plot.
+## Force the display of a grid on the plot.
 ## The argument may be either @code{"on"} or @code{"off"}.  If it is
 ## omitted, the the current grid state is toggled.
 ##
 ## If @var{arg} is @code{"minor"} then the minor grid is toggled. When
 ## using a minor grid a second argument @var{arg2} is allowed, which can
 ## be either @code{"on"} or @code{"off"} to explicitly set the state of
-## the minor grid, or alternatively a positive integer specifying the
-## number of minor grid lines.
+## the minor grid.
 ## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour,
 ## bar, stairs, replot, xlabel, ylabel, title}
 ## @end deftypefn
@@ -41,101 +40,58 @@
 
   persistent grid_on = false;
   persistent minor_on = false;
-  persistent minor_tics = 5;
+
+  nargs = nargin;
 
-  do_replot = false;
+  if (nargs == 2)
+    if (ishandle (x))
+      ax = x;
+      obj = get (x);
+      x = y;
+      nargs--;
+      if (! strcmp (obj.type, "axes"))
+	error ("grid: expecting first argument to be an axes object");
+      endif
+    else
+      print_usage ();
+    endif
+  else
+    ax = gca ();
+  endif
 
-  if (nargin == 0)
+  if (nargs == 0)
     grid_on = ! grid_on;
-    if (grid_on)
-      __gnuplot_raw__ ("set grid;\n");
-    else
-      __gnuplot_raw__ ("set nogrid;\n");
-    endif
-    do_replot = true;
-  elseif (nargin == 1)
+  elseif (nargs == 1)
     if (ischar (x))
       if (strcmp ("off", x))
-        __gnuplot_raw__ ("set nogrid;\n");
 	grid_on = false;
-	do_replot = true;
       elseif (strcmp ("on", x))
-        __gnuplot_raw__ ("set grid;\n");
 	grid_on = true;
-	do_replot = true;
       elseif (strcmp ("minor", x))
 	minor_on = ! minor_on;
 	if (minor_on)
-	  cmd = sprintf ("set mxtics %d;\n", minor_tics);
-	  __gnuplot_raw__ (cmd);
-	  cmd = sprintf ("set mytics %d;\n", minor_tics);
-	  __gnuplot_raw__ (cmd);
-          __gnuplot_raw__ ("set grid xtics mxtics ytics mxtics;\n");
-	  minor_on = true;
-	else
-	  if (grid_on)
-            __gnuplot_raw__ ("set grid xtics nomxtics ytics nomxtics;\n");
-	  else
-	    __gnuplot_raw__ ("set grid noxtics nomxtics noytics nomxtics;\n");
-	  endif
-	  minor_on = false;
+	  grid_on = true;
 	endif
-	do_replot = true;
       else
 	print_usage ();
       endif
     else
       error ("grid: argument must be a string");
     endif
-  elseif (nargin == 2)
-    if (ischar (x))
-      if (strcmp ("minor", x))
-	d = str2num (y);
-	if (isempty (d))
-	  if (strcmp ("off", y))
-	    if (grid_on)
-              __gnuplot_raw__ ("set grid xtics nomxtics ytics nomxtics;\n");
-	    else
-	      __gnuplot_raw__ ("set grid noxtics nomxtics noytics nomxtics;\n");
-	    endif
-	    minor_on = false;
-	  elseif (strcmp ("on", y))
-	    cmd = sprintf ("set mxtics %d;\n", minor_tics);
-	    __gnuplot_raw__ (cmd);
-	    cmd = sprintf ("set mytics %d;\n", minor_tics);
-	    __gnuplot_raw__ (cmd);
-            __gnuplot_raw__ ("set grid xtics mxtics ytics mxtics;\n");
-	    minor_on = true;
-	  else
-	    print_usage ();
-	  endif
-	  do_replot = true;
-	else
-	  if (isscalar(d) && ! isnan (d) && ! isinf (d))
-	    minor_tics = max (floor (d), 0);
-	    cmd = sprintf ("set mxtics %d;\n", minor_tics);
-	    __gnuplot_raw__ (cmd);
-	    cmd = sprintf("set mytics %d;\n", minor_tics);
-	    __gnuplot_raw__ (cmd);
-            __gnuplot_raw__ ("set grid xtics mxtics ytics mxtics;\n");
-	    minor_on = true;
-	    do_replot = true;
-	  else
-	    print_usage ();;
-	  endif
-	endif
-      else
-	print_usage ();;
-      endif
+  else
+    print_usage ();
+  endif
+
+  if (grid_on)
+    set (ax, "xgrid", "on", "ygrid", "on", "zgrid", "on");
+    if (minor_on)
+      set (ax, "xminorgrid", "on", "yminorgrid", "on", "zminorgrid", "on");
     else
-      print_usage ();;
-    endif    
+      set (ax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off");
+    endif
   else
-    print_usage ();;
-  endif    
-
-  if (do_replot && automatic_replot)
-    replot ();
+    set (ax, "xgrid", "off", "ygrid", "off", "zgrid", "off");
+    set (ax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off");
   endif
 
 endfunction
--- a/scripts/plot/hold.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/hold.m	Tue Jan 30 19:16:55 2007 +0000
@@ -37,35 +37,35 @@
 
 ## PKG_ADD: mark_as_command hold
 
-function hold (arg)
+function hold (varargin)
 
-  global __current_figure__;
-  global __hold_state__;
+  [h, varargin] = __plt_get_axis_arg__ ("hold", varargin{:});
 
-  if (isempty (__current_figure__))
-    __current_figure__ = 1;
-  endif
+  hold_state = get (h, "nextplot");
 
-  if (isempty (__hold_state__))
-    __hold_state__ = false;
-  endif
+  nargs = numel (varargin);
 
-  if (length (__hold_state__) < __current_figure__)
-    __hold_state__(__current_figure__) = false;
-  endif
-
-  if (nargin == 0)
-    __hold_state__(__current_figure__) = ! __hold_state__(__current_figure__);
-  elseif (nargin == 1)
-    if (strcmp (arg, "on"))
-      __hold_state__(__current_figure__) = true;
-    elseif (strcmp (arg, "off"))
-      __hold_state__(__current_figure__) = false;
+  if (nargs == 0)
+    if (strcmp (hold_state, "add"))
+      hold_state = "replace";
     else
-      print_usage ();
+      hold_state = "add";
+    endif
+  elseif (nargs == 1)
+    state = varargin{1};
+    if (ischar (state))
+      if (strcmp ("off", state))
+	hold_state = "replace";
+      elseif (strcmp ("on", state))
+	hold_state = "add";
+      else
+	print_usage ();
+      endif
     endif
   else
     print_usage ();
   endif
 
+  set (h, "nextplot", hold_state);
+
 endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/include-globals.awk	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,8 @@
+/^ *__uiobject_globals__;?.*$/ {
+  print "  ## BEGIN text from __uiobject_globals__.m";
+  system (sprintf ("cat %s", file));
+  print "  ## END text from __uiobject_globals__.m";
+  next;
+} {
+  print $0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/isfigure.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,36 @@
+## 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} {} isfigure (@var{h})
+## Return 1 if @var{h} is a graphics handle that contains a figure
+## object and 0 otherwise.
+## @end deftypefn
+
+## Author: jwe
+
+function retval = isfigure (h)
+
+  if (nargin == 1)
+    retval = (ishandle (h) && strcmp (get (h, "type"), "figure"));
+  else
+    print_usage ();
+  endif
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/ishandle.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,38 @@
+## 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} {} ishandle (@var{h})
+## Return 1 if @var{h} is a graphics handle and 0 otherwise.
+## @end deftypefn
+
+## Author: jwe
+
+function retval = ishandle (h)
+
+  if (nargin == 1)
+    ## Ensure that we have a root figure object.
+    __uiobject_init_root_figure__ ();
+    retval = (isnumeric (h) && isscalar (h) && round (h) == h
+	      && ! isempty (__uiobject_handle2idx__ (h)));
+  else
+    print_usage ();
+  endif
+
+endfunction
--- a/scripts/plot/ishold.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/ishold.m	Tue Jan 30 19:16:55 2007 +0000
@@ -25,23 +25,8 @@
 
 function retval = ishold ()
 
-  global __current_figure__;
-  global __hold_state__;
-
-  if (isempty (__current_figure__))
-    __current_figure__ = 1;
-  endif
-
-  if (isempty (__hold_state__))
-    __hold_state__ = false;
-  endif
-
-  if (length (__hold_state__) < __current_figure__)
-    __hold_state__(__current_figure__) = false;
-  endif
-
   if (nargin == 0)
-    retval = __hold_state__(__current_figure__);
+    retval = strcmp (get (gca (), "nextplot"), "add");
   else
     print_usage ();
   endif
--- a/scripts/plot/legend.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/legend.m	Tue Jan 30 19:16:55 2007 +0000
@@ -72,19 +72,15 @@
 
 function legend (varargin)
 
-  __plot_globals__;
+  nargs = nargin;
 
-  cf = __current_figure__;
-  mxi = __multiplot_xi__(cf);
-  myi = __multiplot_yi__(cf);
-
-  nargs = nargin;
+  ca = gca ();
 
   if (nargs > 0)
     pos = varargin{nargs};
     if (isnumeric (pos) && isscalar (pos) && round (pos) == pos)
       if (pos >= -3 && pos <= 4)
-	__plot_key_properties__{cf}{mxi,myi}.position = pos;
+	set (ca, "keypos", pos);
 	nargs--;
       else
 	error ("legend: invalid position specified");
@@ -92,6 +88,11 @@
     endif
   endif
 
+  kids = get (ca, "children");
+  nkids = numel (kids);
+  k = 1;
+  turn_on_legend = false;
+
   if (nargs == 1)
     arg = varargin{1};
     if (ischar (arg))
@@ -99,19 +100,30 @@
 	str = tolower (deblank (arg));
 	switch (str)
 	  case {"off", "hide"}
-	    __plot_key_properties__{cf}{mxi,myi}.visible = false;
+	    set (ca, "key", "off");
 	  case "show"
-	    __plot_key_properties__{cf}{mxi,myi}.visible = true;
+	    set (ca, "key", "on");
 	  case "toggle"
-	    __plot_key_properties__{cf}{mxi,myi}.visible ...
-	      = ! __plot_key_properties__{cf}{mxi,myi}.visible;
+	    val = get (ca, "key");
+	    if (strcmp (val, "on"))
+	      set (ca, "key", "off");
+	    else
+	      set (ca, "key", "on");
+	    endif
 	  case "boxon"
-	    __plot_key_properties__{cf}{mxi,myi}.visible = true;
-	    __plot_key_properties__{cf}{mxi,myi}.box = true;
+	    set (ca, "key", "on", "keybox", "on");
 	  case "boxoff"
-	    __plot_key_properties__{cf}{mxi,myi}.box = false;
+	    set (ca, "keybox", "off");
 	  otherwise
-	    __plot_key_labels__{cf}{mxi,myi}{1} = arg;
+	    while (k <= nkids && ! strcmp (get (kids(k), "type"), "line"))
+	      k++;
+	    endwhile
+	    if (k <= nkids)
+	      turn_on_legend = true;
+	      set (kids(k), "keylabel", arg);
+	    else
+	      warning ("legend: ignoring extra labels");
+	    endif
 	endswitch
 	nargs--;
       else
@@ -133,14 +145,23 @@
   for i = 1:nargs
     arg = varargin{i};
     if (ischar (arg))
-      __plot_key_labels__{cf}{mxi,myi}{i} = arg;
+      while (k <= nkids && ! strcmp (get (kids(k), "type"), "line"))
+	k++;
+      endwhile
+      if (k <= nkids)
+	set (kids(k), "keylabel", arg);
+	turn_on_legend = true;
+      elseif (! warned)
+	warned = true;
+	warning ("legend: ignoring extra labels");
+      endif
     else
       error ("legend: expecting argument to be a character string");
     endif
   endfor
 
-  if (automatic_replot)
-    replot ();
+  if (turn_on_legend)
+    set (ca, "key", "on");
   endif
 
 endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/line.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,61 @@
+## 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} {} line (@var{x}, @var{y})
+## @deftypefnx {Function File} {} line (@var{x}, @var{y}, @var{z})
+## Create line object from @var{x} and @var{y} and insert in current
+## axes object.  Return handle to line object.
+## @end deftypefn
+
+## Author: jwe
+
+function h = line (varargin)
+
+  nargs = nargin;
+
+  if (nargs > 1)
+    if (isnumeric (varargin{1}) && isnumeric (varargin{2}))
+      ## make a default line object, and make it the current axes for
+      ## the current figure.
+      ca = gca ();
+      s = __uiobject_line_ctor__ (ca);
+      s.xdata = varargin{1};
+      s.ydata = varargin{2};
+      num_data_args = 2;
+      if (nargs > 2 && isnumeric (varargin{3}))
+	s.zdata = varargin{3};
+	num_data_args = 3;
+      endif
+      tmp = __uiobject_make_handle__ (s);
+      if (nargs > num_data_args)
+	set (tmp, varargin{num_data_args+1:end});
+      endif
+      __uiobject_adopt__ (ca, tmp);
+      if (nargout > 0)
+	h = tmp;
+      endif
+    else
+      error ("expecting numeric arguments for line data");
+    endif
+  else
+    print_usage ();
+  endif
+
+endfunction
--- a/scripts/plot/loglog.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/loglog.m	Tue Jan 30 19:16:55 2007 +0000
@@ -30,14 +30,13 @@
 
 function loglog (varargin)
 
-  ## FIXME -- these plot states should really just be set
-  ## temporarily, probably inside an unwind_protect block, but there is
-  ## no way to determine their current values.
+  newplot ();
 
-  __gnuplot_raw__ ("set logscale x;\n");
-  __gnuplot_raw__ ("set logscale y;\n");
-  __gnuplot_raw__ ("set nopolar;\n");
+  ## [h, varargin] = __plt_get_axis_arg__ ("loglog", varargin{:});
+  h = gca ();
 
-  __plt__ ("loglog", varargin{:});
+  set (h, "xscale", "log", "yscale", "log");
+
+  __plt__ ("loglog", h, varargin{:});
 
 endfunction
--- a/scripts/plot/loglogerr.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/loglogerr.m	Tue Jan 30 19:16:55 2007 +0000
@@ -42,14 +42,13 @@
 
 function loglogerr (varargin)
 
-  if (nargin < 2)
-    print_usage ();
-  endif
+  newplot ();
 
-  __gnuplot_raw__ ("set logscale x;\n");
-  __gnuplot_raw__ ("set logscale y;\n");
-  __gnuplot_raw__ ("set nopolar;\n");
+  ## [h, varargin] = __plt_get_axis_arg__ ("loglog", varargin{:});
+  h = gca ();
 
-  __errcomm__ ("loglogerr", varargin{:});
+  set (h, "xscale", "log", "yscale", "log");
+
+  __errcomm__ ("loglogerr", h, varargin{:});
 
 endfunction
--- a/scripts/plot/mesh.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/mesh.m	Tue Jan 30 19:16:55 2007 +0000
@@ -30,26 +30,22 @@
 
 ## Author: jwe
 
-function mesh (x, y, z)
-
-  __plot_globals__;
-
-  cf = __current_figure__;
-  mxi = __multiplot_xi__(cf);
-  myi = __multiplot_yi__(cf);
+function h = mesh (x, y, z)
 
   if (nargin == 1)
     z = x;
     if (ismatrix (z))
-      [x, y] = meshgrid(0:columns(z)-1, 0:rows(z)-1);
+      [nr, nc] = size (z);
+      x = 1:nc;
+      y = (1:nr)';
     else
       error ("mesh: argument must be a matrix");
     endif
   elseif (nargin == 3)
     if (isvector (x) && isvector (y) && ismatrix (z))
       if (rows (z) == length (y) && columns (z) == length (x))
-        x = repmat(x(:)', rows (z), 1);
-        y = repmat(y(:), 1, columns (z));
+        x = x(:)';
+        y = y(:);
       else
         msg = "mesh: rows (z) must be the same as length (y) and";
         msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg);
@@ -66,32 +62,24 @@
     print_usage ();
   endif
 
-  ## Show the mesh.
-  xlen = columns (z);
-  ylen = rows (z);
-  if (xlen == columns (x) && xlen == columns (y)
-      && ylen == rows (x) && ylen == rows (y))
-    len = 3 * xlen;
-    zz = zeros (ylen, len);
-    k = 1;
-    for i = 1:3:len
-      zz(:,i)   = x(:,k);
-      zz(:,i+1) = y(:,k);
-      zz(:,i+2) = z(:,k);
-      k++;
-    endfor
-    __gnuplot_raw__ ("set hidden3d;\n");
-    __gnuplot_raw__ ("set data style lines;\n");
-    __gnuplot_raw__ ("set surface;\n");
-    __gnuplot_raw__ ("set nocontour;\n");
-    __gnuplot_raw__ ("set nologscale;\n");
-    __gnuplot_raw__ ("set view 60, 30, 1, 1;\n");
-    __gnuplot_raw__ ("set palette defined (0 \"dark-blue\", 1 \"blue\", 2 \"cyan\", 3 \"yellow\", 4 \"red\" , 5 \"dark-red\");\n");
-    __gnuplot_raw__ ("set nocolorbox;\n");
-    __plt3__ (zz, true, "", "", "",
-	      sprintf ("%s line palette", gnuplot_command_with ()));
-  else
-    error ("mesh: x, y, and z must have same dimensions");
+  ## make a default line object, and make it the current axes for the
+  ## current figure.
+  ca = gca ();
+
+  s = __uiobject_surface_ctor__ (ca);
+
+  s.xdata = x;
+  s.ydata = y;
+  s.zdata = z;
+
+  set (ca, "view", [-37.5, 30]);
+
+  tmp = __uiobject_make_handle__ (s);
+
+  __uiobject_adopt__ (ca, tmp);
+
+  if (nargout > 0)
+    h = tmp;
   endif
 
 endfunction
--- a/scripts/plot/mplot.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-## Copyright (C) 1996, 1997 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} {} mplot (@var{x}, @var{y})
-## @deftypefnx {Function File} {} mplot (@var{x}, @var{y}, @var{fmt})
-## @deftypefnx {Function File} {} mplot (@var{x1}, @var{y1}, @var{x2}, @var{y2})
-## This is a modified version of the @code{plot} function that works with
-## the multiplot version of @code{gnuplot} to plot multiple plots per page.
-## This plot version automatically advances to the next subplot position
-## after each set of arguments are processed.
-##
-## See the description of the @var{plot} function for the various options.
-## @end deftypefn
-
-## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
-## Adapted-By: jwe
-
-function mplot (varargin)
-
-  __plot_globals__;
-
-  cf = __current_figure__;
-
-  __gnuplot_raw__ ("set nologscale;\n");
-  __gnuplot_raw__ ("set nopolar;\n");
-
-  __plt__ ("plot", varargin{:});
-
-  ## update the plot position
-
-  if (__multiplot_mode__(cf))
-
-    if (__multiplot_xi__(cf) < __multiplot_xn__(cf))
-      __multiplot_xi__(cf)++;
-    else
-      __multiplot_xi__(cf) = 1;
-      if (__multiplot_yi__(cf) < __multiplot_yn__(cf))
-        __multiplot_yi__(cf)++;
-      else
-        __multiplot_yi__(cf) = 1;
-      endif
-    endif
-
-    xo = (__multiplot_xi__(cf) - 1.0) * __multiplot_xsize__(cf);
-    yo = (__multiplot_yn__(cf) - __multiplot_yi__(cf)) * __multiplot_ysize__(cf);
-
-    __gnuplot_raw__ (sprintf ("set origin %g, %g;\n", xo, yo));
-
-  endif
-
-endfunction
--- a/scripts/plot/multiplot.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +0,0 @@
-## Copyright (C) 1996, 1997 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} {} multiplot (@var{xn}, @var{yn})
-## Sets and resets multiplot mode.
-##
-## If the arguments are non-zero, @code{multiplot} will set up multiplot
-## mode with @var{xn}, @var{yn} subplots along the @var{x} and @var{y}
-## axes.  If both arguments are zero, @code{multiplot} closes multiplot
-## mode.
-## @end deftypefn
-
-## Author: Vinayak Dutt, Dutt.Vinayak@mayo.EDU
-## Created: 3 July 95
-## Adapted-By: jwe
-
-function multiplot (xn, yn)
-
-  plot_globals;
-
-  cf = __current_figure__;
-
-  if (nargin != 2)
-    print_usage ();
-  endif
-
-  if (! (isscalar (xn) && isscalar (yn)))
-    error ("multiplot: xn and yn have to be scalars");
-  endif
-
-  xn = round (xn);
-  yn = round (yn);
-
-  if (xn == 0 && yn == 0)
-
-    oneplot ();
-
-    __multiplot_xsize__(cf) = 1;
-    __multiplot_ysize__(cf) = 1;
-    __multiplot_xn__(cf) = 1;
-    __multiplot_yn__(cf) = 1;
-    __multiplot_xi__(cf) = 1;
-    __multiplot_yi__(cf) = 1;
-
-  else
-
-    if (xn < 1 || yn < 1)
-      error ("multiplot: xn and yn have to be positive integers");
-    endif
-
-    __gnuplot_raw__ ("set multiplot;\n");
-
-    xsize = 1.0 ./ xn;
-    ysize = 1.0 ./ yn;
-
-    __gnuplot_raw__ (sprintf ("set size %g, %g;\n", xsize, ysize));
-
-    xo = 0.0;
-    yo = (yn - 1.0)*ysize;
-
-    __gnuplot_raw__ (sprintf ("set origin %g, %g;\n", xo, yo));
-
-    __multiplot_mode__(cf) = true;
-    __multiplot_xsize__(cf) = xsize;
-    __multiplot_ysize__(cf) = ysize;
-    __multiplot_xn__(cf) = xn;
-    __multiplot_yn__(cf) = yn;
-    __multiplot_xi__(cf) = 1;
-    __multiplot_yi__(cf) = 1;
-
-    gnuplot_command_replot = "cle;rep";
-
-    clearplot;
-
-  endif
-
-endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/newplot.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,52 @@
+## 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} {} newplot ()
+## @end deftypefn
+
+function newplot ()
+
+  if (nargin == 0)
+    cf = gcf ();
+    fnp = get (cf, "nextplot");
+    switch (fnp)
+      case "new"
+      case "add"
+	return;
+      case "replacechildren"
+      case "replace"
+      otherwise
+	error ("newplot: unrecognized nextplot property for current figure");
+    endswitch
+    ca = gca ();
+    anp = get (ca, "nextplot");
+    switch (anp)
+      case "add"
+      case "replacechildren"
+      case "replace"
+	__uiobject_axes_init__ (ca);
+      otherwise
+	error ("newplot: unrecognized nextplot property for current axes");
+    endswitch
+  else
+    print_usage ();
+  endif
+
+endfunction
--- a/scripts/plot/oneplot.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-## Copyright (C) 1996, 1997 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} {} oneplot ()
-## If in multiplot mode, switches to single plot mode.
-## @end deftypefn
-
-## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
-## Created: 3 July 95
-## Adapted-By: jwe
-
-function oneplot ()
-
-  plot_globals;
-
-  if (__multiplot_mode__(__current_figure__))
-    __gnuplot_raw__ ("set nomultiplot;\n");
-    __gnuplot_raw__ ("set size 1, 1;\n");
-    __gnuplot_raw__ ("set origin 0, 0;\n");
-    __multiplot_mode__(__current_figure__) = false;
-    gnuplot_command_replot = "rep";
-  endif
-
-endfunction
--- a/scripts/plot/orient.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/orient.m	Tue Jan 30 19:16:55 2007 +0000
@@ -29,15 +29,24 @@
 
 ## PKG_ADD: mark_as_command orient
 
-function retval = orient (orientation)
+function retval = orient (varargin)
 
-  static __print_orientation__ = "landscape";
+  nargs = nargin;
 
-  if (nargin == 0)
-    retval = __print_orientation__;
+  if (nargs > 0 && ishandle (varargin{1}))
+    cf = varargin{1};
+    varargin(1) = [];
+    nargs--;
+  else
+    cf = gcf ();
+  endif
+
+  if (nargs == 0)
+    retval = get (cf, "paperorientation");
   elseif (nargin == 1)
+    orientation = varargin{1};
     if (strcmp (orientation, "landscape") || strcmp (orientation, "portrait"))
-      __print_orientation__ = orientation;
+      set (cf, "paperorientation", orientation)
     else
       error ("orient: unknown orientation");
     endif
@@ -47,10 +56,10 @@
 
 endfunction
 
-%!assert(orient,"landscape") # default
+%!assert(orient,"portrait") # default
+%!test orient('landscape')
+%!assert(orient,"landscape") # change to landscape
 %!test orient('portrait')
 %!assert(orient,"portrait")  # change to portrait
-%!test orient('landscape')
-%!assert(orient,"landscape") # change to landscape
 %!fail("orient('nobody')","unknown orientation")
-%!assert(orient,"landscape") # errors don't change the state
+%!assert(orient,"portrait") # errors don't change the state
--- a/scripts/plot/plot.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/plot.m	Tue Jan 30 19:16:55 2007 +0000
@@ -173,13 +173,11 @@
 
 function plot (varargin)
 
-  ## FIXME -- these plot states should really just be set
-  ## temporarily, probably inside an unwind_protect block, but there is
-  ## no way to determine their current values.
+  newplot ();
 
-  __gnuplot_raw__ ("set nologscale;\n");
-  __gnuplot_raw__ ("set nopolar;\n");
+  ## [h, varargin] = __plt_get_axis_arg__ ("plot", varargin{:});
+  h = gca ();
 
-  __plt__ ("plot", varargin{:});
+  __plt__ ("plot", h, varargin{:});
 
 endfunction
--- a/scripts/plot/plot3.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/plot3.m	Tue Jan 30 19:16:55 2007 +0000
@@ -165,135 +165,37 @@
 
 function plot3 (varargin)
 
-  __plot_globals__;
-
-  cf = __current_figure__;
-  mxi = __multiplot_xi__(cf);
-  myi = __multiplot_yi__(cf);
-
-  hold_state = ishold ();
-  
-  unwind_protect
+  x_set = 0;
+  y_set = 0;
+  z_set = 0;
 
-    x_set = 0;
-    y_set = 0;
-    z_set = 0;
-    
-    ## Gather arguments, decode format, and plot lines.
-    for arg = 1:nargin
-      new = varargin{arg};
-      
-      if (ischar (new))
-	if (! z_set)
-	  if (! y_set)
-	    if (! x_set)
-	      error ("plot3: needs x, [ y, [ z ] ]");
-	    else
-	      z = imag (x);
-	      y = real (x);
-	      y_set = 1;
-	      z_set = 1;
-	      if (rows(x) > 1)
-	        x = repmat ((1:rows(x))', 1, columns(x));
-	      else
-	        x = 1:columns(x);
-	      endif
-	    endif
-	  else
-	    z = imag (y);
-	    y = real (y);
-	    z_set = 1;
-	  endif
-	endif
-	[fmt, key] = __pltopt__ ("plot3", new);
-
-	if (isvector (x) && isvector (y))
-	  if (isvector (z))
-	    x = x(:);
-	    y = y(:);
-	    z = z(:);
-	  elseif (length (x) == rows (z) && length (y) == columns (z))
-	    error ("plot3: [length(x), length(y)] must match size(z)");
-	  else
-	    [x, y] = meshgrid (x, y);
-	  endif
-	endif
-
-	if (! size_equal (x, y) || ! size_equal (x, z))
-	  error ("plot3: x, y, and z must have the same shape");
-	endif
-
-	__gnuplot_raw__ ("set nohidden3d;\n")
-
-	__plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ...
-		 ([y; NaN*ones(1,size(y,2))])(:), ...
-		 ([z; NaN*ones(1,size(z,2))])(:)],
-		  true, "u($1):($2):($3)", fmt{1}, key{1});
+  ## Gather arguments, decode format, and plot lines.
+  for arg = 1:nargin
+    new = varargin{arg};
 
-	hold ("on");
-	x_set = 0;
-	y_set = 0;
-	z_set = 0;
-      elseif (! x_set)
-	x = new;
-	x_set = 1;
-      elseif (! y_set)
-	y = new;
-	y_set = 1;
-      elseif (! z_set)
-	z = new;
-	z_set = 1;
-      else
-	if (isvector (x) && isvector (y))
-	  if (isvector (z))
-	    x = x(:);
-	    y = y(:);
-	    z = z(:);
-	  elseif (length (x) == rows (z) && length (y) == columns (z))
-	    error ("plot3: [length(x), length(y)] must match size(z)");
+    if (ischar (new))
+      if (! z_set)
+	if (! y_set)
+	  if (! x_set)
+	    error ("plot3: needs x, [ y, [ z ] ]");
 	  else
-	    [x, y] = meshgrid (x, y);
+	    z = imag (x);
+	    y = real (x);
+	    y_set = 1;
+	    z_set = 1;
+	    if (rows(x) > 1)
+	      x = repmat ((1:rows(x))', 1, columns(x));
+	    else
+	      x = 1:columns(x);
+	    endif
 	  endif
-	endif
-
-	if (! size_equal (x, y) || ! size_equal (x, z))
-	  error ("plot3: x, y, and z must have the same shape");
+	else
+	  z = imag (y);
+	  y = real (y);
+	  z_set = 1;
 	endif
-
-	__gnuplot_raw__ ("set nohidden3d;\n")
-
-	__plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ...
-		   ([y; NaN*ones(1,size(y,2))])(:), ...
-		   ([z; NaN*ones(1,size(z,2))])(:)], true);
-
-	hold ("on");
-	x = new;
-	y_set = 0;
-	z_set = 0;
       endif
-       
-    endfor
-    
-    ## Handle last plot.
-    
-    if (x_set)
-      if (y_set)
-        if (! z_set)
-          z = imag (y);
-          y = real (y);
-          z_set = 1;
-        endif
-      else
-        z = imag (x);
-        y = real (x);
-        y_set = 1;
-        z_set = 1;
-        if (rows (x) > 1)
-          x = repmat ((1:rows (x))', 1, columns(x));
-        else
-          x = 1:columns(x);
-        endif
-      endif
+      [fmt, key] = __pltopt__ ("plot3", new);
 
       if (isvector (x) && isvector (y))
 	if (isvector (z))
@@ -311,19 +213,90 @@
 	error ("plot3: x, y, and z must have the same shape");
       endif
 
-      __gnuplot_raw__ ("set nohidden3d;\n")
+      line (x(:), y(:), z(:));
+
+      ## FIXME -- what about fmt and key?
+      ## fmt{1}, key{1});
 
-      __plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ...
-		 ([y; NaN*ones(1,size(y,2))])(:), ...
-		 ([z; NaN*ones(1,size(z,2))])(:)], true);
+      x_set = 0;
+      y_set = 0;
+      z_set = 0;
+    elseif (! x_set)
+      x = new;
+      x_set = 1;
+    elseif (! y_set)
+      y = new;
+      y_set = 1;
+    elseif (! z_set)
+      z = new;
+      z_set = 1;
+    else
+      if (isvector (x) && isvector (y))
+	if (isvector (z))
+	  x = x(:);
+	  y = y(:);
+	  z = z(:);
+	elseif (length (x) == rows (z) && length (y) == columns (z))
+	  error ("plot3: [length(x), length(y)] must match size(z)");
+	else
+	  [x, y] = meshgrid (x, y);
+	endif
+      endif
+
+      if (! size_equal (x, y) || ! size_equal (x, z))
+	error ("plot3: x, y, and z must have the same shape");
+      endif
+
+      line (x(:), y(:), z(:));
+
+      x = new;
+      y_set = 0;
+      z_set = 0;
     endif
-    
-  unwind_protect_cleanup
-    
-    if (! hold_state)
-      hold ("off");
+
+  endfor
+
+  ## Handle last plot.
+
+  if (x_set)
+    if (y_set)
+      if (! z_set)
+	z = imag (y);
+	y = real (y);
+	z_set = 1;
+      endif
+    else
+      z = imag (x);
+      y = real (x);
+      y_set = 1;
+      z_set = 1;
+      if (rows (x) > 1)
+	x = repmat ((1:rows (x))', 1, columns(x));
+      else
+	x = 1:columns(x);
+      endif
     endif
-    
-  end_unwind_protect
+
+    if (isvector (x) && isvector (y))
+      if (isvector (z))
+	x = x(:);
+	y = y(:);
+	z = z(:);
+      elseif (length (x) == rows (z) && length (y) == columns (z))
+	error ("plot3: [length(x), length(y)] must match size(z)");
+      else
+	[x, y] = meshgrid (x, y);
+      endif
+    endif
+
+    if (! size_equal (x, y) || ! size_equal (x, z))
+      error ("plot3: x, y, and z must have the same shape");
+    endif
+
+    line (x(:), y(:), z(:));
+
+  endif
+
+  set (gca (), "view", [-37.5, 30]);
 
 endfunction
--- a/scripts/plot/plot_border.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,117 +0,0 @@
-## Copyright (C) 1996, 1997 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} {} plot_border (...)
-## Multiple arguments allowed to specify the sides on which the border
-## is shown.  Allowed arguments include:
-##
-## @table @code
-## @item "blank"
-## No borders displayed.
-##
-## @item "all"
-## All borders displayed
-##
-## @item "north"
-## North Border
-##
-## @item "south"
-## South Border
-##
-## @item "east"
-## East Border
-##
-## @item "west"
-## West Border
-## @end table
-##
-## @noindent
-## The arguments may be abbreviated to single characters.  Without any
-## arguments, @code{plot_border} turns borders off.
-## @end deftypefn
-
-## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
-## Created: 3 July 95
-## Adapted-By: jwe
-
-function plot_border (varargin)
-
-  south = 0;
-  west = 0;
-  north = 0;
-  east = 0;
-  all = 0;
-  none = 1;
-
-  k = 1;
-
-  nargs = nargin ();
-
-  while (nargs--)
-
-    arg = varargin{k++};
-
-    if (! ischar (arg))
-      error ("plot_border: input not a string");
-    endif
-
-    ## The effect of the arguments in cumulative.  If something is found
-    ## after "b", do that and ignore "b".
-
-    if (strcmp (arg, "blank") || strcmp (arg, "BLANK")
-        || strcmp (arg, "b") || strcmp (arg, "B"))
-      none = 1;
-    else
-      none = 0;
-      if (strcmp (arg, "south") || strcmp (arg, "SOUTH")
-          || strcmp (arg, "s") || strcmp (arg, "S"))
-        south = 1;
-      elseif (strcmp (arg, "west") || strcmp (arg, "WEST")
-              || strcmp (arg, "w") || strcmp (arg, "W"))
-        west = 2;
-      elseif (strcmp (arg, "north") || strcmp (arg, "NORTH")
-              || strcmp (arg, "n") || strcmp (arg, "N"))
-        north = 4;
-      elseif (strcmp (arg, "east") || strcmp (arg, "EAST")
-              || strcmp (arg, "e") || strcmp (arg, "E"))
-        east = 8;
-      elseif (strcmp (arg, "all") || strcmp (arg, "ALL")
-              || strcmp (arg, "a") || strcmp (arg, "A"))
-        all = 1;
-      endif
-    endif
-  endwhile
-
-  if (none)
-    __gnuplot_raw__ ("set noborder;\n");
-  else
-    if (all)
-      border = 15;
-    else
-      border = south + west + north + east;
-    endif
-    __gnuplot_raw__ (sprintf ("set border %d;\n", border));
-  endif
-
-  if (automatic_replot)
-    replot ();
-  endif
-
-endfunction
--- a/scripts/plot/polar.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/polar.m	Tue Jan 30 19:16:55 2007 +0000
@@ -29,30 +29,30 @@
 
 ## Author: jwe
 
-function polar (x1, x2, fmt)
+function polar (varargin)
 
-  ## FIXME -- these plot states should really just be set
-  ## temporarily, probably inside an unwind_protect block, but there is
-  ## no way to determine their current values.
+  newplot ();
 
-  __gnuplot_raw__ ("set nologscale;\n");
-  __gnuplot_raw__ ("set nopolar;\n");
+  ## [h, varargin] = __plt_get_axis_arg__ ("semilogx", varargin{:});
+  h = gca ();
 
-  if (nargin == 3)
-    if (! ischar (fmt))
+  nargs = numel (varargin);
+
+  if (nargs == 3)
+    if (! ischar (varargin{3}))
       error ("polar: third argument must be a string");
     endif
-    __plr2__ (x1, x2, fmt);
+    __plr2__ (h, varargin{:});
   elseif (nargin == 2)
-    if (ischar (x2))
-      __plr1__ (x1, x2);
+    if (ischar (varargin{2}))
+      __plr1__ (h, varargin{:});
     else
       fmt = "";
-      __plr2__ (x1, x2, fmt);
+      __plr2__ (h, varargin{:}, fmt);
     endif
   elseif (nargin == 1)
     fmt = "";
-    __plr1__ (x1, fmt);
+    __plr1__ (h, varargin{:}, fmt);
   else
     print_usage ();
   endif
--- a/scripts/plot/print.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/print.m	Tue Jan 30 19:16:55 2007 +0000
@@ -101,10 +101,6 @@
 
 function print (varargin)
 
-  __plot_globals__;
-
-  mpmode = __multiplot_mode__(__current_figure__);
-
   orientation = orient ();
   use_color = 0; # 0=default, -1=mono, +1=color
   force_solid = 0; # 0=default, -1=dashed, +1=solid
@@ -301,7 +297,7 @@
     new_terminal = dev;
   endif
 
-  __render_plot__ (new_terminal, name);
+  drawnow (new_terminal, name);
 
   if (! isempty (convertname))
     command = sprintf ("convert '%s' '%s'", name, convertname);
--- a/scripts/plot/replot.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/replot.m	Tue Jan 30 19:16:55 2007 +0000
@@ -27,7 +27,7 @@
 function replot ()
   
   if (nargin == 0)
-    __render_plot__ ();
+    drawnow ();
   else
     print_usage ();
   endif
--- a/scripts/plot/semilogx.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/semilogx.m	Tue Jan 30 19:16:55 2007 +0000
@@ -30,14 +30,13 @@
 
 function semilogx (varargin)
 
-  ## FIXME -- these plot states should really just be set
-  ## temporarily, probably inside an unwind_protect block, but there is
-  ## no way to determine their current values.
+  newplot ();
 
-  __gnuplot_raw__ ("set logscale x;\n");
-  __gnuplot_raw__ ("set nologscale y;\n");
-  __gnuplot_raw__ ("set nopolar;\n");
+  ## [h, varargin] = __plt_get_axis_arg__ ("semilogx", varargin{:});
+  h = gca ();
 
-  __plt__ ("semilogx", varargin{:});
+  set (h, "xscale", "log");
+
+  __plt__ ("semilogx", h, varargin{:});
 
 endfunction
--- a/scripts/plot/semilogxerr.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/semilogxerr.m	Tue Jan 30 19:16:55 2007 +0000
@@ -42,14 +42,13 @@
 
 function semilogxerr (varargin)
 
-  if (nargin < 2)
-    print_usage ();
-  endif
+  newplot ();
 
-  __gnuplot_raw__ ("set logscale x;\n");
-  __gnuplot_raw__ ("set nologscale y;\n");
-  __gnuplot_raw__ ("set nopolar;\n");
+  ## [h, varargin] = __plt_get_axis_arg__ ("loglog", varargin{:});
+  h = gca ();
 
-  __errcomm__ ("semilogxerr", varargin{:});
+  set (h, "xscale", "log");
+
+  __errcomm__ ("semilogxerr", h, varargin{:});
 
 endfunction
--- a/scripts/plot/semilogy.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/semilogy.m	Tue Jan 30 19:16:55 2007 +0000
@@ -30,14 +30,13 @@
 
 function semilogy (varargin)
 
-  ## FIXME -- these plot states should really just be set
-  ## temporarily, probably inside an unwind_protect block, but there is
-  ## no way to determine their current values.
+  newplot ();
 
-  __gnuplot_raw__ ("set nologscale x;\n");
-  __gnuplot_raw__ ("set logscale y;\n");
-  __gnuplot_raw__ ("set nopolar;\n");
+  ## [h, varargin] = __plt_get_axis_arg__ ("semilogy", varargin{:});
+  h = gca ();
 
-  __plt__ ("semilogy", varargin{:});
+  set (h, "yscale", "log");
+
+  __plt__ ("semilogy", h, varargin{:});
 
 endfunction
--- a/scripts/plot/semilogyerr.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/semilogyerr.m	Tue Jan 30 19:16:55 2007 +0000
@@ -42,14 +42,13 @@
 
 function semilogyerr (varargin)
 
-  if (nargin < 2)
-    print_usage ();
-  endif
+  newplot ();
 
-  __gnuplot_raw__ ("set nologscale x;\n");
-  __gnuplot_raw__ ("set logscale y;\n");
-  __gnuplot_raw__ ("set nopolar;\n");
+  ## [h, varargin] = __plt_get_axis_arg__ ("loglog", varargin{:});
+  h = gca ();
 
-  __errcomm__ ("semilogyerr", varargin{:});
+  set (h, "yscale", "log");
+
+  __errcomm__ ("semilogyerr", h, varargin{:});
 
 endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/set.in	Tue Jan 30 19:16:55 2007 +0000
@@ -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} {} set (@var{h}, @var{p}, @var{v}, @dots{})
+## Set the named property @var{p} to the value @var{v} in the graphics
+## handle @var{h}.
+## @end deftypefn
+
+## Author: jwe
+
+function retval = set (h, varargin)
+
+  __uiobject_globals__;
+  
+  if (rem (nargin-1, 2) == 0)
+    if (ishandle (h))
+      idx = __uiobject_handle2idx__ (h);
+      obj = __uiobject_list__(idx).object;
+
+      if (isfield (obj, "__setter__"))
+        obj = feval (obj.__setter__, h, varargin{:});
+      else
+	for i = 1:2:nargin-1
+	  property = varargin{i};
+	  if (ischar (property))
+	    key = tolower (property);
+	    if (isfield (obj, key))
+	      val = varargin{i+1};
+	      if (isfield (obj, "__validators__"))
+		validators = obj.__validators__;
+		if (isfield (validators, key))
+		  feval (validators.(key), val);
+		endif
+	      endif
+	      obj.(key) = val; 
+	    else
+	      warning ("set: unrecognized property `%s' for uiobject `%s'",
+		       property, obj.type);
+	    endif
+	  else
+	    error ("set: expecting property name to be a character string");
+	  endif
+	endfor
+      endif
+      __uiobject_list__(idx).object = obj;
+      __request_drawnow__ ();
+      if (nargout > 0)
+	retval = h;
+      endif
+    else
+      error ("set: invalid handle");
+    endif
+  else
+    print_usage ();
+  endif
+
+endfunction
--- a/scripts/plot/shg.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/shg.m	Tue Jan 30 19:16:55 2007 +0000
@@ -34,6 +34,6 @@
     warning ("shg: ignoring extra arguments");
   endif
 
-  replot ();
+  drawnow ();
 
 endfunction
--- a/scripts/plot/stairs.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/stairs.m	Tue Jan 30 19:16:55 2007 +0000
@@ -49,55 +49,62 @@
 
 function [xs, ys] = stairs (x, y)
 
+  if (nargin < 1 || nargin > 2)
+    print_usage ();
+  endif
 
   if (nargin == 1)
-    if (isvector (x))
-      len = 2 * length (x);
-      tmp_xs = tmp_ys = zeros (len, 1);
-      k = 0;
-      for i = 1:2:len
-        tmp_xs(i) = k++;
-        tmp_ys(i) = x(k);
-        tmp_ys(i+1) = x(k);
-        tmp_xs(i+1) = k;
-      endfor
-    else
-      error ("stairs: argument must be a vector");
+    if (ismatrix (x))
+      if (isvector (x))
+	x = x(:);
+      endif
+      y = x;
+      x = 1:rows (y);
     endif
-  elseif (nargin == 2)
-    if (isvector (x) && isvector (y))
-      xlen = length (x);
-      ylen = length (y);
-      if (xlen == ylen)
-        len = 2 * xlen;
-        tmp_xs = tmp_ys = zeros (len, 1);
-        k = 1;
-        len_m2 = len - 2;
-        for i = 1:2:len_m2
-          tmp_xs(i) = x(k);
-          tmp_ys(i) = y(k);
-          tmp_ys(i+1) = y(k);
-          k++;
-          tmp_xs(i+1) = x(k);
-          if (x(k) < x(k-1))
-            error ("stairs: x vector values must be in ascending order");
-          endif
-        endfor
-        tmp_xs(len-1) = x(xlen);
-        delta = x(xlen) - x(xlen-1);
-        tmp_xs(len) = x(xlen) + delta;
-        tmp_ys(len-1) = y(ylen);
-        tmp_ys(len) = y(ylen);
-      else
-        error ("stairs: arguments must be the same length");
+  endif
+
+  if (ndims (x) > 2 || ndims (y) > 2)
+    error ("stairs: expecting 2-d arguments");
+  endif
+
+  vec_x = isvector (x);
+
+  if (vec_x)
+    x = x(:);
+  endif
+
+  if (isvector (y))
+    y = y(:);
+  endif
+
+  if (ismatrix (y))
+    [nr, nc] = size (y);
+    if (vec_x)
+      x = repmat (x, [1, nc]);
+    else
+      [x_nr, x_nc] = size (x);
+      if (x_nr != nr || x_nc != nc)
+	error ("stairs: argument size mismatch");
       endif
-    else
-      error ("stairs: arguments must be vectors");
     endif
-  else
-    print_usage ();
   endif
 
+  len = 2*nr - 1;
+
+  tmp_xs = tmp_ys = zeros (len, nc);
+
+  tmp_xs(1,:) = x(1,:);
+  tmp_ys(1,:) = y(1,:);
+
+  tmp_x = x(2:nr,:);
+  ridx = 2:2:len-1;
+  tmp_xs(ridx,:) = tmp_x;
+  tmp_ys(ridx,:) = y(1:nr-1,:);
+
+  ridx = 3:2:len;
+  tmp_xs(ridx,:) = tmp_x;
+  tmp_ys(ridx,:) = y(2:nr,:);
+
   if (nargout == 0)
     plot (tmp_xs, tmp_ys);
   else
--- a/scripts/plot/subplot.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/subplot.m	Tue Jan 30 19:16:55 2007 +0000
@@ -59,11 +59,14 @@
 ## @ifinfo
 ## @display
 ## @group
+## @example
+##
 ## +-----+-----+-----+-----+
 ## |  1  |  2  |  3  |  4  |
 ## +-----+-----+-----+-----+
 ## |  5  |  6  |  7  |  8  |
 ## +-----+-----+-----+-----+
+## @end example
 ## @end group
 ## @end display
 ## @end ifinfo
@@ -73,11 +76,7 @@
 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
 ## Adapted-By: jwe
 
-function subplot (rows, columns, index)
-
-  __plot_globals__;
-
-  cf = __current_figure__;
+function h = subplot (rows, columns, index)
 
   if (nargin != 3 && nargin != 1)
     print_usage ();
@@ -112,48 +111,42 @@
     error ("subplot: columns,rows,index must be be positive");
   endif
 
-  if (columns*rows == 1)
+  xsize = 1 / columns;
+  ysize = 1 / rows;
 
-    ## switching to single plot ?
+  yp = fix ((index-1)/columns);
+  xp = index - yp*columns - 1;
 
-    oneplot ();
+  xorigin = xp * xsize;
+  yorigin = (rows - yp - 1) * ysize;
 
-    __multiplot_xn__(cf) = 1;
-    __multiplot_yn__(cf) = 1;
+  pos = [xorigin, yorigin, xsize, ysize];
+
+  cf = gcf ();
 
-  else
+  set (cf, "nextplot", "add");
 
-    ## doing multiplot plots
+  obj = get (cf);
 
-    if (! __multiplot_mode__(cf)
-        || __multiplot_xn__(cf) != columns
-        || __multiplot_yn__(cf) != rows)
-
-      if (__multiplot_xn__(cf) < columns
-	  || __multiplot_yn__(cf) < rows)
-	__plot_data__{cf}{columns,rows} = [];
+  found = false;
+  for child = obj.children
+    obj = get (child);
+    if (strcmp (obj.type, "axes"))
+      if (obj.outerposition == pos)
+	found = true;
+	tmp = child;
+	axes (h);
+	break;
       endif
-
-      __multiplot_mode__(cf) = true;
-      __multiplot_xn__(cf) = columns;
-      __multiplot_yn__(cf) = rows;
-      __multiplot_xsize__(cf) = 1 / columns;
-      __multiplot_ysize__(cf) = 1 / rows;
-
     endif
-
-    ## get the sub plot location
+  endfor
 
-    yp = fix ((index-1)/columns);
-    xp = index - yp*columns - 1;
-    __multiplot_xi__(cf) = ++xp;
-    __multiplot_yi__(cf) = ++yp;
+  if (! found)
+    tmp = axes ("outerposition", pos);
+  endif
 
-    ## set the origin
-
-    xo = (xp - 1.0) * __multiplot_xsize__(cf);
-    yo = (rows - yp) * __multiplot_ysize__(cf);
-
+  if (nargout > 0)
+    h = tmp;
   endif
 
 endfunction
--- a/scripts/plot/subwindow.m	Tue Jan 30 18:45:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-## Copyright (C) 1996, 1997 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} {} subwindow (@var{xn}, @var{yn})
-## Sets the subwindow position in multiplot mode for the next plot.  The
-## multiplot mode has to be previously initialized using the
-## @code{multiplot} function, otherwise this command just becomes an alias
-## to @code{multiplot}
-## @end deftypefn
-
-## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
-## Created: 3 July 95
-## Adapted-By: jwe
-
-function subwindow (xn, yn)
-
-  __plot_globals__;
-
-  cf = __current_figure__;
-
-  ## check calling argument count
-
-  if (nargin != 2)
-    print_usage ();
-  endif
-
-  ## check for scalar inputs
-
-  if (! (isscalar (xn) && isscalar (yn)))
-    error ("subwindow: xn and yn have to be scalars");
-  endif
-
-  xn = round (xn);
-  yn = round (yn);
-
-  ## switch to multiplot mode if not already in, and use the args as the
-  ## args to multiplot()
-
-  if (! __multiplot_mode__(cf))
-    multiplot (xn, yn);
-    return;
-  endif
-
-  ## get the sub plot location
-
-  if (xn < 1 || xn > __multiplot_xn__(cf)
-      || yn < 1 || yn > __multiplot_yn__(__currrent_figure__))
-    error ("subwindow: incorrect xn and yn");
-  endif
-
-  xo = (xn - 1.0) * __multiplot_xsize__(cf);
-  yo = (__multiplot_yn__(cf) - yn) * __multiplot_ysize__(cf);
-
-  __gnuplot_raw__ (sprintf ("set origin %g, %g;\n", xo, yo));
-
-  clearplot;
-
-endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/text.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,98 @@
+## Copyright (C) 2007 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} {@var{h} =} text (@var{x}, @var{y}, @var{label})
+## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{z}, @var{label})
+## Create a text object with text @var{label} at position @var{x},
+## @var{y}, @var{z} on the current axes.  The label may be followed by
+## property-value pairs.
+## @end deftypefn
+
+## Author: jwe
+
+function h = text (varargin)
+
+  if (nargin > 2)
+    x = y = z = 0;
+    if (isnumeric (varargin{1}) && isnumeric (varargin{2}))
+      x = varargin{1};
+      y = varargin{2};
+    else
+      error ("text: expecting first two arguments to be numeric");
+    endif
+
+    if (nargin > 3 && isnumeric (varargin{3}))
+      z = varargin{3};
+      offset = 4;
+    else
+      z = zeros (size (x));
+      offset = 3;
+    endif
+
+    label = varargin{offset};
+    if (ischar (label) || iscellstr (label))
+      varargin(1:offset) = [];
+      if (ischar (label))
+	label = cellstr (label);
+      endif
+      n = numel (label);
+      nx = numel (x);
+      ny = numel (y);
+      nz = numel (z);
+      if (nx == ny && nx == nz)
+	pos = [x(:), y(:), z(:)];
+	ca = gca ();
+	tmp = zeros (n, 1);
+	if (n == 1)
+	  label = label{1};
+	  for i = 1:nx
+	    tmp(i) = __uiobject_text_ctor__ (ca, "string", label,
+					     "position", pos(i,:),
+					     varargin{:});
+	  endfor
+	elseif (n == nx)
+	  for i = 1:nx
+	    tmp(i) = __uiobject_text_ctor__ (ca, "string", label{i},
+					     "position", pos(i,:),
+					     varargin{:});
+	  endfor
+	else
+	  error ("text: dimension mismatch for coordinates and label");
+	endif
+      else
+	error ("text: dimension mismatch for coordinates");
+      endif
+    else
+      error ("text: expecting label to be a character string or cell array of character strings");
+    endif
+
+    for i = 1:numel (tmp)
+      __uiobject_adopt__ (ca, tmp(i));
+    endfor
+
+    if (nargout > 0)
+      h = tmp;
+    endif
+
+  else
+    print_usage ();
+  endif
+
+endfunction
--- a/scripts/plot/title.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/title.m	Tue Jan 30 19:16:55 2007 +0000
@@ -1,4 +1,4 @@
-## Copyright (C) 1996, 1997 John W. Eaton
+## Copyright (C) 2005 John W. Eaton
 ##
 ## This file is part of Octave.
 ##
@@ -18,36 +18,28 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} title (@var{string})
-## Specify a title for a plot.
-## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour,
-## bar, stairs, replot, xlabel, ylabel}
+## @deftypefn {Function File} {} title (@var{title})
+## Create a title object and return a handle to it.
 ## @end deftypefn
 
 ## Author: jwe
 
-function h = title (text)
+function retval = title (varargin)
+
+  nargs = nargin;
 
-  if (nargin != 1)
+  if (nargs == 0)
+    varargin{1} = "";
+    nargs++;
+  endif
+
+  if (nargs == 1)
+    set (gca, "title", varargin{1});
+    if (nargout > 0)
+      retval = h;
+    endif
+  else
     print_usage ();
   endif
 
-  if (ischar (text))
-    __gnuplot_raw__ (sprintf ("set title \"%s\";\n",
-			      undo_string_escapes (text)));
-    if (automatic_replot)
-      replot ();
-    endif
-  else
-    error ("title: text must be a string");
-  endif
-
-  ## FIXME -- eventually, we will return a graphics handle.  For
-  ## now, return something, so that calls that expect a handle won't
-  ## fail (at least immediately).
-
-  if (nargout > 0)
-    h = -1;
-  endif
-
 endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/view.m	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,65 @@
+## Copyright (C) 2007 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} {} view (@var{azimuth}, @var{elevation})
+## @deftypefnx {Function File} {} view (@var{dims})
+## @deftypefnx {Function File} {[@var{azimuth}, @var{elevation}] =} view ()
+## Set or get the viewpoint for the current axes.
+## @end deftypefn
+
+## Author: jwe
+
+function [azimuth, elevation] = view (x, y, z)
+
+  if (nargin < 4)
+    if (nargin == 1)
+      if (x == 2)
+	az = 0;
+	el = 90;
+      elseif (x == 3)
+	az = -37.5;
+	el = 30;
+      else
+	error ("view: expecting single argument to be 2 or 3");
+      endif
+    elseif (nargin == 2)
+      az = x;
+      el = y;
+    elseif (nargin == 3)
+      error ("view: view (x, y, z) not implemented");
+    endif
+
+    if (nargin > 0)
+      set (gca (), "view", [az, el]);
+    endif
+
+    if (nargout == 1)
+      error ("view: T = view () not implemented");
+    endif
+
+    if (nargout == 2)
+      azimuth = az;
+      elevation = el;
+    endif
+  else
+    print_usage ();
+  endif
+
+endfunction
--- a/scripts/plot/xlabel.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/xlabel.m	Tue Jan 30 19:16:55 2007 +0000
@@ -32,10 +32,6 @@
 
 function h = xlabel (varargin)
 
-  ## FIXME -- eventually, we will return a graphics handle.  For
-  ## now, return something, so that calls that expect a handle won't
-  ## fail (at least immediately).
-
   if (nargout > 0)
     h = __axis_label__ ("xlabel", varargin{:});
   else
--- a/scripts/plot/ylabel.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/ylabel.m	Tue Jan 30 19:16:55 2007 +0000
@@ -26,10 +26,6 @@
 
 function h = ylabel (varargin)
 
-  ## FIXME -- eventually, we will return a graphics handle.  For
-  ## now, return something, so that calls that expect a handle won't
-  ## fail (at least immediately).
-
   if (nargout > 0)
     h = __axis_label__ ("ylabel", varargin{:});
   else
--- a/scripts/plot/zlabel.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/scripts/plot/zlabel.m	Tue Jan 30 19:16:55 2007 +0000
@@ -22,16 +22,10 @@
 ## See xlabel.
 ## @end deftypefn
 
-## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
-## Created: 3 July 95
-## Adapted-By: jwe
+## Author: jwe
 
 function h = zlabel (varargin)
 
-  ## FIXME -- eventually, we will return a graphics handle.  For
-  ## now, return something, so that calls that expect a handle won't
-  ## fail (at least immediately).
-
   if (nargout > 0)
     h = __axis_label__ ("zlabel", varargin{:});
   else
--- a/src/ChangeLog	Tue Jan 30 18:45:59 2007 +0000
+++ b/src/ChangeLog	Tue Jan 30 19:16:55 2007 +0000
@@ -1,3 +1,4 @@
+<<<<<<< ChangeLog
 2007-01-29  David Bateman  <dbateman@free.fr>
 
 	* DLD-FUNCTIONS/find.cc (find_nonzero_elem_idx): Don't panic if
@@ -194,6 +195,40 @@
 	OCTAVE_VALUE_INT_MATRIX_T::comlex_array_value):
 	Use octave_idx_type instead of int for indexing.
 
+=======
+2007-01-26  John W. Eaton  <jwe@octave.org>
+
+	* DLD-FUNCTIONS/__contourc__.cc: New function.
+	* Makefile.in (DLD_XSRC): Add it to the list.
+
+2007-01-25  John W. Eaton  <jwe@octave.org>
+
+	* input.cc (Vdrawnow_requested): New static variable.
+	(F__request_drawnow__): New function.
+	(interactive_input): New function.  Update Vlast_prompt_time here.
+	(octave_gets, get_user_input, octave_yes_or_no):
+	Call interactive_input instead of gnu_readline.
+
+	* symtab.h (symbol_record::eternal): New data member.
+	(symbol_record::symbol_record): Initialize it.
+	(symbol_record::make_eternal, symbol_record::is_eternal):
+	Don't forward to symbol_def functions.
+	(symbol_record::symbol_def::make_eternal,
+	symbol_record::symbol_def::is_eternal): Delete.
+	(symbol_record::symbol_def::eternal): Delete data member.
+	(symbol_record::symbol_def::symbol_def): Delete initialization.
+
+	* pt-id.cc (tree_identifier::link_to_global): Include variable
+	name in warning message.
+
+	* variables.cc (F__lock_global__): New function.
+
+2007-01-11  John W. Eaton  <jwe@octave.org>
+
+	* ls-oct-ascii.cc (save_ascii_data_for_plotting, save_three_d):
+	Set precision to 6 instead of 4.
+
+>>>>>>> 1.1602.2.4
 2006-12-04  David Bateman  <dbateman@free.fr>
 
 	* xpow.cc (xpow (const Matrix&, double)): Add matrix type probing
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/DLD-FUNCTIONS/__contourc__.cc	Tue Jan 30 19:16:55 2007 +0000
@@ -0,0 +1,332 @@
+/* Contour lines for function evaluated on a grid.
+
+Copyright (C) 2004 Shai Ayal
+
+Adapted to an oct file from the stand alone contourl by Victro Munoz
+Copyright (C) 2004 Victor Munoz
+
+Based on contour plot routine (plcont.c) in PLPlot package
+http://plplot.org/
+
+Copyright (C) 1995, 2000, 2001 Maurice LeBrun
+Copyright (C) 2000, 2002 Joao Cardoso
+Copyright (C) 2000, 2001, 2002, 2004  Alan W. Irwin
+Copyright (C) 2004  Andrew Ross
+
+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.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "quit.h"
+
+#include "defun-dld.h"
+#include "error.h"
+#include "oct-obj.h"
+
+static Matrix this_contour;
+static Matrix contourc;
+static int elem;
+
+// this is the quanta in which we increase this_contour
+#define CONTOUR_QUANT 50
+
+// cl_add_point(x,y);
+//
+// Add a coordinate point (x,y) to this_contour 
+
+static void
+cl_add_point (double x, double y)
+{
+  if (elem % CONTOUR_QUANT == 0)
+    this_contour = this_contour.append (Matrix (2, CONTOUR_QUANT, 0));
+
+  this_contour (0, elem) = x;
+  this_contour (1, elem) = y;
+  elem++;
+}
+
+// cl_end_contour();
+//
+// Adds contents of current contour to contourc.
+// this_contour.cols () - 1;
+
+static void
+cl_end_contour (void)
+{
+  if (elem > 2)
+    {
+      this_contour (1, 0) = elem - 1;
+      contourc = contourc.append (this_contour.extract_n (0, 0, 2, elem));
+    }
+  this_contour = Matrix ();
+  elem = 0;
+}
+
+// cl_start_contour(flev,x,y);
+//
+// Start a new contour, and adds contents of current one to contourc
+
+static void
+cl_start_contour (double flev, double x, double y)
+{
+  cl_end_contour ();
+  this_contour.resize (2, 0);
+  cl_add_point (flev, flev);
+  cl_add_point (x, y);
+}
+
+static void
+cl_drawcn (RowVector & X, RowVector & Y, Matrix & Z, double flev,
+	   int krow, int kcol, double lastx, double lasty, int startedge,
+	   Matrix & ipts)
+{
+
+  int kx = 0, lx = Z.cols () - 1, ky = 0, ly = Z.rows () - 1;
+
+  double f[4];
+  double px[4], py[4], locx[4], locy[4];
+  int iedge[4];
+  int num, first, inext, kcolnext, krownext;
+
+  px[0] = X (krow + 1);
+  px[1] = X (krow);
+  px[2] = X (krow);
+  px[3] = X (krow + 1);
+  py[0] = Y (kcol);
+  py[1] = Y (kcol);
+  py[2] = Y (kcol + 1);
+  py[3] = Y (kcol + 1);
+
+  f[0] = Z (krow + 1, kcol) - flev;
+  f[1] = Z (krow, kcol) - flev;
+  f[2] = Z (krow, kcol + 1) - flev;
+  f[3] = Z (krow + 1, kcol + 1) - flev;
+
+  for (int i = 0, j = 1; i < 4; i++, j = (j + 1) % 4)
+    {
+      iedge[i] = (f[i] * f[j] > 0.0) ? -1 : ((f[i] * f[j] < 0.0) ? 1 : 0);
+    }
+
+  // Mark this square as done
+  ipts(krow,kcol) = 1;
+
+  // Check if no contour has been crossed i.e. iedge[i] = -1
+  if (iedge[0] == -1 && iedge[1] == -1 && iedge[2] == -1 && iedge[3] == -1)
+    return;
+
+  // Check if this is a completely flat square - in which case ignore it
+  if (f[0] == 0.0 && f[1] == 0.0 && f[2] == 0.0 && f[3] == 0.0)
+    return;
+
+  // Calculate intersection points
+  num = 0;
+  if (startedge < 0)
+    {
+      first = 1;
+    }
+  else
+    {
+      locx[num] = lastx;
+      locy[num] = lasty;
+      num++;
+      first = 0;
+    }
+
+  for (int k = 0, i = (startedge < 0 ? 0 : startedge); k < 4;
+       k++, i = (i + 1) % 4)
+    {
+      if (i == startedge)
+	continue;
+
+      // If the contour is an edge check it hasn't already been done
+      if (f[i] == 0.0 && f[(i + 1) % 4] == 0.0)
+	{
+	  kcolnext = kcol;
+	  krownext = krow;
+	  if (i == 0)
+	    kcolnext--;
+	  if (i == 1)
+	    krownext--;
+	  if (i == 2)
+	    kcolnext++;
+	  if (i == 3)
+	    krownext++;
+	  if (kcolnext < kx || kcolnext >= lx || krownext < ky
+	      || krownext >= ly || ipts(krownext,kcolnext) == 1)
+	    continue;
+	}
+      if (iedge[i] == 1 || f[i] == 0.0)
+	{
+	  int j = (i + 1) % 4;
+	  if (f[i] != 0.0)
+	    {
+	      locx[num] =
+		(px[i] * fabs (f[j]) + px[j] * fabs (f[i])) / fabs (f[j] -
+								    f[i]);
+	      locy[num] =
+		(py[i] * fabs (f[j]) + py[j] * fabs (f[i])) / fabs (f[j] -
+								    f[i]);
+	    }
+	  else
+	    {
+	      locx[num] = px[i];
+	      locy[num] = py[i];
+	    }
+	  // If this is the start of the contour then move to the point
+	  if (first == 1)
+	    {
+	      cl_start_contour (flev, locx[num], locy[num]);
+	      first = 0;
+	    }
+	  else
+	    {
+	      // Link to the next point on the contour
+	      cl_add_point (locx[num], locy[num]);
+	      // Need to follow contour into next grid box
+	      // Easy case where contour does not pass through corner
+	      if (f[i] != 0.0)
+		{
+		  kcolnext = kcol;
+		  krownext = krow;
+		  inext = (i + 2) % 4;
+		  if (i == 0)
+		    kcolnext--;
+		  if (i == 1)
+		    krownext--;
+		  if (i == 2)
+		    kcolnext++;
+		  if (i == 3)
+		    krownext++;
+		  if (kcolnext >= kx && kcolnext < lx
+		      && krownext >= ky && krownext < ly
+		      && ipts(krownext,kcolnext) == 0)
+		    {
+		      cl_drawcn (X, Y, Z, flev, krownext, kcolnext,
+				 locx[num], locy[num], inext, ipts);
+		    }
+		}
+	      // Hard case where contour passes through corner.  This
+	      // is still not perfect - it may lose the contour  which
+	      // won't upset the contour itself (we can find it again
+	      // later) but might upset the labelling (which is only
+	      // relevant for the PLPlot implementation, since we
+	      // don't worry about labels---for now!)
+	      else
+		{
+		  kcolnext = kcol;
+		  krownext = krow;
+		  inext = (i + 2) % 4;
+		  if (i == 0)
+		    {
+		      kcolnext--;
+		      krownext++;
+		    }
+		  if (i == 1)
+		    {
+		      krownext--;
+		      kcolnext--;
+		    }
+		  if (i == 2)
+		    {
+		      kcolnext++;
+		      krownext--;
+		    }
+		  if (i == 3)
+		    {
+		      krownext++;
+		      kcolnext++;
+		    }
+		  if (kcolnext >= kx && kcolnext < lx
+		      && krownext >= ky && krownext < ly
+		      && ipts(krownext,kcolnext) == 0)
+		    {
+		      cl_drawcn (X, Y, Z, flev, krownext, kcolnext,
+				 locx[num], locy[num], inext, ipts);
+		    }
+
+		}
+	      if (first == 1)
+		{
+		  // Move back to first point
+		  cl_start_contour (flev, locx[num], locy[num]);
+		  first = 0;
+		}
+	      else
+		{
+		  first = 1;
+		}
+	      num++;
+	    }
+	}
+    }
+}
+
+static void
+cl_cntr (RowVector & X, RowVector & Y, Matrix & Z, double flev)
+{
+  Matrix ipts (Z.rows (), Z.cols (), 0);
+
+  for (int krow = 0; krow < Z.rows () - 1; krow++)
+    {
+      for (int kcol = 0; kcol < Z.cols () - 1; kcol++)
+	{
+	  if (ipts(krow,kcol) == 0)
+	    {
+	      cl_drawcn (X, Y, Z, flev, krow, kcol, 0.0, 0.0, -2, ipts);
+	    }
+	}
+    }
+}
+
+DEFUN_DLD (__contourc__, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Loadable Function} {} __contourc__ (@var{x}, @var{y}, @var{z}, @var{levels})\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () == 4)
+    {
+      RowVector X = args (0).row_vector_value ();
+      RowVector Y = args (1).row_vector_value ();
+      Matrix Z = args (2).matrix_value ().transpose ();
+      RowVector L = args (3).row_vector_value ();
+
+      if (! error_state)
+	{
+	  contourc.resize (2, 0);
+
+	  for (int i = 0; i < L.length (); i++)
+	    cl_cntr (X, Y, Z, L (i));
+
+	  cl_end_contour ();
+
+	  retval = contourc;
+	}
+      else
+	error ("__contourc__: invalid argument values");
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
--- a/src/Makefile.in	Tue Jan 30 18:45:59 2007 +0000
+++ b/src/Makefile.in	Tue Jan 30 19:16:55 2007 +0000
@@ -56,7 +56,7 @@
 	lu.cc luinc.cc matrix_type.cc minmax.cc pinv.cc qr.cc \
 	quad.cc qz.cc rand.cc regexp.cc schur.cc sort.cc sparse.cc \
 	spchol.cc spdet.cc spfind.cc spkron.cc splu.cc spparms.cc spqr.cc \
-	sqrtm.cc svd.cc syl.cc time.cc urlwrite.cc \
+	sqrtm.cc svd.cc syl.cc time.cc urlwrite.cc __contourc__.cc \
 	__gnuplot_raw__.l __glpk__.cc __pchip_deriv__.cc __qp__.cc
 
 DLD_SRC := $(addprefix DLD-FUNCTIONS/, $(DLD_XSRC))
--- a/src/input.cc	Tue Jan 30 18:45:59 2007 +0000
+++ b/src/input.cc	Tue Jan 30 19:16:55 2007 +0000
@@ -140,6 +140,10 @@
 // TRUE after a call to completion_matches.
 bool octave_completion_matches_called = false;
 
+// TRUE if the plotting system has requested a call to drawnow at
+// the next user prompt.
+static bool Vdrawnow_requested = false;
+
 static void
 do_input_echo (const std::string& input_string)
 {
@@ -206,6 +210,21 @@
   return retval;
 }
 
+static inline std::string
+interactive_input (const std::string& s, bool force_readline = false)
+{
+  Vlast_prompt_time.stamp ();
+
+  if (Vdrawnow_requested && (interactive || forced_interactive))
+    {
+      feval ("drawnow");
+
+      Vdrawnow_requested = false;
+    }
+
+  return gnu_readline (s, force_readline);
+}
+
 static std::string
 octave_gets (void)
 {
@@ -229,9 +248,7 @@
 
       octave_diary << prompt;
 
-      Vlast_prompt_time.stamp ();
-
-      retval = gnu_readline (prompt);
+      retval = interactive_input (prompt);
 
       // There is no need to update the load_path cache if there is no
       // user input.
@@ -606,7 +623,7 @@
 
   octave_diary << prompt;
 
-  std::string input_buf = gnu_readline (prompt.c_str (), true);
+  std::string input_buf = interactive_input (prompt.c_str (), true);
 
   if (! input_buf.empty ())
     {
@@ -753,7 +770,7 @@
 
   while (1)
     {
-      std::string input_buf = gnu_readline (prompt_string);
+      std::string input_buf = interactive_input (prompt_string);
 
       if (input_buf == "yes")
 	return true;
@@ -1230,6 +1247,27 @@
   return SET_INTERNAL_VARIABLE (echo_executing_commands);
 }
 
+DEFUN (__request_drawnow__, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} __request_drawnow__ ()\n\
+@deftypefnx {Built-in Function} {} __request_drawnow__ (@var{flag})\n\
+Request a call drawnow at the next user prompt.\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin == 0)
+    Vdrawnow_requested = true;
+  else if (nargin == 1)
+    Vdrawnow_requested = args(0).bool_value ();
+  else
+    print_usage ();
+
+  return retval;
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/src/ls-oct-ascii.cc	Tue Jan 30 18:45:59 2007 +0000
+++ b/src/ls-oct-ascii.cc	Tue Jan 30 19:16:55 2007 +0000
@@ -355,7 +355,7 @@
 {
   bool infnan_warned = true;
 
-  return save_ascii_data (os, t, name, infnan_warned, false, 4);
+  return save_ascii_data (os, t, name, infnan_warned, false, 6);
 }
 
 // Maybe this should be a static function in tree-plot.cc?
@@ -380,7 +380,7 @@
 	 << "# total columns: " << nc << "\n";
 
       long old_precision = os.precision ();
-      os.precision (4);
+      os.precision (6);
 
       if (parametric)
 	{
--- a/src/pt-id.cc	Tue Jan 30 18:45:59 2007 +0000
+++ b/src/pt-id.cc	Tue Jan 30 19:16:55 2007 +0000
@@ -120,7 +120,12 @@
       if (! sym->is_linked_to_global ())
 	{
 	  if (sym->is_defined () && sym->is_variable ())
-	    warning ("local variable value may have changed to match global");
+	    {
+	      std::string nm = sym->name ();
+
+	      warning ("value of local variable `%s' may have changed to match global",
+		       nm.c_str ());
+	    }
 
 	  link_to_global_variable (sym);
 	}
--- a/src/symtab.cc	Tue Jan 30 18:45:59 2007 +0000
+++ b/src/symtab.cc	Tue Jan 30 19:16:55 2007 +0000
@@ -249,7 +249,7 @@
 {
   if (is_defined ())
     {
-      if (! tagged_static)
+      if (! (tagged_static || is_eternal ()))
 	{
 	  while (! aliases_to_clear.empty ())
 	    {
--- a/src/symtab.h	Tue Jan 30 18:45:59 2007 +0000
+++ b/src/symtab.h	Tue Jan 30 19:16:55 2007 +0000
@@ -89,7 +89,7 @@
 
     symbol_def (const octave_value& val = octave_value (),
 		unsigned int sym_type = 0)
-      : symbol_type (sym_type), eternal (0), read_only (0), help_string (),
+      : symbol_type (sym_type), read_only (0), help_string (),
 	definition (val), count (1) { }
 
     ~symbol_def (void) { }
@@ -157,9 +157,6 @@
     bool is_read_only (void) const
       { return read_only; }
 
-    bool is_eternal (void) const
-      { return eternal; }
-
     bool is_matrix_type (void) const 
       { return definition.is_matrix_type (); }
 
@@ -211,8 +208,6 @@
 
     void unprotect (void) { read_only = 0; }
 
-    void make_eternal (void) { eternal = 1; }
-
     octave_value& def (void) { return definition; }
 
     std::string help (void) const { return help_string; }
@@ -232,9 +227,6 @@
     // The type of this symbol (see the enum above).
     unsigned int symbol_type : 9;
 
-    // Nonzero means this variable cannot be cleared.
-    unsigned int eternal : 1;
-
     // Nonzero means this variable cannot be given a new value.
     unsigned int read_only : 1;
 
@@ -264,8 +256,8 @@
   symbol_record (void)
     : formal_param (false), automatic_variable (false),
       linked_to_global (false), tagged_static (false),
-      can_hide_function (true), visible (true), nm (), chg_fcn (0),
-      definition (new symbol_def ()), next_elem (0) { }
+      can_hide_function (true), visible (true), eternal (false),
+      nm (), chg_fcn (0), definition (new symbol_def ()), next_elem (0) { }
 
   // FIXME -- kluge alert!  We obviously need a better way of
   // handling allow_shadow!
@@ -273,8 +265,9 @@
   symbol_record (const std::string& n, symbol_record *nxt)
     : formal_param (false), automatic_variable (false),
       linked_to_global (false), tagged_static (false),
-      can_hide_function (n != "__end__"), visible (true), nm (n),
-      chg_fcn (0), definition (new symbol_def ()), next_elem (nxt) { }
+      can_hide_function (n != "__end__"), visible (true),
+      eternal (false), nm (n), chg_fcn (0),
+      definition (new symbol_def ()), next_elem (nxt) { }
 
   ~symbol_record (void)
     {
@@ -341,13 +334,13 @@
 
   bool is_read_only (void) const { return definition->is_read_only (); }
 
-  bool is_eternal (void) const { return definition->is_eternal (); }
+  bool is_eternal (void) const { return eternal; }
 
   void protect (void) { definition->protect (); }
 
   void unprotect (void) { definition->unprotect (); }
 
-  void make_eternal (void) { definition->make_eternal (); }
+  void make_eternal (void) { eternal = 1; }
 
   void hide (void) { visible = false; }
   void show (void) { visible = true; }
@@ -450,6 +443,7 @@
   unsigned int tagged_static : 1;
   unsigned int can_hide_function : 1;
   unsigned int visible : 1;
+  unsigned int eternal : 1;
 
   std::string nm;
   change_function chg_fcn;
--- a/src/variables.cc	Tue Jan 30 18:45:59 2007 +0000
+++ b/src/variables.cc	Tue Jan 30 19:16:55 2007 +0000
@@ -2045,6 +2045,36 @@
   return retval;
 }
 
+DEFUN (__lock_global__, args, ,
+    "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} __lock_global__ (@var{name})\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () == 1)
+    {
+      std::string nm = args(0).string_value ();
+
+      if (! error_state)
+	{
+	  symbol_record *sr = global_sym_tab->lookup (nm);
+
+	  if (sr)
+	    sr->make_eternal ();
+	  else
+	    error ("__lock_global__: %s not found in global symbol table",
+		   nm.c_str ());
+	}
+      else
+	error ("__lock_global__: expecting argument to be a character string");
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
 // Deleting names from the symbol tables.
 
 static inline bool
--- a/test/ChangeLog	Tue Jan 30 18:45:59 2007 +0000
+++ b/test/ChangeLog	Tue Jan 30 19:16:55 2007 +0000
@@ -1,3 +1,9 @@
+2007-01-11  John W. Eaton  <jwe@octave.org>
+
+	* fntests.m: Also handle scripts directory in the build tree.
+
+	* Makefile.in (OCTAVE_SCRIPT_PATH): Delete unused variable.
+
 2006-11-14  Luis F. Ortiz  <lortiz@interactivesupercomputing.com>
 
 	* fntests.m: Include liboctave in the list of directories to test.
--- a/test/Makefile.in	Tue Jan 30 18:45:59 2007 +0000
+++ b/test/Makefile.in	Tue Jan 30 19:16:55 2007 +0000
@@ -20,8 +20,6 @@
 
 OCTAVE_BINARY = ../src/octave
 
-OCTAVE_SCRIPT_PATH = .//:$(TOPDIR)/src//:$(srcdir):$(srcdir)/../scripts//
-
 ifeq ($(SHARED_LIBS), true)
   OCTAVE_LD_LIBRARY_PATH = `pwd`/../src:`pwd`/../liboctave:`pwd`/../libcruft
   ifeq ($(@library_path_var@),)
--- a/test/fntests.m	Tue Jan 30 18:45:59 2007 +0000
+++ b/test/fntests.m	Tue Jan 30 19:16:55 2007 +0000
@@ -3,6 +3,7 @@
 global files_with_no_tests = {};
 global files_with_tests = {};
 global topsrcdir;
+global topbuilddir;
 
 currdir = canonicalize_file_name (".");
 
@@ -14,6 +15,7 @@
 
 srcdir = canonicalize_file_name (xdir);
 topsrcdir = canonicalize_file_name (fullfile (xdir, ".."));
+topbuilddir = canonicalize_file_name (fullfile (currdir, ".."));
 
 if (strcmp (currdir, srcdir))
   testdirs = {srcdir};
@@ -22,10 +24,16 @@
 endif
 
 src_tree = canonicalize_file_name (fullfile (topsrcdir, "src"));
+liboctave_tree = canonicalize_file_name (fullfile (topsrcdir, "liboctave"));
 script_tree = canonicalize_file_name (fullfile (topsrcdir, "scripts"));
-liboctave_tree = canonicalize_file_name (fullfile (topsrcdir, "liboctave"));
+local_script_tree = canonicalize_file_name (fullfile (currdir, "../scripts"));
+
 fundirs = {src_tree, liboctave_tree, script_tree};
 
+if (! strcmp (currdir, srcdir))
+  fundirs{end+1} = local_script_tree;
+endif
+
 function print_test_file_name (nm)
   filler = repmat (".", 1, 55-length (nm));
   printf ("  %s %s", nm, filler);
@@ -79,6 +87,7 @@
   global files_with_tests;
   global files_with_no_tests;
   global topsrcdir;
+  global topbuilddir;
   lst = dir (d);
   dp = dn = 0;
   for i = 1:length (lst)
@@ -98,7 +107,9 @@
       p = n = 0;
       ## Only run if it contains %!test, %!assert %!error or %!warning
       if (hastests (f))
-	print_test_file_name (strrep (f, [topsrcdir, "/"], ""));
+	tmp = strrep (f, [topsrcdir, "/"], "");
+	tmp = strrep (tmp, [topbuilddir, "/"], "../");
+	print_test_file_name (tmp);
 	[p, n] = test (f, "quiet", fid);
 	print_pass_fail (n, p);
 	dp += p;