0

I have some data I would like to plot in gnuplot. For being able to plot them I wrote a script called "plot_A.gp". In it I set the axis values, labels and the output terminal.
In order not to have it modificated for every data file, I was wondering if it is possible to make the script able to handle drag and drop-files.

As example script:

set xrange [0 to 100]
set xlabel "x-axis"
set ylabel "y-axis"
set terminal eps
set output %1.pdf
plot %1 using 1:($2*$2) with lines

How can I set %1 to the file name I just dropped onto the script?

arc_lupus
  • 3,942
  • 5
  • 45
  • 81

1 Answers1

1

Please execute the script with call instead of load at the gnuplot prompt. call accepts upto 10 arguments. Before gnuplot 5.0, these arguments are called $0, $1, ..., $9.

In gnuplot 4.6, your script would look like this:

datafile="$0"
outputfile="$0".".pdf"
set xrange [0 to 100]
set xlabel "x-axis"
set ylabel "y-axis"
plot "hello" using 1:($$2*$$2) with lines
set terminal eps
set output outputfile
replot
set terminal wxt
set output

Because $2 refers to the third parameter to the script, to access the second column use $$2 instead. Alternately, you can also use 1:(column(2)*column(2)).

You would call it like this.

gnuplot> call "plot_A.gp" "hello"

This will plot the data in the file "hello" and create a pdf called "hello.pdf". I have also reset the terminal back to wxt, as a best-practice.

From gnuplot 5.0, using $0, $1 etc is deprecated. Instead you should use the special variables ARG0, ARG2, ..., ARG9. I don't have access to gnuplot 5.0. But I think you just need to use ARG0 instead of $0. Please you could refer to this answer to How to pass command line argument to gnuplot?

Community
  • 1
  • 1
Gautham
  • 41
  • 3