#!/bin/csh -f
#
# Usage:        dettemps
# Options:      none
#
# Purpose:      To extract all det temperatures.
#
# Created:      10jul99, TAB
# 2004 nov 30 jlyke updated nominal values
# 2005 mar 22 jlyke changed reporting precision and
#                   updated nominal values for new coldheads
# 2006 jan 18 jlyke adapted for OSIRIS
# 2009 apr 14 jlyke added active control keyword
# 2013 jan 11 jlyke added the output keywords
# 2017 nov 19 jlyke updated output formatting
#----------------------------------------------------------------------
# Get the temperatures
set service = osiris
set allcapsserv = `echo $service | /usr/bin/tr "[a-z]" "[A-Z]"`

# get imager current temp (icurtmp), target (itrgtmp), and htr ctrl (ihtract)
set icurtmp = `show -s $service -terse icurtmp`
set itrgtmp = `show -s $service -terse itrgtmp`
set ihtract = `show -s $service -terse ihtract`
set ihtrout = `show -s $service -terse ihtrout`
set ihtrout = `echo "scale=1; $ihtrout/1" | bc`

# get spec current temp (scurtmp), target (strgtmp), and heater ctrl (shtract)
set scurtmp = `show -s $service -terse scurtmp`
set strgtmp = `show -s $service -terse strgtmp`
set shtract = `show -s $service -terse shtract`
set shtrout = `show -s $service -terse shtrout`
set shtrout = `echo "scale=1; $shtrout/1" | bc`

#----------------------------------------------------------------------
# Get logging information

# Detector temp log
# logdir
set otcslogdir = `show -s $service -terse otcslogdir`
# logfile
set otcslogfile = `show -s $service -terse otcslogfile`
# is logging enabled?
set otcslogging = `show -s $service -terse otcslogging`
if ($otcslogging == 1 ) then
  set otcslogstat = "on"
else
  set otcslogstat = "off"
endif

#----------------------------------------------------------------------
# Print results to the screen
set format = "%-10s %-9s %8d %10.1f %10.2f %11.2f\n"

echo " Service = $allcapsserv            OSIRIS Detector Temperatures (K) "
echo "==============================================================="
echo " Keyword   Detector HtrActive    HtrOut%      Target      Temp "
echo "---------------------------------------------------------------"
printf "$format" " scurtmp" "SPEC" $shtract $shtrout $strgtmp $scurtmp
printf "$format" " icurtmp" "IMAG" $ihtract $ihtrout $itrgtmp $icurtmp 
echo "==============================================================="
echo "           Log File    "
echo "---------------------------------------------------------------"
echo "   $otcslogdir$otcslogfile"
echo "   Logging is $otcslogstat"
echo "      "


