Skip to content

Commit 830b5a6

Browse files
Assuring time-steps are merged properly (#89)
1 parent ef6fa92 commit 830b5a6

File tree

1 file changed

+32
-10
lines changed
  • var/repos/builtin/recipes/eccc-casr

1 file changed

+32
-10
lines changed

var/repos/builtin/recipes/eccc-casr/casr.sh

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -378,35 +378,57 @@ while [[ "$toDateUnix" -le "$endDateIterUnix" ]]; do
378378
fi
379379

380380
# Remove any left-over .tmp file
381-
if [[ -e ${cache}/${file}*.tmp ]]; then
382-
rm -r "${cache}/${file}*.tmp"
381+
if [[ -e ${cache}/*${file}*.tmp ]]; then
382+
rm -r "${cache}/*${file}*.tmp"
383383
fi
384384

385385
# Wait for any left-over processes to finish
386386
wait
387387

388388
# Change lon values so the extents are from ~-180 to 0
389389
# assuring the process finished using an `until` loop
390-
until ncap2 -A -s 'where(lon>0) lon=lon-360' \
390+
until ncap2 -O -s 'where(lon>0) lon=lon-360' \
391391
"${cache}/${file}" \
392-
"${cache}/${prefix}${file}"; do
393-
rm "${outputDir}/${prefix}${file}"
392+
"${cache}/lon_${file}"; do
393+
rm "${cache}/lon_${file}*"
394394
echo "$(logDate)$(basename $0): Process killed: restarting process in 10 sec" >&2
395395
echo "$(logDate)$(basename $0): NCAP2 -s [...] failed" >&2
396396
sleep 10;
397397
done
398398

399399
# Check to see if the final file exists in the $outputDir
400400
if [[ -f "${outputDir}/${prefix}${file}" ]]; then
401-
ncrcat -O "${cache}/${prefix}${file}" "${outputDir}/${prefix}${file}" \
402-
"${outputDir}/${prefix}${file}";
401+
# If it already has 24 time-steps (complete file), skip it
402+
tSteps="$(cdo ntime "${outputDir}/${prefix}${file}" | head -n 1)"
403+
404+
if [[ $tSteps != 24 ]]; then
405+
# Copying the existing file to cache for further merging
406+
cp "${outputDir}/${prefix}${file}" "${cache}/temp_${file}"
407+
408+
# Enable skipping duplicate time-steps
409+
export SKIP_SAME_TIME=1
410+
411+
# Merging existing time-steps (temp_) with the extracted ones (lon_)
412+
echo "$(logDate)$(basename $0): WARNING! File ${prefix}${file} already exists in ${outputDir}" >&2;
413+
echo "$(logDate)$(basename $0): Merging missing time-steps" >&2;
414+
cdo -O mergetime "${cache}/lon_${file}" "${cache}/temp_${file}" \
415+
"${cache}/merged_${file}" >&2;
416+
417+
# Copy the merged_ file to the $outputDir
418+
cp "${cache}/merged_${file}" "${outputDir}/${prefix}${file}"
419+
420+
else
421+
echo "$(logDate)$(basename $0): ${prefix}${file} and all time-steps already exist, skipping" >&2;
422+
fi
423+
403424
else
404-
cp "${cache}/${prefix}${file}" "${outputDir}/${prefix}${file}"
425+
# Otherwise, copy whatever has been extracted
426+
cp "${cache}/lon_${file}" "${outputDir}/${prefix}${file}"
405427
fi
406428

407429
# Remove any left-over .tmp file
408-
if [[ -e ${cache}/${file}*.tmp ]]; then
409-
rm -r "${cache}/${file}*.tmp"
430+
if [[ -e ${cache}/*${file}*.tmp ]]; then
431+
rm -r "${cache}/*${file}*.tmp"
410432
fi
411433

412434
# Wait for any left-over processes to finish

0 commit comments

Comments
 (0)