Skip to content

Commit

Permalink
Fixes GSI monitor undefined and error exits
Browse files Browse the repository at this point in the history
After moving the GSI monitor scripts to workflow, several of the scripts
would fail because set -eu is on, either due to undefined variables or
trying to operate on non-existent files. This corrects some of those issues.

Some of the non-existent files were globs, for these the bash built-in
`compgen -G` is used to check if it resolves to any files.

Refs: #967
  • Loading branch information
WalterKolczynski-NOAA committed Aug 19, 2022
1 parent 4a22035 commit cb29351
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 68 deletions.
20 changes: 15 additions & 5 deletions scripts/exgdas_atmos_verfrad.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,20 @@ if [[ -s ${radstat} && -s ${biascr} ]]; then
netcdf=1
fi

mv diag_${type}_ges.${PDATE}*.${Z} ${type}.${Z}
${UNCOMPRESS} ./${type}.${Z}
if [[ -f "diag_${type}_ges.${PDATE}*.${Z}" ]]; then
mv diag_${type}_ges.${PDATE}*.${Z} ${type}.${Z}
${UNCOMPRESS} ./${type}.${Z}
else
echo "WARNING: diag_${type}_ges.${PDATE}*.${Z} not available, skipping"
fi

if [[ $USE_ANL -eq 1 ]]; then
mv diag_${type}_anl.${PDATE}*.${Z} ${type}_anl.${Z}
${UNCOMPRESS} ./${type}_anl.${Z}
if [[ -f "diag_${type}_anl.${PDATE}*.${Z}" ]]; then
mv diag_${type}_anl.${PDATE}*.${Z} ${type}_anl.${Z}
${UNCOMPRESS} ./${type}_anl.${Z}
else
echo "WARNING: diag_${type}_anl.${PDATE}*.${Z} not available, skipping"
fi
fi
done

