#!/bin/bash
#####################################################################
# 
# rt_batch_reproc.bash
#
# Purpose:
# This script performs reprocessing of real-time BERNESE runs that 
# were unsuccessful due to insufficient CPU resources or delayed 
# availability of required input data.
# 
#
# History:  
#       Created by: Ming Chen 2026/05/5
#                   ming.chen@noaa.gov
# 
# Usage: rt_batch_reproc.bash
# 
#
#####################################################################
#

pkghome=/home/mchen36/wrk/RT_COSMIC2_REL1.2
cd $pkghome
source set_env.bash

if [ -z "${podgen_home}" ]; then 
   echo "env is not set up, source the set_env.bash file first .."
   exit
fi

podgen=${podgen_home}

sdate="2026-07-14 08:00:00"
edate="2026-07-14 09:00:00"

# Convert dates to Unix epoch seconds
current_sec=$(date -d "$sdate" +%s)
end_sec=$(date -d "$edate" +%s)

while (( current_sec < end_sec )); do
    # Format and display the current interval
    mydate=`date -d "@$current_sec" "+%Y-%m-%dT%H:%M:%S"`
    echo "$mydate"
    i=0
    while (( i < 1 )); do    
       python update_yaml.py -t "$mydate" -i rt_cosmic2_reproc.yaml -o rt_cosmic2_reproc.yaml
       python ${podgen}/rt_bern_proc.py --config-file rt_cosmic2_reproc.yaml 
      ((i++))
    done
    # Add the sliding seconds 
    ((current_sec += 1800))
done
