esrf

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

#%TITLE% XSCANS.MAC
#%NAME%
#  Expanded scan versions of some standard %B%spec%B% scan macros
#
#%DESCRIPTION%
#  Expanded scan macros extend the range of standard scans, adding extra
#  points with an optionally different step size. The additional points are
#  placed symetrically at both sides of the `normal' scan range. The original
#  purpose of these macros was to explore in the same scan a central region
#  (a diffraction peak for instance) and the evolution of the background far
#  apart from it.%BR%
#  New: (16/Oct/1996) dmesh is available
#
#%OVERVIEW%
#  Names of expanded scan macros are formed by adding an initial 'x' to the
#  name of the corresponding standard macro.%BR%
#  These macros follow the syntax of the standard scan macros and in addition
#  accept two optional parameters %B%expansion%B% and %B%step_ratio%B%.
#  These parameters are stored in global variables and are not really optional:
#  if they are not entered explicitly, the last values are used.%BR%
#  The total scan range and the number of intervals after expansion is always
#  larger than the values entered in the macro call.%BR%
#  The range is expanded a factor approximately defined by the parameter
#  %B%expansion%B%. The step size in the expanded regions is exactly
#  %B%step_ratio%B% times the size in the central non-expanded part.%BR%
#  The actual total scan range and number of intervals is calculated
#  internally by the macros.
#
#%EXAMPLE%
#  xascan th -1 +1 20 1 5 8%BR% %BR%
#  This macro will scan the motor `th' taking data with a counting time of 1
#  second. The total scan range will extend from -5 to +5 (expansion=5).
#  There will be 20 intervals in the central range, [-1,+1], while in the
#  expanded regions, [-5,-1] and [+1,+5], the step size will be 8 times larger.
#%END%

__v_e_r_s_i_o_n_ = gsub("\\.", "", VERSION) + 0
if (__v_e_r_s_i_o_n_ > 60401) {
    eprint "\n\n*********************************************************"
    eprint "*********************************************************"
    eprint "This macro file *xscans.mac* cannot be used with SPEC versions later "
    eprint "than 6.04.01. Please take it out of your setup files!"
    eprint "Until then the setup will fail!!!!"
    eprint "*********************************************************"
    eprint "*********************************************************\n\n"
    exit
}
unglobal __v_e_r_s_i_o_n_

############# Defines and initializes global variables.
global _exp _sr
if (_exp < 1) _exp = 1
if (_sr <=0) _sr = 1

