0
votes

Situation:

I have a rather complicated yet generic gnuplot script to visualize multiple measurement values. However there still is a vast amount of code duplication for the actual plot commands that I want to avoid.

Minimal example (many variables and options omitted) could be as follows:

#define variables here
folder="folder/"
algo="Version1 Version2"

#label:start
#plot first specific e.g. runtime of a program
set output folder."/Runtime".fileext
plot for[i=1:words(algo)] \
   folder.word(algo,i).".data" using 1:2 .....

#plot antoher specific e.g. Cache Misses
set output folder."/CacheMisses".fileext
plot for[i=1:words(algo)] \
   folder.word(algo,i).".data" using 1:3 .....

#label:end

#change some variables e.g.
algo="Version3 Version4"

#repeat everything between label:start and label:end

In my real script there are about 20 plots in one block (between label:start and label:end) and a high number of blocks (with different variables).

Question:

Is there an easy way to substitute blocks of gnuplot 'code' with a generic or text-replacement method to avoid duplication?

My desired script would look like this:

#define variables here
folder="folder/"
algo="Version1 Version2"

magical_command(...)

#change some variables e.g.
algo="Version3 Version4"

magical_command(...)

I have already found out:

  • the gnuplot macros do not support variadic texts (i.e. varaibles) inside.
  • functions need a plot command; which reduces only parts of the duplication
  • my best guess at the moment would be a call to commandline (e.g. with cmd) to call another gnuplot-script and parameterize the needed variables (Not sure about options though)
1

1 Answers

1
votes

I suppose the easiest would be to call the gnuplot script with some argument:

gnuplot -e "algo='Version1 Version2'" yourgnuplotscript.gp

where yourgnuplotscript.gp contains everything between label:start and label:end.

If you need to call this for many algo variables, you could use a bash script with a for loop that runs over those variables.