#!/bin/sh
#++++++++++++++++
# Copyright:    (C) 2008-2017 UDS/CNRS
# License:       GNU General Public License
#.IDENTIFICATION findgsc
#.LANGUAGE       C-shell
#.AUTHOR         Francois Ochsenbein [CDS]
#.ENVIRONMENT
#.KEYWORDS
#.VERSION  1.0   18-Feb-1993
#.VERSION  1.1   28-Sep-1995: Now on vizir ...
#.VERSION  1.2   23-Apr-1996: New version...
#.VERSION  1.3   24-May-1999: 1.2 option
#.VERSION  2.0   11-Dec-2001; 2.2 option/version
#.VERSION  2.1   31-Jan-2002: Corrected bug for -f option
#.VERSION  2.2   31-Jan-2004: Accept file input in -g option
#.VERSION  2.3   01-Sep-2008: for proxy usage
#.VERSION  2.4   28-Aug-2009: Bourne version
#.PURPOSE        Find Stars in Guide Star Catalogue (GSC-I and GSC-II)
#		around a position or from name
#.COMMENTS       Interface to the "aclient" remote query
#	For direct queries, use
#	aclient 130.79.129.166 1660 gsc[1.1|1.2|1.3|2.2|2.3] [options]
#	   all options for each GSC version listed by -help, e.g.
#	aclient 130.79.129.166 1660 gsc2.3 -help
#----------------

D_BIN=`dirname $0`
pgm=`basename $0`
rpc=`basename $0 | sed 's/find//'`
# No argument is assumed to call for help
test $# -eq 0 && exec $0 -help

# GSC: the version may be specificied as an argument
#   or at the end of the program
vers=`basename $0 | sed 's/findgsc-*//'`

if [ -z "$vers" ]; then
    case "$1" in 
    [12].*) vers="$1"; shift; 	;;
      [12]) vers="$1"; shift; 	;;
  [Aa][Cc][Tt]) vers="1.3"; 	;;
       "")  echo "Usage: $pgm version [GSCversion-specific options]..."
            exit 1		;;
        *)  vers="1.2";         ;;	# Default GSC version
    esac
fi
test $# -eq 0 && exec $pgm $vers -help

case "$vers" in
    1) vers="1.2"; ;;	# Default GSC-I version
    2) vers="2.3"; ;;	# Default GSC-II version
  [Aa][Cc][Tt]) vers="1.3"; 	;;
esac

rpc="gsc${vers}"
pgm="find$rpc"
#echo "#...rpc=$rpc, pgm=$pgm, args=$* ($#)"

case "$1" in
     h*)  # Assume help
      exec $0 -help
      ;;
    -h*)  # Differs from standard help
    cat <<===Help
--------------------------------------------------------------------
Available GSC versions:
     1.1  (1991)           1.2  (1996)        1.3 (=GSC-ACT)
     2.2  (August 2001)    2.3  (April 2007)
--------------------------------------------------------------------
Usage: $pgm J2000-center [-r radius_in_arcmin]
   or  $pgm -g GSC-id [other_options]
   or  $pgm -g - [other_options]     (GSC identifiers in stdin)
   or  $pgm -f [file_with_data] [other_options]
   or  $pgm - [other_options]        (data in stdin)
===Help
    exec $D_BIN/find_gen $pgm $rpc -rhelp
    ;;

  # Use the generic find_gen service
  *)
    exec $D_BIN/find_gen $pgm $rpc "$@"
    ;;
esac
