esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% disable.mac
#%NAME% 
#   Deactivate selected counters or motors
#
#%CATEGORY% Positioning, Counting, Tools
#
#%DESCRIPTION%
#   Use these macro to speed up scans.%BR%
#   By default, SPEC reads all counter for a scan point, whether it is plotted
#   or not.
#   By skipping the readout of uninteresting counters, the duration scans can
#   be reduced considerately.
#   Also "pseudo" motors can cause a substantial software overhead.
#   These macros allow you to optimize SPEC for a certain subset of
#   motors and counters "on the fly" without making modifications in the
#   configuration editor.
#
#%LOG%
#
#%LI% 23/01/02 LC: added disable_save() and disable_undo macros for undoing feature.
#%LI%              created intermediate functions _enable() _disable(), for internal macro use.
#
#%END%

#%UU% mnemonic [mnemonic ...]
#%MDESC%
# This macro can be used for counters and motors.%BR%
# It is usefull for speeding up scans by disabling the readout of counters
# which are currently not used.  %BR%
# As arguments you may use motor or counter mnemonics in any order, as
# well as the key word "all", "all motors", "all counters", "except","only"
# "but not" and "and".
# For example, you can specify "disable all except ywire posmon and posy" or
# "disable all counters but not pd3". %BR%
# Use "?" to get list of enable counters/motors

def disable '_disable("$*")'

#%IU% %MDESC%
def _disable(clist) '{
  local n mne[] i j s

  if (clist == "") print "usage: disable counter|motor [counter|motor ...]"

  if (clist == "?") {
    for (i=0,n=0; i< COUNTERS; i++) if (counter_par(i,"disable") == 0) n++
    for (i=0,m=0; i< MOTORS; i++) if (motor_par(i,"disable") == 0) m++
    if (n+m == 0) print "no counters or motors are enabled"
    if (n>0) print "The following counters are enabled:"
    for (i=0; i< COUNTERS; i++)
      if (counter_par(i,"disable")==0) printf ("%s ",cnt_mne(i))
    if (n>0) printf("\n")
    if (n>0 && m>0) printf("\n")
    if (m>0) print "The following motors are enabled:"
    for (i=0; i< MOTORS; i++)
      if (motor_par(i,"disable")==0) printf ("%s ",motor_mne(i))
    if (m>0) printf("\n")
  }
  else  {
    disable_save()
    n = split(clist,mne)
    s = 1
    for (i=0; i<n; i++) {
      if (mne[i] == "all" && mne[i+1] == "counters") {}
      else if (mne[i] == "counters")
        for (j=0; j<COUNTERS; j++) disable_counter (cnt_mne(j),s)
      else if (mne[i] == "all" && mne[i+1] == "motors") {}
      else if (mne[i] == "motors")
        for (j=0; j<MOTORS; j++) disable_motor (motor_mne(j),s)
      else if (mne[i] == "all") {
        for (j=0; j<MOTORS; j++) disable_motor (motor_mne(j),s)
        for (j=0; j<COUNTERS; j++) disable_counter (cnt_mne(j),s)
      }
      else if (mne[i] == "only") {
        for (j=0; j<MOTORS; j++) disable_motor (motor_mne(j),!s)
        for (j=0; j<COUNTERS; j++) disable_counter (cnt_mne(j),!s)
      }
      else if (mne[i] == "except") s = !s
      else if (mne[i] == "but" && mne[i] == "not") {s = !s; i++}
      else if (mne[i] == "and") {}
      else if (cnt_num (mne[i]) != -1) disable_counter (mne[i],s)
      else if (motor_num (mne[i]) != -1) disable_motor (mne[i],s)
      else print "Is \""mne[i]"\" a counter or motor?"
    }
  }
}'

#%UU% mnemonic [mnemonic ...]
#%MDESC%
# Undo "disable". %BR%
# The same key words as for "disable" are allowed, e.g.
# "enable only ywire posmon and posy".

def enable '_enable ("$*")'

