#!/bin/tcsh -f set debug set norun foreach arg ( $* ) if("$arg" == "debug") then set debug = 1 echo "running in debug mode, crystal will not have to move..." set P2 = " 0 0 -5" set P1 = " 0 0 -6" set norun = "-norun" endif if("$arg" == "norun") then set norun = "-norun" continue endif end # assume there is a RUN_1 set foo = `runinfo.com | awk '{gsub("[{}]", "."); if(NR==4)print $0 }' ` if ("$foo" == "") then echo " There is no programmed Run_1 in BLUICE, would you like to set one up from snapshot info, now? [no]" set go_on = ($<) set go_on = ` echo $go_on | awk '{print toupper($1)}'` # No RUN_1 ask to use RUN_0 if (("$go_on" == "") || ("$go_on" =~ "N*")) then echo echo ' Ok, then do this: set up a "Run_1" in the bluice data collection tab before calling this script, then ...' echo " This script will help you to either" echo " 1) Create a copy-and-paste text (which you can then execute) to collect a single Run_1 of images " echo " divided up equally from different locations along your crystal. " echo " -- OR --" echo " 2) Create as series of Muliple complete runs at different locations with identical parameters but with incremented RUN numbers " echo " In either case you will specify the starting and ending points and can set or change the suggested number of positions to use." exit else # OK, use the info in RUN_0 goto setup_via_Run0 endif else # RUN_1 was setup so user the runinfo.com we got goto run1_is_setup endif setup_via_Run0: # No Run_1 programmed try for setup from snap shot set foo = `runinfo.com | awk '{gsub("[{}]", "."); if(NR==3)print $0 }' ` echo "$foo" if ("$foo" == "") then # Dang it No Snap shot either, dcss down and just debugging I guess echo "BAD RUN_0 info setting up Dummy fields" #set Parms = "first_frame_num prefix dir first_image phi_beg phi_beg_run phi_end delta_phi wedge expo det_dist IB wave1 wave2 wave3 FRAMES IB" set foo = "1 2 3 4 5 6 test /data/mcfuser/align 9 10 1 180 .5 30 1s 600 17 18 19 11111 0 0 0 0 0 0" ../enumerate_fields.com $foo endif run1_is_setup: echo "" echo ' a single continous run spread out along the crystal "cont" ' echo -n ' or "mult" complete runs at various locations [cont] --->> ' set arg_in = ( $< ) set multi_run = `echo $arg_in | awk '{if($1 ~"mu") print 1}'` if ("$multi_run") set multi_run = MULTI_RUNS set run_num = 1 set run_waypoint = run_waypoint.txt if (-e $run_waypoint) then # append_file_date.com $run_waypoint >>& /dev/null rm $run_waypoint touch $run_waypoint endif set first_frame_num = 00001 set prefix = ` echo $foo | awk '{print $7}'` set dir = `echo $foo | awk '{print $8}'` set first_image = ` echo ${dir}/${prefix}_${run_num}_${first_frame_num}.cbf` set phi_beg = $foo[11] set phi_beg_run = $phi_beg set phi_end = $foo[12] set delta_phi = $foo[13] set wedge = $foo[14] set expo = $foo[15] set det_dist = $foo[16] set IB = $foo[26] set wave1 = `echo $foo[20] | awk '{if ( $1 + 0 != 0 ) print $1"eV"}'` set wave2 = `echo $foo[21]| awk '{if ( $1 + 0 != 0 ) print $1"eV"}'` set wave3 = `echo $foo[22]| awk '{if ( $1 + 0 != 0 ) print $1"eV"}'` set FRAMES = `echo $phi_end $phi_beg $delta_phi | awk '{print ($1-$2) / $3}'` set IB = `echo $IB | awk '{ if ($1 == 1) print "-inverse"}'` set Parms = "first_frame_num prefix dir first_image phi_beg phi_beg_run phi_end delta_phi wedge expo det_dist IB wave1 wave2 wave3 FRAMES IB" ### let user make changes to runs check_run_info: echo first_frame_num $first_frame_num echo prefix $prefix echo dir $dir echo first_image $first_image echo phi_beg $phi_beg echo phi_end $phi_end echo delta_phi $delta_phi echo wedge $wedge echo expo $expo echo det_dist $det_dist echo IB $IB echo wave1 $wave1 echo wave2 $wave2 echo wave3 $wave3 echo FRAMES $FRAMES echo " Want to change anything? [n] " set go_on = ($<) set go_on = ` echo $go_on | awk '{print toupper($1)}'` if (("$go_on" == "") || ("$go_on" =~ "N*")) then echo "OK will change nothing" goto carry_on endif echo " make changes by entering the parmater_name parameter, e.e." echo " to change Total number of FRAMES you must adjust delta_phi or phi_beg or phi_end" echo " to turn on Inverse Beam enter this: IB 1" echo "wedge 30 wave2 11500" set input = ($<) set n = $#input set i = 0 set limit = `echo $#input | awk '{print $1 -1}'` while ( $i < $limit ) @ i = ( $i + 1 ) @ j = ( $i + 1 ) set arg = "$input[$i]" set val = "$input[$j]" # echo $i $j $#input $input foreach parm ($Parms) if ("$parm" == "$arg") then # echo " will try to set $parm to $val" echo $parm $val | awk '{print "set " $1 " = " $2}' >! test_set_val.txt source test_set_val.txt endif end end set FRAMES = `echo $phi_end $phi_beg $delta_phi | awk '{print ($1-$2) / $3}'` set IB = `echo $IB | awk '{ if ($1 == 1) print "-inverse"}'` goto check_run_info carry_on: if ($debug) goto compute #### get start and end sample positions echo " move sample to data collection END point, " set go_on = ( $< ) set P2 = `sample.com | awk '{print $(NF-2), $(NF-1), $(NF)}'` echo " move sample to data collection START point, " set go_on = ( $< ) set P1 = `sample.com | awk '{print $(NF-2), $(NF-1), $(NF)}'` compute: set slope_m = `echo $P2 $P1 | awk '{print $1-$4, $2-$5, $3-$6}'` # the vector length slope_m is the distance of the move set travel_dist = `echo $slope_m | awk '{print 1000*($1**2 + $2**2 + $3**2)**.5}'` #echo " data colection will be spread over a distance of $travel_dist microns" # set the size of each move set dz_um = `pinhole.com | awk '{gsub("um", "");print $NF}'` if ("$dz_um" == "100") set dz_um = "80" # how many moves will there be set moves = `echo $travel_dist $dz_um | awk '{print int($1/$2) + 1}'` # num moves is 1 less than number of positions, awk {print int ($X )} rounds down, so add 1 set positions = `echo $moves | awk '{print $1 + 1}'` recalculate: #the increment of each move set delta_xyz = `echo $slope_m $moves | awk '{print $1/$4, $2/$4, $3/$4}'` #echo " distance to travel: $travel_dist ; move size: $dz_um; moves: $moves, delta_xyz : $delta_xyz" # frames is number of frames for each sample position set frames = `echo $FRAMES $positions | awk '{print int ($1/$2)}'` # maybe not prefectly divisible so add remainder to last position, in case needed set last_frames = `echo $FRAMES $frames $positions | awk '{print $1 - ( $2 * ($3 -1) )}'` # round $travel_dist for text out to user set travel = `echo $travel_dist | awk '{print int($1)}'` echo echo "${travel}um overall distance moved, $moves moves of ${dz_um}um each" if (! $multi_run) then set delta_range = `echo $delta_phi $frames | awk '{print $1 * $2}'` echo " $positions positions of $frames frames each,but # of frames ($last_frames) at last position may be different." endif if ($multi_run) echo " will collect a complete data set of $FRAMES frames at each the $positions positions" echo -n " would you like to change the number of collection positions? (y,n) [n] --->> " set yes_no = ($<) if ( ("$yes_no" == "") || ("$yes_no" == "n") ) goto go_on echo -n " How many positions would you like [$positions] --->> " set positions = ($<) set moves = `echo $positions | awk '{print $1 - 1}'` set dz_um = `echo ${travel_dist} $moves | awk '{print int($1/$2)}'` goto recalculate go_on: ################################################################# foreach move (`seq 0 $moves`) set iteration = `echo $move | awk '{print ($1 +1)}'` # how far to move the sample set inc = `echo $delta_xyz $move | awk '{print $1*$4, $2*$4, $3*$4}'` set Pinc${move} = ` echo $P1 $inc | awk '{print $1 +$4, $2+$5, $3+$6}'` # echo sample.com to `eval echo \$Pinc${move}` | tee -a $run_waypoint echo sample.com to `eval echo \$Pinc${move}` >>& $run_waypoint if ("$multi_run") then set run_num = $iteration set frames = $FRAMES set phi_beg_run = $phi_beg set first_image = ` echo ${dir}/${prefix}_${run_num}_${first_frame_num}.cbf` endif # echo "run1.com $first_image ${expo}s ${det_dist}mm $wave1 $wave2 $wave3 wedge=$wedge $IB delta=$delta_phi frames=$frames phi=$phi_beg_run $norun" | tee -a $run_waypoint # echo "run1.com $first_image ${expo}s ${det_dist}mm $wave1 $wave2 $wave3 wedge=$wedge $IB delta=$delta_phi frames=$frames phi=$phi_beg_run $norun" | tee -a $run_waypoint echo "run1.com $first_image ${expo}s ${det_dist}mm $wave1 $wave2 $wave3 wedge=$wedge $IB delta=$delta_phi frames=$frames phi=$phi_beg_run $norun" >>& $run_waypoint if (! "$multi_run") then set first_frame_num = `echo $first_frame_num $frames | awk '{printf "%05d\n", $1 + $2}'` set first_image = ` echo ${dir}/${prefix}_${run_num}_${first_frame_num}.cbf` endif set phi_beg_run = `echo $phi_beg_run $delta_phi $frames| awk '{print $1 + ($2 * $3) }'` if ("$iteration" == "$moves") set frames = $last_frames # endif #echo phi.com $phi ";" sample.com to `eval echo \$Pinc${move}` ";" sleep 1 | tee -a $run_waypoint #sleep 1 end ######################################################################### #echo "" #cat $run_waypoint | awk '{if (NR == 2) print $0}' #echo "" #echo " are you happy with the above first run " #set go_on = ($<) # #cat $run_waypoint | awk '{if (NR%2 != 0) print $0}' >! waypoint_move_only.txt cat run_waypoint.txt | awk '{gsub ("phi=", "phi.com ")} {if (NR%2 != 1) print $(NF-1), $NF, "; sleep 1" } {if (NR%2 != 0) print $0} ' >! waypoint_move_only.txt echo "" echo " To Start Collecting--->> source run_waypoint.txt" echo "" echo " Just check moves --->> source waypoint_move_only.txt" echo "" echo " Edit script to Change parameters--->> gedit $run_waypoint & " echo "" exit cat run_waypoint.txt | awk '{if(NR%2==0) print $0} # this will only work for the "multi" run setups #setup (ONLY) multiple runs in bluice: # write the text for doing this: cat run_waypoint.txt | awk '{if(NR%2==0) print $0}' | awk '{print $0, "-norun runslot="NR}' # actually do it (make the blue ice window `cat run_waypoint.txt | awk '{if(NR%2==0) print $0}' | awk '{print $0, "-norun runslot="NR}'`