#!/bin/bash
#set -x

SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

cat >plots.gnu <<EOF

#set datafile separator ";"
set title "$1"
set ylabel "Track"
set xlabel "Time, seconds"
#set xrange [0:10]
#set yrange [0:40]
set ytics nomirror textcolor rgbcolor "red"
#set grid xtics ytics
set size ratio 0.71
set terminal pdf size 26.7cm, 19cm
set output "plot.pdf"
#set terminal x11
#set terminal svg size 1000, 600 dynamic
#set output "plot.svg"
EOF

clock=460850

rm -f ly.dat

$SCRIPT_DIR/plot $1 $clock >plot.out

rm -f ly.dat
if [ -s ly.dat ]
then
cat >>plots.gnu <<EOF
set autoscale y2
set y2label "LY cps"
set y2tics nomirror textcolor rgbcolor "blue"
plot "sk.dat" using 1:2 title "SK" with points, "lk.dat" using 1:2 title "LK" with points, "ly.dat" using 1:2 title "LY" with points axes x1y2
#plot "sk.dat" using 1:2 title "SK" with points, "lk.dat" using 1:2 title "LK" with points
pause -1 "$filename"
EOF
else
cat >>plots.gnu <<EOF
plot "sk.dat" using 1:2 title "SK" with points, "lk.dat" using 1:2 title "LK" with points
pause -1 "$filename"
EOF
fi

gnuplot plots.gnu

#rm -f [ls]k.dat
