#!/bin/bash -e

# Batch system directives
#SBATCH  --job-name=run.v2_F2010_nc00_freq
#SBATCH  --nodes=4
#SBATCH  --output=run.v2_F2010_nc00_freq.%j 
#SBATCH  --exclusive 
#SBATCH  --constraint=cpu

# template to create a case run shell script. This should only ever be called
# by case.submit when on batch. Use case.submit from the command line to run your case.

# cd to case
cd /pscratch/sd/h/huiwan/vis/ncic/cases_202411/v2_F2010_nc00_freq/case_scripts

# Set PYTHONPATH so we can make cime calls if needed
LIBDIR=/global/cfs/cdirs/m4792/huiwan/vis/ncic/code/maint-2.0_CondiDiag1.0_cdnc/cime
export PYTHONPATH=$LIBDIR:$PYTHONPATH

# setup environment
source .env_mach_specific.sh

# get new lid
lid=$(python -c 'import CIME.utils; print CIME.utils.new_lid()')
export LID=$lid

# Clean/make timing dirs
RUNDIR=$(./xmlquery RUNDIR --value)
if [ -e $RUNDIR/timing ]; then
    /bin/rm -rf $RUNDIR/timing
fi
mkdir -p $RUNDIR/timing/checkpoints

# minimum namelist action
./preview_namelists --component cpl
#./preview_namelists # uncomment for full namelist generation

# uncomment for lockfile checking
# ./check_lockedfiles

# setup OMP_NUM_THREADS
export OMP_NUM_THREADS=$(./xmlquery THREAD_COUNT --value)

# save prerun provenance?

# MPIRUN!
cd $(./xmlquery RUNDIR --value)
srun  --label  -n 256 -N 4 -c 4  --cpu_bind=cores   -m plane=64 /pscratch/sd/h/huiwan/vis/ncic/cases_202411/v2_F2010_nc00_freq/build/e3sm.exe   >> e3sm.log.$LID 2>&1 

# save logs?

# save postrun provenance?

# resubmit ?
