#!/bin/csh -f
#
# dobar-all - do a bar plot of general-vs-cache for the given 
#   set of patterns and configs
#
set usage='usage: dobar-all [-t title] [-rw] patfile Nio Ncomp type config...'
# where type is data, imp, avg, or avgimp
# where -rw, if present, means that the pattern file contains only
# read patterns, and that for each we should look for the
# corresponding write pattern to include on the same graph
#
# 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

# extract optional -rw
unset rw
if ($#argv > 0 && "opt$1" == opt-rw) then
	set rw
	shift
endif

# extract optional title
unset title
if ($#argv > 0 && "opt$1" == opt-t) then
    if ($#argv > 1) then
    	   set title="$2"
           shift; shift
    else
	echo "$usage"
	exit 1
    endif
else
    if ($#argv == 0) then
	echo "$usage"
	exit 1
    endif
endif

# extract optional -rw
if ($#argv > 0 && "opt$1" == opt-rw) then
	set rw
	shift
endif

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

set patfile="$1"
set Nio="$2"
set Ncomp="$3"
set type="$4"
set dirs=($argv[5-])

if (! -f "$patfile") then
    echo Can not access pattern file "$patfile"
    exit 1
endif

foreach pat (`cat $patfile`)
    set files=()

    set wpat=`echo $pat | sed 's/wr/ww/'`
    if ($?rw) then
	set pats =(patterns $pat $wpat)
    else
	set pats =(pattern $pat)
    endif

    set nonomatch
    foreach dir ($dirs)
	set f=($dir/results/$pat.$Nio.$Ncomp*.$type)
	# test for No Match
	if ("$f" != "$dir/results/$pat.$Nio.$Ncomp*.$type") then
		set files=($files $f)
	endif

	if (! $?rw) continue

	set f=($dir/results/$wpat.$Nio.$Ncomp*.$type)
	# test for No Match
	if ("$f" != "$dir/results/$wpat.$Nio.$Ncomp*.$type") then
		set files=($files $f)
	endif
    end
    set nomatch
    if ($?title) then
	dobar-one -t "$title, $type for $pats" $files
    else
	dobar-one -t "Bar plot of $type for $pats" $files
    endif
end
