Index: palm/trunk/SCRIPTS/palmbuild
===================================================================
--- palm/trunk/SCRIPTS/palmbuild	(revision 2500)
+++ palm/trunk/SCRIPTS/palmbuild	(revision 2506)
@@ -27,4 +27,10 @@
 # -----------------
 # $Id$
+# option -V added to check for an existing SOURCES_FOR_RUN_... folder
+# host configuration added to SOURCES_FOR_RUN_... folder name
+# SOURCES_FOR_RUN_... folder is deleted in case of compilation errors
+# host_identifier renamed host_configuration
+# 
+# 2500 2017-09-25 11:10:03Z raasch
 # bugfix for r2492
 # 
@@ -52,5 +58,5 @@
  column1=""
  column2=""
- host_identifier=default
+ host_configuration=default
  locat=normal
  makefile=""
@@ -62,4 +68,5 @@
  ssh_key=""
  suf=f90
+ use_existing_sources_folder=false
  version="palmbuild  1.0  Rev$Rev: 2316 $"
  working_directory=`pwd`
@@ -69,5 +76,6 @@
     # ERROR HANDLING
     # IN CASE OF EXIT:
- trap 'if [[ $locat != normal ]]
+ trap 'rm -rf  ${source_path}/${host_configuration}_last_make_protocol
+       if [[ $locat != normal ]]
        then
           printf "\n\n +++ palmbuild killed \n\n"
@@ -77,5 +85,4 @@
           exit 0
        fi
-       rm  ${source_path}/${host_identifier}_last_make_protocol
       ' exit
 
@@ -83,5 +90,5 @@
     # IN CASE OF TERMINAL-BREAK:
  trap 'printf "\n\n +++ palmbuild killed by \"^C\" \n\n"
-       rm  ${source_path}/${host_identifier}_last_make_protocol
+       rm  ${source_path}/${host_configuration}_last_make_protocol
        exit
       ' 2
@@ -90,13 +97,14 @@
 
     # READ SHELLSCRIPT-OPTIONS
- while  getopts  :d:h:m:s:S:uv  option
+ while  getopts  :d:h:m:s:S:uvV  option
  do
    case  $option  in
        (d)   fname=$OPTARG;;
-       (h)   host_identifier=$OPTARG;;
+       (h)   host_configuration=$OPTARG;;
        (m)   makefile=$OPTARG;;
        (s)   suf=$OPTARG;;
        (S)   source_list="$OPTARG";;
        (v)   silent=true;;
+       (V)   use_existing_sources_folder=true;;
        (\?)  printf "\n  +++ unknown option $OPTARG \n";
              locat=parameter; exit;;
@@ -105,6 +113,7 @@
 
 
-    # BUILD THE CONFIGURATION-FILE NAME
- config_file=.palm.config.$host_identifier
+    # BUILD THE CONFIGURATION-FILE NAME AND THE SOURCES_FOR_RUN-FOLDER NAME
+ config_file=.palm.config.$host_configuration
+ sources_for_run_catalog=SOURCES_FOR_RUN_${host_configuration}_$fname
 
 
@@ -277,9 +286,9 @@
 
     line=`grep %base_directory $config_file`
-    make_depository=`echo $line | cut -d" " -s -f2`/MAKE_DEPOSITORY_${host_identifier}
+    make_depository=`echo $line | cut -d" " -s -f2`/MAKE_DEPOSITORY_${host_configuration}
 
  else
 
-    make_depository=${base_directory}/MAKE_DEPOSITORY_${host_identifier}
+    make_depository=${base_directory}/MAKE_DEPOSITORY_${host_configuration}
 
  fi
@@ -342,5 +351,5 @@
 
     # GET CONFIRMATION TO CONTINUE
- printf "\n  *** update will be made for host \"$host_identifier\" "
+ printf "\n  *** update will be made for host configuration \"$host_configuration\" "
 
 
@@ -367,5 +376,5 @@
     if [[ "$remote_ip" != "" ]]
     then
-       column2="$host_identifier"
+       column2="$host_configuration"
        printf "| %-20s%-50s | \n" "host identifier:" "$column2"
        printf "|                                                                        | \n"
@@ -373,5 +382,5 @@
        printf "| %-20s%-50s | \n" "remote depository:" "$column2"
     else
-       column2="$host_identifier"
+       column2="$host_configuration"
        printf "| %-20s%-50s | \n" "host identifier:" "$column2"
        printf "|                                                                        | \n"
@@ -518,10 +527,10 @@
           echo "  *** creating utilities on remote host"
           make_call_string="make  -f Makefile_utilities  $make_options  F90=$compiler_name  F90_SER=$compiler_name_ser  COPT=\"$cpp_options\"  F90FLAGS=\"$compiler_options\"  LDFLAGS=\"$linker_options\" "
