
#!/bin/bash
#####################################################################
# 
# rt_wget_gnss_ultra.bash 
#
# Purpose:
# This shell script automates the download of COD0OPSULT GNSS
# product data from NASA web servers and supports automated
# real-time processing via a cron job.
# https://cddis.nasa.gov/archive/gnss/products/latest/ultra/
#
# History:  
#       Created by: Ming Chen 2026/04/18
#                   ming.chen@noaa.gov
# 
# Usage: rt_wget_gnss_ultra.bash [yyyymndd hh]
# 
#
#####################################################################
#
pkghome=/home/mchen36/wrk/RT_COSMIC2_REL1.2
cd  $pkghome
source  ${pkghome}/set_env.bash
if [ -z "${podgen_home}" ]; then 
   echo "env is not set up, source the set_env.bash file first .."
   exit
fi
source ${utils_home}/gpsdate.bash
podgen=${podgen_home}
latency=2 

# current real UTC
cdate=$(date -u +"%Y%m%d %H%M")  
cdate=`date -d "$cdate -${latency} hours" +"%Y%m%d %H%M"`
# the local time with  UTC + %z - latency
# %z is -4 summer saving time, -5 normal time
# 22 04 10 16 or 23 05 11 17

# user input UTC, the hour must be in 0 6 12 18
if [ -n "$1" ]; then
 cdate="$1"
fi

ymd=`date -d "$cdate " +%Y%m%d`
h=`date -d "$cdate " +"%H"`
h=$((10#$((10#$h / 6)) * 6 ))
hh=$(printf "%02d" "$h")

echo " python rt_wget_gnss_ultra.py ${ymd}T${hh}"
python rt_wget_gnss_ultra.py "${ymd}T${hh}"
