esrf

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

#$Log: XEscan.mac,v $
#Revision 1.6  2022/03/22 10:13:37  witsch
#Somewhere after the change to arrayscans, the XEscan stopped working.
#The points would all plot at point X=0. Corrected.
#
#Revision 1.5  2013/02/06 15:49:20  witsch
#Bugfix by D.Wermeille:
#
#There is a macro XEscan to do Escan with different intervals similar to
#xascan or xdscan.
#This macro must have never been working with the fixQ option.
#The problem was all the parameters were eval, even fixQ when it was
#entered as the last parameter.
#I modified the macro (on BM28) so it is working.
#I just replace line 51 by:
#
#if(!sscanf(xepars[i],"%f",bidon) && xepars[i] != "fixQ") }
#
#and it works (on XMAS).
#
#Revision 1.4  2011/06/03 12:54:01  perez
# Allow mathematical expressions (without white spaces) as argins
#
#Revision 1.3  2008/09/29 08:17:33  perez
#Fix some cosmetic bugs
#
#Revision 1.2  2002/03/20 17:26:59  beteva
#Fixed a bug in XEscanf. Added more help.
#
#Revision 1.1  1996/09/27 10:21:00  lagier
#Initial revision
#
#%NAME%
#  XESCAN.MAC - Extended Escan: Variable point density.
#%DESCRIPTION%
#Energy scan for multiple consecutive energy regions, with equal or
#different step (variable point density).
#%EXAMPLE%
#%DT% XEscan 2 10 8 20 2 10 fixQ%BR%
#%DL%Does a Escan, with 8 points between 2 and 10 keV, and 2 points between
#10 and 20, integration time of 10 seconds and HKL constant.
#%END%

#%IU%
#%MDESC%
# Print out XEscan macro usage and exit
#
def XEscan_usage '{
 print "Usage: XEscan start end intervals [end intervals] time [fixQ]"
 print "       (repeat [end intervals] as many times you need)"
 print "       (Units are KeV)"
 print "       (the literal \"fixQ\" means keep HKL constant)"
 exit
}'


#%UU% start end1 intervals1 [end2 intervals2 ...] time ["fixQ"]
#%MDESC% Extended Escan. You can define as many ends and intervals as you want.
#If only one - does a normal Escan. The enrgy is in KeV, the time in s.
#The literal \"fixQ\" means keep HKL constant.
def XEscan '{
  global XEN XE_FIXQ
  local xepars
  local i

  XEN = split("$*",xepars)

  # Allow mathematical expressions (without white spaces) as argins
  for(i in xepars) {
#    if(!sscanf(xepars[i],"%f",bidon)) {
# Correction by D. Wermeille
    if(!sscanf(xepars[i],"%f",bidon) && xepars[i] != "fixQ") {
     xepars[i]=eval(sprintf("%s",xepars[i]))
    }
  }

  if (!XEN || XEN<4) { XEscan_usage }
  if (_XEchk(XEN,xepars[XEN-1])) { XEscan_usage }
  p xepars

  if ($#<=5) { Escan $* }
  else
   {
    _XEcalcsteps (xepars)
    HEADING = sprintf("$0 $*")

    if (XE_FIXQ) {
      _XEscan XE_START XE_FINISH XE_INTERVALS XE_TIME "fixQ"
     } else {
      _XEscan XE_START XE_FINISH XE_INTERVALS XE_TIME
   }
  }
}'

#%IU% (xepar,nbinp)
#%MDESC% Do extended energy scan with %B%xepar%B% parameters for
#%B%nbinp%B% inputs.
def XEscanf(xepar,nbinp) '{
  global XEN XE_FIXQ

  XEN = nbinp
  XE_FIXQ = 0
  _XEcalcsteps (xepar)
  HEADING = sprintf("XEscan %7.4f %7.4f %d %4.1f\n", \
            XE_START, XE_FINISH, XE_INTERVALS, XE_TIME)
  _XEscan XE_START XE_FINISH XE_INTERVALS XE_TIME
}'


