#!/bin/bash
#SBATCH -n 1
#SBATCH -t 01:00:00
#SBATCH -J gfasftp
##SBATCH -e /esarchive/recon/ecmwf/gfas/scripts/i535-marc-hourly/out-logs/format-ftp-%j.err
##SBATCH -o /esarchive/recon/ecmwf/gfas/scripts/i535-marc-hourly/out-logs/format-ftp-%j.out

#module load xarray/0.19.0-foss-2019b-Python-3.7.4
#module load netcdf4-python/1.5.8-foss-2019b-Python-3.7.4
#module load dask/2022.2.0-foss-2019b-Python-3.7.4
#module load numpy/1.21.6-foss-2019b-Python-3.7.4

#default values, take if not given in command line
script_root_default=/esarchive/scratch/rgrodofz/software/ghost/GHOST/download_scripts
dl_root_default=/esarchive/obs/ghost
network_list_default=WMO_WDCGG

# options passed
while [ True ]; do
if [ "$1" = "-t" ]; then
    testing=true

    # default arguments
    script_root=${2:-$script_root_default}
    dl_root=${3:-$dl_root_default}
    network_list=${4:-$network_list_default}

    break
else
    testing=false

    # default arguments
    script_root=${1:-$script_root_default}
    dl_root=${2:-$dl_root_default}
    network_list=${3:-$network_list_default}

    # load modules
    source $script_root/load_modules.sh

    break
fi
done

# load modules
source $script_root/load_modules.sh

# run download script
time python3 -u $script_root/run_GHOST_downloads.py $script_root $dl_root $network_list $testing #script path, download path, network list, test mode flag