#!/bin/bash
EPS=${1/.bufdat/.eps}
[ -n "$1" -a -n "$2" -a "$2" != "$1" ] && EPS="$2"

if [ "$EPS" = "$1" ]
then
	echo "Usage: $0 file.bufdat [output.eps]"
	exit 1
fi

(cat << EOF
set terminal postscript eps enhanced color solid
set xlabel "Mcy"
set key top left
plot "$1" using (\$2/1000000):(\$1) title "probes" with lines lt 7,\
     "$1" using (\$2/1000000):(\$4) title "synchronizations" with points pt 5,\
     "$1" using (\$2/1000000):(\$3) title "writing" with lines lt 3,\
     "$1" using (\$2/1000000):(\$5+\$6) title "written" with lines lt 2,\
     "$1" using (\$2/1000000):(\$5+\$6+\$7) title "available" with lines lt 1,\
     "$1" using (\$2/1000000):(\$7) title "pages" with lines lt 6
EOF
) | gnuplot > $EPS
