#!/bin/bash

# display weekly schedule for NuSTAR
# wsNuSTAR {-h}

#SRK 2021-FEB-05
#-----------------------------------------------------------------------
HELP=; TF="OUT_wsNuSTAR.txt"
#-----------------------------------------------------------------------
trap "[ -e $TF ] && rm $TF" EXIT
#-----------------------------------------------------------------------
URL="http://nustarsoc.caltech.edu/NuSTAR_Public/NuSTAROperationSite/"
#-----------------------------------------------------------------------

while getopts h OPTVAL
do
    case $OPTVAL in
        h) HELP=1;;
        *) echo "wsNUSTAR -h for help"; exit -1
    esac
done
shift $((OPTIND-1))

if [ $HELP ]; then
  echo "wsNuSTAR -{h}"
  echo "produces planned schedule for the NuSTAR X-ray Observatory"
  exit
fi

#-----------------------------------------------------------------------
#the Big Lift!
#-----------------------------------------------------------------------

curl -s "$URL/file/sr-schedule.txt" -o $TF

echo 
awk 'BEGIN{print "YYYY:DOY:HH:MM Source RA DEC ksec type"
     print "-------------- ----------------- ------ ------ ----- ----"}
     !/^;/{sub(/:..$/,"",$1)
           printf ("%s %s %7.2f %6.2f %3.1f %s\n", $1,$4,$5,$6,$7,$8)}' $TF \
     | column -t  | sed 's/:/ /;s/:/ /'