#!/bin/csh -f
#   filename: set_mission_epoch
#
#   purpose:  set epochinsecondsoffset column in db_Missioncatalog
#
#   invocation method: set_mission_epoch

#   history:
#     04/10/96  A. Williard/		     ACE R1.0	Original implementation
#		I. Horowitz
#     07/03/96  I. Horowitz 	IDR ACE0???  ACE R2.0	Added -f option to csh - this
#                                                       allows ops user to switch SIDs
#                                                       without .cshrc change
#
set user_done = "N"
set epoch = 1199145600

echo " "
echo " "
echo "********************************************************************"
echo "*                                                   "
echo "*         DPS Spacecraft Clock Epoch Time Input"
echo "*                                                   "
echo "********************************************************************"
echo " "

set response = "Y"

echo -n "Database account name? "
set myname = $<

echo -n "Database account password? "
stty -echo
set mypass = $<
stty echo

echo " "
echo " "
echo "The DPS mission epoch date offset is the number of seconds since midnight 1/1/58" 
echo "For example, an epoch of midnight 1/1/96 has an offset of 1199145600. "

sqlplus -s /nolog <<ENDORACLE
connect $myname/$mypass
COLUMN epochinsecondsoffset FORMAT 9999999999990 HEADING "Current|Epoch Offset" JUSTIFY CENTER
SELECT epochinsecondsoffset FROM db_missioncatalog;
ENDORACLE

echo " "
echo -n "Is the current offset correct? (y/n) [$response] "
set in_resp = $<
if ( $in_resp != "" ) then
    set response = `echo $in_resp | tr '[a-z]' '[A-Z]'`
endif

if ( $response == "Y" ) then
   exit
endif

while ( `echo $user_done | tr '[a-z]' '[A-Z]'` != "Y" )
   echo " "
   echo -n "New DPS epoch offset: [$epoch]  "
   set new_epoch = $<
   if ( $new_epoch != "" ) then
      set epoch = $new_epoch
   endif
   echo " "
   echo " Is $new_epoch the correct value? (y/n)"
   set user_done = $<
end

$ORACLE_HOME/bin/sqlplus -s '/NOLOG' <<ENDORACLE
   connect $myname/$mypass

   update db_missioncatalog set epochinsecondsoffset = $epoch;
   commit;

ENDORACLE


echo " "
echo "================== DPS Epoch Date Input Completed =============="

