#!/bin/bash
MY_PATH="`dirname \"$0\"`"              # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`"  # absolutized and normalized
if [ -z "$MY_PATH" ] ; then
  # error; for some reason, the path is not accessible
  # to the script (e.g. permissions re-evaled after suid)
  exit 1  # fail
fi

function usage {
 echo "Usage : `basename ${0}` -exec executable -i geometry -size X.YYY"
 echo " call executable for mesh geometryX.YYY.msh"
 exit 0
}

if [[ $# -eq 0 ]] ; then
usage
fi

while [[ $# -gt 0 ]] && [[ ."$1" = .-* ]] ;
do
    opt="$1";
    shift;              #expose next argument
    case "$opt" in
        "-exec" )
           EXFILE=${1}; shift;;
        "-exec="* )     # alternate format: -i=argdat
           EXFILE="${opt#*=}" ;;
        "-i" )
           FILE=${1}; shift;;
        "-i="* )     # alternate format: -i=argdat
           FILE="${opt#*=}" ;;  
        "-size" )
           SIZE="$1"; shift;;
        "-size="* )
           SIZE="${opt#*=}";;
        *) echo >&2 "Invalid option: $@"; exit 1;;
   esac
done

${EXFILE} ${FILE}${SIZE}.msh ${SIZE}
