Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot, how to *skip* missing data files?

Tags:

gnuplot

Depending on various factors i may not have 1 or more data files, referenced in pre-defined gnuplot plot instructions, that don't exist. When this is the case i get "warning: Skipping unreadable file" which cancels the rest of the instructions.

Is there any way i can ask gnuplot to skip any missing data files and plot all of the existing ones?

like image 762
lourencoj Avatar asked Jul 23 '12 10:07

lourencoj


Video Answer


2 Answers

Here is a similar solution without a helper script

file_exists(file) = system("[ -f '".file."' ] && echo '1' || echo '0'") + 0
if ( file_exists("mydatafile") ) plot "mydatafile" u 1:2 ...

the + 0 part is to convert the result from string to integer, in this way you can also use the negation

if ( ! file_exists("mydatafile") ) print "mydatafile not found."
like image 85
boclodoa Avatar answered Nov 08 '22 13:11

boclodoa


Unfortunately, I can't seem to figure out how to do this without a simple helper script. Here's my solution with the "helper":

#!/bin/bash
#script ismissing.sh.  prints 1 if the file is missing, 0 if it exists.
test -e $1
echo $?

Now, make it executable:

chmod +x ismissing.sh

Now in your gnuplot script, you can create a simple function:

is_missing(x)=system("/path/to/ismissing.sh ".x)

and then you guard your plot commands as follows:

if (! is_missing("mydatafile") ) plot "mydatafile" u 1:2 ...

EDIT

It appears that gnuplot isn't choking because your file is missing -- The actual problem arises when gnuplot tries to set the range for the plot from the missing data (I assume you're autoscaling the axis ranges). Another solution is to explicitly set the axis ranges:

set xrange [-10:10]
set yrange [-1:1]
plot "does_not_exist" u 1:2
plot sin(x)  #still plots
like image 30
mgilson Avatar answered Nov 08 '22 13:11

mgilson