Index: palm/trunk/SCRIPTS/palmrun
===================================================================
--- palm/trunk/SCRIPTS/palmrun	(revision 2609)
+++ palm/trunk/SCRIPTS/palmrun	(revision 2610)
@@ -27,7 +27,10 @@
 # -----------------
 # $Id$
+# use of wildcards in file connection statements enabled
+# 
+# 2605 2017-11-09 15:31:46Z raasch
 # in case of remote jobs, input files with "job" or "jobopt" (new) attribute
 # will not be sent with the job file any more, but copied into the
-# SOURCES_FOR_RUN... folder on the remote host, before he job is submitted
+# SOURCES_FOR_RUN... folder on the remote host, before the job is submitted
 # 
 # 2600 2017-11-01 14:11:20Z raasch
@@ -85,5 +88,6 @@
  set +o noclobber    # EXISTING FILES ARE ALLOWED TO BE OVERWRITTEN
 
- typeset -i  ibd=0 ibdt=0 iec=0 iic=0 iin=0 ioc=0 iout=0
+ typeset -i  ibd=0 ibdt=0 iec=0 iic=0 iin=0 ioc=0 iout=0 nr_of_input_files=0
+ typeset -i  nr_of_output_files=0
  typeset -x -i  memory=0   # HAS TO BE EXPORTED HERE, OTHERWISE AN UNKNOWN SIDE
                            # SIDE EFFECT MAY CAUSE DATA LOSS WHEN GETOPTS IS READING THE
@@ -556,5 +560,5 @@
           # LOCALLY REQUIRED ON THAT MACHINE (I.E. s2b = loc), THE FILE CONNECTION
           # IS NOT CHECKED AND STORED.
-       IFSALT="$IFS"; IFS="$IFS:"
+       IFSALT="$IFS"; IFS="$IFS:"      # ADD ":" AS FIELD SEPARATOR
        if [[ "$s2a" = in  &&  ! ( $create_remote_batch_job = true  &&  ( "$s2b" = loc  ||  "$s2b" = locopt ) ) ]]
        then
@@ -570,7 +574,6 @@
           then
              (( iin = iin + 1 ))
-             localin[$iin]=$s1; transin[$iin]=$s2b; actionin[$iin]=$s2c;
-             typein[$iin]=$s3; pathin[$iin]=$s4; endin[$iin]=$s5;
-             extin[$iin]=$s6
+             localin_pre[$iin]=$s1; transin_pre[$iin]=$s2b; actionin_pre[$iin]=$s2c;
+             pathin_pre[$iin]=$s4; endin_pre[$iin]=$s5; extin_pre[$iin]=$s6
 
                 # FILES WITH JOB-ATTRIBUTE ARE STORED IN THE SOURCES_FOR_RUN
@@ -578,7 +581,24 @@
              if [[ $running_on_remote = true  && ( "$s2b" = job  ||  "$s2b" = jobopt ) ]]
              then
-                pathin[$iin]=${fast_io_catalog}/${sources_for_run_catalog}
+                pathin_pre[$iin]=${fast_io_catalog}/${sources_for_run_catalog}
              fi
 
+                # CHECK FOR MULTIPLE FILES, SET A RESPECTIVE FLAG AND REMOVE
+                # THE WILDCARD FROM THE ENDING
+             if [[ "${s5: -1}" = "*" ]]
+             then
+                if [[ "$s2c" = "di" ]]
+                then
+                   printf "\n    +++ wildcards (*) not allowed with \"di\" file attribute."
+                   printf "\n        see file \"$fileconnection_file\", line"
+                   printf "\n$line"
+                   locat=iofiles_file; exit
+                fi
+                multin[$iin]=true
+                string=${endin_pre[$iin]}
+                endin_pre[$iin]="${string%?}"
+             else
+                multin[$iin]=false
+             fi
           fi
        elif [[ "$s2a" = out  &&  ! ( $create_remote_batch_job = true  &&  "$s2b" = loc ) ]]
@@ -595,6 +615,24 @@
           then
              (( iout = iout + 1 ))