#%UU% motor <start> <finish> <intervals> <time> [<expansion>] [<step_ratio>]
#%MDESC%
#    Expanded version of the standard %B%ascan%B% macro.%BR%
#
def xascan '
    if ($# < 5 || $# > 7) {
        print "Usage:  xascan  motor start finish intervals time [expansion] [step_ratio]"
        exit
    }
    _check0 "$1"
    _m[0] = $1; _s[0] = $2; _f[0] = $3
    _n1= int($4); _ctime = $5
    if ($# > 5) {_exp = $6} else {print "Using expansion = " _exp}
    if ($# > 6) {_sr = $7} else {print "Using step rate = " _sr}
    _nm = 1
    _xascan
'

#%UU% mot1 <s1> <f1> <mot2> <s2> <f2> <intervals> <time> [<expansion>] [<step_ratio>]
#%MDESC%
#    Expanded version of the standard %B%a2scan%B% macro.%BR%
#
def xa2scan '
    if ($# < 8 || $# > 10) {
        print "Usage:  xa2scan mot1 s1 f1 mot2 s2 f2 intervals time
[expansion] [step_ratio]"
        exit
    }
    _check0 "$1"; _check0 "$4"
    _m[0] = $1; _s[0] = $2; _f[0] = $3
    _m[1] = $4; _s[1] = $5; _f[1] = $6
    _n1 = int($7); _ctime = $8
    if ($# > 8) {_exp = $9} else {print "Using expansion = " _exp}
    if ($# > 9) {_sr = $10} else {print "Using step rate = " _sr}
    _nm = 2
    _xascan
'

#%UU% mot1 <s1> <f1> <mot2> <s2> <f2> <mot3> <s3> <f3> <int> <time> [<exp.>] [<step_ratio>]
#%MDESC%
#    Expanded version of the standard %B%a3scan%B% macro.%BR%
#
def xa3scan '
        if ($# < 11 || $# > 13) {
            print "Usage:  xa3scan mot1 s1 f1 mot2 s2 f2 mot3 s3 f3 int time [exp.] [step_ratio]"
            exit
        }
        _check0 "$1"; _check0 "$4"; _check0 "$7"
        _m[0] = $1; _s[0] = $2; _f[0] = $3
        _m[1] = $4; _s[1] = $5; _f[1] = $6
        _m[2] = $7; _s[2] = $8; _f[2] = $9
        _n1 = int($10); _ctime = $11
        if ($# > 11) {_exp = $12} else {print "Using expansion = " _exp}
        if ($# > 12) {_sr = $13} else {print "Using step rate = " _sr}
        _nm = 3
        _xascan
'


#%UU% motor <m1> <s1> <f1> <m2> <s2> <f2> <m3> <s3> <f3> <m4> <s4> <f4> <int> <time> [<exp.>] [<step_ratio>]
#%MDESC%
#    Expanded version of the standard %B%a4scan%B% macro.%BR%
#
def xa4scan '
    if ($# < 14 || $# > 16) {
        print "Usage: xa4scan m1 s1 f1 m2 s2 f2 m3 s3 f3 m4 s4 f4 int time [exp.] [step_ratio]"
        exit
    }
    _check0 "$1"; _check0 "$4"; _check0 "$7"; _check0 "$10"
    _m[0] = $1; _s[0] = $2; _f[0] = $3
    _m[1] = $4; _s[1] = $5; _f[1] = $6
    _m[2] = $7; _s[2] = $8; _f[2] = $9
    _m[3] = $10; _s[3] = $11; _f[3] = $12
    _n1 = int($13); _ctime = $14
    if ($# > 14) {_exp = $15} else {print "Using expansion = " _exp}
    if ($# > 15) {_sr = $16} else {print "Using step rate = " _sr}
    _nm = 4
    _xascan
'


#%UU% motor <start> <finish> <intervals> <time> [<expansion>] [<step_ratio>]
#%MDESC%
#    Expanded version of the standard %B%dscan%B% macro.%BR%
#
def xdscan '
    if ($# < 5 || $# > 7) {
        print "Usage:  xdscan motor start finish intervals time [expansion] [step_ratio]"
        exit
    }
    _check0 "$1"
    if ($# > 5) {_exp = $6} else {print "Using expansion = " _exp}
    if ($# > 6) {_sr = $7} else {print "Using step rate = " _sr}
    waitall
    get_angles
    _c1=A[$1]

    local cleanstr
    cleanstr = sprintf("dscan_cleanup $1 %s;", _c1)
    cdef("cleanup_once", cleanstr, "dscan")

    xascan "$1" _c1+($2) _c1+($3) $4 $5 _exp _sr

    cdef("cleanup_once", "", "dscan", "delete")
    eval(cleanstr)
'


#%UU% motor <start> <finish> <intervals> <time> [<expansion> [<step_ratio> [<thrhold>]]]
#%MDESC%
#  Expanded version of the %B%lineup%B% macro.%BR%
#  The peak position is determined according to the `LUPmode' variable
#  that can be modified with the %B%lupsetup%B% macro. The %B%lineup%B% and
#  %B%lupsetup%B% macros are defined in the `lineup.mac' macro file.%BR%
#  An optional parameter <thrhold> forces the macro to further checks.
#  If the peak value is lower than the threshold value the macro prints a
#  `No peak found' error. If <thrhold> is negative the actual threshold is
#  the absolute value of <thrhold>.
#  If <thrhold> is positive the counters are run one time interval before
#  starting the scan and the threshold value is calculated by multiplying
#  <thrhold> by the detector counts. In other words positive values of
#  <thrhold> are relative thresholds.

#
def xlineup '{
    local newPK new_pos nps threshold myDET

    if ($# < 5 || $# > 8) {
        print "Usage:  xlineup motor start finish interv time [expan. [step_ratio [thrsh]]]"
        exit
    }

    if (!(whatis("lupsetup") & 0x2)) {
        print "You need to load \`lineup.mac\' before using this macro."
        exit
    }

    _check0 "$1"
    if ($# > 5) {_exp = $6} else {print "Using expansion = " _exp}
    if ($# > 6) {_sr = $7} else {print "Using step rate = " _sr}
    waitall
    get_angles
    _c1=A[$1]

    cdef("cleanup_once", sprintf("if (LUPbg) BG=_c2; dscan_cleanup $1 %s;", _c1), "dscan")

    if (PLOT_MODE&2048)
        myDET = PLOT_LIST[0]
    else
        myDET = DET

    if ($# > 7) {
        if (($8) > 0) {
            count $5
            threshold = ($8)*S[myDET]
        } else {
            threshold = fabs($8)
        }
        printf("\nPeak threshold for `%s\' (%s): %g\n\n", \
                cnt_name(myDET), cnt_mne(myDET), threshold)
    } else {
        printf("\nUsing `%s\' (%s). No peak threshold.\n", \
                cnt_name(myDET), cnt_mne(myDET))
    }

    if (LUPbg) {
        _c2=BG
        setplot +64
    }
    xascan "$1" _c1+($2) _c1+($3) $4 $5 _exp _sr

    newPK = pl_xMAX
    cdef("cleanup_once", "", "dscan", "delete")
    if ((newPK <= (_c1+($2)-(($3)-($2))/($4)*_n2*_sr)) || \
       (newPK >= (_c1+($3)+(($3)-($2))/($4)*_n2*_sr)) || \
       ($# > 7 && pl_MAX < threshold)){
        printf("\nNo peak found !")

        local cleanstr
        cleanstr = sprintf("dscan_cleanup $1 %s;", _c1)
        eval(cleanstr)
    } else {
        if (LUPmode == "COM") {new_pos = pl_COM; nps=LUPmode}
        else if (LUPmode == "CEN") {new_pos = pl_CFWHM,nps=LUPmode}
        else {new_pos = pl_xMAX; nps="peak"}

        printf("\nMoving %s to %s at %g\n", motor_name($1), nps, new_pos)

        onp; offt
        printf("\nmv $1 %g\n",new_pos)
        offp; ont
        waitmove; get_angles; A[$1]=new_pos
        _move
        printf("\n")
    }
    if (LUPbg) BG=_c2
}'


#%IU%
#%MDESC%
#    Expanded version of the %B%_ascan%B% macro.%BR%
#
def _xascan '
    if (_n1 <= 0) {
        print "Intervals <= 0"
        exit
    }
    if (_exp < 1) {
        print "Expansion < 1"
        exit
    }
    if (_sr <= 0) {
        print "Step ratio <= 0"
        exit
    }
    _n2 = int((_exp-1)*_n1/2/_sr)
    if (_n2 == 0) _n2=1
    {
        local i
        for (i=0;i<_nm;i++) {
            _bad_lim = 0
            _chk_lim _m[i] (_s[i]-(_f[i]-_s[i])/_n1*_sr*_n2)
            _chk_lim _m[i] (_f[i]+(_f[i]-_s[i])/_n1*_sr*_n2)
            if (_bad_lim) exit;
        }
    }
    HEADING=_nm>1? sprintf("xa%dscan ", _nm):"xascan "
    {
        local i
        for (i=0;i<_nm;i++) {
            HEADING=sprintf("%s%s",HEADING,sprintf(" %s %g %g ",\
            motor_mne(_m[i]),_s[i],_f[i]))
            _d[i] = (_f[i] - _s[i]) / _n1
        }
    }
    HEADING=sprintf("%s %g %g %g %g",HEADING,_n1,_ctime,_exp,_sr)
    _n1 += 2*_n2+1
    _cols=_nm+_hkl_col
    X_L = motor_name(_m[0])
    Y_L = cnt_name(DET)
    _sx = (_s[0]-_n2*_d[0]*_sr)
    _fx = (_f[0]+_n2*_d[0]*_sr)
    _stype = 1|(_nm<<8)
    FPRNT=PPRNT=VPRNT=""
    {
        local i
        for (i=0;i<_nm;i++) {
            FPRNT=sprintf("%s%s  ",FPRNT,motor_name(_m[i]))
            PPRNT=sprintf("%s%8.8s ",PPRNT,motor_name(_m[i]))
            VPRNT=sprintf("%s%9.9s ",VPRNT,motor_name(_m[i]))
        }
    }
    FPRNT=sprintf("%s%s  ",FPRNT,_hkl_sym1)
    scan_head
    PFMT=sprintf("%%s%%8.%df ",UP)
    VFMT=sprintf("%%s%%9.%df ",UP)
    def _scan_on \'
        for (; NPTS < _n1; NPTS++) {
        local i
        for (i=0;i<_nm;i++){
            if (NPTS < _n2)
                A[_m[i]] = _s[i] - (_n2 - NPTS) * _d[i] * _sr
            else { if (NPTS < _n1-_n2)
                A[_m[i]] = _s[i] + (NPTS - _n2) * _d[i]
            else
                A[_m[i]] = _f[i] + (NPTS - (_n1-_n2-1)) * _d[i] * _sr
            }
        }
        scan_move
        FPRNT=PPRNT=VPRNT=""
        for (i=0;i<_nm;i++) {
            FPRNT=sprintf("%s%.8g ",FPRNT,A[_m[i]])
            PPRNT=sprintf(PFMT,PPRNT,A[_m[i]])
            VPRNT=sprintf(VFMT,VPRNT,A[_m[i]])
        }
        FPRNT=sprintf("%s%s ",FPRNT,_hkl_val)
        scan_loop
        scan_data(NPTS, A[_m[0]])
        scan_plot
        }
        scan_tail
    \'
    _scan_on
'

#
# Macro added by R.Pinck on 16/Oct/1996
# changed by Holger to use cleanup_once as done by Pablo for all the others :-(
# for relative mesh scans. Syntax is like dscan but with mesh
#%UU% two-motor relative mesh cscan
#%MDESC% for relative mesh scans. Syntax is like dscan but with mesh
def dmesh '
    if ($# != 9) {
        print "Usage:  dmesh  mot1 s1 f1 intervals1  mot2 s2 f2 intervals2  time"
        exit
    }
    _check0 "$1"; _check0 "$5"
    waitall
    get_angles
    _c1=A[$1]
    _c2=A[$5]

    local cleanstr
    cleanstr = sprintf("dscan_cleanup $1 %s $5 %s;", _c1, _c2)
    cdef("cleanup_once", cleanstr, "dscan")

    mesh "$1" _c1+($2) _c1+($3) $4 "$5" _c2+($6) _c2+($7) $8 $9

    cdef("cleanup_once", "", "dscan", "delete")
    eval(cleanstr)
'


#%MACROS%
#%IMACROS%
#%DEPENDENCIES%
#  The file `lineup.mac' has to be loaded if you want to use %B%xlineup%B%.
#%AUTHOR% P. Fajardo, (Original 4/94).
#  $Revision: 3.4 $ / $Date: 2017/10/19 14:31:55 $
#%TOC%