# HG changeset patch
# User dbateman
# Date 1193140938 0
# Node ID bd56a0609c4f2dd8b9da898d2e29767e57ef31a5
# Parent e426f849fc3646d8364c4a05d7f68e311ec2d600
[project @ 2007-10-23 12:02:17 by dbateman]
diff --git a/scripts/miscellaneous/what.m b/scripts/miscellaneous/what.m
new file mode 100644
--- /dev/null
+++ b/scripts/miscellaneous/what.m
@@ -0,0 +1,116 @@
+## Copyright (C) 2007 David Bateman
+##
+## 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 3 of the License, 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, see
+## .
+
+## -*- texinfo -*-
+## @deftypefn {Command} {} what
+## @deftypefnx {Command} {} what @var{dir}
+## @deftypefnx {Function File} {w =} what (@var{dir})
+## List the Octave specific files in a directory. If the variable @var{dir}
+## is given then check that directory rather than the current directory. If
+## a return argument is requested, the files found are returned in the
+## structure @var{w}.
+## @seealso{which}
+## @end deftypefn
+
+## PKG_ADD: mark_as_command what
+
+function ret = what (d)
+
+ if (nargin == 0)
+ d = pwd ();
+ elseif (isempty (strfind (d, filesep ())))
+ ## Find the appropriate directory on the path
+ p = split (path (), pathsep());
+ p = cellfun (@(x) deblank (x), mat2cell (p, ones (1, size (p, 1)), ...
+ size (p, 2)), "UniformOutput", false);
+ d = p{find (cellfun (@(x) ! isempty (strfind (x, d)), p))(end)};
+ else
+ [status, msg, msgid] = fileattrib (d);
+ if (status != 1)
+ error ("could not find the file or path %s", d);
+ else
+ d = msg.Name;
+ endif
+ endif
+
+ files = dir (d);
+ w.path = d;
+ w.m = cell (0, 1);
+ w.mex = cell (0, 1);
+ w.oct = cell (0, 1);
+ w.mat = cell (0, 1);
+ w.mdl = cell (0, 1);
+ w.p = cell (0, 1);
+ w.classes = cell (0, 1);
+
+ for i = 1 : length (files)
+ n = files(i).name;
+ ## Ignore . and ..
+ if (strcmp (n, ".") || strcmp (n, ".."))
+ continue;
+ else
+ ## Ignore mdl and p files
+ [dummy, f, e] = fileparts (n);
+ if (strcmp (e, ".m"))
+ w.m {end+1} = n;
+ elseif (strcmp (e, mexext ()))
+ w.mex {end + 1} = n;
+ elseif (strcmp (e, ".oct"))
+ w.oct {end + 1} = n;
+ elseif (strcmp (e, ".mat"))
+ w.mat {end + 1} = n;
+ elseif(strcmp (n(1), "@"))
+ w.classes {end + 1} = n;
+ endif
+ endif
+ endfor
+
+ if (nargout == 0)
+ __display_filenames__ ("M-files in directory", w.path, w.m);
+ __display_filenames__ ("\nMEX-files in directory", w.path, w.mex);
+ __display_filenames__ ("\nOCT-files in directory", w.path, w.oct);
+ __display_filenames__ ("\nMAT-files in directory", w.path, w.mat);
+ __display_filenames__ ("\nClasses in directory", w.path, w.classes);
+ else
+ ret = w;
+ endif
+endfunction
+
+function __display_filenames__ (msg, p, f)
+ if (length (f) > 0)
+ printf ("%s %s:\n\n", msg, p)
+
+ maxlen = max (cellfun (@(x) length (x), f));
+ ncols = max (1, floor (terminal_size()(2) / (maxlen + 3)));
+ fmt = "";
+ for i = 1: ncols
+ fmt = sprintf ("%s %%-%ds", fmt, maxlen);
+ endfor
+ fmt = [fmt, "\n"];
+
+ nrows = ceil (length (f) / ncols);
+ for i = 1 : nrows
+ args = f(i:nrows:end);
+ if (length (args) < ncols)
+ n = ncols - length (args);
+ args{end : end + n} = "";
+ endif
+ printf (fmt, args{:});
+ endfor
+ endif
+endfunction
diff --git a/scripts/plot/__axes_limits__.m b/scripts/plot/__axes_limits__.m
new file mode 100644
--- /dev/null
+++ b/scripts/plot/__axes_limits__.m
@@ -0,0 +1,57 @@
+## Copyright (C) 2007 David Bateman
+##
+## 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 3 of the License, 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, see
+## .
+
+## Undocumented internal function.
+
+function retval = __axes_limits__ (fcn, varargin)
+ retval = [];
+ fcnmode = sprintf("%smode", fcn);
+
+ if (nargin > 1 && isscalar (varargin{1}) && ishandle (varargin{1}))
+ h = varargin {1};
+ off = 1;
+ if (! strcmp (get (h, "type"), "axes"))
+ error ("%s: expecting first argument to be an axes object", fcn);
+ endif
+ else
+ off = 0;
+ h = gca ();
+ endif
+
+ if (nargin == off + 1)
+ retval = get (h, fcn);
+ else
+ arg = varargin {off + 1};
+
+ if (ischar (arg))
+ arg = tolower (arg);
+ if (strcmp ("mode", arg))
+
+ retval = get (h, fcnmode);
+ elseif (strcmp ("auto", arg) || strcmp ("manual", arg))
+ set (h, fcnmode, arg);
+ endif
+ else
+ if (!isnumeric (arg) && any (size(arg(:)) != [2, 1]))
+ error ("%s: argument must be a 2 element vector", fcn);
+ else
+ set (h, fcn, arg (:));
+ endif
+ endif
+ endif
+endfunction
diff --git a/scripts/plot/xlim.m b/scripts/plot/xlim.m
new file mode 100644
--- /dev/null
+++ b/scripts/plot/xlim.m
@@ -0,0 +1,46 @@
+## Copyright (C) 2007 David Bateman
+##
+## 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 3 of the License, 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, see
+## .
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {@var{xl} =} xlim ()
+## @deftypefnx {Function File} {} xlim (@var{xl})
+## @deftypefnx {Function File} {@var{m} =} xlim ('mode')
+## @deftypefnx {Function File} {} xlim (@var{m})
+## @deftypefnx {Function File} {} xlim (@var{h}, @dots{})
+## Get or set the limits of the x axis of the current plot. Called without
+## argumenst @code{xlim] returns the x axis limits of the current plot.
+## If passed a two element vector @var{xl}, the limits of the x axis are set
+## to this value.
+##
+## The current mode for calculation of the x axis can be returned with a
+## call @code{xlim ('mode')}, and can be either 'auto' or 'manual'. The
+## current plotting mode can be set by passing either 'auto' or 'manual'
+## as the argument.
+##
+## If passed an handle as the first argument, then operate on this handle
+## rather than the current axes handle.
+## @seealso{ylim, zlim, set, get, gca}
+## @end deftypefn
+
+function retval = xlim (varargin)
+ ret = __axes_limits__ ("xlim", varargin {:});
+
+ if (! isempty (ret))
+ retval = ret;
+ endif
+endfunction
diff --git a/scripts/plot/ylim.m b/scripts/plot/ylim.m
new file mode 100644
--- /dev/null
+++ b/scripts/plot/ylim.m
@@ -0,0 +1,46 @@
+## Copyright (C) 2007 David Bateman
+##
+## 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 3 of the License, 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, see
+## .
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {@var{xl} =} ylim ()
+## @deftypefnx {Function File} {} ylim (@var{xl})
+## @deftypefnx {Function File} {@var{m} =} ylim ('mode')
+## @deftypefnx {Function File} {} ylim (@var{m})
+## @deftypefnx {Function File} {} ylim (@var{h}, @dots{})
+## Get or set the limits of the y axis of the current plot. Called without
+## argumenst @code{ylim] returns the y axis limits of the current plot.
+## If passed a two element vector @var{xl}, the limits of the y axis are set
+## to this value.
+##
+## The current mode for calculation of the y axis can be returned with a
+## call @code{ylim ('mode')}, and can be either 'auto' or 'manual'. The
+## current plotting mode can be set by passing either 'auto' or 'manual'
+## as the argument.
+##
+## If passed an handle as the first argument, then operate on this handle
+## rather than the current axes handle.
+## @seealso{xlim, zlim, set, get, gca}
+## @end deftypefn
+
+function retval = ylim (varargin)
+ ret = __axes_limits__ ("ylim", varargin {:});
+
+ if (! isempty (ret))
+ retval = ret;
+ endif
+endfunction
diff --git a/scripts/plot/zlim.m b/scripts/plot/zlim.m
new file mode 100644
--- /dev/null
+++ b/scripts/plot/zlim.m
@@ -0,0 +1,46 @@
+## Copyright (C) 2007 David Bateman
+##
+## 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 3 of the License, 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, see
+## .
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {@var{xl} =} zlim ()
+## @deftypefnx {Function File} {} zlim (@var{xl})
+## @deftypefnx {Function File} {@var{m} =} zlim ('mode')
+## @deftypefnx {Function File} {} zlim (@var{m})
+## @deftypefnx {Function File} {} zlim (@var{h}, @dots{})
+## Get or set the limits of the z axis of the current plot. Called without
+## argumenst @code{zlim] returns the z axis limits of the current plot.
+## If passed a two element vector @var{xl}, the limits of the z axis are set
+## to this value.
+##
+## The current mode for calculation of the z axis can be returned with a
+## call @code{zlim ('mode')}, and can be either 'auto' or 'manual'. The
+## current plotting mode can be set by passing either 'auto' or 'manual'
+## as the argument.
+##
+## If passed an handle as the first argument, then operate on this handle
+## rather than the current axes handle.
+## @seealso{xlim, ylim, set, get, gca}
+## @end deftypefn
+
+function retval = zlim (varargin)
+ ret = __axes_limits__ ("zlim", varargin {:});
+
+ if (! isempty (ret))
+ retval = ret;
+ endif
+endfunction