-             localout[$iout]=$s1; actionout[$iout]=$s2c; typeout[$iout]=$s3;
-             pathout[$iout]=$s4; endout[$iout]=$s5; extout[$iout]=$s6
+             localout_pre[$iout]=$s1; actionout_pre[$iout]=$s2c; typeout_pre[$iout]=$s3;
+             pathout_pre[$iout]=$s4; endout_pre[$iout]=$s5; extout_pre[$iout]=$s6
+
+                # CHECK FOR MULTIPLE FILES, SET A RESPECTIVE FLAG AND REMOVE
+                # THE WILDCARD FROM THE LOCAL FILENAME
+             if [[ "${s1: -1}" = "*" ]]
+             then
+                if [[ "$s2c" = "di" ]]
+                then
+                   printf "\n    +++ wildcards (*) not allowed with \"di\" file attribute."
+                   printf "\n        see file \"$fileconnection_file\", line"
+                   printf "\n$line"
+                   locat=iofiles_file; exit
+                fi
+                multout[$iout]=true
+                string=${localout_pre[$iout]}
+                localout_pre[$iout]="${string%?}"
+             else
+                multout[$iout]=false
+             fi
           fi
        elif [[ "$s2a" != in  &&  "$s2a" != out ]]
@@ -967,22 +1005,18 @@
     # CHECK, IF INPUT-FILES EXIST, AND DETERMINE HIGHEST CYCLE NUMBER (IF CYCLES EXIST)
  (( i = 0 ))
+ (( nr_of_input_files = 0 ))
  while (( i < iin ))
  do
     (( i = i + 1 ))
-    (( maxcycle = 0 ))
 
        # GENERATE PATH AND FULL FILE NAME (then-BRANCH: FIXED FULL NAME IS GIVEN, I.E. THE
        # FILE IDENTIFIER IS NOT PART OF THE FILENAME))
-    if [[ "${actionin[$i]}" = di ]]
-    then
-       remotepathin[$i]=${pathin[$i]}/${endin[$i]}  # EVALUATE REMOTE-PATH ON THE REMOTE
-                                                    # HOST ONLY
-       eval filename=${pathin[$i]}/${endin[$i]}
+    if [[ "${actionin_pre[$i]}" = di ]]
+    then
+       eval filename=${pathin_pre[$i]}/${endin_pre[$i]}
     else
-       remotepathin[$i]=${pathin[$i]}/${fname}${endin[$i]}  # EVALUATE REMOTE-PATH ON THE REMOTE
-                                                             # HOST ONLY
-       eval filename=${pathin[$i]}/${fname}${endin[$i]}
-    fi
-    eval pathname=${pathin[$i]}
+       eval filename=${pathin_pre[$i]}/${fname}${endin_pre[$i]}
+    fi
+
 
        # CHECK IF FILE EXISTS
@@ -991,114 +1025,220 @@
 
           # FILES WITH ATTRIBUTE locopt ARE OPTIONAL. NO ABORT, IF THEY DO NOT EXIST.
-       if [[ "${transin[$i]}" != "locopt"  &&  "${transin[$i]}" != "jobopt" ]]
+       if [[ "${transin_pre[$i]}" != "locopt"  &&  "${transin_pre[$i]}" != "jobopt" ]]
        then
           printf "\n\n  +++ INPUT-file: "
-          if [[ "${extin[$i]}" = ""  ||  "${extin[$i]}" = " " ]]
+          if [[ "${extin_pre[$i]}" = ""  ||  "${extin_pre[$i]}" = " " ]]
           then
              printf "\n           $filename"
           else
-             printf "\n           $filename.${extin[$i]}"
+             printf "\n           $filename.${extin_pre[$i]}"
           fi
           printf "\n      does not exist\n"
           locat=input; exit
        else
-          transin[$i]="unavailable"
+          (( nr_of_input_files = nr_of_input_files + 1 ))
+          localin[$nr_of_input_files]="${localin_pre[$i]}"
+          transin[$nr_of_input_files]="unavailable"
+          actionin[$nr_of_input_files]="${actionin_pre[$i]}"
+          pathin[$nr_of_input_files]="${pathin_pre[$i]}"
+          endin[$nr_of_input_files]="${endin_pre[$i]}"
+          extin[$nr_of_input_files]="${extin_pre[$i]}"
        fi
 
     else
 
