Skip to content

Commit

Permalink
Update exemcsfc_global_sfc_prep.sh and emcsfc_snow.sh based
Browse files Browse the repository at this point in the history
on NCO comments.

Fixes #973.
  • Loading branch information
GeorgeGayno-NOAA committed Oct 29, 2024
1 parent 85afb0c commit 0557212
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 35 deletions.
14 changes: 6 additions & 8 deletions scripts/exemcsfc_global_sfc_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
# /nwprod/gfs.vX.Y.Z/ush/emcsfc_ice_blend.sh (create global ice blend)
# /nwprod/gfs.vX.Y.Z/ush/emcsfc_snow.sh (create model snow analysis)
# Input Files:
# $AFWA_NH_FILE - nh afwa snow data (grib 1)
# $AFWA_SH_FILE - sh afwa snow data (grib 1)
# $AFWA_GLOBAL_FILE - afwa snow data (grib 2)
# $IMS_FILE - nh ims snow cover and ice data (grib 2)
# $FIVE_MIN_ICE_FILE - global 5-minute ice concentration (grib 2)
# $FIVE_MIN_ICE_MASK_FILE - corresponding land/sea mask for $FIVE_MIN_ICE_FILE
Expand Down Expand Up @@ -77,7 +76,7 @@ export EXECgfs=${EXECgfs:-$HOMEgfs/exec}

# output com directory.
export COMOUT=${COMOUT:-$PWD}
export COMINgfs_m6hrs=${COMINgfs_m6hrs:-$PWD}
export COMIN_m6hrs=${COMIN_m6hrs:-$PWD}

# working directory
export DATA=${DATA:-$PWD}
Expand Down Expand Up @@ -105,9 +104,8 @@ fi
# the input data for emcsfc_ice_blend and emcsfc_snow2mdl programs.
#-----------------------------------------------------------------------

# afwa snow depth data (grib 1)
export AFWA_NH_FILE=${AFWA_NH_FILE:-"NPR.SNWN.SP.S1200.MESH16"}
export AFWA_SH_FILE=${AFWA_SH_FILE:-"NPR.SNWS.SP.S1200.MESH16"}
# afwa snow depth data (grib 2)
export AFWA_GLOBAL_FILE=${AFWA_GLOBAL_FILE:-"snow.usaf.grib2"}

