#!/bin/bash

#PBS -N SREF
#PBS -A SREF-DEV
##PBS -j oe
#PBS -o _SREFDIR_/run/sref_prep__MODEL___MEMBER_.log
#PBS -e _SREFDIR_/run/sref_prep__MODEL___MEMBER_.log
#PBS -l select=1:ncpus=1:mem=3000MB
##PBS -q debug
#PBS -q dev
#PBS -l walltime=03:00:00
##PBS -l hyper=true
#PBS -l debug=true

##BSUB -J SREF_PREP__MODEL___MEMBER_
##BSUB -x

set -eux

trap 'echo "SREF error _MODEL_ _MEMBER_ PREP" >> /lfs/h2/emc/ptmp/$LOGNAME/tmpnwprd/jlogfile_sref' INT TERM ERR
echo "SREF started _MODEL_ _MEMBER_ PREP" >> /lfs/h2/emc/ptmp/$LOGNAME/tmpnwprd/jlogfile_sref

#. /usrx/local/prod/lmod/lmod/init/bash
. /usr/share/lmod/lmod/init/bash
module purge
#module reset
module load PrgEnv-intel/8.1.0
module load envvar/1.0
#module load lsf/10.1
#module load ips/18.0.1.163
module load intel/19.1.3.304
module load libjpeg/9c
module load prod_util/2.0.9
module load prod_envir/2.0.6
module load grib_util/1.2.2
module load netcdf/4.7.4
#module load impi/18.0.1
module load cfp/2.0.4
module load craype/2.7.8
module load cray-pals/1.0.12
module load cray-mpich/8.1.9

#module load gcc/10.3.0
module load gcc/11.2.0
module load intel/19.1.3.304
module load libpng/1.6.37
module list

export OMP_NUM_THREADS=1

export RUN_ENVIR=para
export envir=prod
export job=$$

export CONFIG_FILE=_SREFDIR_/parm/sref_para_config_cray

export PDY=_PDY_
export cyc=_CYC_
export FLENGTH=_FLENGTH_
export INCR=_INCR_
export MODEL=_MODEL_
export MEMBER=_MEMBER_
export IOFORM=_IOFORM_
export RES=_RES_
export MACHINE=_MACHINE_
#export N_TASK=$LSB_DJOB_NUMPROC


_SREFDIR_/jobs/JSREF_WRF_PREP

echo "SREF finished _MODEL_ _MEMBER_ PREP" >> /lfs/h2/emc/ptmp/$LOGNAME/tmpnwprd/jlogfile_sref

qsub _SREFDIR_/run/SREF_REAL__MODEL___MEMBER_.qsub
echo "SREF waiting _MODEL_ _MEMBER_ REAL" >> /lfs/h2/emc/ptmp/$LOGNAME/tmpnwprd/jlogfile_sref