-          echo "$login_init_cmd $module_commands cd ${make_depository}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1 | tee ${host_identifier}_last_make_protocol
-
-          if [[ $(grep -c MAKE_ERROR ${host_identifier}_last_make_protocol) != 0 ]]
+          echo "$login_init_cmd $module_commands cd ${make_depository}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1 | tee ${host_configuration}_last_make_protocol
+
+          if [[ $(grep -c MAKE_ERROR ${host_configuration}_last_make_protocol) != 0 ]]
           then
              printf "\a\n  +++ error(s) occurred during compiling or linking of utilities"
-             printf "\n      for host \"$host_identifier\" "
+             printf "\n      for host configuration \"$host_configuration\" "
              if [[ $silent = false ]]
              then
@@ -534,5 +543,5 @@
                    if [[ "$answer" = l ]]
                    then
-                      more ${host_identifier}_last_make_protocol
+                      more ${host_configuration}_last_make_protocol
                    fi
                 done
@@ -555,9 +564,9 @@
           echo "  *** compile PALM sources on remote host"
           make_call_string="make  $make_options  PROG=$program_name  F90=$compiler_name  COPT=\"$cpp_options\"  F90FLAGS=\"$compiler_options\"  LDFLAGS=\"$linker_options\" "
-          echo "$login_init_cmd $module_commands cd ${make_depository}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1 | tee ${host_identifier}_last_make_protocol
-
-          if [[ $(grep -c MAKE_ERROR ${host_identifier}_last_make_protocol) != 0 ]]
-          then
-             printf "\a\n  +++ error(s) occurred during compiling or linking for host \"$host_identifier\" "
+          echo "$login_init_cmd $module_commands cd ${make_depository}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1 | tee ${host_configuration}_last_make_protocol
+
+          if [[ $(grep -c MAKE_ERROR ${host_configuration}_last_make_protocol) != 0 ]]
+          then
+             printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$host_configuration\" "
              if [[ $silent = false ]]
              then
@@ -570,5 +579,5 @@
                    if [[ "$answer" = l ]]
                    then
-                      more ${host_identifier}_last_make_protocol
+                      more ${host_configuration}_last_make_protocol
                    fi
                 done
@@ -596,35 +605,26 @@
              # FIRST CHECK, IF COMPILED SOURCES FOR THIS RUN IDENTIFIER EXISTS
              # AND ASK, IF THEY SHALL BE USED
-          echo  "[[ -d $fast_io_catalog/SOURCES_FOR_RUN_$fname ]]  &&  echo sources for run found" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1  >  ${host_identifier}_last_make_protocol
-          if [[ $(grep -c "sources for run found" ${host_identifier}_last_make_protocol) != 0 ]]
+          echo  "[[ -d ${fast_io_catalog}/${sources_for_run_catalog} ]]  &&  echo sources for run found" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1  >  ${host_configuration}_last_make_protocol
+          if [[ $(grep -c "sources for run found" ${host_configuration}_last_make_protocol) != 0  &&  $use_existing_sources_folder = true ]]
           then
              printf "\a\n  *** compiled sources for run \"$fname\" found on remote host in folder"
-             printf "\n      $fast_io_catalog/SOURCES_FOR_RUN_$fname"  
-             answer=dummy
-             printf "\n\n"
-             while [[ "$answer" != y  &&  "$answer" != n ]]
-             do
-                printf "  >>> shall they be used (y/n) ? "
-                read  answer
-             done
-             if [[ $answer = y ]]
-             then
-                exit
-             fi
+             printf "\n      ${fast_io_catalog}/${sources_for_run_catalog}"
+             printf "\n      will be used!"
+             exit
           fi
 
              # COPY MAKE DEPOSITORY ON REMOTE MACHINE TO SOURCES_FOR_RUN_...
-          printf "\n  *** copy MAKE_DEPOSITORY_${host_identifier} on remote host to SOURCES_FOR_RUN_$fname \n"
-          echo  "rm -rf $fast_io_catalog/SOURCES_FOR_RUN_$fname; mkdir -p $fast_io_catalog/SOURCES_FOR_RUN_$fname; cp ${make_depository}/${program_name}_current_version.tar  $fast_io_catalog/SOURCES_FOR_RUN_$fname; cd $fast_io_catalog/SOURCES_FOR_RUN_$fname; tar xf ${program_name}_current_version.tar"  |  ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  2>&1
+          printf "\n  *** copy MAKE_DEPOSITORY_${host_configuration} on remote host to $sources_for_run_catalog \n"
+          echo  "rm -rf ${fast_io_catalog}/${sources_for_run_catalog}; mkdir -p ${fast_io_catalog}/${sources_for_run_catalog}; cp ${make_depository}/${program_name}_current_version.tar  ${fast_io_catalog}/${sources_for_run_catalog}; cd ${fast_io_catalog}/${sources_for_run_catalog}; tar xf ${program_name}_current_version.tar"  |  ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  2>&1
 
 
              # COPY CONTENTS OF SOURCES_FOR_RUN_... TO SOURCES_FOR_RUN_... ON THE REMOTE MACHINE