#%IU% %MDESC%
def _enable(clist)'{

  local n m mne[] i j s

  if (clist == "") print "usage: enable counter|motor [counter|motor ...]"

  if (clist == "?") {
    for (i=0,n=0; i< COUNTERS; i++) if (counter_par(i,"disable") == 1) n++
    for (i=0,m=0; i< MOTORS; i++) if (motor_par(i,"disable") == 1) m++
    if (n+m == 0) print "no counters or motors are disabled"
    if (n>0) print "The following counters are disabled:"
    for (i=0; i< COUNTERS; i++)
      if (counter_par(i,"disable")==1) printf ("%s ",cnt_mne(i))
    if (n>0) printf("\n")
    if (n>0 && m>0) printf("\n")
    if (m>0) print "The following motors are disabled:"
    for (i=0; i< MOTORS; i++)
      if (motor_par(i,"disable")==1) printf ("%s ",motor_mne(i))
    if (m>0) printf("\n")
  } else  {
    disable_save()
    n = split(clist,mne)
    s = 0
    for (i=0; i<n; i++) {
      if (mne[i] == "all" && mne[i+1] == "counters") {}
      else if (mne[i] == "counters")
        for (j=0; j<COUNTERS; j++) disable_counter (cnt_mne(j),s)
      else if (mne[i] == "all" && mne[i+1] == "motors") {}
      else if (mne[i] == "motors")
        for (j=0; j<MOTORS; j++) disable_motor (motor_mne(j),s)
      else if (mne[i] == "all") {
        for (j=0; j<MOTORS; j++) disable_motor (motor_mne(j),s)
        for (j=0; j<COUNTERS; j++) disable_counter (cnt_mne(j),s)
      }
      else if (mne[i] == "only") {
        for (j=0; j<MOTORS; j++) disable_motor (motor_mne(j),!s)
        for (j=0; j<COUNTERS; j++) disable_counter (cnt_mne(j),!s)
      }
      else if (mne[i] == "except") s = !s
      else if (mne[i] == "but" && mne[i] == "not") {s = !s; i++}
      else if (mne[i] == "and") {}
      else if (cnt_num (mne[i]) != -1) disable_counter (mne[i],s)
      else if (motor_num (mne[i]) != -1) disable_motor (mne[i],s)
      else print "Is \""mne[i]"\" a counter or motor?"
    }
  }
}'

#%UU% 
#%MDESC%
# Normally "config" or "reconfig" would re-enable all counters and motors
# which were disabled. Include this macro into your "setup" file
# if you do not want this to happen. %BR%
# Make sure that the line "disable_setup" is at the end of the "setup"
# file because some macros as "adcsetup" or "elmetersetup" will re-enable
# counters as well. %BR%

def disable_setup '{
  local i mne t
  for (i=0; i<MOTORS; i++){
    mne = motor_mne(i)
    if (esrf_db(t=SPECBL"/motors/"SPEC"_"mne,"disable") == 1)
      motor_par(i,"disable",1)
  }
  for (i=0; i<COUNTERS; i++) {
    mne = cnt_mne(i)
    if (esrf_db(t=SPECBL"/counters/"SPEC"_"mne,"disable") == 1)
      counter_par(i,"disable",1)
  }
  disable_save()
}'


#%UU% 
#%MDESC%
# restores the motors/counters state just before last called of enable/disable macros.
def disable_undo '
  local i
  if (whatis("DISABLE") != 0x08000000){
    for (i=0; i<MOTORS; i++)   disable_motor (motor_mne(i),DISABLE["mot"][i])
    for (i=0; i<COUNTERS; i++) disable_counter(cnt_mne(i), DISABLE["cnt"][i])
  } else print "Please, call first disable_save to save current motors/counters disabled"
   
'

#%IU% 
#%MDESC%
# Save into a global variable the current disable status of motors/counters.
# It is called from the disable and enable macros,
def disable_save() '{
global DISABLE[]
  local i
  for (i=0; i<MOTORS; i++)   DISABLE["mot"][i] = motor_par(i,"disable")
  for (i=0; i<COUNTERS; i++)DISABLE["cnt"][i] = counter_par(i,"disable")
}'



#%IU% ("cnt",1|0)
#%MDESC% sets or clears the the "disable" flag for the counter "cnt".
# If the second parameter is 1 the counter is disabled if it is 0 the
# counter is enabled. %BR%
# Also, the current state of the counter is saved in the ESRF data base.

def disable_counter (mne,state) '{
  local n t
  n = cnt_num (mne);  if (n == -1) return
  #do not disabled the sec counter !
  if (n == 0 && state == 1) return
  counter_par(n,"disable",state)
  if (state == 1) S[n]=0
  esrf_db(t=SPECBL"/counters/"SPEC"_"mne,"disable",state)
}'

#%IU% ("mot",0|1)
#%MDESC% sets or clears the the "disable" flag for the motor "mot".
# If the second parameter is 1 the motor is disabled if it is 0
# it is enabled. %BR%
# Also, the current state of the motor is saved in the ESRF data base.

def disable_motor(mne,state) '{
  local n t
  n = motor_num (mne);  if (n == -1) return
  motor_par(n,"disable",state)
  esrf_db(t=SPECBL"/motors/"SPEC"_"mne,"disable",state)
}'

#%MACROS%
#%IMACROS%
#%INTERNALS%
# Information whether a specific motor or counter should be
# enabled or disable after "reconfig" is stored in the ESRF data base
# under "ID9/motor/spec_mot1", if it is a motor is called "mot1"
# and "ID9" the beamline name.
# If you have different SPEC configurations "spec" is replaced by the
# configuration name.
#%AUTHOR% Friedrich Schotte, ID9, 27 Oct 2000