#!/bin/tcsh -ef
#
# ABOUT   : NOTCam Pinhole Position measurement script.
#           This script will guide you through the measurements.
#           Both, the WF and HR camera are used and the setup
#           does not require user input. However, opening mirror covers
#           and turning on an off the lambs do.
#          
# USAGE   : notcam.pinholePosition [-e]
#           [-e] Echoes the script on stdout, do not execute
#
# EXITSTA :
#           0: No errors
#
# DEPENDS : notcam.lens
#           notcam.aperture
#           notcam.stop
#           notcam.filter1
#           notcam.grism
#           notcam.notcamfocus
#           notcam.wait_notcam_ready
#
# PROVIDES: notcam.pinholePosition
#
# TFUNCT  : As long as it takes ;-)
#
# AUTHOR  : Sami-Matias Niemi
#
# HISTORY : 12/06/08 Developement version alpha 1
#           16/06/08 Release Candidate 1
#           07/07/08 Initial Release
#           17/07/08 Typos corrected
#           23/04/09 Changed notcaminst. -> notcam.
#                    and notcam.focus -> notcam.notcamfocus (AAD)

if ("$1" == "-e") then
  set e = "echo"
else
  set e = ""
endif

echo "\n\e[00;32m-------------------------------------------------------\e[00m"
echo "\n\e[00;32m--------------------WELCOME----------------------------\e[00m"
echo "\n\e[00;32m-------------------------------------------------------\e[00m"
echo "\n\e[00;32mThis script can be used for measuring pinhole postion inside NOTCam!\e[00m"
echo "\e[00;32mIt requires some amount of user input while measuring the coordinates of the pinhole.\e[00m"
echo "\e[00;32mWhere user input is required, the lines are coloured in \e[00;31mRED.\e[00m"

echo "\n"
echo "\e[00;31mPlease set the Argon baffle lamp on.\e[00m"
echo "\n"

#Writes to the Talker
$e logger -p local0.debug -t "notcam.pinholePosition" "[NOTE]: Script started"

#Setup for the WF camera and pinhole position measurement
$e notcam.lens 1 &
$e notcam.notcamfocus 5650 &
$e notcam.grism 2 &
$e notcam.stop 12 &
$e notcam.filter1 15 &
$e notcam.filter2 10 &
$e notcam.aperture 11 &
$e notcam.wait_notcam_ready

#Set the postprocessing to quick exam
#It seems that it has not been implemented yet!
#$e notcampostproc.postQuickExam on

#Clears the array
$e notcam.clear

#Makes sure that the lamp and quick exam are on
echo "\e[00;31mPlease check that Quick Exam is on and the skysubstraction is off on the PostProcess window!\e[00m" 
echo "\e[00;31mPress return to continue...\e[00m"
set answ = $<

#Expose
$e notcam.object "PinholePos WF"
$e notcam.expose 3

#Write instructions
echo "\n\e[00;31mPlease measure the position of the pinhole from the imexam DS9 window!\e[00m"
echo "\n\e[00;32mYou can do this by placing the cursor above the pinhole and pressing 'a'.\e[00m"
echo "\n\e[00;32mThe green backgrounded window will print out the coordinates.\e[00m"
echo "\n\e[00;32mThe pinhole should locate somewhere around (x,y) = (471,525).\e[00m"
echo "\n\e[00;31mPlease write down the measured values. These coordinates are for the wide field camera.\e[00m"
echo "\n\e[00;31mPlease press return to continue...\e[00m"
set answ = $<

#Change to HR camera
$e notcam.lens 3 &
$e notcam.notcamfocus 20 &
$e notcam.wait_notcam_ready

#Expose
$e notcam.object "PinholePos HR"
$e notcam.expose 7

#Writes the instructions
echo "\n\e[00;31mPlease measure the position of the pinhole from the imexam DS9 window!\e[00m"
echo "\n\e[00;32mYou can do this by placing the cursor above the pinhole and pressing 'a'.\e[00m"
echo "\n\e[00;32mThe green backgrounded window will print out the coordinates.\e[00m"
echo "\n\e[00;32mThe pinhole should locate somewhere around (x,y) = (463,509).\e[00m"
echo "\n\e[00;31mPlease write down the values. These coordinates are for the high resolution camera.\e[00m"

#Quits
echo "\n\e[00;31mDo not forget to update the webpage and turn off the baffle lamp!\e[00m"
echo "\n\e[00;31mDo not forget to reset the instrument setup!!\e[00m"
echo "Thank you!"

# All done. Exit with error status 0 and write to Talker
$e logger -p local0.debug -t "notcam.pinholePosition" "[NOTE]: Script ended successfully"
exit 0
