#! /bin/csh -f # # Check flux via PIN diode on Iend channel # # date # interpret command line and figure out OS-specific aliases goto Setup Return_from_Setup: report: if($?ACTIVE) then diode.com in shutter.com open autoscale.com 1 sleep 1 endif set info = `echo "getpos ${PX}Iend\r\ngetpos ${PX}Izero\r\ngetpos Imono Out\r\ngetpos Imono In\r\ngetpos Horizontal Convergance Angle\r\ngetpos Vertical Convergance Angle\r\ngetpos Mono eV\r\ngetpos Beam Current\r" | sock_exchange.tcl $host 10001 8 | awk '{print $1}'` if($?ACTIVE) then shutter.com close diode.com out endif echo $info | grep "Inf" >& /dev/null if(! $status) then autoscale.com goto report endif set Iring = `echo "$info" | awk '$8>1{print $8+0}'` set Iend = `echo "$info" | awk '{print $1/1000}'` set Izero = `echo "$info" | awk '{print $2}'` set Iout = `echo "$info" | awk '{print $3}'` set Iin = `echo "$info" | awk '{print $4/1000}'` set divH = `echo "$info" | awk '{printf "%.1g", $5}'` set divV = `echo "$info" | awk '{printf "%.1g", $6}'` set energy = `echo "$info" | awk '{printf "%.1f", $7}'` set wave = `echo $info | awk '$7+0>0{printf "%.5f", 12398.4245/$7; exit} {print "?"}'` if("$Iring" == "") then set Iring = `echo "GET /als/als_ops/status.html" | sock_exchange.tcl www-als.lbl.gov | awk 'BEGIN{RS="[<>]"} /mA/{print $1+0; exit}'` endif if("$Iring" == "") then set Iring = `date | awk '{print $4}' | awk -F ":" '{print 400*exp(-($1+$2/60+$3/3600 +23)%8/10) "?"}'` endif if("$Iring" == "") set Iring = "?" # jump to here if we already have motor positions and gauge readings Skip_reading: # allow command-line override of motors and signals if("$user_Iring" != "") set Iring = $user_Iring if("$user_Iend" != "") set Iend = $user_Iend if("$user_divH" != "") set divH = $user_divH if("$user_divV" != "") set divV = $user_divV if("$user_energy" != "") set energy = $user_energy # compute normalized Iend value set flux = `echo $Iend $Iring $energy | awk '$3+0>0 && $2+0>0{printf "%.2e", ($1 / $2) * (9 * 10^15) / $3;exit} {print "?"}'` set Iend_norm = `echo $Iend $Iring | awk '$2+0>0{printf "%.4f", 400*$1/$2; exit} {print "?"}'` set Izero_norm = `echo $Izero $Iring | awk '$2+0>0{printf "%.4f", 400*$1/$2; exit} {print "?"}'` set Iout_norm = `echo $Iout $Iring | awk '$2+0>0{printf "%.4f", 400*$1/$2; exit} {print "?"}'` set Iin_norm = `echo $Iin $Iring | awk '$2+0>0{printf "%.4f", 400*$1/$2; exit} {print "?"}'` # round off for printing set Iend = `echo $Iend | awk '{printf "%.2f", $1}'` set Izero = `echo $Izero | awk '{printf "%.4f", $1}'` set Iout = `echo $Iout | awk '{printf "%.4f", $1}'` set Iin = `echo $Iin | awk '{printf "%.4f", $1}'` echo "$energy eV ($wave A) convergance: $divH x $divV" echo "Iring: $Iring mA" echo "Iin: $Iin uA ( $Iin_norm uA at 400 mA)" echo "Iout: $Iout nA ( $Iout_norm nA at 400 mA)" echo "Izero: $Izero nA ( $Izero_norm nA at 400 mA)" set max_divH = 3.0 set max_divV = 0.3 set max_divH = 2.84 set max_divV = 0.281 # clip the divergence at is maximum values set divH = `echo "$divH $max_divH" | awk '$1+0>$2{$1=$2} {print $1}'` set divV = `echo "$divV $max_divV" | awk '$1+0>$2{$1=$2} {print $1}'` if($beamline == 831) then cat << EOF >! ${tempfile} 30000 0 18000 21.13 3.23369e+06 17500 118.81 3.24248e+06 17000 506.43 3.24321e+06 16500 1580.35 3.22782e+06 16000 3818.75 3.18825e+06 15500 7663.84 3.12042e+06 15000 13115.50 3.03621e+06 14500 19720.10 2.95148e+06 14000 26769.20 2.88208e+06 13500 38050.60 2.84106e+06 13000 49816.50 2.83017e+06 12500 57612.50 2.84837e+06 12000 63099.60 2.89459e+06 11500 72973.00 2.96657e+06 11000 75409.80 3.0572e+06 10500 74564.40 3.15813e+06 10000 70358.70 3.26104e+06 10000 69744.60 3.26104e+06 9500 65117.10 3.36484e+06 9000 58663.00 3.49745e+06 8500 49601.20 3.69402e+06 8000 38117.90 3.98971e+06 7500 27712.10 4.40823e+06 7000 22366.40 4.92746e+06 6500 15370.90 5.51384e+06 6000 10007.40 6.13378e+06 5500 5394.83 5000 2605.61 4500 1795.23 4000 1940.01 3500 2411.35 3000 2245.90 0 0 EOF endif if($beamline == 1231) then cat << EOF >! ${tempfile} 30000 0 18000 21.13 3.23369e+06 17500 118.81 3.24248e+06 17000 506.43 3.24321e+06 16500 1580.35 3.22782e+06 16000 3818.75 3.18825e+06 15500 7663.84 3.12042e+06 15000 13115.50 3.03621e+06 14500 19720.10 2.95148e+06 14000 26769.20 2.88208e+06 13500 38050.60 2.84106e+06 13000 49816.50 2.83017e+06 12500 57612.50 2.84837e+06 12000 63099.60 2.89459e+06 11500 72973.00 2.96657e+06 11000 75409.80 3.0572e+06 10500 74564.40 3.15813e+06 10000 70358.70 3.26104e+06 10000 69744.60 3.26104e+06 9500 65117.10 3.36484e+06 9000 58663.00 3.49745e+06 8500 49601.20 3.69402e+06 8000 38117.90 3.98971e+06 7500 27712.10 4.40823e+06 7000 22366.40 4.92746e+06 6500 15370.90 5.51384e+06 6000 10007.40 6.13378e+06 5500 5394.83 5000 2605.61 4500 1795.23 4000 1940.01 3500 2411.35 3000 2245.90 0 0 EOF endif if($beamline == 821) then cat << EOF >! ${tempfile} 30000 0 18000 55.63 17500 138.16 17000 342.02 16500 951.46 16000 1677.32 15500 466.67 15000 1126.18 14500 1849.06 14000 5578.12 13500 10987.62 13000 15636.92 12500 18366.97 12000 19659.57 11500 21063.44 11000 19675.68 10500 19683.58 10000 18008.90 9500 15176.99 9000 11700.88 8500 9489.80 8000 6391.30 7500 3801.72 7000 2100.00 6500 946.48 6000 294.12 5500 86.78 5000 1.42 0 0 EOF endif if($beamline == 822) then cat << EOF >! ${tempfile} 30000 0 18000 111.26 17500 276.32 17000 684.04 16500 1902.91 16000 3354.63 15500 2666.67 15000 2252.37 14500 3698.11 14000 11156.25 13500 21975.23 13000 31273.85 12500 36733.94 12000 39319.15 11500 42126.89 11000 40486.49 10500 39367.16 10000 36017.80 9500 30353.98 9000 23401.76 8500 18979.59 8000 12782.61 7500 7603.45 7000 4200.00 6500 1892.96 6000 588.24 5500 173.55 5000 2.85 0 0 EOF endif touch ${tempfile} # calculate maximum characterized value echo "$Iring $energy $divH $divV $max_divH $max_divV" |\ cat - ${tempfile} |\ awk 'NR==1{Iring=$1;energy=$2;divH=$3;divV=$4;max_divH=$5;max_divV=$6;next}\ divH>max_divH{divH=max_divH} divV>max_divV{divV=max_divV}\ $1! ${tempfile}.expected set Iexpect = `tail -1 ${tempfile}.expected | awk '$5>0{printf "%#.4g", $5/1000}'` set cpna = `tail -1 ${tempfile}.expected | awk 'NF>4{print $7}'` # sensible defaults? if("$Iexpect" == "") set Iexpect = "0?" if("$cpna" == "") set cpna = 3000000 rm -f ${tempfile} >& /dev/null rm -f ${tempfile}.expected >& /dev/null finish: # report comparison of this flux to maximum characterized value set flux = `echo $Iend $cpna | awk '{printf "%.2g", $1*$2*1000}'` set flux_norm = `echo $Iend_norm $cpna | awk '{printf "%.2g", $1*$2*1000}'` set flux_expected = `echo $Iexpect $cpna | awk '{printf "%.4g", $1*$2*1000}'` set frac = `echo $Iend $Iexpect | awk '$2+0>0{printf "%.0f%%", $1/$2*100}'` echo "Flux = $Iend uA or $flux hv/s ( $Iend_norm uA at 400 mA or $flux_norm hv/s)" echo "Expecting $Iexpect uA or $flux_expected hv/s" echo "beam intensity is $frac of maximum" exit # original: 18000 34.8431 17500 90.3538 17000 235.776 16500 690.482 16000 1939.25 15500 4108.99 15000 6829.17 14500 9699.58 14000 12541.9 13500 16294.7 13000 24233.9 12500 27987.6 12000 31092.5 11500 35942.3 11000 38665.4 10500 39308.9 10000 39410.9 9500 38878.1 9000 35661.7 8500 32229.1 8000 22515.9 7500 18357.8 7000 14547.8 6500 10228.6 6000 6473.07 5500 3448.53 5000 1602.51 4500 755.404 4000 524.978 3500 461.853 3000 282.211 # 9-30-02 18000 9.86 17500 44.43 17000 128.45 16500 153.45 16000 825.83 15500 2077.77 15000 4038.53 14500 6278.01 14000 8590.57 13500 11412.76 13000 15094.81 12500 17779.44 12000 19803.72 11500 23074.31 11000 24450.66 10500 25127.08 10000 24555.12 9500 23607.16 9000 21209.68 8500 18452.18 8000 15363.56 7500 11878.53 7000 9472.75 6500 6802.64 6000 4445.40 5500 2470.91 5000 1203.01 4500 634.46 4000 584.28 3500 766.61 3000 873.07 # 2-14-03 18000 21.13 17500 118.81 17000 506.43 16500 1580.35 16000 3818.75 15500 7663.84 15000 13115.50 14500 19720.10 14000 26769.20 13500 38050.60 13000 49816.50 12500 57612.50 12000 63099.60 11500 72973.00 11000 75409.80 10500 74564.40 10000 70358.70 10000 69744.60 9500 65117.10 9000 58663.00 8500 49601.20 8000 38117.90 7500 27712.10 7000 22366.40 6500 15370.90 6000 10007.40 5500 5394.83 5000 2605.61 4500 1795.23 4000 1940.01 3500 2411.35 3000 2245.90 # 8.2.2 at some point 18000 111.26 17500 276.32 17000 684.04 16500 1902.91 16000 3354.63 15500 2666.67 15000 2252.37 14500 3698.11 14000 11156.25 13500 21975.23 13000 31273.85 12500 36733.94 12000 39319.15 11500 42126.89 11000 40486.49 10500 39367.16 10000 36017.80 9500 30353.98 9000 23401.76 8500 18979.59 8000 12782.61 7500 7603.45 7000 4200.00 6500 1892.96 6000 588.24 5500 173.55 5000 2.85 # 8.2.1 at some point 18000 55.63 17500 138.16 17000 342.02 16500 951.46 16000 1677.32 15500 466.67 15000 1126.18 14500 1849.06 14000 5578.12 13500 10987.62 13000 15636.92 12500 18366.97 12000 19659.57 11500 21063.44 11000 19675.68 10500 19683.58 10000 18008.90 9500 15176.99 9000 11700.88 8500 9489.80 8000 6391.30 7500 3801.72 7000 2100.00 6500 946.48 6000 294.12 5500 86.78 5000 1.42 exit Setup: 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 PX if("$beamline" == 1231) set PX = "PX " set noglob set tempfile = /tmp/flux_temp if(-w "/tmp/$USER") set tempfile = /tmp/${USER}/flux_temp ############################################################# # 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 #set host = beamline set tempfile = /tmp/flux_tmp$$ if(-w "/tmp/${USER}/") set tempfile = /tmp/${USER}/flux_tmp$$ # default: no user-specified values set user_Iend = "" set user_Iring = "" set user_energy = "" set user_divH = "" set user_divV = "" # process command line set i = 0 while ( $i < $#argv ) @ i = ( $i + 1 ) set Arg = "$argv[$i]" set arg = `echo $Arg | awk '{print tolower($0)}'` if("$arg" == "active") set ACTIVE if("$arg" == "-active") set ACTIVE if("$arg" =~ *=*) then set name = `echo $arg | awk -F "[=]" '{print tolower($1)}'` set value = `echo $arg | awk -F "[=]" '{print $2+0}'` if("$value" != "0") then # could be interesting if("$name" =~ hori*) set name = "divh" if("$name" =~ vert*) set name = "divv" if("$name" =~ hdiv*) set name = "divh" if("$name" =~ vdiv*) set name = "divv" if("$name" == "Ials") set name = "iring" if("$name" =~ wave*) then set test = `echo $value | awk '$1+0!=0{print 12398.4245/$1}'` if("$test" != "") set user_energy = $test endif if("$name" == "iend") then set test = `echo $value | awk '$1+0>0{print $1/1000}'` if("$test" != "") set user_Iend = "$test" endif if("$name" == "iring") set user_Iring = "$value" if("$name" == "energy") set user_energy = "$value" if("$name" == "divh") set user_divH = "$value" if("$name" == "divv") set user_divV = "$value" endif endif end # skip ahead if all we need to do is calculate if("$user_Iring" != "" && "$user_Iend" != "" && "$user_energy" != "" && "$user_divH" != "" && "$user_divV" != "" ) then set Izero = "unknown" set Iin = "unknown" set Iout = "unknown" set wave = `echo $user_energy | awk '$1+0!=0{print 12398.4245/$1}'` goto Skip_reading endif goto Return_from_Setup