#!/bin/sh

LIBS=shared

if [ $# -lt 2 ] ; then
  echo "usage: $0 <problem_name> [static]                                "
  echo "where:                                                           "
  echo " <problem_name> is from:                                         "
  echo "     brachistochrone   Breakwell   catmix   diplant   rocket  	 "
  echo "     pendulum     vanderpol       vtbrachistochrone              "
  echo " <lib_dir>  is the path to the load 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
LIBDIR=$2
LIBTYP=$3

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

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

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

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

SAVE_PATH=$LD_LIBRARY_PATH
LD_LIBRARY_PATH=$LIBDIR
export LD_LIBRARY_PATH
echo   LD_LIBRARY_PATH=$LD_LIBRARY_PATH

#if test ! -f  $PROBLEM.spc
#then
#   echo "Error: No specs file  $PROBLEM.spc  found for \"$PROBLEM\"."
#   exit 2
#fi

# Execute the example

./$PROBEXE

LD_LIBRARY_PATH=$SAVE_PATH
export LD_LIBRARY_PATH
