#! /bin/tcsh -f # # move a motor in the beamline # # goto Setup Help: cat << EOF usage: $0 motorname goal where: motorname is one of: example: $0 Mono eV 12398.42 EOF exit 9 Return_from_Setup: # interpret command line set motor = `echo $* | awk '{for(i=1;i<=NF;++i) if($i !~ /^[0-9\.-]/ || $(i-1)=="Line") print $i}'` set goal = `echo $* | awk '$NF~/^[0-9\.-]/ && $(NF-1) != "Line"{print $NF+0}'` # translate between Ed's incompatible whimsy if($beamline == 1231) then if("$motor" == "Iend") set motor = "PX Iend" if("$motor" == "Izero") set motor = "PX Izero" if("$motor" == "Aperture Line 7") set motor = "Aperture Line 11" if("$motor" == "Aperture Line 9") set motor = "Aperture Line 1" if("$motor" == "Aperture Outboard") set motor = "Aperture Line 11" if("$motor" == "Aperture Inboard") set motor = "Aperture Line 1" if("$motor" == "Mono eV with z") set motor = "Mono eV" else if("$motor" == "PX Iend") set motor = "Iend" if("$motor" == "PX Izero") set motor = "Izero" if("$motor" == "Aperture Line 11") set motor = "Aperture Line 7" if("$motor" == "Aperture Line 1") set motor = "Aperture Line 9" if("$motor" == "Aperture Outboard") set motor = "Aperture Line 7" if("$motor" == "Aperture Inboard") set motor = "Aperture Line 9" endif # check for alternate beamline scheme if("$beamline" =~ 50?) then # Oh, hmmm.... goto five_stuff endif # check for problems if("$motor" == "") goto Help if("$goal" == "") goto report # send the move command to the frontend echo "moveto $motor $goal\r" | sock_exchange.tcl $host 10001 1 > /dev/null # wait a tic... usleep 100000 set timeout = 600 while ( `echo "getstat $motor\r" | sock_exchange.tcl $host 10001 1 | awk '{print ($1+0 == 1)}'` ) if("$motor" =~ *Tune*) then @ timeout = ( $timeout - 1 ) if($timeout == 0) then echo "stop $motor\r" | sock_exchange.tcl $host 10001 1 >& /dev/null echo "stop $motor\r" | sock_exchange.tcl $host 10001 1 >& /dev/null set BAD = "taking too long" break endif echo -n "." endif usleep 500000 end report: echo -n "$motor is now at " again: set tout = 1 if("$beamline" =~ 831 || "$beamline" =~ 1231) set tout = 30 set value = `echo "getpos $motor\r" | sock_exchange.tcl $host 10001 1 "" $tout | awk '/^Inf/{print "Inf"; exit} /^[0-9\.-]/{print substr($1,1,index($1,"!")-1); exit} {print "unknown value"}'` if("$value" == "Inf" && ( "$motor" =~ *Iend || "$motor" =~ *Izero || "$motor" =~ *"Beam Position"* )) then set test = `echo "autoon\r" | sock_exchange.tcl $host 10001 1 | awk '{print /Local/}'` if("$test" != "0") then set BAD = "unable to scale $motor" set value = "off-scale" goto finish endif set autoscaling usleep 500000 goto again endif if($?autoscaling) then echo "autooff\r" | sock_exchange.tcl $host 10001 1 > /dev/null endif if("$value" == "") then set BAD = "unable to read $motor" set value = "unknown value" endif finish: echo "$value" # come up with some kind of "epsilon" for a successful move set delta = `echo $value $goal | awk '{print sqrt(($1*$2)^2)/1000}' | awk '$1<0.001{$1=1} {print}'` set error = `echo $value $goal | awk '{print sqrt(($1-$2)^2)}'` set reached = `echo "$error $delta" | awk '{print ($1+0<$2+0)}'` if(! $reached && "$goal" != "" && "$motor" !~ Tune*) then set BAD = "|$value - $goal| = $error > $delta" endif if($?BAD) then echo "ERROR: $BAD" exit 9 endif exit five_stuff: set thishost = `hostname | awk -F "[\.]" '{print $1}'` if("$beamline" =~ 50?) then if("$thishost" == "bl${beamline}c") then set wago = ( wago-2 80 ) else # try to connect to the wago... #ssh -x -f -L 10080:wago-2:80 bl${beamline}c "sleep 99999" set wago = ( localhost 10080 ) endif endif # retreive the "beam pass" status from 5.0.x echo "GET /status.shtml HTTP/1.1\r" |\ sock_exchange.tcl $wago |\ awk '{gsub("[\r\t]","",$0); print $0}' |\ awk '{for(i=1;i<=length($0);++i) {c=substr($0,i,1); ccc=substr($0,i,3);\ if(c == "<") ++tag; \ if (ccc=="") --tag}}' |\ awk 'NF>0' |\ awk '/Digital inputs/,/Analog/{print}' |\ cat >! ${tempfile} set bits = `awk 'NF==8{print}' $tempfile` rm -f ${tempfile} set beamon_bit if($#bits == 8) then set beamon_bit = $bits[1] endif if("$beamon_bit" == "1") then echo "got beam 1" endif if("$beamon_bit" == "0") then echo "no beam 0" endif exit Setup: ############################################################# # platform-specific issues set test = `echo "123asdf" | awk '{print $1+0}'` if("$test" != "123") then alias awk nawk set test = `echo "123asdf" | awk '{print $1+0}'` if("$test" != "123") alias awk gawk set test = `echo "123asdf" | awk '{print $1+0}'` if("$test" != "123") then echo "ERROR: awk no good" exit 9 endif endif set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) then alias echo /bin/echo set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) alias echo '/bin/echo -e' set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) alias echo /usr/bin/echo set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) alias echo '/bin/echo \!* | awk '\''/^-n/{printf "%s", substr($0,4) ; exit} {print}'\' set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) then echo "ERROR: echo command is broken" exit 9 endif endif set test = `echo "string is digit 1" | /usr/bin/tclsh |& wc -l` if($test != 0) then set test = `echo "string is digit 1" | tclsh |& wc -l` if($test != 0) alias tclsh tclsh8.2 set test = `echo "string is digit 1" | tclsh |& wc -l` if($test != 0) alias tclsh tclsh8.3 set test = `echo "string is digit 1" | tclsh |& wc -l` if($test != 0) then setenv LD_LIBRARY_PATH ~jamesh alias tclsh ~jamesh/tclsh8.2 echo "" | tclsh >& /dev/null if("$status") then echo "ERROR: tclsh not available" exit 9 endif endif alias sock_exchange.tcl "tclsh `which sock_exchange.tcl` \!*" endif ###################################################################### if(! $?beamline) then # default to beamline this computer belongs to setenv beamline `beamline.com` if($status) then echo "ERROR: $beamline" exit 9 endif endif #if(! $?beamline) setenv beamline 831 set host = bl${beamline}b if("$beamline" !~ 82*) set host = beamline set tempfile = /tmp/blmotor_tmp$$ if(-w "/tmp/${USER}/") set tempfile = /tmp/${USER}/blmotor_tmp$$ goto Return_from_Setup