#!/bin/sh
#SBATCH -q urgent
#SBATCH --clusters c4
#SBATCH -t 04:15:00
#SBATCH -A nggps_psd
#SBATCH -N 6    
#SBATCH -J longfcst_alone
#SBATCH -e longfcst_alone.err
#SBATCH -o longfcst_alone.out

##PBS -A nggps_psd
##PBS -l partition=c4
###PBS -q batch
##PBS -q urgent
##PBS -l nodes=6:ppn=36
##PBS -l walltime=04:15:00
##PBS -N C384_longfcst  
##PBS -e C384_longfcst.err
##PBS -o C384_longfcst.out
##PBS -S /bin/sh

export analdate=2006072500
echo "$analdate run high-res control long fcst `date`"
export yr=`echo $analdate | cut -c1-4`

export NODES=6
export corespernode=$SLURM_CPUS_ON_NODE
export machine='gaea'
export quilting='.false.'
export control_threads=1
export control_proc=216
export layout="6,6"

export exptname=2003stream
export fg_only='false'

export rungfs='run_fv3.sh'     
export replay_controlfcst='true'    # only used if replay_controlfcst=true
export run_long_fcst_cfsr="true"    # also run a long forecast from CFSR initial conditions

export FHOUT=3
export FHMIN=3
export LEVS=64
## export FHMAX_LONG=24
export FHMAX_LONG=120

export VERBOSE=YES

if [ $replay_controlfcst == 'true' ] 
then
   export charnanal="control2"
elif [ $controlfcst == 'false' ] 
then
   export charnanal="ensmean"
   unset skip_calc_increment
   unset skip_global_cycle
else
   export charnanal="control"
fi
echo "charnanal = $charnanal"
 
export basedir=/lustre/f2/scratch/${USER}
export datadir=$basedir
export datapath="${datadir}/${exptname}"
export datapath2="${datapath}/${analdate}"
export obs_datapath=/lustre/f2/dev/Jeffrey.S.Whitaker/fv3_reanl/gdas1bufr

export hsidir="/3year/NCEPDEV/GEFSRR/${exptname}"

export enkfscripts="/lustre/f2/dev/${USER}/scripts/${exptname}"
export homedir=$enkfscripts
export incdate="${enkfscripts}/incdate.sh"

export execdir=${enkfscripts}/exec_${machine}
export enkfbin=${execdir}/global_enkf
export nemsioget=${execdir}/nemsio_get

export fv3gfspath=/lustre/f2/dev/Jeffrey.S.Whitaker/fv3_reanl/fv3gfs/global_shared.v15.0.0
export FIXFV3=${fv3gfspath}/fix/fix_fv3_gmted2010
export FCSTEXEC=${execdir}/${fv3exec}
export FIXGLOBAL=${fv3gfspath}/fix/fix_am

export RES_CTL=384 

export ANALINC=6
export FHOFFSET=`expr $ANALINC \/ 2`
export analdatem1=`${incdate} $analdate -$ANALINC`
echo "Previous date: $analdatem1"
export analdatep1=`${incdate} $analdate $ANALINC`
export analdatem3=`${incdate} $analdate -$FHOFFSET`
export analdatep1m3=`${incdate} $analdate $FHOFFSET`

export NST_GSI=0          # No NST

export psautco_ctl="0.0008,0.0005"
export prautco_ctl="0.00015,0.00015"

# Model Physics Option
export imp_physics=11 # GFDL MP
## export imp_physics=99 # zhao-carr
if [ $imp_physics == "11" ]; then
   export ncld=5
   export nwat=6
   export cal_pre=F
   export dnats=1
   export do_sat_adj=".true."
   export random_clds=".false."
   export cnvcld=".false."
else
   export ncld=1
   export nwat=2
   export cal_pre=T
    export dnats=0
fi

export k_split=1
export n_split=6
export hydrostatic=F
if [ $hydrostatic == 'T' ];  then
   export fv3exec='fv3-hydro.exe'
   export hord_mt=10
   export hord_vt=10
   export hord_tm=10
   export hord_dp=-10
   export vtdm4=0.05
   export consv_te=0
else
   export fv3exec='fv3-nonhydro.exe'
   export hord_mt=5
   export hord_vt=5
   export hord_tm=5
   export hord_dp=-5
   export vtdm4=0.06
   export consv_te=1
fi

export fv3gfspath=/lustre/f2/dev/Jeffrey.S.Whitaker/fv3_reanl/fv3gfs/global_shared.v15.0.0
export FIXFV3=${fv3gfspath}/fix/fix_fv3_gmted2010
export FCSTEXEC=${execdir}/${fv3exec}
export FIXGLOBAL=${fv3gfspath}/fix/fix_am

if [ $RES_CTL -eq 1534 ]; then
   export fv_sg_adj_ctl=600
   export dt_atmos_ctl=120
   export cdmbgwd_ctl="3.5,0.25"
   export psautco_ctl="0.0008,0.0005"
   export prautco_ctl="0.00015,0.00015"
   export LONB_CTL=3072
   export LATB_CTL=1536
elif [ $RES_CTL -eq 384 ]; then
   export fv_sg_adj_ctl=600
   export dt_atmos_ctl=225
   export cdmbgwd_ctl="1.0,1.2"
   export LONB_CTL=1760
   export LATB_CTL=880
elif [ $RES_CTL -eq 192 ]; then
   export fv_sg_adj_ctl=900
   export dt_atmos_ctl=450
   export cdmbgwd_ctl="0.25,2.0"
   export LONB_CTL=768  
   export LATB_CTL=384
elif [ $RES_CTL -eq 96 ]; then
   export fv_sg_adj_ctl=1800
   export dt_atmos_ctl=900
   export cdmbgwd_ctl="0.125,3.0"
   export LONB_CTL=384  
   export LATB_CTL=192
else
   echo "unknown RES_CTL=${RES_CTL}"
   exit 1
fi

export FHCYC=0 # run global_cycle instead of gcycle inside model

export iau_delthrs="6" # iau_delthrs < 0 turns IAU off
export iaufhrs="3,6,9"

if [ $run_long_fcst_cfsr == "true" ]; then
   export submit_hpss=false
else
   export submit_hpss=true
fi
mkdir -p ${datapath2}/longfcst/${charnanal}
csh ${enkfscripts}/run_long_fcst.csh &> ${datapath2}/longfcst/${charnanal}/longfcst.out 

if [ $run_long_fcst_cfsr == "true" ]; then
   echo "$analdate run high-res control long fcst from CFSR initial conditions `date`"
   
   export charnanal="cfsr"
   echo "charnanal = $charnanal"
   mkdir -p ${datapath2}/${charnanal}
   /bin/cp -f /lustre/f2/dev/Gary.Bates/cfsr_inits/${yr}/C${RES_CTL}_${analdate}/control/* ${datapath2}/${charnanal}
   
   #env
   export fg_only=true
   export submit_hpss=true
   mkdir -p ${datapath2}/longfcst/${charnanal}
   csh ${enkfscripts}/run_long_fcst.csh &> ${datapath2}/longfcst/${charnanal}/longfcst.out 
fi

