#!/bin/csh -f
#+
#OSIRIS library of scripts
#
#NAME
#     cryotemps - print electronics cabinet temps to screen
#
#SYNOPSIS
#     cryotemps (no args)
#
#DESCRIPTION
#     prints the current cabinet and detector temperatures to the screen
#     as well as the log files.
#
#OPTIONS
#     None
#
#EXAMPLES
#     cryotemps 
#
#ENVIRONMENT VARIABLES
#     None
#
#FILES
#     None
#
#SERVERS & KEYWORDS
#     list of the servers and keywords used, for example:
#
#     service = osiris
#          keywords: dtmp[1-8], icurtmp, itrgtmp, scurtmp, strgtmp
#                    dtmplogdir, dtmplogfile, dtmplogging
#                    otcslogdir, otcslogfile, otcslogging
#
#SCRIPTS CALLED
#     list of the scripts called by this script, for example:
#
#     help, syncheck
#
#EXIT STATUS
#     0 - normal exit, no error
#
#SEE ALSO
#     ???
#-
#
# Modification History:
# 2006 jan 18 jlyke adapted for OSIRIS from NIRSPEC version
# 2017 nov 19 jlyke updated output formatting
#----------------------------------------------------------------------
# Get the temperatures
set service = ot1s
set allcapsserv = `echo $service | /usr/bin/tr "[a-z]" "[A-Z]"`

# get dewar temps (dtmp#)
set sensors = (tmp1 tmp2 tmp3 tmp4 tmp5 tmp6 tmp7 tmp8)
set tmp = `show -s $service -terse $sensors`

#----------------------------------------------------------------------
# Get logging information
# Dewar temp log
# logdir
set tmplogdir = `show -s $service -terse logdir`
# logfile
set tmplogfile = `show -s $service -terse logfile`
# is logging enabled?
set tmplogging = `show -s $service -terse logging`
if ($tmplogging == 1 ) then
  set tmplogstat = "on"
else
  set tmplogstat = "off"
endif

#----------------------------------------------------------------------
# Print results to the screen
set format = "%-10s %-33s %-10s %7.2f\n"

set space = "    "
echo " Service = $allcapsserv                 OSIRIS Dewar Temperatures (K) "
echo "==============================================================="
echo " Keyword   Location                          Normal       Temp  "
echo "---------------------------------------------------------------"


set number = ( 1 2 3 4 5 6 7 8 )
foreach num ($number)
set location = `show -s $service -terse tmploc$num`
set range = "`show -s $service -terse tmprng$num`"
printf "$format" " $sensors[$num]" "$location" "$range" $tmp[$num]
end
echo "==============================================================="
echo "           Log File    "
echo "---------------------------------------------------------------"
echo "   $tmplogdir$tmplogfile"
echo "   Logging is $tmplogstat"
echo "      " 

dettemps

