#!/bin/sh

#/* Author      : Rick van der Zwet
# * S-number    : 0433373
# * Version     : $Id: memory.h 363 2007-12-03 06:07:31Z rick $
# * Copyright   : FreeBSD Licence
# * Description : Generate results of 15 combinations
# */

DATAFILE=${1:-./data/lisp.002.din}
DINERO='./data/dinero'
BUS2='./grep-bus2'
COMPU='./compu'
RESULT_PRE="./res-"
RESULT_SUFFIX=".txt"
RESULT_BUS2="./bus2-"
MEM_SETTINGS="1 2 3 4 5"
CACHE_SETTINGS="a b c"

DINERO_ARGS_a="-b1 -u1"
DINERO_ARGS_b="-b128 -a1 -ww -An -u64k"
DINERO_ARGS_c="-b128 -a1 -wc -Aw -u64k"

if [ ! -x $DINERO ]; then
    echo "$DINERO binary not found" 1>&2
    echo "Please alter $0 to specifify right constants" 1>&2
    exit 128;
fi

if [ ! -r $DATAFILE ]; then
    echo "$DATAFILE file not found" 1>&2
    echo "Please alter $0 to specifify right constants or" 1>&2
    echo "Usage $0 <datafile>" 1>&2
    exit 128;
fi

echo "Using datafile $DATAFILE" 1>&2
for mem_setting in $MEM_SETTINGS
do
    for cache_setting in $CACHE_SETTINGS
    do
        (
        eval DINERO_ARGS=\$DINERO_ARGS_$cache_setting
        echo "==============================================="
        echo "Generated       : `date`"
        echo "Input data     : $DATAFILE"
        echo "Memory setting : $mem_setting"
        echo "Cache setting  : $cache_setting"
        echo "Dinero args    : $DINERO_ARGS"
        cat $DATAFILE | $DINERO -o2 $DINERO_ARGS |\
        $BUS2 |\
        tee -i $RESULT_BUS2$mem_setting$cache_setting$RESULT_SUFFIX |\
        $COMPU $mem_setting
        echo "==============================================="
        ) | tee -i $RESULT_PRE$mem_setting$cache_setting$RESULT_SUFFIX 1>&2
    done
done

