#! /bin/csh -f # # take a picture of your crystal # # # set output = "" set display set reso = 704x480 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) setenv beamline 831 set tclsh = tclsh set control = bl${beamline}c set axis = axis if("$beamline" =~ 82?) then # set tclsh = "ssh dcsuser@bl${beamline}c tclsh8.2" # set axis = axis-0 endif if("$beamline" == 821) set axis = bl822d2 if("$beamline" == 822) set axis = bl822d1 if("$beamline" == 501) set ptzaxis = 131.243.79.81 if("$beamline" == 501) set axis = 131.243.79.82 if("$beamline" == 502) set ptzaxis = 131.243.79.111 if("$beamline" == 502) set axis = 131.243.79.63 if("$beamline" == 503) set ptzaxis = 131.243.79.93 if("$beamline" == 503) set axis = 131.243.79.126 # scan the command line foreach arg ( $* ) if("$arg" =~ *.jpg) then set output = "$arg" continue endif if("$arg" =~ -nodisp*) unset display if("$arg" =~ "-fast"*) set noannotate if("$arg" =~ "-noanno"*) set noannotate if("$arg" =~ "-bgsub"*) set bgsub if("$arg" =~ *[0-9]x[1-9]*) then set temp = `echo $arg | awk -F "x" '$1+0>10 && $1+0<800 && $2+0>10 && $2+0 < 500{$1=int(704/int(704/$1));$2=int(480/int(704/$1)); printf "%dx%d", $1, $2}'` if("$temp" =~ *[0-9]x[1-9]*) set reso = "$temp" continue endif if("$arg" == "-mark") set mark if("$arg" == "-trim") set trim = 10 if("$arg" =~ [1234]) set snapcam = $arg if("$arg" == "axis2") set axis = axis2 end if("$output" == "") then # come up with a default name for the jpeg file set img_prefix = `echo -n "" | xos3_exchange.tcl 1 "set_motor_dependency" 1 |& awk '/configure_run /{printf "%s/%s_0_%03d", $7,$6,$8; exit}'` if("$img_prefix" != "") then set dir = `dirname $img_prefix` if(! -e "$dir") then mkdir -p $dir >& /dev/null endif touch ${dir}/.this$$ >& /dev/null if( ! $status ) then set output = "${img_prefix}.jpg" if (-e "$output") then set prefix = `echo $img_prefix | awk '{print substr($0,1,length($0)-3)}'` set num = `ls -1rt ${prefix}* |& tail -1 | awk -F "_" '{printf "%03d", $NF+1}'` set output = "${prefix}${num}.jpg" endif endif rm -f ${dir}/.this$$ >& /dev/null endif endif if ("$output" == "") then #set img_prefix = `echo -n "" | xos_exchange.tcl $control 1 "over out" 1 |& awk '/configure_run_text/{dir=$5;name=$4;run=$3} /configure_run run0/{num=$5; printf "%s/%s_%s_%03d\n", dir,name,run,num}' | tail -1` endif if("$output" == "") then set dir = "." if(! -w "$dir" && $?HOME) then set dir = "$HOME" endif if(! -w "$dir") set dir = "/tmp" set output = "${dir}/snap.jpg" endif set dir = `dirname $output` if(! -e "$dir") mkdir -p $dir # apply sensible defaults if(! $?snapcam) set snapcam = 1 # retreive the beam center and field-of-view for this camera if($?noannotate) then set beam set fov else set beam = `beam.com |& awk 'NF>1{print $(NF-1),$NF}' | tail -1` set fov = `fov.com |& awk 'NF>1{print $(NF-1),$NF}' | tail -1` endif if($#beam != 2) set beam = ( 0.5 0.5 ) if($#fov != 2) set fov = ( 1.0 1.0 ) # grab the image #wget -O $output 'http://bl'${beamline}$h'.als.lbl.gov:/axis-cgi/jpg/image.cgi?camera='$snapcam'&resolution='$reso'&compression=0' #if($status) then # wget -O $output 'http://bl'${beamline}'$h.als.lbl.gov:/cgi-bin/hugesize.jpg?camera='$snapcam'&compression=1' # if($status) exit $status #endif rm -f ${output} >& /dev/null wget --http-user=root --http-passwd=xxxxxxxx -O $output 'http://'${axis}'/axis-cgi/jpg/image.cgi?camera='${snapcam}'&resolution='${reso}'&compression=0&clock=0&date=0' >& /dev/null if(-s $output) goto gotit cat << EOF | $tclsh >! $output set sock [socket $axis 80] set header "" fconfigure \$sock -buffering none -translation binary #puts \$sock "GET /axis-cgi/jpg/image.cgi?camera=${snapcam}&resolution=${reso}&compression=0&clock=off&date=off HTTP/1.0\r\n\r" puts \$sock "GET /axis-cgi/jpg/image.cgi?camera=${snapcam}&resolution=${reso}&compression=0&clock=0&date=0 HTTP/1.0\r\n\r" while { ! ( [string match "*\r\n\r\n" "\$header"] || [string match "*\n\n" "\$header"]) } { append header [read \$sock 1] } fcopy \$sock stdout EOF gotit: echo saved $output if($?bgsub) then set camera = `camera.com | awk '{print $NF}'` set mag = himag if("$camera" == "2") set mag = midmag if("$camera" == "3") then set mag = lomag set door = `door.com |& awk '{print $4}'` if("$door" == "open") set mag = lomag_tray if("$door" == "closed") set mag = lomag_notray endif if(-e /data/calibrations/${mag}_background.im) then set path = ( /programs/kuim/bin/ $path ) echo "subtracting $mag background..." rm -f /tmp/tmp$$snap.im >& /dev/null type -f $output /tmp/tmp$$snap.im >& /dev/null rm -f /tmp/tmp$$bgsub.im >& /dev/null add -a 1 -b -1 /tmp/tmp$$snap.im /data/calibrations/${mag}_background.im /tmp/tmp$$bgsub.im >& /dev/null rm -f /tmp/tmp$$snap.im >& /dev/null rm -f /tmp/tmp$$bgsub.jpg >& /dev/null type -j /tmp/tmp$$bgsub.im /tmp/tmp$$bgsub.jpg >& /dev/null rm -f /tmp/tmp$$bgsub.im >& /dev/null mv /tmp/tmp$$bgsub.jpg $output endif endif if($?trim) then set xsize = `echo $reso | awk -F "x" '{print $1}'` set ysize = `echo $reso | awk -F "x" '{print $2}'` set crop = `echo $xsize $ysize $trim | awk '{printf "%dx%d+%d+%d", $1-2*$3,$2-2*$3,$3,$3}'` convert -quality 100 -crop $crop $output /tmp/tmp$$.jpg mv /tmp/tmp$$.jpg $output # correct the rasterization set reso = `echo $xsize $ysize $trim | awk '{print $1-2*$NF "x" $2-2*$NF}'` # correct the position of the beam center and fov set beam = `echo $beam $xsize $ysize $trim | awk '{print ($1*$3-$NF)/($3-2*$NF),($2*$4-$NF)/($4-2*$NF)}'` set fov = `echo $fov $xsize $ysize $trim | awk '{print $1*($3-2*$NF)/$3, $2*($4-2*$NF)/$4}'` endif # add microscope parameters as a JPEG comment if(! $?noannotate) then convert -quality 100 -comment "beam $beam fov $fov[1]mm $fov[2]mm " $output /tmp/tmp$$.jpg >& /dev/null if(! $status) then rm -f $output >& /dev/null mv /tmp/tmp$$.jpg $output endif endif # put a little circle on it? if($?mark) then set reso = `echo $reso | awk -F "x" '{print $1, $2}'` set beamsize = `grep pinhole /data/log/change.log | tail -1 | awk '{print $(NF-1)+0}'` set beamradius = `echo $beamsize $fov[1] $reso[1] | awk '{print ($1/$2)*$3/2/1000}'` if("$fov" == "" || "$beamsize" == "") set beamradius = 50 # mark the beam position set center = `echo $beam $reso | awk '{printf "%d,%d", $3*$1, $4*$2}'` set edge = `echo $beam $beamradius $reso | awk '{printf "%d,%d", $4*$1, $5*$2-$3}'` convert -quality 100 -fill none -stroke white -strokewidth 1 -draw "circle $center $edge" \ $output /tmp/tmp$$.bmp mv /tmp/tmp$$.bmp $output endif if("$?display") display $output exit ######################################################################## ######################################################################## NOTES... set reso = 704x480 set camera=1 cat << EOF | ssh mcfuser@bl822c "tclsh8.2" >! snap.jpg set sock [socket $axis 80] fconfigure \$sock -buffering none -blocking 1 -translation binary puts \$sock "GET /axis-cgi/jpg/image.cgi?camera=${camera}&resolution=${reso}&compression=0 HTTP/1.0\r\n\r" while { "[gets \$sock]" != "" } { } fcopy \$sock stdout EOF