From 26a2c1778a53301993097556a9c6c1f3e9ea0e10 Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Thu, 19 Nov 2015 15:48:06 +0000
Subject: [PATCH] RunFunctions: Added -append and -overwrite options -append:
 append to log file -overwrite: overwrite log file Original patch provided by
 Timm Severin Resolves feature request
 http://www.openfoam.org/mantisbt/view.php?id=1919

---
 bin/tools/RunFunctions | 72 ++++++++++++++++++++++++++++++++----------
 1 file changed, 56 insertions(+), 16 deletions(-)

diff --git a/bin/tools/RunFunctions b/bin/tools/RunFunctions
index 5a254ea43b8..6dd1fbafa56 100644
--- a/bin/tools/RunFunctions
+++ b/bin/tools/RunFunctions
@@ -40,40 +40,80 @@ getApplication()
 
 runApplication()
 {
-    APP_RUN=$1
-    APP_NAME=${1##*/}
+    APP_RUN=
+    LOG_IGNORE=false
+    LOG_APPEND=false
+
+    # Parse options and executable
+    while [ $# -gt 0 ] && [ -z "$APP_RUN" ]; do
+        key="$1"
+        case "$key" in
+            -append)
+                LOG_IGNORE=true
+                LOG_APPEND=true
+                ;;
+            -overwrite)
+                LOG_IGNORE=true
+                ;;
+            *)
+                APP_RUN="$key"
+                APP_NAME="${key##*/}"
+                ;;
+        esac
     shift
+    done
 
-    if [ -f log.$APP_NAME ]
+    if [ -f log.$APP_NAME ] && [ "$LOG_IGNORE" = "false" ]
     then
         echo "$APP_NAME already run on $PWD: remove log file to re-run"
     else
         echo "Running $APP_RUN on $PWD"
-        $APP_RUN "$@" > log.$APP_NAME 2>&1
+        if [ "$LOG_APPEND" = "true" ]; then
+            $APP_RUN "$@" >> log.$APP_NAME 2>&1
+        else
+            $APP_RUN "$@" > log.$APP_NAME 2>&1
+        fi
     fi
 }
 
 runParallel()
 {
-    APP_RUN=$1
-    APP_NAME=${1##*/}
+    APP_RUN=
+    LOG_IGNORE=false
+    LOG_APPEND=false
+
+    # Parse options and executable
+    while [ $# -gt 0 ] && [ -z "$APP_RUN" ]; do
+        key="$1"
+        case "$key" in
+            -append)
+                LOG_IGNORE=true
+                LOG_APPEND=true
+                ;;
+            -overwrite)
+                LOG_IGNORE=true
+                ;;
+            *)
+                APP_RUN="$key"
+                APP_NAME="${key##*/}"
+                # also read number of processors
+                nProcs="$2"
+                shift
+                ;;
+        esac
     shift
+    done
 
-    if [ -f log.$APP_NAME ]
+    if [ -f log.$APP_NAME ] && [ "$LOG_IGNORE" = "false" ]
     then
         echo "$APP_NAME already run on $PWD: remove log file to re-run"
     else
-        nProcs=$1
-        shift
         echo "Running $APP_RUN in parallel on $PWD using $nProcs processes"
-
-        #if [ "$WM_SCHEDULER" ]
-        #then
-        #    echo "$PWD: $WM_SCHEDULER -np $nProcs" 1>&2
-        #    $WM_SCHEDULER -np $nProcs "( mpirun -np $nProcs $APP_RUN -parallel "$@" < /dev/null > log.$APP_NAME 2>&1 )"
-        #else
+        if [ "$LOG_APPEND" = "true" ]; then
+            ( mpirun -np $nProcs $APP_RUN -parallel "$@" < /dev/null >> log.$APP_NAME 2>&1 )
+        else
             ( mpirun -np $nProcs $APP_RUN -parallel "$@" < /dev/null > log.$APP_NAME 2>&1 )
-        #fi
+        fi
     fi
 }
 
-- 
GitLab