#!/bin/csh -f
#
# mean-max-table -   make a latex table with geometric mean and maxima
#   used in TOCS paper
#
#  must be run after 'get-TOCS-data'
#
# 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

source environset

set contig=TOCS-data.contig
set rsectors=TOCS-data.rsectors

if (! -f $contig || ! -f $rsectors)  then
    echo need to have both files $contig and  $rsectors
    echo be sure to run get-TOCS-data
    exit 1
endif

set tmp=/tmp/mmtable$$
set ddio=$tmp.ddio
set twop=$tmp.twop

# first, compute DDIO/TC ratios and gather in one file
awk 'NF>0' $contig   | dm x2/x4 > $ddio
awk 'NF>0' $contig   | dm x5/x7 >> $ddio
awk 'NF>0' $rsectors | dm x2/x5 >> $ddio
awk 'NF>0' $rsectors | dm x6/x9 >> $ddio
# don't consider DDIO without presort
# awk 'NF>0' $rsectors | dm x3/x5 >> $ddio  
# awk 'NF>0' $rsectors | dm x7/x9 >> $ddio  

# then, compute 2PIO/TC ratios and gather in one file
awk 'NF>0' $contig   | dm x3/x4 > $twop
awk 'NF>0' $contig   | dm x6/x7 >> $twop
awk 'NF>0' $rsectors | dm x4/x5 >> $twop
awk 'NF>0' $rsectors | dm x8/x9 >> $twop

# compute geometric means
set ddiogmean=`avg g < $ddio | awk '{printf "%.2f", $1}'`
set twopgmean=`avg g < $twop | awk '{printf "%.2f", $1}'`

# compute minima  and maxima
set ddiorange=`stats min max < $ddio | awk '{printf "%.2f %.2f", $1, $2}'`
set twoprange=`stats min max < $twop | awk '{printf "%.2f %.2f", $1, $2}'`

# now output the table to table.tex
cat > table.tex <<EOF
\begin{tabular}{l|ccc}
 Method & minimum & geometric mean & maximum \\\\  \hline
 DDIO & $ddiorange[1] & $ddiogmean & $ddiorange[2] \\\\
 2PIO & $twoprange[1] & $twopgmean & $twoprange[2] \\\\ 
\end{tabular}
EOF

cp table.tex table/mean-max.tex
echo output is in table.tex  and table/mean-max.tex
