Mercurial > hg > octave-lyh
annotate scripts/plot/__gnuplot_open_stream__.m @ 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 | |
children | ff8d7f3ad203 fe30458b1de8 |
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."); |
4bb94a71913b
__gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
31 endif |
4bb94a71913b
__gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
32 else |
4bb94a71913b
__gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
33 plot_stream = popen (cmd, "w"); |
4bb94a71913b
__gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
34 if (plot_stream < 0) |
4bb94a71913b
__gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
35 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
|
36 endif |
4bb94a71913b
__gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
37 endif |
4bb94a71913b
__gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
38 if (nargin > 1) |
4bb94a71913b
__gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
39 set (h, "__plot_stream__", plot_stream); |
4bb94a71913b
__gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
40 endif |
4bb94a71913b
__gnuplot_open_stream__.m: New function and its application.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
41 endfunction |