Expand All @@ -177,7 +185,7 @@ if [[ -s ${radstat} && -s ${biascr} ]]; then
#--------------------------------------
# optionally run clean_tankdir script
#
if [[ ${CLEAN_TANKVERF} -eq 1 ]]; then
if [[ ${CLEAN_TANKVERF:-0} -eq 1 ]]; then
${USHradmon}/clean_tankdir.sh glb 60
rc_clean_tankdir=$?
echo "rc_clean_tankdir = $rc_clean_tankdir"
Expand Down Expand Up @@ -208,7 +216,9 @@ fi
export CHGRP_CMD=${CHGRP_CMD:-"chgrp ${group_name:-rstprod}"}
rlist="saphir"
for rtype in $rlist; do
if compgen -G "$TANKverf_rad/*${rtype}*" > /dev/null; then
${CHGRP_CMD} $TANKverf_rad/*${rtype}*
fi
done

exit ${err}
Expand Down
15 changes: 8 additions & 7 deletions ush/ozn_xtrct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ check_diag_files() {
echo ""; echo ""; echo "--> check_diag_files"

for type in ${found_satype}; do
check=$(echo ${avail_satype} | grep ${type})
len_check=$(echo -n "${check}" | wc -c)
len_check=$(echo ${avail_satype} | grep ${type} | wc -c)

if [[ ${len_check} -le 1 ]]; then
echo "missing diag file -- diag_${type}_ges.${pdate}.gz not found " >> ./${out_file}
Expand Down Expand Up @@ -153,9 +152,11 @@ else
echo "ptype = ${ptype}"


for type in ${satype}; do
mv diag_${type}_${ptype}.${PDATE}.gz ${type}.${ptype}.gz
gunzip ./${type}.${ptype}.gz
for type in ${avail_satype}; do
if [[ -f "diag_${type}_${ptype}.${PDATE}.gz" ]]; then
mv diag_${type}_${ptype}.${PDATE}.gz ${type}.${ptype}.gz
gunzip ./${type}.${ptype}.gz
fi
done


Expand All @@ -167,7 +168,7 @@ else
idd=$(echo ${PDATE} | cut -c7-8)
ihh=$(echo ${PDATE} | cut -c9-10)

for type in ${satype}; do
for type in ${avail_satype}; do
echo "processing ptype, type: ${ptype}, ${type}"
rm -f input

Expand Down Expand Up @@ -258,7 +259,7 @@ fi
#-------------------------------------------------------
# Conditionally remove data files older than 40 days
#
if [[ ${CLEAN_TANKDIR} -eq 1 ]]; then
if [[ ${CLEAN_TANKDIR:-0} -eq 1 ]]; then
${HOMEoznmon}/ush/clean_tankdir.sh glb 40
fi

Expand Down
30 changes: 16 additions & 14 deletions ush/radmon_verf_angle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,22 @@ EOF

${USHradmon}/rstprod.sh

tar_file=radmon_angle.tar
tar -cf $tar_file angle*.ieee_d* angle*.ctl*
${COMPRESS} ${tar_file}
mv $tar_file.${Z} ${TANKverf_rad}/.

if [[ $RAD_AREA = "rgn" ]]; then
cwd=$(pwd)
cd ${TANKverf_rad}
tar -xf ${tar_file}.${Z}
rm ${tar_file}.${Z}
cd ${cwd}
fi

if [[ $fail -eq $ctr || $fail -gt $ctr ]]; then
tar_file=radmon_angle.tar
if compgen -G "angle*.ieee_d* angle*.ctl*" > /dev/null; then
tar -cf $tar_file angle*.ieee_d* angle*.ctl*
${COMPRESS} ${tar_file}
mv $tar_file.${Z} ${TANKverf_rad}/.

if [[ $RAD_AREA = "rgn" ]]; then
cwd=$(pwd)
cd ${TANKverf_rad}
tar -xf ${tar_file}.${Z}
rm ${tar_file}.${Z}
cd ${cwd}
fi
fi

if [[ $ctr -gt 0 && $fail -eq $ctr || $fail -gt $ctr ]]; then
err=3
fi
fi
Expand Down
26 changes: 14 additions & 12 deletions ush/radmon_verf_bcoef.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,22 @@ EOF

${USHradmon}/rstprod.sh

tar_file=radmon_bcoef.tar
tar -cf $tar_file bcoef*.ieee_d* bcoef*.ctl*
${COMPRESS} ${tar_file}
mv $tar_file.${Z} ${TANKverf_rad}

if [[ $RAD_AREA = "rgn" ]]; then
cwd=$(pwd)
cd ${TANKverf_rad}
tar -xf ${tar_file}.${Z}
rm ${tar_file}.${Z}
cd ${cwd}
if compgen -G "bcoef*.ieee_d* bcoef*.ctl*" > /dev/null; then
tar_file=radmon_bcoef.tar
tar -cf $tar_file bcoef*.ieee_d* bcoef*.ctl*
${COMPRESS} ${tar_file}
mv $tar_file.${Z} ${TANKverf_rad}

if [[ $RAD_AREA = "rgn" ]]; then
cwd=$(pwd)
cd ${TANKverf_rad}
tar -xf ${tar_file}.${Z}
rm ${tar_file}.${Z}
cd ${cwd}
fi
fi

if [[ $fail -eq $ctr || $fail -gt $ctr ]]; then
if [[ $ctr -gt 0 && $fail -eq $ctr || $fail -gt $ctr ]]; then
err=5
fi
fi
Expand Down
26 changes: 14 additions & 12 deletions ush/radmon_verf_bcor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ else
input_file=${type}
fi

rm input
if [[ -f input ]]; then rm input; fi

# Check for 0 length input file here and avoid running
# the executable if $input_file doesn't exist or is 0 bytes
Expand Down Expand Up @@ -200,19 +200,21 @@ EOF
${USHradmon}/rstprod.sh
tar_file=radmon_bcor.tar

tar -cf $tar_file bcor*.ieee_d* bcor*.ctl*
${COMPRESS} ${tar_file}
mv $tar_file.${Z} ${TANKverf_rad}/.

if [[ $RAD_AREA = "rgn" ]]; then
cwd=$(pwd)
cd ${TANKverf_rad}
tar -xf ${tar_file}.${Z}
rm ${tar_file}.${Z}
cd ${cwd}
if compgen -G "bcor*.ieee_d* bcor*.ctl*" > /dev/null; then
tar -cf $tar_file bcor*.ieee_d* bcor*.ctl*
${COMPRESS} ${tar_file}
mv $tar_file.${Z} ${TANKverf_rad}/.

if [[ $RAD_AREA = "rgn" ]]; then
cwd=$(pwd)
cd ${TANKverf_rad}
tar -xf ${tar_file}.${Z}
rm ${tar_file}.${Z}
cd ${cwd}
fi
fi

if [[ $fail -eq $ctr || $fail -gt $ctr ]]; then
if [[ $ctr -gt 0 && $fail -eq $ctr || $fail -gt $ctr ]]; then
err=7
fi
fi
Expand Down
39 changes: 22 additions & 17 deletions ush/radmon_verf_time.sh
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,22 @@ EOF

${USHradmon}/rstprod.sh

tar_file=radmon_time.tar
tar -cf $tar_file time*.ieee_d* time*.ctl*
${COMPRESS} ${tar_file}
mv $tar_file.${Z} ${TANKverf_rad}/.

if [[ $RAD_AREA = "rgn" ]]; then
cwd=$(pwd)
cd ${TANKverf_rad}
tar -xf ${tar_file}.${Z}
rm ${tar_file}.${Z}
cd ${cwd}
if compgen -G "time*.ieee_d* time*.ctl*" > /dev/null; then
tar_file=radmon_time.tar
tar -cf $tar_file time*.ieee_d* time*.ctl*
${COMPRESS} ${tar_file}
mv $tar_file.${Z} ${TANKverf_rad}/.

if [[ $RAD_AREA = "rgn" ]]; then
cwd=$(pwd)
cd ${TANKverf_rad}
tar -xf ${tar_file}.${Z}
rm ${tar_file}.${Z}
cd ${cwd}
fi
fi

if [[ $fail -eq $ctr || $fail -gt $ctr ]]; then
if [[ $ctr -gt 0 && $fail -eq $ctr || $fail -gt $ctr ]]; then
echo "fail, ctr = $fail, $ctr"
err=10
fi
Expand Down Expand Up @@ -407,11 +409,14 @@ EOF
#--------------------------------------------------------------------
# Remove extra spaces in new bad_pen & low_count files
#
gawk '{$1=$1}1' $bad_pen > tmp.bad_pen
mv -f tmp.bad_pen $bad_pen

gawk '{$1=$1}1' $low_count > tmp.low_count
mv -f tmp.low_count $low_count
if [[ -s ${bad_pen} ]]; then
gawk '{$1=$1}1' $bad_pen > tmp.bad_pen
mv -f tmp.bad_pen $bad_pen
fi
if [[ -s ${low_count} ]]; then
gawk '{$1=$1}1' $low_count > tmp.low_count
mv -f tmp.low_count $low_count
fi

echo " do_pen, do_chan, do_cnt = $do_pen, $do_chan, $do_cnt"
echo " diag_report = $diag_report "
Expand Down
4 changes: 3 additions & 1 deletion ush/rstprod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ source "$HOMEgfs/ush/preamble.sh"
export CHGRP_CMD=${CHGRP_CMD:-"chgrp ${group_name:-rstprod}"}
rlist="saphir abi_g16"
for rtype in $rlist; do
${CHGRP_CMD} *${rtype}*
if compgen -G "*${rtype}*" > /dev/null; then
${CHGRP_CMD} *${rtype}*
fi
done

0 comments on commit cb29351

Please sign in to comment.