Skip to content

Commit

Permalink
Merge pull request #21 from CoryMartin-NOAA/feature/gdaschgres
Browse files Browse the repository at this point in the history
Feature/gdaschgres
  • Loading branch information
RussTreadon-NOAA authored Jun 18, 2020
2 parents 947d784 + ef6f474 commit a1f83ec
Show file tree
Hide file tree
Showing 4 changed files with 775 additions and 427 deletions.
137 changes: 137 additions & 0 deletions jobs/JGDAS_ENKF_CHGRES
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/bin/ksh
set -x

export RUN_ENVIR=${RUN_ENVIR:-"nco"}
export PS4='$SECONDS + '
date


#############################
# Source relevant config files
#############################
export EXPDIR=${EXPDIR:-$HOMEgfs/parm/config}
configs="base anal echgres"
config_path=${EXPDIR:-$NWROOT/gfs.${gfs_ver}/parm/config}
for config in $configs; do
. $config_path/config.$config
status=$?
[[ $status -ne 0 ]] && exit $status
done


##########################################
# Source machine runtime environment
##########################################
. $HOMEgfs/env/${machine}.env anal
status=$?
[[ $status -ne 0 ]] && exit $status


##############################################
# Obtain unique process id (pid) and make temp directory
##############################################
export pid=${pid:-$$}
export outid=${outid:-"LL$job"}

export DATA=${DATA:-${DATAROOT}/${jobid:?}}
mkdir -p $DATA
cd $DATA


##############################################
# Run setpdy and initialize PDY variables
##############################################
export cycle="t${cyc}z"
setpdy.sh
. ./PDY


##############################################
# Determine Job Output Name on System
##############################################
export pgmout="OUTPUT.${pid}"
export pgmerr=errfile


##############################################
# Set variables used in the exglobal script
##############################################
export CDATE=${CDATE:-${PDY}${cyc}}
export CDUMP=${CDUMP:-${RUN:-"gfs"}}
if [ $RUN_ENVIR = "nco" ]; then
export ROTDIR=${COMROOT:?}/$NET/$envir
fi
export DO_CALC_ANALYSIS=${DO_CALC_ANALYSIS:-"YES"}


##############################################
# Begin JOB SPECIFIC work
##############################################

GDATE=$($NDATE -$assim_freq $CDATE)
gPDY=$(echo $GDATE | cut -c1-8)
gcyc=$(echo $GDATE | cut -c9-10)
GDUMP=${GDUMP:-"gdas"}

export OPREFIX="${CDUMP}.t${cyc}z."
export GPREFIX="${GDUMP}.t${gcyc}z."
export APREFIX="${CDUMP}.t${cyc}z."
export GSUFFIX=${GSUFFIX:-$SUFFIX}
export ASUFFIX=${ASUFFIX:-$SUFFIX}


if [ $RUN_ENVIR = "nco" -o ${ROTDIR_DUMP:-NO} = "YES" ]; then
export COMIN=${COMIN:-$ROTDIR/$RUN.$PDY/$cyc}
export COMOUT=${COMOUT:-$ROTDIR/$RUN.$PDY/$cyc}
export COMOUT_ENS=${COMOUT_ENS:-$ROTDIR/enkfgdas.$PDY/$cyc}
export COMIN_OBS=${COMIN_OBS:-$ROTDIR/$RUN.$PDY/$cyc}
export COMIN_GES_OBS=${COMIN_GES_OBS:-$ROTDIR/$GDUMP.$gPDY/$gcyc}
else
export COMOUT="$ROTDIR/$CDUMP.$PDY/$cyc"
export COMOUT_ENS="$ROTDIR/enkfgdas.$PDY/$cyc"
export COMIN_OBS="$DMPDIR/$CDATE/$CDUMP"
export COMIN_GES_OBS="$DMPDIR/$GDATE/$GDUMP"
fi
mkdir -m 775 -p $COMOUT
# COMIN_GES and COMIN_GES_ENS are used in exglobal script
# TO DO: Map NCO's directory into these variables
export COMIN_GES="$ROTDIR/$GDUMP.$gPDY/$gcyc"
export COMIN_GES_ENS="$ROTDIR/enkfgdas.$gPDY/$gcyc"

