program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/sim/src/check_errsig.src"
descr "check_errsig - read error-signals from HK"
# program check_errsig.src, created 95.12.13 Igor Zayer 
#
# Part of alignment procedure; read ISS parameters and provide to
# calling routines. Usually called by 'anlignit.src', 'null_err' 
# and 'setup_iss'. 
# --> IS NOT STAND-ALONE - ASSUMES ISS ON AND A VALID !GR8 VALUE!!!
#
# Calls: --
# ------
#
# Variable usage:
#----------------
# !GI1: X-offset (multxofs)
# !GI2: Y-offset (multyofs)
# !GI8: 'error signal nulled' indicator (0 = not nulled, 1 = OK to lock ISS)
# !GR0: X-error signal, average (multxave)
# !GR1: Y-error signal, average (multyave)
# !GR8: Voltage value of nulled error signal, MUST be supplied externally!!!
# !GS9: name of user logfile
#
# !LR0: lower limit of nulled error signal = !GI8 - 0.1
# !LR1: upper limit of nulled error signal = !GI8 + 0.1
# !LI7: "X nulled criterion": set to 1 if satisfied
# !LI8: "Y nulled criterion": set to 1 if satisfied
##----------------

writen  !GS9 "Executing procedure check_errsig"

## GET & LOG THE MOMENTARY ERROR SIGNALS & OFFSETS
set !LI7 = 0
set !LI8 = 0
set !GR0 = getreal(multxave)
set !GR1 = getreal(multyave)
set !GI1 = getint(mkltxofs)
set !GI2 = getint(mkltyofs)
write  !GS9 "X offset: %3d " !GI1
write  !GS9 "X avgerr: %4.2f " !GR0
write  !GS9 "Y offset: %3d " !GI2
writen !GS9 "Y avgerr: %4.2f " !GR1
## CHECK IF X-ERROR IS CLOSE ENOUGH TO NULL
set !LR0 = !GR8 - 0.1
set !LR1 = !GR8 + 0.1
if !GR0 > !LR0 then
  if !GR0 < !LR1 then
    set !LI7 = 1
  end if
end if
## CHECK IF Y-ERROR CLOSE ENOUGH TO NULL
if !GR1 > !LR0 then
  if !GR1 < !LR1 then
    set !LI8 = 1
  end if
end if
## SET FLAG OF ERROR SIGNAL STATUS
set !GI8 = !LI7 * !LI8

writen !GS9 "Finished procedure check_errsig"
return
