Skip to content

Commit

Permalink
Address SC2086 and SC2250 shellcheck warnings
Browse files Browse the repository at this point in the history
- In monitor ush scripts

Refs NOAA-EMC#1925
  • Loading branch information
KateFriedman-NOAA committed Nov 28, 2023
1 parent 909f7b4 commit 1dc638d
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 157 deletions.
36 changes: 18 additions & 18 deletions ush/ozn_xtrct.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env bash

source "$HOMEgfs/ush/preamble.sh"
source "${HOMEgfs}/ush/preamble.sh"

#------------------------------------------------------------------
# ozn_xtrct.sh
Expand Down Expand Up @@ -58,33 +58,33 @@ nregion=${nregion:-6}
DO_DATA_RPT=${DO_DATA_RPT:-0}

netcdf_boolean=".false."
if [[ $OZNMON_NETCDF -eq 1 ]]; then
if [[ ${OZNMON_NETCDF} -eq 1 ]]; then
netcdf_boolean=".true."
fi

OZNMON_NEW_HDR=${OZNMON_NEW_HDR:-0}
new_hdr="F"
if [[ $OZNMON_NEW_HDR -eq 1 ]]; then
if [[ ${OZNMON_NEW_HDR} -eq 1 ]]; then
new_hdr="T"
fi

#------------------------------------------------------------------
# if VALIDATE_DATA then locate and untar base file
#
validate=".FALSE."
if [[ $VALIDATE_DATA -eq 1 ]]; then
if [[ ! -e $ozn_val_file && ! -h $ozn_val_file ]]; then
echo "WARNING: VALIDATE_DATA set to 1, but unable to locate $ozn_val_file"
if [[ ${VALIDATE_DATA} -eq 1 ]]; then
if [[ ! -e ${ozn_val_file} && ! -h ${ozn_val_file} ]]; then
echo "WARNING: VALIDATE_DATA set to 1, but unable to locate ${ozn_val_file}"
echo " Setting VALIDATE_DATA to 0/OFF"
VALIDATE_DATA=0
else
validate=".TRUE."
val_file=$(basename "${ozn_val_file}")
${NCP} "$ozn_val_file" "$val_file"
tar -xvf "$val_file"
${NCP} "${ozn_val_file}" "${val_file}"
tar -xvf "${val_file}"
fi
fi
echo "VALIDATE_DATA, validate = $VALIDATE_DATA, $validate "
echo "VALIDATE_DATA, validate = ${VALIDATE_DATA}, ${validate} "



Expand Down Expand Up @@ -149,9 +149,9 @@ else
#
for ptype in ${ozn_ptype}; do

iyy=$(echo "${PDY}" | cut -c1-4)
imm=$(echo "${PDY}" | cut -c5-6)
idd=$(echo "${PDY}" | cut -c7-8)
iyy="${PDY:0:4}"
imm="${PDY:4:2}"
idd="${PDY:6:2}"
ihh=${cyc}

for type in ${avail_satype}; do
Expand Down Expand Up @@ -195,10 +195,10 @@ EOF
if [[ ! -d ${TANKverf_ozn}/time ]]; then
mkdir -p "${TANKverf_ozn}/time"
fi
$NCP "${type}.${ptype}.ctl "${TANKverf_ozn}/time/"
$NCP "${type}.${ptype}.${PDY}${cyc}.ieee_d" "${TANKverf_ozn}/time/"
${NCP} "${type}.${ptype}.ctl" "${TANKverf_ozn}/time/"
${NCP} "${type}.${ptype}.${PDY}${cyc}.ieee_d" "${TANKverf_ozn}/time/"

$NCP bad* "${TANKverf_ozn}/time/"
${NCP} bad* "${TANKverf_ozn}/time/"

rm -f input

Expand Down Expand Up @@ -226,10 +226,10 @@ EOF
if [[ ! -d ${TANKverf_ozn}/horiz ]]; then
mkdir -p "${TANKverf_ozn}/horiz"
fi
$NCP "${type}.${ptype}.ctl" "${TANKverf_ozn}/horiz/"
${NCP} "${type}.${ptype}.ctl" "${TANKverf_ozn}/horiz/"

$COMPRESS "${type}.${ptype}.${PDY}${cyc}.ieee_d"
$NCP "${type}.${ptype}.${PDY}${cyc}.ieee_d.${Z}" "${TANKverf_ozn}/horiz/"
${COMPRESS} "${type}.${ptype}.${PDY}${cyc}.ieee_d"
${NCP} "${type}.${ptype}.${PDY}${cyc}.ieee_d.${Z}" "${TANKverf_ozn}/horiz/"


echo "finished processing ptype, type: ${ptype}, ${type}"
Expand Down
26 changes: 13 additions & 13 deletions ush/radmon_diag_ck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ echo "--> radmon_diag_ck.sh"
# Process input arguments
#
nargs=$#
if [[ $nargs -ne 6 ]]; then
if [[ ${nargs} -ne 6 ]]; then
usage
exit 1
fi

