Index: palm/trunk/SCRIPTS/batch_scp
===================================================================
--- palm/trunk/SCRIPTS/batch_scp	(revision 2261)
+++ palm/trunk/SCRIPTS/batch_scp	(revision 2600)
@@ -27,4 +27,8 @@
 # -----------------
 # $Id$
+# cycle numbers made three digits wide
+# host depending code completely removed
+# 
+# 2261 2017-06-08 14:25:57Z raasch
 # option usecycle added, script is running under bash now,
 # filenames are allowed to contain arbitrary number of dots "."
@@ -78,4 +82,5 @@
  catalog_copy=false
  check=false
+ cyclestring=""
  delete=false
  errfile=batch_scp.errfile.$random
@@ -83,5 +88,4 @@
  get=false
  local_host=`hostname`
- local_user=$USER
  local_wdir=`pwd`
  locat=normal
@@ -93,5 +97,4 @@
  silent=false
  transfermode=binary
- zyklusnr=""
  typeset -i iii icycle maxcycle=0 usecycle wait=0
 
@@ -261,14 +264,4 @@
 
 
-   # Using absolute paths for ssh on lcflow (nodes "cfd_*") as the paths of the
-   # job scheduler have changed
- if [[ $(echo $local_host | cut -c1-3) = "cfd" ]]
- then
-   SSH_BIN=/usr/bin/ssh
- else
-   SSH_BIN=ssh
- fi
-
-
     # PRUEFEN, OB LOKALE DATEI/LOKALES VERZEICHNIS VORHANDEN BZW. NICHT VORHANDEN
  if [[ $get = false ]]
@@ -326,10 +319,5 @@
 
     # VERZEICHNISLSTE DES ZIELRECHNERS ERSTELLEN
- if [[ $(echo $local_host | cut -c1-4) = gaia ]]
- then
-    ssh $SSH_PORTOPT $local_user@gaiad "ssh $SSH_PORTOPT $1 -l $remote_user \"unset LANG; cd $3; ls -1; echo '*** list complete'\" "  > $filelist  2>&1
- else
-    $SSH_BIN $SSH_PORTOPT $1 -l $remote_user "unset LANG; cd $3; ls -1; echo '*** list complete'" > $filelist  2>&1
- fi
+ ssh $SSH_PORTOPT $1 -l $remote_user "unset LANG; cd $3; ls -1; echo '*** list complete'" > $filelist  2>&1
  ssh_status=$?
 
@@ -430,58 +418,17 @@
           fi
 
-
-#          text=$(echo $zeile | cut -f1 -d".")
-#
-#          if [[ "$text" = "$4" ]]
-#          then
-#             found=true
-#             cycle=$(echo $zeile | cut -f2 -d".")
-#             if [[ "$cycle" = "$text" ]]
-#             then
-#                (( icycle = 0 ))
-#             else
-#
-#                   # PRUEFEN, OB CYCLE EINE ZAHL IST
-#                (( iii = 1 ))
-#                character=`echo $cycle | cut -c$iii`
-#                character_found=false
-#                while [[ "$character" != ""  &&  $character_found = false ]]
-#                do
-#                   case  $character  in
-#                      (0|1|2|3|4|5|6|7|8|9)  true;;
-#                      (*)  character_found=true
-#                   esac
-#                   (( iii = iii + 1 ))
-#                   character=`echo $cycle | cut -c$iii`
-#                done
-#
-#                if [[ $character_found = false ]]
-#                then
-#                   (( icycle = $cycle ))
-#                fi
-#             fi >|$errfile 2>&1    # AUSGABE FEHLER AUF ERRFILE WENN CYCLE NICHTNUMERISCH
-#
-#
-#                # INFORMATIVE AUSGABE, WENN DATEI NICHTNUMERISCHE EXTENSION HAT
-#                # if [[ $(cat $errfile | grep -c "bad number") != 0 ]]
-#             if [[ $character_found = true ]]
-#             then
-#                if [[ $cycle != "$5" ]]
-#                then
-#                   printf "  +++ file \"$text\" has non-numerical extension \".$cycle\" \n"
-#                   locat=file; exit
-#                else
-#                   if [[ $silent = false ]]
-#                   then
-#                      printf "  >>> file \"$text\" has non-numerical extension \".$cycle\" \n"
-#                   fi
-#                fi
-#             fi
-
-             if (( icycle > maxcycle ))
-             then
-                (( maxcycle = icycle ))
-             fi
-#          fi
+          if (( icycle > maxcycle ))
+          then
+             (( maxcycle = icycle ))
+
+                 # FOR COMPATIBILITY REASONS WITH OLDER VERSIONS
+                 # CHECK IF CYCLE NUMBER CONTAINS LEADING ZEROS
+              if [[ $(echo $cycle | cut -c1) = 0 ]]
+              then
+                 leading_zero=true
+              else
+                 leading_zero=false
+              fi
+          fi
 
        else
