#!/bin/tcsh -f # # IF no command line argument, just report last size in change.log (to maintain consistance with previous version) # Otherwise: read the ENOCDER postion, check that it corresponds to where the logged pinhole should be # change.log entry # and check that the enoder is within 10 counts of the # If different, attempt to redraw the encoded hole size and update change.log # If a valid argument was entered on the command line then ${dir}/change_pinhole.com # Otherwise display the available sizes to choose from # want to be able to kill the move, so ... onintr break set desire = `echo $1 | awk '{print toupper($1)}'` if ($desire != "") goto do_something tac /data/log/change.log | awk '$NF=="pinhole" && $(NF-1)+0>1 && $(NF-1)~/um$/{print "pinhole is",$(NF-1); exit}' exit do_something: set log_dir = "/data/calibrations/pinhole/" set stage_up_log = "${log_dir}/stage_up.log" set dir = "/home/mcfuser/gmeigs/Collimator" if ( "$desire" =~ K* ) then ${dir}/Pinhole.com k exit endif #set sizes = `cat ${log_dir}encoder.log | awk '{print $NF}'` # NO, limit the number of displayed available sizes: #set sizes = "20 30 75 100" set sizes = "20 30 50 75 100" set first_try = 1 try_logged_again: # before attempting move make sure the Encoder reading cooresponds to the LOGGED position set change_log_pinhole_size = `tac /data/log/change.log | awk '$NF=="pinhole" && $(NF-1)+0>1 && $(NF-1)~/um$/{print $(NF-1); exit}'` set foo = `${dir}/Pinhole.com | awk '/ENCODED/{print $0}'` set encoded_pinhole_size = $foo[5] set encoded_hole_number = $foo[4] set cnts_away = $foo[6] set bad_cnts = ` echo $cnts_away | awk '{print ($1**2 >= 100)? "bad" : "" }'` set mismatch = `echo $change_log_pinhole_size $encoded_pinhole_size | awk '{print( $1 == $2)? 0 : "mismatch"}'` if ("$mismatch" == "mismatch" ) then if ("$first_try" != "1") then echo "unsuccessful at updating pinhole.log file, call x2249 for help" exit endif echo "" echo "the logged $change_log_pinhole_size and encoded $encoded_pinhole_size pinhole sizes are mismatched" echo " An attempt will be made to correct this ..." echo " ... " ${dir}/Pinhole.com set sleep 1 ${dir}/change_pinhole.com $encoded_hole_number sleep 1 set first_try = 2 goto try_logged_again endif set first_try = 1 try_cnts_again: set change_log_pinhole_size = `tac /data/log/change.log | awk '$NF=="pinhole" && $(NF-1)+0>1 && $(NF-1)~/um$/{print $(NF-1); exit}'` set foo = `${dir}/Pinhole.com | awk '/ENCODED/{print $0}'` set encoded_pinhole_size = $foo[5] set encoded_hole_number = $foo[4] set cnts_away = $foo[6] set bad_cnts = ` echo $cnts_away | awk '{print ($1**2 >= 100)? "bad" : "" }'` if ("$bad_cnts" == "bad") then if ("$first_try" != "1") then echo "unsuccessful at tweaking pinhole encoder, call x2249 for help" exit endif echo "" echo " the encoded position is off by more than 10 counts: $cnts_away" echo " An attempt will be made to correct this ..." echo " ... " ${dir}/Pinhole.com $encoded_hole_number set first_try = 2 goto try_cnts_again endif echo " $encoded_pinhole_size pinhole now in place" # the must have been something other than ~"kill" on the command line to have gotten here # check to see if it was a valid request foreach size ($sizes) if ($size == $desire) goto good_size end echo "" echo " ... to Change to Another Size, chose from these -->> pinhole.com [ $sizes ]" echo "" exit good_size: set already_there = `echo ${size}um $change_log_pinhole_size | awk '{print ($1 == $2)? "already_there" : 0}'` if ("$already_there" == "already_there") then echo " the ${size}um pinhole is in place, already, ...ALREADY:-)" exit endif ${dir}/change_pinhole.com $size exit break: echo "interupted move in $0" set galil = "192.168.4.170 158" echo "MOD;STD;MOD;STD\r\n" | sock_exchange.tcl $galil 4 ":" 1 exit