I would like to create an array in gnuplot with character indices. I have five data files named a.txt, b.txt, c.txt etc. Each text file has two columns of code profiling data (the function name and the CPU time in seconds):
# f tcpu, s
function1 221.284
function2 161.412
function3 167.322
I would like to plot the normalised profiling data for all the files in a single histogram plot. Prior to normalising the data I have to find the maximum time value in each data file. I do this with gnuplot stats command in a do for loop. I would like to save the maxima in an array tmax. It would be convenient to use the character array indices (tmax['a']), but I cannot find a relevant example anywhere. Please find my minimal example below:
array tmax[5]
# detect and save maxima values
do for [l in "a b c d e"] {
fname = sprintf('%s.txt', l)
stats fname using 2
tmax[l] = STATS_max
}
# print out maxima values
do for [l in "a b c d e"] {
print l
print tmax[l]
}
This attempt fails with the array index out of range error, when I try to save the STATS_max value in tmax[l]. If possible, could you please suggest, how to use character indices in a gnuplot array? The full gnuplot script follows:
#!/usr/bin/gnuplot
set style data histogram
set style fill solid
set style histogram clustered
set xtics rotate by 45 offset 0,0 right
set lmargin 8
set bmargin 11
# border
set style line 11 lc rgb '#808080' lt 1
set border 3 back ls 11
set tics nomirror
# grid
set style line 12 lc rgb '#808080' lt 0 lw 1
set grid back ls 12
set terminal postscript eps size 3.5,2.62 enhanced color \
font 'Helvetica, 10' linewidth 1
set output 'advisor.eps'
set xlabel 'C++ function'
set ylabel 't_{cpu} norm, %'
array tmax[5]
# detect and save maxima values
do for [l in "a b c d e"] {
fname = sprintf('%s.txt', l)
stats fname using 2
tmax[l] = STATS_max
}
# print out maxima values
do for [l in "a b c d e"] {
print l
print tmax[l]
}
plot "a.txt" using ($2/tmax['a']):xtic(1) title 'p=1, t=1', \
"b.txt" using ($2/tmax['b']) title 'p=1, t=8', \
"c.txt" using ($2/tmax['c']) title 'p=8, t=1', \
"d.txt" using ($2/tmax['d']) title 'p=4, t=2', \
"e.txt" using ($2/tmax['e']) title 'p=2, t=4'
Example data file is:
# f tcpu, s
NUTS\\_prop 221.284
Grow\\_tree 161.412
Grow\\_branch 167.322
stan\\_gradient 160.204
log\\_prob\\_grad 160.034
leapfrog\\_integrator 128.392
log\\_prob 116.953
poisson\\_log\\_log 80.262
poisson\\_log\\_lpmf 80.252
add 77.031
