#!/bin/ksh -x

########## config.base ##########
# Common to all steps

echo "BEGIN: config.base"

# Machine environment
export machine="WCOSS2"

# EMC parallel or NCO production
export RUN_ENVIR="nco"

# Account, queue, etc.
export ACCOUNT="GFS-T2O"
export QUEUE="prod"
export QUEUE_ARCH="dev_transfer"

# Project to use in mass store:
HPSS_PROJECT=emc-global

# Directories relative to installation areas:
export PARMgfs=$HOMEgfs/parm
export FIXgfs=$HOMEgfs/fix
export USHgfs=$HOMEgfs/ush
export UTILgfs=$HOMEgfs/util
export EXECgfs=$HOMEgfs/exec
export SCRgfs=$HOMEgfs/scripts

########################################################################

# GLOBAL static environment parameters

export PACKAGEROOT="/lfs/h1/ops/prod/packages"
export RTMFIX=$CRTM_FIX

# Machine specific paths used everywhere

# USER specific paths
export HOMEDIR=$EXPDIR/HOMEDIR
export STMP=$DATAROOT
export PTMP=$ROTDIR
export NOSCRUB=$EXPDIR/NOSCRUB

# Base directories for various builds
export BASE_GIT="/gpfs/dell2/emc/modeling/noscrub/emc.glopara/git"

# Toggle to turn on/off GFS downstream processing.
export DO_BUFRSND="YES"    # BUFR sounding products
export DO_GEMPAK="YES"     # GEMPAK products
export DO_AWIPS="YES"      # AWIPS products
export DO_WDQMS="YES"      # Generate WDQMS products

# NO for retrospective parallel; YES for real-time parallel
export REALTIME="YES"

####################################################
# DO NOT ADD MACHINE DEPENDENT STUFF BELOW THIS LINE
# IF YOU HAVE TO MAKE MACHINE SPECIFIC CHANGES BELOW
# FEEL FREE TO MOVE THEM ABOVE THIS LINE TO KEEP IT
# CLEAR
####################################################
# Build paths relative to $HOMEgfs
export FIXgsi="$HOMEgfs/fix/fix_gsi"
export HOMEfv3gfs="$HOMEgfs/sorc/fv3gfs.fd"
export HOMEpost="$HOMEgfs"
export HOMEobsproc="/lfs/h1/ops/prod/packages/obsproc.v1.0.0"
export BASE_VERIF="$BASE_GIT/verif/global/tags/vsdb"

# CONVENIENT utility scripts and other environment parameters
export NCP="/bin/cp -p"
export NMV="/bin/mv"
export NLN="/bin/ln -sf"
export VERBOSE="YES"
export CHGRP_CMD="chgrp rstprod"
export NEMSIOGET="$HOMEgfs/exec/nemsio_get"
export NCDUMP="$NETCDF/bin/ncdump"
export NCLEN="$HOMEgfs/ush/getncdimlen"

# Machine environment, jobs, and other utility scripts
export BASE_ENV="$HOMEgfs/env"
export BASE_JOB="$HOMEgfs/jobs/rocoto"

# EXPERIMENT specific environment parameters
export SDATE=2018080600
export EDATE=2039123100
export assim_freq=6
export PSLOT="test"
export EXPDIR="$EXPDIR"
export ROTDIR="$(compath.py ${envir}/${NET}/${gfs_ver})"
export ROTDIR_DUMP="YES"
export DUMP_SUFFIX=""
export RUNDIR="$DATAROOT"
export ARCDIR="$NOSCRUB/archive/$PSLOT"
export ATARDIR="/NCEPDEV/$HPSS_PROJECT/1year/$USER/$machine/scratch/$PSLOT"

# Commonly defined parameters in JJOBS
export envir=${envir:-"prod"}
export NET="gfs"
export RUN=${RUN:-${CDUMP:-"gfs"}}
export COMINatmos=${ROTDIR}/${CDUMP}.${PDY}/${cyc}/atmos
export COMOUTatmos=${ROTDIR}/${CDUMP}.${PDY}/${cyc}/atmos
export COMINwave=${ROTDIR}/${CDUMP}.${PDY}/${cyc}/wave
export COMOUTwave=${ROTDIR}/${CDUMP}.${PDY}/${cyc}/wave

export ERRSCRIPT=${ERRSCRIPT:-'eval [[ $err = 0 ]]'}
export LOGSCRIPT=${LOGSCRIPT:-""}
#export ERRSCRIPT=${ERRSCRIPT:-"err_chk"}
#export LOGSCRIPT=${LOGSCRIPT:-"startmsg"}
export REDOUT="1>"
export REDERR="2>"

export SENDECF=${SENDECF:-"YES"}
export SENDCOM=${SENDCOM:-"YES"}
export SENDSDM=${SENDSDM:-"YES"}
export SENDDBN_NTC=${SENDDBN_NTC:-"YES"}
export SENDDBN=${SENDDBN:-"YES"}
export DBNROOT=${DBNROOT:-${UTILROOT}/fakedbn}

# Resolution specific parameters
export LEVS=128
export CASE="C768"
export CASE_ENKF="C384"

