# File mdiltc.src	30.9.93	IZ
#
# Performs a light transfer set in HR CAL mode as part of LFFT
#
#     !GI0 = exposure time in shutter ticks (0.25 msec/tick)
#     !GI7 = Sequence ID
#     !GI9 = wait time after exposure command in seconds
#

program "@(#) MODULE: mdiltc.src RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/eof/src/mdiltc.src"
descr "  mdiltc - Performs a light transfer set in HR cal mode"

display "Executing procedure: mdiltc"
writen !GS9 "  "
write  !GS9 "Executing procedure mdiltc :"
write  !GS9 " %s" !DATE
writen !GS9 " %s" !TIME

tcblock mbcmsumm 1 1

set !GI5 = 4
perform liplbic

write !GS9 "  Taking central 256x256 with"
write !GS9 " exp.time + 4 sec waits"
writen !GS9 " in HR CAL"

set !GI7 = 0xc015

set !LI0 = 120
ask !RI "Enter SHORTEST exposure time ('0' for default of 120 ticks)"
if !RI > 0 then
  set !LI0 = !RI
end if
set !LI1 = 60000
ask !RI "Enter LONGEST exposure time ('0' for default of 60000 ticks)"
if !RI > 0 then
  set !LI1 = !RI
end if
# go figure intermediate exposures in LTC
set !LI2 = !LI1 - !LI0

tcblock mbcmaadc 3
wait time 1
writen !GS9 "  CCD amplifier A, offset: 3"

perform lcalmode

open decom160 !LS1
writen !GS9 "  160k data stored in: %s" !LS1

for !LI7 = 0 to 2
  if !LI7 > 0 then
    tcblock mbcmbadc 3
    wait time 1
    writen !GS9 "  CCD amplifier B, offset: 3"
  end if
  set !GI0 = !LI0
  set !GI9 = !GI0 / 4000.
  set !GI9 = !GI9 + 4
  if !GI9 < 8 then
    set !GI9 = 8
  end if
  writen !GS9 "    The exposure pairs are (ticks):"
  writen  !GS9 "      %d" !GI0
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9

  set !GI0 = !LI2 / 4
  set !GI0 = !LI0 + !GI0
  set !GI9 = !GI0 / 4000.
  set !GI9 = !GI9 + 4
  if !GI9 < 8 then
    set !GI9 = 8
  end if
  writen  !GS9 "      %d" !GI0
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9

  set !GI0 = !LI2 / 8
  set !GI0 = !GI0  * 3
  set !GI0 = !LI0 + !GI0
  set !GI9 = !GI0 / 4000.
  set !GI9 = !GI9 + 4
  if !GI9 < 8 then
    set !GI9 = 8
  end if
  writen  !GS9 "      %d" !GI0
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9

  set !GI0 = !LI2 / 2
  set !GI0 = !LI0 + !GI0
  set !GI9 = !GI0 / 4000.
  set !GI9 = !GI9 + 4
  if !GI9 < 8 then
    set !GI9 = 8
  end if
  writen  !GS9 "      %d" !GI0
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9

  set !GI0 = !LI2 / 3
  set !GI0 = !GI0  * 2
  set !GI0 = !LI0 + !GI0
  set !GI9 = !GI0 / 4000.
  set !GI9 = !GI9 + 4
  if !GI9 < 8 then
    set !GI9 = 8
  end if
  writen  !GS9 "      %d" !GI0
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9

  set !GI0 = !LI2 / 4
  set !GI0 = !GI0  * 3
  set !GI0 = !LI0 + !GI0
  set !GI9 = !GI0 / 4000.
  set !GI9 = !GI9 + 4
  if !GI9 < 8 then
    set !GI9 = 8
  end if
  writen  !GS9 "      %d" !GI0
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9

  set !GI0 = !LI2 / 20
  set !GI0 = !GI0  * 17
  set !GI0 = !LI0 + !GI0
  set !GI9 = !GI0 / 4000.
  set !GI9 = !GI9 + 4
  if !GI9 < 8 then
    set !GI9 = 8
  end if
  writen  !GS9 "      %d" !GI0
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9

  set !GI0 = !LI2 / 10
  set !GI0 = !GI0  * 9
  set !GI0 = !LI0 + !GI0
  set !GI9 = !GI0 / 4000.
  set !GI9 = !GI9 + 4
  if !GI9 < 8 then
    set !GI9 = 8
  end if
  writen  !GS9 "      %d" !GI0
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9

  set !GI0 = !LI2 / 20
  set !GI0 = !GI0  * 19
  set !GI0 = !LI0 + !GI0
  set !GI9 = !GI0 / 4000.
  set !GI9 = !GI9 + 4
  if !GI9 < 8 then
    set !GI9 = 8
  end if
  writen  !GS9 "      %d" !GI0
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9
   tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9

  set !GI0 = !LI1
  set !GI9 = !GI0 / 4000.
  set !GI9 = !GI9 + 4
  if !GI9 < 8 then
    set !GI9 = 8
  end if
  writen  !GS9 "      %d" !GI0
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9
  tcblock mbcmtp3r !GI7 !GI0 !GI0
  wait time !GI9

  writen !GS9 "    The SOFT dark pairs are (ticks):"
  writen  !GS9 "      120"
  tcblock mbcmdrkr !GI7 120 120
  wait time !GI9
  tcblock mbcmdrkr !GI7 120 120
  wait time !GI9
  writen  !GS9 "      40000"
  tcblock mbcmdrkr !GI7 40000 40000
  wait time !GI9
  tcblock mbcmdrkr !GI7 40000 40000
  wait time !GI9
end for

tcblock mbcmaadc 3
wait time 1
writen !GS9 "  Set CCD amplifier back to A, offset: 3"

wait time 7
close decom160

writen !GS9 "Finished procedure mdiltc : %s" !TIME
writen !GS9 "  "
display "End procedure mdiltc"
