#!/bin/csh -f
#
# bxy3 x [y] [n=Nim] [laser=0/1]
#
# moves the telescope in a 3-position box pattern, using
# offsets of x arcsec and y arcsec in detector coordinates.
# This is a "bxy4" pattern with the lower left position missing.
# The lower left quadrant of the detector is noisier than the 
# other three.
#
# Pattern is:       2           4
#
#                       start 
#
#                               3
#
# Nim exposures are taken at each dither position.
# (Nim = 1 by default).
# Note that the "n=Nim" argument can be anywhere within the 
# argument list.
#
#-

# Boiler plate for "-h" support for command autohelp.

if ("$1" == "-h") then
    help $0
    exit $status
endif

# Syncheck is not used in the dither scripts because of the more
# complex syntax required.

set deltaX = "none"
set deltaY = "none"
set Nim    = 1
set laser  = -1

while ($#argv)
    set val = "$1"
    if (`echo $val | cut -c1-2` == "n=") then
        set Nexp = `echo $val | cut -c3-`
        # Nexp must be an int >= 1
        if (`isfloat $Nexp`) then
          set Nexp = `round $Nexp`
          if ($Nexp < 1) then
            set Nexp = 1
          endif
        endif

    else if (`echo $val | cut -c1-6` == "laser=") then
        set laser = `echo $val | cut -c7-`
        if (($laser != "0") && ($laser != "1") && ($laser != "-1"))  then
          echo "Unknown laser= argument: $laser"
          echo "Reset to: -1 = Do no harm"
          set laser = -1
        endif

    else
        if (`isfloat $val`) then
            if ("$deltaX" == "none") then
                set deltaX = $val
            else
                set deltaY = $val
            endif
        else
            if (-e $val) then
                set File = "$val"
            else
                echo ""
                echo The specified dither file \"$File\" does not exist.
                echo Please check your current directory and the file name specifed.
                echo Current directory is `pwd`.
                echo ""
                exit 1
            endif
        endif
    endif
    shift

end

# Now make sure we have all of the parameters.

if ("$deltaX" == "none") set deltaX = 1
if ("$deltaY" == "none") set deltaY = $deltaX

# End of help/syncheck boiler plate.

lgdither $BINDIR/bxy3.dither $deltaX $deltaY n=$Nim laser=$laser