-          printf "\n  *** copy $base_directory/SOURCES_FOR_RUN_$fname"
-          printf "\n      to SOURCES_FOR_RUN_$fname on remote host \n"
-          scp  -q  $ssh_key  $base_directory/SOURCES_FOR_RUN_$fname/{*,.[!.]*}  ${remote_username}@${remote_ip}:${fast_io_catalog}/SOURCES_FOR_RUN_$fname
+          printf "\n  *** copy ${base_directory}/${sources_for_run_catalog}"
+          printf "\n      to $sources_for_run_catalog on remote host \n"
+          scp  -q  $ssh_key  ${base_directory}/${sources_for_run_catalog}/{*,.[!.]*}  ${remote_username}@${remote_ip}:${fast_io_catalog}/${sources_for_run_catalog}
 
 
              # CREATE EXECUTABLE FROM THE NEW/MODIFIED SOURCE FILES, IF THERE ARE ANY
-          if [[ $(ls -1 $base_directory/SOURCES_FOR_RUN_$fname/ | grep -c .$suf) != 0 ]]
+          if [[ $(ls -1 ${base_directory}/${sources_for_run_catalog}/ | grep -c .$suf) != 0 ]]
           then
 
@@ -633,9 +633,9 @@
              [[ "$module_commands" != "" ]]  &&  module_commands=${module_commands}";"
              echo "  *** execute \"make\" on remote host"
-             echo "$login_init_cmd $module_commands cd ${fast_io_catalog}/SOURCES_FOR_RUN_$fname; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1 | tee ${host_identifier}_last_make_protocol
-
-             if [[ $(grep -c MAKE_ERROR ${host_identifier}_last_make_protocol) != 0 ]]
+             echo "$login_init_cmd $module_commands cd ${fast_io_catalog}/${sources_for_run_catalog}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1 | tee ${host_configuration}_last_make_protocol
+
+             if [[ $(grep -c MAKE_ERROR ${host_configuration}_last_make_protocol) != 0 ]]
              then
-                printf "\a\n  +++ error(s) occurred during compiling or linking for host \"$host_identifier\" "
+                printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$host_configuration\" "
                 if [[ $silent = false ]]
                 then
@@ -648,13 +648,15 @@
                       if [[ "$answer" = l ]]
                       then
-                         more ${host_identifier}_last_make_protocol
+                         more ${host_configuration}_last_make_protocol
                       fi
                    done
                    if [[ $answer = k ]]
                    then
+                      echo "rm -rf ${fast_io_catalog}/${sources_for_run_catalog}" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1
                       locat=user_abort; exit
                    fi
                 else
                       # ABORT ANYWAY
+                   echo "rm -rf ${fast_io_catalog}/${sources_for_run_catalog}" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1
                    locat=user_abort; exit
                 fi
@@ -669,5 +671,5 @@
        fi
 
-       rm -rf  ${host_identifier}_last_make_protocol
+       rm -rf  ${source_path}/${host_configuration}_last_make_protocol
 
 
@@ -729,9 +731,9 @@
           echo "  *** compile PALM sources on local host"
 
-          make  $make_options  PROG=$program_name  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$compiler_options"  LDFLAGS="$linker_options"  2>&1 | tee ${host_identifier}_last_make_protocol
+          make  $make_options  PROG=$program_name  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$compiler_options"  LDFLAGS="$linker_options"  2>&1 | tee ${host_configuration}_last_make_protocol
 
           if [[ $? != 0 ]]
           then
-             printf "\a\n  +++ error(s) occurred during compiling or linking for host \"$host_identifier\" "
+             printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$host_configuration\" "
              if [[ $silent = false ]]
              then
@@ -744,5 +746,5 @@
                    if [[ "$answer" = l ]]
                    then
-                      more ${host_identifier}_last_make_protocol
+                      more ${host_configuration}_last_make_protocol
                    fi
                 done
@@ -770,19 +772,10 @@
              # FIRST CHECK, IF COMPILED SOURCES FOR THIS RUN IDENTIFIER EXISTS
              # AND ASK, IF THEY SHALL BE USED
