#! /bin/sh

# Batch pour analyse des images de mires

usage="mire [-s(kip sextractor)] nom.fits reperes.txt timing.txt"

skip_sextractor=false;
while getopts s flag ; do
    case $flag in
	s) skip_sextractor=true;;
	\?) echo $usage; exit 1;;
    esac
done
shift `expr "$OPTIND" - 1`


echo "********** Image : $1 ****"

PATH_TO_MIRE="/home/meynadie/svn/mire"

CATALOG=$(basename $1 .fits).cat
OUTPUT_FITS=$(basename $1 .fits)_sf.fits
OUTPUT_RING=$(basename $1 .fits).ring
OUTPUT_SQUARE=$(basename $1 .fits).square

if test $skip_sextractor == false
then
    rm -f $CATALOG mire.param
    echo "Détection d'objets..."
    cp -f $PATH_TO_MIRE/mire.param .
    sex -c $PATH_TO_MIRE/mire.sex $1
    mv test.cat $CATALOG
fi

echo "Mesures géométriques..."
OUTPUT_FILENAME=$(basename $1 .fits).mes
python $PATH_TO_MIRE/process.py -c $CATALOG -r $2 -o $OUTPUT_FITS -m $OUTPUT_FILENAME -t $3 --ring $OUTPUT_RING -s $OUTPUT_SQUARE





exit 0