#! /bin/sh
#
# Run the tests for the circulate test
#
#MACH=anlsp2
MACH=`uname -s`
Show=eval
OPT="-O"
donopoll=1
do_html=0
#PATH=/usr/local/mpi/lib/rs6000/ch_mpl:$PATH
#PATH=/home/MPI/mpich/lib/rs6000/ch_mpl:$PATH
#export PATH
do_base=0
do_log=0
do_update=0
mpirunargs=""
#
for arg in "$@" ; do
    case $arg in 
	-echo) set -x ;;
	-base) do_base=1 ;;
	-show) Show=echo ;;
        -logs) do_log=1 ;;
	-nopoll) mpirunargs="-nopoll" ;;
	-html) do_html=1 ;;
	-update) do_update=1 ;;
	-mach=*) MACH=`echo a$arg | sed "s/a-mach=//"` ;;
        *) echo "Unrecognized argument $arg" ; exit 1 ;;
    esac
done
#
if [ $do_base = 1 ] ; then 
    if [ -s related.lst ] ; then 
	dirs=". `cat related.lst`"
    else
	dirs="."
    fi
    curdir=`pwd`
    for dir in $dirs ; do
	if [ $do_log = 1 ] ; then
	    cd $dir
	    if [ $do_html = 1 ] ; then 
	        echo "<H2>`cat title.txt`</H2>"
	        echo "<PRE>"
	    else 
	        cat title.txt
	    fi
	    $Show make circulate.log
	    if [ $do_update = 0 -o ! -s circulate.$MACH-20000.alog ] ; then
	        $Show mpirun $mpirunargs -np 4 -mvhome -mvback circulate.log_profile.log circulate.log
	        $Show /bin/mv circulate.log_profile.log circulate.$MACH-20000.alog
	    fi
	    if [ $do_update = 0 -o ! -s circulate.$MACH-500.alog ] ; then 
	        $Show mpirun $mpirunargs -np 4 -mvhome -mvback circulate.log_profile.log circulate.log -n 500 -m 500
	        $Show /bin/mv circulate.log_profile.log circulate.$MACH-500.alog
	    fi
	    if [ $do_html = 1 ] ; then 
	        echo "</PRE>"
		echo "<UL>"
		echo "<LI> <A HREF="'"'"circulate/C/circulate.$MACH-20000.alog"'"'">Logs for circulate -n 20000 -m 20000</A>"
		echo "<LI> <A HREF="'"'"circulate/C/circulate.$MACH-500.alog"'"'">Logs for circulate -n 500 -m 500</A>"
		echo "</UL>"
	    fi
	    cd $cur_dir
        else
	    cd $dir
	    if [ $do_html = 1 ] ; then
	        echo "<H2>`cat title.txt`</H2>"
	        echo "<PRE>"
	    else 
		cat title.txt
	    fi
	    $Show make circulate
	    $Show mpirun $mpirunargs -np 4 -mvhome circulate
	    $Show mpirun $mpirunargs -np 4 -mvhome circulate -n 500 -m 500
	    cd $cur_dir
	    if [ $do_html = 1 ] ; then
	        echo "</PRE>"
	    fi
	fi
    done
    exit 0
fi
