|
From: Chris K <gnu...@li...> - 2006-04-02 00:02:19
|
As I am trying to send data to gnuplot, I have been experimenting to understand
how to pipe data to stdin.
Short version: It is possible to put ascii data after a plot command with more
than one blob (several sections that end with the line "e") Can I send more that
one binary blob?
In particular, I was seeing if I could send binary data via stdin:
cat "command-1.gp" "binary.dat" | gnuplot
where the command-1.gp file is one line:
plot "-" binary record=5x2 using 1:2 with linespoints
and the binary.dat file is 10 floats (40 bytes)
That worked like I expected it to, parsing the binary file as "x1 y1 x2 y3 x3 y3
x4 y4 x5 y5" and plotting markers at (x1,y1) (x2,y2),...
When I tried something more complicated, it failed:
plot "-" binary record=5x2 using 1:2 with linespoints,\
"-" binary record=5x2 using 1:2 with linespoints
cat "command-2.gp" "binary.dat" "binary.dat" | gnuplot
The error message seems to indicated the second "-" is the problem:
gnuplot> plot "-" binary record=5x2 using 1:($2) with linespoints, "-"
binary record=5x2 using 1:($2)**2 with linespoints
^
line 0: warning: Skipping data file with no valid points
The documentation page explains that:
> General binary data can be entered at the command line via
the special file name '-'. However, this is intended for use through
a pipe where programs can exchange binary data, not for keyboards.
There is no "end of record" character for binary data.
Gnuplot continues reading from a pipe until it has read the
number of points declared in the array qualifier.
But I used a record qualifier. And I don't know how to simulate the array using
records (even given that I can resort the order of the binary data). Both
"array=5,5 index0" and "array=5,5 index 1" work like I expect. But I don't see
how i can make an (x,y) plot from index 0 and index 1.
Can gnuplot do the same ascii data tricks with binary data?
|
|
From: Daniel J S. <dan...@ie...> - 2006-04-02 05:38:22
|
Chris, I've read your list entry and will investigate. I can't recall thinking to try an example with multiple plots and "-", so there may be a problem. Dan Chris K wrote: > As I am trying to send data to gnuplot, I have been experimenting to understand > how to pipe data to stdin. > > > Short version: It is possible to put ascii data after a plot command with more > than one blob (several sections that end with the line "e") Can I send more that > one binary blob? > > In particular, I was seeing if I could send binary data via stdin: > > cat "command-1.gp" "binary.dat" | gnuplot > > where the command-1.gp file is one line: > > plot "-" binary record=5x2 using 1:2 with linespoints > > and the binary.dat file is 10 floats (40 bytes) > > That worked like I expected it to, parsing the binary file as "x1 y1 x2 y3 x3 y3 > x4 y4 x5 y5" and plotting markers at (x1,y1) (x2,y2),... > > When I tried something more complicated, it failed: > > plot "-" binary record=5x2 using 1:2 with linespoints,\ > "-" binary record=5x2 using 1:2 with linespoints > > cat "command-2.gp" "binary.dat" "binary.dat" | gnuplot > > The error message seems to indicated the second "-" is the problem: > > gnuplot> plot "-" binary record=5x2 using 1:($2) with linespoints, "-" > binary record=5x2 using 1:($2)**2 with linespoints > > ^ > line 0: warning: Skipping data file with no valid points > > The documentation page explains that: > > >>General binary data can be entered at the command line via > > the special file name '-'. However, this is intended for use through > a pipe where programs can exchange binary data, not for keyboards. > There is no "end of record" character for binary data. > Gnuplot continues reading from a pipe until it has read the > number of points declared in the array qualifier. > > But I used a record qualifier. And I don't know how to simulate the array using > records (even given that I can resort the order of the binary data). Both > "array=5,5 index0" and "array=5,5 index 1" work like I expect. But I don't see > how i can make an (x,y) plot from index 0 and index 1. > > Can gnuplot do the same ascii data tricks with binary data? > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting language > that extends applications into web and mobile media. Attend the live webcast > and join the prime developer group breaking into this new coding territory! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 > _______________________________________________ > gnuplot-beta mailing list > gnu...@li... > https://lists.sourceforge.net/lists/listinfo/gnuplot-beta > -- Dan Sebald phone: 608 256 7718 email: daniel DOT sebald AT ieee DOT org URL: http://webpages DOT charter DOT net/dsebald/ |
|
From: Daniel J S. <dan...@ie...> - 2006-04-02 08:15:12
|
Daniel J Sebald wrote: > Chris, > > I've read your list entry and will investigate. I can't recall thinking > to try an example with multiple plots and "-", so there may be a problem. Actually, I did give an example of this. If you look in 'image.dem' there is a plot titled: "Binary data specified at the command line, intended for use through pipe" in which the binary data is inside the file itself (i.e., as though one somehow typed binary data at the command line, which will never happen but it is simply meant to illustrate). So... >> plot "-" binary record=5x2 using 1:2 with linespoints,\ >> "-" binary record=5x2 using 1:2 with linespoints >> >> cat "command-2.gp" "binary.dat" "binary.dat" | gnuplot >> >> The error message seems to indicated the second "-" is the problem: >> >> gnuplot> plot "-" binary record=5x2 using 1:($2) with linespoints, >> "-" >> binary record=5x2 using 1:($2)**2 with linespoints >> >> ^ >> line 0: warning: Skipping data file with no valid points >> ... I wonder why the above is failing. The warning makes me think that gnuplot believes it has run out of data. Might you have an extra CR or LF as a result of the cat process? Actually, this seems to work for me. For example, try the attached files with the command cat "command" "bin1.bin" "bin2.bin" | gnuplot and you should see a PNG file appear in the directory. >> The documentation page explains that: >> >> >>> General binary data can be entered at the command line via >> >> >> the special file name '-'. However, this is intended for use through >> a pipe where programs can exchange binary data, not for keyboards. >> There is no "end of record" character for binary data. >> Gnuplot continues reading from a pipe until it has read the >> number of points declared in the array qualifier. >> >> But I used a record qualifier. And I don't know how to simulate the >> array using >> records (even given that I can resort the order of the binary data). >> Both >> "array=5,5 index0" and "array=5,5 index 1" work like I expect. But I >> don't see >> how i can make an (x,y) plot from index 0 and index 1. >> >> Can gnuplot do the same ascii data tricks with binary data? I'm not exactly sure what you mean to do here. However, look through the examples in image.dem and see if there is anything close to what you want. (I'm thinking there should be.) I tried giving enough examples of every feature. Dan |
|
From: Chris K <gnu...@li...> - 2006-04-02 10:40:44
|
Daniel J Sebald wrote:
> Daniel J Sebald wrote:
>>> plot "-" binary record=5x2 using 1:2 with linespoints,\
>>> "-" binary record=5x2 using 1:2 with linespoints
>>>
>>> cat "command-2.gp" "binary.dat" "binary.dat" | gnuplot
>>>
>>> The error message seems to indicated the second "-" is the problem:
>>>
>>> gnuplot> plot "-" binary record=5x2 using 1:($2) with
>>> linespoints, "-"
>>> binary record=5x2 using 1:($2)**2 with linespoints
>>>
>>> ^
>>> line 0: warning: Skipping data file with no valid points
>>>
>
> ... I wonder why the above is failing. The warning makes me think that
> gnuplot believes it has run out of data. Might you have an extra CR or
> LF as a result of the cat process?
>
> Actually, this seems to work for me. For example, try the attached
> files with the command
>
> cat "command" "bin1.bin" "bin2.bin" | gnuplot
>
> and you should see a PNG file appear in the directory.
Your example worked. So I have written more test cases, and I have isolated the
trigger for failure.
This works:
set title "test-2.gp"
plot "-" binary record=10 using 0:1 with linespoints,\
"-" binary record=10 using 0:($1)**2 with linespoints
This works:
set title "test-3.gp"
plot "-" binary record=10 using 0:1 with linespoints,\
"-" binary record=5x2 using 1:($2)**2 with linespoints
This fails, saying "line 0: warning: Skipping data file with no valid points"
set title "test-4.gp"
plot "-" binary record=5x2 using 1:2 with linespoints,\
"-" binary record=5x2 using 1:($2)**2 with linespoints
The use of 5x2 instead of 10 in the first plot triggers the error. I am going
to hypothesize that the first use of "record=5x2" causes it to read an amount of
data greater than "record=10". But I have not read the code to check.
I see in datafile.c :
/* Daniel Sebald: added general binary 2d data support. (20 August 2004)
*/
So thanks for the help with this.
--
Chris
|
|
From: Chris K <gnu...@li...> - 2006-04-02 11:42:19
|
I almost see what is happening now. > This works: > > set title "test-2.gp" > plot "-" binary record=10 using 0:1 with linespoints,\ > "-" binary record=10 using 0:($1)**2 with linespoints > > This works: > > set title "test-3.gp" > plot "-" binary record=10 using 0:1 with linespoints,\ > "-" binary record=5x2 using 1:($2)**2 with linespoints > > This fails, saying "line 0: warning: Skipping data file with no valid points" > > set title "test-4.gp" > plot "-" binary record=5x2 using 1:2 with linespoints,\ > "-" binary record=5x2 using 1:($2)**2 with linespoints > > The use of 5x2 instead of 10 in the first plot triggers the error. I am going > to hypothesize that the first use of "record=5x2" causes it to read an amount of > data greater than "record=10". But I have not read the code to check. > outd.data is exactly 10 floats long (40 bytes) cat test-2.gp outd.data out.data | gnuplot WORKS cat test-3.gp outd.data out.data | gnuplot WORKS cat test-4.gp outd.data out.data | gnuplot FAILS cat test-4.gp outd.data out.data outd.data | gnuplot WORKS This is passing strange. I am attaching my files. (Endian is correct for Mac OS X on PPC, you may need to specify). -- Chris |
|
From: Daniel J S. <dan...@ie...> - 2006-04-02 18:58:22
|
Chris K wrote: > This is passing strange. I am attaching my files. > > (Endian is correct for Mac OS X on PPC, you may need to specify). OK, "endian=big" works.> I almost see what is happening now. > outd.data is exactly 10 floats long (40 bytes) > > cat test-2.gp outd.data out.data | gnuplot WORKS > cat test-3.gp outd.data out.data | gnuplot WORKS > cat test-4.gp outd.data out.data | gnuplot FAILS > cat test-4.gp outd.data out.data outd.data | gnuplot WORKS If you mean that it plots, then yes "WORKS" is correct. However, I think this isn't working the manner you intend. It's subtle because of the fact the data within the file looks to be a simple linear or affine relationship. Thus, the shape of the curve when gnuplot does or doesn't generate the index data is about the same. Read on... >>This works: >> >>set title "test-2.gp" >>plot "-" binary record=10 using 0:1 with linespoints,\ >> "-" binary record=10 using 0:($1)**2 with linespoints It specifies record of 10 and since "0" is a special qualifier in gnuplot meaning to generate the index data 10x1=10 floats for the first line and 10*1=10 floats for the second line. No problem; a plot with red and green lines each containing 10 points. (I'll send you the PNGs in a separate email.) Note that "0" and "-1" as special column numbers isn't the most intuitive. Ease of programming probably trumped in that case. There may be a bug here however. I notice that with "0" the index starts at "-1" on the plot. That doesn't seem a reasonable place to start. It should be either "0" or "1". I will check the documentation to see if the start value is specified and will fix it accordingly. >> >>This works: >> >>set title "test-3.gp" >>plot "-" binary record=10 using 0:1 with linespoints,\ >> "-" binary record=5x2 using 1:($2)**2 with linespoints Again, there is a "0" on the first line so that is 10x1=10 floats. But now the second line is saying that the record inside the binary file is 5 by 2 or five pairs (or five 2 tuples) and the using syntax says to use the first coordinate of the pair and the second coordinate of that pair. The "record" and "using" do no conflict, but the specification is that there are only 5 points. So if you look at the graphs you should see there are only 5 points for "test-3.png". As I said before, because of the linear nature of the data, you may have seen the two and thought that "test-2" and "test-3" plotted the same but in fact they are different. >> >>This fails, saying "line 0: warning: Skipping data file with no valid points" >> >>set title "test-4.gp" >>plot "-" binary record=5x2 using 1:2 with linespoints,\ >> "-" binary record=5x2 using 1:($2)**2 with linespoints >> >>The use of 5x2 instead of 10 in the first plot triggers the error. I am going >>to hypothesize that the first use of "record=5x2" causes it to read an amount of >>data greater than "record=10". You may be correct. But I don't see why if fails. This could be a strange "loose end" kind of bug (an unaccounted for boundary value or something) because the "record" and "using" make sense on the plot. The data in the file is 0 1 2 3 4 5 6 7 8 9 and both the red and green plots are obviously treating the data as (0,1) (2,3) (4,5) (6,7) (8,9) in "test-4.png". OK, so a couple strange things there, using "0" starting at -1 and a complaint about running out of data when there really shouldn't be. Let me work on this... Dan |
|
From: Chris K <gnu...@li...> - 2006-04-02 21:25:04
|
Daniel J Sebald wrote: > Chris K wrote: > >> outd.data is exactly 10 floats long (40 bytes) >> >> cat test-2.gp outd.data out.data | gnuplot WORKS >> cat test-3.gp outd.data out.data | gnuplot WORKS >> cat test-4.gp outd.data out.data | gnuplot FAILS >> cat test-4.gp outd.data out.data outd.data | gnuplot WORKS > > If you mean that it plots, then yes "WORKS" is correct. However, I > think this isn't working the manner you intend. That's what I meant. > > It's subtle because of the fact the data within the file looks to be a > simple linear or affine relationship. Thus, the shape of the curve when > gnuplot does or doesn't generate the index data is about the same. Read > on... Yup, just 0..9 > >>> This works: >>> >>> set title "test-2.gp" >>> plot "-" binary record=10 using 0:1 with linespoints,\ >>> "-" binary record=10 using 0:($1)**2 with linespoints > > It specifies record of 10 and since "0" is a special qualifier in > gnuplot meaning to generate the index data 10x1=10 floats for the first > line and 10*1=10 floats for the second line. No problem; a plot with > red and green lines each containing 10 points. (I'll send you the PNGs > in a separate email.) > My plots look like your PNGs > There may be a bug here however. I notice that with "0" the index > starts at "-1" on the plot. That doesn't seem a reasonable place to > start. It should be either "0" or "1". I will check the documentation > to see if the start value is specified and will fix it accordingly. Yeah, I did not pay attention to the (-1) starting x-scale. That is even weirder than I thought. Definitely a bug from my POV. >>> >>> This works: >>> >>> set title "test-3.gp" >>> plot "-" binary record=10 using 0:1 with linespoints,\ >>> "-" binary record=5x2 using 1:($2)**2 with linespoints > > Again, there is a "0" on the first line so that is 10x1=10 floats. But > now the second line is saying that the record inside the binary file is > 5 by 2 or five pairs (or five 2 tuples) and the using syntax says to use > the first coordinate of the pair and the second coordinate of that > pair. The "record" and "using" do no conflict, but the specification is > that there are only 5 points. > > So if you look at the graphs you should see there are only 5 points for > "test-3.png". As I said before, because of the linear nature of the > data, you may have seen the two and thought that "test-2" and "test-3" > plotted the same but in fact they are different. I knew they were different. I was mainly worried about crashing. > >>> >>> This fails, saying "line 0: warning: Skipping data file with no valid >>> points" >>> >>> set title "test-4.gp" >>> plot "-" binary record=5x2 using 1:2 with linespoints,\ >>> "-" binary record=5x2 using 1:($2)**2 with linespoints >>> >>> The use of 5x2 instead of 10 in the first plot triggers the error. I >>> am going >>> to hypothesize that the first use of "record=5x2" causes it to read >>> an amount of >>> data greater than "record=10". > > You may be correct. But I don't see why if fails. This could be a > strange "loose end" kind of bug (an unaccounted for boundary value or > something) because the "record" and "using" make sense on the plot. The > data in the file is 0 1 2 3 4 5 6 7 8 9 and both the red and green plots > are obviously treating the data as > > (0,1) > (2,3) > (4,5) > (6,7) > (8,9) > > in "test-4.png". > > OK, so a couple strange things there, using "0" starting at -1 and a > complaint about running out of data when there really shouldn't be. Let > me work on this... > > Dan > And since "cat test-4.gp outd.data out.data outd.data | gnuplot WORKS" it *seems* to be (a) reading exactly twice as much data for the first 5x2 record as it should and then (b) is happy with a normal amount of data in the second 5x2 record. This behavior is strange enough that I can't really understand how to work around it. And I looked at datafile.c and the parsing is very powerful and very hairy. Trying to think in "clever c" and "clever haskell" in the same day is giving me mental whiplash. -- Chris |