跳过Gnuplot中的空文件 [英] Skipping empty files in Gnuplot

查看:93
本文介绍了跳过Gnuplot中的空文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gnuplot 4.6.另外,我知道一年多以前在此处提出了类似的问题.要解决这个问题,需要编写一个小的bash脚本.我想知道是否有可能从gnuplot脚本中实现此目的,尤其是当gnuplot-4.6添加了许多很酷的功能时.我正在尝试实现这样的目标:

I am using gnuplot 4.6. Also, I know that a similar question was asked more than a year ago here. The answer to that requires to write a small bash script. I want to know if it is possible to achieve this from within gnuplot script, especially when gnuplot-4.6 has so many cool features added. I am trying to achieve something like this :

set xrange[xL:xU]
set yrange[yL:yU]
plot "file1.dat" using 1:2 w l lt 1 lw 1 lc 3,\
"file2.dat" using 1:2 w l lt 1 lw 1 lc 3

我将循环重复上述过程,并且xrange& yrange参数在每次迭代中都会更新.另外,我将每次迭代的输出另存为某些图像文件.现在,保证file2.dat在所有迭代中都有一些要点.但是对于file1.dat而言,这不是正确的.因此,我希望gnuplot在它为空的情况下跳过对file1.dat的绘制.请注意,如果从file1.dat中未绘制任何点,则对我而言完全可以.

I am repeating the above process in a loop and the xrange & yrange parameters are being updated in each iteration. Also, I am saving the output of each iteration as some image file. Now, file2.dat is guaranteed to have some points in all iterations. BUT this is NOT true for file1.dat. Hence, I want gnuplot to skip plotting the file1.dat in case it is empty. Please note, that it is PERFECTLY OK in my case if no points are plotted from file1.dat.

使用if语句可以轻松实现这一点,只要gnuplot中有一些命令可以检测文件是否没有点,而无需尝试对其进行打印.在这种情况下,上面的代码将如下所示:

This can be achieved easily using an if statement, provided there is some command in gnuplot to detect if a file has no points, without trying to plot it. In that case, the above code will look something like this :

set xrange[xL:xU]
set yrange[yL:yU]
if ("file.dat" not empty){
plot "file1.dat" using 1:2 w l lt 1 lw 1 lc 3,\
    "file2.dat" using 1:2 w l lt 1 lw 1 lc 3
}else {
plot "file2.dat" using 1:2 w l lt 1 lw 1 lc 3
}

请帮助我制定上述if语句的'condition'.

Please help me formulate the 'condition' of the aforementioned if statement.

感谢&干杯

Abhinav

推荐答案

我找不到仅使用gnuplot命令的黑客.结果,我发布了一项工作,该工作可以利用shell的帮助来查找file1.dat是否具有任何数据行.

I could not find any hack that used only gnuplot commands. As a result, I am posting a work around which takes the help of shell to find if file1.dat has any any lines of data or not.

gnuplot脚本文件中的条件如下所示:

The condition in the gnuplot script file will look like :

if(system("awk '{x++}END{ print x}' file1.dat")>0){
    plot "file1.dat" using 1:2 w l lt 1 lw 1 lc 3,\
    "file2.dat" using 1:2 w l lt 1 lw 1 lc 3
}else{
    plot "file2.dat" using 1:2 w l lt 1 lw 1 lc 3
}

如果有人可以给我一个gnuplot仅命令方法,我仍将不胜感激.

I still would be grateful if anyone can give me a gnuplot command only method.

这篇关于跳过Gnuplot中的空文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