###############################################################
# Run relevant exglobal script
env
msg="HAS BEGUN on `hostname`"
postmsg "$jlogfile" "$msg"
$LOGSCRIPT


${CHGRESFCSTSH:-$HOMEgsi/scripts/exglobal_enkf_chgres_fv3gfs.sh.ecf}
status=$?
[[ $status -ne 0 ]] && exit $status


##############################################
# End JOB SPECIFIC work
##############################################

##############################################
# Final processing
##############################################
if [ -e "$pgmout" ] ; then
cat $pgmout
fi


msg="ENDED NORMALLY."
postmsg "$jlogfile" "$msg"


##########################################
# Remove the Temporary working directory
##########################################
cd $DATAROOT
[[ $KEEPDATA = "NO" ]] && rm -rf $DATA

date
exit 0
227 changes: 227 additions & 0 deletions scripts/exglobal_enkf_chgres_fv3gfs.sh.ecf
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
#!/bin/ksh
################################################################################
#### UNIX Script Documentation Block
# . .
# Script name: exglobal_enkf_chgresfcst.sh.ecf
# Script description: Runs chgres on full-resolution forecast for EnKF recentering
#
# Author: Cory Martin Org: NCEP/EMC Date: 2020-06-08
#
# Abstract: This script runs chgres on full-resolution forecast for later
# use in the EnKF recentering step
#
# $Id$
#
# Attributes:
# Language: POSIX shell
# Machine: WCOSS-Dell / Hera
#
################################################################################

# Set environment.
export VERBOSE=${VERBOSE:-"YES"}
if [ $VERBOSE = "YES" ]; then
echo $(date) EXECUTING $0 $* >&2
set -x
fi

# Directories.
pwd=$(pwd)
export NWPROD=${NWPROD:-$pwd}
export HOMEgfs=${HOMEgfs:-$NWPROD}
export HOMEgsi=${HOMEgsi:-$NWPROD}
export FIXgsm=${FIXgsm:-$HOMEgfs/fix/fix_am}
export DATA=${DATA:-$pwd/chgresfcst.$$}
export COMIN=${COMIN:-$pwd}
export COMIN_OBS=${COMIN_OBS:-$COMIN}
export COMIN_GES=${COMIN_GES:-$COMIN}
export COMIN_GES_ENS=${COMIN_GES_ENS:-$COMIN_GES}
export COMIN_GES_OBS=${COMIN_GES_OBS:-$COMIN_GES}
export COMOUT=${COMOUT:-$COMIN}

# Base variables
CDATE=${CDATE:-"2001010100"}
CDUMP=${CDUMP:-"gdas"}
GDUMP=${GDUMP:-"gdas"}

# Derived base variables
GDATE=$($NDATE -$assim_freq $CDATE)
BDATE=$($NDATE -3 $CDATE)
PDY=$(echo $CDATE | cut -c1-8)
cyc=$(echo $CDATE | cut -c9-10)
bPDY=$(echo $BDATE | cut -c1-8)
bcyc=$(echo $BDATE | cut -c9-10)

# Utilities
export NCP=${NCP:-"/bin/cp"}
export NMV=${NMV:-"/bin/mv"}
export NLN=${NLN:-"/bin/ln -sf"}
export CHGRP_CMD=${CHGRP_CMD:-"chgrp ${group_name:-rstprod}"}
export NCLEN=${NCLEN:-$HOMEgfs/ush/getncdimlen}
export ERRSCRIPT=${ERRSCRIPT:-'eval [[ $err = 0 ]]'}

# IAU
DOIAU=${DOIAU:-"NO"}
export IAUFHRS=${IAUFHRS:-"6"}

