From 49dc315c1ef6c5f4952a06b0ba70c36e771f128e Mon Sep 17 00:00:00 2001 From: Walter Kolczynski - NOAA Date: Fri, 29 Sep 2023 13:25:58 -0400 Subject: [PATCH] Move product functions to separate script (#1891) PR #1822 converted some formerly stand-alone scripts and moved them inside one of the standard product scripts. However, `trim_rh.sh` is also used by gempak and AWIPS, so this change caused those jobs to start failing (they are not yet tested by CI). Those functions have now been moved into a separate product functions script that can be sourced by all the scripts that need the functions. A third similar script was also eliminated and converted into a function. Additionally fixes a base bug in AWIPS and updates some scripts to satisfy (or at least mostly satisfy) the linter. **AWIPS still failing when creating GRIB1 products.** That will be addressed in a future PR (and may need a subject-matter expert). Resolves #1890 --- jobs/JGFS_ATMOS_AWIPS_20KM_1P0DEG | 11 +- jobs/rocoto/awips.sh | 7 +- scripts/exgdas_atmos_post.sh | 2 - scripts/exgfs_atmos_awips_20km_1p0deg.sh | 48 ++++----- scripts/exgfs_atmos_grib_awips.sh | 14 ++- scripts/exgfs_atmos_nawips.sh | 127 +++++++++++------------ scripts/exgfs_atmos_post.sh | 2 - ush/fv3gfs_dwn_nems.sh | 28 +---- ush/product_functions.sh | 40 +++++++ ush/scale_dec.sh | 28 ----- 10 files changed, 137 insertions(+), 170 deletions(-) create mode 100755 ush/product_functions.sh delete mode 100755 ush/scale_dec.sh diff --git a/jobs/JGFS_ATMOS_AWIPS_20KM_1P0DEG b/jobs/JGFS_ATMOS_AWIPS_20KM_1P0DEG index 7e5f308d71..b9228bc5af 100755 --- a/jobs/JGFS_ATMOS_AWIPS_20KM_1P0DEG +++ b/jobs/JGFS_ATMOS_AWIPS_20KM_1P0DEG @@ -47,21 +47,22 @@ export pgmout=OUTPUT.$$ ######################################################## # Execute the script. -${HOMEgfs}/scripts/exgfs_atmos_awips_20km_1p0deg.sh ${fcsthrs} +"${HOMEgfs}/scripts/exgfs_atmos_awips_20km_1p0deg.sh" "${fcsthrs}" export err=$?; err_chk ######################################################## ############################################ # print exec I/O output ############################################ -if [ -e "${pgmout}" ] ; then - cat ${pgmout} +if [[ -e "${pgmout}" ]] ; then + cat "${pgmout}" fi ################################### # Remove temp directories ################################### -if [ "${KEEPDATA}" != "YES" ] ; then - rm -rf ${DATA} +cd "${DATAROOT}" || pass +if [[ "${KEEPDATA}" != "YES" ]] ; then + rm -rf "${DATA}" fi diff --git a/jobs/rocoto/awips.sh b/jobs/rocoto/awips.sh index ffa59ec539..57fbd92572 100755 --- a/jobs/rocoto/awips.sh +++ b/jobs/rocoto/awips.sh @@ -34,9 +34,10 @@ fhrlst=$(echo ${FHRLST} | sed -e 's/_/ /g; s/f/ /g; s/,/ /g') echo echo "=============== BEGIN AWIPS ===============" -for fhr in ${fhrlst}; do +for fhr3 in ${fhrlst}; do + fhr=$(( 10#${fhr3} )) if (( fhr > FHMAX_GFS )); then - echo "Nothing to process for FHR = ${fhr}, cycle" + echo "Nothing to process for FHR = ${fhr3}, cycle" continue fi @@ -44,7 +45,6 @@ for fhr in ${fhrlst}; do fhmax=84 if (( fhr >= fhmin && fhr <= fhmax )); then if ((fhr % 3 == 0)); then - fhr3=$(printf %03d $((10#${fhr}))) export fcsthrs=${fhr3} ${AWIPS20SH} fi @@ -58,7 +58,6 @@ for fhr in ${fhrlst}; do fhmax=240 if (( fhr >= fhmin && fhr <= fhmax )); then if ((fhr % 6 == 0)); then - fhr3=$(printf %03i $((10#${fhr}))) export fcsthrs=${fhr3} ${AWIPS20SH} ${AWIPSG2SH} diff --git a/scripts/exgdas_atmos_post.sh b/scripts/exgdas_atmos_post.sh index c49be8b0b8..305d97a002 100755 --- a/scripts/exgdas_atmos_post.sh +++ b/scripts/exgdas_atmos_post.sh @@ -31,8 +31,6 @@ cd "${DATA}" || exit 1 export POSTGPSH=${POSTGPSH:-${USHgfs}/gfs_post.sh} export GFSDOWNSH=${GFSDOWNSH:-${USHgfs}/fv3gfs_downstream_nems.sh} export GFSDWNSH=${GFSDWNSH:-${USHgfs}/fv3gfs_dwn_nems.sh} -export TRIMRH=${TRIMRH:-${USHgfs}/trim_rh.sh} -export MODICEC=${MODICEC:-${USHgfs}/mod_icec.sh} export INLINE_POST=${INLINE_POST:-".false."} ############################################################ diff --git a/scripts/exgfs_atmos_awips_20km_1p0deg.sh b/scripts/exgfs_atmos_awips_20km_1p0deg.sh index 0f9868a506..279b5003ed 100755 --- a/scripts/exgfs_atmos_awips_20km_1p0deg.sh +++ b/scripts/exgfs_atmos_awips_20km_1p0deg.sh @@ -37,6 +37,9 @@ fi cd "${DATA}" || exit 2 +# "Import" functions used in this script +source "${HOMEgfs}/ush/product_functions.sh" + ############################################### # Wait for the availability of the pgrb file ############################################### @@ -51,6 +54,7 @@ while (( icnt < 1000 )); do if (( icnt >= 180 )); then msg="FATAL ERROR: No GFS pgrb2 file after 30 min of waiting" err_exit "${msg}" + exit 5 fi done @@ -79,8 +83,6 @@ export opt25=":(APCP|ACPCP|PRATE|CPRAT):" export opt26=' -set_grib_max_bits 25 -fi -if ' export opt27=":(APCP|ACPCP|PRATE|CPRAT|DZDT):" export opt28=' -new_grid_interpolation budget -fi ' -export TRIMRH=${TRIMRH:-$USHgfs/trim_rh.sh} -export SCALEDEC=${SCALDEC:-$USHgfs/scale_dec.sh} ############################################################### # Process GFS GRIB AWIP PRODUCTS IN GRIB2 # @@ -109,43 +111,28 @@ export err=$?; err_chk cat temp_gfs gfs_pwat_levels_10.grb > tmp_masterfile for GRID in conus ak prico pac 003; do - # shellcheck disable=SC2086 case ${GRID} in conus) - # Grid 20km_conus - CONUS - 20 km Quadruple Resolution (Lambert Conformal) - # export grid_20km_conus="30 6 0 0 0 0 0 0 369 257 12190000 226541000 8 25000000 265000000 20318000 20318000 0 64 25000000 25000000 0 0" - # $COPYGB2 -g "$grid_20km_conus" -i0 -x tmp_masterfile awps_file_f${fcsthrs}_${GRID} - - export gridconus="lambert:265.0:25.0:25.0 226.541:369:20318.0 12.19:257:20318.0" + gridconus="lambert:265.0:25.0:25.0 226.541:369:20318.0 12.19:257:20318.0" + # shellcheck disable=SC2086,SC2248 ${WGRIB2} tmp_masterfile ${opt1uv} ${opt21} ${opt22} ${opt23} ${opt24} ${opt25} ${opt26} \ ${opt27} ${opt28} -new_grid ${gridconus} "awps_file_f${fcsthrs}_${GRID}" ;; ak) - # Grid 20km_ak - Alaska - Double Resolution (Polar Stereographic) - # Redefined grid 217 for Alaska region - # export grid_20km_ak="20 6 0 0 0 0 0 0 277 213 30000000 187000000 8 60000000 225000000 22500000 22500000 0 64" - # $COPYGB2 -g "$grid_20km_ak" -i0 -x tmp_masterfile awps_file_f${fcsthrs}_${GRID} - - export gridak="nps:210.0:60.0 170.0:277:22500 35.0:225:22500" + gridak="nps:210.0:60.0 170.0:277:22500 35.0:225:22500" + # shellcheck disable=SC2086,SC2248 ${WGRIB2} tmp_masterfile ${opt1uv} ${opt21} ${opt22} ${opt23} ${opt24} ${opt25} ${opt26} \ ${opt27} ${opt28} -new_grid ${gridak} "awps_file_f${fcsthrs}_${GRID}" ;; prico) - # Grid 20km_prico - 0.25 degree Lat/Lon grid for Puerto Rico (20km) - # export grid_20km_prico="0 6 0 0 0 0 0 0 275 205 0 0 50750000 271750000 48 -250000 340250000 250000 250000 0" - # $COPYGB2 -g "$grid_20km_prico" -i0 -x tmp_masterfile awps_file_f${fcsthrs}_${GRID} - - export gridprico="latlon 271.75:275:0.25 50.75:205:-0.25" + gridprico="latlon 271.75:275:0.25 50.75:205:-0.25" + # shellcheck disable=SC2086,SC2248 ${WGRIB2} tmp_masterfile ${opt1} ${opt21} ${opt22} ${opt23} ${opt24} ${opt25} ${opt26} \ ${opt27} ${opt28} -new_grid ${gridprico} "awps_file_f${fcsthrs}_${GRID}" ;; pac) - # Grid 20km_pac - 20 km Mercator grid for Pacific Region - # export grid_20km_pac="10 6 0 0 0 0 0 0 837 692 -45000000 110000000 48 20000000 65720000 270000000 64 0 20000000 20000000" - # NEW export grid_20km_pac="10 6 0 0 0 0 0 0 837 725 -45000000 110000000 48 20000000 65734500 270000000 64 0 20000000 20000000" - # $COPYGB2 -g "$grid_20km_pac" -i0 -x tmp_masterfile awps_file_f${fcsthrs}_${GRID} - - export gridpac="mercator:20.0 110.0:837:20000:270.0 -45.0:725:20000:65.7345" + gridpac="mercator:20.0 110.0:837:20000:270.0 -45.0:725:20000:65.7345" + # shellcheck disable=SC2086,SC2248 ${WGRIB2} tmp_masterfile ${opt1} ${opt21} ${opt22} ${opt23} ${opt24} ${opt25} ${opt26} \ ${opt27} ${opt28} -new_grid ${gridpac} "awps_file_f${fcsthrs}_${GRID}" ;; @@ -153,7 +140,8 @@ for GRID in conus ak prico pac 003; do ###################################################################### # Process GFS GRIB AWIP 1.0 DEGREE (GRID 003) PRODUCTS IN GRIB2 # ###################################################################### - export grid003="latlon 0:360:1.0 90:181:-1.0" + grid003="latlon 0:360:1.0 90:181:-1.0" + # shellcheck disable=SC2086,SC2248 ${WGRIB2} tmp_masterfile ${opt1} ${opt21} ${opt22} ${opt23} ${opt24} ${opt25} ${opt26} \ ${opt27} ${opt28} -new_grid ${grid003} "awps_file_f${fcsthrs}_${GRID}" ;; @@ -162,9 +150,8 @@ for GRID in conus ak prico pac 003; do exit 2 ;; esac - # shellcheck disable= - ${TRIMRH} "awps_file_f${fcsthrs}_${GRID}" - ${SCALEDEC} "awps_file_f${fcsthrs}_${GRID}" + trim_rh "awps_file_f${fcsthrs}_${GRID}" + scale_dec "awps_file_f${fcsthrs}_${GRID}" ${GRB2INDEX} "awps_file_f${fcsthrs}_${GRID}" "awps_file_fi${fcsthrs}_${GRID}" ########################################################################### @@ -201,7 +188,8 @@ for GRID in conus ak prico pac 003; do ${TOCGRIB2} < "parm_list" >> "${pgmout}" 2> errfile export err=$?; err_chk - echo " error from tocgrib2=",$err + # TODO: Should this be fatal? + echo "error from tocgrib2=${err}" if [[ ${SENDCOM} == "YES" ]]; then ############################## diff --git a/scripts/exgfs_atmos_grib_awips.sh b/scripts/exgfs_atmos_grib_awips.sh index f10508626f..d3d7592745 100755 --- a/scripts/exgfs_atmos_grib_awips.sh +++ b/scripts/exgfs_atmos_grib_awips.sh @@ -37,13 +37,10 @@ if (( num != 1 )); then exit 16 fi -cd "${DATA}" || exit 2 +cd "${DATA}/awips_g1" || exit 2 -fcsthrs=$(printf "%03d" "${fcsthrs}") - -export SCALEDEC=${SCALDEC:-${USHgfs}/scale_dec.sh} - -cd ${DATA}/awips_g1 || exit 2 +# "Import" functions used in this script +source "${HOMEgfs}/ush/product_functions.sh" ############################################### # Wait for the availability of the pgrb file @@ -59,6 +56,7 @@ while (( icnt < 1000 )); do if (( icnt >= 180 )); then msg="FATAL ERROR: No GFS pgrb2 file after 30 min of waiting" err_exit "${msg}" + exit 5 fi done @@ -79,7 +77,7 @@ cp "${COM_ATMOS_GRIB_0p25}/gfs.t${cyc}z.pgrb2b.0p25.f${fcsthrs}" "tmpfile2b" cat tmpfile2 tmpfile2b > tmpfile ${WGRIB2} tmpfile | grep -F -f "${PARMproduct}/gfs_awips_parmlist_g2" | \ ${WGRIB2} -i -grib masterfile tmpfile -${SCALEDEC} masterfile +scale_dec masterfile ${CNVGRIB} -g21 masterfile masterfile.grib1 ln -s masterfile.grib1 fort.11 @@ -130,7 +128,7 @@ if [[ "${SENDCOM}" = 'YES' ]]; then fi if [[ -e "${pgmout}" ]] ; then - cat ${pgmout} + cat "${pgmout}" fi ############################################################################### diff --git a/scripts/exgfs_atmos_nawips.sh b/scripts/exgfs_atmos_nawips.sh index 07b0ca8b3f..98c6ddffdc 100755 --- a/scripts/exgfs_atmos_nawips.sh +++ b/scripts/exgfs_atmos_nawips.sh @@ -10,25 +10,28 @@ # echo " data on the CCS is properly protected." ##################################################################### -source "$HOMEgfs/ush/preamble.sh" "${2}" +source "${HOMEgfs}/ush/preamble.sh" "${2}" #### If EMC GFS PARA runs hourly file are not available, The ILPOST #### will set to 3 hour in EMC GFS PARA. #### Note: ILPOST default set to 1 export ILPOST=${ILPOST:-1} -cd $DATA +cd "${DATA}" || exit 1 RUN2=$1 fend=$2 DBN_ALERT_TYPE=$3 -destination=${4} +destination=$4 -DATA_RUN=$DATA/$RUN2 -mkdir -p $DATA_RUN -cd $DATA_RUN +DATA_RUN="${DATA}/${RUN2}" +mkdir -p "${DATA_RUN}" +cd "${DATA_RUN}" || exit 1 + +# "Import" functions used in this script +source "${HOMEgfs}/ush/product_functions.sh" # -NAGRIB=$GEMEXE/nagrib2 +NAGRIB="${GEMEXE}/nagrib2" # cpyfil=gds @@ -42,19 +45,19 @@ output=T pdsext=no maxtries=360 -fhcnt=$fstart -while [ $fhcnt -le $fend ] ; do +fhcnt=${fstart} +while (( fhcnt <= fend )) ; do if mkdir "lock.${fhcnt}" ; then - cd lock.$fhcnt - cp $FIXgempak/g2varswmo2.tbl g2varswmo2.tbl - cp $FIXgempak/g2vcrdwmo2.tbl g2vcrdwmo2.tbl - cp $FIXgempak/g2varsncep1.tbl g2varsncep1.tbl - cp $FIXgempak/g2vcrdncep1.tbl g2vcrdncep1.tbl + cd "lock.${fhcnt}" || exit 1 + cp "${FIXgempak}/g2varswmo2.tbl" "g2varswmo2.tbl" + cp "${FIXgempak}/g2vcrdwmo2.tbl" "g2vcrdwmo2.tbl" + cp "${FIXgempak}/g2varsncep1.tbl" "g2varsncep1.tbl" + cp "${FIXgempak}/g2vcrdncep1.tbl" "g2vcrdncep1.tbl" fhr=$(printf "%03d" "${fhcnt}") - GEMGRD=${RUN2}_${PDY}${cyc}f${fhr} + GEMGRD="${RUN2}_${PDY}${cyc}f${fhr}" # Set type of Interpolation for WGRIB2 export opt1=' -set_grib_type same -new_grid_winds earth ' @@ -67,7 +70,6 @@ while [ $fhcnt -le $fend ] ; do export opt26=' -set_grib_max_bits 25 -fi -if ' export opt27=":(APCP|ACPCP|PRATE|CPRAT|DZDT):" export opt28=' -new_grid_interpolation budget -fi ' - export TRIMRH=$HOMEgfs/ush/trim_rh.sh case ${RUN2} in # TODO: Why aren't we interpolating from the 0p25 grids for 35-km and 40-km? @@ -80,71 +82,66 @@ while [ $fhcnt -le $fend ] ; do GRIBIN_chk="${!source_var}/${model}.${cycle}.pgrb2.${res}.f${fhr}.idx" icnt=1 - while [ $icnt -lt 1000 ]; do - if [ -r $GRIBIN_chk ] ; then + while (( icnt < 1000 )); do + if [[ -r "${GRIBIN_chk}" ]] ; then + # File available, wait 5 seconds then proceed sleep 5 break else + # File not available yet, wait 10 seconds and try again echo "The process is waiting ... ${GRIBIN_chk} file to proceed." sleep 10 - let "icnt=icnt+1" + icnt=$((icnt+1)) fi - if [ $icnt -ge $maxtries ]; then - echo "ABORTING: after 1 hour of waiting for ${GRIBIN_chk} file at F$fhr to end." + if (( icnt >= maxtries )); then + echo "FATAL ERROR: after 1 hour of waiting for ${GRIBIN_chk} file at F${fhr} to end." export err=7 ; err_chk - exit $err + exit "${err}" fi done - case $RUN2 in + case "${RUN2}" in gfs35_pac) - # $COPYGB2 -g "0 6 0 0 0 0 0 0 416 186 0 0 75125000 130000000 48 17000000 260000000 312000 312000 0" -x $GRIBIN grib$fhr - # NEW define gfs35_pac="0 6 0 0 0 0 0 0 416 186 0 -1 75125000 130000000 48 17405000 259480000 312000 312000 0" - # $COPYGB2 -g "0 6 0 0 0 0 0 0 416 186 0 -1 75125000 130000000 48 17405000 259480000 312000 312000 0" -x $GRIBIN grib$fhr - export gfs35_pac='latlon 130.0:416:0.312 75.125:186:-0.312' - $WGRIB2 $GRIBIN $opt1 $opt21 $opt22 $opt23 $opt24 $opt25 $opt26 $opt27 $opt28 -new_grid ${gfs35_pac} grib$fhr - $TRIMRH grib$fhr + # shellcheck disable=SC2086,SC2248 + "${WGRIB2}" "${GRIBIN}" ${opt1} ${opt21} ${opt22} ${opt23} ${opt24} ${opt25} ${opt26} ${opt27} ${opt28} -new_grid ${gfs35_pac} "grib${fhr}" + trim_rh "grib${fhr}" ;; gfs35_atl) - # $COPYGB2 -g "0 6 0 0 0 0 0 0 480 242 0 0 75125000 230000000 48 -500000 20000000 312000 312000 0" -x $GRIBIN grib$fhr - # NEW define gfs35_atl="0 6 0 0 0 0 0 0 480 242 0 -1 75125000 230000000 48 -67000 19448000 312000 312000 0" - # $COPYGB2 -g "0 6 0 0 0 0 0 0 480 242 0 -1 75125000 230000000 48 -67000 19448000 312000 312000 0" -x $GRIBIN grib$fhr - export gfs35_atl='latlon 230.0:480:0.312 75.125:242:-0.312' - $WGRIB2 $GRIBIN $opt1 $opt21 $opt22 $opt23 $opt24 $opt25 $opt26 $opt27 $opt28 -new_grid ${gfs35_atl} grib$fhr - $TRIMRH grib$fhr + # shellcheck disable=SC2086,SC2248 + "${WGRIB2}" "${GRIBIN}" ${opt1} ${opt21} ${opt22} ${opt23} ${opt24} ${opt25} ${opt26} ${opt27} ${opt28} -new_grid ${gfs35_atl} "grib${fhr}" + trim_rh "grib${fhr}" ;; gfs40) - # $COPYGB2 -g "30 6 0 0 0 0 0 0 185 129 12190000 226541000 8 25000000 265000000 40635000 40635000 0 64 25000000 25000000 0 0" -x $GRIBIN grib$fhr - export gfs40='lambert:265.0:25.0:25.0 226.541:185:40635.0 12.19:129:40635.0' - $WGRIB2 $GRIBIN $opt1uv $opt21 $opt22 $opt23 $opt24 $opt25 $opt26 $opt27 $opt28 -new_grid ${gfs40} grib$fhr - $TRIMRH grib$fhr + # shellcheck disable=SC2086,SC2248 + "${WGRIB2}" "${GRIBIN}" ${opt1uv} ${opt21} ${opt22} ${opt23} ${opt24} ${opt25} ${opt26} ${opt27} ${opt28} -new_grid ${gfs40} "grib${fhr}" + trim_rh "grib${fhr}" ;; *) - cp $GRIBIN grib$fhr + cp "${GRIBIN}" "grib${fhr}" esac - export pgm="nagrib2 F$fhr" + export pgm="nagrib2 F${fhr}" startmsg - $NAGRIB << EOF - GBFILE = grib$fhr - INDXFL = - GDOUTF = $GEMGRD - PROJ = $proj - GRDAREA = $grdarea - KXKY = $kxky - MAXGRD = $maxgrd - CPYFIL = $cpyfil - GAREA = $garea - OUTPUT = $output - GBTBLS = $gbtbls - GBDIAG = - PDSEXT = $pdsext - l - r + ${NAGRIB} << EOF +GBFILE = grib${fhr} +INDXFL = +GDOUTF = ${GEMGRD} +PROJ = ${proj} +GRDAREA = ${grdarea} +KXKY = ${kxky} +MAXGRD = ${maxgrd} +CPYFIL = ${cpyfil} +GAREA = ${garea} +OUTPUT = ${output} +GBTBLS = ${gbtbls} +GBDIAG = +PDSEXT = ${pdsext} +l +r EOF export err=$?;err_chk @@ -155,24 +152,24 @@ EOF "${destination}/${GEMGRD}" fi fi - cd $DATA_RUN + cd "${DATA_RUN}" || exit 1 else - if [ $fhcnt -ge 240 ] ; then - if [ $fhcnt -lt 276 -a $RUN2 = "gfs_0p50" ] ; then - let fhcnt=fhcnt+6 + if (( fhcnt <= 240 )) ; then + if (( fhcnt < 276 )) && [[ "${RUN2}" = "gfs_0p50" ]] ; then + fhcnt=$((fhcnt+6)) else - let fhcnt=fhcnt+12 + fhcnt=$((fhcnt+12)) fi - elif [ $fhcnt -lt 120 -a $RUN2 = "gfs_0p25" ] ; then + elif ((fhcnt < 120)) && [[ "${RUN2}" = "gfs_0p25" ]] ; then #### let fhcnt=fhcnt+1 - let fhcnt=fhcnt+$ILPOST + fhcnt=$((hcnt + ILPOST)) else fhcnt=$((ILPOST > finc ? fhcnt+ILPOST : fhcnt+finc )) fi fi done -$GEMEXE/gpend +"${GEMEXE}/gpend" ##################################################################### diff --git a/scripts/exgfs_atmos_post.sh b/scripts/exgfs_atmos_post.sh index d17c67867a..acf0234e98 100755 --- a/scripts/exgfs_atmos_post.sh +++ b/scripts/exgfs_atmos_post.sh @@ -42,8 +42,6 @@ export POSTGPSH=${POSTGPSH:-${USHgfs}/gfs_post.sh} export GFSDOWNSH=${GFSDOWNSH:-${USHgfs}/fv3gfs_downstream_nems.sh} export GFSDOWNSHF=${GFSDOWNSHF:-${USHgfs}/inter_flux.sh} export GFSDWNSH=${GFSDWNSH:-${USHgfs}/fv3gfs_dwn_nems.sh} -export TRIMRH=${TRIMRH:-${USHgfs}/trim_rh.sh} -export MODICEC=${MODICEC:-${USHgfs}/mod_icec.sh} export INLINE_POST=${INLINE_POST:-".false."} ############################################################ diff --git a/ush/fv3gfs_dwn_nems.sh b/ush/fv3gfs_dwn_nems.sh index 0de295f172..93f88e2687 100755 --- a/ush/fv3gfs_dwn_nems.sh +++ b/ush/fv3gfs_dwn_nems.sh @@ -29,32 +29,8 @@ grid0p50="latlon 0:720:0.5 90:361:-0.5" # shellcheck disable=SC2034 grid1p00="latlon 0:360:1.0 90:181:-1.0" -# Functions used in this script -function trim_rh() { - # trim RH values larger than 100. - local filename=$1 - ${WGRIB2} "${filename}" \ - -not_if ':RH:' -grib "${filename}.new" \ - -if ':RH:' -rpn "10:*:0.5:+:floor:1000:min:10:/" -set_grib_type same \ - -set_scaling -1 0 -grib_out "${filename}.new" - rc=$? - if (( rc == 0 )); then mv "${filename}.new" "${filename}"; fi - return "${rc}" -} - -function mod_icec() { - # modify icec based on land-sea mask - local filename=$1 - ${WGRIB2} "${filename}" \ - -if 'LAND' -rpn 'sto_1' -fi \ - -if 'ICEC' -rpn 'rcl_1:0:==:*' -fi \ - -set_grib_type same \ - -set_scaling same same \ - -grib_out "${filename}.new" - rc=$? - if (( rc == 0 )); then mv "${filename}.new" "${filename}"; fi - return "${rc}" -} +# "Import" functions used in this script +source "${HOMEgfs}/ush/product_functions.sh" # Transform the input ${grid_string} into an array for processing IFS=':' read -ra grids <<< "${grid_string}" diff --git a/ush/product_functions.sh b/ush/product_functions.sh new file mode 100755 index 0000000000..05b23fbee2 --- /dev/null +++ b/ush/product_functions.sh @@ -0,0 +1,40 @@ +#! /usr/bin/env bash + +function trim_rh() { + # trim RH values larger than 100. + local filename=$1 + ${WGRIB2} "${filename}" \ + -not_if ':RH:' -grib "${filename}.new" \ + -if ':RH:' -rpn "10:*:0.5:+:floor:1000:min:10:/" -set_grib_type same \ + -set_scaling -1 0 -grib_out "${filename}.new" + rc=$? + if (( rc == 0 )); then mv "${filename}.new" "${filename}"; fi + return "${rc}" +} + +function mod_icec() { + # modify icec based on land-sea mask + local filename=$1 + ${WGRIB2} "${filename}" \ + -if 'LAND' -rpn 'sto_1' -fi \ + -if 'ICEC' -rpn 'rcl_1:0:==:*' -fi \ + -set_grib_type same \ + -set_scaling same same \ + -grib_out "${filename}.new" + rc=$? + if (( rc == 0 )); then mv "${filename}.new" "${filename}"; fi + return "${rc}" +} + +function scale_dec() { + # change the scaling for temperature, precipitable water, and water-equivalent accumlated snow depth + local filename=$1 + ${WGRIB2} "${filename}" -not_if ':(TMP|PWAT|WEASD):' -grib "${filename}.new" \ + -if ':(TMP|PWAT):' -set_grib_type same \ + -set_scaling -1 0 -grib_out "${filename}.new" \ + -if ':(WEASD):' -set_grib_type same \ + -set_scaling 0 0 -grib_out "${filename}.new" + rc=$? + if (( rc == 0 )); then mv "${filename}.new" "${filename}"; fi + return "${rc}" +} diff --git a/ush/scale_dec.sh b/ush/scale_dec.sh deleted file mode 100755 index 77136d7f70..0000000000 --- a/ush/scale_dec.sh +++ /dev/null @@ -1,28 +0,0 @@ -#! /usr/bin/env bash - -# -# This script uses WGRIB2 to change binary scale factor -# and Decimal scale factor in GRIB2 file -# -# -set_scaling D B -# D = decimal scaling or the text 'same' with no quotes -# B = binary scaling or the text 'same' with no quotes -# - -source "$HOMEgfs/ush/preamble.sh" - -f=$1 - -export WGRIB2=${WGRIB2:-${wgrib2_ROOT}/bin/wgrib2} - -# export WGRIB2=/gpfs/dell1/nco/ops/nwprod/grib_util.v1.1.0/exec/wgrib2 - -$WGRIB2 $f -not_if ':(TMP|PWAT|WEASD):' -grib $f.new \ - -if ':(TMP|PWAT):' -set_grib_type same \ - -set_scaling -1 0 -grib_out $f.new \ - -if ':(WEASD):' -set_grib_type same \ - -set_scaling 0 0 -grib_out $f.new -export err=$?; err_chk -mv $f.new $f - -exit 0