#!/bin/bash

# ltsCXO: obtain long term schedule  for CXO, including pool targets
# usage: ltCXO   [no other inputs]
# output: LTS.txt, Pool.txt
# needs "textutil"

# LAST REVISED: 2 February 2021
#----------------------------------------------------------------------- 
OFL=LTS.txt  OFP=Pool.txt
:> $OFL; :> $OFP 
#----------------------------------------------------------------------- 
TF="OUT_ltCXO" TFh=${TF}.html TFt=${TF}.txt
trap "[ -e $TFh ] && rm $TFt $TFh" EXIT
#----------------------------------------------------------------------- 
HDR="Name                  ksec     RA        DEC     Instrument"


curl -s "https://cxc.harvard.edu/target_lists/longsched.html" > $TFh
textutil -convert txt $TFh    #output in $TFt

#Long Term Schedule targets

echo "LONG TERM SCHEDULE: CXO"; echo "$HDR" | tee -a $OFL
sed '1,/Click here for table header/d;/ Pool Targets /,$d' $TFt | \
	grep "^[0-9][0-9]* " | cut -c17-61 -c86-101 | tee -a $OFL

#Pool Targets

printf "\nPOOL TARGETS\n"; printf "%s\n" "$HDR" | tee -a $OFP
sed -n '/ Pool Targets/,/ LTS changes *$/p' $TFt | \
	grep "^[0-9][0-9]* " | cut -c17-61 -c86-101 | tee -a $OFP
