#%TITLE% LTSCAN.MAC
#%NAME% Macros for lookup scan
#
#%CATEGORY% Scans
#
#%LOG%
#$Revision: 1.6 $
#
#%DESCRIPTION%
# Those macros provide users a lookup scan posibility on n motors
#%OVERVIEW%
# There is two external macro :%BR%%BR%
#%DL%
#%DT% ltinit : %DD%initilise global variable for each motor
#%DT% ltscan : %DD%start scan on motor
#%XDL%
#%SETUP%
#%DL%
#%DT% ltinit mot1 mot2...motn
#%DD% It initialise global variable LT_START,LT_STOP,LT_LINE and
# one array for each motors motname_ltscan_arr.
#%DL% Global variable description:
#%DT% LT_START
#%DD% is a long array which index line start position in the motors array
#%DT% LT_STOP
#%DD% is a long array which index line stop position in the motors array
#%DT% LT_LINE
#%DD% the number of line in the scan sizeof(LT_STOP|LT_START) or less
#%DT% <motorname>_ltscan_arr
#%DD% is a motor float array position
#%XDL%
#%DL%
#%DT% ltscan mot1 mot2...motn ctime
#%DD% start scan on motors : mot1 mot2... motn. Count time is given by
# ctime,which if positive, specifies seconds and if negative,
# specifies monitor counts.
#%EXAMPLE%
#%DL%
#%DT% ltscan samy samz 0.5 with this global :
# LT_START = [0,4]
# LT_STOP = [3,6]
# LT_LINE = 2
# samy_lscan_arr = [0,1,2,3,4,5,6,7]
# samz_ltscan_arr = [7,6,5,4,3,2,1,0]
#
# this will scan 2 lines;
# first 0..3 is [(0,7), (1,6), (2,5), (3,4)] and
# the second 4..6 is [(4,3), (5,2), (6,1), (7,0)]
#%XDL%
#%IU% <parma>
#%MDESC%
#
def _ltscan '{
{
_n1 = 0
local i
for(i = 0 ; i < LT_LINE ; ++i)
{
local nbPoint
startpos = LT_START[i]
stoppos = LT_STOP[i]
# ??
if(stoppos < startpos)
nbPoint = startpos - stoppos
else
nbPoint = stoppos - startpos
# Beuurk
_n1 += nbPoint + 1
}
}
HEADING = _nm>1? sprintf("lt%dscan ", _nm):"ltscan "
{
local i
for (i=0;i<_nm;i++) {
HEADING=sprintf("%s%s", HEADING, sprintf(" %s ", motor_mne(_m[i])))
}
}
HEADING=sprintf("%s %g %g", HEADING, _n1, _ctime)
FPRNT = PPRNT = VPRNT = ""
_cols = _nm + _hkl_col
{
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)
{
local lineId
local startIndex
local stopIndex
for (lineId = 0 ; lineId < LT_LINE ; ++lineId)
{
global LTSCAN_INDEX
LTSCAN_INDEX = LT_START[lineId]
stopIndex = LT_STOP[lineId]
if (startIndex >= stopIndex)
{
for (;LTSCAN_INDEX >= stopIndex;--LTSCAN_INDEX)
{
_ltscan_core
}
}
else
{
for (;LTSCAN_INDEX <= stopIndex;++LTSCAN_INDEX)
{
_ltscan_core
}
}
}
}
}'
# init stub macro.
cdef("_ltscan_core", "", "")
#%IU% <parma>
#%MDESC%
# Called in _ltscan via _ltscan_core
def _ltscanonepoint '{
#$*
local i
for (i=0 ; i<_nm ; i++)
{
local mne_arr
# Sets trarget value for i-th motor.
mne_arr = sprintf("%s_ltscan_arr",motor_mne(_m[i]))
A[_m[i]] = @mne_arr[LTSCAN_INDEX]
}
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
++NPTS
}'
#%UU% <motor1> .. <motorn> <ctime>
#%MDESC%
#
def ltscan '{
if ($# < 2) {
eprint "Usage : ltscan motor1... motorn ctime"
exit
}
{
#CHECK
local nb_motor
local m_names
local indMaxStart
local indMaxStop
local indMax
# ??
if(!(whatis("LT_START") & 0x80000004))
{
if(!whatis("LT_START")){
eprint "There is no array LT_START"
}
else{
eprint "LT_START is not an array"
}
exit
}
if(!(whatis("LT_STOP") & 0x80000004)){
if(!whatis("LT_STOP")) {
eprint "There is no array LT_STOP"
}
else{
eprint "LT_STOP is not an array"
}
exit
}
# ??
indMaxStart = array_op("max", LT_START)
indMaxStop = array_op("max", LT_STOP)
print "indMaxStart=" indMaxStart " indMaxStop="indMaxStop
# beurk:
# indMax is the max of the 2...
if(indMaxStart > indMaxStop){
indMax = indMaxStart
}
else{
indMax = indMaxStop
}
print "indMax="indMax
# time is the last param.
nb_motor = split("$*", m_names)
nb_motor -= 1
_ctime = m_names[nb_motor]
local i
# ??
# _m ??
# _nm ??
# long array _m[nb_motor] # do NOT declare _m here as it is already correctly
# defined as associative array in standard.mac
_nm = nb_motor
for(i = 0; i < nb_motor; ++i) {
local m_name
m_name = m_names[i]
if(m_name != motor_mne(@m_name)) {
eprint sprintf("Invalide motor name : %s", m_name)
exit
}
local motorArray
motorArray = sprintf("%s_ltscan_arr", m_name)
if(!(whatis(motorArray) & 0x80000004)) {
if(!whatis(motorArray)){
eprint sprintf("There is no array (%s) motor position for %s motor", \
motorArray, m_name)
}
else{
eprint sprintf("%s is not an array", motorArray)
}
exit
}
local motorArraySize
motorArraySize = array_op("cols", @motorArray)
if(motorArraySize < indMax)
{
eprint printf("position-array size of motor \"%s\" is smaller (%d) than the index max (%d) \n", \
m_name, motorArraySize, indMax)
exit
}
# ??
_m[i] = @m_name
}
{
local startsize
local stopsize
startsize = array_op("cols", LT_START)
stopsize = array_op("cols", LT_STOP)
if(stopsize < LT_LINE || startsize < LT_LINE)
{
eprint "array size < number of lines (LT_LINE)"
print "startsize="startsize " stopsize="stopsize
exit
}
}
_ltscan
}
}'
#%UU% <mot1> ... <motN>
#%MDESC%
#
def ltinit '{
local _nb_param
_nb_param = $#
if (!_nb_param) {
eprint "ltinit motor1 ... motorn"
exit
}
_ltinit(_nb_param, "$*")
}'
#%IU% <parma>
#%MDESC%
#
def _ltinit(argc, argv) '{
local m_names
local nb_motor
nb_motor = split(argv, m_names)
for(i = 0;i < argc;++i) {
local m_name
m_name = m_names[i]
if(m_name != motor_mne(@m_name)) {
eprint sprintf("Invalid motor name : %s", m_name)
exit
}
local arr_name
arr_name = sprintf("%s_ltscan_arr", m_name)
global double array @arr_name[1]
}
global long array LT_START[1]
global long array LT_STOP[1]
global LT_LINE
cdef("_ltscan_core", "_ltscanonepoint\n", "_ltscan")
}'
#%IU% <parma>
#%MDESC%
#
def ltinit_datacol '{
if($# < 6) {
print "Usage: $0 phistart deltaphi nframes time nsweeps motor1 ... motorn"
exit
}
local nb_arg
local arg_name
nb_arg = split("$*", arg_name)
local nb_motors
nb_motors = nb_arg - 5
local motor_list
local i
for(i=5 ; i < nb_arg ; ++i){
motor_list = sprintf("%s %s", motor_list, arg_name[i])
}
_ltinit(nb_motors, motor_list)
cmd = sprintf("_ltDataCol %lf %lf %d %lf %d\n", \
arg_name[0], arg_name[1], arg_name[2], arg_name[3], arg_name[4])
cdef("_ltscan_core", cmd, "_ltscan")
}'
#%IU% <parma>
#%MDESC%
#
def _ltDataCol '{
local i
for (i=0 ; i<_nm ; i++) {
local mne_arr
mne_arr = sprintf("%s_ltscan_arr", motor_mne(_m[i]))
A[_m[i]] = @mne_arr[LTSCAN_INDEX]
}
scan_move
datacol $1 $2 $3 $4 $5
}'
#%UU% <parma>
#%MDESC%
#
def ltscan_test '{
local arr_name_mot1 arr_name_mot2
local _mne_mot1 _mne_mot2
_mne_mot1 = "jetx"
_mne_mot2 = "jetz"
ltinit jetx jetz
_nb_points = 35
# Number of line in the scan sizeof(LT_STOP|LT_START) or less
LT_LINE = 1
# array which index line start position in the motors array
LT_START[0] = 0
# array which index line stop position in the motors array
LT_STOP[0] = _nb_points - 1
# array containing points to scan.
arr_name_mot1 = sprintf("%s_ltscan_arr", _mne_mot1)
arr_name_mot2 = sprintf("%s_ltscan_arr", _mne_mot2)
print "arr_name_mot1 : " arr_name_mot1 " arr_name_mot2 : " arr_name_mot2
#double array @arr_name_mot1[_nb_points][1]
# double array @arr_name_mot2[_nb_points][1]
double array @arr_name_mot1[_nb_points]
double array @arr_name_mot2[_nb_points]
print "Fills LT arrays"
for (ii=0 ; ii< _nb_points ; ii++){
@arr_name_mot1[ii] = ii
@arr_name_mot2[ii] = ii
#@arr_name_mot1[ii][1] = ii
#@arr_name_mot2[ii][1] = ii
}
print "arrays:"
print "arr_name_mot1 "
print @arr_name_mot1
print ""
print "arr_name_mot2 "
print @arr_name_mot2
printf ("Scanning points %d to %d \n", LT_START[0], LT_STOP[0])
print "---------------------------------------"
ltscan jetx jetz 0.1
}'
|