From 7e1fdd31539f168041339c610f138761385a4228 Mon Sep 17 00:00:00 2001
From: Lukas Kluft <lukas.kluft@gmail.com>
Date: Tue, 14 Jan 2025 10:34:39 +0200
Subject: [PATCH] Skip files that have already been remapped

---
 remap.sh | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/remap.sh b/remap.sh
index 7d9891c..486a8a4 100755
--- a/remap.sh
+++ b/remap.sh
@@ -19,17 +19,21 @@ tgt_grid="hpz9"
 infile=$1
 outdir=$(dirname $infile)/healpix
 outfile=${outdir}/$(basename $infile)
+outfile_part=${outdir}/$(basename $infile).partial
 
 mkdir -p $outdir
 
-# Remap, chunk, and compress the given input file
-cdo \
-  --format nc4 \
-  --compression_type zstd \
-  --chunktype auto \
-  --chunksize $((4**9)) \
-  --num_threads 4 \
-  -remap,$tgt_grid,"$weightsdir/weights_${src_grid}_${tgt_grid}.nc" \
-  $infile $outfile
-
-ncrename -d cells,cell $outfile
+if [ ! -f $outfile ]; then
+  # Remap, chunk, and compress the given input file
+  cdo \
+    --format nc4 \
+    --compression_type zstd \
+    --chunktype auto \
+    --chunksize $((4**9)) \
+    --num_threads 4 \
+    -remap,$tgt_grid,"$weightsdir/weights_${src_grid}_${tgt_grid}.nc" \
+    $infile $outfile_part
+
+  ncrename -d cells,cell $outfile_part
+  mv $outfile_part $outfile
+fi
-- 
GitLab