#!/bin/tcsh -f # cloned from James's sumup.com #convert the last 3 days of M2 pressure log to gnuplot friendly format # 3 X 24 X 360 (one reading is taken every 10 seconds) tail -25920 /data/log/M2_pressure.log | awk '{print $2, $3, $4, $6, $7, $8}' >&! M2_3day.log #tail -700 /data/log/M2_pressure.log | awk '{print $2, $3, $4, $6, $7, $8}' >&! M2_3day.log #tail -700 Mono_Tank_Pressure.log >&! Mono_3day.log set tempfile = tempfile #figure out if our clock is wrong set now = `date | awk '{print "puts [clock scan \""$0"\"]"}' | tclsh` ping -w 1 -c 1 cgsrv.als.lbl.gov >& /dev/null if (! $status) then set rightnow = `rdate cgsrv.als.lbl.gov | awk 'NF>5{print "puts [clock scan \""$(NF-3),$(NF-2),$(NF-1),$NF"\"]"}' | tclsh` else set rightnow = $now endif set rightdate = `echo 'puts [clock format '$now' -format "%a %b %d %T %Z %Y"]' | tclsh` set clockskew = `echo $now $rightnow | awk '{print $2-$1}'` set test = `echo $clockskew | awk '{print (sqrt(($1)^2) < 2 || sqrt(($1)^2) >200000)}'` if ("$test") then set clockskew = 0 else echo "WARNING: this computer clock is $clockskew off..." endif # now have a look at the beamline log history # plot the last 8 hours or so of interesting readings set epoch = `echo "puts [expr [clock seconds] + $clockskew]" | tclsh` set endepoch = `echo 'puts [expr [clock scan "now"] + '$clockskew']' | tclsh` set startepoch = `echo 'puts [expr [clock scan "3 days ago"] + '$clockskew']' | tclsh` set startepoch = `echo 'puts [expr [clock scan "24 hours ago"] + '$clockskew']' | tclsh` set startdate = `echo 'puts [clock format '$startepoch' -format "%a %b %d %T %Z %Y"]' | tclsh | awk '{print $2,$3,$4,$6}'` set enddate = `echo 'puts [clock format '$endepoch' -format "%a %b %d %T %Z %Y"]' | tclsh | awk '{print $2,$3,$4,$6}'` ###################################################################### set last_logged_signal = `tail -1 /home/mcfuser/public_html/Beam_Current.log | awk '{print $5}'` # now filter stuff that is uninteresting if it is zero foreach signal ( Imono_In Imono_Out Izero Iend Horizontal_Centroid Vertical_Centroid Horizontal_FWHM Vertical_FWHM ) set mean = `awk '{++count;sum+=$6} END{if(count)print sum/count}' ${signal}.log` set sigma = `awk -v mean=$mean '{++count;sum+=($6-mean)^2} END{if(count)print sqrt(sum/count)}' ${signal}.log` cat ${signal}.log |\ awk -v mean=$mean -v sigma=$sigma '($6-mean)<6*sigma && $6>sigma/2' |\ cat >! ${tempfile}.log set before = `cat ${signal}.log | wc -l` set after = `cat ${tempfile}.log | wc -l` set loss = `echo "$before $after" | awk '{print $1-$2}'` if($after > 10) then mv ${tempfile}.log ${signal}.log endif end # report on last time signals were interesting foreach signal ( Beam_Current Imono_In Imono_Out Izero Iend Horizontal_Centroid Vertical_Centroid Horizontal_FWHM Vertical_FWHM ) set last_plotted_signal = `tail -1 ${signal}.log | awk '{print $5}'` set now = `echo "puts [expr [clock seconds] + $clockskew]" | tclsh` # retreive the most recent interesting signal reading set last_signal = `tail -1 ${signal}.log | awk '{print $5}'` # retreive the last gap in interesting signal set first_signal = `tac ${signal}.log | awk 'last-$5>300{print last;exit} {last=$5}'` if("$first_signal" == "") set first_signal = $startepoch set uptime = `echo $now $first_signal | awk '{d=$1-$2;h=int(d/3600);m=int(d/60)%60;s=d%60;printf "%02d:%02d:%02d",h,m,s;}'` set downtime = `echo $now $last_signal | awk '{d=$1-$2;h=int(d/3600);m=int(d/60)%60;s=d%60;printf "%02d:%02d:%02d",h,m,s;}'` set test = `echo $now $last_signal | awk '{print ($1 - 30 < $2)}'` if( $last_logged_signal == $last_plotted_signal ) then # this signal is "up" echo "$signal up for $uptime" else # this signal is down echo "$signal down for $downtime" endif end # now make the graphs... foreach signal ( Beam_Current Imono_In Imono_Out Izero Iend Mono_eV M2_Tilt Chi2 Z2 Theta2 Horizontal_Convergance_Angle Horizontal_Centroid Vertical_Centroid Horizontal_FWHM Vertical_FWHM Mono_Tank_Pressure Ion_Pump_Voltage lN2_Pressure diode2 ) set yaxis = "$signal" set title = "$signal" set using = 6 if(! -e "${signal}.log") then echo "ERROR: ${signal}.log is missing" endif if("$signal" == Vertical_Centroid) then if("$tuned_Vcen" == "") set tuned_Vcen = `tail -1 ${signal}.log | awk '{print $6+0}'` if("$tuned_Vcen" == "") set tuned_Vcen = 0 set title = "vertical beam position" set yaxis = "$title (um)" set using = '(($6-'$tuned_Vcen')*2.6242)' endif if("$signal" == Horizontal_Centroid) then if("$tuned_Hcen" == "") set tuned_Hcen = `tail -1 ${signal}.log | awk '{print $6+0}'` if("$tuned_Hcen" == "") set tuned_Hcen = 0 set title = "horizontal beam position" set yaxis = "$title (um)" set using = '(($6-'$tuned_Hcen')*14.069)' endif if("$signal" == Vertical_FWHM) then set title = "vertical beam size" set yaxis = "$title (um)" set using = '($6*2.6242)' endif if("$signal" == Horizontal_FWHM) then set title = "horizontal beam size" set yaxis = "$title (um)" set using = '($6*14.069)' endif if("$signal" == Theta2) then if("$tuned_Theta2" == "") set tuned_Theta2 = `tail -1 ${signal}.log | awk '{print $6+0}'` # set title = "expected beam position" # set yaxis = "$title (um)" # set using = '($6-'$tuned_Theta2')*1' endif if("$signal" == M2_Tilt) then if("$tuned_M2" == "") set tuned_M2 = `tail -1 ${signal}.log | awk '{print $6+0}'` if("$tuned_M2" == "") set tuned_M2 = 0 set title = "vertical beam steering" set yaxis = "$title (um)" set using = '($6-'$tuned_M2')*-2.1827' endif if("$signal" == Chi2) then if("$tuned_Chi2" == "") set tuned_Chi2 = `tail -1 ${signal}.log | awk '{print $6+0}'` if("$tuned_Chi2" == "") set tuned_Chi2 = 0 set title = "horizontal beam steering" set yaxis = "$title (um)" set using = '($6-'$tuned_Chi2')*53270.9' endif #rm -f graph.png #rm -f thmb.png gnuplot -persist << EOF set title "$signal" set grid set y2tics #set xtics set xdata time set timefmt "%b %d %H:%M:%S %Y" set xlabel "time of day" set xrange ["$startdate":"$enddate"] set ylabel "$yaxis" set y2label "ring current" set size 1,0.5 #set terminal png small color #set output "graph.png" #plot '${signal}.log' using 1:$using ti "$title", '/home/mcfuser/public_html/Beam_Current.log' using 1:6 axis x1y2 ti "Iring" plot '/home/mcfuser/public_html/Beam_Current.log' using 1:6 axis x1y2 ti "Iring" with l lt 2, '${signal}.log' using 1:$using ti "$title" lt 1 #set size 0.5,0.25 #set output "thmb.png" #plot '${signal}.log' using 1:$using ti "$title", '/home/mcfuser/public_html/Beam_Current.log' every 5 using 1:6 axis x1y2 ti "Iring" with l plot '/home/mcfuser/public_html/Beam_Current.log' using 1:6 axis x1y2 ti "Iring" with l lt 2, '/home/mcfuser/public_html/${signal}.log' using 1:$using ti "$title" lt 1 set output EOF #if(-s graph.png) mv graph.png ${signal}.png #if(-s thmb.png) mv thmb.png ${signal}_thmb.png end exit #if(! -e Izero.png) mv PX_Izero_thmb.png Izero_thmb.png #if(! -e Iend.png) mv PX_Iend_thmb.png Iend_thmb.png #if(! -e Izero.png) mv PX_Izero.png Izero.png #if(! -e Iend.png) mv PX_Iend.png Iend.png # report how long each motor has been where it currently is foreach motor ( Mono_eV M2_Tilt Chi2 Z2 Theta2 Horizontal_Convergance_Angle ) set now = `echo "puts [expr [clock seconds] + $clockskew]" | tclsh` set now = "$last_logged_signal" set last_value = `tail -1 ${motor}.log | awk '{print $6+0}'` set last_move = `tac ${motor}.log | awk -v last_value=$last_value 'sqrt(($6-last_value)^2)>0.001*last_value{print $5;exit}'` set hold_time = `echo "$now $last_move" | awk '{d=$1-$2;h=int(d/3600);m=int(d/60)%60;s=d%60;printf "%02d:%02d:%02d",h,m,s;}'` if("$last_move" == "") set hold_time = "ever" echo "$motor has been at $last_value for $hold_time" end # schedule the next check set now = `echo "puts [expr [clock seconds] + $clockskew]" | tclsh` set next_graph_update = `echo "$now $graph_update_rate" | awk '{printf "%d", $1+$2}'` if("$next_graph_update" == "" || "$next_graph_update" == "300") then echo "WHAT THE FUCK: now=$now next_graph_update=$next_graph_update" set next_graph_update = 0 endif exit ####################################################