#!/bin/csh -f

# gather the data for the LU experiments
#
# Part of
#              The STARFISH Parallel file-system simulator
#        (Simulation Tool for Advanced Research in File Systems)
# 
#                               David Kotz
#                           Dartmouth College
#                              Version 3.0
#                              January 1996
#                          dfk@cs.dartmouth.edu


set output=lu.data

rm -f $output

set metrics=(DISK_LAYOUT LU_SLAB_SIZE BLOCK_SIZE IOPFS total LUbytes diskread diskwrite)

set tmp=/tmp/lu$$
set rawdata=$tmp.raw
set mapdata=$tmp.map
onintr cleanup

echo > $rawdata
foreach i (luconfigs/*)
   # we assume that there is only one trial for each point
   # collect each point as a separate line in the $rawdata file
   foreach sim ($i/results/*.1.sim*)
      echo $sim
      simex -sim $sim -noheader -noname -sum $metrics | transpose >> $rawdata
   end
end

# now each column in $rawdata corresponds to one metric; 
# for each column, map its values to names, if appropriate
set col = 1
echo > $mapdata
set prev=""
while ($col <= $#metrics)
   echo mapping $metrics[$col] "(ignore warning if your sim files are new)"
   colex $col < $rawdata | mapmetric $metrics[$col] | abut $prev - > $tmp
   mv $tmp $mapdata
   @ col = $col + 1
   set prev=$mapdata
end

# prepare for Excel: 
#  rename some of the metric names and strip trailing tab,
#  sort into a nice order,
#  add blank lines at certain key points
sed -e 's/rsectors/random/' -e 's/cache/TC/' -e 's/general/DD/' -e 's/	$//' $mapdata \
 | sort +0 -1 +1n -2 +2n -3 +3 \
 | awk 'NR > 1 && $2 != prev {print ""}\
        {print; prev = $2}' \
 > $output

echo output is in $output and columns are as follows
echo $metrics | colex 1-$#metrics

cleanup:
rm -f $tmp*
