#! /bin/csh -f # # take a run of diffraction images using BLU-ICE # # defaults set name = test set directory = /data/${user}/ set delta = 1 set range = 100 set exposure = 1.0 set dosemode = 1 set bincode = 2 set newdark = 1 set inverse_beam = 0 set runslot = run1 goto Setup Return_from_Setup: if ($#argv == 0) then cat << EOF usage: run1.com file_1_001.img frames=100 [1s] [200mm] [12660eV] [param=value] where: -norun - just program the run, do not collect it -[no]dose - do [not] use dose mode -[no]inverse - do [not] collect inverse beam wedges file_0_001.img - is the name of the file you want to collect 1s - is the exposure time 200mm - is the xtal-to-detector distance param - is one of: frames phi range exposure delta wedge dist energy wave runslot value - is the desired value for param example: run1.com /data/${user}/test_1_001.img -dose 1s 12657eV 12655.6eV 12400eV -inverse 200mm EOF exit 9 endif echo "collecting:" echo "$firstimage to $lastimage" ################################################################### wait: # wait until there is no data collection running collecting.com if($status) then # abort.com sleep 10 echo "waiting for current data collection to stop..." goto wait endif # report how long this run will take set runtime = `echo $frames $exposure 3.0 | awk '{print ($1+2)*($2+$3)}'` echo "$runtime" | awk '{printf "this should take %02d:%02d:%02d\n", $1/3600,($1-int($1/3600)*3600)/60, $1-int($1/60)*60}' # calculate maximum expected time between lines set timeout = `echo $exposure | awk '{printf "%d", 30+$1*1.5}'` # now configure the run # DCSS 3.0 format: # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 # key runid status nowon run# prefix dir startat axis start end osc wedge time dist waves values . . . mode IB # DCSS 5.0 format: # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 # key runid "self" status nowon run# prefix dir startat axis start end osc wedge time dist beamstop_z attenuation waves values . . . mode IB # configure the run set retry = 3 while ( $retry ) @ retry = ( $retry - 1 ) cat << EOF | xos3_exchange.tcl 2 "stog_configure_run $runslot " $timeout > /dev/null gtos_become_master force gtos_configure_runs runs $runcount $currentrun $dosemode gtos_configure_run $runslot inactive $donewith $runnum $name $directory $n gonio_phi $phi $phiend $delta $wedge $exposure $dist $nwaves $energies $bincode $inverse_beam EOF if ($status) then echo "ERROR configuring the run" continue endif # now check again, and make sure... set current_run = `echo -n "" | xos3_exchange.tcl 1 "motor_depend" | awk -v runslot=$runslot '/configure_run/ && $2==runslot{print; exit}'` if ( $#current_run < 10 ) continue if ( $current_run[6] != $name ) continue if ( $current_run[7] != $directory ) continue if ( `echo $current_run[8] $n | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_run[10] $phi | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_run[11] $phiend | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_run[12] $delta | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_run[13] $wedge | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_run[14] $exposure | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_run[15] $dist | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_run[17] $energy | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_run[22] $bincode | awk '{print ($1+0!=$2+0)}'` ) continue break end if($retry == 0) then cat << EOF ERROR: unable to configure desired run: name: $current_run[6] != $name dir: $current_run[7] != $directory n: $current_run[8] != $n phi: $current_run[10] != $phi phiend: $current_run[11] != $phiend delta: $current_run[12] != $delta wedge: $current_run[13] != $wedge expose: $current_run[14] != $exposure dist: $current_run[15] != $dist energy: $current_run[17] != $energy bin: $current_run[22] != $bincode EOF set BAD = "unable to configure the run" goto exit endif if($?NORUN) goto exit # make sure distance/twotheta are set if("$twotheta" != "") then distance.com $dist twotheta.com $twotheta endif # make sure the beam is tuned up? set tuned_energy = `wave.com |& awk '/^Energy:/{print $2}'` set test = `echo $energy $tuned_energy | awk '{print (NF!=2 || sqrt(($1-$2)^2)>1000)}'` if($test) then wave.com $energy setenv plot "#" tuneup.com ifneeded endif # now push the "Collect" button cat << EOF | xos3_exchange.tcl 1 "start_operation collectRun" $timeout > /dev/null gtos_become_master force gtos_start_operation collectRun 0.1 $currentrun $USER $newdark EOF if($status) then set BAD = "couldn't initiate run" goto exit endif # now wait for run to finish? onintr stop_run watch_run: # monitor run, wait for it to complete echo -n "" | xos3_exchange.tcl 1 "image_ready $lastimage" $timeout |\ awk '/image_ready/{print $NF}' if(! -e $lastimage) then ring.com | grep available >& /dev/null if($status) then # must be no beam while( `ring.com | grep available` == "" && ! -e $lastimage ) echo "waiting for beam" sleep 10 end goto watch_run endif endif if(! -e $lastimage) then sleep 10 if(! -e $lastimage) set BAD = "run did not finish." endif exit: if($?BAD) then echo "ERROR: $BAD" exit 9 endif if(! $?NORUN) then echo "$runslot is finished" else echo "$runslot is updated" endif exit stop_run: onintr abort.com goto exit Setup: set runcount = 1 set currentrun = 1 set runnum = 1 set donewith = 0 set twotheta = "" set dezinger = "" set bin = "" set binmodes = ( unbinned unbinned_dezing binned binned_dezing ) set bincodes = ( 0 4 2 6 ) # first, scan for a default run slot foreach arg ( $* ) if("$arg" =~ runslot=* ) then set test = `echo $arg | awk -F "=" '$NF~/^run/{print $NF} $NF+0>0{print "run"$NF+0}'` if("$test" != "") then set runslot = "$test" endif endif end # default to the currently-stored values in the selected runslot, or the snapshot run if run1 doesn't exist set current_run = `echo -n "" | xos3_exchange.tcl 1 "motor_depend" | awk -v runslot=$runslot '/configure_runs/{print;runs=$2} /configure_run run0 / && runs==0{print; exit} /configure_run / && $2==runslot {print; exit}'` if($#current_run < 18) then echo "ERROR: cannot collect without DCSS running..." exit 9 endif set runcount = $current_run[2] set currentrun = $current_run[3] set isactive = $current_run[4] set dosemode = $current_run[5] #set runslot = $current_run[7] set directory = $current_run[12] set name = $current_run[11] set runnum = $current_run[10] set n = $current_run[13] set phi = $current_run[15] set phiend = $current_run[16] set delta = $current_run[17] set wedge = $current_run[18] set exposure = $current_run[19] set dist = $current_run[20] set nwaves = $current_run[21] set energy = $current_run[22] set energies = $current_run[22] set fiveenergies = ( $current_run[22] $current_run[23] $current_run[24] $current_run[25] $current_run[26] ) set bincode = $current_run[27] set inverse_beam = $current_run[28] if($runcount < 1) set runcount = 1 if($runnum < 1) set runnum = 1 set range = `echo $phiend $phi | awk '{print $1-$2}'` set i = 22 while($#energies < $nwaves) @ i = ( $i + 1 ) set energies = ( $energies $current_run[$i] ) end #set n = 1 #set wedge = $delta set defaultenergy unset frames foreach arg ( $* ) if("$arg" =~ *.img) then set directory = `dirname $arg` if (-e "$directory") set directory = `cd $directory ; pwd` set name = `basename $arg .img` set num = `echo $name | awk -F "_" '{print $NF}'` set n = `echo $num | awk '{print $NF+0}'` set name = `basename $name _$num` set runnum = `echo $name | awk -F "[_]" '{print $NF+0}'` if("$runnum" == "0") set runnum = 1 set name = `basename $name _${runnum}` # set name = `echo $name | awk -F "_" '{for(i=1;i<=NF-2;++i) {printf "%s", $i; if(i0.001{print $1+0}'` if("$arg" =~ *deg && "$number" != "") set arg = "phi=$number" if("$arg" =~ *mm && "$number" != "") set arg = "dist=$number" if("$arg" =~ *s && "$number" != "") set arg = "time=$number" if("$arg" =~ *A && "$number" != "") set arg = "wave=$number" if("$arg" =~ *eV && "$number" != "") set arg = "energy=$number" set afternum = `echo $arg | awk -F "=" '$NF+0>0.001{print $NF+0}'` if("$arg" =~ runslot=* ) then set test = `echo $arg | awk -F "=" '$NF~/^run/{print $NF} $NF+0>0{print "run"$NF+0}'` if("$test" != "") then set runslot = "$test" endif endif if("$arg" =~ phi=* && "$arg" =~ *[0-9]*) then set phi = `echo $arg | awk -F "=" '{print $NF+0}'` endif if("$arg" =~ start=* && "$arg" =~ *[0-9]*) then set phi = `echo $arg | awk -F "=" '{print $NF+0}'` endif if("$arg" =~ num=* && "$arg" =~ *[0-9]*) then set n = `echo $arg | awk -F "=" '{print int($NF+0)}'` endif if("$arg" =~ time=* && "$afternum" != "") then set temp = `echo $afternum | awk '$1>0.001'` set exposure = $afternum # flag to automatically set dezinger mode set desiznger = "" endif if("$arg" =~ expos* && "$afternum" != "") then set temp = `echo $afternum | awk '$1>0.001'` set exposure = $afternum endif if(("$arg" =~ delta=* || "$arg" =~ osc=*) && "$afternum" != "") then set temp = `echo $afternum | awk '$1>0.01 && $1<361'` if("$temp" != "") set delta = $afternum endif if("$arg" =~ wedge=* && "$afternum" != "") then set temp = `echo $afternum | awk '$1>0.01 && $1<361'` if("$temp" != "") set wedge = $afternum endif if("$arg" =~ range=* && "$afternum" != "") then set temp = `echo $afternum | awk '$1>0.01 && $1<3600'` if("$temp" != "") set range = $afternum unset frames endif if("$arg" =~ frames=* && "$afternum" != "") then set temp = `echo $afternum | awk '$1>0.01 && $1<3600'` if("$temp" != "") set frames = $afternum endif if("$arg" =~ dist* && "$afternum" != "") then set temp = `echo $afternum | awk '$1>60 && $1<2000'` if("$temp" != "") set dist = $afternum endif if("$arg" =~ energ* && "$afternum" != "") then set temp = `echo $afternum | awk '$1>2000 && $1<20000'` if("$temp" != "") then if($?defaultenergy) set energies = "" unset defaultenergy set energies = ( $energies $afternum ) endif endif if("$arg" =~ wave* && "$afternum" != "") then set temp = `echo $afternum | awk '$1>0.8 && $1<3{printf "%.2f", 12398.4245/$1}'` if("$temp" != "") then if($?defaultenergy) set energies = "" unset defaultenergy set energies = ( $energies $temp ) endif endif if("$arg" =~ -inverse*) then set inverse_beam = 1 endif if("$arg" =~ -noinverse*) then set inverse_beam = 0 endif if("$arg" == -norun) then set NORUN endif end # automatically dezinger if exposure > 15s (and dezinger is not already set) if("$dezinger" == "") then set test = `echo $exposure 15 | awk '{print ($1 > $2)}'` if($test) then set dezinger = 1 else set dezinger = 0 endif endif # figure out the bin mode if("$bin" == "") then set bincode_index = `echo $bincodes $bincode | awk '{for(i=1;i& /dev/null endif if(! -w $directory && ! $?NORUN) then set test = `echo $directory | awk -F "/" '{print "/"$2"/"$3}'` if(! -w "$test") then # this is not going to work, replace second directory with username set directory = `echo $directory | awk -v user=$user -F "/" '{$3=user ; for(d=2;d<=NF;++d) printf "/%s",$d}'` endif endif set num = `echo $n | awk '{printf "%03d", $1+0}'` if($?frames) then set range = `echo $frames $delta | awk '{print $1*$2}'` unset frames endif # calculate the ending phi value set phiend = `echo $phi $range | awk '{print $1+$2}'` set phiend = `echo $phi $phiend $delta | awk '{n=($2-$1)/$3} n+0!=int(n)+0{n=int(n+1)} {print $1+n*$3}'` set frames = `echo $phi $phiend $delta $donewith $nwaves $inverse_beam | awk '{n=($2-$1)/$3 - $4; print n*$5*($6+1)}'` set lastnum = `echo $n $frames $nwaves $inverse_beam | awk '{printf "%03d",($1+$2-1)/$3/($4+1)}'` # sanity check on wedge size if( `echo $delta $wedge | awk '{print ($1>$2)}'` ) set wedge = $delta set wedge = `echo "$delta $wedge" | awk '$2<$1{$2=$1} {print $1*sprintf("%.0f",($2/$1))}'` set firstimage = ${directory}/${name}_$runnum set lastimage = ${directory}/${name}_$runnum if($#energies > 1) then set firstimage = "${firstimage}_E1" set lastimage = "${lastimage}_E$#energies" endif set firstimage = "${firstimage}_${num}.img" set lastimage = "${lastimage}_${lastnum}.img" set energies = ( $energies ) set nwaves = $#energies # pad up the energies while ( $#energies < 5 ) set energies = ( $energies 0 ) end set energy = $energies[1] # see what "slot" this run will be programmed into set slotnum = `echo $runslot | awk '{print substr($1,4)}'` # make sure it will be displayed in BLU-ICE set currentrun = $slotnum if($currentrun > $runcount) set runcount = $currentrun goto Return_from_Setup