In the gnuplot 5.2 manual is well explained that it is possible to use string variables ARG0, ARG1, ..., ARG9 and an integer variable ARGC to pass variables to the scripts. For example if I execute
gnuplot -persist -c "script1.gp" "sin(x)" 1.23 "This is a plot title"
ARG0 holds "script1.gp"
ARG1 holds the string "sin(x)"
ARG2 holds the string "1.23"
ARG3 holds the string "This is a plot title"
ARGC is 3
Is there a way to pass more then 10 arguments to a gnuplot script, please?
Using two files you could use something like this.
In this example, the first script (send.plt
) send the "arguments", as a single string, to second script.
Arg2Sent = "This is a long string send to another script as a single argument"
call "receive.plt" sprintf("%s", Arg2Sent)
The second script (receive.plt
) contain:
array Arg[words(ARG1)]
do for [i=1:|Arg|]{
Arg[i] = word(ARG1, i)
print sprintf("Arg[%2g]: %s", i, Arg[i])
}
The output
Arg[ 1]: This
Arg[ 2]: is
Arg[ 3]: a
Arg[ 4]: long
Arg[ 5]: string
Arg[ 6]: send
Arg[ 7]: to
Arg[ 8]: another
Arg[ 9]: script
Arg[10]: as
Arg[11]: a
Arg[12]: single
Arg[13]: argument
Another example, this time using numbers.
Arg2Sent = "0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765"
call "receive.plt" sprintf("%s", Arg2Sent)
The output
Arg[ 2]: 1
Arg[ 3]: 1
Arg[ 4]: 2
Arg[ 5]: 3
Arg[ 6]: 5
Arg[ 7]: 8
Arg[ 8]: 13
Arg[ 9]: 21
Arg[10]: 34
Arg[11]: 55
Arg[12]: 89
Arg[13]: 144
Arg[14]: 233
Arg[15]: 377
Arg[16]: 610
Arg[17]: 987
Arg[18]: 1597
Arg[19]: 2584
Arg[20]: 4181
Arg[21]: 6765
A long example
Arg2Sent = "'first filename with spaces.txt' \
'second filename with spaces.txt' \
'third filename with spaces.txt' \
'fourth filename with spaces.txt' \
'fifth filename with spaces.txt' \
'sixth filename with spaces.txt' \
'seventh filename with spaces.txt' \
'eighth filename with spaces.txt' \
'ninth filename with spaces.txt' \
'tenth filename with spaces.txt' \
'eleventh filename with spaces.txt' \
'twelfth filename with spaces.txt' \
'thirteenth filename with spaces.txt' \
'fourteenth filename with spaces.txt' \
'fifteenth filename with spaces.txt' \
'sixteenth filename with spaces.txt' \
'seventeenth filename with spaces.txt' \
'eighteenth filename with spaces.txt' \
'nineteenth filename with spaces.txt' \
'twentieth filename with spaces.txt'"
call "receive.plt" sprintf("%s", Arg2Sent)
The output
Arg[ 1]: first filename with spaces.txt
Arg[ 2]: second filename with spaces.txt
Arg[ 3]: third filename with spaces.txt
Arg[ 4]: fourth filename with spaces.txt
Arg[ 5]: fifth filename with spaces.txt
Arg[ 6]: sixth filename with spaces.txt
Arg[ 7]: seventh filename with spaces.txt
Arg[ 8]: eighth filename with spaces.txt
Arg[ 9]: ninth filename with spaces.txt
Arg[10]: tenth filename with spaces.txt
Arg[11]: eleventh filename with spaces.txt
Arg[12]: twelfth filename with spaces.txt
Arg[13]: thirteenth filename with spaces.txt
Arg[14]: fourteenth filename with spaces.txt
Arg[15]: fifteenth filename with spaces.txt
Arg[16]: sixteenth filename with spaces.txt
Arg[17]: seventeenth filename with spaces.txt
Arg[18]: eighteenth filename with spaces.txt
Arg[19]: nineteenth filename with spaces.txt
Arg[20]: twentieth filename with spaces.txt
One last example
Arg2Sent = "data.dat 1 2 'lp pt 6' 'pi -1' blue 'A randon example'"
call "receive.plt" sprintf("%s", Arg2Sent)
The receive.plt
contain
array Arg[words(ARG1)]
do for [i=1:|Arg|]{
Arg[i] = word(ARG1, i)
}
filename = sprintf("%s", Arg[1])
firstcolumn = int(Arg[2])
secondcolumn = int(Arg[3])
plottype = sprintf("%s", Arg[4])
pointstyle = sprintf("%s", Arg[5])
color = sprintf("'%s'", Arg[6])
title = sprintf("%s", Arg[7])
plot filename u firstcolumn:secondcolumn w @plottype @pointstyle lc @color t title
The output