#!/bin/sh
# $Id$

CYCLE=1
while [ $CYCLE = 1 ]
do
    case $1 in
    --help)
	echo "Usage: mpirun [OPTION]... [command [arg ...]]"
	echo "-np 1           run the command with one processor (default)"
	echo "--help          display this help and exit"
	echo "-v, --version   output version information and exit"
	exit 0
	;;

    -np)
	if [ $2 != "1" ]; then
	    echo "FAIL:Uniprocessor version of MPI can only use one processor."
	    exit 1
	fi
	shift; shift
	;;

    --version|-v|-V)
	echo "ESMF mpiuni:"
	echo "  revision $Id$"
	exit 0
	;;

    *)
	CYCLE=0;;
    esac
done

if [ $# -gt 0 ]; then
    progname=$1
    shift
    # If the given command isn't in PATH, assume relative path is used, so prepend a ./
    if ! command -v $progname &> /dev/null; then
        progname=`dirname $progname`/`basename $progname`
    fi

    # Execute the program
    $progname $*
    exit $?
fi

exit 0
