esrf

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

#$Log: getbeam_presets.mac,v $
#Revision 1.1  2013/05/31 08:36:58  beteva
#Initial revision
#
#%TITLE% getbeam_presets.mac
#%NAME% getbeam_presets.mac
#%DESCRIPTION%
# Preset parameters, counters, motors and positions, used in different
#getbeam procedures.
#%END%

#%IU% ()
#%MDESC% Set the primary slits motors and counter names. Return 0 if OK,-1 if
#any of the motors or the counter is not configured. If the GB_USE["silent"]
#not set, print the setup error messages.
def gb_pslit() '{
global GB_HO GB_USE[]
global GB_PSLIT_MNE[] GB_PSLIT_MOT[] GB_PSLIT_CTMNE
local nn

  if (!GB_HO)
    GB_HO = "getbeam"

  GB_USE["pslit"] = xml_read(GB_HO, "/gb/pslit/data")
  if (GB_USE["pslit"] == -1) {
    if (GB_USE["silent"] == 0)
      printf( "Primary slits not properly configured or not used.\n")
    return(-1)
  }

  for (nn in XML_tmp[]["name"]) {
    if (XML_tmp[nn]["role"] == "motmne") {
      GB_PSLIT_MNE[XML_tmp[nn]["name"]] = XML_tmp[nn]["value"]
    } else if (XML_tmp[nn]["role"] == "ctmne") {
      GB_PSLIT_CTMNE = XML_tmp[nn]["value"]
    }
  }
  for (mmne in GB_PSLIT_MNE) {
    GB_PSLIT_MOT[mmne]=motor_num(GB_PSLIT_MNE[mmne])
    if (GB_PSLIT_MOT[mmne] == -1) {
      eprintf ("Wrong motor mnemonic, check your %s.xml file.\n", GB_HO)
      return(-1)
    }
  }

  if (cnt_num(GB_PSLIT_CTMNE) == -1) {
    eprintf ("Wrong counter mnemonic %s, check your %s.xml file.\n", \
             GB_HO, GB_PSLIT_CTMNE)
    return(-1)
  }
  return(0)
}'

#%IU% ()
#%MDESC% Set the undulator motors and counter names. Return 0 if OK, -1 if any
#of the motors or the counter is not configured. If the GB_USE["silent"]
#not set, print the setup error messages.
def gb_u() '{
global GB_HO GB_USE[]
global GB_U_MNE GB_U_MOT GB_U_CTMNE
global GB_U_SAFETY GB_POS


   if (!GB_HO)
    GB_HO = "getbeam"

  GB_USE["undulator"] = xml_read(GB_HO, "/gb/undulator/data")
  if (GB_USE["undulator"] == -1) {
    if (GB_USE["silent"] == 0)
      printf( "Undulator not properly configured or not used.\n")
    return(-1)
  }

  GB_U_SAFETY = -1

  for (nn in XML_tmp[]["name"]) {
    if (XML_tmp[nn]["role"] == "motmne") {
      GB_U_MNE[XML_tmp[nn]["name"]] = XML_tmp[nn]["value"]
    } else if (XML_tmp[nn]["role"] == "ctmne") {
      GB_U_CTMNE = XML_tmp[nn]["value"]
    }
  }
  for (mmne in GB_U_MNE) {
    GB_U_MOT[mmne]=motor_num(GB_U_MNE[mmne])
    if (GB_U_MOT[mmne] == -1) {
      eprintf ("Wrong motor mnemonic, check your %s.xml file.\n", GB_HO)
      return(-1)
    }
  }
  if (cnt_num(GB_U_CTMNE) == -1) {
      eprintf ("Wrong counter mnemonic %s, check your %s.xml file.\n", \
               GB_HO, GB_U_CTMNE)
    return(-1)
  }
  return(0)
}'

