#!/usr/bin/env tcsh 
# Copyright 2005, 2006 University of Leiden.
#
# This file is part of MIA+EWS.
#
# MIA+EWS 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.
#
# MIA+EWS 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.
#
# You should have received a copy of the GNU General Public License
# along with MIA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#!/usr/bin/env tcsh 
#   Usage:
#   dispSearch inputFiles (blank separated list) maskFile  outputBaseName [fringeSmooth] [delaySmooth] maxopd
#
#set defaults
set fringesmooth = 50
set delaysmooth  = 2
set remAve = ""

#
if ( $# < 3 ) then
   echo "   dispVis needs at least 3 input parameters "
   exit 1
endif
#
#override defaults if given
#
if ($# >= 4 ) set fringesmooth = $4
if ($# >= 5 ) set delaysmooth  = $5
if ($# >= 6 ) set remAve  = "-removeAverage"
if ($# >= 7 ) set maxopd  = "-maxopd $7"
echo $maxopd
#
echo "compressing raw data"
$vltiCbin/oir1dCompressData "$1" $2 $3.compressed.fits 
if (0 == $status) then
  echo "compression complete"
else
   echo "compression failed"
   exit
endif
echo "computing fringes"
$vltiCbin/oirFormFringes $3.compressed.fits $3.fringes.fits -smooth $fringesmooth $remAve
if (0 == $status) then
  echo "fringing complete"
else
   echo "fringing failed"
   exit
endif
echo "removing piezo OPD"
$vltiCbin/oirRotateInsOpd $3.fringes.fits $3.insopd.fits
if (0 == $status) then
  echo "insOpd complete"
else
   echo "insOpd failed"
   exit
endif
echo "computing group delay "

set cmd = "$vltiCbin/oirGroupDelay  $3.insopd.fits $3.groupdelay.fits -smooth $delaysmooth -search $maxopd"
echo $cmd
$vltiCbin/oirGroupDelay  $3.insopd.fits $3.groupdelay.fits -smooth $delaysmooth -search $maxopd
if (0 == $status) then
  echo "group delay complete"
else
   echo "group delay failed"
   exit
endif
