
#!/bin/bash
# Run download_imerg.py as a SEPARATE fresh process per year (a single
# long-lived process silently stalled after several minutes in practice).
cd "$(dirname "$0")/../.."
mkdir -p cache
if [ -f "$HOME/.venvs/obs_vn_grid/bin/activate" ]; then
  source "$HOME/.venvs/obs_vn_grid/bin/activate"
fi
# Either direction: "2006 2025" (ascending) or "2025 2006" (descending).
if [ "$1" -le "$2" ]; then
  years=$(seq "$1" "$2")
else
  years=$(seq "$1" -1 "$2")
fi
for year in $years; do
  echo "YEAR_START: $year"
  python3 scripts/grid/download_imerg.py "$year" "$year" >> cache/imerg_download.log 2>&1
  echo "YEAR_END: $year"
done
echo "ALL_YEARS_DONE"


