#! /bin/tcsh -f
#
#	Jiffy for changing wavelength
set energy = ""
if($?QUERY_STRING) set CGI
if($?CGI) then
    # we are running as CGI
    echo "Content-Type: text/html\n"
    set path = ( `pwd` $path )
endif
if("$1" != "") then
    set energy = `echo $1 | awk '$1+0>1000{print $1+0} $1+0<3 && $1+0>0.1{printf "%.2f", 12398.4245/$1}'`
endif
# allow use of element symbol/name
if(("$1" =~ *[a-z]*)||("$1" =~ *[A-Z]*)) then
    set temp = `echo "$1" | elements | awk '{print $3, $4, $4-20, $4+20; exit}'`
    if($#temp == 4) then
	echo "$temp[1] edge: $temp[2]"
	set energy = $temp[2]
    endif
endif
if("$energy" != "") then
    echo "moving Mono to $energy eV"
    set newenergy = `blmotor.com Mono eV $energy | tail -1 | awk '$NF+0>2000{print $NF}'`
    if("$newenergy" == "") then
	echo "unable to move motor."
	set beamline = `beamline.com`
        echo 'please switch the beamline control computer (bl'${beamline}'b) to "Remote Control"'
	exit 9
    else
	set energy = "$newenergy"
    endif
else
    set energy = `blmotor.com Mono eV | awk '{printf "%.3f", $NF+0}'`
endif
if($?CGI) echo "
"
echo "$energy"| awk '{printf "Energy: %.3f eV\n", $NF+0}'
if($?CGI) echo "
"
echo "$energy"| awk '{printf "Wavelength: %.5f A\n", 12398.4245/$1}'
if($?CGI) echo "
"