@@ -504,4 +451,5 @@
           then
              (( maxcycle = maxcycle + 1 ))
+
                 # TRY TO USE FIXED CYCLE NUMBER, IF GIVEN AS OPTION
              if [[ "$usecycle" != "" ]]
@@ -514,11 +462,11 @@
                 fi
              fi
-             zyklusnr=".$maxcycle"
+             cyclestring=`printf ".%03d" $maxcycle`
           else
              if (( maxcycle == 0 ))
              then
-                zyklusnr=""
+                cyclestring=""
              else
-                zyklusnr=".$maxcycle"
+                cyclestring=`printf ".%03d" $maxcycle`
              fi
           fi
@@ -536,11 +484,18 @@
           if (( maxcycle == 0 ))
           then
-             zyklusnr=""
+             cyclestring=""
           else
-             zyklusnr=".$maxcycle"
+
+                # MAKE CYCLE NUMBER THREE DIGITS WIDE
+             if [[ $leading_zero = true ]]
+             then
+                cyclestring=`printf ".%03d" $maxcycle`
+             else
+                cyclestring=.$maxcycle
+             fi
              (( maxcycle = 0 ))
           fi
        else
-          zyklusnr=""
+          cyclestring=""
        fi
     fi
@@ -551,7 +506,7 @@
     then
        (( maxcycle = usecycle ))
-       zyklusnr=".$usecycle"
+       cyclestring=`printf ".%03d" $usecycle`
     else
-       zyklusnr=""
+       cyclestring=""
     fi
 
@@ -571,5 +526,5 @@
  if [[ $make_catalog = force ]]
  then
-    zyklusnr=""
+    cyclestring=""
     (( maxcycle = 0 ))
  fi
@@ -580,5 +535,5 @@
  if [[ $print_local_filename = true ]]
  then
-    printf "$4$zyklusnr\n"
+    printf "$4$cyclestring\n"
     rm -r $filelist
     exit
@@ -591,5 +546,5 @@
  if [[ "$5" != ""  &&  $get = false ]]
  then
-    zyklusnr=${zyklusnr}.$5
+    cyclestring=${cyclestring}.$5
  fi
 
@@ -599,11 +554,8 @@
  if [[ $catalog_copy = true  &&  $get = true ]]
  then
+
     rm -rf $filelist
-    if [[ $(echo $local_host | cut -c1-4) = gaia ]]
-    then
-       ssh $SSH_PORTOPT $local_user@gaiad "ssh $1 -l $remote_user \"cd $3\" " > $filelist
-    else
-       $SSH_BIN $SSH_PORTOPT $1 -l $remote_user "cd $3" > $filelist
-    fi
+    ssh $SSH_PORTOPT $1 -l $remote_user "cd $3" > $filelist
+
     if [[ $? != 0 ]]
     then
@@ -616,4 +568,5 @@
        locat=directory; exit
     fi
+
  fi
 
@@ -630,12 +583,5 @@
 
 
-    # Auf IBM-Rechnern (HLRN) Tilde aus Katalognamen entfernen, da scp
-    # diese nicht versteht
  catalog_name=$3