-          # DETERMINE THE FILE'S CYCLE NUMBER
-       ls -1 -d $filename    >   filelist  2>/dev/null
-       ls -1 -d $filename.*  >>  filelist  2>/dev/null
-       while  read line
+          # FIRST CHECK FOR MULTIPLE NAMES WITH THE SAME BASENAME ($fname) AND
+          # CREATE A LIST FOR THE DETECTED BASENAME ENDINGS
+       if [[ "${multin[$i]}" = true ]]
+       then
+             # DETERMINE THE EXISTING EXTENSIONS FROM THE LIST OF FILES
+          ls -1 -d ${filename}    >   filelist  2>/dev/null
+          ls -1 -d ${filename}.*  >>  filelist  2>/dev/null
+          ls -1 -d ${filename}_*  >>  filelist  2>/dev/null
+
+          endings=""
+          while  read line
+          do
+                 # filename without path (i.e. after the last "/")
+              basefilename=$(basename ${line})
+
+                 # check if there is an extension and remove it
+              ext=${basefilename##*.}
+              if [[ "$ext" = "${extin_pre[$i]}" ]]
+              then
+                 basefilename=${basefilename%.*}
+              fi
+
+                 # check for an existing cycle number and remove it
+              cycle=${basefilename##*.}
+              if [[ $cycle =~ ^-?[0-9]+$ ]]
+              then
+                 basefilename=${basefilename%.*}
+              fi
+
+                 # remove the fname from the beginning
+              length_fname=${#fname}
+              ending=${basefilename:${length_fname}}
+
+                 # remove the ending given in the .iofiles from the beginning
+              endingstring="${endin_pre[$i]}"
+              length_ending=${#endingstring}
+              ending=${ending:${length_ending}}
+
+              if [[ "$ending" = "" ]]
+              then
+                    # standard ending as given in the .iofiles
+                 if [[ $(echo $endings | grep -c DEFAULT) = 0 ]]
+                 then
+                    endings="$endings DEFAULT"
+                 fi
+              else
+                    # ending must start with "_", otherwise its a different file
+                 if [[ "${ending:0:1}" = "_" ]]
+                 then
+                    if [[ $(echo $endings | grep -c "$ending") = 0 ]]
+                    then
+                       endings="$endings $ending"
+                    fi
+                 fi
+              fi
+ 
+          done <filelist
+
+          rm filelist
+
+       else
+
+             # SINGLE NAME
+          endings=DEFAULT
+
+       fi
+
+          # FOR EACH BASENAME ENDING CREATE AN ENTRY IN THE FINAL INPUT FILE LIST
+       for  ending  in  $endings
        do
-              # filename without path (i.e. after the last "/")
-           basefilename=$(basename ${line})
-
-              # check if there is an extension
-           extension=${basefilename##*.}
-           if [[ "$extension" = "${extin[$i]}" ]]
-           then
-              basefilename=${basefilename%.*}
-           fi
-
-              # check for an existing cycle number
-           cycle=${basefilename##*.}
-           if [[ $cycle =~ ^-?[0-9]+$ ]]
-           then
-              (( icycle = $cycle ))
-           else
-              (( icycle = 0 ))
-           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 ]]
+
+             # DEFAULT MEANS THAT THE ENDING GIVEN IN .iofiles SHALL BE USED
+          if [[ $ending = DEFAULT ]]
+          then
+             ending=""
+          fi
+
+             # NEW ENTRY (ENDING IS ALSO ADDED TO LOCAL FILENAME READ BY PALM!)
+          (( nr_of_input_files = nr_of_input_files + 1 ))
+          localin[$nr_of_input_files]="${localin_pre[$i]}"$ending
+          transin[$nr_of_input_files]="${transin_pre[$i]}"
+          actionin[$nr_of_input_files]="${actionin_pre[$i]}"
+          pathin[$nr_of_input_files]="${pathin_pre[$i]}"
+          endin[$nr_of_input_files]="${endin_pre[$i]}"$ending
+          extin[$nr_of_input_files]="${extin_pre[$i]}"
+
+
+             # GENERATE PATH AND FULL FILE NAME (then-BRANCH: FIXED FULL NAME IS GIVEN, I.E. THE
+             # FILE IDENTIFIER IS NOT PART OF THE FILENAME))
+          if [[ "${actionin[$nr_of_input_files]}" = di ]]
+          then
+             eval filename=${pathin[$nr_of_input_files]}/${endin[$nr_of_input_files]}
+          else
+             eval filename=${pathin[$nr_of_input_files]}/${fname}${endin[$nr_of_input_files]}
+          fi
+
+             # DETERMINE THE FILE'S CYCLE NUMBER
+          (( maxcycle = 0 ))
+          ls -1 -d $filename    >   filelist  2>/dev/null
+          ls -1 -d $filename.*  >>  filelist  2>/dev/null
+          while  read line
+          do
+                 # filename without path (i.e. after the last "/")
+              basefilename=$(basename ${line})
+   
+                 # check if there is an extension
+              extension=${basefilename##*.}
+              if [[ "$extension" = "${extin[$nr_of_input_files]}" ]]
               then
-                 leading_zero=true
+                 basefilename=${basefilename%.*}
+              fi
+   
+                 # check for an existing cycle number
+              cycle=${basefilename##*.}
+              if [[ $cycle =~ ^-?[0-9]+$ ]]
+              then
+                 (( icycle = $cycle ))
               else
-                 leading_zero=false
+                 (( icycle = 0 ))
               fi
-           fi
-
-       done <filelist
-       rm filelist
-
-          # MAKE CYCLE NUMBER THREE DIGITS WIDE
-       if [[ $leading_zero = true ]]
-       then
-          cyclestring=`printf "%03d" $maxcycle`
-       else
-          cyclestring=$maxcycle
-       fi
-
-          # APPEND CYCLE NUMBER TO FILENAME
-       if (( maxcycle > 0 ))
-       then
-          if [[ "${extin[$i]}" != " "  &&   "${extin[$i]}" != "" ]]
-          then
-             filename=${filename}.$cyclestring.${extin[$i]}
+   
+              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
+   
+          done <filelist
+          rm filelist
+   
+             # MAKE CYCLE NUMBER THREE DIGITS WIDE
+          if [[ $leading_zero = true ]]
+          then
+             cyclestring=`printf "%03d" $maxcycle`
           else
-             filename=${filename}.$cyclestring
-          fi
-       else
-          if [[ "${extin[$i]}" != " "  &&   "${extin[$i]}" != "" ]]
-          then
-             filename=${filename}.${extin[$i]}
-          fi
-       fi
-       
-          # STORE FILENAME WITHOUT PATH BUT WITH CYCLE NUMBER,
-          # IS LATER USED FOR TRANSFERRING FILES WIHIN THE JOB (SEE END OF FILE)
-       absnamein[$i]=$filename
-       if (( maxcycle > 0 ))
-       then
-          if [[ "${actionin[$i]}" = di ]]
-          then
-             frelin[$i]=${endin[$i]}.$cyclestring
+             cyclestring=$maxcycle
+          fi
+   
+             # APPEND CYCLE NUMBER TO FILENAME
+          if (( maxcycle > 0 ))
+          then
+             if [[ "${extin[$nr_of_input_files]}" != " "  &&   "${extin[$nr_of_input_files]}" != "" ]]
+             then
+                filename=${filename}.$cyclestring.${extin[$nr_of_input_files]}
+             else
+                filename=${filename}.$cyclestring
+             fi
           else
-             frelin[$i]=${fname}${endin[$i]}.$cyclestring
-          fi
-       else
-          if [[ "${actionin[$i]}" = di ]]
-          then
-             frelin[$i]=${endin[$i]}
+             if [[ "${extin[$nr_of_input_files]}" != " "  &&   "${extin[$nr_of_input_files]}" != "" ]]
+             then
+                filename=${filename}.${extin[$nr_of_input_files]}
+             fi
+          fi
+          
+             # STORE FILENAME WITHOUT PATH BUT WITH CYCLE NUMBER,
+             # IS LATER USED FOR TRANSFERRING FILES WIHIN THE JOB (SEE END OF FILE)
+          absnamein[$nr_of_input_files]=$filename
+          if (( maxcycle > 0 ))
+          then
+             if [[ "${actionin[$nr_of_input_files]}" = di ]]
+             then
+                frelin[$nr_of_input_files]=${endin[$nr_of_input_files]}.$cyclestring
+             else
+                frelin[$nr_of_input_files]=${fname}${endin[$nr_of_input_files]}.$cyclestring
+             fi
           else
-             frelin[$i]=${fname}${endin[$i]}
-          fi
-       fi
-
-    fi
+             if [[ "${actionin[$nr_of_input_files]}" = di ]]
+             then
+                frelin[$nr_of_input_files]=${endin[$nr_of_input_files]}
+             else
+                frelin[$nr_of_input_files]=${fname}${endin[$nr_of_input_files]}
+             fi
+          fi
+
+       done
+
+    fi
+
  done
 
-    
+
     # GENERATE FULL FILENAMES OF OUTPUT-FILES (WITHOUT $ OR ~),
     # CHECK, IF OUTPUT-FILES EXIST, AND DETERMINE HIGHEST CYCLE NUMBER (IF CYCLES EXIST),
     # OR, IN CASE THAT FILE DOES NOT EXIST, CHECK, IF IT CAN BE CREATED  
-    # THESE ACTIONS ARE NOT CARRIED OUT, IF FILES SHALL BE TRASFERRED FROM THE REMOTE TO
+    # THESE ACTIONS ARE NOT CARRIED OUT, IF FILES SHALL BE TRANSFERRED FROM THE REMOTE TO
     # THE LOCAL HOST (BECAUSE THEIR IS NO DIRECT ACCESS TO THE LOCAL DIRECTORIES FROM THE
     # REMOTE HOST)
@@ -1107,19 +1247,19 @@
  do
     (( i = i + 1 ))
-    if [[ ! ( $running_on_remote = true  &&  ( "${actionout[$i]}" = tr || "${actionout[$i]}" = tra || "${actionout[$i]}" = trpe ) ) ]]
-    then
-       if [[ "${actionout[$i]}" = tr ]]
-       then
-          actionout[$i]=""
-       elif [[ "${actionout[$i]}" = trpe ]]
-       then
-          actionout[$i]=pe
-       elif [[ "${actionout[$i]}" = tra ]]
-       then
-          actionout[$i]=a
+    if [[ ! ( $running_on_remote = true  &&  ( "${actionout_pre[$i]}" = tr || "${actionout_pre[$i]}" = tra || "${actionout_pre[$i]}" = trpe ) ) ]]
+    then
+       if [[ "${actionout_pre[$i]}" = tr ]]
+       then
+          actionout_pre[$i]=""
+       elif [[ "${actionout_pre[$i]}" = trpe ]]
+       then
+          actionout_pre[$i]=pe
+       elif [[ "${actionout_pre[$i]}" = tra ]]
+       then
+          actionout_pre[$i]=a
        fi
        (( maxcycle = 0 ))
-       eval filename=${pathout[$i]}/${fname}${endout[$i]}
-       eval catalogname=${pathout[$i]}
+       eval filename=${pathout_pre[$i]}/${fname}${endout_pre[$i]}
+       eval catalogname=${pathout_pre[$i]}
        if ! ls $filename* 1>/dev/null 2>&1
        then
@@ -1156,64 +1296,6 @@
              fi
           fi 2>/dev/null
-       else
-
-             # DETERMINE THE CYCLE NUMBER
-          ls -1 -d $filename    >   filelist  2>/dev/null
-          ls -1 -d $filename.*  >>  filelist  2>/dev/null
-          while  read line
-          do
-
-                # filename without path (i.e. after the last "/")
-             basefilename=$(basename ${line})
-
-                # check if there is an extension
-             extension=${basefilename##*.}
-             if [[ "$extension" = "${extout[$i]}" ]]
-             then
-                basefilename=${basefilename%.*}
-             fi
-
-                # check for an existing cycle number
-             cycle=${basefilename##*.}
-             if [[ $cycle =~ ^-?[0-9]+$ ]]
-             then
-                (( icycle = $cycle + 1 ))
-             else
-                (( icycle = 1 ))
-             fi
-
-             if (( icycle > maxcycle ))
-             then
-                (( maxcycle = icycle ))
-             fi
-
-          done <filelist
-          rm filelist
-       fi
-
-          # APPEND CYCLE NUMBER TO FILENAME AND CHECK, IF FILE CAN BE CREATED
-          # IN CASE OF FILE-APPEND, FILE MUST BE APPENDED TO THE ONE WITH HIGHEST CYCLE NUMBER
-       if [[ "${actionout[$i]}" != a ]]
-       then
-          cyclestring=`printf "%03d" $maxcycle`
-          if (( maxcycle > 0 ))
-          then
-             filename_tmp=${filename}.$cyclestring
-             if  cat /dev/null > $filename_tmp 
-             then
-                rm  $filename_tmp
-             else
-                printf "\n  +++ OUTPUT-file:"
-                printf "\n           $filename_tmp"
-                printf "\n      cannot be created"
-                locat=output  ; exit
-             fi
-          fi
-       else
-          (( maxcycle = maxcycle - 1 ))
-       fi
-       
-       (( cycnum[$i] = maxcycle ))
-       pathout[$i]=$filename
+
+       fi
 
     fi
@@ -1499,5 +1581,5 @@
  then
     (( i = 0 ))
-    while (( i < iin ))
+    while (( i < nr_of_input_files ))
     do
        (( i = i + 1 ))
@@ -1678,5 +1760,5 @@
  then
     (( i = 0 ))
-    while (( i < iin ))
+    while (( i < nr_of_input_files ))
     do
        (( i = i + 1 ))
@@ -1721,5 +1803,5 @@
        # LOOP OVER ALL ACTIVATED FILES (LISTED IN THE CONFIGURATION FILE)
     (( i = 0 ))
-    while (( i < iin ))
+    while (( i < nr_of_input_files ))
     do
        (( i = i + 1 ))
@@ -1987,5 +2069,5 @@
 
 
-       # PROVIDE DATA FOR 
+       # PROVIDE DATA FOR ATMOSPHERE OCEAN COUPLING
     if [[ $run_coupled_model = false ]]
     then
@@ -2066,7 +2148,75 @@
 
 
+       # IN A FIRST PASS, ADD ADDITIONAL OUTPUT FILE CONNECTIONS IN CASE OF
+       # WILDCARDS
+    (( i = 0 ))
+    (( nr_of_output_files = 0 ))
+
+    while (( i < iout ))
+    do
+
+       (( i = i + 1 ))
+
+          # FIRST CHECK FOR MULTIPLE NAMES WITH THE SAME LOCAL NAME AND
+          # CREATE A LIST FOR THE DETECTED ENDINGS
+       if [[ "${multout[$i]}" = true ]]
+       then
+             # DETERMINE THE EXISTING EXTENSIONS FROM THE LIST OF FILES
+          ls -1 -d ${localout_pre[$i]}    >   filelist  2>/dev/null
+          ls -1 -d ${localout_pre[$i]}_*  >>  filelist  2>/dev/null
+
+          endings="DEFAULT"
+          while  read line
+          do
+                 # remove the local name from the beginning
+              localnamestring="${localout_pre[$i]}"
+              length_localname=${#localnamestring}
+              ending=${line:${length_localname}}
+
+              if [[ "$ending" != "" ]]
+              then
+                 endings="$endings $ending"
+              fi
+ 
+          done <filelist
+
+          rm filelist
+
+       else
+
+             # SINGLE NAME
+          endings=DEFAULT
+
+       fi
+
+          # FOR EACH BASENAME ENDING CREATE AN ENTRY IN THE FINAL OUTPUT FILE LIST
+       for  ending  in  $endings
+       do
+
+             # DEFAULT MEANS THAT THE ENDING GIVEN IN .iofiles SHALL BE USED
+          if [[ $ending = DEFAULT ]]
+          then
+             ending=""
+          fi
+
+             # NEW ENTRY (ENDING IS ALSO ADDED TO LOCAL FILENAME READ BY PALM!)
+          (( nr_of_output_files = nr_of_output_files + 1 ))
+          localout[$nr_of_output_files]="${localout_pre[$i]}"$ending
+          transout[$nr_of_output_files]="${transout_pre[$i]}"
+          actionout[$nr_of_output_files]="${actionout_pre[$i]}"
+          pathout[$nr_of_output_files]="${pathout_pre[$i]}"
+          endout[$nr_of_output_files]="${endout_pre[$i]}"$ending
+          extout[$nr_of_output_files]="${extout_pre[$i]}"
+
+       done
+
+    done
+
+
+
+
        # COPY LOCAL OUTPUT-FILES TO THEIR PERMANENT DESTINATIONS
     (( i = 0 ))
-    while (( i < iout ))
+    while (( i < nr_of_output_files ))
     do
        (( i = i + 1 ))
@@ -2093,9 +2243,56 @@
        fi
 
-          # ADD CYCLE NUMBER TO FILENAME
        if [[ ! ( $running_on_remote = true  &&  ( "${actionout[$i]}" = tr || "${actionout[$i]}" = tra || "${actionout[$i]}" = trpe ) ) ]]
        then
 
-              # IN APPEND MODE, FILES KEEP THEIR CURRENT CYCLE NUMBER
+          eval filename=${pathout[$i]}/${fname}${endout[$i]}
+
+             # DETERMINE THE CYCLE NUMBER
+          ls -1 -d $filename    >   filelist  2>/dev/null
+          ls -1 -d $filename.*  >>  filelist  2>/dev/null
+          while  read line
+          do
+   
+                # filename without path (i.e. after the last "/")
+             basefilename=$(basename ${line})
+   
+                # check if there is an extension
+             extension=${basefilename##*.}
+             if [[ "$extension" = "${extout[$i]}" ]]
+             then
+                basefilename=${basefilename%.*}
+             fi
+   
+                # check for an existing cycle number
+             cycle=${basefilename##*.}
+             if [[ $cycle =~ ^-?[0-9]+$ ]]
+             then
+                (( icycle = $cycle + 1 ))
+             else
+                (( icycle = 1 ))
+             fi
+   
+             if (( icycle > maxcycle ))
+             then
+                (( maxcycle = icycle ))
+             fi
+   
+          done <filelist
+          rm filelist
+
+   
+             # SET THE CYCLE NUMBER
+             # IN CASE OF FILE-APPEND, IT MUST BE THE HIGHEST EXISTING CYCLE NUMBER
+          if [[ "${actionout[$i]}" = a ]]
+          then
+             (( maxcycle = maxcycle - 1 ))
+          fi
+          
+          (( cycnum[$i] = maxcycle ))
+          pathout[$i]=$filename
+
+
+             # ADD CYCLE NUMBER TO FILENAME
+             # IN APPEND MODE, FILES KEEP THEIR CURRENT CYCLE NUMBER
           if [[ "${actionout[$i]}" != "a" ]]
           then
@@ -2393,5 +2590,5 @@
           # MAY BE VERY HUGE)
        (( i = 0 ))
-       while (( i < iin ))
+       while (( i < nr_of_input_files ))
        do
           (( i = i + 1 ))
Index: palm/trunk/SOURCE/lpm_advec.f90
===================================================================
--- palm/trunk/SOURCE/lpm_advec.f90	(revision 2609)
+++ palm/trunk/SOURCE/lpm_advec.f90	(revision 2610)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! bugfix in logarithmic interpolation of v-component (usws was used by mistake)
+! 
+! 2606 2017-11-10 10:36:31Z schwenkel
 ! Changed particle box locations: center of particle box now coincides 
 ! with scalar grid point of same index.
@@ -431,15 +434,15 @@
 !--                large particle speed.
                    us_int    = MAX( surf_def_h(0)%us(surf_start), 0.01_wp )  
-                   vsws_int  = surf_def_h(0)%usws(surf_start)
+                   vsws_int  = surf_def_h(0)%vsws(surf_start)
                 ELSEIF ( surf_lsm_h%start_index(jlog,ilog) <=                  &
                          surf_lsm_h%end_index(jlog,ilog) )  THEN
                    surf_start = surf_lsm_h%start_index(jlog,ilog)
                    us_int    = MAX( surf_lsm_h%us(surf_start), 0.01_wp )  
-                   vsws_int  = surf_lsm_h%usws(surf_start)
+                   vsws_int  = surf_lsm_h%vsws(surf_start)
                 ELSEIF ( surf_usm_h%start_index(jlog,ilog) <=                  &
                          surf_usm_h%end_index(jlog,ilog) )  THEN
                    surf_start = surf_usm_h%start_index(jlog,ilog)
                    us_int    = MAX( surf_usm_h%us(surf_start), 0.01_wp )  
-                   vsws_int  = surf_usm_h%usws(surf_start)
+                   vsws_int  = surf_usm_h%vsws(surf_start)
                 ENDIF 
 !
