跳过Gnuplot中的空文件

跳过Gnuplot中的空文件,plot,gnuplot,skip,is-empty,isnullorempty,Plot,Gnuplot,Skip,Is Empty,Isnullorempty,我正在使用gnuplot4.6。另外,我知道一年多前也有人问过类似的问题。解决这个问题需要编写一个小的bash脚本。我想知道是否有可能在gnuplot脚本中实现这一点,特别是当gnuplot-4.6添加了这么多很酷的特性时。我正在努力实现这样的目标: 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

我正在使用gnuplot4.6。另外,我知道一年多前也有人问过类似的问题。解决这个问题需要编写一个小的bash脚本。我想知道是否有可能在gnuplot脚本中实现这一点,特别是当gnuplot-4.6添加了这么多很酷的特性时。我正在努力实现这样的目标:

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
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
}
我在循环中重复上述过程,每次迭代中都会更新xrange和yrange参数。此外,我还将每个迭代的输出保存为一些图像文件。现在,file2.dat保证在所有迭代中都有一些点。但对于file1.dat,情况并非如此。因此,如果file1.dat为空,我希望gnuplot跳过打印它。请注意,在我的例子中,如果没有从file1.dat中绘制点,这是完全正确的

这可以通过使用if语句轻松实现,前提是gnuplot中有一些命令可以检测文件是否没有点,而无需尝试打印它。在这种情况下,上述代码将如下所示:

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
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声明的“条件”

谢谢,干杯


Abhinav

我找不到任何只使用gnuplot命令的黑客。因此,我发布了一篇文章,在shell的帮助下查找file1.dat是否有任何数据行

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

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命令的方法,我仍将不胜感激。

如果文件存在,仍然无法使用只使用gnuplot命令的方法进行检查。您需要某种助手脚本来完成此操作。但为什么这是一个问题?plot命令将发出警告,仅此而已。这是一个问题,因为即使一个文件没有范围内点,我仍然希望打印另一个文件,该文件具有范围内点。你说得对!我认为plot命令只跳过丢失的文件,但它没有。