#!/bin/csh -f
#+
# gcent -- move an object to the center of the guider pickoff mirror
#
# Purpose:
#	Given the pixel coordinates of an object on a DEIMOS guider image,
#	compute and apply the required telescope move to bring the
#	object to the center of the field of view for the DEIMOS TV
#	guider pickoff mirror (pixel coordinates x=512, y=800).
#
# Usage:
#	gcent [-n] x y
# 
# Arguments:
#	-n = no move, only print the required shift
#	x = column location of object [pixels]
#	y = row location of object [pixels]
# 
# Output:
# 
# Exit values:
#	 0 = normal completion
#	 1 = wrong number of arguments
#
# Example:
#	1) Move a target at pixel (100,200) to the pickoff mirror center:
#		gcent 100 200
#
#	2) Display the telescope move required to shift a target at
#	pixel (100,200) to the pickoff mirror center, without 
#	actually performing the move:
#		gcent -n 100 200
#
#-
# Modification history:
#	Date unknown	RWG	Original version
#	2000-Jul-05	GDW	Added documentation
#	2002-Jun-12	GDW	Adapted for DEIMOS
#	2002-Jul-30	GDW	Updated documentation
#-----------------------------------------------------------------------

# check for no-move flag...
if ( "$1" == "-n" ) then
  set move = 0
  shift
else
  set move = 1
endif

# check args...
if (${#argv} != 2) then  
  echo "Usage: gcent [-n] x y"
  exit 1
endif

# set scale...
source $DEIMOS_PROC_DIR/tel/set_scale

# compute shifts...
set dx = `calc "$gscale*($1 - 512)"`
set dy = `calc "$gscale*(800 - $2)"`
if ( ! $move ) then
  echo "Move $dx pixels in x and $dy pixels in y"
  exit
endif

# apply shift...
gxy $dx $dy