#!/bin/bash
#
#    Project: The EDNA Kernel
#             http://www.edna-site.org
#
#    File: "$Id:$"
#
#    Copyright (C) 2008-2009 European Synchrotron Radiation Facility
#                            Grenoble, France
#
#    Principal authors: Marie-Francoise Incardona (incardon@esrf.fr)
#                       Olof Svensson (svensson@esrf.fr) 
#   					Jerome Kieffer (kieffer@esrf.fr)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Lesser General Public License as published
#    by the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program 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 Lesser General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    and the GNU Lesser General Public License  along with this program.  
#    If not, see <http://www.gnu.org/licenses/>.
#
if [ -z $PYTHON ];
then
    echo "Note: If you encounter a python error at this step, "
    echo "      please check that the \$PYTHON environment variable "
    echo "      correspond to the python binary you intent to use."    
    export PYTHON=$(which python)
    echo "\$PYTHON = $PYTHON" 
fi

full_path=$( readlink -fn $0 )
edna_kernel_bin_path=$( dirname "${full_path}" )

NewOpt=""
Profile=0
for i in $*
do
	if [ $i = "--profile" ]
	then
		Profile=1
	else
		NewOpt=$NewOpt" "$i
	fi
	
done
if [ $Profile -eq 1 ]
then 
	echo "Running in Profiling mode"
	${PYTHON} -u  -m cProfile -o profile.log $edna_kernel_bin_path/edna-test-launcher.py --verbose $NewOpt
else
	${PYTHON}  -u $edna_kernel_bin_path/edna-test-launcher.py --verbose $NewOpt
fi

