program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/sim/src/take_pic.src"
descr "take_pic - takes verification images (in VC2)"
# program take_pic.src, created 95.12.14 Igor Zayer 
#
# Part of alignment procedure: takes verification images;
# usually called by 'alignit.src'
#
# Variable usage:
#----------------
# !GI0: exposure time (ticks)
# !GI9: wait time (seconds)
# !GS7: 'enable calling the leg routine' string (is set once picture is taken)
# !GS8: name of 160k file
# !GS9: name of user logfile
#
# !LI0: loop count variable
# !LI1: loop count variable
# !LI2: exposure time answer variable
# !LI3: status of HR telemetry (= 2 for VC2)
# !LI5: temporarily stores !GI0
# !LS0: answer string
#----------------

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

##CHECK FOR VC2 (= DEP REG. #3 MUST BE 2)
set !LI3 = getint(mksqrg3)
if !LI3 <> 2 then
  beep
  beep
  display "Not in VC2 - aligment picture would be useless!!"
  writen !GS9 "Not in VC2 - aligment picture would be useless!!"
  goto done
end if

wait:
menu !LS0 "Make sure IDL procedure mdi_display is running!!" "OK" "wait.."
if  !LS0 = "wait.." then
  goto wait
end if

##SET HEADER TO INVOKE 4X4 IP SUMMING (table index 30)
tcblock mbcmhdr1 0x4040 0x4040 0 1 30
writen !GS9 " using index 30 = QPROG_TAP_CONT_4X4BIN"
set !GI9 = 7

for !LI0 = 0 to 32000
  ##ASK FOR EXPOSURE TIME
  for !LI1 = 0 to 32000
    set !LI5 = !GI0
    display "Present default exposure is (ticks): %4d" !GI0
    set !LI2 = 0
    ask !LI2 "Exposure time in ticks (enter zero for above default):"
    if !LI2 > 0 then
      set !LI5 = !LI2
    end if
    display "Eposure time (ticks): %4d" !LI5
    menu !LS0 "Is this correct?" "CORRECT" "NO, re-enter" "just QUIT"
    if !LS0 = "just QUIT" then
      goto done
    end if
    exit if !LS0 = "CORRECT"
  end for
  set !GI0 = !LI5
  ##TAKE PICTURE IF STILL IN VC2
  set !LI3 = getint(mksqrg3)
  if !LI3 = 2 then
    tcblock mbcmtp1 0 0 !GI0
    ###sync hk###
    write !GS9 " taking exposure with %d" !GI0
    writen !GS9 " ticks"
    setstr !GS7 = "enable legs"
    wait time !GI9
  else
    beep
    beep
    display "Not in VC2 - sorry!!"
    writen !GS9 "Not in VC2 - quitting!!"
    goto done
  end if
  menu !LS0 "TAKE ANOTHER PICTURE?" "YES, another one..." "NO, enough!"
  exit if !LS0 = "NO, enough!"
end for

done:
writen !GS9 "Finished procedure take_pic : %s" !TIME
writen !GS9 " "
display "Finished Procedure take_pic                                    "
return
