我有一个C ++程序,使用嵌入式lua脚本将数据点从程序写入文件,我希望能够同时运行gnuplot实例来绘制数据点。
select
coalesce(A.ID, B.ID, C.ID) as ID,
A.ColA, A.ColB, B.ColC, B.ColD, B.ColE, C.ColF, C.ColG
from
(select
ID,
row_number() over (partition by ID order by ColA) as rownumber,
ColA,
ColB
from
TableA t) A
full outer join
(select
ID,
row_number() over (partition by ID order by ColC) as rownumber,
ColC,
ColD,
ColE
from
TableB t) B on B.ID = A.ID and B.rownumer = A.rownumber
full outer join
(select
ID,
row_number() over (partition by ID order by ColF) as rownumber,
ColF,
ColG
from
TableC t) C on C.ID = nvl(A.ID, B.ID) and C.rownumer = A.rownumber
gnuplot文件如下所示:
io.output(pfile);
io.write(t, "\t", p_x, "\t", p_y, "\t", p_z, "\n");
上面的gnuplot脚本适用于完整的数据文件,但我希望它在程序运行时实时绘制。当lua脚本写入文件时,有时gnuplot脚本会捕获具有不完整的最后一行的文件。这会产生错误:
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
如何让gnuplot编写最后一行或无效数据集的脚本?
谢谢!
答案 0 :(得分:1)
有些乱搞lua实际上为我解决了它。在io.write(...)调用之后调用io.flush()函数似乎每次都将完整的行写入文件。
当然,并没有告诉gnuplot SKIP或IGNORE的最后一行,但确保最后一行完整。