#!/bin/csh -f
#
# dotrend-one - do a trend plot for the given set of data files.  
#	Either .avg or .data files can be used.
#	All files should be the same pattern
#
set usage='usage: dotrend-one [-t title] xfield configs/*/results/foo.avg...'
# where xfield is the field number (column) in avg files that
# specifies the independent variable
#
# 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

set P=`runbin`	# where to find awk scripts

# extract optional title
unset title
if ($#argv > 0 && "$1" == -t) then
    if ($#argv > 1) then
    	   set title="$2"
	   set xfield=$3
	   set files=($argv[4-])
    else
	echo "$usage"
	exit 1
    endif
else
    if ($#argv > 0) then
	   set xfield=$1
	   set files=($argv[2-])
    else
	echo "$usage"
	exit 1
    endif
endif

set tmp=/tmp/dotrend
onintr cleanup
mkdir $tmp

if ($?title) then
	echo "set title '$title'" > $tmp/plot
else
	echo > $tmp/plot
endif
echo "set time" >> $tmp/plot

cat $files | dsort 1 7 9 10 11 5 6 3 4 \
	| nawk -f $P/dotrend.awk xfield=$xfield 

lasergnu -f $tmp/plot

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

cleanup:
rm -rf $tmp