- if [[ $(hostname | cut -c1-4) = hreg  ||  $(hostname | cut -c1-4) = breg ]]
- then
-    catalog_name=${catalog_name#"~/"}
-    catalog_name=${catalog_name#"~"}
- fi
  [[ "$catalog_name" != "" ]]  &&  catalog_name=${catalog_name}/
 
@@ -648,27 +594,10 @@
        if [[ $append = false ]]
        then
-          if [[ $(echo $local_host | cut -c1-2) = cs ]]
-          then
-             if [[ $catalog_copy = false ]]
-             then
-                scp $PORTOPT -p -q -v $2 $remote_user@$1:$catalog_name$4$zyklusnr
-             else
-                scp $PORTOPT -p -r -q -v $2 $remote_user@$1:$catalog_name$4$zyklusnr
-             fi
-          elif [[ $(echo $local_host | cut -c1-4) = gaia ]]
-          then
-             if [[ $catalog_copy = false ]]
-             then
-                ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr"  > /dev/null
-             else
-                ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p -r $2 $remote_user@$1:$catalog_name$4$zyklusnr"  > /dev/null
-             fi
+
+          if [[ $catalog_copy = false ]]
+          then
+             scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$cyclestring  > /dev/null
           else
-             if [[ $catalog_copy = false ]]
-             then
-                scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
-             else
-                scp $PORTOPT -p -r $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
-             fi
+             scp $PORTOPT -p -r $2 $remote_user@$1:$catalog_name$4$cyclestring  > /dev/null
           fi
           scp_status=$?
@@ -681,10 +610,5 @@
              local_size=`echo $local_size | cut -d" " -f5`
 
-             if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
-             then
-                remote_size=`ssh $SSH_PORTOPT $local_user@gaiad "ssh $SSH_PORTOPT $1 -l $remote_user \"ls -al $catalog_name$4$zyklusnr\" "`
-             else
-                remote_size=`$SSH_BIN $SSH_PORTOPT $1 -l $remote_user "ls -al $catalog_name$4$zyklusnr"`
-             fi
+             remote_size=`ssh $SSH_PORTOPT $1 -l $remote_user "ls -al $catalog_name$4$cyclestring"`
              remote_size=`echo $remote_size | cut -d" " -f5`
 
@@ -697,11 +621,9 @@
              fi
           fi
-       else
-          if [[ $(echo $local_host | cut -c1-4) = gaia ]]
-          then
-             ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $2 $remote_user@$1:${catalog_name}batch_scp_append_file.$random"  > /dev/null
-          else
-             scp $PORTOPT -p $2 $remote_user@$1:${catalog_name}batch_scp_append_file.$random  > /dev/null
-          fi
+
+       else
+
+          scp $PORTOPT -p $2 $remote_user@$1:${catalog_name}batch_scp_append_file.$random  > /dev/null
+
           if [[ $? != 0 ]]
           then
@@ -711,10 +633,5 @@
              local_size=`echo $local_size | cut -d" " -f5`
 
-             if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
-             then
-                remote_size=`ssh $SSH_PORTOPT $local_user@gaiad "ssh $SSH_PORTOPT $1 -l $remote_user \"ls -al ${catalog_name}batch_scp_append_file.$random\" "`
-             else
-                remote_size=`$SSH_BIN $SSH_PORTOPT $1 -l $remote_user "ls -al ${catalog_name}batch_scp_append_file.$random"`
-             fi
+             remote_size=`ssh $SSH_PORTOPT $1 -l $remote_user "ls -al ${catalog_name}batch_scp_append_file.$random"`
              remote_size=`echo $remote_size | cut -d" " -f5`
 
@@ -730,10 +647,6 @@
           rm  $filelist
 
-          if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
-          then
-             ssh $SSH_PORTOPT $local_user@gaiad "ssh $SSH_PORTOPT $1 -l $remote_user \"cd $3; cat batch_scp_append_file.$random >> $4$zyklusnr; rm batch_scp_append_file.$random; echo '*** append complete'\" " > $filelist
-          else
-             $SSH_BIN $SSH_PORTOPT $1 -l $remote_user "cd $3; cat batch_scp_append_file.$random >> $4$zyklusnr; rm batch_scp_append_file.$random; echo '*** append complete'" > $filelist
-          fi
+          ssh $SSH_PORTOPT $1 -l $remote_user "cd $3; cat batch_scp_append_file.$random >> $4$cyclestring; rm batch_scp_append_file.$random; echo '*** append complete'" > $filelist
+
           if [[ $? != 0 ]]
           then
@@ -749,21 +662,16 @@
           fi
        fi
+
     else
-       if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
-       then
-          ssh $SSH_PORTOPT $local_user@gaiad "ssh $1 -l $remote_user \"mkdir -p $3\" "
-       else
-          $SSH_BIN $SSH_PORTOPT $1 -l $remote_user "mkdir -p $3"
-       fi
+
+       ssh $SSH_PORTOPT $1 -l $remote_user "mkdir -p $3"
+
        if [[ $? != 0 ]]
        then
           locat=ssh_failed_4; exit
        fi
-       if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
-       then
-          ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr"  > /dev/null
-       else
-          scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
-       fi
+
+       scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$cyclestring  > /dev/null
+
        if [[ $? != 0 ]]
        then
@@ -784,10 +692,6 @@
        else
 
-          if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
-          then
-             ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $remote_user@$1:$catalog_name$4$zyklusnr $2"  > /dev/null
-          else
-             scp $PORTOPT -p $remote_user@$1:$catalog_name$4$zyklusnr $2  > /dev/null
-          fi
+          scp $PORTOPT -p $remote_user@$1:$catalog_name$4$cyclestring $2  > /dev/null
+
           if [[ $? != 0 ]]
           then
@@ -796,4 +700,5 @@
 
        fi
+
     else
 
@@ -801,11 +706,6 @@
        locat=unavailable_feature; exit
 
-#       ftp -i $1 << %END%  > /dev/null
-#$transfermode
-#cd $3
-#mget *
-#quit
-#%END%
-    fi
+    fi
+
  fi
 
@@ -837,10 +737,10 @@
           if [[ $catalog_copy = false ]]
           then
-             printf "      new file has cycle number $maxcycle \n"
+             printf "      new file has cycle number .%03d \n" $maxcycle
           else
-             printf "      new catalog has cycle number $maxcycle \n"
-          fi
-       else
-          printf "      append to cycle number $maxcycle \n"
+             printf "      new catalog has cycle number .%03d \n" $maxcycle
+          fi
+       else
+          printf "      append to cycle number .%03d \n" $maxcycle
        fi
     fi
