Mercurial > hg > octave-lojdl
changeset 9113:4bb94a71913b
__gnuplot_open_stream__.m: New function and its application.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Sun, 12 Apr 2009 20:40:53 -0400 |
parents | f5b51f54f44e |
children | 79e90381b402 |
files | scripts/ChangeLog scripts/plot/Makefile.in scripts/plot/__gnuplot_get_var__.m scripts/plot/__gnuplot_open_stream__.m scripts/plot/gnuplot_drawnow.m |
diffstat | 5 files changed, 56 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,10 @@ +2009-04-12 Ben Abbott <bpabbott@mac.com> + + * plot/__gnuplot_open_stream__.m: New function. + * plot/__gnuplot_get_var__.m: If not open, open the gnuplot plot stream. + * plot/gnuplot_drawnow.m: Replace internal function open_gnuplot_stream + with new __gnuplot_open_stream__. + 2009-04-11 David Bateman <dbateman@free.fr> * geometry/trisurf.m: New file.
--- a/scripts/plot/Makefile.in +++ b/scripts/plot/Makefile.in @@ -49,6 +49,7 @@ __ezplot__.m \ __gnuplot_get_var__.m \ __gnuplot_has_feature__.m \ + __gnuplot_open_stream__.m \ __go_close_all__.m \ __go_draw_axes__.m \ __go_draw_figure__.m \
--- a/scripts/plot/__gnuplot_get_var__.m +++ b/scripts/plot/__gnuplot_get_var__.m @@ -37,7 +37,11 @@ endif if (numel (h) == 1 && isfigure (h)) - ostream = get (h, "__plot_stream__"); + if (isempty (get (gcf, "__plot_stream__"))) + ostream = __gnuplot_open_stream__ (2, h); + else + ostream = get (h, "__plot_stream__"); + endif else ostream = h; endif
new file mode 100644 --- /dev/null +++ b/scripts/plot/__gnuplot_open_stream__.m @@ -0,0 +1,41 @@ +## Copyright (C) 2009 Ben Abbott +## +## 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 of the License, or +## (at your option) any later version. +## +## This program 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 +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{stream}} __gnuplot_open_stream__ (@var{npipes}, @var{h}) +## Undocumented internal function. +## @end deftypefn + +## Author: Ben Abbott <bpabbott@mac.com> +## Created: 2009-04-11 + +function plot_stream = __gnuplot_open_stream__ (npipes, h) + cmd = gnuplot_binary (); + if (npipes > 1) + [plot_stream(1), plot_stream(2), pid] = popen2 (cmd); + if (pid < 0) + error ("__gnuplot_open_stream__: failed to open connection to gnuplot."); + endif + else + plot_stream = popen (cmd, "w"); + if (plot_stream < 0) + error ("__gnuplot_open_stream__: failed to open connection to gnuplot."); + endif + endif + if (nargin > 1) + set (h, "__plot_stream__", plot_stream); + endif +endfunction
--- a/scripts/plot/gnuplot_drawnow.m +++ b/scripts/plot/gnuplot_drawnow.m @@ -41,7 +41,7 @@ printing = ! output_to_screen (gnuplot_trim_term (term)); default_plot_stream = get (h, "__plot_stream__"); unwind_protect - plot_stream = open_gnuplot_stream (2, h); + plot_stream = __gnuplot_open_stream__ (2, h); if (__gnuplot_has_feature__ ("variable_GPVAL_TERMINALS")) available_terminals = __gnuplot_get_var__ (plot_stream, "GPVAL_TERMINALS"); available_terminals = regexp (available_terminals, "\\b\\w+\\b", "match"); @@ -79,7 +79,7 @@ ## Graphics terminal for display. plot_stream = get (h, "__plot_stream__"); if (isempty (plot_stream)) - plot_stream = open_gnuplot_stream (2, h); + plot_stream = __gnuplot_open_stream__ (2, h); new_stream = true; else new_stream = false; @@ -108,24 +108,6 @@ endif endfunction -function plot_stream = open_gnuplot_stream (npipes, h) - cmd = gnuplot_binary (); - if (npipes > 1) - [plot_stream(1), plot_stream(2), pid] = popen2 (cmd); - if (pid < 0) - error ("drawnow: failed to open connection to gnuplot"); - endif - else - plot_stream = popen (cmd, "w"); - if (plot_stream < 0) - error ("drawnow: failed to open connection to gnuplot"); - endif - endif - if (! isempty (h)) - set (h, "__plot_stream__", plot_stream); - endif -endfunction - function [enhanced, implicit_margin] = gnuplot_set_term (plot_stream, new_stream, h, term, file) ## Generate the gnuplot "set terminal <term> ..." command. Include ## the subset of properties "position", "units", "paperposition",