user_communication()
{
  echo "Are you happy with the pointing? (y)"
  read bla
  ZENTRUM=`xpaget WWFI-fc regions -format ds9 -system wcs -sky fk5 -skyformat sexagesimal | head -n 5 | tail -n 1 | grep -o -P '(?<=\().*(?=\))' | awk 'BEGIN {FS=","}; {print $1,$2}' | awk 'BEGIN {FS="."} {print $1,$2}' | awk '{print $1,$3}'`
  PA=`xpaget WWFI-fc regions -format ds9 -system wcs -sky fk5 -skyformat sexagesimal | head -n 5 | tail -n 1 | grep -o -P '(?<=\().*(?=\))' | awk 'BEGIN {FS=","}; {printf "%3.0f", $5}'`
  if [ "$PA" -gt "180" ]
  then
    PA=$(($PA - 360))
  fi
  echo 'image; text 1800 200 # text={Center = '$ZENTRUM'} color=blue font="helvetica 15 normal roman"' | xpaset WWFI-fc regions
  echo 'image; text 1470 400 # text={PA = '$PA'°} color=blue font="helvetica 15 normal roman"' | xpaset WWFI-fc regions
  echo 'image; text 1800 3350 # text={'$OBJECT'} color=blue font="helvetica 15 normal roman"' | xpaset WWFI-fc regions

  echo "Do you want to save a jpeg? (y/n)"
  read savejpeg
  if [ "$savejpeg" == "y" ]
  then
    xpaset -p WWFI-fc saveimage jpeg ${OBJECT}_WWFI-fc.jpeg 100
    echo "Your image has been saved as $WWFI/Finding_Charts/${OBJECT}_WWFI-fc.jpeg"
  fi
  #get RA DEC in degrees
  echo "Center coordinates are:"
  xpaget WWFI-fc regions -format ds9 -system wcs -sky fk5 -skyformat degrees | head -n 5 | tail -n 1 | grep -o -P '(?<=\().*(?=\))' | awk 'BEGIN {FS=","}; {print "RA="$1/360*24" h","DEC="$2" deg"}'

}

if [ $# == "1" ]
then
  OBJECT=$1
  ds9 -title WWFI-fc -width 750 -height 750 -cmap heat -cmap invert yes -zscale -dsseso survey DSS2-red -dsseso size 60 60 arcmin -dsseso name $OBJECT -region CCDs.reg -zoom to fit -dsseso close &
 user_communication $OBJECT
elif [ $# == "3" ]
then
  RA=$1
  DEC=$2
  OBJECT=$3
  ds9 -title WWFI-fc -width 750 -height 750 -cmap heat -cmap invert yes -zscale -dsseso survey DSS2-red -dsseso size 60 60 arcmin -dsseso coord $RA $DEC sexagesimal -region CCDs.reg -zoom to fit -dsseso close &
  user_communication $OBJECT
else
  echo "usage: finding_chart.sh [OBJECTNAME]"
  echo " or    finding_chart.sh [RA] [DEC] [OBJECTNAME]"
  echo " "
  echo " e.g.  finding_chart.sh M31"
  echo " or    finding_chart.sh 0:42:44 +41:16:13 M31"
fi

#DS9 Syntax:
#-dsseso []
#        [<object>]
#        [name <object>]
#        [coord <ra> <dec> degrees|sexagesimal] # in wcs fk5
#        [size <width> <height> degrees|arcmin|arcsec]
#        [save yes|no]
#        [frame new|current]
#        [update frame|crosshair]
#        [survey DSS1|DSS2-red|DSS2-blue|DSS2-infrared]
#        [open|close]
