#! /bin/csh -f # # maximize the cross-section of the centered sample by rotating phi # # # set start_time = `echo "puts [clock seconds]" | tclsh` set path = ( /programs/kuim/bin $path ) set tempfile = tempfile #set reso = 704x480 set reso = 352x240 set phis = "$1" set phis = `echo $phis | awk '$1+0<3{$1=3} {step=180/($1-1); for(phi=0;phi<=180;phi+=step) print phi}'` echo -n "" >! ${tempfile}.rot more_points: foreach phi ( $phis ) phi.com $phi > /dev/null snap.com ${tempfile}.jpg -nodisplay $reso >& /dev/null echo -n "$phi " | tee -a ${tempfile}.rot ls -l ${tempfile}.jpg | awk '{printf " %d ", $5}' | tee -a ${tempfile}.rot # extract an "outer border" mask of the loop convert -normalize -threshold 32768 -mattecolor white ${tempfile}.jpg ${tempfile}mask.bmp convert -fill green -draw "color 10,10" -fill green -draw "color 10,230" -channel Green -normalize ${tempfile}mask.bmp ${tempfile}mask.jpg #if($?debug) animate -delay 20 ${tempfile}.jpg ${tempfile}mask.jpg mv ${tempfile}mask.jpg ${tempfile}.jpg rm -f ${tempfile}.im >& /dev/null type -f ${tempfile}.jpg ${tempfile}.im >& /dev/null header ${tempfile}.im |\ awk '/^Entropy/{printf " %s ", $NF}' |\ tee -a ${tempfile}.rot echo "" | tee -a ${tempfile}.rot end rm -f ${tempfile}.im ${tempfile}.jpg >& /dev/null rm -f ${tempfile}mask.jpg ${tempfile}mask.bmp >& /dev/null set plot = "" if($?debug) set plot = "plot '${tempfile}.rot', a*cos(0.0349*(x-b))+c" # fit a sine wave to get lowest-order phi-dependent term of image entropy echo "fit a*cos(0.0349*(x-b))+c '${tempfile}.rot' via a,b,c; $plot " |\ gnuplot -persist |&\ awk '/^a / && $4=="+/-"{a=$3} /^b / && $4=="+/-"{b=$3} END{print a,b}' |\ cat >! ${tempfile}.fit set amp = `awk '{print $1}' ${tempfile}.fit` set min = `awk '$1<0{$2+=90} {print int($2+90)%180}' ${tempfile}.fit` set max = `awk '$1<0{$2+=90} {print int($2+0)%180}' ${tempfile}.fit` #echo "amp = $amp" phi.com $max rm -f ${tempfile}.fit ${tempfile}.rot >& /dev/null