#!/bin/sh

if [ $# -lt 2 ] ; then
  echo "usage: $0 <problem_name> <spc_file>"
  echo "where:                                                          "
  echo " <problem_name> is one of the following:                        "
  echo "   adlittle   pilot4     refinery                               "
  echo " <spc_file> is the options file (e.g., "lp" for lp.spc)         "
  exit 1
fi

CURDIR=$PWD
PROBLEM=$1
SPC=$2

SPC=`basename $SPC .spc`  # Delete the .spc suffix if present

if test ! -f  $PROBLEM.mps
then
   echo "Error: \"$PROBLEM\" is an unrecognized problem."
   echo "Error: No mps file found."
   exit 1
else
   \cp -f  $PROBLEM.mps fort.10
fi

if test ! -f  $SPC.spc
then
   echo "Error: No specs file  $SPC.spc  found for \"$PROBLEM\"."
   exit 2
else
   \cp -f  $SPC.spc     fort.4
fi

# Execute the example
echo "                                     "
echo "Running executable: \"$PWD/$PROBLEM\""
echo "                                     "

../libtool --mode=execute ./lpsolver $PROBLEM

# Clean up

if test -f fort.9
then
   \mv  -f fort.9   $PROBLEM.out
fi

if test -f fort.11
then
   \mv  -f fort.11   $PROBLEM.basis
fi

if test -f fort.12
then
   \mv  -f fort.12   $PROBLEM.newbasis
fi

if test -f fort.4
then
   \rm fort.4
fi

if test -f fort.10
then
   \rm fort.10
fi
