#!/bin/bash
# Time-stamp: <22 Jul 2002 at 14:42:31 by charpov on berlioz.cs.unh.edu>

# Draws a curve of "states left in queue" based on output from TLC

if [ "$1" = "-nosafe" ] # skip building file /tmp/5
then shift
else i=5
     echo "$i" > /tmp/5
     while [ $i -lt 50000 ] # 50000 minutes maximum
     do i=$[$i+5]
       echo "$i" >> /tmp/5
     done
fi

if ! fgrep -q Progress "$1.result" # if no "Progress" lines, no curve to draw
then echo Too small to show!
     exit 
fi

sed -n 's/Progress.* \([0-9]*\) states left on queue.*/\1/p' "$1.result" \
  | paste -d" " /tmp/5 - | grep '[0-9] [0-9]' > tlc.dat

gnuplot <<EOF

set title "States in queue"
set data style lines
set xlabel "Minutes"
set key left
set terminal postscript color solid
set output "/tmp/tlc.ps"

plot "tlc.dat" title "$1"

EOF

gv /tmp/tlc.ps

/bin/rm tlc.dat
# files /tmp/5 and /tmp/tlc.ps are left on disk
