#! /bin/sh
# The SPIMS software is covered by a license. The use of the software
# represents acceptance of the terms and conditions in the license.
# ******************************************************************
# Copyright (c) 1989, Swedish Institute of Computer Science
# parameter: <distribution name>(<parameter_list>)
# Note: the paranthesis have to be quoted in the shell
HOST=`hostname`
VERBOSE=0
STARTED=0

cd $SPIMSDIR
if [ $# != 0 ]; then
    if [ $1 = "-v" ]; then
        VERBOSE=1; shift
    fi
fi

if [ $# = 0 ]; then
    echo "Usage example: dist-evaluate 'uniform(1,2)'"
    exit 1
fi
DISTSTRING=$1
if [ $VERBOSE = 1 ]; then
    echo Distribution: $DISTSTRING
fi

#
# Make sure that there are demons running where needed
#
if `null/bench $h <benchmarks/test >/dev/null 2>&1 `; then
    if [ $VERBOSE = 1 ]; then
	echo A demon for the null protocol on $HOST is already running
    fi
else	
    if [ $VERBOSE = 1 ]; then
        echo Starting a demon for the null protocol on $HOST
    fi
    startdemon $HOST null
    STARTED=1
fi

#
# Test that all demons are running
#
if [ $STARTED != 0 ]; then
    if [ $VERBOSE = 1 ]; then
	echo Checking that the demons came alive
    fi
    sleep 10
    if `null/bench $h <benchmarks/test >/dev/null 2>&1 `; then
        echo -n ""
    else
        echo Failed starting a demon on $HOST for the null protocol
        exit 2
    fi
fi
#
# Do the measurements
#	Check the exit value??
#
FILE=tmp.$HOST.null.`date +%T`
sed s/generic/$DISTSTRING/ <benchmarks/dist-evaluate >$FILE
if [ $VERBOSE = 1 ]; then
    echo Measurement specification:
    cat $FILE
fi
echo Measuring - be patient...
null/bench <$FILE 2>&1 | filters/dist-evaluate
rm -f $FILE




