#!/bin/csh -f
#
# cvplot - plot the CDF of the coef of variation for a set of data files.
#    The coef of variation is the std.dev. divided by the mean. Here
# the sample is the 5 or so trials for a given experiment. One hopes
# for a low coef of variation.
# 
# usage:
#   cvplot column [-t title] file.data...
# where column is a column number in the data files (eg 3 is total time). 

if ($#argv < 2) then 
    echo 'usage: cvplot column [-t title] file.data...'
    exit 1
endif

set column=$1
shift

if ("$1" == -t) then
    if ($#argv >= 2) then
        set title="$2"
        shift; shift
    else
        echo 'usage: cvplot column [-t title] file.data...'
    	   exit 1
    endif    
else
    set title="Coefficient of variation, column $column"
endif

set list=($*)
if ($#list == 0) then
    echo 'usage: cvplot column [-t title] file.data...'
    exit 1
endif

set tmp=/tmp/cv$$
set data=$tmp.data
set cdf=$tmp.cdf
set plot=$tmp.plot

onintr cleanup

echo>$data

foreach i ($*)
    cols $column < $i | avg c >> $data    
end

cdf $data > $cdf

cat > $plot <<EOF
set title "$title"
set ylabel "CDF"
set xlabel "coefficient of variation"
set nokey
plot "$cdf" w linespoints
EOF

lasergnu -f $plot

cleanup:
    rm -f $tmp.*
