Skip to content

Commit

Permalink
Use seq to generate the list of times, instead of a bash for-loop (NO…
Browse files Browse the repository at this point in the history
…AA-EMC#2264)

I'm running a year-long forecast, which means I get a large portion of the log file dedicated to these loops.  

`seq ${START} ${STEP} ${STOP}` will generate a sequence going from START to STOP by STEP, including STOP if relevant.  That seems to be the purpose of these loops.  It will by default separate the list with newlines, but `seq -s ' ' ${START} ${STEP} ${STOP}` will separate them with spaces instead, more closely mimicing the previous behavior.

I would like this to be two lines in the log, rather than a few hundred, and this may also be faster, though probably more for reasons of fewer writes to disk than because bash isn't designed for arithmetic.
  • Loading branch information
DWesl committed Jan 30, 2024
1 parent d5bee38 commit 6bbe823
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions ush/forecast_predet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,10 @@ FV3_predet(){
FV3_OUTPUT_FH=""
local fhr=${FHMIN}
if (( FHOUT_HF > 0 && FHMAX_HF > 0 )); then
for (( fh = FHMIN; fh < FHMAX_HF; fh = fh + FHOUT_HF )); do
FV3_OUTPUT_FH="${FV3_OUTPUT_FH} ${fh}"
done
FV3_OUTPUT_FH="${FV3_OUTPUT_FH} $(seq -s ' ' "${FHMIN}" "${FHOUT_HF}" "${FHMAX_HF}")"
fhr=${FHMAX_HF}
fi
for (( fh = fhr; fh <= FHMAX; fh = fh + FHOUT )); do
FV3_OUTPUT_FH="${FV3_OUTPUT_FH} ${fh}"
done

FV3_OUTPUT_FH="${FV3_OUTPUT_FH} $(seq -s ' ' "${fhr}" "${FHOUT}" "${FHMAX}")"

# Model resolution specific parameters
DELTIM=${DELTIM:-225}
Expand Down

0 comments on commit 6bbe823

Please sign in to comment.