#%IU% (no, v)
#%MDESC% Check the XEscan %B%no%B% - number of input parameters and
#set the fix HKL flag if %B%v%B% is \"fixQ\". Return 0 if OK, -1 if error.
def _XEchk (no,v) '{
local roin

  if (v=="fixQ") { XE_FIXQ=1 ; roin = (no-5)/2 }
  else { XE_FIXQ = 0 ; roin = (no-4)/2 }

  return ((roin == int (roin)) - 1)
}'

#%IU% (xepars)
#%MDESC% Fills in the global float array (XE_STEPS) with each scan steps.

def _XEcalcsteps (xepars) '{

  global XE_START XE_FINISH XE_INTERVALS XE_TIME
#  float array XE_STEPS [1000]

  local stepno argno totno

  totno = (XE_FIXQ)?XEN-2:XEN-1
  stepno = 0
  XE_INTERVALS = 0
  XE_START     = xepars [0]
  XE_FINISH    = xepars [totno-2]
  XE_TIME      = xepars [totno]


  for (argno=1 ; argno<totno ; argno+=2) {
    local sno
    sno = xepars[argno+1]
    if (sno <= 0) {
       print "Number of Intervals <= 0"
       exit
    }
    XE_INTERVALS += sno
  }
  float array XE_STEPS [XE_INTERVALS+1]
  XE_INTERVALS = 0
  XE_STEPS [0] = XE_START

  for (argno=1 ; argno<totno ; argno+=2) {
    local ssz sno

    sno = xepars[argno+1]
    XE_INTERVALS += sno
    ssz = (xepars[argno] - XE_STEPS[stepno])/sno

    for (;stepno<XE_INTERVALS;stepno++) {
      XE_STEPS[stepno+1] = XE_STEPS[stepno] + ssz
    }
  }
}'

#%IU% start finish intervals time [fixQ]
#%MDESC% Modified Escan.
def _XEscan '

  { _s1 = $1; _f1 = $2; _n1 = int($3); _ctime = $4; }

  if (_s1 <= 0 || _f1 <= 0) {
    print "Energy from",_s1,"to",_f1
    print "Can only deal with positive energies."
    exit
  }

  _bad_lim = 0
  _chk_mlim _s1
  _chk_mlim _f1
  if (_bad_lim) exit

  _d1 = (_f1 - _s1) / _n1++
  X_L = "Energy"
  Y_L = cnt_name(DET)
  _sx = _s1; _fx = _f1

  FPRNT=sprintf("Energy  %s  ",motor_name(Mono))
  PPRNT=sprintf("%9.9s %9.9s ", "Energy",motor_name(Mono))
  _stype = 1|(1<<8)
  _cols=2
  if (mono_type == 3 || mono_type == 4) {
    FPRNT=sprintf("%s%s  %s  ",FPRNT,\
                 motor_name(montrav),motor_name(mond))
                PPRNT=sprintf("%s%9.9s %9.9s ",PPRNT,\
                  motor_name(montrav),motor_name(mond))
    _stype = 1|(3<<8)
    _cols=4
  }
  VPRNT=PPRNT

  scan_head
  def _scan_on \'
    for (; NPTS < _n1; NPTS++) {
      local   E
      get_angles

      E = XE_STEPS [NPTS]

      calcM E; calcE

      if (XE_FIXQ) { calcA; }

      scan_move
      calcE; E = hc_over_e / LAMBDA
      FPRNT=sprintf("%g %g ",E,A[Mono])
      PPRNT=sprintf("%9.4f %9.4f ",E,A[Mono])
      if (mono_type == 3 || mono_type == 4) {
         FPRNT=sprintf("%s%9.4f %9.4f ",FPRNT,A[montrav],A[mond])
         PPRNT=sprintf("%s%9.4f %9.4f ",PPRNT,A[montrav],A[mond])
      }
      VPRNT=PPRNT
      scan_loop
      scan_plot
      scan_data(NPTS, E)
    }
    scan_tail
  \'
  _scan_on
'

#%MACROS%
#%IMACROS%
#%AUTHOR%
#  Marie-Claire LAGIER
#%TOC%
#$Revision: 1.6 $ $Date: 2022/03/22 10:13:37 $