Skip to content

Commit

Permalink
Removing Shell checks
Browse files Browse the repository at this point in the history
  • Loading branch information
AnilKumar-NOAA committed Sep 27, 2023
1 parent c3934a3 commit 3fdd4a8
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions scripts/exglobal_stage_ic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ gcyc="${GDATE:8:2}"

# Determine NMEM_ENS based on the configuration file (e.g., config.base)
# Assuming NMEM_ENS is defined in config.base as an integer
NMEM_ENS=$(cat "${EXPDIR}/config.base" | grep "NMEM_ENS" | awk -F= '{print $2}')

config_file="${EXPDIR}/config.base"

if [ -e "$config_file" ]; then
NMEM_ENS=$(grep "NMEM_ENS" "$config_file" | awk -F= '{print $2}')
else
echo "Error: $config_file does not exist or is not accessible." >&2
exit 1
fi

member_dirs=()

# Populate the member_dirs array based on the value of NMEM_ENS
for ((i = 0; i < NMEM_ENS; i++)); do
member_dirs+=("mem$(printf "%03d" $i)")
for ((i = 0; i < "${NMEM_ENS}"; i++)); do
member_dirs+=("mem$(printf "%03d" "${i}")")
done

# Now, member_dirs contains elements like "mem000," "mem001," ..., "memNNN" where NNN is the value of NMEM_ENS.
Expand All @@ -32,16 +41,16 @@ error_message(){
# Start staging gefs and gfs here

# Check for command line argument to select gfs or gefs
if [ "$#" -ne 1 ]; then
echo "Usage: $0 [gfs | gefs]"
if [[ $# -ne 1 ]]; then
echo "Usage: ${0} [gfs | gefs]"
exit 1
fi


if [ "$selection" = "gfs" ]; then
# Stage the FV3 initial conditions to ROTDIR (cold start)

MEM=""
member_dir=""
NMEM_ENS=0

YMD=${PDY} HH=${cyc} generate_com -r COM_ATMOS_INPUT
Expand All @@ -62,8 +71,9 @@ err=$((err + rc))
err=$((err + rc))
done
done
elif [ "$selection" = "gefs" ]; then
MEM=""
elif [[ "${selection}" = "gefs" ]]; then

member_dir=""
YMD=${PDY} HH=${cyc} generate_com -r COM_ATMOS_INPUT
[[ ! -d "${COM_ATMOS_INPUT}" ]] && mkdir -p "${COM_ATMOS_INPUT}"
for member_dir in $(seq -w 0 $((NMEM_ENS - 1))); do
Expand All @@ -86,9 +96,9 @@ YMD=${PDY} HH=${cyc} generate_com -r COM_ATMOS_INPUT
fi

# Stage ocean initial conditions to ROTDIR (warm start)
if [[ "${DO_OCN:-}" = "YES" && "$selection" = "gfs" ]]; then
if [[ "${DO_OCN:-}" = "YES" && "${selection}" = "gfs" ]]; then

MEM=""
member_dir=""
NMEM_ENS=0

YMD=${gPDY} HH=${gcyc} generate_com -r COM_OCEAN_RESTART
Expand Down Expand Up @@ -120,8 +130,8 @@ NMEM_ENS=0
err=$((err + rc))
;;
esac
elif [[ "${DO_OCN:-}" = "YES" && "$selection" = "gefs" ]]; then
MEM=""
elif [[ "${DO_OCN:-}" = "YES" && "${selection}" = "gefs" ]]; then
member_dir=""
YMD=${gPDY} HH=${gcyc} generate_com -r COM_OCEAN_RESTART
[[ ! -d "${COM_OCEAN_RESTART}" ]] && mkdir -p "${COM_OCEAN_RESTART}"
for member_dir in $(seq -w 0 $((NMEM_ENS - 1))); do
Expand All @@ -138,8 +148,8 @@ elif [[ "${DO_OCN:-}" = "YES" && "$selection" = "gefs" ]]; then
fi

# Stage ice initial conditions to ROTDIR (warm start)
if [[ "${DO_ICE:-}" = "YES" && "$selection" = "gfs" ]]; then
MEM=""
if [[ "${DO_ICE:-}" = "YES" && "${selection}" = "gfs" ]]; then
member_dir=""
NMEM_ENS=0
YMD=${gPDY} HH=${gcyc} generate_com -r COM_ICE_RESTART
[[ ! -d "${COM_ICE_RESTART}" ]] && mkdir -p "${COM_ICE_RESTART}"
Expand All @@ -151,13 +161,11 @@ if [[ "${DO_ICE:-}" = "YES" && "$selection" = "gfs" ]]; then
(( rc != 0 )) && error_message "${source}" "${target}" "${rc}"
err=$((err + rc))

elif [[ "${DO_ICE:-}" = "YES" && "$selection" = "gefs" ]]; then
MEM=""
elif [[ "${DO_ICE:-}" = "YES" && "${selection}" = "gefs" ]]; then
member_dir=""
YMD=${gPDY} HH=${gcyc} generate_com -r COM_ICE_RESTART
[[ ! -d "${COM_ICE_RESTART}" ]] && mkdir -p "${COM_ICE_RESTART}"
for member_idx in $(seq -w 0 $((NMEM_ENS - 1))); do
# Pad member_idx with zeros to make it three digits
member_dir="mem$(printf "%03d" "$member_idx")"
for member_dir in $(seq -w 0 $((NMEM_ENS - 1))); do
source="${BASE_CPLIC}/${CPL_ATMIC}/${YMD}${HH}/${member_dir}/ice/${PDY}.${cyc}0000.cice_model.res.nc"
target="${COM_OCEAN_RESTART}/${PDY}.${cyc}0000.cice_model.res.nc"
${NCP} "${source}" "${target}"
Expand All @@ -171,8 +179,8 @@ elif [[ "${DO_ICE:-}" = "YES" && "$selection" = "gefs" ]]; then
fi

# Stage the WW3 initial conditions to ROTDIR (warm start; TODO: these should be placed in $RUN.$gPDY/$gcyc)
if [[ "${DO_WAVE:-}" = "YES" && "$selection" = "gfs" ]]; then
MEM=""
if [[ "${DO_WAVE:-}" = "YES" && "${selection}" = "gfs" ]]; then
member_dir=""
NMEM_ENS=0
YMD=${PDY} HH=${cyc} generate_com -r COM_WAVE_RESTART
[[ ! -d "${COM_WAVE_RESTART}" ]] && mkdir -p "${COM_WAVE_RESTART}"
Expand All @@ -184,8 +192,8 @@ if [[ "${DO_WAVE:-}" = "YES" && "$selection" = "gfs" ]]; then
(( rc != 0 )) && error_message "${source}" "${target}" "${rc}"
err=$((err + rc))
done
elif [[ "${DO_WAVE:-}" = "YES" && "$selection" = "gefs" ]]; then
MEM=""
elif [[ "${DO_WAVE:-}" = "YES" && "${selection}" = "gefs" ]]; then
member_dir=""
YMD=${gPDY} HH=${gcyc} generate_com -r COM_WAVE_RESTART
[[ ! -d "${COM_WAVE_RESTART}" ]] && mkdir -p "${COM_WAVE_RESTART}"
for member_dir in $(seq -w 0 $((NMEM_ENS - 1))); do
Expand Down

0 comments on commit 3fdd4a8

Please sign in to comment.