#%TITLE% ondulator.mac
#%NAME%
# Reads and sets the gap and phase of the ondulator
#
#%CATEGORY% Obsolete
#
#%SETUP%
# In the current setup your computer must have access to aries (where the
# data base is running) and draco (where the device server runs). You need
# the external programs getgap and setgap in your path (See A.Goetz CSS
# for that.
#
#%END%
#%UU% [phase device name]
#%MDESC% Macro to setup the phase macros for the hel. ondulator. The
# device name on aries which controls the phase has to be entered
# (for example: fe/id/16)
def gapsetup '
{
global PHASEHOST PHASENETHOST PHASEDEV PHASE_R PHASE_W1 PHASE_W2
global PHASE_MNE PHASE_NO
local _p n ii jj
PHASEHOST = "aries" # Machine computer
if ($#) {
n=split("$*",_p);
PHASEDEV = _p[0]
PHASE_NO=int((n-1)/4)
for (ii=0,jj=0;ii<n-4;ii+=4,jj++) {
PHASE_MNE[jj]= _p[ii+1];
PHASE_R[jj] = _p[ii+2]; PHASE_W1[jj] = _p[ii+3]; PHASE_W2[jj] = _p[ii+4];
}
} else {
PHASEDEV = getval("Enter the front end dev name (Ex: fe/id/16)" ,PHASEDEV)
PHASE_NO = getval("Enter the number of gaps or phases to define",PHASE_NO)
for (ii=0,jj=0;ii<4*PHASE_NO;ii+=4,jj++) {
PHASE_MNE[jj] = getval(\
"Enter an identifier (mnemonic) for this gap/phase",PHASE_MNE[ii])
PHASE_R[jj] = getval(\
"Enter the axe number (starts at 1 for first carriage)",PHASE_R[ii])
PHASE_W1[jj] = getval(\
"Enter number of insertion device carriage (starts at 1)",PHASE_W1[ii])
PHASE_W2[jj] = getval(\
"Enter the axe number on this carriage (starts at 1)",PHASE_W2[ii])
}
}
} '
#%IU% <gap spec index> <variable for phase>
#%MDESC% Reads the phase on defined gap/phase with index <gap spec index>
# and puts it in variable <variable for phase>.
def phase_read '{
local line tempfile
tempfile = "/tmp/bla_phase"
unix(sprintf("sh -c \"NETHOST=%s; export NETHOST; getgap %s %d>%s \" ",\
PHASEHOST, PHASEDEV, PHASE_R[$1] ,tempfile))
line = getline(tempfile)
# sscanf(line,"%*s %*s %f",$2)
sscanf(line,"%f",$2)
getline(tempfile,"close")
unix(sprintf("rm -f %s",tempfile))
}'
#%UU% [phase/gap mnemonic]
#%MDESC% Reads the ondulator phase and writes the result on the screen
# and in the data file.
def getond '
{
global PHASE PHASEIDX
phase_findindex PHASEIDX "$*"
phase_read PHASE
printf("#C %s. The %s is at %f.\n", date(),PHASE_MNE[PHASEIDX] , PHASE)
if (DATAFILE != "")
fprintf(DATAFILE,\
"#C %s. The %s is at %f.\n", date(),PHASE_MNE[PHASEIDX], PHASE)
}
'
#%IU% <idx-variable> <user-entry>
#%MDESC% Finds the index in the internal array from user-entry.
def phase_findindex '
{
local ii _intidx
_intidx = $1
if (("$2" == "0") || ("$2" == "")) {
if (PHASE_NO == 1) {
_intidx = 0
} else {
for (ii=0;ii<PHASE_NO;ii++) {
printf("%3d: %10s",ii+1,PHASE_MNE[ii])
}
_intidx = getval("\nEnter a number to choose gap/phase",_intidx+1)-1
}
} else {
_intidx = -1;
for (ii=0;ii<PHASE_NO;ii++) {
if ("$2" == PHASE_MNE[ii]) {
_intidx = ii ;
break;
}
}
}
if ((_intidx >= PHASE_NO ) || (_intidx < 0)) {
print "Gap/phase not defined - Run gapsetup !"
exit
}
$1 = _intidx
}'
#%UU% [gap/phase-mnemonic] [gap/phase]
#%MDESC% Sets the ondulator gap with identifier [gap/phase-mnemonic]
# to [gap/phase].
def setond '{
global PHASESET PHASEIDX
if ($# == 0) {
phase_findindex PHASEIDX "0"
PHASESET = getval(\
sprintf("Enter value to set %s",PHASE_MNE[PHASEIDX]),PHASESET)
} else if ($# == 1) {
if (PHASE_NO == 1)
PHASESET = $1
else {
p "Usage: $0 [gap/phase-mnemonic] [gap/phase-value]"
exit
}
} else {
phase_findindex PHASEIDX "$1"
PHASESET = $2
}
unix(sprintf("sh -c \"NETHOST=%s; export NETHOST; setgap %s %d %d %f \" ",\
PHASEHOST,PHASEDEV,PHASEIND_W1[PHASEIDX],PHASEIND_W2[PHASEIDX],PHASESET))
}'
#%UU <gap/phase-mnemonic> <phase to wait for> [timeout in s]
#%MDESC% wait until phase has changed to <phase to wait for>, or
# timeout has been reached.
def waitphase '{
local starttime timeout actphase newphase idx
phase_findindex idx "$1"
newphase = $2 ; timeout = $3
starttime = time ()
for (;;) {
phase_read actphase
if (fabs(actphase - newphase) < .1)
break;
sleep (10)
if ((timeout > 0) && (timeout < (time()-starttime))) {
printf("* Timed out while waiting for ond. phase to be %f (is %f now)\n"\
,newphase,actphase)
break;
}
}
}'
#%MACROS%
#%IMACROS%
#%AUTHOR% JK May 95
|