#!/usr/bin/env bash
# Wenchang Yang (wenchang@princeton.edu)
# Sun Jan  1 20:13:55 EST 2023
#run under tigercpu
##SBATCH --nodes=1                # node count
##SBATCH --ntasks-per-node=1      # number of tasks per node
# 
#SBATCH --ntasks=1               # total number of tasks across all nodes = nodes x ntasks-per-node
#SBATCH --cpus-per-task=1        # cpu-cores per task (>1 if multi-threaded tasks)
#SBATCH --mem-per-cpu=4G         # memory per cpu-core (4G is default)
#SBATCH --time=24:00:00          # total run time limit (HH:MM:SS)
#SBATCH --mail-type=all          # send email when job begins/ends/fails
#SBATCH --mail-user=wenchang@princeton.edu
# 
##SBATCH --array=1-100#%32        # job array with index values 1, 2, ...,; max job # is 32 if specified
##SBATCH --output=slurm-%A.%a.out # stdout file
##SBATCH --error=slurm-%A.%a.err  # stderr file
set -ve
##env settings
#export PATH=/tigress/wenchang/miniconda3/bin:$PATH
#export PYTHONPATH=/tigress/wenchang/wython
#export PYTHONUNBUFFERED=TRUE # see https://stackoverflow.com/questions/230751/how-to-flush-output-of-print-function
#export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK #for multi-threaded job
#ii_job=$SLURM_ARRAY_TASK_ID #for job array
#year=23
year=24

#current year sreport
ofile=sreport.20${year}.txt
if [ -e $ofile ]; then
    echo "[exists]: $ofile"
else
    sreport cluster UserUtilizationByAccount -t HourPer start=01/01/${year} end=01/01/$((year+1)) >> $ofile
    echo "[created]: $ofile"
fi

#current year report, geoclim only
ofile_geoclim=sreports.geoclim.20${year}.txt
if [ -e $ofile_geoclim ]; then
    echo "[exists]: $ofile_geoclim"
else
    head -n6 $ofile > $ofile_geoclim
    #sreport cluster UserUtilizationByAccount -t HourPer start=01/01/${year} end=01/01/$((year+1)) |grep geoclim >> $ofile_geoclim
    cat $ofile |grep geoclim >> $ofile_geoclim
    echo "[created]: $ofile_geoclim"
fi

#2018 - current year sreport
ofile=sreport.2018-20${year}.txt
if [ -e $ofile ]; then
    echo "[exists]: $ofile"
else
    sreport cluster UserUtilizationByAccount -t HourPer start=01/01/18 end=01/01/$((year+1)) >> $ofile
    echo "[created]: $ofile"
fi

#2018 - current year report, geoclim only
ofile_geoclim=sreports.geoclim.2018-20${year}.txt
if [ -e $ofile_geoclim ]; then
    echo "[exists]: $ofile_geoclim"
else
    head -n6 $ofile > $ofile_geoclim
    #sreport cluster UserUtilizationByAccount -t HourPer start=01/01/18 end=01/01/$((year+1)) |grep geoclim >> $ofile_geoclim
    cat $ofile |grep geoclim >> $ofile_geoclim
    echo "[created]: $ofile_geoclim"
fi

