#!/bin/tcsh -ef
#
# ABOUT   : NOTCam loop script for repeated exposures in 
#           staring mode.
#
# USAGE   : notcam.loop-exp [-e] exptime
#           -e      : Echo script on stdout, do not execute
#           exptime : Exposure time in seconds
#
# DEPENDS : notcam.expose, notcam.autosave_on, notcam.imtype
#
# PROVIDES: notcam.loop-exp
#
# TFUNCT  : Continues until aborted with Ctrl-C
#
# AUTHOR  : Anlaug Amanda Djupvik
#
# HISTORY : 2010/05/06 (Initial release, AAD)
#   

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

# Get command line arguments
set t = `echo "$1" | sed -n -e '/^[0-9.]*$/p'`

# Check for errors in arguments
if ($t == '') then
   echo " Error in arguments"
   echo " Usage: notcam.loop-exp t \n"
   echo "        t = exptime in seconds \n"
exit 1
endif


# Warn that if "t" is < 3 seconds then shutter effects
set tt = `echo "10*$t" | bc -l | awk '{printf ("%5i"),$1}'`
if ($tt == 0) then
    echo "Zero exposure time not allowed."
    exit 1
    logger -p local0.debug -t "notcam.loop-exp" "[ERROR]: Invalid exptime. Exits."
endif
if ($tt < 30) then
echo "For t < 3 seconds shutter effects can alter the flux by more than 1%."
echo "For t = 2 seconds the errors introduced are around 3% and increase with smaller t." 
echo "Continue anyhow (y/n)?"
set answ = $<
  if ("$answ" == "n") then
     echo  " Interrupted. \n"
     exit 1
  else if ("$answ" == "y") then
     echo "Be warned!"
  else
     echo " Invalid option."
    exit 1
   endif
endif

# Write to Talker
logger -p local0.debug -t "notcam.loop-exp" "[NOTE]: Loop script started. To be ended with Ctrl-C."

# Execute or Echo script

$e notcam.autosave_on
$e notcam.imtype OBJECT

onceagain:

$e notcam.expose $t

goto onceagain