# Dependent Scripts and Executables
export APRUN_CHGRES=${APRUN_CHGRES:-${APRUN:-""}}
export CHGRESNCEXEC=${CHGRESNCEXEC:-$HOMEgfs/exec/chgres_recenter_ncio.exe}
export NTHREADS_CHGRES=${NTHREADS_CHGRES:-1}
APRUNCFP=${APRUNCFP:-""}

# OPS flags
RUN=${RUN:-""}
SENDECF=${SENDECF:-"NO"}
SENDDBN=${SENDDBN:-"NO"}

# level info file
SIGLEVEL=${SIGLEVEL:-${FIXgsm}/global_hyblev.l${LEVS}.txt}

# forecast files
APREFIX=${APREFIX:-""}
ASUFFIX=${ASUFFIX:-$SUFFIX}
# at full resolution
ATMF03=${ATMF03:-${COMOUT}/${APREFIX}atmf003${ASUFFIX}}
ATMF04=${ATMF04:-${COMOUT}/${APREFIX}atmf004${ASUFFIX}}
ATMF05=${ATMF05:-${COMOUT}/${APREFIX}atmf005${ASUFFIX}}
ATMF06=${ATMF06:-${COMOUT}/${APREFIX}atmf006${ASUFFIX}}
ATMF07=${ATMF07:-${COMOUT}/${APREFIX}atmf007${ASUFFIX}}
ATMF08=${ATMF08:-${COMOUT}/${APREFIX}atmf008${ASUFFIX}}
ATMF09=${ATMF09:-${COMOUT}/${APREFIX}atmf009${ASUFFIX}}
# at ensemble resolution
ATMF03ENS=${ATMF03ENS:-${COMOUT}/${APREFIX}atmf003.ensres${ASUFFIX}}
ATMF04ENS=${ATMF04ENS:-${COMOUT}/${APREFIX}atmf004.ensres${ASUFFIX}}
ATMF05ENS=${ATMF05ENS:-${COMOUT}/${APREFIX}atmf005.ensres${ASUFFIX}}
ATMF06ENS=${ATMF06ENS:-${COMOUT}/${APREFIX}atmf006.ensres${ASUFFIX}}
ATMF07ENS=${ATMF07ENS:-${COMOUT}/${APREFIX}atmf007.ensres${ASUFFIX}}
ATMF08ENS=${ATMF08ENS:-${COMOUT}/${APREFIX}atmf008.ensres${ASUFFIX}}
ATMF09ENS=${ATMF09ENS:-${COMOUT}/${APREFIX}atmf009.ensres${ASUFFIX}}
ATMFCST_ENSRES=${ATMFCST_ENSRES:-${COMOUT_ENS}/mem001/${APREFIX}atmf006${ASUFFIX}}

# Set script / GSI control parameters
DOHYBVAR=${DOHYBVAR:-"NO"}
lrun_subdirs=${lrun_subdirs:-".true."}
USE_CFP=${USE_CFP:-"NO"}
CFP_MP=${CFP_MP:-"NO"}
nm=""
if [ $CFP_MP = "YES" ]; then
nm=0
fi
if [ $DOHYBVAR = "YES" ]; then
l_hyb_ens=.true.
export l4densvar=${l4densvar:-".false."}
export lwrite4danl=${lwrite4danl:-".false."}
else
echo "DOHYBVAR != YES, this script will exit without regridding deterministic forecast"
exit 0
fi

################################################################################
################################################################################
# Preprocessing
mkdata=NO
if [ ! -d $DATA ]; then
mkdata=YES
mkdir -p $DATA
fi

cd $DATA || exit 99

##############################################################
# get resolution information
LONB_ENKF=${LONB_ENKF:-$($NCLEN $ATMFCST_ENSRES grid_xt)} # get LONB_ENKF
LATB_ENKF=${LATB_ENKF:-$($NCLEN $ATMFCST_ENSRES grid_yt)} # get LATB_ENFK
LEVS_ENKF=${LEVS_ENKF:-$($NCLEN $ATMFCST_ENSRES pfull)} # get LATB_ENFK

