#!/bin/csh -f
#++++++++++++++++
#.IDENTIFICATION getobs
#.LANGUAGE       C_shell
#.AUTHOR         Francois Ochsenbein <francois@astro.u-strasbg.fr>
#.ENVIRONMENT    CDS Catalogues Service
#.KEYWORDS       
#.VERSION  1.0   26-May-1999
#.PURPOSE        Find out the corresponding observation
#.COMMENTS       The program requires the JD and
#	Arg#1 (required): JD
#----------------

#### Check the number of arguments in the correct range.
if ($#argv < 1) then
    echo "Usage: $0 JD"
    echo "       Print out the observation file containing the JD"
    exit 1
endif

#### Get the 3 words: JD YYYY-MMM-DD hh:mm:ss as info[1] [2] [3]
set info = `/usr/local/bin/fcat $0.jd | grep ^$1 | acut -d\; -f1`
#### Derive the observation file name
set f = `echo $info[2] | gawk -F- '{print substr($1,3) tolower($2) $3}'`.dat

#echo "info=" $info "f=" $f

#### Print the wavelength and flux (Wavelength in col#1, flux in col#k)
if ($?PATH_INFO) then
    echo "\section{Observations at HJD$1 from file {\tt $f}}"
    echo "\begin{alltt}"
    echo "\#  Date  UTC  Time    ExpTime air    HRV       Flux"
    echo "\#                       (s)        (km/s)      ----"
else
    echo  "## Observation at HJD$1 from file: $f"
    echo  "#  Date  UTC  Time    ExpTime air    HRV       Flux"
    echo  "#                       (s)        (km/s)      ----"
endif

#ls -l $f.*
/usr/local/bin/fcat $f | grep "^$info[2] $info[3]"

if ($?PATH_INFO) echo "\end{alltt}\hline"
#######################################################################
