#!/bin/csh -f
#
# improve - compute the improvement ratio for a set of files
# 	This takes a set of *avg files, either general.nosort
# or general.sort, finds the corresponding *.data files, and the
# corresponding cache.nosort *.data files (if any), and 
# computes improvement ratio (througputs DDIO/TC).  It creates a *.imp
# file for each *.avg file, containing only three numbers, the
# average, stddev, and cv, of the ratios across all corresponding *.data.
# If either in a pair of *.data files is missing, that trial is left
# out of the average ratio; if all are missing, no .imp file is created.
# 
# It also creates a .thruput file
#
set usage='usage: improve [foo.avg]...'
#
# Part of
#              The STARFISH Parallel file-system simulator
#        (Simulation Tool for Advanced Research in File Systems)
# 
#                               David Kotz
#                           Dartmouth College
#                              Version 3.0
#                              October 1996
#                          dfk@cs.dartmouth.edu

if ($#argv == 0) then
	echo "$usage"
	exit 1
endif

set tmp=/tmp/improve$$

onintr cleanup

# columns in .thruput file: general cache general/cache
# columns in .imp file, all about the ratio general/cache: avg stddev cv

foreach a ($*)
    echo $a
    echo > $tmp
    foreach adata ($a:r.*.data)
    	set bdata=`echo $adata | sed -e 's/general/cache/' -e 's/\.sort/.nosort/'`
    	if (-r $bdata) colex 13 < $adata | abut - $bdata | dm x1 x14 x1/x14 >> $tmp
    end
    if (`wc -l < $tmp` == 0) then 
    	echo no matching trials for $a
    	rm -f  $a:r.imp $a:r.thruput
    else
        colex 3 < $tmp | avg asc > $a:r.imp
    	mv $tmp $a:r.thruput
    endif
end

cleanup:
rm -f $tmp
