#! /bin/bash 
#
# PURPOSE: Run the QNX simulator from Matlab. This is the companion script to
#          qnx.m The mission file name is the first argument, followed by the
#          configuration directory.  An optional third argument turns on TRN.
#
# AUTHORS: 1. Rob McEwen, 2015/April/14. Initial.
#          2. Rob McEwen, 2016/Feb/11. Moved the recognition logic and
#                         configuration file copies into qnx.m
# 
#missionList="SimWCakeSimple.cfg Flat4c.cfg PortOALow2.cfg"
#echo "QNX bash script executing."
#cd $AUV/../offboard
#pwd
#missionList=`cat missionList.txt`
#
# if [ $# -ne 1 ]
# then
#     echo " "
#     echo " Please provide a mission file including the .cfg suffix."
#     echo " Pre-setup missions are:"
#     for mission in $missionList
#     do
# 	echo "    $mission"
#     done
#     echo " "
#     exit -1
# fi
#missionList=$*;
#missionList="${@:2}"
#echo $missionList
#recognized=false
#
cd $AUV/missions
pwd
#
if [ -a "$1" ] 
then
    echo " "
    if [ -n $2 ]
    then
	echo "QNX:  Starting the simulation in 2 seconds with option $2."
    else
	echo "QNX:  Starting the simulation in 2 seconds:"
    fi
    echo " "
    sleep 2
    cd $AUV/bin
    #../../offboard memscript &
    #supervisor -fastsim -plan $1 > /dev/null >& /dev/null
    supervisor -fastsim -plan $1 $2 -abort abortSimPlan.cfg
    ls -l $AUV_LOG_DIR/latest
else
    echo "Can't find $1"
    exit -1
fi
