|
From: <P...@dr...> - 2007-12-11 10:43:03
|
I tried to get a gnuplot script to read
from stdin like a normal linux filter using plot '-'
However gnuplot doesn't support this because it
clears it's stdin on startup, as the following
code from plot.c shows:
#ifdef X11
/* This call used to be in x11.trm, with the following comment:
* Multi-character inputs like escape sequences but also mouse-past=
ed
* text got buffered and therefore didn't trigger the select() func=
tion
* in X11_waitforinput(). Switching to unbuffered input solved this=
.
* 23 Jan 2002 (joze)
* But switching to unbuffered mode causes all characters in the inpu=
t
* buffer to be lost. So the only safe time to do it is on program en=
try.
* The #ifdef X11 is probably unnecessary, but makes the change minim=
al.
* Do any non-X platforms suffer from the same problem?
* EAM - Jan 2004.
*/
setvbuf(stdin, (char *) NULL, _IONBF, 0);
#endif
As you can see it's hardcoded, so even if one selects
a different terminal, stdin is still cleared.
I know how to work around this but it's a horrible hack.
I.E. rather than:
gen_data | ./plot.gp > file.png
one needs to do:
(cat plot.gp; gen_data) | gnuplot > file.png
Perhaps FAQ 1.4 could be updated with this info.
Also, can we determine if we're using X11 are runtime,
so that this issue can be worked around using GNUTERM environment
variable for example?
What's the X issue exactly. Does it really need to read from stdin?
thanks,
P=C3=A1draig.
|
|
From: Ethan M. <merritt@u.washington.edu> - 2007-12-12 20:43:52
|
On Tuesday 11 December 2007 02:32, P=C3=A1draig Brady wrote:
> I tried to get a gnuplot script to read
> from stdin like a normal linux filter using plot '-'
It certainly works in general. Consider the following trivial example,
which draws a big red triangle:
plot '-' with filledcurve
1 1
2 3
3 2
e
Could you please provide a specific example in which it doesn't work?
> I know how to work around this but it's a horrible hack.
> I.E. rather than:
> gen_data | ./plot.gp > file.png
Erk. What is that supposed to be doing?
I suspect that the gnuplot command
plot '-'
doesn't mean what you think it does.
It does not mean "read from original stdin of parent process";
it means "read from the current input stream".
Assuming that the file ./plot.gp calls gnuplot, that means that
plot '-' will read from the file plot.gp.
Please explain exactly what you are trying to do, so that we can
suggest alternatives.
> one needs to do:
> (cat plot.gp; gen_data) | gnuplot > file.png
That command makes no sense to me. Maybe you want this?
file plot.gp contains:
set term png
system "gen_data > temp.dat"
plot "temp.dat"
gnuplot plot.gp > file.png
=2D-=20
Ethan A Merritt Courier Deliveries: 1959 NE Pacific
Dept of Biochemistry
Health Sciences Building
University of Washington - Seattle WA 98195-7742
|
|
From: Ethan M. <merritt@u.washington.edu> - 2007-12-12 22:16:35
|
On Wednesday 12 December 2007 12:43, Ethan Merritt wrote: > That command makes no sense to me. Maybe you want this? > > file plot.gp contains: > set term png > system "gen_data > temp.dat" > plot "temp.dat" > > gnuplot plot.gp > file.png Or maybe even: setenv GNUTERM png echo 'plot "< gen_data"' | gnuplot > file.png -- Ethan A Merritt |
|
From: <HBB...@t-...> - 2007-12-12 21:21:37
|
Pádraig Brady wrote:
> I tried to get a gnuplot script to read
> from stdin like a normal linux filter using plot '-'
> I know how to work around this but it's a horrible hack.
> I.E. rather than:
> gen_data | ./plot.gp > file.png
Without seeing what's in plot.gp, it's quite unclear what you're trying
to do here. What's wrong with the more conventional
gen_data | gnuplot plot.gp > file.png
?
|
|
From: <P...@dr...> - 2007-12-13 13:22:56
|
Hans-Bernhard Br=C3=B6ker wrote: > P=C3=A1draig Brady wrote: >> I tried to get a gnuplot script to read >> from stdin like a normal linux filter using plot '-' >=20 >> I know how to work around this but it's a horrible hack. >> I.E. rather than: >> gen_data | ./plot.gp > file.png >=20 > Without seeing what's in plot.gp, it's quite unclear what you're trying > to do here. What's wrong with the more conventional >=20 > gen_data | gnuplot plot.gp > file.png I want to read data on stdin and write png to stdout. I.E. behave like a standard unix filter which has lots of advantages. Here is an example plot.gpi script to do that: #!/usr/bin/env gnuplot set term png plot '-' However it doesn't work as shown below, as gnuplot drains its stdin on st= artup as detailed previously. It should not do that if possible. At least it sh= ould be a runtime rather than a compile time decision. Your variation above is= equivalent. $ seq 10 | ./plot.gpi > plot.png plot '-' "./plot.gpi", line 3: warning: Skipping data file with no valid points If you write the data to stdin after the plot command, then it works: (cat ./plot.gpi; seq 10) | gnuplot > plot.png Ethan's variant here is not as general as it hardcodes the source of the data within the script echo 'plot "< seq 10"' | GNUTERM=3Dpng gnuplot > plot.png thanks, P=C3=A1draig. |
|
From: Ethan M. <merritt@u.washington.edu> - 2007-12-14 23:25:05
|
On Thursday 13 December 2007 05:17, P=C3=A1draig Brady wrote: > If you write the data to stdin after the plot command, then it works: > (cat ./plot.gpi; seq 10) | gnuplot > plot.png >=20 > Ethan's variant here is not as general as it hardcodes the > source of the data within the script >=20 > echo 'plot "< seq 10"' | GNUTERM=3Dpng gnuplot > plot.png You are trying to use gnuplot in a mode it was not designed for. If it works for you, OK. But I think that in general this is not something we should try to support. =20 As I pointed out before, you are assuming that "stdin" is exactly the same as "current input stream". But it is not the same. =20 Consider the gnuplot commands "load" and "reread", for example. If either of these is in effect, then plot '-' will read from the current command file rather than from stdin. =20 My advice is to write a small perl/python/whatever wrapper to=20 manage the input and output streams. =2D-=20 Ethan A Merritt |
|
From: <HBB...@t-...> - 2007-12-14 23:44:58
|
Pádraig Brady wrote: > I want to read data on stdin and write png to stdout. You're missing the fact that you also want to read input to gnuplot from a second place: the script file. It's this script file that gets in the way of what you're trying to do, as shown by the fact that (cat script ; gen_data) | gnuplot works. As does gnuplot script <(gen_data) gnuplot is designed to take commands, not data, from its standard input. It's an extension for it to accept data from the command input stream. > I.E. behave like a standard unix filter which has lots of advantages. Standard unix filters aren't in the habit of taking commands from their standard input. gnuplot is. |