#!/bin/sh
DATE="03/10/1997"
MYCOMMAND=/usr/local/share/vecfem3/vempfade
#**************************************************************************
#**                                                                     ***
#**        Copyrights University of Karlsruhe, 1996                     ***
#**        Program by L. Grosz                                          ***
#**                                                                     ***
#**************************************************************************
echo "VECFEM: starts an executable"
echo "Version: $DATE"
echo "Copyrights by University of Karlsruhe 1996"
#---------------------------------
#
#** find the vecfem variables
#
if [ "$MYCOMMAND" = "" ]; then
  . vempfade
  echo vempfade from `dirname $(which vempfade)`
else
  VEMPATH=`dirname $MYCOMMAND`
  SC=`basename $MYCOMMAND`
  if test -r $VEMPATH/vempfade ; then
     . $VEMPATH/vempfade
     echo vempfade from $VEMPATH
  else
    HELP=`which $SC`
    VEMPATH=`dirname $HELP`
    if test -r $VEMPATH/vempfade ; then
      . $VEMPATH/vempfade
      echo vempfade from $VEMPATH
    else
      . vempfade
      echo vempfade from `dirname $(which vempfade)`
    fi
  fi
fi
#
#---------------------------------
EXT=$$
NPROC=${1:-1}

if [ $# -gt 1 ]
 then
   EXECUTE=$2
   test -r $EXECUTE
   if [ $? -eq 1 ]
     then
     echo ">> executable "$EXECUTE" was not found !" >&2
     echo ">> abend !" >&2
     exit 1
    fi
 else 
   EXECUTE="a.out"
fi

echo "executable : "$EXECUTE
echo "architecture : "$VECFEM_ARCH
echo "number of processors : "$NPROC
echo "options : "$VEMRUN_OPTIONS

case $VECFEM_ARCH in
   AIXSP) poe $EXECUTE -procs $NPROC $VEMRUN_OPTIONS ; RTRNCD=$? ;;
   Paragon) pexec $EXECUTE -sz $NPROC $VEMRUN_OPTIONS ; RTRNCD=$? ;;
   CRAYT3D ) pexec $EXECUTE -sz $NPROC $VEMRUN_OPTIONS ; RTRNCD=$? ;;
   CRAYYMP_MPI | LINUX_MPI) mpirun -np $NPROC $VEMRUN_OPTIONS $EXECUTE ; RTRNCD=$? ;;
   AP1000 ) mpirun -ncells $NPROC -nohostf -packsize 0 $EXECUTE $VEMRUN_OPTIONS; RTRNCD=$? ;;
   *) $EXECUTE $VEMRUN_OPTIONS ; RTRNCD=$? ;;
esac
if [ $RTRNCD -eq 0 ]
 then
   echo "vecfem ended!"
 else
   exit 1
fi
