#! /bin/tcsh -f # # take a diffraction image using BLU-ICE # # defaults set name = test set directory = /data/${user}/ set delta = 1 set exposure = 1.0 set dosemode = 1 set bincode = 2 set newdark = 0 set image_ready = image_ready goto Setup Return_from_Setup: if ($#argv == 0) then cat << EOF usage: snapshot.com file_0_001.img [1s] [200mm] [12660eV] [-fast] [param=value] where: -norun - just program the shot, do not collect it -fast - indicates do not wait for image to appear on disk -[no]dose - do [not] use dose mode -[no]dark - do [not] take a new dark first 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 12660eV - is the desired photon energy param - is one of: phi exposure delta dist energy wave twotheta value - is the desired value for param example: snapshot.com /data/${user}/test_0_001.img EOF exit 9 endif echo "collecting:" echo "${prefix}_${num}.img" # special equates for snapshot run set range = $delta set wedge = $delta set inverse_beam = 0 set currentrun = 0 set runnum = 0 set runslot = run0 ################################################################### # use BLAK-ICE? if("$beamline" =~ 82?) then cat << EOF | xos_exchange.tcl bl${beamline}c 1 "image_ready" stog_become_master force gtos_configure_runs runs 0 0 gtos_configure_run_text run0 0 $name $directory gtos_configure_run run0 $phi ${num} 1 $n 1.00 $exposure $dist 0 4 0 1.0 0 E1 E2 E3 E4 E5 1 $energy 0 0 0 0 gtos_start_collect snap EOF if("$status") then set BAD = "unable to collect image" goto exit endif endif ################################################################### wait: # wait until there is no data collection running collecting.com |& grep -v not 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 1 $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 picture # 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 # configure the run set retry = 3 while ( $retry ) @ retry = ( $retry - 1 ) # wait for second configure_run (acknowledgement) cat << EOF | xos3_exchange.tcl 2 "stog_configure_run run0 " $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 1 $energy 0 0 0 0 $bincode $inverse_beam EOF if ($status) then echo "ERROR configuring the snapshot" continue endif # now check again, and make sure... set current_snap = `echo -n "" | xos3_exchange.tcl 1 "motor_depend" | awk '/configure_run run0/{print; exit}'` if ( $#current_snap < 10 ) continue if ( $current_snap[6] != $name ) continue if ( $current_snap[7] != $directory ) continue if ( `echo $current_snap[8] $n | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_snap[10] $phi | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_snap[11] $phiend | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_snap[12] $delta | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_snap[13] $wedge | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_snap[14] $exposure | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_snap[15] $dist | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_snap[17] $energy | awk '{print ($1+0!=$2+0)}'` ) continue if ( `echo $current_snap[22] $bincode | awk '{print ($1+0!=$2+0)}'` ) continue break end if($retry == 0) then cat << EOF ERROR: unable to configure desired run: $current_snap[6] != $name $current_snap[7] != $directory $current_snap[8] != $n echo $current_snap[10] != $phi echo $current_snap[11] != $phiend echo $current_snap[12] != $delta echo $current_snap[13] != $delta echo $current_snap[14] != $exposure echo $current_snap[15] != $dist echo $current_snap[17] != $energy echo $current_snap[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 # now push the "Collect" button set retry = 3 while ( $retry ) @ retry = ( $retry - 1 ) cat << EOF | xos3_exchange.tcl 1 "$image_ready" $timeout | awk '/'"${image_ready}"'|error|shutter_state shutter/{fflush();print;fflush()}' gtos_become_master force gtos_start_operation collectRun 0.1 0 $USER $newdark EOF if ($status) then echo "ERROR initiating the snapshot" continue endif break end if( "$retry" == "0" ) then set BAD = "unable to start collectRun" goto exit endif if( ! $?FAST && ! -e ${directory}/${name}_0_${num}.img) then # maybe NFS is slow? sync >& /dev/null head -1 ${directory}/${name}_0_${num}.img >& /dev/null if(! -e ${directory}/${name}_0_${num}.img) then set BAD = "${directory}/${name}_0_${num}.img was not produced" goto exit endif endif exit: if( $?BAD ) then echo "ERROR: $BAD" exit 9 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 ###################################################################### set runcount = 1 set currentrun = 0 set runnum = 0 set donewith = 0 set twotheta = "" set dezinger = "" set bin = "" set binmodes = ( unbinned unbinned_dezing binned binned_dezing ) set bincodes = ( 0 4 2 6 ) 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" =~ 82?) then set current_run = `echo -n "" | xos_exchange.tcl bl${beamline}c 1 "configure_run_text run0" | tail -1` set current_snap = `echo -n "" | xos_exchange.tcl bl${beamline}c 1 "configure_run run0" | tail -1` if($#current_snap < 21) goto get_snapinfo set dosemode = 0 set name = $current_run[4] set directory = $current_run[5] set n = $current_snap[4] set phi = $current_snap[3] set delta = $current_snap[7] set phiend = `echo "$phi $delta" | awk '{print $1+$2}'` set wedge = $current_snap[14] set exposure = $current_snap[8] set dist = $current_snap[9] set energy = $current_snap[21] set bincode = $current_snap[11] goto commandline endif get_snapinfo: # default to the currently-stored snapshot run set current_snap = `echo -n "" | xos3_exchange.tcl 1 "motor_depend" |& awk '/configure_runs/{print} /configure_run run0/{print; exit}'` if($#current_snap < 18) then echo "ERROR: cannot collect without DCSS running..." exit 9 endif set runcount = $current_snap[2] set currentrun = $current_snap[3] set isactive = $current_snap[4] set dosemode = $current_snap[5] set name = $current_snap[11] set directory = $current_snap[12] set n = $current_snap[13] set phi = $current_snap[15] set phiend = $current_snap[16] set delta = $current_snap[17] set wedge = $current_snap[18] set exposure = $current_snap[19] set dist = $current_snap[20] set energy = $current_snap[22] set bincode = $current_snap[27] commandline: 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 name = `basename $name _0` # 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" =~ *keV && "$number" != "") set arg = "energy=`echo $number | awk '{print $1*1000}'`" if("$arg" =~ *eV && "$number" != "") set arg = "energy=$number" set afternum = `echo $arg | awk -F "=" '$NF+0>0.001{print $NF+0}'` 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" =~ time=* && "$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" =~ dist* && "$afternum" != "") then set temp = `echo $afternum | awk '$1>60 && $1<1901'` if("$temp" != "") set dist = $afternum endif if("$arg" =~ twoth* && "$afternum" != "") then set temp = `echo $afternum | awk '$1>-2 && $1<45'` if("$temp" != "") set twotheta = $afternum endif if("$arg" =~ 2theta* && "$afternum" != "") then set temp = `echo $afternum | awk '$1>-2 && $1<45'` if("$temp" != "") set twotheta = $afternum endif if("$arg" =~ energ* && "$afternum" != "") then set temp = `echo $afternum | awk '$1>2000 && $1<20000'` if("$temp" != "") set energy = $afternum endif if("$arg" =~ wave* && "$afternum" != "") then set temp = `echo $afternum | awk '$1>0.8 && $1<3{print 12398.4245/$1}'` if("$temp" != "") set energy = $temp endif if("$arg" == -norun) then set NORUN endif end # automatically dezinger if exposure > 15s 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 prefix = ${directory}/${name}_0 # default to the last collected image? if($?default_image) then set n = `ls -1 ${prefix}_???.img |& tail -1 | awk -F "_" '{print $NF+1}'` endif set num = `echo $n | awk '{printf "%03d", $1+0}'` set phiend = `echo $phi $delta | awk '{print $1+$2}'` # don't wait for file to hit disk if we are in a hurry set image_ready = image_ready if ($?FAST) set image_ready = "operation_completed collectFrame" goto Return_from_Setup