#%IU% ()
#%MDESC% Set the energy motor name. Return 0 if OK, -1 if the motor is not
#configured.
def gb_en() '{
global GB_HO GB_USE[]
global GB_EN_MNE GB_EN_MOT

  if (!GB_HO)
    GB_HO = "getbeam"

  GB_USE["mono"] = xml_read(GB_HO, "/gb/energy/data")
  if (GB_USE["mono"] == -1) {
      printf( "Energy not properly configured, %s.xml file.\n", GB_HO)
    return(-1)
  }

  GB_EN_MNE = XML_tmp[0]["value"]
  GB_EN_MOT = motor_num(GB_EN_MNE)
  if (GB_EN_MOT == -1) {
    eprintf ("Wrong motor mnemonic, check your %s.xml file.\n", GB_HO) 
    return(-1)
  }
  return(0)
}'

#%IU% ()
#%MDESC% Set the calibration foils motor and counter names and positions.
#Return 0 if OK, -1 if the motors or the counter not configured. If the
#GB_USE["silent"] not set, print the setup error messages.
def gb_calibfoils() '{
global GB_HO GB_USE[]
global GB_CALIB_MOT GB_CALIB_MNE
global GB_CALIB_CTMNE GB_CALIB_LIST
local nn

  if (!GB_HO)
    GB_HO = "getbeam"

  GB_USE["foil"] = xml_read(GB_HO, "/gb/foil/data")
  if (GB_USE["foil"] == -1) {
    if (GB_USE["silent"] == 0)
      printf( "Calibration foils not properly configured or not used.\n")
    return(-1)
  }

  for (nn in XML_tmp[]["name"]) {
    if (XML_tmp[nn]["role"] == "motmne") {
      GB_CALIB_MNE = XML_tmp[nn]["value"]
    } else if (XML_tmp[nn]["role"] == "ctmne") {
      GB_CALIB_CTMNE = XML_tmp[nn]["value"]
    } else if (XML_tmp[nn]["role"] == "enlist") {
      GB_CALIB_LIST  = XML_tmp[nn]["value"]
    }
  }

  GB_CALIB_MOT = motor_num(GB_CALIB_MNE)
  if (GB_CALIB_MOT == -1) {
    eprintf ("Wrong motor mnemonic, check your %s.xml file.\n", GB_HO)
    return(-1)
  }

  if (cnt_num(GB_CALIB_CTMNE) == -1) {
    eprintf ("Wrong counter mnemonic, check your %s.xml file.\n", GB_HO)
    return(-1)
  }

  if (GB_CALIB_LIST == "") {
    eprintf ("Calibration foil list empy,check your %s.xml file.\n", GB_HO) 
    return(-1)
  }
  return(0)
}'

#%IU% ()
#%MDESC% Set the secondary slits motors and counter names. Return 0 if OK,-1 if
#any of the motors or the counter is not configured. If the GB_USE["silent"]
#not set, print the setup error messages.
def gb_sslit() '{
global GB_HO GB_USE[]
global GB_SSLIT_MNE[] GB_SSLIT_MOT[] GB_SSLIT_CTMNE
local nn

  if (!GB_HO)
    GB_HO = "getbeam"

  GB_USE["sslit"] = xml_read(GB_HO, "/gb/sslit/data")
  if (GB_USE["sslit"] == -1) {
    if (GB_USE["silent"] == 0)
      printf( "Secondary slits not properly configured or not used.\n")
    return(-1)
  }

  for (nn in XML_tmp[]["name"]) {
    if (XML_tmp[nn]["role"] == "motmne") {
      GB_SSLIT_MNE[XML_tmp[nn]["name"]] = XML_tmp[nn]["value"]
    } else if (XML_tmp[nn]["role"] == "ctmne") {
      GB_SSLIT_CTMNE = XML_tmp[nn]["value"]
  }
  for (mmne in GB_SSLIT_MNE) {
    GB_SSLIT_MOT[mmne]=motor_num(GB_SSLIT_MNE[mmne])
    if (GB_SSLIT_MOT[mmne] == -1) {
      eprintf ("Wrong motor mnemonic, check your %s.xml file.\n", GB_HO)
      return(-1)
    }
  }

  if (cnt_num(GB_SSLIT_CTMNE) == -1) {
    eprintf ("Wrong counter mnemonic %s, check your %s.xml file.\n", \
             GB_HO, GB_SSLIT_CTMNE)
    return(-1)
  }
  return(0)
}'

