Mercurial > hg > octave-nkf
changeset 5406:c49aec8a9080
[project @ 2005-07-08 15:25:43 by jwe]
author | jwe |
---|---|
date | Fri, 08 Jul 2005 15:25:44 +0000 |
parents | 00d369dffec0 |
children | 2911127d0fe7 |
files | scripts/ChangeLog scripts/plot/__errplot__.m scripts/plot/__plot_globals__.m scripts/plot/__plt__.m scripts/plot/figure.m scripts/plot/hold.m scripts/plot/ishold.m src/ChangeLog src/DLD-FUNCTIONS/gplot.l src/DLD-FUNCTIONS/matrix_type.cc |
diffstat | 10 files changed, 248 insertions(+), 105 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,13 @@ +2005-07-08 John W. Eaton <jwe@octave.org> + + * plot/__errplot__.m: Use __plot_globals__. + * plot/__plt__.m: Likewise. + * plot/figure.m: Likewise. + + * plot/hold.m: New file. + * plot/ishold.m: New file. + * plot/__plot_globals__.m: New file. + 2005-07-05 cctsim <cctsim@yahoo.co.uk> * strings/dec2base.m: Don't remove all leading zeros if result is zero.
--- a/scripts/plot/__errplot__.m +++ b/scripts/plot/__errplot__.m @@ -36,10 +36,14 @@ function __errplot__ (fstr, a1, a2, a3, a4, a5, a6) + __plot_globals__; + if (nargin < 3 || nargin > 7) # at least three data arguments needed usage ("__errplot__ (fmt, arg1, ...)"); endif + j = __plot_data_offset__(__current_figure__); + fmt = __pltopt__ ("__errplot__", fstr); nplots = size (a1, 2); @@ -67,8 +71,23 @@ a1(:,i)-a3(:,i), a1(:,i)+a4(:,i), ... a2(:,i)-a5(:,i), a2(:,i)+a6(:,i)]; endswitch - cmd = sprintf ("__gnuplot_plot__ tmp %s", ifmt); - eval (cmd); -endfor + + __plot_data__{__current_figure__}{j} = tmp; + + __plot_command__{__current_figure__} \ + = sprintf ("%s%s __plot_data__{__current_figure__}{%d} %s", + __plot_command__{__current_figure__}, + __plot_command_sep__, j, ifmt); + __plot_command_sep__ = ",\\\n"; + + j++; + + endfor + + __plot_data_offset__(__current_figure__) = j; + + if (! isempty (__plot_command__{__current_figure__})) + eval (__plot_command__{__current_figure__}); + endif endfunction
new file mode 100644 --- /dev/null +++ b/scripts/plot/__plot_globals__.m @@ -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. + +## This is a script file shared by __plt__ and __errplot__. + +global __current_figure__; +global __plot_data_offset__; +global __plot_command__; +global __plot_command_sep__; +global __plot_data__; + +if (isempty (__current_figure__)) + __current_figure__ = 1; +endif + +if (length (__plot_data_offset__) < __current_figure__) + __plot_data_offset__(__current_figure__) = 1; +endif + +if (length (__plot_command__) < __current_figure__) + __plot_command__{__current_figure__} = ""; +endif + +if (length (__plot_data__) < __current_figure__) + __plot_data__{__current_figure__} = []; +endif + +if (ishold ()) + if (isempty (__plot_command__{__current_figure__})) + __plot_command__{__current_figure__} = "__gnuplot_plot__"; + __plot_command_sep__ = ""; + else + gp_cmd = __plot_command__{__current_figure__}; + __plot_command_sep__ = ",\\\n"; + endif +else + __plot_command__{__current_figure__} = "__gnuplot_plot__"; + __plot_command_sep__ = ""; + __plot_data__{__current_figure__} = []; + __plot_data_offset__(__current_figure__) = 1; +endif
--- a/scripts/plot/__plt__.m +++ b/scripts/plot/__plt__.m @@ -25,19 +25,17 @@ function __plt__ (caller, varargin) + __plot_globals__; + nargs = nargin (); if (nargs > 1) k = 1; - j = 1; + j = __plot_data_offset__(__current_figure__); x_set = false; y_set = false; - have_gp_cmd = false; - - gp_cmd = "__gnuplot_plot__"; - sep = ""; ## Gather arguments, decode format, gather plot strings, and plot lines. @@ -56,9 +54,9 @@ if (x_set) fmt = __pltopt__ (caller, next_arg); if (y_set) - [data{j}, fmtstr] = __plt2__ (x, y, fmt); + [__plot_data__{__current_figure__}{j}, fmtstr] = __plt2__ (x, y, fmt); else - [data{j}, fmtstr] = __plt1__ (x, fmt); + [__plot_data__{__current_figure__}{j}, fmtstr] = __plt1__ (x, fmt); endif have_data = true; x_set = false; @@ -69,7 +67,7 @@ elseif (x_set) if (y_set) fmt = __pltopt__ (caller, ""); - [data{j}, fmtstr] = __plt2__ (x, y, fmt); + [__plot_data__{__current_figure__}{j}, fmtstr] = __plt2__ (x, y, fmt); have_data = true; x = next_arg; y_set = false; @@ -83,24 +81,30 @@ endif if (have_data) - if (iscell (data{j})) - for i = 1:length (data{j}) - gp_cmd = sprintf ("%s%s data{%d}{%d} %s", gp_cmd, sep, - j, i, fmtstr{i}); - sep = ",\\\n"; + if (iscell (__plot_data__{__current_figure__}{j})) + for i = 1:length (__plot_data__{__current_figure__}{j}) + __plot_command__{__current_figure__} \ + = sprintf ("%s%s __plot_data__{__current_figure__}{%d}{%d} %s", + __plot_command__{__current_figure__}, + __plot_command_sep__, j, i, fmtstr{i}); + __plot_command_sep__ = ",\\\n"; endfor else - gp_cmd = sprintf ("%s%s data{%d} %s", gp_cmd, sep, j, fmtstr); - sep = ",\\\n"; + __plot_command__{__current_figure__} \ + = sprintf ("%s%s __plot_data__{__current_figure__}{%d} %s", + __plot_command__{__current_figure__}, + __plot_command_sep__, j, fmtstr); + __plot_command_sep__ = ",\\\n"; endif j++; - have_gp_cmd = true; endif endwhile - if (have_gp_cmd) - eval (gp_cmd); + __plot_data_offset__(__current_figure__) = j; + + if (! isempty (__plot_command__{__current_figure__})) + eval (__plot_command__{__current_figure__}); endif else
--- a/scripts/plot/figure.m +++ b/scripts/plot/figure.m @@ -29,6 +29,8 @@ function f = figure (n) + __plot_globals__; + static figure_list = create_set (0); static figure_called = 0; @@ -38,6 +40,8 @@ f = n; endif + __current_figure__ = f; + if (nargin < 2) if (gnuplot_has_frames) gnuterm = getenv ("GNUTERM");
new file mode 100644 --- /dev/null +++ b/scripts/plot/hold.m @@ -0,0 +1,73 @@ +## 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 {Built-in Function} {} hold @var{args} +## Tell Octave to `hold' the current data on the plot when executing +## subsequent plotting commands. This allows you to execute a series of +## plot commands and have all the lines end up on the same figure. The +## default is for each new plot command to clear the plot device first. +## For example, the command +## +## @example +## hold on +## @end example +## +## @noindent +## turns the hold state on. An argument of @code{"off"} turns the hold +## state off, and @code{hold} with no arguments toggles the current hold +## state. +## @end deftypefn + +## PKG_ADD: mark_as_command hold + +function hold (arg) + + 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 + + usage_msg = "hold (\"on\") or hold (\"off\")"; + + 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; + else + usage (usage_msg); + endif + else + usage (usage_msg); + endif + +endfunction
new file mode 100644 --- /dev/null +++ b/scripts/plot/ishold.m @@ -0,0 +1,49 @@ +## 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 {Built-in Function} {} ishold +## Return 1 if the next line will be added to the current plot, or 0 if +## the plot device will be cleared before drawing the next line. +## @end deftypefn + +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__); + else + usage ("ishold ()"); + endif + +endfunction
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2005-07-08 John W. Eaton <jwe@octave.org> + + * DLD-FUNCTIONS/gplot.l (Fhold, Fishold): Delete. + (clear_before_plotting): Delete static variable. + Delete PKG_ADD line for hold. + 2005-07-07 John W. Eaton <jwe@octave.org> * pr-output.cc (pr_plus_format): Delete "static" from template decl.
--- a/src/DLD-FUNCTIONS/gplot.l +++ b/src/DLD-FUNCTIONS/gplot.l @@ -15,8 +15,6 @@ // PKG_ADD: mark_as_command ("gshow"); -// PKG_ADD: mark_as_command ("hold"); - // PKG_ADD: mark_as_command ("set"); // PKG_ADD: mark_as_command ("show"); @@ -260,9 +258,6 @@ // The gnuplot terminal type. static std::string gnuplot_terminal_type; -// Should the graph window be cleared before plotting the next line? -static bool clear_before_plotting = true; - // Pipe to gnuplot. static oprocstream *plot_stream = 0; @@ -877,24 +872,14 @@ else if (caller == "plot") { ndim = 2; - if (clear_before_plotting || plot_line_count == 0) - { - plot_line_count = 0; - outstr += Vgnuplot_command_plot + " "; - } - else - outstr += Vgnuplot_command_replot + " "; + plot_line_count = 0; + outstr += Vgnuplot_command_plot + " "; } else if (caller == "splot") { ndim = 3; - if (clear_before_plotting || plot_line_count == 0) - { - plot_line_count = 0; - outstr += Vgnuplot_command_splot + " "; - } - else - outstr += Vgnuplot_command_replot + " "; + plot_line_count = 0; + outstr += Vgnuplot_command_splot + " "; } else throw gpt_parse_error ("unknown plot command"); @@ -1180,70 +1165,6 @@ return retval; } -DEFUN_DLD (hold, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} hold @var{args}\n\ -Tell Octave to `hold' the current data on the plot when executing\n\ -subsequent plotting commands. This allows you to execute a series of\n\ -plot commands and have all the lines end up on the same figure. The\n\ -default is for each new plot command to clear the plot device first.\n\ -For example, the command\n\ -\n\ -@example\n\ -hold on\n\ -@end example\n\ -\n\ -@noindent\n\ -turns the hold state on. An argument of @code{off} turns the hold state\n\ -off, and @code{hold} with no arguments toggles the current hold state.\n\ -@end deftypefn") -{ - octave_value_list retval; - - gnuplot_init (); - - int argc = args.length () + 1; - - string_vector argv = args.make_argv ("hold"); - - if (error_state) - return retval; - - switch (argc) - { - case 1: - clear_before_plotting = ! clear_before_plotting; - break; - - case 2: - if (argv[1] == "on") - clear_before_plotting = false; - else if (argv[1] == "off") - clear_before_plotting = true; - else - print_usage ("hold"); - break; - - default: - print_usage ("hold"); - break; - } - - return retval; -} - -DEFUN_DLD (ishold, , , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} ishold\n\ -Return 1 if the next line will be added to the current plot, or 0 if\n\ -the plot device will be cleared before drawing the next line.\n\ -@end deftypefn") -{ - gnuplot_init (); - - return octave_value (! clear_before_plotting); -} - DEFUN_DLD (purge_tmp_files, , , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} purge_tmp_files\n\
--- a/src/DLD-FUNCTIONS/matrix_type.cc +++ b/src/DLD-FUNCTIONS/matrix_type.cc @@ -180,7 +180,7 @@ { // Use STL function to convert to lower case std::transform (str_typ.begin (), str_typ.end (), - str_typ.begin (), std::tolower); + str_typ.begin (), tolower); if (str_typ == "diagonal") mattyp.mark_as_diagonal ();