From a9da0e069b97227fcc45e81c828cfdfd5f3b0af3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Oriol=20Tint=C3=B3?= <oriol.tinto@lmu.de>
Date: Wed, 24 May 2023 17:25:57 +0200
Subject: [PATCH] Revert "Fix prepare_date_local.sh and prepare_date_remote.sh"

This reverts commit 76d1efd956d7709565d6a7c31c8c863c99e3bdfe.
---
 .../real-from-dwd-ana/prepare_date_local.sh   | 46 ++++++++++++-----
 .../real-from-dwd-ana/prepare_date_remote.sh  | 49 +++++++++++++------
 2 files changed, 68 insertions(+), 27 deletions(-)

diff --git a/templates/real-from-dwd-ana/prepare_date_local.sh b/templates/real-from-dwd-ana/prepare_date_local.sh
index d077f3d..6cca59f 100644
--- a/templates/real-from-dwd-ana/prepare_date_local.sh
+++ b/templates/real-from-dwd-ana/prepare_date_local.sh
@@ -33,18 +33,42 @@ if [ "${IS_LOCAL}" == "True" ]; then
     exit 1
   fi
 
-  # Create member folder and go there
-  mkdir -p ${COMMON_DATE_FOLDER}
-  cd ${COMMON_DATE_FOLDER} || exit
 
-  # Save filenames to be used later by other scripts.
-  echo "${AN_FILE}" > an_file.txt
-  echo "${FG_FILE}" > fg_file.txt
+  # Check if we copy the initial conditions from the local system or the remote one
+  if [ "${IS_LOCAL}" != "True" ]; then
+    # Create member folder
+    ssh "${HPCUSER}@${HPCHOST}" mkdir -p ${COMMON_DATE_FOLDER}
 
-  # Copy the first-guess and analysis files.
-  cp "${FG_SOURCE}" "${FG_FILE}"
-  cp "${AN_SOURCE}" "${AN_FILE}"
+    # Save filenames to be used later by other scripts.
+    echo "${AN_FILE}" > an_file.txt
+    echo "${FG_FILE}" > fg_file.txt
+    rsync -v an_file.txt "${HPCUSER}@${HPCHOST}":"${COMMON_DATE_FOLDER}/an_file.txt"
+    rsync -v fg_file.txt "${HPCUSER}@${HPCHOST}":"${COMMON_DATE_FOLDER}/fg_file.txt"
 
