###CHECKPOINT ARGS: -nostartlog -maxcmds=150
program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/flight/src/pztff_hr_obs_v07.src"
descr "pztff_hr_obs - execute a flat-field using  PZT's"
# program pztff_hr_obs.src, created 95.12.14 Igor Zayer 
#	951221  (IZ) modified to run properly in queuing mode, using
#		     dummy commands to set short waits
#
# Moves the ISS mirror in open loop using the PZT offsets. Must be
# in open loop, checked by 'checkiss'. Except an operational ISS,
# it doesn't assume anything: You just get darks if You haven't 
# opened the door... The offsets are optimized for OBSmode, but 
# the mode is NOT being checked here - You get what You asked for.
#
# Calls: open_log, checkiss, log_iss_par, close_log
# ------
#
# Variable usage:
#----------------
# !GI0: exposure time in ticks
# !GS6: 'OK to proceed with ISS' indicator (= "enable ISS" if OK)
# 
# !LI1: original PZT A offset
# !LI2: original PZT B offset
# !LI3: original PZT C offset
#
# Version 6 modified by CED 1/23/96 (Added CHECKPOINT ARGS line at top)
#----------------

display "Executing procedure pztff_hr_obs"
perform   open_log_v03
write  !GS9 "Executing procedure pztff_hr_obs :"
write  !GS9 " %s" !DATE
writen !GS9 " %s" !TIME

## SEE WHETHER ISS IS USEABLE
perform   checkiss_v02	       ## this also logs initial ISS params.
if !GS6 <> "enable ISS" then
  writen !GS9 " ISS not ready or closed loop - giving up!"
  goto done
end if

## SET EXPOSURE TIME TO FIXED 600 TICKS
set !GI0 = 600
 
## FLASH CCD FIRST (using PROG TAP_CONT_8X8BIN = 33)
tcb mbcmhdr1 0x4040 0x4040 0 1 33 
tcb mbcmtp3r  0 0 4000
tcb mbdummy
tcb mbdummy
tcb mbdummy
tcb mbdummy
tcb mbdummy
tcb mbdummy
tcb mbdummy

tcb mbcmtp3r  0 0 4000
tcb mbdummy
tcb mbdummy
tcb mbdummy
tcb mbdummy
tcb mbdummy
tcb mbdummy
tcb mbdummy

## OPEN DATAFILE 
open d !GS8
writen !GS9 " 160k data stored in: %s" !GS8

## TAKE A DARK (NON-TIME-CRITICAL) WITH TAP_CONT_1X1 (= 38)
tcb mbcmhdr1 0x4040 0x4040 0 1 38
tcb mbcmdrk 0 0 !GI0
wait time 110

## SETUP HEADER TO USE IP PROG TAPB_14FRM (= 52)
tcb mbcmhdr1 0x4040 0x4040 0 1 52 

## SEE WHERE WE START FROM
set !LI1 = getint(mkltaos)
set !LI2 = getint(mkltbos)
set !LI3 = getint(mkltcos)

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 63
tcblock mbltbofs 68
tcblock mbltcofs 58
tcb mbsqreg 0  1               ## tcblock mbipldin 0x140 3072  1
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 72
tcblock mbltbofs 64
tcblock mbltcofs 53
tcb mbsqreg 0  2
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 72
tcblock mbltbofs 59
tcblock mbltcofs 59
tcb mbsqreg 0  3
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 63
tcblock mbltbofs 58
tcblock mbltcofs 68
tcb mbsqreg 0  4
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 37
tcblock mbltbofs 87
tcblock mbltcofs 65
tcb mbsqreg 0  5
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 54
tcblock mbltbofs 89
tcblock mbltcofs 46
tcb mbsqreg 0  6
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 98
tcblock mbltbofs 62
tcblock mbltcofs 30
tcb mbsqreg 0  7
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 106
tcblock mbltbofs 36
tcblock mbltcofs 47
tcb mbsqreg 0  8
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 46
tcblock mbltbofs 45
tcblock mbltcofs 99
tcb mbsqreg 0  9
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 0
tcblock mbltbofs 104
tcblock mbltcofs 104
tcb mbsqreg 0  10 
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 46
tcblock mbltbofs 120
tcblock mbltcofs 23
tcb mbsqreg 0  11
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 89
tcblock mbltbofs 99
tcblock mbltcofs 1
tcb mbsqreg 0  12
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 127
tcblock mbltbofs 10
tcblock mbltcofs 10
tcb mbsqreg 0  13
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs 72
tcblock mbltbofs 10
tcblock mbltcofs 107
tcb mbsqreg 0  14
tcb mbcmtp3r 0 0 !GI0
tcb mbdummy

## PUT OFFSETS BACK WHERE THEY WERE...
tcblock mbltaofs 0
tcblock mbltbofs 0
tcblock mbltcofs 0
tcblock mbltaofs !LI1
tcblock mbltbofs !LI2
tcblock mbltcofs !LI3

## NOW DOWNLINK...
tcb mbsqreg 0  15
tcb mbcmtp3r 0 0 !GI0
wait time 110
tcb mbsqreg 0  16
tcb mbcmtp3r 0 0 !GI0
wait time 110
tcb mbsqreg 0  17
tcb mbcmtp3r 0 0 !GI0
wait time 110
tcb mbsqreg 0  18
tcb mbcmtp3r 0 0 !GI0
wait time 110
tcb mbsqreg 0  19
tcb mbcmtp3r 0 0 !GI0
wait time 110
tcb mbsqreg 0  20
tcb mbcmtp3r 0 0 !GI0
wait time 110
tcb mbsqreg 0  21
tcb mbcmtp3r 0 0 !GI0
wait time 110
tcb mbsqreg 0  22
tcb mbcmtp3r 0 0 !GI0
wait time 110
tcb mbsqreg 0  23
tcb mbcmtp3r 0 0 !GI0
wait time 110
tcb mbsqreg 0  24
tcb mbcmtp3r 0 0 !GI0
wait time 110
tcb mbsqreg 0  25
tcb mbcmtp3r 0 0 !GI0
wait time 110
tcb mbsqreg 0  26
tcb mbcmtp3r 0 0 !GI0
wait time 110
tcb mbsqreg 0  27
tcb mbcmtp3r 0 0 !GI0
wait time 110
tcb mbsqreg 0  28
tcb mbcmtp3r 0 0 !GI0
wait time 110

## TAKE ANOTHER DARK (NON-TIME-CRITICAL) WITH TAP_CONT_1X1 (= 38)
tcb mbcmhdr1 0x4040 0x4040 0 1 38
tcb mbcmdrk 0 0 !GI0
wait time 110

## SET HEADER TO A SAFE QPROG_TAP_CONT_4X4BIN (=30)
tcb mbcmhdr1 0x4040 0x4040 0 1 30

## LOG FINAL SATE OF ISS
###sync hk###   ## this is to allow for light travel time, not HK..
perform   log_iss_par_v01

done:
writen !GS9 "Finished procedure pztff_hr_obs : %s" !TIME
writen !GS9 " "
display "Finished Procedure pztff_hr_obs                                   "
perform   close_log_v02
return
