#!/usr/bin/env bash

OUTPUT=$2
TERM=$6
TITLE=$3
XRANGE=$4
YRANGE=$5
TEST_RATE=$1

NEXT_COL="red"

function change_col {

	if [ $NEXT_COL = "yellow" ]
	then
		NEXT_COL="red"
	fi

	if [ $NEXT_COL = "blue" ]
	then
		NEXT_COL="yellow"
	fi

	if [ $NEXT_COL = "green" ]
	then
		NEXT_COL="blue"
	fi

	if [ $NEXT_COL = "red" ]
	then
		NEXT_COL="green"
	fi
}

echo "set term $TERM"
echo "set output '$OUTPUT'"
echo "set grid"

echo "set ylabel 'Coverage (\\%)'"
echo "set xlabel ''"
#echo "set xrange [0:100]"
echo "set yrange [0:100]"
echo "set title '$TITLE'"

echo "set multiplot"

echo "set size 1, 0.625"
echo "set origin 0.0,0.325"

for COVERAGE_TYPE in ${@:7}
do
	echo "plot'$COVERAGE_TYPE' w lines lw 2.5 lc '$NEXT_COL' title ''"
	change_col
done

echo "unset yrange"
echo "set size 1, 0.375"
echo "set origin 0.0,0.0"

echo "set title ''"

echo "set yrange [:${YRANGE}]"
echo "set ylabel 'Test / s'"
echo "set xlabel 'Time (s)'"
echo "plot '$TEST_RATE' w fillsteps fs solid 0.3 noborder lt 1 title '', '$TEST_RATE' with steps lt 1 lw 1 title ''"
echo "unset multiplot"

echo "exit"
