#!/bin/csh -f

# Extract the end-of-15daily solutions from the 5 minutely leveled ISCs in the tdp file.
# End of day corresponds to 23:55 of each day. Key of the last day of the RfR comparison with ARL

# $1 is the input tdp file (uploadDcb_sta_sat.tdp.gz)
# Output goes to stdout

set key = `tail -1 /gdgps3/ocx/LiveSky2/ARL_Truth/15Day_epochs | awk '{print $NF}'`

set beg = `grep -v ^'#' /gdgps3/ocx/LiveSky2/ARL_Truth/15Day_epochs | head -1 | awk '{print $3}'`

zcat $1 | awk '{D = ('$key' - $1)/(15*86400); if ((D == int(D)) && ($1 >= '$beg') && ($1 <= '$key')) print $0}'