-          if [[ -d $fast_io_catalog/SOURCES_FOR_RUN_$fname ]]
+          if [[ -d ${fast_io_catalog}/${sources_for_run_catalog}  &&  $use_existing_sources_folder = true ]]
           then
              printf "\a\n  *** compiled sources for run \"$fname\" found on local host in folder"
-             printf "\n      $fast_io_catalog/SOURCES_FOR_RUN_$fname"  
-             answer=dummy
-             printf "\n\n"
-             while [[ "$answer" != y  &&  "$answer" != n ]]
-             do
-                printf "  >>> shall they be used (y/n) ? "
-                read  answer
-             done
-             if [[ $answer = y ]]
-             then
-                exit
-             fi
+             printf "\n      ${fast_io_catalog}/${sources_for_run_catalog}"
+             printf "\n      will be used!"
+             exit
           fi
 
@@ -792,5 +785,5 @@
              printf "\n  +++ directory for local make depository:"
              printf "\n           $make_depository"
-             printf "\n      not found. Please run \"palmbuild -h $host_identifier\" "
+             printf "\n      not found. Please run \"palmbuild -h $host_configuration\" "
              locat=make_depository; exit
           fi
@@ -798,10 +791,10 @@
 
              # COPY MAKE DEPOSITORY ON LOCAL MACHINE TO SOURCES_FOR_RUN_...
-          printf "\n  *** copy MAKE_DEPOSITORY_${host_identifier} on local host to "
-          printf "\n      $fast_io_catalog/SOURCES_FOR_RUN_$fname \n"
-          rm -rf $fast_io_catalog/SOURCES_FOR_RUN_$fname
-          mkdir -p $fast_io_catalog/SOURCES_FOR_RUN_$fname
-          cp ${make_depository}/${program_name}_current_version.tar  $fast_io_catalog/SOURCES_FOR_RUN_$fname
-          cd $fast_io_catalog/SOURCES_FOR_RUN_$fname
+          printf "\n  *** copy MAKE_DEPOSITORY_${host_configuration} on local host to "
+          printf "\n      ${fast_io_catalog}/${sources_for_run_catalog} \n"
+          rm -rf ${fast_io_catalog}/${sources_for_run_catalog}
+          mkdir -p ${fast_io_catalog}/${sources_for_run_catalog}
+          cp ${make_depository}/${program_name}_current_version.tar  ${fast_io_catalog}/${sources_for_run_catalog}
+          cd $fast_io_catalog/${sources_for_run_catalog}
           tar xf ${program_name}_current_version.tar
 
@@ -809,11 +802,11 @@
              # COPY CONTENTS OF SOURCES_FOR_RUN_... TO SOURCES_FOR_RUN_...
              # IN THE FAST_IO_CATALOG ON THE LOCAL MACHINE
-          printf "\n  *** copy $base_directory/SOURCES_FOR_RUN_$fname to"
-          printf "\n      $fast_io_catalog/SOURCES_FOR_RUN_$fname on local host \n"
-          cp  $base_directory/SOURCES_FOR_RUN_$fname/{*,.[!.]*}  ${fast_io_catalog}/SOURCES_FOR_RUN_$fname
+          printf "\n  *** copy ${base_directory}/${sources_for_run_catalog} to"
+          printf "\n      ${fast_io_catalog}/${sources_for_run_catalog} on local host \n"
+          cp  ${base_directory}/${sources_for_run_catalog}/{*,.[!.]*}  ${fast_io_catalog}/${sources_for_run_catalog}
 
 
              # CREATE EXECUTABLE FROM THE NEW/MODIFIED SOURCE FILES, IF THERE ARE ANY
-          if [[ $(ls -1 $base_directory/SOURCES_FOR_RUN_$fname/ | grep -c .$suf) != 0 ]]
+          if [[ $(ls -1 ${base_directory}/${sources_for_run_catalog}/ | grep -c .$suf) != 0 ]]
           then
 
@@ -827,5 +820,5 @@
              then
 
-                printf "\a\n  +++ error(s) occurred during compiling or linking for host \"$host_identifier\" "
+                printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$host_configuration\" "
                 if [[ $silent = false ]]
                 then
@@ -834,13 +827,15 @@
                    while [[ "$answer" != c  &&  "$answer" != k ]]
                    do
-                      printf "  >>> continue / list errors / kill palmbuild (c/k) ? "
+                      printf "  >>> continue / kill palmbuild (c/k) ? "
                       read  answer
                    done
                    if [[ $answer = k ]]
                    then
+                      rm -rf ${fast_io_catalog}/${sources_for_run_catalog}
                       locat=user_abort; exit
                    fi
                 else
                       # ABORT ANYWAY
+                   rm -rf ${fast_io_catalog}/${sources_for_run_catalog}
                    locat=user_abort; exit
                 fi
