#! /bin/tcsh -f # # read fluorescence counts using XOS or the direct delta-tau connection # # goto Setup Help: cat << EOF-Help usage: $0 [#s] where: #s is the desired photon counting time example: $0 0.5 EOF-Help 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 # which host is doing the counting? set pmac = pmac2 set shutter = 4 set counter = 6 if ( $beamline != 831 ) set pmac = bl${beamline}c set control = $pmac set tempfile = /tmp/fluor_temp$$ # interpret command line first set binrange = ( 0 1024 ) foreach arg ( $* ) if( "$arg" =~ [0-9\.]* ) then # interpret numbers as the desired count time (in seconds) set count_time = `echo $arg | awk '$1 ~ /^[0-9]/ || /^.[0-9]/{print $1+0}'` endif if( "$arg" == "Se" ) then # interpret numbers as the desired count time (in seconds) set binrange = ( 445 465 ) endif end if(! $?count_time) set count_time = 1 # figure out time to "sleep" while we count photons set sleep_time = `echo $count_time | awk '{printf "%d", $1*1000000}'` set wait_time = `echo $count_time | awk '{printf "%d", $1+3}'` onintr report get_counts: # zero the counter "motor" set counts = `echo -n "#${counter}p\r#${counter}hmz\rM${shutter}12=1\rM${shutter}11=1\r" | sock_exchange.tcl $pmac 14001 4 "\006" 0.1 |& awk '{gsub("[\006\r]"," ",$0); print}'` # see if deltatau responded amicably if($#counts == 1) then # wait for counts to accumulate usleep $sleep_time # read Izero? # now read how many counts we got set counts = `echo -n "M${shutter}12=0\rM${shutter}11=1\r#${counter}p\r#${counter}hmz\r" | sock_exchange.tcl $pmac 14001 4 "\006" 0.1 |& awk '{gsub("[\006\r]"," ",$0); print}'` # report this value goto finish endif # didn't work, try XOS set counts = "" xos_counts: # pretend to be a gui, do counter read, and then disconnect if ("$beamline" == 1231) then if(! $?binrange) set binrange = ( 440 470 ) set counts = `echo "gtos_become_master force\ngtos_set_shutter_state shutter open\ngtos_start_operation acquireSpectrum 0.1 1 1024 $count_time" | xos3_exchange.tcl 1 "operation_completed" $wait_time |& awk '/operation_completed/{for(i=6;i<=NF;++i) print i-6,$i}' | tee spectrum.txt | awk -v start=$binrange[1] -v end=$binrange[2] 'NR>=start && NR<=end{sum+=$2} END{print sum}'` # echo "gtos_become_master force\ngtos_set_shutter_state shutter closed" | xos3_exchange.tcl 1 "state shutter closed" > /dev/null else set counts = `echo "gtos_become_master force\ngtos_set_shutter_state shutter open\ngtos_read_ion_chambers $count_time 0 i_fluor" | xos3_exchange.tcl 1 "report_ion_chambers" $wait_time |& awk '/report_ion_chambers/{print $NF}'` endif if($?debug) echo "|${counts}|" # see if XOS responded amicably if("$counts" != "") then # we got a value goto finish endif # didn't work, try LBL/DCS set counts = "" # pretend to be a gui, do counter read, and then disconnect set xos_time = `echo $count_time | awk '{print $1*1000}'` set counts = `echo "gtos_read_ion_chambers Fluorescence $xos_time" | xos_exchange.tcl $control 1 "report_ion_chambers" $wait_time | awk '/report_ion_chambers/{print $NF}'` if($?debug) echo "|${counts}|" # see if XOS responded amicably if("$counts" != "") then # we got a value goto finish endif # didn't work, try something else? set counts = "" # jump ahead if we are out of ideas goto finish report: finish: if("$counts" == "") then set counts = "unknown" set BAD else # round it off to the nearest photon? set counts = `echo "$counts" | awk '$1>=0{printf "%d", $1}'` endif echo "$counts fluorescent photons were counted in ${count_time} s." if($?BAD) exit 9 exit