I'm having a hard time getting my gnuplot script to work. Basically, I have six data files and I want to plot them in the same file with a fit for every data set.
It gets a little complicated because I have to reformat the data before plotting. For that I am using stats commands. Here lies the problem. The final plotting command contains a for loop in which the data formatting is done. Each stats command produces statistical data with a prefix Potentiali, where i goes from 1 to 6.
Now my question is, how can I access this running index in the plot loop?
This is my script:
#!/bin/bash
gnuplot << EOF
set terminal epslatex color size 16cm,11cm
set output "strain-energy.tex"
set xrange [-10:10]
set yrange [0:*]
fstr(N) = sprintf('f%d(x) = a%d*x**7 + b%d*x**6 + c%d*x**5 + d%d*x**4 + e%d*x**3 + f%d*x**2 + g%d*x + h%d', N, N, N, N, N, N, N, N, N)
eval(fstr(1))
fitstr(N) = sprintf('set fit quiet; fit [-10:10] f%d(x) ''/path/Shift_%d/potential.dat'' every ::1 using (\$1-Potential%d_pos_min_y):(\$2-Potential%d_min_y) via a%d,b%d,c%d,d%d,e%d,f%d,g%d,h%d', N, N, N, N, N, N, N, N, N, N, N, N)
do for [i=1:6] {
stats "/path/Shift_".i."/potential.dat" every ::1 using (\$1):(\$2) prefix "Potential".i nooutput
eval(fstr(i))
eval(fitstr(i))
}
plot for [i=1:6] "/path/Shift_".i."/potential.dat" every ::1 using (100*((\$1-Potential.i._pos_min_y)/Potential_pos_min_y)):(1000*(\$2-Potential_min_y)) ls i title "\\\footnotesize{C".i."}", f1(x) ls 1, f2(x) ls 2, f3(x) ls 3, f4(x) ls 4, f5(x) ls 5, f6(x) ls 6
set output
EOF
word()function.forloop, copy and paste the relevantstatsline six times and change what you need to, thenplot '/path/Shift_1/potential.dat' .... Keeping the loops would likely require fiddling either withword()as @Miguel mentioned, orevalwhich will lead you down a dark and twisted road...