#!/bin/csh
#
# Script for POINTING TEST on INT with IDS or WFC
#
# Before running the script you need to prepare the file tcs.cat and
#   to input temperature, pressure, humidity and wavelength for
#   calculation of atmospheric refraction;
#   set autoxy to 500000 500000 and autotime to 100 msec for IDS;
#   be aware that the INT has a dec limit of -30 degrees;
#   the system will slew to all sources listed in the catalogue.
# You might want to split the whole pointing test into several parts,
#   running each time a sub-catalogue.
# The full catalogue for the faint grid was copied to
#   /home/intobs/tcs_faint.cat, sources with dec < -30 were removed.
# I did the first star manually, GOCAT first_star, checking the rotator
#   center on the autoguider (update this script if necessary),
#   guide on pixel x y and POINT NEW.
# If you make the guide window bigger than 105x105 you get lots of
#   WARNING - tImgCapt - DMA transfer failed (timed out), using default
#   blank frame
#
# history: 17/10/2000 found script and made it work for IDS, Juerg Rey
#          10/02/2004 modified, Robert Greimel
#          27/05/2005 modified, Juerg Rey

# initialize the system
cmd TCS USER "ENTER APERTURE 0 1065 -42"
agwin acq pos 1032 512
agwin gui size 240 240

# make sure that we are writing to a clean pointing data file
cmd TCS USER "POINT NEW"

# now loop over all the stars in the pointing grid
foreach star ( `grep -v '^\!' ft.cat | awk '/[0-9]/ {print $1}' ` )
  echo -n $star
  gocat $star
  if ($status == 0) then
    guide on pixel 1032 512 .5 .5 #rotator center WFC
    echo -n " ... pulling in "
    # this is a waiting loop to make sure that the autoguider had enough
    # time to pull in the star. It would be much nicer if we knew the
    # autoguider position error
    foreach i (1 2 3 4 5 6)
      echo -n "."
      sleep 8
    end
    cmd TCS USER "POINT"
    guide off
    echo " done"
  else
    echo " ... out of range - skipping"
  endif
end

echo "resetting aperture 0"
cmd TCS USER "ENTER APERTURE 0 -251 326"  #WFC only
