From bdf6677037c27e79f86260a11e9405705955d151 Mon Sep 17 00:00:00 2001 From: Kasra Farmer Date: Wed, 4 Dec 2024 08:39:55 -0700 Subject: [PATCH] Improving the scripts for CONUS II Given that there might be descrepencies between various versions of the CONUS II dataset files (what is locally available and what is offered by NCAR,) minor changes are proposed to alleviate issues that may come up. Reported-by: Logan Fang Signed-off-by: Kasra Keshavarz --- scripts/gwf-ncar-conus_ii/conus_ii.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/gwf-ncar-conus_ii/conus_ii.sh b/scripts/gwf-ncar-conus_ii/conus_ii.sh index 380c0f4..f88e49f 100755 --- a/scripts/gwf-ncar-conus_ii/conus_ii.sh +++ b/scripts/gwf-ncar-conus_ii/conus_ii.sh @@ -312,8 +312,25 @@ function concat_files () { shift 2 # shift arguments by 2 positions local filesArr=("$@") # array of file names - # concatenating $files and producing a single $fName.nc - ncrcat "${filesArr[@]}" "${fTempDir}/${fName}_cat.nc" + # Create temp directory for intermediate files + local ctmpdir="${fTempDir}/tmp_concat_$$" + mkdir -p "$ctmpdir" + + # Process each file to add Time variable + for f in "${filesArr[@]}"; do + if [ -f "$f" ]; then + local basename_f=$(basename "$f") + ncap2 -s 'Time=XTIME' "$f" "${ctmpdir}/${basename_f}" + else + echo "Warning: File $f does not exist, skipping" + fi + done + + # Concatenate processed files + ncrcat "${ctmpdir}"/* "${fTempDir}/${fName}_cat.nc" + + # Clean up + rm -rf "$ctmpdir" }