sky2det (version 0.0)
You can also look at:
#! /usr/bin/ksh
###########################################################################
#
#
# SYNTAX: sky2det skyx skyy inst mode radius
#
# DESCRIPTION: This utility converts from sky coordinates to detector
# DESCRIPTION: coordinates. It does this by selecting all events with sky
# DESCRIPTION: coordinates within the given radius of the given point.
# DESCRIPTION: The detector coordinates are the mean of the detector coordinates
# DESCRIPTION: of the selected points.
# DESCRIPTION: detx and dety are echoed to stdout
# DESCRIPTION: NOTE: skyx, skyy, and radius MUST have a decimal point
# DESCRIPTION: in them.
#
# VERSION: 0.0
#
# HISTORY:
#
##############################################################################
skyx=$1
skyy=$2
inst=$3
mode=$4
radius=$5
$UTIL/log_entry "Converting ($skyx,$skyy,$radius) to $inst detector coordinates"
###################################
# select rows from event files
###################################
list=$($UTIL/generate_filename event $inst any $mode any )
list=$(ls $list 2>/dev/null)
rm -f files$$.tmp
i=0
for event in $list; do
rm -f z$$_$i.tmp
$UTIL/setup_parfile $FTOOLS/fselect.par infile="$event[1]" \
outfile=z$$_$i.tmp \
expr="CIRCLE($skyx,$skyy,$radius,X,Y)" \
histkw=no \
copyall=no \
keycopy=no \
clobber=yes
$FTOOLS/fselect >stdout.log 2>stderr.log
$UTIL/ftool_test fselect $? $0 2 stdout.log stderr.log
echo "z$$_$i.tmp" >> files$$.tmp
let i=$i+1
done
################################
# merging files
################################
rm -f z$$.tmp
$UTIL/setup_parfile $FTOOLS/fmerge.par infiles=@files$$.tmp \
outfile="z$$.tmp" \
columns="DETX DETY" \
copyprime=no \
history=yes \
clobber=yes
$FTOOLS/fmerge >stdout.log 2>stderr.log
$UTIL/ftool_test fmerge $? $0 2 stdout.log stderr.log
##################################################
# clear out the individual selection result files
##################################################
for file in $(cat files$$.tmp ); do
rm -f $file
done
rm -f files$$.tmp
###########################################################
# check if there were any photons within the given radius
###########################################################
naxis2=$($UTIL/read_fits_keyword z$$.tmp[1] NAXIS2 )
if [ -z "$naxis2" -o "$naxis2" = "0" ]; then
echo "No photons wthin radius"
rm -f z$$.tmp
exit 0
fi
######################
# find DETX
######################
$UTIL/setup_parfile $FTOOLS/fstatistic.par infile=z$$.tmp \
colname=DETX
$FTOOLS/fstatistic >stdout.log 2>stderr.log
code=$?
detx=$($UTIL/read_parfile fstatistic.par mean )
$UTIL/ftool_test fstatistic $code $0 2 stdout.log stderr.log
######################
# find DETy
######################
$UTIL/setup_parfile $FTOOLS/fstatistic.par infile=z$$.tmp \
colname=DETY
$FTOOLS/fstatistic >stdout.log 2>stderr.log
code=$?
dety=$($UTIL/read_parfile fstatistic.par mean )
$UTIL/ftool_test fstatistic $code $0 2 stdout.log stderr.log
rm -f z$$.tmp
#############################
# echo results to stdout
#############################
echo "$detx $dety"
exit 0