#///////////////////////////////////////////////////////////////////////////////
#  Copyright (c) 2014 Clemson University.
# 
#  This file was originally written by Bradley S. Meyer and Michael J. Bojazi.
# 
#  This is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
# 
#  This software is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
# 
#///////////////////////////////////////////////////////////////////////////////

#///////////////////////////////////////////////////////////////////////////////
#//!
#//! \file Makefile
#//! \brief A short shell script to run an executable multiple times with
#//!        arguments from an input file.
#//!
#///////////////////////////////////////////////////////////////////////////////

#!bin/bash

#///////////////////////////////////////////////////////////////////////////////
# Edit the executable name; that is, replace ./the_executable with
# your desired executable.
#///////////////////////////////////////////////////////////////////////////////

EXECUTABLE=./the_executable

#///////////////////////////////////////////////////////////////////////////////
# Check input.  Note that the input text file should have, for each line,
# a space delimited set of arguments in order.
#///////////////////////////////////////////////////////////////////////////////

if [ $# -eq 1 -a $1 == "--example" ]
  then
    echo -e "\n$0 input.txt\n"
    exit
fi

if [ ! $# -eq 1 ]
  then
    echo -e "\nUsage: $0 file\n"
    echo -e "  file = text file with parameters\n"
    echo -e "For an example, type: $0 --example\n"
    exit
fi

#///////////////////////////////////////////////////////////////////////////////
# Perform loop.  Each line of the input runs the executable with the arguments
# in the input file.
#///////////////////////////////////////////////////////////////////////////////

while read line; do
  eval x=($line)
  $EXECUTABLE "${x[@]}"
done <$1