# ims snow cover and ice cover data (grib 1 or grib 2)
export IMS_FILE=${IMS_FILE:-"ims.grib2"}
Expand Down Expand Up @@ -187,7 +185,7 @@ export MODEL_LATITUDE_FILE=${MDL_LATS:-$FIXgfs_am/global_latitudes.t${resolution
export MODEL_LONGITUDE_FILE=${MDL_LONS:-$FIXgfs_am/global_longitudes.t${resolution}.grb}
export GFS_LONSPERLAT_FILE=${LONSPERLAT:-$FIXgfs_am/global_lonsperlat.t${resolution}.txt}
export MODEL_SNOW_FILE=${FNSNOAJCAP:-${RUN}.${cycle}.snogrb_t${resolution}}
export MODEL_SNOW_FILE_m6hrs=${FNSNOGJCAP:-${COMINgfs_m6hrs}/${RUN}.${cycle_m6hrs}.snogrb_t${resolution}}
export MODEL_SNOW_FILE_m6hrs=${FNSNOGJCAP:-${COMIN_m6hrs}/${RUN}.${cycle_m6hrs}.snogrb_t${resolution}}

echo "Create ${JCAP} snow data."

Expand Down Expand Up @@ -245,7 +243,7 @@ export MODEL_LATITUDE_FILE=${MDL_LATS_ENKF:-$FIXgfs_am/global_latitudes.t${resol
export MODEL_LONGITUDE_FILE=${MDL_LONS_ENKF:-$FIXgfs_am/global_longitudes.t${resolution}.grb}
export GFS_LONSPERLAT_FILE=${LONSPERLAT_ENKF:-$FIXgfs_am/global_lonsperlat.t${resolution}.txt}
export MODEL_SNOW_FILE=${FNSNOAJCAP_ENKF:-${RUN}.${cycle}.snogrb_t${resolution}}
export MODEL_SNOW_FILE_m6hrs=${FNSNOGJCAP_ENKF:-${COMINgfs_m6hrs}/${RUN}.${cycle_m6hrs}.snogrb_t${resolution}}
export MODEL_SNOW_FILE_m6hrs=${FNSNOGJCAP_ENKF:-${COMIN_m6hrs}/${RUN}.${cycle_m6hrs}.snogrb_t${resolution}}

echo "Create enkf snow data."

Expand Down
77 changes: 50 additions & 27 deletions ush/emcsfc_snow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
# $MODEL_SLMASK_FILE - model landmask (grib 1 or 2)
# $MODEL_LATITUDE_FILE - model latitude (grib 1 or 2)
# $MODEL_LONGITUDE_FILE - model longitude (grib 1 or 2)
# $AFWA_NH_FILE - nh afwa snow data (grib 1)
# $AFWA_SH_FILE - sh afwa snow data (grib 1)
# $AFWA_GLOBAL_FILE - global afwa snow data (grib 2)
# $IMS_FILE - nh ims snow cover data (grib 2)
# $CLIMO_QC - nh climatological snow cover (grib 2)
Expand All @@ -33,9 +31,8 @@
#
# Condition codes:
# 0 - normal termination
# $rc1 - non-zero status indicates corrupt ims data.
# $rc2 - non-zero status indicates a problem in emcsfc_snow2mdl execution.
# see source code for details - /nwprod/gfs.vX.Y.Z/sorc/emcsfc_snow2mdl.fd
# non 0 - indicates missing or corrupt input data
# or a problem in emcsfc_snow2mdl execution.
#
# If a non-zero status occurs, no model snow analysis will be created.
# This is not fatal to the model executation. But any problems should
Expand Down Expand Up @@ -101,12 +98,9 @@ GFS_LONSPERLAT_FILE=${GFS_LONSPERLAT_FILE:-global_lonsperlat.t1534.3072.1536.txt

#------------------------------------------------------------------------
# Input snow data. ims snow cover and afwa snow depth. ims is NH only.
# In OPS, we run with ims only, or ims and afwa. afwa data is too
# unreliable to use on its own. ims is grib2. afwa is grib1.
# AFWA is global.
#------------------------------------------------------------------------

AFWA_NH_FILE=${AFWA_NH_FILE:-""}
AFWA_SH_FILE=${AFWA_SH_FILE:-""}
AFWA_GLOBAL_FILE=${AFWA_GLOBAL_FILE:-""}
IMS_FILE=${IMS_FILE:-"imssnow96.grb.grib2"}

Expand Down Expand Up @@ -136,31 +130,30 @@ fi
cd $DATA

#------------------------------------------------------------------------
# Do a quick check of the ims data to ensure it is not corrupt.
# WGRIB2 works for a grib 1 or grib 2 file. If IMS is bad,
# don't run emcsfc_snow2mdl program because afwa data alone is
# unreliable.
# Do a quick check of the ims data to ensure it exists and is
# not corrupt.
#------------------------------------------------------------------------

$WGRIB2 ${IMS_FILE}
rc1=$?

if ((rc1 != 0));then
echo "WARNING: ${pgm} detects corrupt IMS data. Can not run."
exit $rc1
if [[ ! -f $IMS_FILE ]]; then
set +x
echo "WARNING: ${pgm} detects missing ims data. Will not run."
set -x
exit 7
fi

#------------------------------------------------------------------------
# The model analysis time is set to the ims valid time, because the
# ims data has highest priority of all input data.
#------------------------------------------------------------------------

$WGRIB2 -Sec0 ${IMS_FILE} 2>&1 | grep "grib1 message"
$WGRIB2 -d 1 ${IMS_FILE}
status=$?
if (( status == 0 )); then # grib 1 file
tempdate=$($WGRIB -v $IMS_FILE | head -1)
IMSDATE=${tempdate#*D=}
else # grib 2 file
if (( status != 0 )); then
set +x
echo "WARNING: ${pgm} detects corrupt ims data. Will not run."
set -x
exit 9
else
tempdate=$($WGRIB2 -t $IMS_FILE | head -1)
IMSDATE=${tempdate#*d=}
fi
Expand All @@ -170,6 +163,36 @@ IMSMONTH=$(echo $IMSDATE10 | cut -c5-6)
IMSDAY=$(echo $IMSDATE10 | cut -c7-8)
IMSHOUR=0 # emc convention is to use 00Z.

#------------------------------------------------------------------------
# Ensure AFWA data exists and is not too old.
#------------------------------------------------------------------------

if [[ ! -f $AFWA_GLOBAL_FILE ]]; then
set +x
echo "WARNING: ${pgm} detects missing afwa data. Will not run."
set -x
exit 3
else
$WGRIB2 -d 1 $AFWA_GLOBAL_FILE
status=$?
if ((status != 0));then
set +x
echo "WARNING: ${pgm} detects corrupt afwa data. Will not run."
set -x
exit $status
else
tempdate=$($WGRIB2 -d 1 -t $AFWA_GLOBAL_FILE)
AFWADATE=${tempdate#*d=}
two_days_ago=$($NDATE -48 $IMSDATE10)
if ((AFWADATE < two_days_ago)); then
set +x
echo "WARNING: ${pgm} detects old afwa data. Will not run."
set -x
exit 4
fi
fi
fi

pgmout=${pgmout:-OUTPUT}

if test "$use_prod_util" = "true" ; then
Expand All @@ -183,8 +206,8 @@ cat > ./fort.41 << !
nesdis_snow_file="${IMS_FILE}"
nesdis_lsmask_file=""
afwa_snow_global_file="${AFWA_GLOBAL_FILE}"
afwa_snow_nh_file="${AFWA_NH_FILE}"
afwa_snow_sh_file="${AFWA_SH_FILE}"
afwa_snow_nh_file=""
afwa_snow_sh_file=""
afwa_lsmask_nh_file=""
afwa_lsmask_sh_file=""
/
Expand Down Expand Up @@ -217,7 +240,7 @@ cat > ./fort.41 << !
eval $SNOW2MDLEXEC >> $pgmout 2> errfile
rc2=$?

if ((rc2!= 0));then
if ((rc2 != 0));then
echo "WARNING: ${pgm} completed abnormally."
exit $rc2
else
Expand Down

0 comments on commit 0557212

Please sign in to comment.