# File: lcmtap.src
#
# This procedure file exercises the shutter by taking a picture with 
# the parameters specified below and logging the actual shutter times.
#
#     !GI0 = exposure time in shutter ticks (0.25 msec/tick)
#     !GI7 = Sequence ID
#     !GI8 = shutter path; 1 - 1x ; 3 - 3x
#     !GI9 = wait time after exposure command in seconds
#

program "@(#) MODULE: lcmtap.src RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/eof/src/lcmtap.src"
descr "  lcmtap - Takes a picture and calculates shutter times"

if !GI7 = 0 then
  set !GI7 = 0x8004
end if

if !GI8 = 1 then
  writen !GS9 "Taking a 1x image with an exposure of %6d ticks" !GI0
  tcblock mbcmtp1r !GI7 !GI0 !GI0		## Take 1x exposure
end if

if !GI8 = 3 then
  writen !GS9 "Taking a 3x image with an exposure of %6d ticks" !GI0
  tcblock mbcmtp3r !GI7 !GI0 !GI0		## Take 3x exposure
end if

if !GI9 > 25 then
  wait time !GI9
else
  wait mf 2
end if

#set !LI1 = getraw(hk2[91])
#set !LI2 = getraw(hk2[92])
#set !LI3 = !LI2 * 256
#set !LI3 = !LI3 + !LI1
set !LI3 = getint(mkshnexp)

set !LI4 = getint(mksqfqpp)

if !LI4 = 0 then
  set !LI5 = getint(mksqsho4)
  set !LI6 = getint(mksqshc4)
end if

if !LI4 = 1 then
  set !LI5 = getint(mksqsho1)
  set !LI6 = getint(mksqshc1)
end if

if !LI4 = 2 then
  set !LI5 = getint(mksqsho2)
  set !LI6 = getint(mksqshc2)
end if

if !LI4 = 3 then
  set !LI5 = getint(mksqsho3)
  set !LI6 = getint(mksqshc3)
end if

set !LI7 = !LI3 * 64
set !LR1 = !LI7 + !LI5
set !LR1 = !LR1 / 65535
set !LI8 = !LR1

set !LR2 = !LI8 * 65535
set !LR2 = !LR2 + !LI6
set !LR2 = !LR2 - !LI5
set !LR2 = !LR2 / 256

writen !GS9 "Nominal shutter exposure time (ticks) = %6d" !LI3
writen !GS9 "Sequence Frame Queue Packet Pointer   = %6d" !LI4
write  !GS9 "Opening count = %6d; " !LI5
writen !GS9 "Closing count = %6d" !LI6
writen !GS9 "Shutter closing time overflows        = %6d" !LI8
writen !GS9 "Shutter exposure time (milliseconds)  = %9.2f" !LR2
writen !GS9 " "
