#! /bin/sh
#
# This is a simple install test for MPICH.  This assumes that a successful
# build of MPICH has taken place
#
installloc=$HOME/mpitmp
nox=0
for arg in "$@" ; do
    case $arg in 
	-echo) set -x ;;
	
	-prefix=*)
	installloc=`echo A$arg | sed -e 's/A-prefix=//g'`
	;;

	-nox) nox=1 ;;
	-help|-u|-usage)
	echo "insttest [ -prefix=directory ] [ -nox ]"
	echo "Install and perform basic test on MPICH installation"
	echo "Note: this must not run as batch, as it tries to start up"
	echo "the nupshot and upshot programs."
	echo " "
	echo "Set -nox if nupshot/upshot are not to be tested."
	exit 1
	;;

	*)
	echo "Unknown argument ($arg)"
	exit 1
	;;
    esac
done
# Check that DISPLAY is valid first
if [ $nox = 0 -a -z "$DISPLAY" ] ; then 
    echo "Need to set DISPLAY before testing upshot/nupshot"
fi
#
make install PREFIX=$installloc
if [ $? != 0 ] ; then
    echo "Error in installation"
    exit 1
fi
cd $installloc
cd examples
make cpi
mpirun -np 2 cpi
../bin/mpicc -mpilog -o cpilog cpi.c -lm
mpirun -np 4 cpilog
if [ -x ../bin/nupshot ] ; then 
    ../bin/nupshot cpilog_profile.log
else
    echo "Nupshot not available!"
fi
if [ -x ../bin/upshot ] ; then
    ../bin/upshot  cpilog_profile.log
else 
    echo "Upshot not available!"
fi
make clean
exit 0
