#!/bin/csh -f

# svn/cvs: $Id: plain 108 2006-08-15 00:01:04Z lou $

# Simple csh script to run the osi_dylp main program. Mainly to make it a bit
# easier to find MPS files and get the parameters right. Also, the script
# will look for a dylp options (.spc) file and add it to the osi_dylp command
# line.

# Edit here to choose the C interface (osi_dylp) or the OSI interface
# (odsi+dylp) as the default.

#set wrapper = (./osi_dylp)
set wrapper = (./odsi+dylp)

# Usage message

set usage =  "plain [-odsi|-dylp] [additional parameters] <mps file>"
set usage1 = "  Where -odsi selects the odsi+dylp (OsiDylp/C++) wrapper"
set usage2 = "        -dylp selects the osi_dylp (native/C) wrapper"
set usage3 = "        and [additional parameters] should be appropriate"
set usage4 = "        for the specified wrapper."
set usage5 = "        The default wrapper is $wrapper[1]"

if ($#argv < 1) then
  set argv = "--help"
endif

# See if the user has specified a front-end on the command line.

switch ($argv[1])
  case -odsi:
    set wrapper = "./odsi+dylp"
    shift
    breaksw
  case -dylp:
    set wrapper = "./osi_dylp"
    shift
    breaksw
endsw

set netlib = "../../Data/Netlib"

# MPS file should be the last parameter

set example = $argv[$#argv]

# Search the current directory for example or example.mps, $netlib for
# example.gz, example.mps.gz

if (-e ${example}) then
  set mpsfile = ${example}
else if (-e ${example}.mps) then
  set mpsfile = ${example}.mps
else if (-e ${netlib}/${example}.gz) then
  gunzip -c ${netlib}/${example}.gz > ${example}
  set mpsfile = ${example}
else if (-e ${netlib}/${example}.mps.gz) then
  gunzip -c ${netlib}/${example}.mps.gz > ${example}.mps
  set mpsfile = ${example}.mps
else
 if ("${example}" != "--help") echo "Can't locate mps file for $example."
 echo "Usage: $usage"
 echo $usage1:q
 echo $usage2:q
 echo $usage3:q
 echo $usage4:q
 echo $usage5:q
 exit
endif

# Check for example.spc in current directory and $netlib

if (-e ${example}.spc) then
  set spcfile = "-o ${example}.spc"
else if (-e ${netlib}/${example}.spc) then
  set spcfile = "-o ${netlib}/${example}.spc"
else if (-e generic.spc) then
  set spcfile = "-o generic.spc"
else
  set spcfile
endif

# If there are two or more arguments, the rest are assumed to be
# command line parameters. In the absence of user preferences, set "-t"
# for terse output.

if ($#argv > 1) then
  @ flagcnt = $#argv - 1
  set flags = "$argv[1-$flagcnt]"
else
  set flags = "-t"
endif

# Go to it.

echo -n "Processing $mpsfile"
if ("$spcfile" != "") then
  echo -n ", spc = $spcfile"
endif
if ("$flags" != "") then
  echo -n ", flags = $flags"
endif
echo "."

$wrapper $spcfile \
      -m ${mpsfile} -L ${example}.log \
      -O ${example}.out $flags

