2
我有以下函數使用perl + gnuplot來繪製數據。輸入數據文件非常多,其中大約一半產生無效範圍,我想檢測並刪除這些不良文件。該函數只處理單個文件,我無法讀取任何gnuplot輸出,只是阻止。我試圖徒勞地讀GPR/GPE。Perl open3讀取gnuplot塊的管道句柄
sub plot_file {
my $filename = shift;
if ($filename =~ m![^\/]+/([^.]+)\.([^.]+)\.([^.]+)!) {
my ($node, $box, $metric) = ($1, $2, $3);
my $plot_file = "plots/$node.$box.$metric.eps";
if ($metric !~ /Sqr/) {
open3(\*GPW, \*GPR, \*GPE, "$gnuplot") or die "no gnuplot";
print GPW "set terminal postscript 'Consola' 12\n";
print GPW "NODE = '$node'\n";
print GPW "BOX = '$box'\n";
print GPW "METRIC = '$metric'\n";
print GPW "DATA_FILE = '$filename'\n";
print GPW "OUT_FILE = '$plot_file'\n";
print GPW "set size 1.0,0.5\n";
print GPW "set title BOX.' - '.NODE.' - '.METRIC\n";
print GPW "set output OUT_FILE\n";
print GPW "plot DATA_FILE using 1:2 with lines notitle\n";
my $skip;
while (<GPE>) {
if (/Warning/) {
system ("rm $plot_file");
$skip = 1;
last;
}
}
if (not $skip) {
system ("epstopdf $plot_file");
}
}
}
}