#/bin/bash

usage="Usage: $0  datetime[%Y-%m-%d %H%M]"
cdate=`date -u +"%Y-%m-%d %H%M"`

# cdate is the end_time if window_hours is negative
window_minutes="-720.0"
#window_minutes="-2160.0"
sliding_interval="30"

# UTC time
if [ $# -lt 1 ]; then echo -e "$usage" ; exit 2; fi
sdate=`date -d "$1" +"%Y-%m-%d %H%M"`
edate=${sdate}
if [ -n "$2" ]; then
  edate=`date -d "$2 " +"%Y-%m-%d %H%M"`
fi

#sdate='2026-02-19 0000'
#edate='2026-02-19 0000'

echo "$sdate $edate"
# loop over days
ymd=$sdate
SATELLITES=(1 2 3 4 5 6)
SATELLITES=(6)

while [[ "$ymd" < "$edate" ]] || [[ "$ymd" = "$edate" ]] ;  do
  cdate=`date -d "$ymd " +"%Y-%m-%dT%H:%M:00"`
  for sat in "${SATELLITES[@]}"; do
    #python ucar2umd_rnx_rt.py cosmic2 $sat $ant -t "2026-04-05T03:00:00" --window-minutes ${window_minutes} --umd-repo '/ROSDC_data3/xinjiaz/data_GPSRO/UCAR_unpack_STAR'
    # python ucar2umd_att_rt.py cosmic2 2  -t "2026-04-05T03:00:00" --umd-repo '/data2/xinjiaz/data_GPSRO/UCAR'
    python ucar2umd_att_rt.py cosmic2 $sat -t $cdate --window-minutes ${window_minutes} --umd-repo '/data2/xinjiaz/data_GPSRO/UCAR'
    #python ucar2umd_rnx_rt.py cosmic2 $sat 1 -t $cdate --window-minutes ${window_minutes} --umd-repo '/ROSDC_data3/xinjiaz/data_GPSRO/UCAR_unpack_STAR'
    #python ucar2umd_rnx_rt.py cosmic2 $sat 2 -t $cdate --window-minutes ${window_minutes} --umd-repo '/ROSDC_data3/xinjiaz/data_GPSRO/UCAR_unpack_STAR'
    #python ucar2umd_rnx_rt.py cosmic2 $sat 1 -t $cdate --window-minutes ${window_minutes} 
    #python ucar2umd_rnx_rt.py cosmic2 $sat 2 -t $cdate --window-minutes ${window_minutes}
  done
  ymd=`date -d "$ymd + ${sliding_interval} minutes" +"%Y-%m-%d %H%M"`
done
