#!/bin/sh

case $# in 
3) ;;
*) echo 'Usage: times2gif filename1 filename2 matrixBit > outputfile' 1>&2;
    exit 1;;
esac

tmpfile=/tmp/algs2gif_tmp_$$
tmpfileE=${tmpfile}a
tmpfileC=${tmpfile}b
tmpfileM=${tmpfile}c
tmpfilet=${tmpfile}d
tmpfilew=${tmpfile}e
tmpfilex=${tmpfile}f
tmpfiley=${tmpfile}g
instance1=`/bin/basename $1 .d`
instance2=`/bin/basename $2 .d`

./algcomp2 "$1" "$2" "$3" | /bin/awk '
NF!=4{next}
/^E/{print $0 > "'"$tmpfileE"'";next;}
/^C/{print $0 > "'"$tmpfileC"'";next;}
/^M/{print $0 > "'"$tmpfileM"'";next;}
/^[a-z]/{print $0 > "'"$tmpfilet"'";next;}
END{print "" > "'"$tmpfileE"'";
    print "" > "'"$tmpfileC"'";
    print "" > "'"$tmpfileM"'";
    print "" > "'"$tmpfilet"'";}'

gnuplot << _eof_ | ppmtogif 2>/dev/null
set term pbm medium color
set size 1.2,1.2
set key below
set title '($instance1)/($instance2)'
set ylabel 'Ratio of Normalized Running Times'
set xlabel 'Number of Cities'
set logscale x
set xrange [800:15000000]
set format y '%7.1f'
set label "<1 $instance1 faster    >1 $instance2 faster" at screen 0.08,0.67 center rotate
set lmargin 11
plot '$tmpfileE' using 2:4 title 'Uniform Points' lt 1 pt 1, '$tmpfileC' using 2:4 title 'Clustered Points' lt 4 pt 2, '$tmpfilet' using 2:4 title 'TSPLIB Instances' lt 3 pt 4, '$tmpfileM' using 2:4 title 'Random Matrices' lt 7 pt 3, 1 notitle with lines lt -1 lw 0
quit
_eof_
/bin/rm $tmpfileE $tmpfileC $tmpfileM $tmpfilet
exit
