# HG changeset patch # User Ben Abbott # Date 1239583253 14400 # Node ID 4bb94a71913b97b802634e7b5fc77fcdd8ae882a # Parent f5b51f54f44ee22d3638a2212ddf520ad47c0e25 __gnuplot_open_stream__.m: New function and its application. diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,10 @@ +2009-04-12 Ben Abbott + + * 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 * geometry/trisurf.m: New file. diff --git a/scripts/plot/Makefile.in b/scripts/plot/Makefile.in --- 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 \ diff --git a/scripts/plot/__gnuplot_get_var__.m b/scripts/plot/__gnuplot_get_var__.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 diff --git a/scripts/plot/__gnuplot_open_stream__.m b/scripts/plot/__gnuplot_open_stream__.m 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 +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{stream}} __gnuplot_open_stream__ (@var{npipes}, @var{h}) +## Undocumented internal function. +## @end deftypefn + +## Author: Ben Abbott +## 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 diff --git a/scripts/plot/gnuplot_drawnow.m b/scripts/plot/gnuplot_drawnow.m --- 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 ..." command. Include ## the subset of properties "position", "units", "paperposition",