#!/bin/csh
#SBATCH --job-name=AnStat_amsua_n18_BinValAxisProfileDiffCI
#SBATCH --ntasks=64
#SBATCH --cpus-per-task=1
#SBATCH --mem=480G
#SBATCH --time=00:60:00
#SBATCH --partition=PESQ2
#SBATCH --output=log.job.out

date

#
# set environment:
# ================
source /mnt/beegfs/andy.stokely/spack-stack/spack/opt/spack/linux-rhel8-zen2/gcc-12.2.0/lmod-8.7.24-u3b6n6iarioyrubv4zseezun5hzsnquo/lmod/8.7.24/init/csh
setenv HDF5_DISABLE_VERSION_CHECK 1
setenv NUMEXPR_MAX_THREADS 1

setenv pySourceDir /mnt/beegfs/luiz.sapucci/mpas_jedi_tutorial/omboma_from2experiments/graphics

set mainScript = AnalyzeStats
ln -sf ${pySourceDir}/${mainScript}.py ./

#
# make plots:
# ===========
module purge
ml anaconda3-2022.05-gcc-11.2.0-q74p53i
source "/opt/spack/opt/spack/linux-rhel8-zen2/gcc-11.2.0/anaconda3-2022.05-q74p53iarv7fk3uin3xzsgfmov7rqomj/etc/profile.d/conda.csh"
conda env list
conda activate /mnt/beegfs/professor/conda/envs/mpasjedi
setenv PYTHONDONTWRITEBYTECODE 1 # avoid __pycache__ creation
module list

set success = 1
set try = 0
while ($success != 0 && $try < 5)
  @ try++
  echo "try=$try"

  python ${mainScript}.py -n 1 -r 128 -d amsua_n18 -app variational -nout 1 -a BinValAxisProfileDiffCI >& an.log
  grep 'TypeError: super() takes at least 1 argument (0 given)' an.log
  if ( $status == 0 ) then
    sleep 2
    deactivate
    module purge
    ml anaconda3-2022.05-gcc-11.2.0-q74p53i
    source "/opt/spack/opt/spack/linux-rhel8-zen2/gcc-11.2.0/anaconda3-2022.05-q74p53iarv7fk3uin3xzsgfmov7rqomj/etc/profile.d/conda.csh"
    conda env list
    conda activate /mnt/beegfs/professor/conda/envs/mpasjedi
    module list
  else
    set success = 0
  endif
end

grep 'Finished main() successfully' an.log
if ( $status != 0 ) then
  touch ./FAIL
  exit 1
endif

rm ./*.py

date

exit
