foamJob: Add -append option to append to the log-file rather than overwriting

Thanks to alexeym for patch
Resolves feature-request http://www.openfoam.org/mantisbt/view.php?id=1655
This commit is contained in:
Henry
2015-04-27 10:25:04 +01:00
parent d542ea93d5
commit 4c20de71bb

View File

@ -40,6 +40,7 @@ options:
-case <dir> specify alternative case directory, default is the cwd -case <dir> specify alternative case directory, default is the cwd
-parallel parallel run of processors -parallel parallel run of processors
-screen also sends output to screen -screen also sends output to screen
-append append to log file instead of overwriting it
-wait wait for execution to complete (when not using -screen) -wait wait for execution to complete (when not using -screen)
-version <ver> specify an alternative OpenFOAM version -version <ver> specify an alternative OpenFOAM version
-help print the usage -help print the usage
@ -51,7 +52,7 @@ USAGE
exit 1 exit 1
} }
#for being able to echo strings that have single quotes # Echo strings that have single quotes
echoArgs() { echoArgs() {
addSpace="" addSpace=""
@ -75,7 +76,7 @@ echoArgs() {
unset version unset version
# replacement for possibly buggy 'which' # Replacement for possibly buggy 'which'
findExec() { findExec() {
case "$1" in case "$1" in
*/*) */*)
@ -107,12 +108,12 @@ findExec() {
# MAIN SCRIPT # Main script
#~~~~~~~~~~~~ #~~~~~~~~~~~~
unset parallelOpt screenOpt waitOpt unset parallelOpt screenOpt waitOpt
# parse options # Parse options
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
do do
case "$1" in case "$1" in
@ -132,6 +133,10 @@ do
screenOpt=true screenOpt=true
shift shift
;; ;;
-a | -append)
appendOpt=true
shift
;;
-w | -wait) -w | -wait)
waitOpt=true waitOpt=true
shift shift
@ -157,22 +162,22 @@ done
[ "$#" -ge 1 ] || usage "No application specified" [ "$#" -ge 1 ] || usage "No application specified"
# use foamExec for a specified version # Use foamExec for a specified version
# also need foamExec for remote (parallel) runs # Also need foamExec for remote (parallel) runs
if [ -n "$version" -o "$parallelOpt" = true ] if [ -n "$version" -o "$parallelOpt" = true ]
then then
# when possible, determine if application even exists # When possible, determine if application even exists
if [ -z "$version" ] if [ -z "$version" ]
then then
findExec $1 >/dev/null || usage "Application '$1' not found" findExec $1 >/dev/null || usage "Application '$1' not found"
fi fi
# use foamExec for dispatching # Use foamExec for dispatching
APPLICATION=`findExec foamExec` || usage "'foamExec' not found" APPLICATION=`findExec foamExec` || usage "'foamExec' not found"
[ -n "$version" ] && APPLICATION="$APPLICATION -version $version" [ -n "$version" ] && APPLICATION="$APPLICATION -version $version"
# attempt to preserve the installation directory 'FOAM_INST_DIR' # Attempt to preserve the installation directory 'FOAM_INST_DIR'
if [ -d "$FOAM_INST_DIR" ] if [ -d "$FOAM_INST_DIR" ]
then then
APPLICATION="$APPLICATION -prefix $FOAM_INST_DIR" APPLICATION="$APPLICATION -prefix $FOAM_INST_DIR"
@ -191,7 +196,7 @@ then
# ~~~~~~~~ # ~~~~~~~~
# #
# is the case decomposed? # Check if the case decomposed
# #
if [ -r "processor0" ] if [ -r "processor0" ]
then then
@ -211,13 +216,13 @@ then
fi fi
# #
# locate mpirun # Find mpirun
# #
mpirun=`findExec mpirun` || usage "'mpirun' not found" mpirun=`findExec mpirun` || usage "'mpirun' not found"
mpiopts="-np $NPROCS" mpiopts="-np $NPROCS"
# #
# is the machine ready to run parallel? # Check if the machine ready to run parallel
# #
echo "Parallel processing using $WM_MPLIB with $NPROCS processors" echo "Parallel processing using $WM_MPLIB with $NPROCS processors"
case "$WM_MPLIB" in case "$WM_MPLIB" in
@ -247,15 +252,22 @@ then
esac esac
# #
# run (in parallel) # Run (in parallel)
# #
if [ "$screenOpt" = true ] if [ "$screenOpt" = true ]
then then
echo "Executing: $mpirun $mpiopts $APPLICATION $(echoArgs "$@") -parallel | tee log" [ "$appendOpt" = true ] && teeOpts=" -a"
$mpirun $mpiopts $APPLICATION "$@" -parallel | tee log echo "Executing: $mpirun $mpiopts $APPLICATION $(echoArgs "$@") -parallel | tee $teeOpts log"
$mpirun $mpiopts $APPLICATION "$@" -parallel | tee $teeOpts log
else else
echo "Executing: $mpirun $mpiopts $APPLICATION $(echoArgs "$@") -parallel > log 2>&1" if [ "$appendOpt" = true ]
$mpirun $mpiopts $APPLICATION "$@" -parallel > log 2>&1 & then
echo "Executing: $mpirun $mpiopts $APPLICATION $(echoArgs "$@") -parallel >> log 2>&1"
$mpirun $mpiopts $APPLICATION "$@" -parallel >> log 2>&1 &
else
echo "Executing: $mpirun $mpiopts $APPLICATION $(echoArgs "$@") -parallel > log 2>&1"
$mpirun $mpiopts $APPLICATION "$@" -parallel > log 2>&1 &
fi
pid=$! pid=$!
if [ "$waitOpt" = true ] if [ "$waitOpt" = true ]
@ -266,16 +278,23 @@ then
else else
# #
# run (on single processor) # Run (on single processor)
# #
if [ "$screenOpt" = true ] if [ "$screenOpt" = true ]
then then
echo "Executing: $APPLICATION $(echoArgs "$@") | tee log &" [ "$appendOpt" = true ] && teeOpts=" -a"
$APPLICATION "$@" | tee log & echo "Executing: $APPLICATION $(echoArgs "$@") | tee $teeOpts log &"
$APPLICATION "$@" | tee $teeOpts log &
wait $! wait $!
else else
echo "Executing: $APPLICATION $(echoArgs "$@") > log 2>&1 &" if [ "$appendOpt" = true ]
$APPLICATION "$@" > log 2>&1 & then
echo "Executing: $APPLICATION $(echoArgs "$@") >> log 2>&1 &"
$APPLICATION "$@" >> log 2>&1 &
else
echo "Executing: $APPLICATION $(echoArgs "$@") > log 2>&1 &"
$APPLICATION "$@" > log 2>&1 &
fi
pid=$! pid=$!
if [ "$waitOpt" = true ] if [ "$waitOpt" = true ]
@ -285,4 +304,5 @@ else
fi fi
fi fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------