annotate scripts/plot/__gnuplot_open_stream__.m @ 12073:fe30458b1de8 release-3-2-x

try to avoid gnuplot zombies
author John W. Eaton <jwe@octave.org>
date Wed, 26 Aug 2009 08:17:08 +0200
parents 4bb94a71913b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9113
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
1 ## Copyright (C) 2009 Ben Abbott
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
2 ##
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
3 ## This program is free software; you can redistribute it and/or modify
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
4 ## it under the terms of the GNU General Public License as published by
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
5 ## the Free Software Foundation; either version 2 of the License, or
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
6 ## (at your option) any later version.
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
7 ##
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
8 ## This program is distributed in the hope that it will be useful,
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
11 ## GNU General Public License for more details.
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
12 ##
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
13 ## You should have received a copy of the GNU General Public License
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
14 ## along with Octave; see the file COPYING. If not, see
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
15 ## <http://www.gnu.org/licenses/>.
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
16
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
17 ## -*- texinfo -*-
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
18 ## @deftypefn {Function File} {@var{stream}} __gnuplot_open_stream__ (@var{npipes}, @var{h})
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
19 ## Undocumented internal function.
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
20 ## @end deftypefn
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
21
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
22 ## Author: Ben Abbott <bpabbott@mac.com>
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
23 ## Created: 2009-04-11
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
24
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
25 function plot_stream = __gnuplot_open_stream__ (npipes, h)
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
26 cmd = gnuplot_binary ();
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
27 if (npipes > 1)
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
28 [plot_stream(1), plot_stream(2), pid] = popen2 (cmd);
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
29 if (pid < 0)
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
30 error ("__gnuplot_open_stream__: failed to open connection to gnuplot.");
12073
fe30458b1de8 try to avoid gnuplot zombies
John W. Eaton <jwe@octave.org>
parents: 9113
diff changeset
31 else
fe30458b1de8 try to avoid gnuplot zombies
John W. Eaton <jwe@octave.org>
parents: 9113
diff changeset
32 plot_stream(3) = pid;
9113
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
33 endif
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
34 else
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
35 plot_stream = popen (cmd, "w");
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
36 if (plot_stream < 0)
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
37 error ("__gnuplot_open_stream__: failed to open connection to gnuplot.");
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
38 endif
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
39 endif
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
40 if (nargin > 1)
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
41 set (h, "__plot_stream__", plot_stream);
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
42 endif
4bb94a71913b __gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
43 endfunction