##############################################################
# If analysis increment is written by GSI, regrid forecasts to increment resolution
if [ $DO_CALC_ANALYSIS == "YES" ]; then
$NLN $ATMF06 fcst.06
$NLN $ATMF06ENS fcst.ensres.06
$NLN $ATMFCST_ENSRES atmens_fcst
if [ $DOHYBVAR = "YES" -a $l4densvar = ".true." -a $lwrite4danl = ".true." ]; then
$NLN $ATMF03 fcst.03
$NLN $ATMF03ENS fcst.ensres.03
$NLN $ATMF04 fcst.04
$NLN $ATMF04ENS fcst.ensres.04
$NLN $ATMF05 fcst.05
$NLN $ATMF05ENS fcst.ensres.05
$NLN $ATMF07 fcst.07
$NLN $ATMF07ENS fcst.ensres.07
$NLN $ATMF08 fcst.08
$NLN $ATMF08ENS fcst.ensres.08
$NLN $ATMF09 fcst.09
$NLN $ATMF09ENS fcst.ensres.09
fi
export OMP_NUM_THREADS=$NTHREADS_CHGRES
SIGLEVEL=${SIGLEVEL:-${FIXgsm}/global_hyblev.l${LEVS_ENKF}.txt}

if [ $USE_CFP = "YES" ]; then
rm $DATA/mp_chgres.sh
fi

nfhrs=`echo $IAUFHRS_ENKF | sed 's/,/ /g'`
for FHR in $nfhrs; do
echo "Regridding deterministic forecast for forecast hour $FHR"
rm -f chgres_nc_gauss0$FHR.nml
cat > chgres_nc_gauss0$FHR.nml << EOF
&chgres_setup
i_output=$LONB_ENKF
j_output=$LATB_ENKF
input_file="fcst.0$FHR"
output_file="fcst.ensres.0$FHR"
terrain_file="atmens_fcst"
vcoord_file="$SIGLEVEL"
/
EOF
if [ $USE_CFP = "YES" ]; then
echo "$APRUN_CHGRES $CHGRESNCEXEC chgres_nc_gauss0$FHR.nml" | tee -a $DATA/mp_chgres.sh
else
$APRUN_CHGRES $CHGRESNCEXEC chgres_nc_gauss0$FHR.nml
rc=$?
export ERR=$rc
export err=$ERR
$ERRSCRIPT || exit 3
fi
done

if [ $USE_CFP = "YES" ]; then
chmod 755 $DATA/mp_chgres.sh
ncmd=$(cat $DATA/mp_chgres.sh | wc -l)
if [ $ncmd -gt 0 ]; then
ncmd_max=$((ncmd < npe_node_max ? ncmd : npe_node_max))
APRUNCFP_CHGRES=$(eval echo $APRUNCFP)
if [ ${CFP_MP:-"NO"} = "YES" ]; then
if [ -s $DATA/mp_chgres_srun.sh ]; then rm -f $DATA/mp_chgres_srun.sh; fi
touch $DATA/mp_chgres_srun.sh
nm=0
cat $DATA/mp_chgres.sh | while read line; do
echo "$nm $line" >> $DATA/mp_chgres_srun.sh
nm=$((nm+1))
done
$APRUNCFP_CHGRES -n $nm --multi-prog $DATA/mp_chgres_srun.sh
else
$APRUNCFP_CHGRES $DATA/mp_chgres.sh
export ERR=$?
export err=$ERR
$ERRSCRIPT || exit 3
fi
fi
fi

else
echo "DO_CALC_ANALYSIS != YES, doing nothing"
fi


################################################################################
# Postprocessing
cd $pwd
[[ $mkdata = "YES" ]] && rm -rf $DATA

set +x
if [ $VERBOSE = "YES" ]; then
echo $(date) EXITING $0 with return code $err >&2
fi
exit $err
Loading

0 comments on commit a1f83ec

Please sign in to comment.