#!/bin/sh
#
# $Id$

FITS=$1

if [ -z "$FITS" ]; then
   echo "Usage: $0 filename(fits)"
   exit 0
fi

# region file
COO=${FITS%fits}COO
REG=${FITS%fits}REG
if [ -f "$COO" ]; then
  MPHOT=mphot.opt
  if [ -f "$MPHOT" ]; then
     R=$(awk '{if( /FWHM OF OBJECT/ ) print $5; }' < $MPHOT)
  else
     R=3
  fi

  echo 'global color=yellow font="helvetica 10 normal" edit=0 move=0 delete=0 highlite=0' > $REG
  awk -v r=$R '{ if( /^ *[0-9][0-9]*([ ]+[0-9][0-9]*[.]+[0-9][0-9]*)+/ ) print "circle",$2,$3,r; }' < $COO >> $REG

  ds9 -zscale $FITS -regions $REG
  rm $REG
else
  echo "No $COO has been found."
fi