while [[ $# -ge 1 ]]
do
key="$1"
echo $key
echo "${key}"

case $key in
case ${key} in
-r|--rad)
radstat_file="$2"
shift # past argument
Expand All @@ -52,7 +52,7 @@ echo "--> radmon_diag_ck.sh"
;;
*)
#unspecified key
echo " unsupported key = $key"
echo " unsupported key = ${key}"
;;
esac

Expand All @@ -71,23 +71,23 @@ echo "--> radmon_diag_ck.sh"
#---------------------------------------------
# get list of diag files in the radstat file
#
radstat_contents=`tar -tf ${radstat_file} | grep '_ges' |
radstat_contents=`tar -tf "${radstat_file}" | grep '_ges' |
gawk -F"diag_" '{print $2}' |
gawk -F"_ges" '{print $1}'`


#---------------------------------------------
# load contents of satype_file into an array
#
satype_contents=`cat ${satype_file}`
satype_contents=`cat "${satype_file}"`


#-------------------------------------------------
# compare $satype_contents and $radstat_contents
# report anything missing
#
for sat in $satype_contents; do
test=`echo $radstat_contents | grep $sat`
for sat in ${satype_contents}; do
test=`echo "${radstat_contents}" | grep "${sat}"`

if [[ ${#test} -le 0 ]]; then
missing_diag="${missing_diag} ${sat}"
Expand Down Expand Up @@ -117,10 +117,10 @@ echo "--> radmon_diag_ck.sh"
# TODO Rewrite these array parsing commands to avoid using Bash's sloppy word splitting
# File sizes contain only digits and immediately precede the date
# shellcheck disable=SC2207
sizes=($(tar -vtf ${radstat_file} --wildcards '*_ges*' | grep -P -o '(\d)+(?= \d{4}-\d{2}-\d{2})'))
sizes=($(tar -vtf "${radstat_file}" --wildcards '*_ges*' | grep -P -o '(\d)+(?= \d{4}-\d{2}-\d{2})'))
# Filenames are the last group of non-whitespace characters
# shellcheck disable=SC2207
filenames=($(tar -vtf ${radstat_file} --wildcards '*_ges*' | grep -P -o '\S+$'))
filenames=($(tar -vtf "${radstat_file}" --wildcards '*_ges*' | grep -P -o '\S+$'))
# shellcheck disable=


Expand All @@ -144,7 +144,7 @@ echo "--> radmon_diag_ck.sh"
zero_len_diag="${zero_len_diag} ${sat}"
fi

rm -f ${uz_file_name}
rm -f "${uz_file_name}"
fi

done
Expand All @@ -159,13 +159,13 @@ echo "--> radmon_diag_ck.sh"
#
if [[ ${#zero_len_diag} -gt 0 ]]; then
for zld in ${zero_len_diag}; do
echo " Zero Length diagnostic file: $zld" >> $output_file
echo " Zero Length diagnostic file: ${zld}" >> "${output_file}"
done
fi

if [[ ${#missing_diag} -gt 0 ]]; then
for md in ${missing_diag}; do
echo " Missing diagnostic file : $md" >> $output_file
echo " Missing diagnostic file : ${md}" >> "${output_file}"
done
fi

Expand Down
102 changes: 51 additions & 51 deletions ush/radmon_err_rpt.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env bash

source "$HOMEgfs/ush/preamble.sh"
source "${HOMEgfs}/ush/preamble.sh"

################################################################################
#### UNIX Script Documentation Block
Expand Down Expand Up @@ -63,28 +63,28 @@ err=0
RADMON_SUFFIX=${RADMON_SUFFIX}

have_diag_rpt=0
if [[ -s $diag_rpt ]]; then
if [[ -s ${diag_rpt} ]]; then
have_diag_rpt=1
else
err=1
fi
echo "have_diag_rpt = $have_diag_rpt"
echo "have_diag_rpt = ${have_diag_rpt}"

#-----------------------------------------------------------------------------
# read each line in the $file1
# search $file2 for the same satname, channel, and region
# if same combination is in both files, add the values to the output file
#
{ while read myline; do
echo "myline = $myline"
echo "myline = ${myline}"
bound=""

echo $myline
satname=$(echo $myline | gawk '{print $1}')
channel=$(echo $myline | gawk '{print $3}')
region=$(echo $myline | gawk '{print $5}')
value1=$(echo $myline | gawk '{print $7}')
bound=$(echo $myline | gawk '{print $9}')
echo "${myline}"
satname=$(echo "${myline}" | gawk '{print $1}')
channel=$(echo "${myline}" | gawk '{print $3}')
region=$(echo "${myline}" | gawk '{print $5}')
value1=$(echo "${myline}" | gawk '{print $7}')
bound=$(echo "${myline}" | gawk '{print $9}')

#
# Check findings against diag_report. If the satellite/instrument is on the
Expand All @@ -96,95 +96,95 @@ echo "have_diag_rpt = $have_diag_rpt"
diag_match=""
diag_match_len=0

if [[ $have_diag_rpt == 1 ]]; then
diag_match=$(gawk "/$satname/" $diag_rpt)
if [[ ${have_diag_rpt} == 1 ]]; then
diag_match=$(gawk "/${satname}/" "${diag_rpt}")
diag_match_len=$(echo ${#diag_match})
fi


if [[ $diag_match_len == 0 ]]; then
if [[ ${diag_match_len} == 0 ]]; then

if [[ $type == "chan" ]]; then
echo "looking for match for $satname and $channel"
if [[ ${type} == "chan" ]]; then
echo "looking for match for ${satname} and ${channel}"
{ while read myline2; do
satname2=$(echo $myline2 | gawk '{print $1}')
channel2=$(echo $myline2 | gawk '{print $3}')
satname2=$(echo "${myline2}" | gawk '{print $1}')
channel2=$(echo "${myline2}" | gawk '{print $3}')

if [[ $satname == $satname2 && $channel == $channel2 ]]; then
match="$satname channel= $channel"
echo "match from gawk = $match"
if [[ ${satname} == ${satname2} && ${channel} == ${channel2} ]]; then
match="${satname} channel= ${channel}"
echo "match from gawk = ${match}"
break;
else
match=""
fi

done } < $file2
done } < "${file2}"


else
match=$(gawk "/$satname/ && /channel= $channel / && /region= $region /" $file2)
echo match = $match
match=$(gawk "/${satname}/ && /channel= ${channel} / && /region= ${region} /" "${file2}")
echo match = "${match}"

match_len=$(echo ${#match})
if [[ $match_len > 0 ]]; then
channel2=$(echo $match | gawk '{print $3}')
if [[ ${match_len} > 0 ]]; then
channel2=$(echo "${match}" | gawk '{print $3}')

if [[ $channel2 != $channel ]]; then
if [[ ${channel2} != ${channel} ]]; then
match=""
fi
fi

fi
match_len=$(echo ${#match})

if [[ $match_len > 0 ]]; then
if [[ ${match_len} > 0 ]]; then

value2=$(echo $match | gawk '{print $7}')
bound2=$(echo $match | gawk '{print $9}')
value2=$(echo "${match}" | gawk '{print $7}')
bound2=$(echo "${match}" | gawk '{print $9}')

if [[ $type == "chan" ]]; then
tmpa=" $satname channel= $channel"
if [[ ${type} == "chan" ]]; then
tmpa=" ${satname} channel= ${channel}"
tmpb=""

elif [[ $type == "pen" ]]; then
tmpa="$satname channel= $channel region= $region"
tmpb="$cycle1 $value1 $bound"
elif [[ ${type} == "pen" ]]; then
tmpa="${satname} channel= ${channel} region= ${region}"
tmpb="${cycle1} ${value1} ${bound}"

elif [[ $type == "cnt" ]]; then
tmpa="$satname channel= $channel region= $region"
tmpb="$cycle1 $value1 $bound"
elif [[ ${type} == "cnt" ]]; then
tmpa="${satname} channel= ${channel} region= ${region}"
tmpb="${cycle1} ${value1} ${bound}"

else
tmpa="$satname channel= $channel region= $region"
tmpb="$cycle1: $type= $value1"
tmpa="${satname} channel= ${channel} region= ${region}"
tmpb="${cycle1}: ${type}= ${value1}"
fi

line1="$tmpa $tmpb"
echo "$line1" >> $outfile
line1="${tmpa} ${tmpb}"
echo "${line1}" >> "${outfile}"

if [[ $type != "chan" ]]; then
tmpc=$(echo $tmpa |sed 's/[a-z]/ /g' | sed 's/[0-9]/ /g' | sed 's/=/ /g' | sed 's/_/ /g' | sed 's/-/ /g')
if [[ ${type} != "chan" ]]; then
tmpc=$(echo "${tmpa}" |sed 's/[a-z]/ /g' | sed 's/[0-9]/ /g' | sed 's/=/ /g' | sed 's/_/ /g' | sed 's/-/ /g')

if [[ $type == "pen" || $type == "cnt" ]]; then
line2=" $tmpc $cycle2 $value2 $bound2"
if [[ ${type} == "pen" || ${type} == "cnt" ]]; then
line2=" ${tmpc} ${cycle2} ${value2} ${bound2}"
else
line2=" $tmpc $cycle2: $type= $value2"
line2=" ${tmpc} ${cycle2}: ${type}= ${value2}"
fi

echo "$line2" >> $outfile
echo "${line2}" >> "${outfile}"
fi

#-----------------------------------------
# add hyperlink to warning entry
#
line3=" http://www.emc.ncep.noaa.gov/gmb/gdas/radiance/es_rad/${RADMON_SUFFIX}/index.html?sat=${satname}&region=${region}&channel=${channel}&stat=${type}"
if [[ $channel -gt 0 ]]; then
echo "$line3" >> $outfile
echo "" >> $outfile
if [[ ${channel} -gt 0 ]]; then
echo "${line3}" >> "${outfile}"
echo "" >> "${outfile}"
fi
fi
fi
done } < $file1
done } < "${file1}"


################################################################################
Expand Down
Loading

0 comments on commit 1dc638d

Please sign in to comment.