esrf

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


#%TITLE% z3scan.mac
#%NAME%
#  z3scan
#%CATEGORY%
#%DESCRIPTION%
#  3 zone step scan
#%EXAMPLE%
# considering a m1 motor is defined:
#
#   z3scan m1 5 5 0.1 15 20 0.01 20 5 0.1 30
#
#%DL%
#%DT%XXXsetup%DD%
#%SETUP%
#%UL%
#%LI%
#%XUL%


global Z3_PAR[]
# Z3_PAR["mot_mne"]


#%UU% <mot_mne> <p1> <n1> <dt1> <p2> <n2> <dt2> <p3> <n3> <dt3> <p4>
#%MDESC%
#    Performs a step scan with one motor over 3 zones.
# A different number of intervals and counting time can be used for
# each zone.
def z3scan '{
    local _nb_param
    local z3_p1 z3_p2 z3_p3 z3_p4 z3_t1 z3_t2 z3_t3 z3_n1 z3_n2 z3_n3
    local z3_min z3_max z3_aux

    _nb_param = $#

    if (_nb_param != 11) {
        print "$0 : 3-zones step-scan"
        print "Usage : $0 <mot_mne> <start_position1> <nb_pts1> <count_time1>   <s2> <n2> <ct2>   <s3> <n3> <ct3>   <end_position>"
        exit
    }

    Z3_PAR["mot_mne"] = $1
    z3_p1  = $2
    z3_n1  = int($3)
    z3_t1  = $4
    z3_p2  = $5
    z3_n2  = int($6)
    z3_t2  = $7
    z3_p3  = $8
    z3_n3  = int($9)
    z3_t3  = $10
    z3_p4  = $11

    _check0 "$1"

    # Checks number of intervals.
    if ((z3_n1 == 0 )||(z3_n2 == 0)||(z3_n3 == 0)) {
        print "Intervals <= 0"
        exit
    }

    # Calcul of limits.
    z3_min =  99999999
    z3_max = -99999999

    if (z3_p1 > z3_max)
        z3_max = z3_p1

    if (z3_p1 < z3_min)
        z3_min = z3_p1

    if (z3_p2 > z3_max)
        z3_max = z3_p2

    if (z3_p2 < z3_min)
        z3_min = z3_p2

    if (z3_p3 > z3_max)
        z3_max = z3_p3

    if (z3_p3 < z3_min)
        z3_min = z3_p3

    if (z3_p4 > z3_max)
        z3_max = z3_p4

    if (z3_p4 < z3_min)
        z3_min = z3_p4

    # Check of limits.
    _bad_lim = 0
    _chk_lim Z3_PAR["mot_mne"] z3_min
    _chk_lim Z3_PAR["mot_mne"] z3_max

    if (_bad_lim){
        printf("Bad limits \n --> exit\n")
        exit
    }

    # Scan header.
    HEADING = sprintf("z3scan %s %g %d %g %g %d %g %g %d %g %g", "$1", \
                      z3_p1, z3_n1, z3_t1, z3_p2, z3_n2,                \
                      z3_t2, z3_p3, z3_n3, z3_t3, z3_p4)

    _cols = 1 + _hkl_col
    X_L = motor_name(Z3_PAR["mot_mne"])
    Y_L = cnt_name(DET)
    _sx = z3_min ; _fx = z3_max

    # Total number of points over the 3 zones.
    _n1 = z3_n1 + z3_n2 + z3_n3 +1

    FPRNT = PPRNT = VPRNT = ""
    FPRNT = sprintf("%s%s  ",   FPRNT, motor_name(Z3_PAR["mot_mne"]))
    PPRNT = sprintf("%s%8.8s ", PPRNT, motor_name(Z3_PAR["mot_mne"]))
    VPRNT = sprintf("%s%9.9s ", VPRNT, motor_name(Z3_PAR["mot_mne"]))

    FPRNT = sprintf("%s%s  ", FPRNT, _hkl_sym1)
    scan_head
    PFMT = sprintf("%%s%%8.%df ", UP)
    VFMT = sprintf("%%s%%9.%df ", UP)

    NPTS = 0

    # Zone 1:
    z3_aux = (z3_p2 - z3_p1)/z3_n1
    z3_scan_on Z3_PAR["mot_mne"] z3_p1 z3_p2 z3_n1 z3_t1 z3_aux

    # Zone 2:
    z3_aux = (z3_p3 - z3_p2)/z3_n2
    z3_scan_on Z3_PAR["mot_mne"] z3_p2 z3_p3 z3_n2 z3_t2 z3_aux

    # Zone 3:
    z3_aux = (z3_p4 - z3_p3)/z3_n3
    z3_n3++
    z3_scan_on Z3_PAR["mot_mne"] z3_p3 z3_p4 z3_n3 z3_t3 z3_aux
}'



#%IU% <motor_mne> <start_position> <end_position> <number_of_points> <count_time> <step size>
#%MDESC%
#    
def z3_scan_on '{
    local z3_n

    # motor ; start ; end
    _m[0] = $1; _s[0] = $2; _f[0] = $3

    # number of points ; counting time
    _n1 = $4; _ctime = $5

    # step size
    _d[0] = $6

    # number of motors
    _nm = 1
    z3_n = 0

    for (; z3_n < _n1; z3_n++, NPTS++) {
        local i

        for (i=0;i<_nm;i++){
            A[_m[i]] = _s[i] + z3_n * _d[i]
        }
        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
}'


#%MACROS%
#%IMACROS%
#%TOC%
#%DEPENDENCIES%
#%AUTHOR%  G.Berruyer
#%END%