#!/bin/csh -f
#++++++++++++++++
#.IDENTIFICATION simref
#.LANGUAGE       C-shell
#.AUTHOR         Francois Ochsenbein [CDS]
#.ENVIRONMENT    
#.KEYWORDS       
#.VERSION  1.0   18-Feb-1993
#.VERSION  1.1   25-Nov-1995: Allow writing like "A+A, 295, 66"
#.VERSION  1.2   27-Jun-2006: Option -f
#.VERSION  1.3   26-Jan-2007: Simbad4
#.VERSION  1.4   17-Sep-2009: option -head => show header
#.PURPOSE        Get All Texts from Simbad References
#.COMMENTS       
#----------------
set D_BIN = `dirname $0`
set path = ($D_BIN /usr/local/bin /usr/bin /usr/ucb /bin)

set acl_con = "aclient cdsarc.u-strasbg.fr 1660"
set cgi_con = "aclient_cgi cdsarc.u-strasbg.fr"

set rcon="$acl_con"
which aclient |& grep -v ' ' >& /dev/null # note SUN needs the grep
if( $status > 0 || $?http_proxy ) set rcon="$cgi_con"

if ($#argv < 1) then
    echo "Usage: `basename $0` {Simbad-Reference|-f file_name}"
    #echo "    -f References are contained in file_name (- for standard input)"
    echo "A SIMBAD Reference is written YYYYJJJJJ.v.pA"
    echo "  with YYYY = Year"
    echo "      JJJJJ = Journal abbreviation",
    echo "      v=Volume, p=Page, A=1st letter of 1st Author"
    exit 1
else
    set call = `echo "$*" | tr '&/,: ' '+....' | tr -s .`
endif

if (("$1" =~ "-h"*) && ("$1" !~ "-head"*)) then	# assume -help
    exec $0
endif

if ("$1" == "-f") then
    shift
    set Ufile = `cat $* | $rcon savbib`
    if ($#Ufile < 1) then
        echo "****simref: could'nt transmit the file $*"
	exit 1
    endif
    $rcon simref -in $Ufile[1]
    exit $status
endif

$rcon simref $call 
exit $status
