#!/bin/csh -f
#
# doscatter-big - do a big scatter plot of all
# the basic data files of given fs/sort/layout vs another fs/sort/layout
#
# 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

# I generally use this rather than doscatter-all.

set usage='usage: doscatter-big [-t title] {data|avg} Xfs.sort.layout Yfs.sort.layout'
# where data means to use data files, avg means to use avg files
# where the first one describes the x axis, and the second describes y axis

# extract optional title
if ($#argv > 0 && "$1" == -t) then
    if ($#argv == 5) then
    	   set title="$2"
	   set davg=$3
	   set x=$4
	   set y=$5
    else
	echo "$usage"
	exit 1
    endif
else
    if ($#argv == 3) then
       set davg=$1
       set x=$2
       set y=$3
    else 
	echo "$usage"
	exit 1
    endif
    set title = "Scatter plot of thruput ($davg) for $y vs. $x"
endif

set tmp=/tmp/doscatter-big$$
mkdir $tmp
set xtmp=$tmp/x
set ytmp=$tmp/y
set data=$tmp/data
set names=$tmp/names
set plot=$tmp/plot
set max=$tmp/max
onintr cleanup

foreach rsize (8 8192)
    foreach ydir (configs/$rsize.1280.$y.16)
        foreach rw (r w)
            echo DIRECTORY $ydir, $rw
    	    set xdata=$xtmp.$rw.$rsize
    	    set ydata=$ytmp.$rw.$rsize
    	    echo > $xdata
    	    echo > $ydata
    	    echo > $names

            foreach yfile ($ydir/results/w$rw*.16.16.*$davg)
    	    	if ($yfile =~ *wrlw*) then
    	    	    set scale=`dm x10 < $yfile`	  # Ncomp
    	    	else
    	    	    set scale=1
    	    	endif
                set xfile=`echo $yfile | sed "s/$y/$x/"`
            	if (-r $xfile) then
                    dm x13/1024./$scale < $yfile >> $ydata
                    dm x13/1024./$scale < $xfile >> $xdata
            	else
            	    echo missing $xfile
            	endif

    	    	echo $yfile >> $names
            end

    	    abut $xdata $ydata > $data.$rw.$rsize
    	    abut $xdata $ydata $names > $names.$rw.$rsize
        end
    end
end

rm -f $names

set maxbw = 38.4192    #  72 * 512 / 1024 / 1024 * 16 * 4002 / 60
echo 0 $maxbw > $max
echo $maxbw $maxbw >> $max
echo $maxbw 0 >> $max

echo > $plot
echo set xlabel \"MB/s, $x\" >> $plot
echo set ylabel \"MB/s, $y\" >> $plot
echo set title \"$title\" >> $plot
echo set noclip >> $plot
echo set function style lines >> $plot
echo set data style points >> $plot
echo set time >> $plot
if ($x =~ *contig) then
    echo -n plot x notitle, \"$max\"  title \"Max disk B/W\" w lines >> $plot
else
    echo -n plot x notitle >> $plot
endif

foreach rsize (8 8192)
    foreach rw (r w)
    	echo , \\  >> $plot
    	echo -n \"$data.$rw.$rsize\" title \"$rw $rsize\" >> $plot
    end
end
echo "" >> $plot

lasergnu -f $plot

if (-d doscatter.data) rm -rf doscatter.data
cpdir $tmp doscatter.data

cleanup:
rm -rf $tmp
