#!/bin/csh -f
#
# boxlog - plot a box plot of distribution of a given event's datum
#   (eg idle time) for a set of elogs
#
# usage:
#   boxlog [-t title] eventcode elogfile...
# Finds the distribution of the data for the given event, for each log.
# Computes the box plot for each distribution and plots them all on one plot.
# The box plot shows the min, max, median, and upper/lower quartiles
#  of the distribution. The plots are ordered in the order the files
#  are given. The x axis is the data axis, the y axis is the file# axis.
# Logs are numbered in the order given.
# Uses bin/boxplot

set TMP=/tmp/boxlog$$

onintr cleanup

mkdir $TMP

# extract optional title
if ($1 == -t) then
    shift 
    if ($#argv > 0) then
    	   set title="$1"
    	   shift
    else
    	   echo Usage: '[-t title]'
    endif
endif

if ($#argv < 2) then
	   echo usage: boxlog eventcode elogfile...
	   exit 1
endif

set eventcode=$1
shift

if (! $?title) set title="Box plot of logs, event $eventcode"

set count=0

foreach i ($*)
        @ count = $count + 1
	   elogdump =$eventcode $i:r | cols 4 > $TMP/file$count
	   echo file$count "  " $i >> $TMP/key
end

cd $TMP
boxplot -t $title:q file*
enscript key

cleanup:
rm -rf $TMP