# Surface cycle update frequency
if [[ "$CDUMP" == "gdas" ]] ; then
   export FHCYC=1
   export FTSFS=10
elif [[ "$CDUMP" == "gfs" ]] ; then
   export FHCYC=24
fi

# Output frequency of the forecast model (for cycling)
export FHMIN=0
export FHMAX=9
export FHOUT=3

# Cycle to run EnKF  (set to BOTH for both gfs and gdas)
export EUPD_CYC="gdas"

# GFS cycle info
export gfs_cyc=4 # 0: no GFS cycle, 1: 00Z only, 2: 00Z and 12Z only, 4: all 4 cycles.

# GFS output and frequency
export FHMIN_GFS=0

export FHMAX_GFS_00=384
export FHMAX_GFS_06=384
export FHMAX_GFS_12=384
export FHMAX_GFS_18=384
export FHMAX_GFS=$(eval echo \${FHMAX_GFS_$cyc})

export FHOUT_GFS=3
export FHMAX_HF_GFS=120
export FHOUT_HF_GFS=1
export ILPOST=1           # gempak output frequency up to F120

# frequency for saving restart files. set to 6,12,24,48 etc 
export restart_interval_gfs=12

# I/O QUILTING, true--use Write Component; false--use GFDL FMS
# if quilting=true, choose OUTPUT_GRID as cubed_sphere_grid in netcdf or gaussian_grid
# if gaussian_grid, set OUTPUT_FILE for nemsio or netcdf
# WRITE_DOPOST=true, use inline POST
export QUILTING=".true."
export OUTPUT_GRID="gaussian_grid"
export OUTPUT_FILE="netcdf"
export WRITE_DOPOST=".true."

# suffix options depending on file format
if [ $OUTPUT_FILE = "netcdf" ]; then
    export SUFFIX=".nc"
    export NEMSIO_IN=".false."
    export NETCDF_IN=".true."
else
    export SUFFIX=".nemsio"
    export NEMSIO_IN=".true."
    export NETCDF_IN=".false."
fi

# IAU related parameters
export DOIAU="YES"        # Enable 4DIAU for control with 3 increments
export IAUFHRS="3,6,9"
export IAU_FHROT=`echo $IAUFHRS | cut -c1`
export IAU_DELTHRS=6
export IAU_OFFSET=6
export DOIAU_ENKF="YES"   # Enable 4DIAU for EnKF ensemble
export IAUFHRS_ENKF="3,6,9"
export IAU_DELTHRS_ENKF=6

# Use Jacobians in eupd and thereby remove need to run eomg
export lobsdiag_forenkf=".true."

# run GLDAS to spin up land ICs
export DO_GLDAS=YES
export gldas_cyc=00

# run wave component
export DO_WAVE=YES
export WAVE_CDUMP="both"

# Microphysics Options: 99-ZhaoCarr, 8-Thompson; 6-WSM6, 10-MG, 11-GFDL
export imp_physics=11

# Shared parameters
# Hybrid related
export DOHYBVAR="YES"
export NMEM_ENKF="80"
export SMOOTH_ENKF="NO"
export l4densvar=".true."
export lwrite4danl=".true."

# EnKF output frequency
if [ $DOHYBVAR = "YES" ]; then
    export FHMIN_ENKF=3
    export FHMAX_ENKF=9
    if [ $l4densvar = ".true." ]; then
        export FHOUT=1
        export FHOUT_ENKF=1
    else
        export FHOUT_ENKF=3
    fi
fi

# turned on nsst in anal and/or fcst steps, and turn off rtgsst

export DONST="YES"
if [ $DONST = "YES" ]; then export FNTSFA="        "; fi

# The switch to apply SST elevation correction or not
export nst_anl=.true.

# Analysis increments to zero in CALCINCEXEC
export INCREMENTS_TO_ZERO="'liq_wat_inc','icmr_inc','rwmr_inc','snmr_inc','grle_inc'"

if [ $OUTPUT_FILE = "nemsio" ]; then
    export DO_CALC_INCREMENT="YES"
    export DO_CALC_ANALYSIS="NO"
fi

# Stratospheric increments to zero
export INCVARS_ZERO_STRAT="'sphum_inc','liq_wat_inc','icmr_inc','rwmr_inc','snmr_inc','grle_inc'"
export INCVARS_EFOLD="5"

# Swith to generate netcdf or binary diagnostic files.  If not specified,
# script default to binary diagnostic files.   Set diagnostic file
# variables here since used in both DA and vrfy jobs
export netcdf_diag=".true."
export binary_diag=".false."

# Verification options
export DO_METP="NO"                  # Run MET+ jobs

# Archiving options
export HPSSARCH="NO"         # save data to HPSS archive
export ARCH_CYC=00           # Archive data at this cycle for warm_start capability
export ARCH_WARMICFREQ=1     # Archive frequency in days for warm_start capability
export ARCH_FCSTICFREQ=1     # Archive frequency in days for gdas and gfs forecast-only capability
export DELETE_COM_IN_ARCHIVE_JOB="YES"   # NO=retain ROTDIR.  YES default in arch.sh and earc.sh.

echo "END: config.base"