#%IU% ()
#%MDESC% Set the attenuators motor names and predefined positions.
#Return 0 if OK, -1 if the motors or the positions not configured. If the
#GB_USE["silent"] not set, print the setup error messages.
def gb_filters(key, curr) '{
global GB_HO GB_USE[]
global GB_FILTERS
local nn res

  if (!GB_HO)
    GB_HO = "getbeam"

  GB_USE["filter"] = xml_read(GB_HO, "/gb/filter")
  if (GB_USE["filter"] == -1) {
    if (GB_USE["silent"] == 0)
      printf( "Filters not properly configured or not used.\n")
    return(-1)
  }
  unglobal GB_FILTERS
  global GB_FILTERS
  xml_read(GB_HO, sprintf("/gb/filter/%s/data", key))

  if (curr > 0) {
    for (nn in XML_tmp[]["name"]) {
      if (curr > XML_tmp[nn]["curr"]) { 
        GB_FILTERS[key][XML_tmp[nn]["name"]] = XML_tmp[nn]["value"] * 1.0
      }
    }
  } else {
    for (nn in XML_tmp[]["name"]) {
      GB_FILTERS[key][XML_tmp[nn]["name"]] = XML_tmp[nn]["value"] * 1.0
    }
  }
  return(0)
}'

#%IU% (key, [key2])
#%MDESC% Set the slits predefined positions. Return 0 if OK, -1 if the
#positions not configured.
def gb_positions(key, key2) '{
global GB_HO
local nn mm

  if (!GB_HO)
    GB_HO = "getbeam"

  if (xml_read(GB_HO, "/gb/position") < 0) {
    eprintf ("No predefined positions, check your %s.xml file.\n", GB_HO)
    return(-1)
  }
  xml_read(GB_HO, sprintf("/gb/position/%s/data", key))
  if (key2) {
    for (nn in XML_tmp[]["type"]) {
      if (XML_tmp[nn]["type"] == key2) {
        mm = motor_num(XML_tmp[nn]["name"])
        if (mm < 0) {
          eprintf ("Motor %s not configured, exiting..\n",XML_tmp[nn]["name"])
          return(-1)
        } else {
          printf("Motor %s (%d) position set to %g\n", \
		XML_tmp[nn]["name"], mm, XML_tmp[nn]["value"])
          A[mm] = XML_tmp[nn]["value"]
        }
      }
    }
  } else {
    for (nn in XML_tmp[]["name"]) {
      mm = motor_num(XML_tmp[nn]["name"])
      if (mm < 0) {
        eprintf ("Motor %s not configured, exiting..\n",XML_tmp[nn]["name"])
        return(-1)
      } else {
        printf("Motor %s position set to %g\n", \
	  XML_tmp[nn]["name"], XML_tmp[nn]["value"])
        A[mm] = XML_tmp[nn]["value"]      
      }
    }
  }
}'

#%IU% (key)
#%MDESC% Get the predefined parameters for different procedures.
def gb_parameter(key) '{
global GB_HO GB_PARAMS[]
local nn mm

  if (!GB_HO)
    GB_HO = "getbeam"

  if (xml_read(GB_HO, "/gb/parameter") < 0) {
    eprintf ("No predefined parameters, check your %s.xml file.\n", GB_HO)
    return(-1)
  }
  unglobal GB_PARAMS
  global GB_PARAMS[]
  xml_read(GB_HO, sprintf("/gb/parameter/%s/data", key))
  for (nn in XML_tmp[]["name"]) {
    for (mm in XML_tmp[nn]) {
      if (asc(mm) != 95) {
        GB_PARAMS[XML_tmp[nn]["name"]][mm] = XML_tmp[nn][mm]
      }
    }
  }
}'

#%MACROS%
#%IMACROS%
#%DEPENDENCIES% %B%%B%
#%TOC%
#%AUTHOR% A.Beteva%BR%
#$Revision: 1.1 $$Date: 2013/05/31 08:36:58 $