Index: palm/trunk/SCRIPTS/palm_simple_build
===================================================================
--- palm/trunk/SCRIPTS/palm_simple_build	(revision 2850)
+++ palm/trunk/SCRIPTS/palm_simple_build	(revision 2850)
@@ -0,0 +1,159 @@
+#!/usr/bin/env bash
+#--------------------------------------------------------------------------------#
+# This file is part of the PALM model system.
+#
+# PALM is free software: you can redistribute it and/or modify it under the terms
+# of the GNU General Public License as published by the Free Software Foundation,
+# either version 3 of the License, or (at your option) any later version.
+#
+# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# PALM. If not, see <http://www.gnu.org/licenses/>.
+#
+# Copyright 1997-2018  Leibniz Universitaet Hannover
+#--------------------------------------------------------------------------------#
+#
+# Current revisions:
+# -----------------
+# 
+# 
+# Former revisions:
+# -----------------
+# $Id$
+# Refactoring of the palm_simple_ build and run scripts
+# 
+# 2718 2018-01-02 08:49:38Z maronga
+# Corrected "Former revisions" section
+#
+# 2696 2017-12-14 17:12:51Z kanani
+# Change in file header (GPL part)
+#
+# 2225 2017-05-16 11:36:20Z raasch
+# shell changed to bash
+#
+# 1310 2014-03-14 08:01:56Z raasch
+# update GPL copyright
+#
+# 1046 2012-11-09 14:38:45Z maronga
+# code put under GPL (PALM 3.9)
+#
+# palm_simple_install - a script for simple installation and compilation of
+#                       the palm code without using mbuild
+# This script creates (from the working copy of the palm repository)
+# a subdirectory MAKE_DEPOSITORY_simple which contains a copy of the
+# palm source code and  a modified makefile which loads required compiler
+# and preprocessor settings via "include MAKE.inc"
+
+# Options: -i <include file>
+#          one of the include files in ~/palm/current_version/trunk/INSTALL
+
+# Last changes:
+# 25/01/10 - Siggi - Generating the first version
+# 18/03/10 - Siggi - switch to palm/current_version removed: working
+#                    copy can be in any directory
+#------------------------------------------------------------------------------#
+SOURCE="${BASH_SOURCE[0]}"
+while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
+  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+  SOURCE="$(readlink "$SOURCE")"
+  # if $SOURCE was a relative symlink, we need to resolve it
+  # relative to the path where the symlink file was located
+  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
+done
+SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+
+working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../")
+trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../")
+
+
+get_number_of_cpu_cores() {
+   {
+      n=$(sysctl -n machdep.cpu.core_count 2> /dev/null)
+   } || {
+      n=$(grep -c ^processor /proc/cpuinfo 2> /dev/null)
+   } || {
+   if ! [[ $n =~ ^-?[0-9]+$ ]]; then
+      n=1
+   fi
+   }
+   echo $n
+}
+
+print_help() {
+   echo "Usage: palm_simple_run -b <build-config> [-x]"
+   echo ""
+   echo "List of allowed option:"
+   echo ""
+   echo "   -b <build-config>   Suffix of any MAKE.inc.<build-config> file in the trunk/INSTALL dir."
+   echo "   -x                  Clean the build directory from last build attempts"
+   echo ""
+}
+
+build_config=unknown
+clean="false"
+
+# Read shellscript options
+while  getopts  :b:xh  option
+do
+  case  $option  in
+      (b)   build_config=$OPTARG;;
+      (x)   clean="true";;
+      (h)   print_help
+            exit 0;;
+      (\?)  echo "Unknown option -$OPTARG"
+            print_help
+            exit 1;;
+  esac
+done
+
+if [[ ${build_config} == "unknown" ]]; then
+   echo "Missing option -b <build-config>"
+   print_help
+   exit 1
+fi
+
+
+build_dir=${working_dir}/MAKE_DEPOSITORY_$build_config
+
+
+# Check, if include file exists
+build_config_file=${trunk_dir}/INSTALL/MAKE.inc.$build_config
+if [[ ! -f ${build_config_file} ]]; then
+   echo "+++ ERROR: no such make include file:"
+   echo "    \"${build_config_file}\""
+   exit 1
+fi
+
+
+# Create the make depository
+if [[ ! -d ${build_dir} ]]; then
+   mkdir -p ${build_dir}
+else
+   if [[ ${clean} == "true" ]]; then
+      echo "Cleaning the build directory..."
+      rm -rf ${build_dir}/*
+   fi
+fi
+
+
+# Copy makefile and all source code files to make depository
+cp -n ${trunk_dir}/SOURCE/Makefile  ${build_dir}/Makefile_in
+cp -n ${build_config_file}          ${build_dir}/MAKE.inc
+cp -n ${trunk_dir}/SOURCE/*.f90     ${build_dir}
+
+
+# Replace comment in makefile by include statement
+sed  's/#to_be_replaced_by_include/include MAKE.inc/g'  ${build_dir}/Makefile_in  >  ${build_dir}/Makefile
+rm  ${build_dir}/Makefile_in
+
+cd ${build_dir}
+make -j $(get_number_of_cpu_cores)
+cd ../
+
+
+echo "*** PALM build finished. Executable can be found in:"
+echo "    \"${build_dir}\""
+exit 0
Index: palm/trunk/SCRIPTS/palm_simple_install
===================================================================
--- palm/trunk/SCRIPTS/palm_simple_install	(revision 2845)
+++ 	(revision )
@@ -1,108 +1,0 @@
-#!/bin/bash
-#--------------------------------------------------------------------------------#
-# This file is part of the PALM model system.
-#
-# PALM is free software: you can redistribute it and/or modify it under the terms
-# of the GNU General Public License as published by the Free Software Foundation,
-# either version 3 of the License, or (at your option) any later version.
-#
-# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# PALM. If not, see <http://www.gnu.org/licenses/>.
-#
-# Copyright 1997-2018  Leibniz Universitaet Hannover
-#--------------------------------------------------------------------------------#
-#
-# Current revisions:
-# -----------------
-# 
-# 
-# Former revisions:
-# -----------------
-# $Id$
-# Corrected "Former revisions" section
-#
-# 2696 2017-12-14 17:12:51Z kanani
-# Change in file header (GPL part)
-#
-# 2225 2017-05-16 11:36:20Z raasch
-# shell changed to bash
-#
-# 1310 2014-03-14 08:01:56Z raasch
-# update GPL copyright
-#
-# 1046 2012-11-09 14:38:45Z maronga
-# code put under GPL (PALM 3.9)
-#
-# palm_simple_install - a script for simple installation and compilation of
-#                       the palm code without using mbuild
-     # This script creates (from the working copy of the palm repository)
-     # a subdirectory MAKE_DEPOSITORY_simple which contains a copy of the
-     # palm source code and  a modified makefile which loads required compiler
-     # and preprocessor settings via "include MAKE.inc"
-
-     # Options: -i <include file>
-     #          one of the include files in ~/palm/current_version/trunk/INSTALL
-
-     # Last changes:
-     # 25/01/10 - Siggi - Generating the first version
-     # 18/03/10 - Siggi - switch to palm/current_version removed: working
-     #                    copy can be in any directory
-
-
-    # Variable declarations + default values
- include_file=unknown
-
-
-    # Read shellscript options
- while  getopts  :i:  option
- do
-   case  $option  in
-       (i)   include_file=$OPTARG;;
-       (\?)  printf "\n  +++ unknown option $OPTARG \n"
-             printf "\n      allowed option are -d, -f, -l, -s \n"
-             exit;;
-   esac
- done
-
-
-
-    # Check, if include file exists
- if [[ ! -f trunk/INSTALL/$include_file ]]
- then
-    echo "+++ ERROR: include file"
-    echo "    \"trunk/INSTALL/$include_file\""
-    echo "    not found"
-    exit
- fi
-
-
-     # Create the make depository
- if [[ ! -d MAKE_DEPOSITORY_simple ]]
- then
-    mkdir  MAKE_DEPOSITORY_simple
- else
-    rm  MAKE_DEPOSITORY_simple/*
- fi
-
-
-     # Copy makefile and all source code files to make depository
- cp  trunk/SOURCE/Makefile        MAKE_DEPOSITORY_simple/Makefile_old
- cp  trunk/INSTALL/$include_file  MAKE_DEPOSITORY_simple/MAKE.inc
- cp  trunk/SOURCE/*.f90           MAKE_DEPOSITORY_simple
-
-
-     # Replace comment in makefile by include statement
- sed  's/#to_be_replaced_by_include/include MAKE.inc/g'  MAKE_DEPOSITORY_simple/Makefile_old  >  MAKE_DEPOSITORY_simple/Makefile
- rm  MAKE_DEPOSITORY_simple/Makefile_old
-
-
-     # Create directory for input files
- if [[ ! -d JOBS/example_cbl/INPUT ]]
- then
-    mkdir -p  JOBS/example_cbl/INPUT
-    cp trunk/INSTALL/example_cbl_p3d  JOBS/example_cbl/INPUT
- fi
Index: palm/trunk/SCRIPTS/palm_simple_run
===================================================================
--- palm/trunk/SCRIPTS/palm_simple_run	(revision 2845)
+++ palm/trunk/SCRIPTS/palm_simple_run	(revision 2850)
@@ -1,3 +1,3 @@
-#!/bin/bash
+#!/usr/bin/env bash
 #--------------------------------------------------------------------------------#
 # This file is part of the PALM model system.
@@ -24,4 +24,7 @@
 # -----------------
 # $Id$
+# Refactoring of the palm_simple_ build and run scripts
+# 
+# 2718 2018-01-02 08:49:38Z maronga
 # Corrected "Former revisions" section
 #
@@ -63,129 +66,190 @@
 # with make in directory  ...../MAKE_DEPOSITORY_simple
 #--------------------------------------------------------------------------------#
-
-
-    # Variable declarations + default values
- case=example_cbl
- cpumax=999999
- execute_for=unknown
- localhost=unknown
- localhost_realname=$(hostname)
- mpi_procs=1
- mpi_procs_per_node=1
- openmp_threads=1
-
- typeset -i  ii
-
-
-    # Read shellscript options
- while  getopts  :c:e:l:n:p:t:  option
- do
-   case  $option  in
-       (c)   case=$OPTARG;;
-       (e)   execute_for=$OPTARG;;
-       (l)   localhost=$OPTARG;;
-       (n)   mpi_procs_per_node=$OPTARG;;
-       (p)   mpi_procs=$OPTARG;;
-       (t)   openmp_threads=$OPTARG;;
-       (\?)  printf "\n  +++ unknown option $OPTARG \n"
-             printf "\n      allowed option are -c, -e, -l, -n, -p, -t \n"
-             exit;;
-   esac
- done
-
-
-    # Find out the global svn revision number
- global_revision=`svnversion ${palm_dir}trunk  2>/dev/null`
- global_revision="Rev: $global_revision"
-
-
-    # Generate unique directory/files for this run
- timedate="`date +%d.%b_%H:%M:%S`"
- suffix=$case+$mpi_procs+$timedate
- RUNDIR=OUTPUT.$suffix/
-
- if [[ ! -d $RUNDIR ]]
- then
-    mkdir $RUNDIR
-    echo "*** running in directory $RUNDIR"
- else
-    echo "+++ ERROR: $RUNDIR exists\!   Must be unique.  Exiting."
-    exit
- fi
-
-
-    # Check if palm has been installed and copy executable into the run
-    # directory
- if [[ ! -f ${palm_dir}MAKE_DEPOSITORY_simple/palm ]]
- then
-    echo "+++ ERROR: palm executable does not exist."
-    echo "           Please run \"palm_simple_install\"."
-    exit
- else
-    cp  ${palm_dir}MAKE_DEPOSITORY_simple/palm  $RUNDIR/palm
- fi
-
-
-    # Check, if parameter file exists and copy into the run directory
- if [[ ! -f ${palm_dir}JOBS/${case}/INPUT/${case}_p3d ]]
- then
-    echo "+++ ERROR: parameter file"
-    echo "           \"${palm_dir}JOBS/${case}/INPUT/${case}_p3d\""
-    echo "           does not exist."
-    exit
- else
-    cp  ${palm_dir}JOBS/${case}/INPUT/${case}_p3d  $RUNDIR/PARIN
- fi
-
-
-    # Switch to run directory
- cd  $RUNDIR
-
-
-
-    # Create NAMELIST file containing environment values needed by palm
- cat  >  ENVPAR  <<  %%END%%
- &envpar  run_identifier = '$case', host = '$localhost',
-          write_binary = 'false', tasks_per_node = $mpi_procs_per_node,
-          maximum_cpu_time_allowed = ${cpumax}.,
-          revision = '$global_revision',
-          local_dvrserver_running = .FALSE. /
-
-%%END%%
-
-
-    # Coupled runs cannot be carried out with this simple run script
- echo "no_coupling"  >  runfile_atmos
-
-
-    # Generate hostfile (if neccessary)
- (( ii = 1 ))
- while (( ii <= $mpi_procs ))
- do
-    echo  $localhost_realname  >>  hostfile
-    (( ii = ii + 1 ))
- done
-
-
-    # Set number of OpenMP threads
- export OMP_NUM_THREADS=$openmp_threads
-
-
-
-    # Start palm run
- echo "*** palm will be run:  MPI tasks: $mpi_procs   OpenMP thread: $OMP_NUM_THREADS"
-
- case $execute_for in
-
-    (imuk)         mpiexec  -machinefile hostfile  -n $mpi_procs  ./palm  < runfile_atmos;;
-    (sgi-mpt)      mpiexec_mpt  -np $mpi_procs  ./palm  < runfile_atmos;;
-    (hpc-flow)     mpiexec  -machinefile $TMPDIR/machines -n $mpi_procs  -env I_MPI_FABRICS shm:ofa ./palm  < runfile_atmos;;
-    (pgi-openacc)  export PGI_ACC_SYNCHRONOUS=1; ./palm;;
-    (*)      echo "+++ -e option to define execution command is missing";;
-
- esac
-
- echo "*** palm finished"
- echo "*** see"
- echo "    \"$RUNDIR\""
- echo "    for results"
+SOURCE="${BASH_SOURCE[0]}"
+while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
+  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+  SOURCE="$(readlink "$SOURCE")"
+  # if $SOURCE was a relative symlink, we need to resolve it
+  # relative to the path where the symlink file was located
+  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
+done
+SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+
+working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../")
+trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../")
+
+# Variable declarations + default values
+build_config=unknown
+run_config=unknown
+test_case=unknown
+mpi_ranks=1
+mpi_ranks_per_node=1
+openmp_threads=1
+localhost_realname=$(hostname)
+cpumax=999999
+
+print_help() {
+   echo "Usage: palm_simple_run -b <build-config> -c <run-config> -s <test-case>"
+   echo "                       [-n <mpi-ranks-per-node>] [-p <mpi-ranks>]"
+   echo "                       [-t <openmp-threads>]"
+   echo ""
+   echo "List of allowed option:"
+   echo ""
+   echo "   -b <build-config>        Suffix of any MAKE.inc.<build-config> file in the trunk/INSTALL dir."
+   echo "   -c <run-config>          Suffix of any RUN.cmd.<run-config> file in the trunk/INSTALL dir."
+   echo "   -n <mpi-ranks-per-node>  Number of MPI ranks per compute node."
+   echo "   -p <mpi-ranks>           Number of MPI ranks in total."
+   echo "   -s <test-case>           Prefix of any <test-case>_p3d file in the trunk/INSTALL dir."
+   echo "   -t <openmp-threads>      Number of OpenMP threads"
+   echo ""
+   echo ""
+}
+
+
+   # Read shellscript options
+while  getopts  :b:c:n:p:s:t:h  option
+do
+  case  $option  in
+      (b)   build_config=$OPTARG;;
+      (c)   run_config=$OPTARG;;
+      (n)   mpi_ranks_per_node=$OPTARG;;
+      (p)   mpi_ranks=$OPTARG;;
+      (s)   test_case=$OPTARG;;
+      (t)   openmp_threads=$OPTARG;;
+      (h)   print_help
+            exit 0;;
+      (\?)  echo "Unknown option -$OPTARG"
+            print_help
+            exit 1;;
+  esac
+done
+
+if [[ ${build_config} == "unknown" ]]
+then
+   echo "Missing option -b <build-config>"
+   print_help
+   exit 1
+fi
+
+if [[ ${run_config} == "unknown" ]]
+then
+   echo "Missing option -c <run-config>"
+   print_help
+   exit 1
+fi
+
+if [[ ${test_case} == "unknown" ]]
+then
+   echo "Missing option -s <test-case>"
+   print_help
+   exit 1
+fi
+
+build_dir=${working_dir}/BUILD_${build_config}
+
+if [[ ! -d ${build_dir} ]]
+then
+   echo "+++ ERROR: No build for configuration ${build_config} exists! "
+   echo "           Please run \"palm_simple_install -b ${build_config}\""
+   echo "           or specify a different build that this run should be based on"
+   exit 1
+fi
+
+   # Check, if include file exists
+run_config_file=${trunk_dir}/INSTALL/RUN.cmd.${run_config}
+if [[ ! -f ${run_config_file} ]]
+then
+   echo "+++ ERROR: no such run command file:"
+   echo "    \"${run_config_file}\""
+   exit 1
+fi
+
+   # Find out the global svn revision number
+global_revision=$(svnversion ${trunk_dir}  2>/dev/null)
+global_revision="Rev: $global_revision"
+
+
+   # Generate unique directory/files for this run
+#timedate="$(date +%F_%H:%M:%S)"
+suffix=${build_config}_${run_config}_${test_case}_${mpi_ranks}_${mpi_ranks_per_node}_${openmp_threads}
+execution_dir=${working_dir}/RUN_${suffix}
+
+if [[ ! -d ${execution_dir} ]]
+then
+   mkdir -p ${execution_dir}
+   echo "*** PALM running in directory ${execution_dir}"
+else
+   echo "+++ ERROR: ${execution_dir} exists\!   Must be unique.  Exiting."
+   exit 1
+fi
+
+
+# Check if palm has been installed and copy executable into the run
+# directory
+if [[ ! -f ${build_dir}/palm ]]
+then
+   echo "+++ ERROR: palm executable does not exist."
+   echo "           Please run \"palm_simple_install\"."
+   exit 1
+else
+   cp  ${build_dir}/palm  ${execution_dir}/palm
+fi
+
+
+# Check, if parameter file exists and copy into the run directory
+if [[ ! -f ${trunk_dir}/INSTALL/${test_case}_p3d ]]
+then
+   echo "+++ ERROR: parameter file"
+   echo "           \"${trunk_dir}/INSTALL/${test_case}_p3d\""
+   echo "           does not exist."
+   exit 1
+else
+   cp  ${trunk_dir}/INSTALL/${test_case}_p3d  ${execution_dir}/PARIN
+fi
+
+
+
+
+# Create NAMELIST file containing environment values needed by palm
+cat  >  ${execution_dir}/ENVPAR  <<  EOF
+&envpar  run_identifier = '${test_case}',
+         host = 'localhost',
+         revision = '${global_revision}',
+         tasks_per_node = ${mpi_ranks_per_node},
+         maximum_parallel_io_streams = ${mpi_ranks_per_node},
+         batch_job = .TRUE.,
+         write_binary = .FALSE.,
+         maximum_cpu_time_allowed = ${cpumax}.,
+         local_dvrserver_running = .FALSE.,
+/
+EOF
+
+
+# Coupled runs cannot be carried out with this simple run script
+echo "no_coupling"  >  ${execution_dir}/runfile_atmos
+
+
+# Generate hostfile (if neccessary)
+(( ii = 1 ))
+while (( ii <= $mpi_ranks ))
+do
+   echo  $localhost_realname  >>  ${execution_dir}/hostfile
+   (( ii = ii + 1 ))
+done
+
+
+# Switch to run directory
+cd  ${execution_dir}
+
+# Start palm run
+echo "*** PALM will be executed with configuration: ${run_config}"
+echo "       MPI ranks in total: $mpi_ranks"
+echo "       MPI ranks per node: $mpi_ranks_per_node"
+echo "       OpenMP threads:     $openmp_threads"
+
+# execute according to the run command file
+source ${run_config_file}
+
+echo "*** PALM execution finished. Results can be found in:"
+echo "    \"${execution_dir}\""
+exit 0
