#! /bin/csh -f # # eta.com # # Script for estimating time-to-completion of the arrival of a # series of evenly-spaced files of a watched pattern. # #if($#argv == 0) goto Help goto Setup # # Routine (at bottom) to read command-line args # Help: cat << EOF-help usage: eta.com 'pattern' total where: pattern - the "ls" pattern matching the files you want to monitor total - expected total number of files example: eta.com '/data/frames/se1*.img' 100 EOF-help exit 9 Return_from_Setup: #set pattern = "$1" if("$pattern" == "") goto Help again: set noglob set dirname = `set noglob ; echo "$pattern" | nawk -F "[/]" '{for(i=1;i 3*rms)) {\ print i,step[i];rejected[i]=1;done=0;++rejects}}};\ print first, last, avg, n+1, rejects+0, filename[0], filename[n]}' |\ cat >! ${tempfile}timings # get the current time (seconds) set now = `echo 'puts [clock seconds]' | tclsh` # name of last file set lastfile = `tail -1 ${tempfile}timings | nawk '{print $7}'` if (! -e "$lastfile") then # just guess... set PREDICT endif if($?PREDICT) then if(! $?exposure) goto Help # simulate this run echo "$now $expected $exposure $waves 3.5 5" |\ nawk '{now=$1;total=$2;step=$3+$5} $4>=2{step+=$6} {\ printf "%s %d %s %s %s ", now,now+step*total,step,0,0}' |\ cat >! ${tempfile}timings echo "nothing $pattern" >> ${tempfile}timings endif # time first file appeared (seconds) set first = `tail -1 ${tempfile}timings | nawk '{print $1}'` # time last file appeared (seconds) set last = `tail -1 ${tempfile}timings | nawk '{print $2}'` # mean delta-time between files set interval = `tail -1 ${tempfile}timings | nawk '{print $3}'` # number of files that exist set arrived = `tail -1 ${tempfile}timings | nawk '{print $4}'` # name of last file set lastfile = `tail -1 ${tempfile}timings | nawk '{print $7}'` rm -f ${tempfile}timings # delta-time since first file appeared set elapsed = `echo "$now $first" | nawk '{print $1-$2}'` # delta-time since last file appeared set sincelast = `echo "$now $last" | nawk '{print $1-$2}'` # delta-time between first and last files set first2last = `echo "$first $last" | nawk '{print $2-$1}'` # number of images that SHOULD have been collected since "last" image was collected set stall = `echo "$sincelast $interval" | nawk '$2+0>0{printf "%d", $1/$2}'` # correct for silly mistakes if($arrived > $expected) set expected = $arrived # calculate delta-times in seconds set left = `echo "$expected $arrived" | nawk '{print $1-$2}'` set togo = `echo "$left $interval" | nawk '{print $1*$2}'` set timeleft = `echo "$togo" | nawk '{printf "%d", $1}'` set full = `echo "$elapsed $togo" | nawk '{printf "%d", $1+$2}'` set eta = `echo "$now $togo" | nawk '{printf "%d", $1+$2}'` set interval = `echo $interval | nawk '{printf "%.1f", $1}'` set elapsed = `echo $elapsed | nawk '{printf "%02d:%02d:%02d",$1/3600,($1/60)%60,$1%60}'` set togo = `echo $togo | nawk '{printf "%02d:%02d:%02d",$1/3600,($1/60)%60,$1%60}'` set full = `echo $full | nawk '{printf "%02d:%02d:%02d",$1/3600,($1/60)%60,$1%60}'` # convert these to date strings set eta = `echo "puts [clock format $eta]" | tclsh` set now = `echo "puts [clock format $now]" | tclsh` set last = `echo "puts [clock format $last]" | tclsh` echo "" echo "now on $lastfile" echo "$expected files expected, $arrived so far, $left to go" echo "$elapsed elapsed, $togo remaining" echo "rate: ${interval} s/file" echo "total time expected: $full" if($stall > 3) then # stall doesn't count if we are paused with no beam set beam = `blmotor.com Izero |& nawk '{print ( $NF > 0.1)}'` if(! $beam) set stall = 0 endif if($stall > 3) then echo "WARNING: expected $stall more files by now! " if("$alert_email" != "") then echo "data collection has stalled" | mail $alert_email set alert_email = "" endif echo "last file at: $last" endif echo "time is now: $now" echo "will finish at $eta" if($timeleft < 120 && $?first_time) set did_five_minute unset first_time if($?AUDIO && ! $?did_five_minute && $timeleft < 120) then set did_five_minute rsh imac "./say hello, data collection has two minutes left, get your next crystal ready" endif if("$togo" == "00:00:00") then echo "finished." if($?AUDIO) then rsh imac "./say data collection is complete" while ( `dcsmotor.com hutch_parker |& awk '/hutch_parker is now at 0.00/{f=1} END{print f+0}'` ) sleep 10 collecting.com if($status) exit rsh imac "./say data collection is complete" end endif exit endif if ($?PREDICT) exit # wait for the expected interval set interval = `echo $interval | nawk '{printf "%d", $1+1}'` sleep $interval goto again ############################################################################### # set-up routine (moved to bottom for clarity) Setup: # defaults (can be reset interdependently) set pattern = "" # file "glob"ing pattern set expected = 100 # total number of files expected set first_time set tempfile = /tmp/eta_temp if(-w /tmp/${USER}) set tempfile = /tmp/${USER}/eta_temp set alert_email = "" # platform-specific stuff set uname = `uname` if("$uname" == Linux) alias nawk awk 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 /usr/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 '/bin/echo \!* | nawk '\''/^-n/{printf "%s", substr ( $0,4 ) ; exit} {printf $0"\n"}'\' set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) echo "ERROR: echo command is broken" endif echo "" | tclsh >& /dev/null if($status) then alias tclsh tclsh8.2 echo "" | tclsh >& /dev/null if($status) alias tclsh tclsh8.3 echo "" | tclsh >& /dev/null if($status) then echo "ERROR: tclsh not available" exit 9 endif alias sock_exchange.tcl "tclsh `which sock_exchange.tcl` \!*" endif #goto Return_from_Setup # scan the command line set i = 0 while ( $i < $#argv ) @ i = ( $i + 1 ) set arg = "$argv[$i]" if("$arg" == "alert") then set alert_email = "5108409746@alphapage.airtouch.com" set alert_email = "5109285556@mobile.att.net" echo "will alert $alert_email if there is a stall" endif if("$arg" =~ *@*) then set alert_email = "$arg" echo "will alert $alert_email if there is a stall" endif if("$arg" == "-audio") then set AUDIO echo "will use audio alerts" rsh imac "./say hello, audio warnings enabled" endif # check for local directory specifier if(("$arg" =~ */*)||(-e "$arg")||("$arg" =~ *\**)) then if(-e "$arg") then test -d $arg if(! $status) then # just a directory set pattern = "${arg}\*" continue endif # must be a file? if("$pattern" == "") then set pattern = "$arg" endif continue else if("$pattern" == "") then # no files specified yet set noglob set dirname = `set noglob ; echo "$arg" | nawk -F "[/]" '{for(i=1;i&! ${tempfile}dcss_reply # DCSS 3.0 format: # key runid status nowon run# prefix dir startat axis start end osc wedge time dist waves values . . . mode IB # stog_configure_run run0 complete 1 0 run1 /data/mcfuser/Gd_lyso1 4 gonio_phi 90.00 91.00 1.00 180.0 1.0 150.000 1 12398.42 0 0 0 0 2 0 # stog_configure_run run1 collecting 321 1 HEL_Gd /data/mcfuser/Gd_lyso1 1 gonio_phi 0.00 100.00 1.00 1.0 1.0 150.000 2 12660.00 11000.00 0 0 0 2 1 # stog_configure_run run2 inactive 0 4 test /data/mcfuser/franke/tests 1 gonio_phi 1.00 41.00 1.00 180.0 3.1 30.000 1 10000.01 0 0 0 0 0 0 # stog_configure_run run3 complete 4 4 test /data/mcfuser/frankel/tests 1 gonio_phi 1.00 5.00 1.00 180.0 3.1 449.000 1 10000.01 0 0 0 0 0 0 # mode: # 0 # 1 # 2 # 3 # 4 # DCSS 1.0 format: # key run# phi0 first startat total osc time dist ? bin stage wedge IB ? ? ? ? ? waves values # stog_configure_run run1 2.000000 1 4 10 0.500000 1.100000 600.000000 0 4 2 3.000000 0 E1 E2 E3 E4 E5 1 12398.42 0 0 0 # stage: # 0 inactive # 1 running # 2 paused # 3 complete # retrieve wich run is running set numruns = `awk '/^stog_configure_runs/ {print $2+1}' ${tempfile}dcss_reply` set thisrun = `awk -v numruns=$numruns '/^stog_configure_run /{++runs; if($3=="collecting"){print;exit}} runs>=numruns{exit}' ${tempfile}dcss_reply` set lastrun = `awk -v numruns=$numruns '/^stog_configure_run /{++runs} runs==numruns{print;exit}' ${tempfile}dcss_reply` rm -f ${tempfile}dcss_reply >& /dev/null if("$thisrun" == "") then echo "data collection is not running" set thisrun = ( $lastrun ) set PREDICT else echo "getting current run information..." endif set prefix = `echo $thisrun | nawk '{print $7 "/" $6 "_" $5 "_"}'` set expected = `echo $thisrun | nawk '{start=$10;end=$11;osc=$12;waves=$16;IB=$NF; print int((end-start)/osc*waves*(IB+1))}'` set exposure = `echo $thisrun | nawk '{print $14}'` set waves = `echo $thisrun | nawk '{print $16}'` if("$prefix" == "") then echo "no data collection is running" goto Return_from_Setup endif #echo "collecting: ${prefix} ($expected files)" set noglob set pattern = "${prefix}*.img" #echo " ${pattern} ($expected files)" goto Return_from_Setup