#!/bin/csh -f
#PBS -N gen_stats
#PBS -l select=1:ncpus=36:mpiprocs=36
#PBS -l walltime=00:03:00
#PBS -q premium
#PBS -A UMMM0004
#PBS -j oe

# environment
# ===========
source /etc/profile.d/modules.csh
module purge
module load conda/latest
conda activate npl

setenv HDF5_DISABLE_VERSION_CHECK 1
setenv NUMEXPR_MAX_THREADS 1

# directories
# ===========
set DIR = /glade/scratch/$USER/mpas_jedi_tutorial

# graphics
set graphDir = ${DIR}/graphics

# experiment
set expdir = ${DIR}/omboma_from2experiments/${exp}
set daDiagDir = ${expdir}/CyclingDA/${da}
set WorkDir = ${daDiagDir}/stats

mkdir -p ${WorkDir}
cd ${WorkDir}

ln -fs ${graphDir}/*.py ./
set mainScript = "DiagnoseObsStatistics.py"
set NUMPROC = 36

mv log.${mainScript} log.${mainScript}_LAST

python ${mainScript} -n ${NUMPROC} -p ${daDiagDir} -o obsout -app variational -nout 1 >& log.${mainScript}
set status=$?

grep "Finished __main__ successfully" log.${mainScript}
if ( $status != 0 ) then
  echo "ERROR in $0 : ${mainScript} failed" > ./FAIL
  exit 1
endif

date

exit
