# 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/set_alt_time_v08.src"
descr " set_alt_time - set interval counter "
#
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
#
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
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"
