#!/bin/csh -f
#
# average-one - average all trials of an experiment into a *.avg file
#  (or average multiple *.imp files into a *.avgimp file)
#
set usage='usage: average-one avgfile datafile...'
#
# 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 < 2) then
	echo "$usage"
	exit 1
endif

set avg=$1
set data=($argv[2-])
set tmp=/tmp/avg$$

onintr cleanup

# collect the data, pull out total and tthruput column, 
# computes (average, stddev, coeff of variation), 
# abut it with trial-1 data file, 
# then cut the (total, tthruput, trial)
# and include the average-total, average-tthruput, stddev-thruput,
# and compute cv-thruput
# this way, avg-total is in x12, and avg-tthruput is in x13

colex 1-11 < $data[1] > $tmp
cat $data | colex 12 13 | avg as | abut $tmp - \
	| dm x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x14 x15 x15/x14 \
	> $avg

cleanup:
rm -f $tmp
