1

following up from the question on SO about command line parameters to gnuplot scripts, and its corresponding answer, I see that I can make a script myscript.gp like

if(!exist("parameters")) parameters=""
plot "< myprog ".parameters u 1:2

and call it with

$ gnuplot -e "parameters='-m 5'" myscript.gp

However, I could achieve a similar result when running in interactive mode with myscript2.gp as

parameters="$0"
plot "< myprog ".parameters u 1:2

and calling it from the interactive prompt as

gnuplot> call "myscript2.gp" "-m 5"

And now the question. As I see it those two methods are not connected and the $O would fail when when running in batch, whereas the 'parameters' is not updated when using call.

How do I set a script which could be called from the shell command line AS WELL AS from the gnuplot interactive command line? Another way to ask it, is it possible to test in which conditions was the script called?

Thanks,

clem steredenn
  • 352
  • 7
  • 20
  • Regarding the same question you refer, have you tried [this answer](http://stackoverflow.com/a/31815067/2174266)? – vagoberto Sep 30 '15 at 16:31
  • @vagoberto, No I didn't, it wasn't there last time I checked. Plus, I was using the standard version of gnuplot. But it looks like they improved it very well. – clem steredenn Sep 30 '15 at 19:18

1 Answers1

0

Playing around, I found a quite inelegant solution, but that could help to achieve what I want.

parameters=""                                  # sets default value
if ("$#" eq sprintf("%d",1)) parameters="$0"   # if using call with 1 parameter: $#=1
if (exist("bpar")) parameters=bpar             # checking for batch call

plot "< myprog ".parameters u 1:2

which can then be called by either

$ gnuplot -e "bpar='-m 5'" myscript.gp

or

gnuplot> call "myscript2.gp" "-m 5"
clem steredenn
  • 352
  • 7
  • 20
  • Please note that this only work when the interactive call is made with one and only one argument. It should probably be included in a loop (but a basic do for [] {} complained about 'Old style if') or the different values ORed together. But I have no time now to look further. – clem steredenn Mar 06 '15 at 13:29