0
votes

I have a C++ program using an embedded lua script to write data points from the program to file, and I want to simultaneously be able to run a gnuplot instance to plot the data points.

io.output(pfile);
io.write(t, "\t", p_x, "\t", p_y, "\t", p_z, "\n");

The gnuplot file looks like:

set termopt enhanced

set title "Linear Momentum Vector"
set xlabel "t (s)"
set ylabel "p (N-s)"

plot "data/plot_p.dat" using 1:2 title "p_x(t)" with lines, \
     "data/plot_p.dat" using 1:3 title "p_y(t)" with lines, \
     "data/plot_p.dat" using 1:4 title "p_z(t)" with lines

set style line 81 lt 0 lc rgb "#808080" lw 0.5

set grid xtics ytics mxtics mytics
set grid back ls 81

pause 0.25
reread

The above gnuplot script works for a complete data file, but I want it to plot in real time while the program is running. While the lua script writes to file, sometimes the gnuplot script catches the file with an incomplete last line. And this generates an error:

"liveplot_p.gnu", line 9: x range is invalid

How would I get gnuplot to script the last line or invalid data sets?

Thank you!

1

1 Answers

1
votes

Some messing around with lua actually solved it for me. Calling the io.flush() function after the io.write(...) call seems to write the complete line into the file every time.

This ofcourse, doesn't tell gnuplot to SKIP or IGNORE the last line but it makes sure the last line is complete.