#!/bin/sh

LIBS=shared

if [ $# -lt 3 ] ; then
  echo "usage: $0 <problem_name> <exe_dir> <lib_dir>  [static]           "
  echo "where:                                                           "
  echo " <problem_name> is from:                                         "
  echo "   sntoy     snmain    snmainm npmain                            "
  echo "   t1diet    t2banana  t3qp    t4manne t5weapon t6wood t7etamacro"
  echo "   spring    springi   maxi                                      "
  echo "   hs118     slmain    sqmain  sample                            "
  echo "   slmainMPS sqmainMPS                                           "
  echo " <exe_dir>  is the path to the executables                       "
  echo " <lib_dir>  is the path to the libraries                         "
  echo " By default, all problems are run using  shared object libraries."
  echo "             The argument "static" gives static object libraries."
  exit 1 
fi

CURDIR=$PWD
PROBLEM=$1
EXEDIR=$2
LIBDIR=$3
LIBTYP=$4

if [ "$LIBTYP" = "" ]; then
   LIBTYP=$LIBS
fi

case $LIBTYP in
*static*)   PROBEXE=${PROBLEM}_a  ;;
*shared*)   PROBEXE=${PROBLEM}    ;;
esac

if test ! -f  $EXEDIR/$PROBEXE
then
   echo "Error: \"$PROBEXE\" is an unrecognized problem."
   exit 1
fi

echo "                                "
echo "Running executable: \"$PROBEXE\""
echo "                                "

LD_LIBRARY_PATH=$LIBDIR:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
echo   LD_LIBRARY_PATH=$LD_LIBRARY_PATH

#
# Copy data files into the executable directory
#

if test -f  $PROBLEM.spc
then
   \cp $PROBLEM.spc $EXEDIR/
fi

if test -f  $PROBLEM.mps
then
   \cp $PROBLEM.mps $EXEDIR/
fi

#
# Execute the example
#

cd $EXEDIR
./$PROBEXE
cp -f $PROBLEM.out $CURDIR/