-  # Change permissions to read only.
-  chmod 440 ./*
+    # Remove temporary files.
+    rm an_file.txt
+    rm fg_file.txt
+
+    # Copy the first-guess and analysis files.
+    rsync -v "${FG_SOURCE}" "${HPCUSER}@${HPCHOST}":"${COMMON_DATE_FOLDER}/${FG_FILE}"
+    rsync -v "${AN_SOURCE}" "${HPCUSER}@${HPCHOST}":"${COMMON_DATE_FOLDER}/${AN_FILE}"
+
+    # Change permissions to read only.
+    ssh "${HPCUSER}@${HPCHOST}" chmod 440 "${COMMON_DATE_FOLDER}/*"
+  else
+    # Create member folder and go there
+    mkdir -p ${COMMON_DATE_FOLDER}
+    cd ${COMMON_DATE_FOLDER} || exit
+
+    # Save filenames to be used later by other scripts.
+    echo "${AN_FILE}" > an_file.txt
+    echo "${FG_FILE}" > fg_file.txt
+
+    # Copy the first-guess and analysis files.
+    cp "${FG_SOURCE}" "${FG_FILE}"
+    cp "${AN_SOURCE}" "${AN_FILE}"
+
+    # Change permissions to read only.
+    chmod 440 ./*
+  fi
 fi
\ No newline at end of file
diff --git a/templates/real-from-dwd-ana/prepare_date_remote.sh b/templates/real-from-dwd-ana/prepare_date_remote.sh
index 9c0e956..8fec0ce 100644
--- a/templates/real-from-dwd-ana/prepare_date_remote.sh
+++ b/templates/real-from-dwd-ana/prepare_date_remote.sh
@@ -2,7 +2,7 @@
 
 IS_LOCAL=%SIMULATION.INITIAL_CONDITIONS.LOCAL%
 
-if [ "${IS_LOCAL}" == "False" ]; then
+if [ "${IS_LOCAL}" == "0" ]; then
   # Get some variables provided by autosubmit.
   WORKDIR=%HPCROOTDIR%
   STARTDATE=%SDATE%
@@ -32,25 +32,42 @@ if [ "${IS_LOCAL}" == "False" ]; then
     exit 1
   fi
 
+
   # Check if we copy the initial conditions from the local system or the remote one
-  # Create member folder
-  ssh "${HPCUSER}@${HPCHOST}" mkdir -p ${COMMON_DATE_FOLDER}
+  if [ "${IS_LOCAL}" == "True" ]; then
+    # Create member folder
+    ssh "${HPCUSER}@${HPCHOST}" mkdir -p ${COMMON_DATE_FOLDER}
+
+    # Save filenames to be used later by other scripts.
+    echo "${AN_FILE}" > an_file.txt
+    echo "${FG_FILE}" > fg_file.txt
+    rsync -v an_file.txt "${HPCUSER}@${HPCHOST}":"${COMMON_DATE_FOLDER}/an_file.txt"
+    rsync -v fg_file.txt "${HPCUSER}@${HPCHOST}":"${COMMON_DATE_FOLDER}/fg_file.txt"
 
-  # Save filenames to be used later by other scripts.
-  echo "${AN_FILE}" > an_file.txt
-  echo "${FG_FILE}" > fg_file.txt
-  rsync -v an_file.txt "${HPCUSER}@${HPCHOST}":"${COMMON_DATE_FOLDER}/an_file.txt"
-  rsync -v fg_file.txt "${HPCUSER}@${HPCHOST}":"${COMMON_DATE_FOLDER}/fg_file.txt"
+    # Remove temporary files.
+    rm an_file.txt
+    rm fg_file.txt
 
-  # Remove temporary files.
-  rm an_file.txt
-  rm fg_file.txt
+    # Copy the first-guess and analysis files.
+    rsync -v "${FG_SOURCE}" "${HPCUSER}@${HPCHOST}":"${COMMON_DATE_FOLDER}/${FG_FILE}"
+    rsync -v "${AN_SOURCE}" "${HPCUSER}@${HPCHOST}":"${COMMON_DATE_FOLDER}/${AN_FILE}"
 
-  # Copy the first-guess and analysis files.
-  rsync -v "${FG_SOURCE}" "${HPCUSER}@${HPCHOST}":"${COMMON_DATE_FOLDER}/${FG_FILE}"
-  rsync -v "${AN_SOURCE}" "${HPCUSER}@${HPCHOST}":"${COMMON_DATE_FOLDER}/${AN_FILE}"
+    # Change permissions to read only.
+    ssh "${HPCUSER}@${HPCHOST}" chmod 440 "${COMMON_DATE_FOLDER}/*"
+  else
+    # Create member folder and go there
+    mkdir -p ${COMMON_DATE_FOLDER}
+    cd ${COMMON_DATE_FOLDER} || exit
 
-  # Change permissions to read only.
-  ssh "${HPCUSER}@${HPCHOST}" chmod 440 "${COMMON_DATE_FOLDER}/*"
+    # Save filenames to be used later by other scripts.
+    echo "${AN_FILE}" > an_file.txt
+    echo "${FG_FILE}" > fg_file.txt
 
+    # Copy the first-guess and analysis files.
+    cp "${FG_SOURCE}" "${FG_FILE}"
+    cp "${AN_SOURCE}" "${AN_FILE}"
+
+    # Change permissions to read only.
+    chmod 440 ./*
+  fi
 fi
\ No newline at end of file
-- 
GitLab