##########################                                            ##-#
#                                                                     ##-#
# Assembled by checkpoint, 1.18.2 (23-Sep-99).                        ##-#
# (EDIT THE ORIGINAL SOURCE, NOT THIS FILE!)                          ##-#
# Date-assembled: Fri Jan 15 10:21:53 EST 2010                        ##-#
# Orig-source: /mdisw/cfl/flight/src/set_alt_time_v08.src             ##-#
#                                                                     ##-#
##########################                                            ##-#
# File set_alt_time.src	 1 May 96
#
# This procedure sets Interval counter to a value such that the ALT periods
# are synced to midnight.
# -- 3rd alt should happen at 00:00 --
# HISTORY:
#	Written May-96 by D.Mathur
#	10-Jul-96 (MDM) - Changed "wait mf 1" to "wait time 15" 
#
program "@(#) MODULE: set_alt_time.src RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/flight/src/q_set_alt_time_v08.src"
descr "q_ set_alt_time - set interval counter "
                                                                      ##-#
#=#=#=#=#=#=#=#=#=#=# src ln 14.  (Open Log file)                     ##-#
if !GS9 = "" then                                                     ##-#
  display "Opening logfile from q_set_alt_time_v08"                   ##-#
  perf openlog                                                        ##-#
end if                                                                ##-#
write !GS9 "%s q_set_alt_time_v08:" !TIME                             ##-#
writen !GS9 "Starting..."                                             ##-#
#
set !LI0 = getint(mkdpsqst)
if !LI0 <> 0 then 
    goto set_time
end if
#
display "DEP Standard Sequence Inactive"
goto sat_done
set_time:
#
# Wait until the interval counter has incremented. This ensures that
# the REFTime is at most 7.5 sec old.
#
set !LI0 = getint(mksqintc)         ## Get interval counter
cyh:
wait time 15
set !LI1 = getint(mksqintc)
if !LI0 = !LI1 then
    goto cyh 
end if
#
# Interval counter just changed; Calculate the interval counter for the
# *next* observing interval.
#
set !LI0 = getint(mksqref3)         ## REFTime bits  0-7 
set !LI1 = getint(mksqref2)         ## REFTime bits  8-15
set !LI1 = !LI1 * 256
set !LI0 = !LI0 + !LI1
set !LI1 = getint(mksqref1)         ## REFTime bits 16-23
set !LI1 = !LI1 * 65536
set !LI0 = !LI0 + !LI1
set !LI1 = getint(mksqref0)         ## REFTime bits 24-31
set !LI1 = !LI1 * 16777216
set !LI0 = !LI0 + !LI1              ## REFTime in Seconds
display "!LI0 2: %d" !LI0
set !LI0 = !LI0 + 60                ## *Next* REFTime
set !LI9 = !LI0 / 5760              ## REFTime ALT Periods
set !LI8 = !LI9 * 5760              ## 
set !LI9 = !LI0 - !LI8              ## Number of Sec in Curr ALT Period
set !LI8 = !LI9 / 60                ## Number of Min in Curr ALT Period 
#
#
# Calculate index for the Time Weighted Averaged quantities
# set !LI0 = !LI0 + 60
set !LI2 = !LI0 / 720               ## Number of 12 min periods
set !LI3 = !LI2 * 720 
set !LI4 = !LI0 - !LI3              ## No. of sec in curr 12 min period
set !LI3 = !LI4 / 60                ## No. of min in curr 12 min period
set !LI3 = !LI3 + 12
set !LI4 = !LI3 - 12                ## Index for 2nd TWA quantity
# if !LI3 < 12 then
#     set !LI4 = !LI4 + 12
# end if
#
# Wait for the *next* observing interval to begin
#
set !LI0 = getint(mksqintc)         ## Get interval counter
cyh1:
wait time 15
set !LI1 = getint(mksqintc)
if !LI0 = !LI1 then
    goto cyh1 
end if
#=#=#=#=#=#=#=#=#=#=#+ src ln 79.  Block 0  Next line is #93          ##-#
 display "Running block 0 of q_set_alt_time_v08."                     ##-#
set !LI5 = getint(mktccnt)                                            ##-#
queue on ## Queue next 6 commands.                                    ##-#
#
tcblock mbdpml 0x1000 0x408e !LI8
#
tcblock mbipldin 0x140 917 !LI3     ## Mag Proxy 1
tcblock mbipldin 0x140 937 !LI4     ## Mag Proxy 2
tcblock mbipldin 0x140 969 !LI3     ## Flux Budget 1
tcblock mbipldin 0x140 989 !LI4     ## Flux Budget 2
tcblock mbipldin 0x140 873 !LI3     ## Limb Figure 1
queue off ## Synchronize w/ POCC                                      ##-#
tcblock mbipldin 0x140 897 !LI4     ## Limb Figure 2

display "ALT Time: %d" !LI8 to 20
display "Index 1: %d" !LI3 to 40
display "Index 2: %d" !LI4 to 60
#
sat_done:
# display "Done...End procedure set_alt_time"
#=#=#=#=#=#=#=#=#=#=#- src ln 93.  Block 0   Cmds:7   Total:7         ##-#
wait time 8 ## Wait for hk packet                                     ##-#
set !LI7 = !LI5 + 7                                                   ##-#
if !LI7 > 255 then                                                    ##-#
 set !LI6 = !LI7 - 256                                                ##-#
else                                                                  ##-#
 set !LI6 = !LI7                                                      ##-#
end if                                                                ##-#
set !LI7 = getint(mktccnt)                                            ##-#
if !LI6 <> !LI7 then                                                  ##-#
 write !GS9 "%s q_set_alt_time_v08:" !TIME                            ##-#
 writen !GS9  "CMD CT ERR in block 0. cmd ctr: %d" !LI7               ##-#
 writen !GS9  "      (Sent 7 cmds; expected cmd ctr: %d)" !LI6        ##-#
 writen !GS9  "      Halted.  (restart at line 93)"                   ##-#
 display "ERR: q_set_alt_time_v08 blk 0: cmd ctr isnt %d. (CONT 93)" !LI6##-#
 halt                                                                 ##-#
 write !GS9 "%s q_set_alt_time_v08:" !TIME                            ##-#
 writen !GS9  "Override.  Continuing past block 0..."                 ##-#
else                                                                  ##-#
 write !GS9 "%s q_set_alt_time_v08:" !TIME                            ##-#
 writen !GS9  "Block 0 completed OK."                                 ##-#
display "Completed block 0 of q_set_alt_time_v08."                    ##-#
end if                                                                ##-#
#################### END of BLOCK 0 ####################              ##-#
write !GS9 "%s q_set_alt_time_v08:" !TIME                             ##-#
writen !GS9 "Falling off the bottom."                                 ##-#
