#!/bin/csh -f
#++++++++++++++++
#.IDENTIFICATION getsp
#.LANGUAGE       C_shell
#.AUTHOR         Francois Ochsenbein <francois@astro.u-strasbg.fr>
#.ENVIRONMENT    CDS Catalogues Service
#.KEYWORDS       
#.VERSION  1.0   13-Oct-2000
#.PURPOSE        Find out the spectrophotometry for a file
#.COMMENTS       The program accepts the following arguments:
#	Arg#1 (required): table name (WITH .dat)
#	Arg#2 (required): record number within file 
#----------------

#### Check the number of arguments in the correct range.
if ($#argv != 2) then
    echo "Usage: $0 tablename recno"
    echo "       Print out the spectrophotometry for one star"
    exit 1
endif
set table = `basename $1`.dat
set recno = $2

#### Print the wavelength and flux (Wavelength in col#1, flux in col#k)
if ($?PATH_INFO) then
    echo "\section{Flux for star {\em\#$recno\quad} from file {\tt $table}}"
    echo "\begin{alltt}"
    set tex = 1
else
    echo "#Flux for star #$recno from file $table"
    set tex = 0
endif

/usr/local/bin/fcat $table | gawk -v tex=$tex "NR == $recno"'{file=$1; \
    if (tex>0) c="\\"; \
    print c "#File Name:   ", $1; \
    print c "#Observation date:",$2; \
    u = "arbitrary_units";  if (index($0,"yes")>0) u = "mW/m2/Ang"; \
    printf("%s# Ang   Flux(%s)\n", c, u) ; \
    cmd = "/usr/local/bin/fcat " file;  \
    while((cmd|getline)>0) print $0; close(cmd);  \
  }'
if ($?PATH_INFO) echo "\end{alltt}\hline"
#######################################################################
