source: palm/trunk/SCRIPTS/palmrun @ 2669

Last change on this file since 2669 was 2669, checked in by raasch, 7 years ago

file attributes and activation strings in .palm.iofiles revised, file extensions for nesting, masked output, wind turbine data, etc. changed

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 95.9 KB
Line 
1#!/bin/bash
2
3# palmrun - script for running PALM jobs
4
5#--------------------------------------------------------------------------------#
6# This file is part of PALM.
7#
8# PALM is free software: you can redistribute it and/or modify it under the terms
9# of the GNU General Public License as published by the Free Software Foundation,
10# either version 3 of the License, or (at your option) any later version.
11#
12# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
13# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along with
17# PALM. If not, see <http://www.gnu.org/licenses/>.
18#
19# Copyright 2017  Leibniz Universitaet Hannover
20#--------------------------------------------------------------------------------#
21#
22# Current revisions:
23# ------------------
24#
25#
26# Former revisions:
27# -----------------
28# $Id: palmrun 2669 2017-12-06 16:03:27Z raasch $
29# file attributes in .palm.iofiles restructured, "loc" attribute completely
30# removed,
31# wildcard (*) allowed in .palm.iofiles as file activation string for output
32# files,
33# informative messages in case of missing optional input files shortened
34# bugfix: variable cycle explicitly interpreted with 10 as the number base
35#
36# 2638 2017-11-23 12:44:23Z raasch
37# use of wildcards in file connection statements enabled
38#
39# 2605 2017-11-09 15:31:46Z raasch
40# in case of remote jobs, input files with "job" or "jobopt" (new) attribute
41# will not be sent with the job file any more, but copied into the
42# SOURCES_FOR_RUN... folder on the remote host, before the job is submitted
43#
44# 2600 2017-11-01 14:11:20Z raasch
45# cycle numbers are made three digits wide
46#
47# 2566 2017-10-20 08:50:47Z raasch
48# execute command for combine_plot_fields added
49# "TEMPDIR" renamed "tempdir"
50# temporary working directory for local batch jobs is created immediately within
51# the user's palmrun call, due to a requirement of the "grid engine" batch
52# system, where the working directory is given with batch directive -wd and must
53# already exist when the job is submitted,
54# informative messages in non-trace mode reduced and partly reformatted
55#
56# 2551 2017-10-18 07:25:11Z raasch
57# TEMPDIR added as replacement string to be used in batch directives
58#
59# 2512 2017-10-04 08:26:59Z raasch
60# bugfix for determining cycle numbers of NetCDF input files
61#
62# 2506 2017-09-29 08:30:37Z raasch
63# option -V added to check for an existing SOURCES_FOR_RUN_... folder
64# host configuration added to SOURCES_FOR_RUN_... folder name
65# host_identifier renamed host_configuration
66# option -W added to allow for job dependencies
67#
68# 2501 2017-09-26 11:41:55Z raasch
69# default value for number of cores (option -X) set to 1
70# bugfix for mechanism which overwrites configuration file settings with values
71# provided by palmrun options
72#
73# 2499 2017-09-22 16:47:58Z kanani
74# option -h named configuration identifier
75#
76# 2480 2017-09-19 06:24:14Z maronga
77# bugfix for last revision
78#
79# 2479 2017-09-19 06:12:16Z raasch
80# option -A (project account number) added
81#
82# 2422 2017-09-08 08:25:41Z raasch
83# initial revision
84#
85#--------------------------------------------------------------------------------#
86# palmrun - script for running PALM jobs on local and remote hosts
87#--------------------------------------------------------------------------------#
88
89
90 
91    # DECLARATION OF VARIABLES AND THEIR DEFAULT VALUES
92
93 set +o allexport    # SUPPRESS EXPORT OF ALL VARIABLES, SINCE IN THE PAST THIS
94                     # LEAD TO PROBLEMS IN ROUTINES CALLED BY PALMRUN
95                     # (TOO MANY ARGUMENTS - PROBLEM)
96 set +o noclobber    # EXISTING FILES ARE ALLOWED TO BE OVERWRITTEN
97
98 typeset -i  ibd=0 ibdt=0 iec=0 iic=0 iin=0 ioc=0 iout=0 nr_of_input_files=0
99 typeset -i  nr_of_output_files=0
100 typeset -x -i  memory=0   # HAS TO BE EXPORTED HERE, OTHERWISE AN UNKNOWN SIDE
101                           # SIDE EFFECT MAY CAUSE DATA LOSS WHEN GETOPTS IS READING THE
102                           # SCRIPT-OPTION ARGUMENTS
103 typeset -i  cores cputime cpu_hours cpu_minutes cpu_seconds i ii iia iii iio
104 typeset -i  icycle inode ival maxcycle mpi_tasks
105 typeset -i  nodes remaining_cores run_number tasks_per_node threads_per_task
106
107 activation_string_list=""
108 AddFilenames=""
109 combine_plot_fields=true
110 compiler_name=""
111 compiler_name_ser=""
112 compiler_options=""
113 cores=1
114 cores_atmos=0
115 cores_ocean=0
116 coupled_dist=""
117 cpp_options=""
118 cpumax=0
119 create_batch_job=false
120 create_jobfile_only=false
121 create_remote_batch_job=false
122 dashes="  ----------------------------------------------------------------------------"
123 defaultqueue=""
124 delete_temporary_catalog=true
125 do_compile=true
126 do_trace=false
127 executable=""
128 execute_command=""
129 execution_error=false
130 fileconnection_file=.palm.iofiles
131 fname=test
132 global_revision=""
133 host_configuration="default"
134 hostfile=""
135 hp=""
136 keep_data_from_previous_run=false
137 link_local_input=false
138 link_local_output=false
139 linker_options=""
140 local_jobcatalog=""
141 locat=normal
142 makefile=""
143 max_par_io_str=""
144 prc=$0
145 while [[ $(echo $prc | grep -c "/") != 0 ]]
146 do
147    prc=`echo $prc | cut -f2- -d"/"`
148 done
149 module_calls=""
150 palmrun_memory=""
151 palmrun_script_name=$prc
152 openmp=false
153 previous_job=""
154 project_account=""
155 queue=none
156 restart_run=false
157 return_address=""
158 remote_jobcatalog=""
159 remote_username=""
160 running_in_batch_mode=false
161 run_coupled_model=false
162 run_id=""
163 silent=false
164 source_list=""
165 source_path=""
166 tasks_per_node=0
167 threads_per_task=1
168 transfer_problems=false
169 user_source_path=""
170 use_existing_sources_folder=""
171 use_openmp=false
172 version="palmrun  1.0 Rev$Rev: 2303 $"
173 working_directory=`pwd`
174 write_binary=""
175 TOPT=""
176
177
178    # ERROR HANDLING IN CASE OF EXIT
179 trap 'if [[ $locat != normal  &&  $locat != control_c ]]
180       then
181
182              # CARRY OUT ERROR-COMMANDS GIVEN IN THE CONFIGURATION FILE (EC:)
183          (( i = 0 ))
184          while (( i < iec ))
185          do
186             (( i = i + 1 ))
187             printf "\n  *** Execution of ERROR-command:\n"
188             printf "  >>> ${err_command[$i]}\n"
189             eval  ${err_command[$i]}
190          done
191          [[ $delete_temporary_catalog = true ]]  &&  (cd; rm -rf $tempdir)
192          printf "\n\n+++ palmrun killed \n\n"
193       elif [[ $locat != control_c ]]
194       then
195          printf "\n --> palmrun finished\n\n"
196       fi' exit
197
198
199    # ACTIONS IN CASE OF TERMINAL-BREAK (CONTROL-C):
200 trap 'cd; rm -rf $tempdir
201       printf "\n+++ palmrun killed by \"^C\" \n\n"
202       locat=control_c
203       exit
204      ' 2
205
206
207    # READ SHELLSCRIPT-OPTIONS AND REBUILD THE PALMRUN-COMMAND STRING (prc),
208    # WHICH WILL BE USED TO START RESTART-JOBS
209 while  getopts  :a:A:bBCd:FG:h:jkm:M:O:q:r:R:s:t:T:u:U:vVw:W:xX:yY:Z option
210 do
211   case  $option  in
212       (a)   activation_string_list=$OPTARG; prc="$prc -a'$OPTARG'";;
213       (A)   project_account=$OPTARG; prc="$prc -A'$OPTARG'";;
214       (b)   create_batch_job=true; prc="$prc -b";;
215       (B)   delete_temporary_catalog=false; prc="$prc -B";;
216       (C)   restart_run=true; prc="$prc -C";;
217       (d)   fname=$OPTARG; prc="$prc -d$OPTARG";;
218       (F)   create_jobfile_only=true;;
219       (G)   global_revision=$OPTARG; prc="$prc -G'$OPTARG'";;
220       (h)   host_configuration=$OPTARG; prc="$prc -h$OPTARG";;
221       (j)   running_in_batch_mode=true;;
222       (k)   keep_data_from_previous_run=true; prc="$prc -k";;
223       (m)   palmrun_memory=$OPTARG; prc="$prc -m$OPTARG";;
224       (M)   makefile=$OPTARG; prc="$prc -M$OPTARG";;
225       (O)   use_openmp=true; threads_per_task=$OPTARG; prc="$prc -O$OPTARG";;
226       (q)   queue=$OPTARG; prc="$prc -q$OPTARG";;
227       (r)   run_id=$OPTARG;;
228       (R)   return_address=$OPTARG;;
229       (s)   source_list=$OPTARG;;
230       (t)   palmrun_cpumax=$OPTARG; prc="$prc -t$OPTARG";;
231       (T)   palmrun_tasks_per_node=$OPTARG; prc="$prc -T$OPTARG";;
232       (u)   remote_username=$OPTARG; prc="$prc -u$OPTARG";;
233       (U)   return_username=$OPTARG; prc="$prc -U$OPTARG";;
234       (v)   silent=true; prc="$prc -v";;
235       (V)   use_existing_sources_folder="-V";;
236       (w)   max_par_io_str=$OPTARG; prc="$prc -w$OPTARG";;
237       (W)   previous_job=$OPTARG;;
238       (x)   do_trace=true;set -x; prc="$prc -x";;
239       (X)   palmrun_cores=$OPTARG; prc="$prc -X$OPTARG";;
240       (y)   ocean_file_appendix=true; prc="$prc -y";;
241       (Y)   run_coupled_model=true; coupled_dist=$OPTARG; prc="$prc -Y'$OPTARG'";;
242       (Z)   combine_plot_fields=false; prc="$prc -Z";;
243       (\?)  printf "\n  +++ unknown option $OPTARG \n"
244             printf "\n  --> type \"$0 ?\" for available options \n"
245             locat=parameter;exit;;
246   esac
247 done
248
249
250    # SKIP GIVEN OPTIONS TO READ POSITIONAL PARAMETER, IF GIVEN
251    # CURRENTLY ONLY PARAMETER ? (TO OUTPUT A SHORT COMMAND INFO) IS ALLOWED
252 (( to_shift = $OPTIND - 1 ))
253 shift $to_shift
254
255    # PRINT SHORT DESCRIPTION OF PALMRUN OPTIONS
256 if [[ "$1" = "?" ]]
257 then
258   (printf "\n  *** Description of available palmrun options:\n"
259    printf "\n      Option  Description                              Default-Value"
260    printf "\n        -a    activation string list                   \"\" "
261    printf "\n        -A    project account number                   ---"
262    printf "\n        -b    batch-job on local machine               ---"
263    printf "\n        -B    do not delete temporary directory at end ---"
264    printf "\n        -d    base name of files attached to program   test"
265    printf "\n        -F    create batch job file only               ---"
266    printf "\n        -h    host configuration                       \"default\" "
267    printf "\n        -k    keep data from previous run"
268    printf "\n        -m    memory demand in MB (batch-jobs)         0 MB"
269    printf "\n        -M    Makefile name                            Makefile"
270    printf "\n        -O    threads per openMP task                  ---"
271    printf "\n        -q    queue                                    \"$queue\" "
272    printf "\n        -s    filenames of routines to be compiled     \"\" "
273    printf "\n              must end with .f, .f90, .F, or .c !"
274    printf "\n              use \"..\" for more than one file and wildcards"
275    printf "\n              -s LM compiles all locally modified files"
276    printf "\n        -t    allowed cpu-time in seconds (batch)      0"
277    printf "\n        -T    tasks per node                           ---"
278    printf "\n        -u    username on remote machine               \"\" "
279    printf "\n        -v    no prompt for confirmation               ---"
280    printf "\n        -V    check if SOURCES_FOR_RUN_... exists      ---"
281    printf "\n        -w    maximum parallel io streams              as given by -X"
282    printf "\n        -W    name of job to wait for                  ---"
283    printf "\n        -x    tracing of palmrun for debug purposes    ---"
284    printf "\n        -X    # of processors (on parallel machines)   1"
285    printf "\n        -y    add appendix \"_O\" to all local output"
286    printf "\n              files (ocean precursor runs followed by"
287    printf "\n              coupled atmosphere-ocean runs)           ---"
288    printf "\n        -Y    run coupled model, \"#1 #2\" with" 
289    printf "\n              #1 atmosphere and #2 ocean processors    \"#/2 #/2\" depending on -X"
290    printf "\n        -Z    skip combine_plot_fields at the end of      "
291    printf "\n              the simulation                           ---"
292    printf "\n "
293    printf "\n      Possible values of positional parameter <modus>:"
294    printf "\n        \"?\"       -  this outline \n\n") | more
295    exit
296 elif [[ "$1" != "" ]]
297 then
298    printf "\n  +++ positional parameter $1 unknown \n"
299    locat=parameter; exit
300 fi
301
302
303
304    # SHORT STARTING MESSAGE
305 printf "\n*** $version "
306 printf "\n    will be executed.     Please wait ..."
307
308
309    # BUILD THE CONFIGURATION-FILE NAME AND THE SOURCES_FOR_RUN-FOLDER NAME
310 config_file=.palm.config.$host_configuration
311 sources_for_run_catalog=SOURCES_FOR_RUN_${host_configuration}_$fname
312
313
314    # CHECK, IF CONFIGURATION FILE EXISTS
315 if [[ ! -f $config_file ]]
316 then
317    printf "\n\n  +++ configuration file: "
318    printf "\n           $config_file"
319    printf "\n      does not exist"
320    locat=connect; exit 
321 fi
322
323
324    # CHECK, IF FILE CONNECTION FILE EXISTS
325 if [[ ! -f $fileconnection_file ]]
326 then
327    printf "\n\n  +++ file connection file: "
328    printf "\n           $fileconnection_file"
329    printf "\n      does not exist"
330    locat=connect; exit 
331 fi
332
333
334    # CHECK, IF THE ACTIVATION_STRING_LIST HAS BEEN GIVEN
335 if [[ "$activation_string_list" = "" ]]
336 then
337    printf "\n\n  +++ no activation string list given: "
338    printf "\n        please set palmrun option \"-a\" "
339    locat=palmrun_option; exit 
340 fi
341
342
343    # SET VARIABLE TO ACTIVATE PALM BINARY OUTPUT FOR RESTARTS
344 if [[ $(echo $activation_string_list | grep -c "restart") != 0 ]]
345 then
346    write_binary=true
347 else
348    write_binary=false
349 fi
350
351
352    # READ AND EVALUATE THE CONFIGURATION-FILE
353 [[ $silent = false ]]  &&  printf "\n\n    Reading the configuration file... "
354
355    # READ VARIABLE SETTINGS FROM CONFIG FILE LINE BY LINE
356 while  read line
357 do
358
359       # FIRST REPLACE ENVIRONMENT-VARIABLES BY THEIR RESPECTIVE VALUES
360    eval  line=\"$line\"
361
362
363       # INTERPRET THE LINE
364    if [[ "$(echo $line)" = "" ]]
365    then
366
367          # EMPTY LINE, NO ACTION
368       continue
369
370    elif [[ "$(echo $line | cut -c1)"  =  "#" ]]
371    then
372
373          # LINE IS A COMMENT LINE
374       continue
375
376    elif [[ "$(echo $line | cut -c1)"  =  "%" ]]
377    then
378
379          # LINE DEFINES AN ENVIRONMENT-VARIABLE
380       var=`echo $line | cut -d" " -s -f1 | cut -c2-`
381       value=`echo $line | cut -d" " -s -f2-`
382
383
384          # VALUE FROM THE CONFIGURATION-FILE IS ASSIGNED TO THE
385          # ENVIRONMENT-VARIABLE, BUT ONLY IF NO VALUE HAS BEEN ALREADY
386          # ASSIGNED WITHIN THIS SCRIPT (E.G. BY SCRIPT-OPTIONS).
387          # NON-ASSIGNED VARIABLES HAVE VALUE "" OR 0 (IN CASE OF INTEGER).
388          # HENCE THE GENERAL RULE IS: SCRIPT-OPTION OVERWRITES THE
389          # CONFIGURATION-FILE.
390       if [[ "$(eval echo \$$var)" = ""  ||  "$(eval echo \$$var)" = "0" ]]
391       then
392          eval  export  $var="\$value"
393
394             # TERMINAL OUTPUT OF ENVIRONMENT-VARIABLES, IF TRACEBACK IS SWITCHED on
395          if [[ $do_trace = true ]]
396          then
397             printf "\n*** ENVIRONMENT-VARIABLE $var = $value"
398          fi
399       fi
400
401    elif [[ "$(echo $line | cut -c1-3)" = "BD:" ]]
402    then
403
404          # LINE DEFINES BATCH-DIRECTIVE
405       (( ibd = ibd + 1 ))
406       line=$(echo $line | cut -c4-)
407       batch_directive[$ibd]="$line"
408
409    elif [[ "$(echo $line | cut -c1-4)" = "BDT:" ]]
410    then
411
412          # LINE DEFINES BATCH-DIRECTIVE FOR SENDING BACK THE JOBFILE FROM A
413          # REMOTE TO A LOCAL HOST
414       (( ibdt = ibdt + 1 ))
415       line=$(echo $line | cut -c5-)
416       batch_directive_transfer[$ibdt]="$line"
417
418    elif [[ "$(echo $line | cut -c1-3)" = "EC:" ]]
419    then
420
421          # LINE DEFINES ERROR-COMMAND
422       (( iec = iec + 1 ))
423       line=$(echo $line | cut -c4-)
424       err_command[$iec]="$line"
425
426    elif [[ "$(echo $line | cut -c1-3)" = "IC:" ]]
427    then
428
429          # LINE DEFINES INPUT-COMMAND
430       (( iic = iic + 1 ))
431       line=$(echo $line | cut -c4-)
432       in_command[$iic]="$line"
433
434    elif [[ "$(echo $line | cut -c1-3)" = "OC:" ]]
435    then
436
437          # LINE DEFINES OUTPUT-COMMAND
438       (( ioc = ioc + 1 ))
439       line=$(echo $line | cut -c4-)
440       out_command[$ioc]="$line"
441
442    else
443
444          # SKIP ALL OTHER LINES
445       continue
446
447    fi
448
449 done < $config_file
450
451
452    # CHECK SETTING OF REQUIRED PARAMETERS
453 if [[ "$compiler_name" = "" ]]
454 then
455    printf "\n  +++ no compiler name found in $config_file"
456    printf "\n      Please add line \"compiler_name ...\" to that file."
457    locat=config_file; exit
458 fi
459 if [[ "$compiler_name_ser" = "" ]]
460 then
461    printf "\n  +++ no compiler name for non-paralle compilation found in $config_file"
462    printf "\n      Please add line \"compiler_name_ser ...\" to that file."
463    locat=config_file; exit
464 fi
465 if [[ "$compiler_options" = "" ]]
466 then
467    printf "\n  +++ no compiler options found in $config_file"
468    printf "\n      Please add line \"compiler_options ...\" to that file."
469    locat=config_file; exit
470 fi
471 if [[ "$linker_options" = "" ]]
472 then
473    printf "\n  +++ no linker options found in $config_file"
474    printf "\n      Please add line \"linker_options ...\" to that file."
475    locat=config_file; exit
476 fi
477 if [[ "$execute_command" = "" ]]
478 then
479    printf "\n  +++ no execute command found in $config_file"
480    printf "\n      Please add line \"execute_command ...\" to that file."
481    locat=config_file; exit
482 fi
483
484 if [[ "$hostfile" != "" ]]
485 then
486    if [[ $hostfile != auto  &&  ! -f $hostfile ]]
487    then
488       printf "\n  +++ no hostfile \"$hostfile\" found"
489       printf "\n      Please check line \"hostfile ...\" in $config_file"
490       locat=config_file; exit   
491    fi
492 fi
493
494
495    # DETERMINE THE CALL STATUS
496 if [[ "$return_address" != "" ]]
497 then
498 
499       # I AM RUNNING ON A REMOTE HOST, WHICH ALSO MEANS THAT I AM RUNNING IN
500       # BATCH MODE AND ...
501    running_on_remote=true
502 
503 else
504
505       # I HAVE BEEN CALLED INTERACTIVELY ON THIS HOST
506     if [[ "$remote_ip" != "" ]]
507     then
508
509           # I HAVE TO CREATE A BATCH JOB TO RUN PALM ON THE REMOTE HOST
510        create_remote_batch_job=true
511
512     fi
513     running_on_remote=false
514 fi
515
516
517
518    # READ AND EVALUATE THE I/O-FILE LIST
519 [[ $silent = false ]]  &&  printf "\n    Reading the I/O files... "
520
521    # READ THE FILE CONNECTION FILE LINE BY LINE
522 while  read line
523 do
524
525       # REPLACE REPEATING SPACES BETWEEN THE COLUMNS BY A SINGLE SPACE
526    line=`echo "$line" | sed -e "s/\s\{1,\}/ /g"`
527
528       # INTERPRET THE LINE
529    if [[ "$(echo $line)" = "" ]]
530    then
531          # EMPTY LINE, NO ACTION
532       continue
533
534    elif [[ "$(echo $line | cut -c1)"  =  "#" ]]
535    then
536
537          # LINE IS A COMMENT LINE
538       true
539
540    else
541
542          # LINE DEFINES FILE CONNECTION. READ THE FILE ATTRIBUTES.
543          # s2a: in/out - field
544          # s2b: action - field (optional)
545       s1=`echo "$line" | cut -d" " -f1`
546       s2=`echo "$line" | cut -d" " -s -f2`
547#       s2a=$(echo $s2 | cut -d":" -f1)
548       if [[ $(echo $s2 | grep -c ":") = 0 ]]
549       then
550          s2a=$s2
551          s2b=""
552       else
553          s2a=`echo $s2 | cut -d":" -f1`
554          s2b=`echo $s2 | cut -d":" -f2`
555       fi
556       s3=`echo "$line" | cut -d" " -f3 | sed 's/*/wildcard /g'`
557       s4=`echo "$line" | cut -d" " -s -f4`
558       eval s4=\"$s4\"    # REPLACE ENVIRONMENT-VARIABLES IN PATH BY THEIR RESPECTIVE VALUES
559       echo "### s4=\"$s4\" "
560       s5=`echo "$line" | cut -d" " -s -f5`
561       s6=`echo "$line" | cut -d" " -s -f6`
562
563       
564          # STORE FILE CONNECTION, IF ACTIVATED BY ACTIVATION-STRING FROM
565          # INPUT- OR OUTPUT-LIST.
566          # VARIABLE S3 MAY CONTAIN A LIST OF ACTIVATION STRINGS (FIELD-SEPERATOR ":").
567          # IF EXECUTION IS SCHEDULED FOR A REMOTE-MACHINE AND THE FILE IS ONLY
568          # LOCALLY REQUIRED ON THAT MACHINE (I.E. s2b != tr), THE FILE CONNECTION
569          # IS NOT CHECKED AND STORED.
570       IFSALT="$IFS"; IFS="$IFS:"      # ADD ":" AS FIELD SEPARATOR
571       if [[ ( "$s2a" = in  || "$s2a" = inopt )  &&  ! ( $create_remote_batch_job = true  &&  "$s2b" != tr ) ]]
572       then
573          found=false
574          for  actual  in  $activation_string_list
575          do
576             for  formal  in  $s3
577             do
578                [[ $actual = $formal  ||  "$formal" = "-" ]]  &&  found=true
579             done
580          done
581          if [[ $found = true ]]
582          then
583             (( iin = iin + 1 ))
584             localin_pre[$iin]=$s1; actionin_pre[$iin]=$s2b;
585             pathin_pre[$iin]=$s4; endin_pre[$iin]=$s5; extin_pre[$iin]=$s6
586             if [[ "$s2a" = inopt ]]
587             then
588                optin_pre[$iin]=yes
589             else
590                optin_pre[$iin]=no
591             fi 
592
593                # FILES WITH JOB-ATTRIBUTE ARE STORED IN THE SOURCES_FOR_RUN
594                # FOLDER IF THE JOB IS RUNNING ON A REMOTE HOST
595             if [[ $running_on_remote = true  &&  "$s2b" = tr ]]
596             then
597                pathin_pre[$iin]=${fast_io_catalog}/${sources_for_run_catalog}
598             fi
599
600                # CHECK FOR MULTIPLE FILES, SET A RESPECTIVE FLAG AND REMOVE
601                # THE WILDCARD FROM THE ENDING
602             if [[ "${s5: -1}" = "*" ]]
603             then
604                if [[ "$s2b" = "di" ]]
605                then
606                   printf "\n    +++ wildcards (*) not allowed with \"di\" file attribute."
607                   printf "\n        see file \"$fileconnection_file\", line"
608                   printf "\n$line"
609                   locat=iofiles_file; exit
610                fi
611                multin[$iin]=true
612                string=${endin_pre[$iin]}
613                endin_pre[$iin]="${string%?}"
614             else
615                multin[$iin]=false
616             fi
617          fi
618       elif [[ "$s2a" = out  &&  ! ( $create_remote_batch_job = true ) ]]
619       then
620          found=false
621          echo "### line=\"$line\" "
622          for  actual  in  $activation_string_list
623          do
624             for  formal  in  $s3 
625             do
626                echo "--- actual=\"$actual\"   formal=\"$formal\"   s3=\"$s3\" "
627                if [[ $actual = $formal  ||  $formal = wildcard  ]]
628                then
629                   found=true
630                   echo "--- found"
631                else
632                   echo "--- not found"
633                fi
634             done
635          done
636          if [[ $found = true ]]
637          then
638             (( iout = iout + 1 ))
639             localout_pre[$iout]=$s1; actionout_pre[$iout]=$s2b
640             pathout_pre[$iout]=$s4; endout_pre[$iout]=$s5; extout_pre[$iout]=$s6
641             echo "### pathout_pre[$iout]=\"${pathout_pre[$iout]}\" "
642
643                # CHECK IF WILDCARD IS USED AS ACTIVATION STRING
644                # IN SUCH CASES, NO WARNING WILL LATER BE OUTPUT IF LOCAL FILES DO NOT EXIST
645             if [[ $formal = wildcard  ]]
646             then
647                warnout_pre[$iout]=false
648             else
649                warnout_pre[$iout]=true
650             fi
651
652                # CHECK FOR MULTIPLE FILES, SET A RESPECTIVE FLAG AND REMOVE
653                # THE WILDCARD FROM THE LOCAL FILENAME
654             if [[ "${s1: -1}" = "*" ]]
655             then
656                if [[ "$s2b" = "di" ]]
657                then
658                   printf "\n    +++ wildcards (*) not allowed with \"di\" file attribute."
659                   printf "\n        see file \"$fileconnection_file\", line"
660                   printf "\n$line"
661                   locat=iofiles_file; exit
662                fi
663                multout[$iout]=true
664                string=${localout_pre[$iout]}
665                localout_pre[$iout]="${string%?}"
666             else
667                multout[$iout]=false
668             fi
669          fi
670       elif [[ "$s2a" != in  &&  "$s2a" != inopt  &&  "$s2a" != out ]]
671       then
672          printf "\n  +++ I/O-attribute in file $fileconnection_file has invalid"
673          printf "\n      value \"$s2\". Only \"in\", \"inopt\", and \"out\" are allowed!"
674          locat=connect; exit
675       fi
676       IFS="$IFSALT"
677    fi
678
679 done < $fileconnection_file
680
681
682
683    # VALUES OF PALMRUN-OPTIONS OVERWRITE THOSE FROM THE CONFIGURATION-FILE
684 [[ $palmrun_memory     != ""   ]]  &&  memory=$palmrun_memory
685 [[ $palmrun_cpumax     != ""   ]]  &&  cpumax=$palmrun_cpumax
686 [[ "$palmrun_cores" != ""  ]]  &&  cores=$palmrun_cores
687 [[ "$max_par_io_str" != "" ]]  &&  maximum_parallel_io_streams=$max_par_io_str
688 [[ "$palmrun_tasks_per_node" != "" ]]  &&  tasks_per_node=$palmrun_tasks_per_node
689
690
691
692      # EVALUATE MODEL COUPLING FEATURES (OPTION -Y)
693 if [[ $run_coupled_model = true ]] 
694 then
695
696    cores_atmos=`echo $coupled_dist | cut -d" " -s -f1`
697    cores_ocean=`echo $coupled_dist | cut -d" " -s -f2`
698
699    if (( $cores_ocean + $cores_atmos != $cores ))
700    then
701
702       printf "\n  +++ number of processors does not fit to specification by \"-Y\"."
703       printf "\n      PEs (total)     : $cores"
704       printf "\n      PEs (atmosphere): $cores_atmos"
705       printf "\n      PEs (ocean)     : $cores_ocean"
706       locat=coupling; exit
707
708    fi
709
710 fi
711
712
713    # IF I AM IN BATCH MODE, CHECK IF EXECUTABLE AND OTHER REQUIRED FILES
714    # HAVE BEEN GENERATED BY PALMBUILD AND STORED IN THE SOURCES_FOR_RUN_...
715    # FOLDER
716 if [[ $running_in_batch_mode = true ]]
717 then
718 
719    if [[ ! -d ${fast_io_catalog}/${sources_for_run_catalog} ]]
720    then
721       printf "\n  +++ directory ${fast_io_catalog}/${sources_for_run_catalog} is missing"
722       printf "\n      Please check the output of the palmrun-call"
723       printf "\n      that you did on your local host."
724       locat=SOURCES_FOR_RUN; exit
725    fi
726
727 else
728
729       # CREATE THE SOURCES_FOR_RUN_... FOLDER, BUT NOT IF I AM PART OF AN
730       # AUTOMATIC RESTART RUN
731       # AUTOMATIC RESTART RUNS JUST ACCESS THE DIRECTORY CREATED BY THE INITIAL RUN
732    if [[ $restart_run = false ]]
733    then
734
735          # COLLECT FILES TO BE COMPILED IN THE SOURCES_FOR_RUN_... FOLDER ON
736          # THE LOCAL HOST
737       if [[ ! -d $source_path ]]
738       then
739          printf "\n\n  +++ source path \"$source_path\" on local host"
740          printf "\n      \"$(hostname)\" does not exist"
741          locat=source_path; exit
742       fi
743
744       rm -rf   $sources_for_run_catalog
745       mkdir -p $sources_for_run_catalog
746
747       if [[ "$source_list" = LM ]]
748       then
749
750             # DETERMINE MODIFIED FILES OF THE SVN WORKING COPY
751          source_list=""
752          cd  $source_path
753
754
755             # CHECK, IF TRUNK-DIRECTORY IS UNDER SVN CONTROL
756          if [[ ! -d ../.svn ]]
757          then
758             printf "\n\n  +++ source directory"
759             printf "\n         \"$source_path\" "
760             printf "\n         is not under control of \"subversion\"."
761             printf "\n         Please do not use palmrun-option \"-s LM\"\n"
762          fi
763
764
765             # LIST ALL MODIFIED SOURCE CODE FILES
766          Filenames=""
767          svn status  >  tmp_svnstatus
768          while  read line
769          do
770             firstc=`echo $line | cut -c1`
771             if [[ $firstc = M  ||  $firstc = "?" ]]
772             then
773                Name=`echo "$line" | cut -c8-`
774                extension=`echo $Name | cut -d. -f2`
775                if [[ "$extension" = f90 || "$extension" = F90 || "$extension" = f || "$extension" = F || "$extension" = c ]]
776                then
777                   Filenames="$Filenames "$Name
778                fi
779             fi
780          done < tmp_svnstatus
781          rm -rf  tmp_svnstatus
782
783
784             # COPY FILES TO SOURCES_FOR_RUN_...
785          for  filename  in  $Filenames
786          do
787             cp  $filename  ${working_directory}/${sources_for_run_catalog}
788             source_list=$source_list"$filename "
789          done
790
791          cd -  > /dev/null
792
793
794          # COPY FILES GIVEN BY OPTION -s TO DIRECTORY SOURCES_FOR_RUN_...
795       elif [[ "$source_list" != "" ]]
796       then
797
798          cd  $source_path
799
800          for  filename  in  $source_list
801          do
802
803                # SOURCE CODE FILE IS NOT ALLOWED TO INCLUDE PATH
804             if [[ $(echo $filename | grep -c "/") != 0 ]]
805             then
806                printf "\n  +++ source code file:  $filename"
807                printf "\n      must not contain (\"/\") "
808                locat=source; exit
809             fi
810
811             if [[ ! -f $filename ]]
812             then
813                printf "\n  +++ source code file:  $filename"
814                printf "\n      does not exist"
815                locat=source; exit
816             else
817                cp  $filename  ${working_directory}/${sources_for_run_catalog}
818             fi
819
820          done
821
822          cd -  > /dev/null
823
824       fi
825
826          # CHECK, IF MAKEFILE EXISTS AND COPY IT TO THE SOURCES_FOR_RUN... DIRECTORY
827       [[ "$makefile" = "" ]]  &&  makefile=$source_path/Makefile
828       if [[ ! -f $makefile ]]
829       then
830          printf "\n  +++ file \"$makefile\" does not exist"
831          locat=make; exit
832       else
833          cp  $makefile  ${sources_for_run_catalog}/Makefile
834       fi
835
836
837          # COPY FILES FROM OPTIONAL SOURCE PATH GIVEN IN THE CONFIGURATION FILE
838       if [[ "$user_source_path" != "" ]]
839       then
840
841             # DOES THE DIRECTORY EXIST?
842          if [[ ! -d $user_source_path ]]
843          then
844
845             printf "\n\n  *** INFORMATIVE: additional source code directory"
846             printf "\n      \"$user_source_path\" "
847             printf "\n      does not exist or is not a directory."
848             printf "\n      No source code will be used from this directory!\n"
849             user_source_path=""
850             if [[ $silent == false ]]
851             then
852                sleep 2
853             fi
854
855          else
856
857             cd $user_source_path
858             found=false
859
860             Names=$(ls -1 *.f90 2>&1)
861             [[ $(echo $Names | grep -c '*.f90') = 0 ]]  &&  AddFilenames="$Names"
862             Names=$(ls -1 *.F90 2>&1)
863             [[ $(echo $Names | grep -c '*.F90') = 0 ]]  &&  AddFilenames="$AddFilenames $Names"
864             Names=$(ls -1 *.F 2>&1)
865             [[ $(echo $Names | grep -c '*.F') = 0   ]]  &&  AddFilenames="$AddFilenames $Names"
866             Names=$(ls -1 *.f 2>&1)
867             [[ $(echo $Names | grep -c '*.f') = 0   ]]  &&  AddFilenames="$AddFilenames $Names"
868             Names=$(ls -1 *.c 2>&1)
869             [[ $(echo $Names | grep -c '*.c') = 0   ]]  &&  AddFilenames="$AddFilenames $Names"
870
871             cd -  > /dev/null
872             cd  $sources_for_run_catalog
873
874                # COPY MAKEFILE IF EXISTING
875             if [[ -f $user_source_path/Makefile ]]
876             then
877                printf "\n\n  *** user Makefile from directory"
878                printf "\n      \"$user_source_path\" is used \n"
879                if [[ $silent == false ]]
880                then
881                   sleep 1
882                fi
883                cp  $user_source_path/Makefile  .
884             fi
885
886             for  filename  in  $AddFilenames
887             do
888                if [[ -f $filename ]]
889                then
890                   printf "\n  +++ source code file \"$filename\" found in additional"
891                   printf "\n      source code directory \"$user_source_path\" "
892                   printf "\n      but was also given with option \"-s\" which means that it should be taken"
893                   printf "\n      from directory \"$source_path\"."
894                   locat=source; exit
895                fi
896
897                cp  $user_source_path/$filename  .
898                source_list="$source_list $filename"
899
900                   # CHECK IF FILE IS CONTAINED IN MAKEFILE
901                if [[ $(grep -c $filename Makefile) = 0 ]]
902                then
903                   printf "\n\n  +++ user file \"$filename\" "
904                   printf "\n      is not listed in Makefile \n"
905                   locat=source; exit
906                else
907
908                   if [[ $found = false ]]
909                   then
910                      found=true
911                      printf "\n\n  *** following user file(s) added to the"
912                      printf " files to be translated:\n      "
913                   fi
914                   printf "$filename  "
915                   if [[ $silent == false ]]
916                   then
917                      sleep 0.5
918                   fi
919
920                fi
921             done
922             [[ $found = true ]]  &&  printf "\n"
923             cd -  > /dev/null
924          fi
925       fi
926
927          # COPY CONFIGURATION FILES
928       cp  $config_file  $sources_for_run_catalog
929       cp  $fileconnection_file  $sources_for_run_catalog
930
931          # COPY SHELLSCRIPTS
932       cp  ${source_path}/../SCRIPTS/palmrun    $sources_for_run_catalog
933       cp  ${source_path}/../SCRIPTS/batch_scp  $sources_for_run_catalog
934
935    fi
936
937 fi
938
939
940    # GET THE GLOBAL REVISION-NUMBER OF THE SVN-REPOSITORY
941    # (HANDED OVER TO RESTART-RUNS USING OPTION -G)
942 if [[ "$global_revision" = "" ]]
943 then
944    global_revision=`svnversion $source_path  2>/dev/null`
945    global_revision="Rev: $global_revision"
946 fi
947
948
949    # IN CASE OF PARALLEL EXECUTION, CHECK SOME SPECIFICATIONS CONCERNING PROCESSOR NUMBERS
950 if [[ -n $cores ]]
951 then
952
953       # CHECK, IF THE NUMBER OF CORES PER NODE HAS BEEN GIVEN UND IF IT IS AN
954       # INTEGRAL DIVISOR OF THE TOTAL NUMBER OF CORES GIVEN BY OPTION -X
955    if [[ $tasks_per_node = 0 ]]
956    then
957       printf "\n"
958       printf "\n  +++ option \"-T\" (tasks per node) is missing"
959       printf "\n      set -T option or define tasks_per_node in the config file"
960       locat=tasks_per_node; (( iec = 0 )); exit
961    fi
962
963    if (( cores < tasks_per_node ))
964    then
965       printf "\n"
966       printf "\n  +++ tasks per node (-T) cannot exceed total number of cores (-X)"
967       printf "\n      given values: -T $tasks_per_node  -X $cores"
968       locat=tasks_per_node; (( iec = 0 )); exit
969    fi
970
971    (( nodes = cores / ( tasks_per_node * threads_per_task ) ))
972    (( mpi_tasks = cores / threads_per_task ))
973    [[ $mpi_tasks = 0 ]]  &&  (( mpi_tasks = 1 ))
974    (( ii = cores / tasks_per_node ))
975    (( remaining_cores =  cores - ii * tasks_per_node ))
976    if (( remaining_cores > 0 ))
977    then
978       printf "\n"
979       printf "\n  +++ WARNING: tasks per node (option \"-T\") is not an integral"
980       printf "\n      divisor of the total number of cores (option \"-X\")"
981       printf "\n      values of this palmrun-call: \"-T $tasks_per_node\" \"-X $cores\""
982       printf "\n      One of the nodes is filled with $remaining_cores instead of $tasks_per_node tasks"
983       (( nodes = nodes + 1 ))
984    fi
985
986       # SET THE TOTAL NUMBER OF NODES, REQUIRED FOR THE SUBJOB-COMMAND (SEE FURTHER BELOW)
987    if [[ "$tasks_per_node" != "" ]]
988    then
989       TOPT="-T $tasks_per_node"
990    fi
991
992 fi
993
994
995    # SET DEFAULT VALUE FOR THE MAXIMUM NUMBER OF PARALLEL IO STREAMS
996 if [[ "$maximum_parallel_io_streams" = "" ]]
997 then
998    maximum_parallel_io_streams=$cores
999 fi
1000
1001
1002    # SET PORT NUMBER OPTION FOR CALLS OF SSH/SCP AND batch_scp SCRIPT
1003 if [[ "$scp_port" != "" ]]
1004 then
1005    PORTOPT="-P $scp_port"
1006    SSH_PORTOPT="-p $scp_port"
1007 fi
1008
1009
1010    # DETERMINE THE SSH-OPTION IN CASE THAT AN SSH-KEY IS EXPLICITLY GIVEN IN THE
1011    # CONFIG-FILE
1012 if [[ "$ssh_key" != "" ]]
1013 then
1014    ssh_key="-i $HOME/.ssh/$ssh_key"
1015 fi
1016
1017
1018    # SET QUEUE, IF NOT GIVEN
1019 if [[ $create_batch_job = true  ||  $create_remote_batch_job = true ]]
1020 then
1021
1022    if [[ $queue = none  &&  "$defaultqueue" = "" ]]
1023    then
1024       printf "\n"
1025       printf "\n  +++ no default queue given in configuration file and no queue"
1026       printf "\n      given with option -q"
1027    fi
1028    if [[ $queue = none ]]
1029    then
1030       queue=$defaultqueue
1031    fi
1032
1033 fi
1034
1035
1036    # GENERATE FULL FILENAMES OF INPUT-FILES, INCLUDING THEIR PATH
1037    # CHECK, IF INPUT-FILES EXIST, AND DETERMINE HIGHEST CYCLE NUMBER (IF CYCLES EXIST)
1038 (( i = 0 ))
1039 (( nr_of_input_files = 0 ))
1040 while (( i < iin ))
1041 do
1042    (( i = i + 1 ))
1043
1044       # GENERATE PATH AND FULL FILE NAME (then-BRANCH: FIXED FULL NAME IS GIVEN, I.E. THE
1045       # FILE IDENTIFIER IS NOT PART OF THE FILENAME))
1046    if [[ "${actionin_pre[$i]}" = di ]]
1047    then
1048       eval filename=${pathin_pre[$i]}/${endin_pre[$i]}
1049    else
1050       eval filename=${pathin_pre[$i]}/${fname}${endin_pre[$i]}
1051    fi
1052
1053
1054       # CHECK IF FILE EXISTS
1055    if ! ls $filename* 1>/dev/null 2>&1
1056    then
1057
1058          # FILES WITH ATTRIBUTE opt ARE OPTIONAL. NO ABORT, IF THEY DO NOT EXIST.
1059       if [[ "${optin_pre[$i]}" != "yes" ]]
1060       then
1061          printf "\n\n  +++ INPUT-file: "
1062          if [[ "${extin_pre[$i]}" = ""  ||  "${extin_pre[$i]}" = " " ]]
1063          then
1064             printf "\n           $filename"
1065          else
1066             printf "\n           $filename.${extin_pre[$i]}"
1067          fi
1068          printf "\n      does not exist\n"
1069          locat=input; exit
1070       else
1071          (( nr_of_input_files = nr_of_input_files + 1 ))
1072          localin[$nr_of_input_files]="${localin_pre[$i]}"
1073          optin[$nr_of_input_files]="${optin_pre[$i]}"
1074          actionin[$nr_of_input_files]="unavailable"
1075          pathin[$nr_of_input_files]="${pathin_pre[$i]}"
1076          endin[$nr_of_input_files]="${endin_pre[$i]}"
1077          extin[$nr_of_input_files]="${extin_pre[$i]}"
1078       fi
1079
1080    else
1081
1082          # FIRST CHECK FOR MULTIPLE NAMES WITH THE SAME BASENAME ($fname) AND
1083          # CREATE A LIST FOR THE DETECTED BASENAME ENDINGS
1084       if [[ "${multin[$i]}" = true ]]
1085       then
1086             # DETERMINE THE EXISTING EXTENSIONS FROM THE LIST OF FILES
1087          ls -1 -d ${filename}    >   filelist  2>/dev/null
1088          ls -1 -d ${filename}.*  >>  filelist  2>/dev/null
1089          ls -1 -d ${filename}_*  >>  filelist  2>/dev/null
1090
1091          endings=""
1092          while  read line
1093          do
1094                 # filename without path (i.e. after the last "/")
1095              basefilename=$(basename ${line})
1096
1097                 # check if there is an extension and remove it
1098              ext=${basefilename##*.}
1099              if [[ "$ext" = "${extin_pre[$i]}" ]]
1100              then
1101                 basefilename=${basefilename%.*}
1102              fi
1103
1104                 # check for an existing cycle number and remove it
1105              cycle=${basefilename##*.}
1106              if [[ $cycle =~ ^-?[0-9]+$ ]]
1107              then
1108                 basefilename=${basefilename%.*}
1109              fi
1110
1111                 # remove the fname from the beginning
1112              length_fname=${#fname}
1113              ending=${basefilename:${length_fname}}
1114
1115                 # remove the ending given in the .iofiles from the beginning
1116              endingstring="${endin_pre[$i]}"
1117              length_ending=${#endingstring}
1118              ending=${ending:${length_ending}}
1119
1120              if [[ "$ending" = "" ]]
1121              then
1122                    # standard ending as given in the .iofiles
1123                 if [[ $(echo $endings | grep -c DEFAULT) = 0 ]]
1124                 then
1125                    endings="$endings DEFAULT"
1126                 fi
1127              else
1128                    # ending must start with "_", otherwise its a different file
1129                 if [[ "${ending:0:1}" = "_" ]]
1130                 then
1131                    if [[ $(echo $endings | grep -c "$ending") = 0 ]]
1132                    then
1133                       endings="$endings $ending"
1134                    fi
1135                 fi
1136              fi
1137 
1138          done <filelist
1139
1140          rm filelist
1141
1142       else
1143
1144             # SINGLE NAME
1145          endings=DEFAULT
1146
1147       fi
1148
1149          # FOR EACH BASENAME ENDING CREATE AN ENTRY IN THE FINAL INPUT FILE LIST
1150       for  ending  in  $endings
1151       do
1152
1153             # DEFAULT MEANS THAT THE ENDING GIVEN IN .iofiles SHALL BE USED
1154          if [[ $ending = DEFAULT ]]
1155          then
1156             ending=""
1157          fi
1158
1159             # NEW ENTRY (ENDING IS ALSO ADDED TO LOCAL FILENAME READ BY PALM!)
1160          (( nr_of_input_files = nr_of_input_files + 1 ))
1161          localin[$nr_of_input_files]="${localin_pre[$i]}"$ending
1162          optin[$nr_of_input_files]="${optin_pre[$i]}"
1163          actionin[$nr_of_input_files]="${actionin_pre[$i]}"
1164          pathin[$nr_of_input_files]="${pathin_pre[$i]}"
1165          endin[$nr_of_input_files]="${endin_pre[$i]}"$ending
1166          extin[$nr_of_input_files]="${extin_pre[$i]}"
1167
1168
1169             # GENERATE PATH AND FULL FILE NAME (then-BRANCH: FIXED FULL NAME IS GIVEN, I.E. THE
1170             # FILE IDENTIFIER IS NOT PART OF THE FILENAME))
1171          if [[ "${actionin[$nr_of_input_files]}" = di ]]
1172          then
1173             eval filename=${pathin[$nr_of_input_files]}/${endin[$nr_of_input_files]}
1174          else
1175             eval filename=${pathin[$nr_of_input_files]}/${fname}${endin[$nr_of_input_files]}
1176          fi
1177
1178             # DETERMINE THE FILE'S CYCLE NUMBER
1179          (( maxcycle = 0 ))
1180          ls -1 -d $filename    >   filelist  2>/dev/null
1181          ls -1 -d $filename.*  >>  filelist  2>/dev/null
1182          while  read line
1183          do
1184                 # filename without path (i.e. after the last "/")
1185              basefilename=$(basename ${line})
1186   
1187                 # check if there is an extension
1188              extension=${basefilename##*.}
1189              if [[ "$extension" = "${extin[$nr_of_input_files]}" ]]
1190              then
1191                 basefilename=${basefilename%.*}
1192              fi
1193   
1194                 # check for an existing cycle number
1195              cycle=${basefilename##*.}
1196              if [[ $cycle =~ ^-?[0-9]+$ ]]
1197              then
1198                    # NUMBERS WITH LEADING ZEROS ARE INTERPRETED AS OCTAL NUMBERS
1199                    # 10# EXPLICITLY SPECIFIES THE NUMBER BASE AS 10
1200                 (( icycle = $((10#$cycle)) ))
1201              else
1202                 (( icycle = 0 ))
1203              fi
1204   
1205              if (( icycle > maxcycle ))
1206              then
1207                 (( maxcycle = icycle ))
1208   
1209                    # FOR COMPATIBILITY REASONS WITH OLDER VERSIONS
1210                    # CHECK IF CYCLE NUMBER CONTAINS LEADING ZEROS
1211                 if [[ $(echo $cycle | cut -c1) = 0 ]]
1212                 then
1213                    leading_zero=true
1214                 else
1215                    leading_zero=false
1216                 fi
1217              fi
1218   
1219          done <filelist
1220          rm filelist
1221   
1222             # MAKE CYCLE NUMBER THREE DIGITS WIDE
1223          if [[ $leading_zero = true ]]
1224          then
1225             cyclestring=`printf "%03d" $maxcycle`
1226          else
1227             cyclestring=$maxcycle
1228          fi
1229   
1230             # APPEND CYCLE NUMBER TO FILENAME
1231          if (( maxcycle > 0 ))
1232          then
1233             if [[ "${extin[$nr_of_input_files]}" != " "  &&   "${extin[$nr_of_input_files]}" != "" ]]
1234             then
1235                filename=${filename}.$cyclestring.${extin[$nr_of_input_files]}
1236             else
1237                filename=${filename}.$cyclestring
1238             fi
1239          else
1240             if [[ "${extin[$nr_of_input_files]}" != " "  &&   "${extin[$nr_of_input_files]}" != "" ]]
1241             then
1242                filename=${filename}.${extin[$nr_of_input_files]}
1243             fi
1244          fi
1245         
1246             # STORE FILENAME WITHOUT PATH BUT WITH CYCLE NUMBER,
1247             # IS LATER USED FOR TRANSFERRING FILES WIHIN THE JOB (SEE END OF FILE)
1248          absnamein[$nr_of_input_files]=$filename
1249          if (( maxcycle > 0 ))
1250          then
1251             if [[ "${actionin[$nr_of_input_files]}" = di ]]
1252             then
1253                frelin[$nr_of_input_files]=${endin[$nr_of_input_files]}.$cyclestring
1254             else
1255                frelin[$nr_of_input_files]=${fname}${endin[$nr_of_input_files]}.$cyclestring
1256             fi
1257          else
1258             if [[ "${actionin[$nr_of_input_files]}" = di ]]
1259             then
1260                frelin[$nr_of_input_files]=${endin[$nr_of_input_files]}
1261             else
1262                frelin[$nr_of_input_files]=${fname}${endin[$nr_of_input_files]}
1263             fi
1264          fi
1265
1266       done
1267
1268    fi
1269
1270 done
1271
1272
1273    # GENERATE FULL FILENAMES OF OUTPUT-FILES (WITHOUT $ OR ~),
1274    # CHECK, IF OUTPUT-FILES EXIST, AND DETERMINE HIGHEST CYCLE NUMBER (IF CYCLES EXIST),
1275    # OR, IN CASE THAT FILE DOES NOT EXIST, CHECK, IF IT CAN BE CREATED 
1276    # THESE ACTIONS ARE NOT CARRIED OUT, IF FILES SHALL BE TRANSFERRED FROM THE REMOTE TO
1277    # THE LOCAL HOST (BECAUSE THEIR IS NO DIRECT ACCESS TO THE LOCAL DIRECTORIES FROM THE
1278    # REMOTE HOST)
1279 (( i = 0 ))
1280 while (( i < iout ))
1281 do
1282    (( i = i + 1 ))
1283    if [[ ! ( $running_on_remote = true  &&  ( "${actionout_pre[$i]}" = tr || "${actionout_pre[$i]}" = tra || "${actionout_pre[$i]}" = trpe ) ) ]]
1284    then
1285       if [[ "${actionout_pre[$i]}" = tr ]]
1286       then
1287          actionout_pre[$i]=""
1288       elif [[ "${actionout_pre[$i]}" = trpe ]]
1289       then
1290          actionout_pre[$i]=pe
1291       elif [[ "${actionout_pre[$i]}" = tra ]]
1292       then
1293          actionout_pre[$i]=a
1294       fi
1295       (( maxcycle = 0 ))
1296       eval filename=${pathout_pre[$i]}/${fname}${endout_pre[$i]}
1297       eval catalogname=${pathout_pre[$i]}
1298       if ! ls $filename* 1>/dev/null 2>&1
1299       then
1300     
1301             # IF OUTPUT-FILE DOES NOT EXIST CHECK, IF IT CAN BE CREATED
1302          if  cat /dev/null > $filename 
1303          then
1304             rm  $filename
1305          else
1306
1307                # CHECK, IF THE DIRECTORY WHERE FILE SHALL BE COPIED TO EXISTS
1308                # IF IT DOES NOT EXIST, TRY TO CREATE IT
1309             if [[ ! -d $catalogname ]]
1310             then
1311                if  mkdir -p  $catalogname
1312                then
1313                   printf "\n\n  *** directory:"
1314                   printf "\n           $catalogname"
1315                   printf "\n      was created\n"
1316                else
1317                   printf "\n\n  +++ OUTPUT-file:"
1318                   printf "\n           $filename"
1319                   printf "\n      cannot be created, because directory does not exist"
1320                   printf "\n      and cannot be created either"
1321                   printf "\n"
1322                   locat=output  ; exit
1323                fi 2>/dev/null
1324             else
1325                printf "\n\n  +++ OUTPUT-file:"
1326                printf "\n           $filename"
1327                printf "\n      cannot be created, although directory exists"
1328                printf "\n"
1329                locat=output  ; exit
1330             fi
1331          fi 2>/dev/null
1332
1333       fi
1334
1335    fi
1336 done
1337
1338
1339    # DETERMINE THE NAME OF PALMRUN'S TEMPORARY WORKING DIRECTORY
1340 if [[ $running_in_batch_mode = false ]]
1341 then
1342    run_id=$RANDOM
1343    job_id=${fname}.$run_id
1344
1345    tempdir=$fast_io_catalog/$job_id
1346 fi
1347
1348
1349    # CHECK SETTINGS REQUIRED FOR BATCH JOBS
1350 if [[ $create_batch_job = true  ||  $create_remote_batch_job = true ]]
1351 then
1352
1353       # CHECK, IF JOB DIRECTIVES HAVE BEEN GIVEN IN CONFIGURATION FILE
1354    if [[ $ibd = 0 ]]
1355    then
1356       printf "\n"
1357       printf "\n  +++ no batch directives found in configuration file"
1358       locat=config_file_batch_directives; (( iec = 0 )); exit
1359    fi
1360
1361       # CHECK IF CPUTIME IS GIVEN FOR JOB
1362    done=false
1363    cputime=$cpumax
1364    while [[ $done = false ]]
1365    do
1366       if (( cputime == 0 ))
1367       then
1368          printf "\n  +++ cpu-time is undefined"
1369          printf "\n  >>> Please type CPU-time in seconds as INTEGER:"
1370          printf "\n  >>> "
1371          read  cputime   1>/dev/null  2>&1
1372       else
1373          done=true
1374       fi
1375    done
1376    cpumax=$cputime
1377
1378       # CHECK THE MEMORY DEMAND
1379    done=false
1380    while [[ $done = false ]]
1381    do
1382       if (( memory == 0 ))
1383       then
1384          printf "\n  +++ memory demand is undefined"
1385          printf "\n  >>> Please type memory in  MByte per process  as INTEGER:"
1386          printf "\n  >>> "
1387          read  memory  1>/dev/null  2>&1
1388       else
1389          done=true
1390       fi
1391    done
1392
1393       # IN CASE OF REMOTE-JOBS CHECK, IF A USERNAME FOR THE REMOTE HOST IS GIVEN
1394    if [[ $create_remote_batch_job = true  &&  -z $remote_username ]]
1395    then
1396       while [[ -z $remote_username ]]
1397       do
1398          printf "\n  +++ username on remote host with IP \"$remote_ip\" is undefined"
1399          printf "\n  >>> Please type username:"
1400          printf "\n  >>> "
1401          read  remote_username
1402       done
1403    fi
1404
1405 else
1406
1407    if [[ $running_in_batch_mode = false ]]
1408    then
1409       cputime=10000000  # NO LIMT FOR INTERACTIVE RUNS
1410       cpumax=$cputime
1411    else
1412       cputime=$cpumax
1413    fi
1414
1415 fi
1416
1417
1418    # CALCULATE HOURS/MINUTES/SECONDS, E.G. FOR BATCH-DIRECTIVES
1419 (( cpu_hours  = cputime / 3600 ))
1420 (( resttime = cputime - cpu_hours * 3600 ))
1421 (( cpu_minutes  = resttime / 60 ))
1422 (( cpu_seconds = resttime - cpu_minutes * 60 ))
1423 timestring=${cpu_hours}:${cpu_minutes}:${cpu_seconds}
1424
1425
1426    # OUTPUT OF THE PALMRUN-HEADER
1427 calltime=$(date)
1428 printf "\n"
1429 printf "#------------------------------------------------------------------------# \n"
1430 printf "| %-35s%35s | \n" "$version" "$calltime"
1431 printf "|                                                                        | \n"
1432 column1="called on:"; column2=$(hostname)
1433 printf "| %-25s%-45s | \n" "$column1" "$column2"
1434 if [[ $create_remote_batch_job = true ]]
1435 then
1436    column1="execution on:"; column2="$host_configuration (username: $remote_username)"
1437 else
1438    if [[ $running_on_remote = true ]]
1439    then
1440       column1="execution on:"; column2="$host_configuration (IP:$remote_ip)"
1441    else
1442       column1="execution on:"; column2="$host_configuration (IP:$local_ip)"
1443    fi
1444 fi
1445 printf "| %-25s%-45s | \n" "$column1" "$column2"
1446
1447 column1="running in:"
1448 if [[ $running_in_batch_mode = true ]]
1449 then
1450    column2="batch job mode"
1451 else
1452    if [[ $create_batch_job = true  ||  $create_remote_batch_job = true ]]
1453    then
1454       column2="job creation mode"
1455    else
1456       column2="interactive run mode"
1457    fi
1458 fi
1459 printf "| %-25s%-45s | \n" "$column1" "$column2"
1460
1461 if  [[ $running_in_batch_mode = true  ||  $create_batch_job = true  ||  $create_remote_batch_job = true ]]
1462 then
1463    if [[ "$project_account" != "" ]]
1464    then
1465       column1="project account number:"
1466       column2="$project_account"
1467       printf "| %-25s%-45s | \n" "$column1" "$column2"
1468    fi
1469 fi
1470
1471 if [[ -n $cores ]]
1472 then
1473    if [[ $run_coupled_model = false ]]
1474    then
1475       column1="number of cores:"; column2=$cores
1476    else
1477       column1="number of cores:"; column2="$cores  (atmosphere: $cores_atmos, ocean: $cores_ocean)"
1478    fi
1479    printf "| %-25s%-45s | \n" "$column1" "$column2"
1480 fi
1481 if [[ -n $tasks_per_node ]]
1482 then
1483    column1="tasks per node:"; column2="$tasks_per_node (number of nodes: $nodes)"
1484    printf "| %-25s%-45s | \n" "$column1" "$column2"
1485    if (( remaining_cores > 0 ))
1486    then
1487       column1=" "; column2="one of the nodes only filled with $remaining_cores tasks"
1488       printf "| %-25s%-45s | \n" "$column1" "$column2"
1489    fi
1490 fi
1491 if [[ $maximum_parallel_io_streams != $cores ]]
1492 then
1493    column1="max par io streams:"; column2="$maximum_parallel_io_streams"
1494    printf "| %-25s%-45s | \n" "$column1" "$column2"
1495 fi
1496 if [[ $use_openmp = true ]]
1497 then
1498    column1="threads per task:"; column2="$threads_per_task"
1499    printf "| %-25s%-45s | \n" "$column1" "$column2"
1500 fi
1501 if [[ $create_batch_job = true  ||  $create_remote_batch_job = true  ||  $running_in_batch_mode = true ]]
1502 then
1503    column1="memory demand / PE":; column2="$memory MB"
1504    printf "| %-25s%-45s | \n" "$column1" "$column2"
1505    column1="job cpu time (h:m:s):"; column2="$timestring"
1506    printf "| %-25s%-45s | \n" "$column1" "$column2"
1507 fi
1508 printf "|                                                                        | \n"
1509 if [[ "$source_list" != "" ]]
1510 then
1511    if [[ "$make_options" != "" ]]
1512    then
1513       column1="make options:"; column2=$(echo "$make_options" | cut -c-45)
1514       printf "| %-25s%-45s | \n" "$column1" "$column2"
1515       line=$(echo "$make_options" | cut -c46-)
1516       while [[ "$line" != "" ]]
1517       do
1518          column1=""
1519          column2=$(echo "$line" | cut -c-45)
1520          printf "| %-25s%-45s | \n" "$column1" "$column2"
1521          line=$(echo "$line" | cut -c46-)
1522       done
1523    fi
1524 fi
1525
1526 column1="cpp directives:"; column2=$(echo "$cpp_options" | cut -c-45)
1527 printf "| %-25s%-45s | \n" "$column1" "$column2"
1528 line=$(echo "$cpp_options" | cut -c46-)
1529 while [[ "$line" != "" ]]
1530 do
1531    column1=""
1532    column2=$(echo "$line" | cut -c-45)
1533    printf "| %-25s%-45s | \n" "$column1" "$column2"
1534    line=$(echo "$line" | cut -c46-)
1535 done
1536
1537 column1="compiler options:"; column2=$(echo "$compiler_options" | cut -c-45)
1538 printf "| %-25s%-45s | \n" "$column1" "$column2"
1539 line=$(echo "$compiler_options" | cut -c46-)
1540 while [[ "$line" != "" ]]
1541 do
1542    column1=""
1543    column2=$(echo "$line" | cut -c-45)
1544    printf "| %-25s%-45s | \n" "$column1" "$column2"
1545    line=$(echo "$line" | cut -c46-)
1546 done
1547
1548 column1="linker options:"; column2=$(echo "$linker_options" | cut -c-45)
1549 printf "| %-25s%-45s | \n" "$column1" "$column2"
1550 line=$(echo "$linker_options" | cut -c46-)
1551 while [[ "$line" != "" ]]
1552 do
1553    column1=""
1554    column2=$(echo "$line" | cut -c-45)
1555    printf "| %-25s%-45s | \n" "$column1" "$column2"
1556    line=$(echo "$line" | cut -c46-)
1557 done
1558
1559 if [[ "$login_init_cmd" != "" ]]
1560 then
1561    column1="login init commands:"; column2=$(echo "$login_init_cmd" | cut -c-45)
1562    printf "| %-25s%-45s | \n" "$column1" "$column2"
1563    line=$(echo "$login_init_cmd" | cut -c46-)
1564    while [[ "$line" != "" ]]
1565    do
1566       column1=""
1567       column2=$(echo "$line" | cut -c-45)
1568       printf "| %-25s%-45s | \n" "$column1" "$column2"
1569       line=$(echo "$line" | cut -c46-)
1570    done
1571 fi
1572
1573 if [[ "$module_commands" != "" ]]
1574 then
1575    column1="module commands:"; column2=$(echo "$module_commands" | cut -c-45)
1576    printf "| %-25s%-45s | \n" "$column1" "$column2"
1577    line=$(echo "$module_commands" | cut -c46-)
1578    while [[ "$line" != "" ]]
1579    do
1580       column1=""
1581       column2=$(echo "$line" | cut -c-45)
1582       printf "| %-25s%-45s | \n" "$column1" "$column2"
1583       line=$(echo "$line" | cut -c46-)
1584    done
1585 fi
1586 printf "|                                                                        | \n"
1587 column1="base name of files:"; column2=$fname
1588 printf "| %-25s%-45s | \n" "$column1" "$column2"
1589 column1="activation string list:"; column2=$(echo $activation_string_list)
1590 printf "| %-25s%-45s | \n" "$column1" "$column2"
1591
1592 if [[ "$ocean_file_appendix" = true ]]
1593 then
1594    printf "| %-35s%-35s | \n" "suffix \"_O\" is added to local files" " "
1595 fi
1596
1597 if [[ "$source_list" != "" ]]
1598 then
1599    printf "|                                                                        | \n"
1600    printf "| Files to be compiled:                                                  | \n"
1601    line=$source_list
1602    while [[ "$line" != "" ]]
1603    do
1604       linestart=$(echo $line | cut -c-70)
1605       printf "| %-70s | \n" "$linestart"
1606       line=$(echo "$line" | cut -c71-)
1607    done
1608 fi
1609 printf "#------------------------------------------------------------------------#"
1610
1611
1612
1613    # OUTPUT OF FILE CONNECTIONS IN CASE OF TRACEBACK
1614 if [[ $do_trace = true ]]
1615 then
1616    (( i = 0 ))
1617    while (( i < nr_of_input_files ))
1618    do
1619       (( i = i + 1 ))
1620       if (( i == 1 ))
1621       then
1622          printf "\n\n >>> INPUT-file assignments:\n"
1623       fi
1624       printf "\n     ${localin[$i]} :  ${absnamein[$i]}"
1625    done
1626    (( i = 0 ))
1627    while (( i < iout ))
1628    do
1629       (( i = i + 1 ))
1630       if (( i == 1 ))
1631       then
1632          printf "\n\n >>> OUTPUT-file assignments:\n"
1633       fi
1634       printf "\n     ${localout[$i]} :  ${pathout[$i]}"
1635    done
1636    (( i = 0 ))
1637    while (( i < iic ))
1638    do
1639       (( i = i + 1 ))
1640       if (( i == 1 ))
1641       then
1642          printf "\n\n >>> INPUT-commands:\n"
1643       fi
1644       printf "\n     ${in_command[$i]}" 
1645    done
1646    (( i = 0 ))
1647    while (( i < ioc ))
1648    do
1649       (( i = i + 1 ))
1650       if (( i == 1 ))
1651       then
1652          printf "\n\n >>> OUTPUT-commands:\n"
1653       fi
1654       printf "\n     ${out_command[$i]}" 
1655    done
1656 fi
1657
1658    # QUERY FOR CONTINUE
1659 if [[ $silent = false  &&  $running_in_batch_mode = false ]]
1660 then
1661    antwort=dummy
1662    printf "\n\n"
1663    printf " >>> everything o.k. (y/n) ?  "
1664    while  read antwort
1665    do
1666       if [[ "$antwort" != y  &&  "$antwort" != Y  &&  "$antwort" != n  &&  "$antwort" != N ]]
1667       then
1668          printf " >>> everything o.k. (y/n) ?  "
1669       else
1670          break
1671       fi
1672    done
1673    if [[ $antwort = n  ||  $antwort = N ]]
1674    then
1675       locat=user_abort; (( iec = 0 )); exit
1676    fi
1677    if [[ $create_batch_job = true  ||  $create_remote_batch_job = true ]]
1678    then
1679       printf "\n ***  batch-job will be created and submitted"
1680    else
1681       printf "\n ***  PALMRUN will now continue to execute on this machine"
1682    fi
1683 fi
1684
1685 
1686
1687    # PROVIDE FILES TO EXECUTE PALM AND CREATE THE EXECUTABLE
1688 if [[ $restart_run = false  &&  $running_in_batch_mode = false ]]
1689 then
1690
1691    if [[ $create_batch_job = true  ||  $create_remote_batch_job  = true ]]
1692    then
1693       printf "\n\n  *** creating executable and other sources for the remote host\n"
1694    else
1695       printf "\n\n  *** creating executable and other sources for the local host\n"
1696    fi
1697
1698       # FIRST CHECK, IF A MAKE DEPOSITORY EXISTS, AND IF NOT, ASK THE USER IF
1699       # IT SHALL BE CREATED
1700    ask_for_make_depository=false
1701    if [[ $create_remote_batch_job = true ]]
1702    then
1703
1704       line=`grep %base_directory $config_file`
1705       make_depository=`echo $line | cut -d" " -s -f2`/MAKE_DEPOSITORY_${host_configuration}
1706       echo  "[[ ! -d ${make_depository} ]]  &&  echo depository not found" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1  | tee ${host_configuration}_last_make_protokoll
1707
1708       if [[ $(grep -c "depository not found" ${host_configuration}_last_make_protokoll) != 0 ]]
1709       then
1710          printf "\n\n  +++ make depository \"${make_depository}\""
1711          printf "\n      on remote host not found!"
1712          ask_for_make_depository=true
1713       fi
1714       rm ${host_configuration}_last_make_protokoll
1715
1716    else
1717
1718          # CHECK FOR MAKE_DEPOSITORY ON THE LOCAL HOST
1719       make_depository=${base_directory}/MAKE_DEPOSITORY_${host_configuration}
1720       if [[ ! -d ${make_depository} ]]
1721       then
1722          printf "\n\n  +++ make depository \"${make_depository}\""
1723          printf "\n      on local host not found!"
1724          ask_for_make_depository=true
1725       fi
1726
1727    fi
1728
1729    if [[ $ask_for_make_depository = true ]]
1730    then
1731
1732       antwort=dummy
1733       printf "\n\n"
1734       printf "  >>> Create a new one (y/n) ?  "
1735       while  read antwort
1736       do
1737          if [[ "$antwort" != y  &&  "$antwort" != Y  &&  "$antwort" != n  &&  "$antwort" != N ]]
1738          then
1739             printf "  >>> Create a new one (y/n) ?  "
1740          else
1741             break
1742          fi
1743       done
1744       if [[ $antwort = n  ||  $antwort = N ]]
1745       then
1746          locat=user_abort; (( iec = 0 )); exit
1747       fi
1748
1749       if [[ $do_trace = true ]]
1750       then
1751          palmbuild  -h $host_configuration
1752       else
1753          palmbuild  -v  -h $host_configuration
1754       fi
1755
1756       if [[ $? != 0 ]]
1757       then
1758   
1759              # ABORT IN CASE OF COMPILATION PROBLEMS
1760          printf "\n  +++ error while compiling for the MAKE_DEPOSITORY"
1761          locat=make_depository
1762          exit
1763       else
1764          echo "  *** now continue with creating executable and other sources"
1765       fi
1766
1767    fi
1768
1769       # NOW CREATE THE SOURCES_FOR_RUN FOLDER
1770    palmbuild  -v  $use_existing_sources_folder  -h $host_configuration  -d $fname
1771
1772    if [[ $? != 0 ]]
1773    then
1774
1775           # ABORT IN CASE OF COMPILATION PROBLEMS
1776       printf "\n  +++ error while creating executable and/or other sources"
1777       locat=execution
1778       rm -rf  $sources_for_run_catalog
1779       exit
1780
1781    else
1782
1783       printf "  *** executable and other sources created\n"
1784       rm -rf  $sources_for_run_catalog
1785
1786    fi
1787
1788 fi
1789
1790
1791    # WHEN CREATING A REMOTE BATCH JOB, THOSE INPUT FILES WITH TRANSFER-ATTRIBUT
1792    # WILL BE COPIED TO THE REMOTE HOST
1793 if [[ $create_remote_batch_job = true ]]
1794 then
1795    (( i = 0 ))
1796    while (( i < nr_of_input_files ))
1797    do
1798       (( i = i + 1 ))
1799       if [[ "${actionin[$i]}" = tr ]]
1800       then
1801          eval inputfile=${pathin[$i]}/${frelin[$i]}
1802          scp  -q $ssh_key  $PORTOPT  $inputfile  ${remote_username}@${remote_ip}:${fast_io_catalog}/${sources_for_run_catalog}/${frelin[$i]}
1803       fi
1804    done
1805    if (( i > 0 ))
1806    then
1807       printf "  *** input files have been copied to the remote host\n"
1808    fi
1809 fi
1810 
1811
1812    # NOW PERFORM THOSE ACTIONS REQUIRED TO EXECUTE THE PROGRAM (PALM) ON THIS MACHINE
1813    # (COMPILING/LINKING, EXECUTING, COPYING I/O FILES)
1814 if [[ $create_batch_job = false  &&  $create_remote_batch_job = false ]]
1815 then
1816
1817       # CHANGE TO THE TEMPORARY WORKING DIRECTORY
1818    if [[ $running_in_batch_mode = false ]]
1819    then
1820          # CREATE THE DIRECTORY AND COPY FILES FROM SOURCES_FOR_RUN_... TO THAT
1821          # FOLDER
1822       mkdir -p  $tempdir
1823       chmod  go+rx  $tempdir
1824       cd  $tempdir
1825       cp  ${fast_io_catalog}/${sources_for_run_catalog}/{*,.[!.]*}  $tempdir
1826       printf "\n  *** changed to temporary directory: $tempdir"
1827
1828    else
1829
1830          # IN BATCH MODE PALMRUN IS CALLED FROM TEMPDIR
1831       printf "\n  *** running in temporary directory: $tempdir"
1832
1833    fi
1834
1835
1836       # PROVIDE THE INPUT FILES
1837       # LOOP OVER ALL ACTIVATED FILES (LISTED IN THE CONFIGURATION FILE)
1838    optional_files_missing=false
1839    (( i = 0 ))
1840    while (( i < nr_of_input_files ))
1841    do
1842       (( i = i + 1 ))
1843       if (( i == 1 ))
1844       then
1845          printf "\n\n  *** providing INPUT-files:\n$dashes"
1846       fi
1847
1848
1849          # SKIP OPTIONAL FILES, IF THEY DO NOT EXIST
1850       if [[ "${actionin[$i]}" = unavailable ]]
1851       then
1852          optional_files_missing=true
1853          continue
1854       fi
1855
1856          # CHECK FOR SINGLE FILE (SERIAL RUN) OR DIRECTORY (ONE FILE PER CORE FOR PARELLEL EXECUTION)
1857       files_for_cores=false; filetype=file
1858       if [[ "${actionin[$i]}" = pe  &&  -n $cores ]]
1859       then
1860          files_for_cores=true; filetype=files
1861          actionin[$i]=""
1862       elif [[ "${actionin[$i]}" = pe  &&  ! -n $cores ]]
1863       then
1864          actionin[$i]=""
1865       elif [[ "${actionin[$i]}" = lnpe  &&  -n $cores ]]
1866       then
1867          files_for_cores=true; filetype=files
1868          actionin[$i]="ln"
1869       elif [[ "${actionin[$i]}" = lnpe  &&  ! -n $cores ]]
1870       then
1871          actionin[$i]="ln"
1872       fi
1873
1874       if [[ $files_for_cores = true ]]
1875       then
1876          printf "\n  >>> INPUT: ${absnamein[$i]}/....  to  ${localin[$i]}"
1877       else
1878          printf "\n  >>> INPUT: ${absnamein[$i]}  to  ${localin[$i]}"
1879       fi
1880
1881          # INPUT-FILES TO BE LINKED
1882       if [[ "${actionin[$i]}" = ln ]]
1883       then
1884
1885          printf "\n      $filetype will be linked"
1886          if [[ $files_for_cores = false ]]
1887          then
1888             if [[ -f "${absnamein[$i]}" ]]
1889             then
1890                ln  ${absnamein[$i]}  ${localin[$i]}
1891                got_tmp[$i]=true
1892             fi
1893          else
1894             if [[ -d "${absnamein[$i]}" ]]
1895             then
1896                mkdir -p ${localin[$i]}
1897                cd ${absnamein[$i]}
1898                for file in $(ls *)
1899                do
1900                   ln $file $tempdir/${localin[$i]}
1901                done >|/dev/null 2>&1
1902                cd $tempdir
1903             fi
1904
1905                # IF "ln -f" HAS FAILED DO A NORMAL COPY "cp -r"
1906             if [[ ! -f "${localin[$i]}/_000000" ]]
1907             then
1908                printf "\n  --- WARNING: ln failed, using cp instead (might be time consuming...)"
1909                cp -r  ${absnamein[$i]}/*  ${localin[$i]}
1910             fi
1911
1912             got_tmp[$i]=true
1913          fi
1914       fi
1915
1916          # FILE IS STORED IN THE RESPECTIVE DIRECTORY GIVEN IN THE CONFIGURATION FILE
1917       if [[ "${actionin[$i]}" = ""  ||  "${actionin[$i]}" = "di"  ||  "${actionin[$i]}" = "tr"  ||  "${actionin[$i]}" = "npe" ]]
1918       then
1919
1920          if [[ "${actionin[$i]}" = "npe"  &&  -n $cores ]]
1921          then
1922
1923                # FILE COPIES ARE PROVIDED FOR ALL CORES
1924                # EACH FILE GETS A UNIQUE FILENAME WITH A FOUR DIGIT NUMBER
1925             printf "\n      file will be provided for $cores processors"
1926             mkdir -p ${localin[$i]}
1927             ival=$cores
1928             (( ii = 0 ))
1929             while (( ii <= ival-1 ))
1930             do
1931                if (( ii < 10 ))
1932                then
1933                   cp  ${absnamein[$i]}  ${localin[$i]}/_000$ii
1934                elif (( ii < 100 ))
1935                then
1936                   cp  ${absnamein[$i]}  ${localin[$i]}/_00$ii
1937                elif (( ii < 1000 ))
1938                then
1939                   cp  ${absnamein[$i]}  ${localin[$i]}/_0$ii
1940                else
1941                   cp  ${absnamein[$i]}  ${localin[$i]}/_$ii
1942                fi
1943                (( ii = ii + 1 ))
1944             done
1945
1946          else
1947
1948             if [[ $files_for_cores = true ]]
1949             then
1950
1951                   # PROVIDE FILES FOR EACH CORE
1952                   # FIRST CREATE THE LOCAL DIRECTORY, THEN COPY FILES
1953                   # FROM THE PERMANENT DIRECTORY BY LINKING THEM TO THE LOCAL ONE
1954                printf "\n      providing $cores files for the respective cores"
1955                mkdir -p ${localin[$i]}
1956                        if [[ $link_local_input = true ]]
1957                              then
1958                                 printf "      files will be linked\n"
1959                                 cd ${absnamein[$i]}
1960                                 for file in $(ls *)
1961                                 do
1962                                    ln -f $file  ${localin[$i]}
1963                                 done
1964                                 cd $tempdir
1965                              fi
1966
1967                   # IF "ln -f" FAILED OR IF "$link_local_input = false" DO A NORMAL "cp -r"
1968                              if [[ ! -f "${localin[$i]}/_000000" ]]
1969                              then
1970                                 if [[ $link_local_input = true ]]
1971                                        then
1972                                        printf "\n  --- WARNING: ln failed, using cp instead (might be time consuming...)"
1973                                 fi
1974                                 cp -r  ${absnamein[$i]}/*  ${localin[$i]}
1975                              fi
1976
1977             else
1978
1979                   # PROVIDE FILE FOR RUNS ON A SINGLE CORE
1980                        if [[ $link_local_input = true ]]
1981                        then
1982                                 printf "      file will be linked\n"
1983                                 ln -f  ${absnamein[$i]}  ${localin[$i]}
1984                        fi
1985                                # If "ln -f" fails or if "$link_local_input = false" do a normal "cp"
1986                        if [[ ! -f "${localin[$i]}" ]]
1987                then
1988                                 if [[ $link_local_input = true ]]
1989                          then
1990                      printf "\n  --- WARNING: ln failed, using cp instead (might be time consuming...)"
1991                                 fi
1992                   if [[ $running_on_remote = true  &&  "${actionin[$i]}" = tr ]]
1993                   then
1994                      mv  ${absnamein[$i]}  ${localin[$i]}
1995                   else
1996                                 cp  ${absnamein[$i]}  ${localin[$i]}
1997                   fi
1998                fi
1999             fi
2000          fi
2001       fi
2002
2003    done
2004    if (( i != 0 ))
2005    then
2006       if [[ $optional_files_missing = true ]]
2007       then
2008          printf "\n  *** INFORMATIVE: some optional INPUT-files are not present"
2009       fi
2010       printf "\n$dashes\n  *** all INPUT-files provided \n"
2011    fi
2012
2013
2014       # EXECUTE INPUT-COMMANDS GIVEN IN THE CONFIGURATION FILE
2015    (( i = 0 ))
2016    while (( i < iic ))
2017    do
2018       (( i = i + 1 ))
2019       if (( i == 1 ))
2020       then
2021          printf "\n\n  *** execution of INPUT-commands:\n$dashes"
2022       fi
2023       printf "\n  >>> ${in_command[$i]}"
2024       eval  ${in_command[$i]}
2025       if (( i == iic ))
2026       then
2027          printf "\n$dashes\n"
2028       fi
2029    done
2030
2031
2032       # CREATE THE NAMELIST-FILE WITH VALUES OF ENVIRONMENT-VARIABLES REQUIRED BY PALM
2033       # (FILE ENVPAR WILL BE READ BY PALM)
2034    cat  >  ENVPAR  <<  EOF
2035 &envpar  run_identifier = '$fname', host = '$host_configuration',
2036          write_binary = .${write_binary}., tasks_per_node = $tasks_per_node,
2037          maximum_parallel_io_streams = $maximum_parallel_io_streams,
2038          maximum_cpu_time_allowed = ${cpumax}.,
2039          revision = '$global_revision',
2040          batch_job = .${running_in_batch_mode}. /
2041
2042EOF
2043
2044
2045       # STARTING THE EXECUTABLE
2046    printf "\n\n  *** execution starts in directory\n      \"`pwd`\"\n$dashes\n"
2047    PATH=$PATH:$tempdir
2048
2049
2050       # REPLACE PARAMETERS IN THE EXECUTION COMMAND WITH REAL VALUES
2051    line=`echo  "${execute_command}" | sed 's/{{MPI_TASKS}}/$mpi_tasks/g' | sed 's/{{TASKS_PER_NODE}}/$tasks_per_node/g'`
2052    line2=`echo  "${execute_command}" | sed 's/{{MPI_TASKS}}/1/g' | sed 's/{{TASKS_PER_NODE}}/1/g' | sed 's/palm/combine_plot_fields.x/g'`
2053    eval line=\"$line\"
2054    execute_command="$line"
2055
2056
2057       # EXECUTION COMMAND FOR COMBINE_PLOT_FIELDS
2058    if [[ "$execute_command_for_combine" = "" ]]
2059    then
2060       eval line2=\"$line2\"
2061       execute_command_for_combine="$line2"
2062    fi
2063   
2064
2065
2066       # PROVIDE A HOSTFILE, IF REQUIRED
2067    if [[ "$hostfile" != "" ]]
2068    then
2069
2070       if [[ $hostfile = auto ]]
2071       then
2072             # CREATE A NEW HOSTFILE
2073          (( ii = 1 ))
2074          while (( ii <= cores / threads_per_task ))
2075          do
2076             echo  $(hostname)  >>  hostfile
2077             (( ii = ii + 1 ))
2078          done
2079          if (( cores / threads_per_task == 0 ))
2080          then
2081             echo  $(hostname)  >>  hostfile
2082          fi
2083       
2084       else
2085          cp  $hostfile  hostfile
2086       fi
2087       eval line=\"`head -n $ii  hostfile`\"
2088       printf "\n  *** running on: $line"
2089    fi
2090
2091
2092
2093       # SET THE NUMBER OF OPENMP-THREADS
2094    if [[ $use_openmp = true ]]
2095    then
2096       export OMP_NUM_THREADS=$threads_per_task
2097       printf "\n  *** number of OpenMP threads per MPI-task: $OMP_NUM_THREADS"
2098    else
2099       export OMP_NUM_THREADS=1
2100    fi
2101
2102
2103       # PROVIDE DATA FOR ATMOSPHERE OCEAN COUPLING
2104    if [[ $run_coupled_model = false ]]
2105    then
2106       if [[ "$ocean_file_appendix" = true ]]
2107       then
2108          echo "precursor_ocean"  >  coupling_steering
2109       else
2110          echo "precursor_atmos"  >  coupling_steering
2111      fi
2112    else
2113       (( iia = $cores_atmos / $threads_per_task ))
2114       (( iio = $cores_ocean / $threads_per_task ))
2115       printf "\n      coupled run ($iia atmosphere, $iio ocean)"
2116       printf "\n\n"
2117       echo "coupled_run $iia $iio"  >  coupling_steering
2118    fi
2119
2120    printf "\n  *** execute command:"
2121    printf "\n      \"$execute_command\" \n\n"
2122
2123    $execute_command  <  coupling_steering
2124
2125    if [[ $? != 0 ]]
2126    then
2127
2128           # ABORT IN CASE OF RUNTIME ERRORS
2129       printf "\n  +++ runtime error occured"
2130       locat=execution
2131       exit
2132
2133    else
2134
2135       printf "\n$dashes\n  *** execution finished \n"
2136
2137    fi
2138
2139
2140       # CALL OF combine_plot_fields IN ORDER TO MERGE SINGLE FILES WRITTEN
2141       # BY EACH CORE INTO ONE FILE
2142   if [[ ! -f combine_plot_fields.x ]]
2143   then
2144
2145      printf "\n\n\n  +++ WARNING: no combine_plot_fields found"
2146      printf "\n      2d- and/or 3d-data may be incomplete!"
2147      printf "\n      Your previous palmbuild may have failed. Please check.\n"
2148
2149   elif [[ "$combine_plot_fields" == true ]]
2150   then
2151
2152      printf "\n\n\n *** post-processing: now executing \"$execute_command_for_combine\" ..."
2153      $execute_command_for_combine
2154
2155   else
2156
2157         # TEMPORARY SOLUTION TO SKIP combine_plot_fields. THIS IS REQUIRED IN CASE OF HUGE AMOUNT OF
2158         # DATA OUTPUT
2159      printf "\n\n\n *** post-processing: skipping combine_plot_fields (-Z option set) ..."
2160   fi
2161
2162
2163
2164       # EXECUTE OUTPUT-COMMANDS GIVEN IN THE CONFIGURATION FILE
2165    (( i = 0 ))
2166    while (( i < ioc ))
2167    do
2168       (( i = i + 1 ))
2169       if (( i == 1 ))
2170       then
2171          printf "\n\n  *** execution of OUTPUT-commands:\n$dashes"
2172       fi
2173       printf "\n  >>> ${out_command[$i]}"
2174       eval  ${out_command[$i]}
2175       if (( i == ioc ))
2176       then
2177          printf "\n$dashes\n"
2178       fi
2179    done
2180
2181
2182       # IN A FIRST PASS, ADD ADDITIONAL OUTPUT FILE CONNECTIONS IN CASE OF
2183       # WILDCARDS
2184    (( i = 0 ))
2185    (( nr_of_output_files = 0 ))
2186
2187    while (( i < iout ))
2188    do
2189
2190       (( i = i + 1 ))
2191
2192          # FIRST CHECK FOR MULTIPLE NAMES WITH THE SAME LOCAL NAME AND
2193          # CREATE A LIST FOR THE DETECTED ENDINGS
2194       if [[ "${multout[$i]}" = true ]]
2195       then
2196             # DETERMINE THE EXISTING EXTENSIONS FROM THE LIST OF FILES
2197          ls -1 -d ${localout_pre[$i]}    >   filelist  2>/dev/null
2198          ls -1 -d ${localout_pre[$i]}_*  >>  filelist  2>/dev/null
2199
2200          endings="DEFAULT"
2201          while  read line
2202          do
2203                 # remove the local name from the beginning
2204              localnamestring="${localout_pre[$i]}"
2205              length_localname=${#localnamestring}
2206              ending=${line:${length_localname}}
2207
2208              if [[ "$ending" != "" ]]
2209              then
2210                 endings="$endings $ending"
2211              fi
2212 
2213          done <filelist
2214
2215          rm filelist
2216
2217       else
2218
2219             # SINGLE NAME
2220          endings=DEFAULT
2221
2222       fi
2223
2224          # FOR EACH BASENAME ENDING CREATE AN ENTRY IN THE FINAL OUTPUT FILE LIST
2225       for  ending  in  $endings
2226       do
2227
2228             # DEFAULT MEANS THAT THE ENDING GIVEN IN .iofiles SHALL BE USED
2229          if [[ $ending = DEFAULT ]]
2230          then
2231             ending=""
2232          fi
2233
2234             # NEW ENTRY (ENDING IS ALSO ADDED TO LOCAL FILENAME READ BY PALM!)
2235          (( nr_of_output_files = nr_of_output_files + 1 ))
2236          localout[$nr_of_output_files]="${localout_pre[$i]}"$ending
2237          transout[$nr_of_output_files]="${transout_pre[$i]}"
2238          actionout[$nr_of_output_files]="${actionout_pre[$i]}"
2239          pathout[$nr_of_output_files]="${pathout_pre[$i]}"
2240          endout[$nr_of_output_files]="${endout_pre[$i]}"$ending
2241          extout[$nr_of_output_files]="${extout_pre[$i]}"
2242          warnout[$nr_of_output_files]="${warnout_pre[$i]}"
2243
2244       done
2245
2246    done
2247
2248
2249
2250
2251       # COPY LOCAL OUTPUT-FILES TO THEIR PERMANENT DESTINATIONS
2252    (( i = 0 ))
2253    while (( i < nr_of_output_files ))
2254    do
2255       (( i = i + 1 ))
2256       if (( i == 1 ))
2257       then
2258          printf "\n\n  *** saving OUTPUT-files:"
2259
2260             # GET RUN NUMBER ASSIGNED BY PALM
2261          if [[ -f RUN_NUMBER ]]
2262          then
2263              read  run_number  <  RUN_NUMBER
2264              printf "\n  *** PALM generated run_number = "$run_number" will be used as unified cycle number for all output files"
2265              usecycle_option="-U $run_number"
2266          else
2267              run_number=0
2268              usecycle_option=""
2269          fi
2270          if [[ $running_on_remote = true  &&  "$remote_loginnode" != "" ]]
2271          then
2272             printf "\n  *** in case of SCP transfers to local host"
2273             printf "\n      they will be done via remote login-node \"$remote_loginnode\" "
2274          fi
2275          printf "\n$dashes"
2276       fi
2277
2278       if [[ ! ( $running_on_remote = true  &&  ( "${actionout[$i]}" = tr || "${actionout[$i]}" = tra || "${actionout[$i]}" = trpe ) ) ]]
2279       then
2280
2281          eval filename=${pathout[$i]}/${fname}${endout[$i]}
2282
2283             # DETERMINE THE CYCLE NUMBER
2284          ls -1 -d $filename    >   filelist  2>/dev/null
2285          ls -1 -d $filename.*  >>  filelist  2>/dev/null
2286          while  read line
2287          do
2288   
2289                # filename without path (i.e. after the last "/")
2290             basefilename=$(basename ${line})
2291   
2292                # check if there is an extension
2293             extension=${basefilename##*.}
2294             if [[ "$extension" = "${extout[$i]}" ]]
2295             then
2296                basefilename=${basefilename%.*}
2297             fi
2298   
2299                # check for an existing cycle number
2300             cycle=${basefilename##*.}
2301             if [[ $cycle =~ ^-?[0-9]+$ ]]
2302             then
2303                   # NUMBERS WITH LEADING ZEROS ARE INTERPRETED AS OCTAL NUMBERS
2304                   # 10# EXPLICITLY SPECIFIES THE NUMBER BASE AS 10
2305                (( icycle = $((10#$cycle)) + 1 ))
2306             else
2307                (( icycle = 1 ))
2308             fi
2309   
2310             if (( icycle > maxcycle ))
2311             then
2312                (( maxcycle = icycle ))
2313             fi
2314   
2315          done <filelist
2316          rm filelist
2317
2318   
2319             # SET THE CYCLE NUMBER
2320             # IN CASE OF FILE-APPEND, IT MUST BE THE HIGHEST EXISTING CYCLE NUMBER
2321          if [[ "${actionout[$i]}" = a ]]
2322          then
2323             (( maxcycle = maxcycle - 1 ))
2324          fi
2325         
2326          (( cycnum[$i] = maxcycle ))
2327          pathout[$i]=$filename
2328
2329
2330             # ADD CYCLE NUMBER TO FILENAME
2331             # IN APPEND MODE, FILES KEEP THEIR CURRENT CYCLE NUMBER
2332          if [[ "${actionout[$i]}" != "a" ]]
2333          then
2334                # SET RUN NUMBER AS CYCLE NUMBER, IF THERE IS NOT A CONFLICT
2335                # WITH AN EXISTING CYCLE NUMBER
2336             if (( run_number >= cycnum[$i] ))
2337             then
2338                (( cycnum[$i] = run_number ))
2339             else
2340                if (( run_number > 0 ))
2341                then
2342                   printf "\n  --- INFORMATIVE: The following file cannot get a unified cycle number"
2343                fi
2344             fi
2345          fi
2346          if (( cycnum[$i] > 0 ))
2347          then
2348             cyclestring=`printf "%03d" ${cycnum[$i]}`
2349             pathout[$i]=${pathout[$i]}.$cyclestring
2350          fi
2351       fi           
2352
2353          # CHECK FOR SINGLE FILE (SERIAL RUN) OR DIRECTORY (ONE FILE PER CORE FOR PARELLEL EXECUTION)
2354       files_for_cores=false; filetype=file
2355       link_local_output=false
2356       if [[ "${actionout[$i]}" = pe  &&  -n $cores ]]
2357       then
2358          files_for_cores=true; filetype=directory
2359          actionout[$i]=""
2360       elif [[ "${actionout[$i]}" = pe  &&  ! -n $cores ]]
2361       then
2362          actionout[$i]=""
2363       elif [[ "${actionout[$i]}" = lnpe  &&  -n $cores ]]
2364       then
2365          files_for_cores=true; filetype=directory
2366          link_local_output=true
2367          actionout[$i]=""
2368       elif [[ "${actionout[$i]}" = lnpe  &&  ! -n $cores ]]
2369       then
2370          link_local_output
2371          actionout[$i]=""
2372       elif [[ "${actionout[$i]}" = trpe  &&  -n $cores ]]
2373       then
2374          files_for_cores=true; filetype=directory
2375          actionout[$i]="tr"
2376       elif [[ "${actionout[$i]}" = trpe  &&  ! -n $cores ]]
2377       then
2378          actionout[$i]="tr"
2379       fi
2380
2381       if [[ ! -f ${localout[$i]}  &&  $files_for_cores = false ]]
2382       then
2383          if [[ ${warnout[$i]} = true ]]
2384          then
2385             printf "\n  +++ temporary OUTPUT-file  ${localout[$i]}  does not exist\n"
2386          fi
2387       elif [[ ! -d ${localout[$i]}  &&  $files_for_cores = true ]]
2388       then
2389          if [[ ${warnout[$i]} = true ]]
2390          then
2391             printf "\n  +++ temporary OUTPUT-file  ${localout[$i]}/....  does not exist\n"
2392          fi
2393       else
2394
2395
2396             # COPY VIA SCP TO LOCAL HOST (ALWAYS IN BINARY MODE USING batch_scp option -m)
2397             # IF TARGET DIRECTORY DOES NOT EXISTS, TRY TO CREATE IT
2398          if [[ "${actionout[$i]}" = tr  ||  "${actionout[$i]}" = tra ]]
2399          then
2400             if [[ $running_on_remote = true ]]
2401             then
2402
2403                   # SET OPTIONS FOR TRANSFER
2404                if [[ "${actionout[$i]}" = tr ]]
2405                then
2406                   if [[ $files_for_cores = false ]]
2407                   then
2408                      catalog_option=""
2409                      catalog_string=""
2410                   else
2411                      catalog_option="-c"
2412                      catalog_string="/"
2413                   fi
2414                   append_option=""
2415                   append_string=""
2416                else
2417                   append_option="-A"
2418                   append_string="append"
2419                fi
2420
2421                transfer_failed=false
2422                printf "\n  >>> OUTPUT: ${localout[$i]}$catalog_string  $append_string by SCP to"
2423                printf "\n              ${pathout[$i]}/${host_configuration}_${fname}${endout[$i]}$catalog_string\n"
2424
2425                   # TRANSFER VIA SCP
2426                if [[ "$remote_loginnode" != "" ]]
2427                then
2428                   echo "cd $tempdir; ${fast_io_catalog}/${sources_for_run_catalog}/batch_scp $PORTOPT $catalog_option $append_option -b -m $usecycle_option -u $local_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${host_configuration}_${fname}${endout[$i]}  ${extout[$i]}"  |  ssh -q $remote_username@$remote_loginnode
2429                else
2430                   batch_scp $PORTOPT $catalog_option $append_option -b -m $usecycle_option -u $local_username $return_address  ${localout[$i]} "${pathout[$i]}" ${host_configuration}_${fname}${endout[$i]}  ${extout[$i]}
2431                fi
2432                [[ $? != 0 ]]  &&  transfer_failed=true
2433
2434
2435                   # IF TRANSFER FAILED, CREATE BACKUP COPY ON THIS MACHINE
2436                if [[ $transfer_failed = true ]]
2437                then
2438                   printf "  +++ transfer failed. Trying to save a copy on this host under:\n"
2439                   printf "      ${pathout[$i]}/${host_configuration}_${fname}${endout[$i]}_$run_id\n"
2440
2441                      # FIRST CHECK, IF DIRECTORY EXISTS, AND CREATE IT, IF NECESSARY
2442                   eval  local_catalog=${pathout[$i]}
2443                   if [[ ! -d $local_catalog ]]
2444                   then
2445                      printf "  *** local directory does not exist. Trying to create:\n"
2446                      printf "      $local_catalog \n"
2447                      mkdir -p  $local_catalog
2448                   fi
2449                   eval  cp  ${localout[$i]}  ${pathout[$i]}/${host_configuration}_${fname}${endout[$i]}_$run_id
2450                   transfer_problems=true
2451                fi
2452
2453             else
2454
2455                   # UNSET actionout. DUE TO THIS SETTING, FILE WILL LATER JUST
2456                   # BE COPIED OR APPENDED ON THIS MACHINE
2457                if [[ "${actionout[$i]}" = tr ]]
2458                then
2459                   actionout[$i]=""
2460                else
2461                   actionout[$i]="a"
2462                fi
2463             fi
2464          fi
2465
2466
2467             # APPEND ON THIS MACHINE
2468          if [[ "${actionout[$i]}" = "a" ]]
2469          then
2470             if [[ "${extout[$i]}" != " "  &&  "${extout[$i]}" != "" ]]
2471             then
2472                printf "\n  >>> OUTPUT: ${localout[$i]}  append to"
2473                printf "\n              ${pathout[$i]}.${extout[$i]}\n"
2474                cat  ${localout[$i]}  >>  ${pathout[$i]}.${extout[$i]}
2475             else
2476                printf "\n  >>> OUTPUT: ${localout[$i]}  append to"
2477                printf "\n              ${pathout[$i]}\n"
2478                cat  ${localout[$i]}  >>  ${pathout[$i]}
2479             fi
2480          fi
2481
2482             # COPY ON THIS MACHINE
2483             # COPY HAS TO BE USED, BECAUSE MOVE DOES NOT WORK IF FILE-ORIGIN AND TARGET ARE
2484             # ON DIFFERENT FILE-SYSTEMS
2485          if [[ "${actionout[$i]}" = ""  &&  $files_for_cores = false ]]
2486          then
2487
2488                # COPY IN CASE OF RUNS ON SINGLE CORES
2489             if [[ "${extout[$i]}" != " "  &&  "${extout[$i]}" != "" ]]
2490             then
2491                printf "\n  >>> OUTPUT: ${localout[$i]}  to"
2492                printf "\n              ${pathout[$i]}.${extout[$i]}\n"
2493                              if [[ $link_local_output = true ]]
2494                              then
2495                                 printf "      file will be linked\n"
2496                                 ln -f  ${localout[$i]}  ${pathout[$i]}.${extout[$i]}
2497                              fi
2498                                 # If "ln -f" fails of if "$link_local_output = false" do a normal "cp"
2499                              if [[ ! -f "${pathout[$i]}.${extout[$i]}" ]]
2500                then
2501                                 if [[ $link_local_output = true ]]
2502                          then
2503                      printf "  --- WARNING: ln failed, using cp instead (might be time consuming...)\n"
2504                                 fi
2505                                 cp  ${localout[$i]}  ${pathout[$i]}.${extout[$i]}
2506                              else
2507                   printf "+++ no copy because file ${pathout[$i]}.${extout[$i]} exists\n"
2508                fi
2509             else
2510                printf "\n  >>> OUTPUT: ${localout[$i]}  to"
2511                printf "\n              ${pathout[$i]}\n"
2512                              if [[ $link_local_output = true ]]
2513                              then
2514                                 printf "      file will be linked\n"
2515                                 ln -f  ${localout[$i]}  ${pathout[$i]}
2516                              fi
2517                                 # If "ln -f" fails of if "$link_local_output = false" do a normal "cp"
2518                        if [[ ! -f "${pathout[$i]}" ]]
2519                then
2520                                 if [[ $link_local_output = true ]]
2521                          then
2522                      printf "  --- WARNING: ln failed, using cp instead (might be time consuming...)\n"
2523                                 fi
2524                                 cp  ${localout[$i]}  ${pathout[$i]}
2525                              else
2526                                 printf "+++ no copy because file ${pathout[$i]} exists\n"
2527                fi
2528             fi
2529
2530          elif [[ "${actionout[$i]}" = ""  &&  $files_for_cores = true ]]
2531          then
2532
2533                # FILES FROM THE DIFFERENT CORES ARE MOVED WITH ln-COMMAND TO THE PERMANENT DIRECTORY
2534                # AS A FIRST STEP, THE PERMANENT DIRECTORY IS CREATED
2535             printf "\n  >>> OUTPUT: ${localout[$i]}/_....  to"
2536             printf "\n              ${pathout[$i]}\n"
2537                    if [[ $link_local_output = true ]]
2538                    then
2539                              printf "      files will be linked\n"
2540                              mkdir -p ${pathout[$i]}
2541                              cd ${localout[$i]}
2542                              for file in $(ls *)
2543                              do
2544                                 ln -f $file  ${pathout[$i]}
2545                              done >|/dev/null 2>&1
2546                              cd $tempdir
2547                    fi
2548
2549                # IF "ln -f" HAS FAILED OR IF "$link_local_output = false" DO A NORMAL COPY "cp -r"
2550                    if [[ ! -f "${pathout[$i]}/_000000" ]]
2551             then
2552                              if [[ $link_local_output = true ]]
2553                              then
2554                   printf "  --- WARNING: ln failed, using cp instead (might be time consuming...)\n"
2555                              fi
2556                              cp -r  ${localout[$i]}/*  ${pathout[$i]}
2557             fi
2558
2559          fi
2560       fi
2561    done
2562
2563    if (( i != 0 ))
2564    then
2565       if [[ $transfer_problems = true ]]
2566       then
2567          printf "\n$dashes\n  *** OUTPUT-files saved"
2568          printf "\n  +++ WARNING: some data transfers failed! \n"
2569       else
2570          printf "\n$dashes\n  *** all OUTPUT-files saved \n"
2571       fi
2572    fi
2573
2574
2575       # IF REQUIRED, START A RESTART-JOB
2576       # FILE CONTINUE_RUN MUST HAVE BEEN CREATED BY THE EXECUTABLE (PALM)
2577    if [[ -f CONTINUE_RUN ]]
2578    then
2579
2580          # ADD RESTART-OPTIONS TO THE PALMRUN-CALL (IF THEY ARE NOT USED ALREADY):
2581          # -C TELLS PALMRUN THAT IT IS A RESTART-RUN
2582          # -v SILENT MODE WITHOUT INTERACTIVE QUERIES
2583          # -b START A BATCH JOB
2584       [[ $(echo $prc | grep -c "\-C") = 0 ]]  &&  prc="$prc -C"
2585       [[ $(echo $prc | grep -c "\-v") = 0 ]]  &&  prc="$prc -v"
2586       [[ $(echo $prc | grep -c "\-b") = 0 ]]  &&  prc="$prc -b"
2587
2588
2589          # REPLACE THE HASH IN THE ACTIVATION STRINGS (GIVEN WITH OPTION -a)
2590          # SO THAT RESTARTS ACCESS DIFFERENT FILES THAN THE INITIAL RUN
2591       if [[ $(echo $prc | grep -c "#") != 0 ]]
2592       then
2593          prc=`echo $prc | sed 's/#/r/g'`
2594       fi
2595
2596
2597          # START THE RESTART-JOB
2598       printf "\n\n  *** initiating restart-run on \"$local_ip\" using command:\n"
2599       echo "      $prc"
2600       printf "\n$dashes\n"
2601       if [[ $running_on_remote = true ]]
2602       then
2603
2604          echo "*** ssh will be used to initiate restart-runs!"
2605          echo "    return_address=\"$return_address\" "
2606          echo "    return_username=\"$local_username\" "
2607
2608          if [[ "$remote_loginnode" != "" ]]
2609          then
2610             echo "echo \" PATH=\\\$PATH:$LOCAL_PALMRUN_PATH; cd $LOCAL_PWD; $prc\" |  ssh -q $SSH_PORTOPT  $local_username@$return_address  " |  ssh -q $remote_username@$remote_loginnode
2611          else
2612             echo \" PATH=\\\$PATH:$LOCAL_PALMRUN_PATH; cd $LOCAL_PWD; $prc\" |  ssh -q $SSH_PORTOPT  $local_username@$return_address
2613          fi
2614
2615             # WAIT TO ALLOW THE RESTART-JOB TO BE QUEUED, BEFORE THE CURRENT JOB IS FINISHED
2616          sleep 30
2617
2618       else
2619
2620             # START THE RESTART JOB ON THE LOCAL HOST
2621          eval  $prc                # THE ' MUST BE EVALUATED
2622          cd -  > /dev/null
2623
2624       fi
2625       printf "\n$dashes\n  *** restart-run initiated \n"
2626
2627
2628          # DELETE INPUT-(RESTART)FILES, WHICH HAVE BEEN FETCHED FROM THE TEMPORARY DATA
2629          # DIRECTORY, BACAUSE THEY ARE NOT REQUIRED BY THE RESTART-JOB.
2630          # THIS IS DONE IN ORDER TO AVOID EXCEEDING DISC QUOTAS OR DISC SPACE (RESTART-FILES
2631          # MAY BE VERY HUGE)
2632       (( i = 0 ))
2633       while (( i < nr_of_input_files ))
2634       do
2635          (( i = i + 1 ))
2636          if [[ "${got_tmp[$i]}" = true   &&  $keep_data_from_previous_run = false ]]
2637          then
2638             rm -r  ${absnamein[$i]}
2639          fi
2640       done
2641
2642    fi
2643
2644
2645       # ALL ACTIONS FINISHED, TEMPORARY WORKING-DIRECTORY CAN BE DELETED
2646    cd  $HOME
2647    [[ $delete_temporary_catalog = true ]]  &&  rm -rf $tempdir
2648
2649
2650 else
2651
2652
2653       # PREPARING ACTIONS,
2654       # IF A BATCH-JOB IS TO BE GENERATED AND TO BE STARTED ON A LOCAL OR REMOTE-MACHINE
2655
2656       # BUILD THE PALMRUN-COMMAND TO BE CALLED IN THE BATCH-JOB
2657    palmrun_com="$palmrun_script_name -d $fname -h $host_configuration -m $memory -t $cpumax -q $queue -r $run_id -U $local_username"
2658    [[ "$activation_string_list" != "" ]]  &&  palmrun_com=${palmrun_com}" -a \"$activation_string_list\""
2659    [[ "$global_revision" != "" ]]  &&  palmrun_com=${palmrun_com}" -G \"$global_revision\""
2660    [[ $keep_data_from_previous_run = true ]]  &&  palmrun_com=${palmrun_com}" -k"
2661    [[ $do_trace = true ]]        &&  palmrun_com=${palmrun_com}" -x"
2662    [[ "$cores" != "" ]]       &&  palmrun_com=${palmrun_com}" -X $cores"
2663    [[ $use_openmp = true ]]  &&  palmrun_com=${palmrun_com}" -O $threads_per_task"
2664    [[ $tasks_per_node != 0 ]]  &&  palmrun_com=${palmrun_com}" -T $tasks_per_node"
2665    [[ $delete_temporary_catalog = false ]]  &&  palmrun_com=${palmrun_com}" -B"
2666    [[ "$ocean_file_appendix" = true ]]  &&  palmrun_com=${palmrun_com}" -y"
2667    [[ $run_coupled_model = true ]]  &&  palmrun_com=${palmrun_com}" -Y \"$coupled_dist\""
2668    [[ "$combine_plot_fields" = false ]]  &&  palmrun_com=${palmrun_com}" -Z"
2669    [[ "$max_par_io_str" != "" ]]  &&  palmrun_com=${palmrun_com}" -w $max_par_io_str"
2670    [[ "$project_account" != "" ]]  &&  palmrun_com=${palmrun_com}" -A $project_account"
2671    if [[ $create_remote_batch_job = true ]]
2672    then
2673       palmrun_com=${palmrun_com}" -j -u $remote_username -R $local_ip"
2674       if [[ $do_trace = true ]]
2675       then
2676          printf "\n *** PALMRUN-command on remote host:\n     $palmrun_com \n"
2677       fi
2678    elif [[ $create_batch_job = true ]]
2679    then
2680       palmrun_com=${palmrun_com}" -j"
2681       if [[ $do_trace = true ]]
2682       then
2683          printf "\n *** PALMRUN-command on local host:\n     $palmrun_com \n"
2684       fi
2685    fi
2686
2687
2688       # DETERMINE THE FULL PATHS FOR THE JOB PROTOCOL FILES ON THE LOCAL AND
2689       # REMOTE HOST
2690    job_protocol_file_local=${local_jobcatalog}/${host_configuration}_${job_id}
2691    job_protocol_file=$job_protocol_file_local
2692    if [[ $create_remote_batch_job = true ]]
2693    then
2694       job_protocol_file_remote=${remote_jobcatalog}/${host_configuration}_${job_id}
2695       job_protocol_file=$job_protocol_file_remote
2696       job_transfer_protocol_file=${remote_jobcatalog}/last_job_transfer_protocol
2697       scpjob_file=${remote_jobcatalog}/scpjob.$run_id
2698    fi
2699
2700
2701       # BUILD THE JOB-SCRIPTS ON FILE jobfile
2702    jobfile=jobfile.$run_id
2703
2704
2705       # FIRST CREATE THE BATCH DIRECTIVES
2706    (( i = 0 ))
2707    while (( i < ibd ))
2708    do
2709       (( i = i + 1 ))
2710       line=`echo  "${batch_directive[$i]}" | sed 's/{{JOB_ID}}/$job_id/g' | sed 's/{{JOBFILE}}/$job_protocol_file/g' | sed 's/{{CPU_HOURS}}/$cpu_hours/g' | sed 's/{{CPU_MINUTES}}/$cpu_minutes/g' | sed 's/{{CPU_SECONDS}}/$cpu_seconds/g' | sed 's/{{NODES}}/$nodes/g' | sed 's/{{CORES}}/$cores/g' | sed 's/{{TASKS_PER_NODE}}/$tasks_per_node/g' | sed 's/{{HOST_CONFIGURATION}}/${host_configuration}/g' | sed 's/{{FNAME}}/$fname/g' | sed 's/{{QUEUE}}/$queue/g' | sed 's/{{MEMORY}}/$memory/g' | sed 's/{{PROJECT_ACCOUNT}}/$project_account/g' | sed 's/{{PREVIOUS_JOB}}/$previous_job/g' | sed 's/{{TEMPDIR}}/$tempdir/g'`
2711       eval line=\"$line\"
2712       echo  "$line"                               >>  $jobfile
2713    done
2714    echo " "                                       >>  $jobfile
2715
2716
2717       # FOR BATCH JOBS ON REMOTE HOSTS, ADD THE JOBFILE TO SEND BACK THE JOB
2718       # PROTOCOL
2719    if [[ $create_remote_batch_job = true ]]
2720    then
2721       echo "set +vx"                              >>  $jobfile
2722       echo "trap '"                               >>  $jobfile
2723       echo "set +vx"                              >>  $jobfile
2724       echo "cd ${remote_jobcatalog}"              >>  $jobfile
2725       echo "cat >  scpjob.$run_id << %%END%%"     >>  $jobfile
2726
2727          # ADD THE BATCH DIRECTIVES
2728       (( i = 0 ))
2729       while (( i < ibdt ))
2730       do
2731          (( i = i + 1 ))
2732          line=`echo  "${batch_directive_transfer[$i]}" | sed 's/{{JOB_ID}}/$job_id/g' | sed 's/{{JOBFILE}}/$job_protocol_file/g' | sed 's/{{JOB_TRANSFER_PROTOCOL_FILE}}/$job_transfer_protocol_file/g' | sed 's/{{CPU_HOURS}}/$cpu_hours/g' | sed 's/{{CPU_MINUTES}}/$cpu_minutes/g' | sed 's/{{CPU_SECONDS}}/$cpu_seconds/g' | sed 's/{{NODES}}/$nodes/g' | sed 's/{{TASKS_PER_NODE}}/$tasks_per_node/g' | sed 's/{{HOST_CONFIGURATION}}/${host_configuration}/g' | sed 's/{{FNAME}}/$fname/g' | sed 's/{{PROJECT_ACCOUNT}}/$project_account/g'`
2733          eval line=\"$line\"
2734          echo  "$line"                            >>  $jobfile
2735       done
2736       echo " "                                    >>  $jobfile
2737
2738       echo "set -x"                               >>  $jobfile
2739       echo "${fast_io_catalog}/${sources_for_run_catalog}/batch_scp  $PORTOPT  -d  -w 10  -u $local_username $local_ip  $job_protocol_file_remote  \"$local_jobcatalog\"  ${host_configuration}_${fname}"  >>  $jobfile
2740       echo "%%END%%"                              >>  $jobfile
2741       echo "echo \" *** submitting job for transfering the job protocol file to $local_ip\" "  >>  $jobfile
2742       echo "$submit_command  $scpjob_file"        >>  $jobfile
2743       echo "rm $scpjob_file"                      >>  $jobfile
2744       echo "rm -rf $job_transfer_protocol_file"   >>  $jobfile
2745       echo "set -x"                               >>  $jobfile
2746       echo "     ' exit"                          >>  $jobfile
2747    fi
2748
2749
2750       # ACTIVATE ERROR-TRACEBACK
2751    if [[ $do_trace = true ]]
2752    then
2753       echo  "set -x"                                    >>  $jobfile
2754    else
2755       echo  "set +vx"                                   >>  $jobfile
2756    fi
2757
2758
2759       # INITIALIZE THE ENVIRONMENT AND LOAD MODULES
2760    if [[ "$login_init_cmd" != "" ]]
2761    then
2762       echo  "$login_init_cmd"        >>  $jobfile
2763    fi
2764    if [[ "$module_commands" != "" ]]
2765    then
2766       echo  "$module_commands"     >>  $jobfile
2767    fi
2768
2769
2770       # CREATE TEMPORARY DIRECTORY AND SWITCH TO IT
2771    if [[ $create_remote_batch_job = true ]]
2772    then
2773       echo  "mkdir  $tempdir"           >>  $jobfile
2774       echo  "chmod  go+rx  $tempdir"    >>  $jobfile
2775    else
2776          # DIRECTORY FOR LOCAL BATCH JOBS IS CREATED NOW, DUE TO A
2777          # REQUIREMENT OF THE GRID ENGINE BATCH SYSTEM (WORKING DIR IS GIVEN IN
2778          # BATCH DIRECTIVE -wd AND MUST ALREADY EXIST WHEN THE JOB IS SUBMITTED)
2779       mkdir  $tempdir
2780       chmod  go+rx  $tempdir
2781    fi
2782    echo  "cd  $tempdir"                 >>  $jobfile
2783    echo  "export tempdir=$tempdir"      >>  $jobfile
2784    echo  "cp  ${fast_io_catalog}/${sources_for_run_catalog}/{*,.[!.]*}  ."  >>  $jobfile
2785    echo  "export PATH=.:\$PATH"         >>  $jobfile
2786    echo  "export execute_palmrun=true"  >>  $jobfile
2787
2788
2789       # PROVIDE NAME OF THE CURRENT WORKING-DIRECTORY ON THE LOCAL MACHINE (FROM WHERE THE JOB IS
2790       # STARTED) BY SETTING AN ENVIRONMENT-VARIABLE. THIS INFORMATION IS USED IN THE JOB BY PALMRUN
2791       # IN CASE THAT RESTART-RUNS HAVE TO BE GENERATED
2792    echo  "LOCAL_PWD=$working_directory"                >>  $jobfile
2793    echo  "export LOCAL_PWD"                            >>  $jobfile
2794
2795
2796       # PROVIDE THE PATH OF THE LOCAL PALMRUN-SCRIPT FOR THE SAME REASON
2797    echo  "LOCAL_PALMRUN_PATH=${source_path}/../SCRIPTS"   >>  $jobfile
2798    echo  "export LOCAL_PALMRUN_PATH"                      >>  $jobfile
2799
2800
2801       # CALL PALMRUN WITHIN THE JOB
2802       # AS FINAL ACTION, REMOVE THE TEMPORARY DIRECTORY CREATED AT THE BEGINNING OF THE JOB
2803    echo  "set -x"                                              >>  $jobfile
2804    echo  "[[ \$execute_palmrun = true ]]  &&  $palmrun_com"    >>  $jobfile
2805
2806
2807       # TRANSFER JOBFILE TO THE TARGET HOST
2808    if [[ $create_jobfile_only = false ]]
2809    then
2810
2811       if [[ $create_remote_batch_job = true ]]
2812       then
2813
2814          echo " "
2815          echo " *** transfer of job to remote host via scp"
2816          if [[ $do_trace = true ]]
2817          then
2818             echo "     scp $ssh_key $PORTOPT $jobfile ${remote_username}@${remote_ip}:${remote_jobcatalog}/${host_configuration}_${job_id}"
2819          fi
2820          scp $ssh_key $PORTOPT $jobfile ${remote_username}@${remote_ip}:${remote_jobcatalog}/${host_configuration}_${job_id}  >  /dev/null
2821
2822          printf " *** submit the job (output of submit command, e.g. the job-id, may follow)"
2823          if [[ $do_trace = true ]]
2824          then
2825             echo "     cd $remote_jobcatalog; $submit_command ${host_configuration}_${job_id}; rm ${host_configuration}_${job_id}  |  ssh  -q  $ssh_key $SSH_PORTOPT  ${remote_username}@${remote_ip}  2>&1"
2826          fi
2827          echo "cd $remote_jobcatalog; $submit_command ${host_configuration}_${job_id}; rm ${host_configuration}_${job_id}"  |  ssh  -q  $ssh_key $SSH_PORTOPT  ${remote_username}@${remote_ip}  2>&1
2828
2829       elif [[ $create_batch_job = true ]]
2830       then
2831
2832          eval  local_jobcatalog=$local_jobcatalog
2833          cp  $jobfile  ${local_jobcatalog}/${host_configuration}_${job_id}
2834          cd $local_jobcatalog
2835          echo " "
2836          echo " *** submit the job"
2837          if [[ $do_trace = true ]]
2838          then
2839             echo "$submit_command ${host_configuration}_${job_id}"
2840          fi
2841          $submit_command ${host_configuration}_${job_id}
2842          rm ${host_configuration}_${job_id}
2843          cd -  > /dev/null
2844
2845       fi
2846
2847       rm -rf  $jobfile
2848
2849    else
2850
2851       printf "\n *** jobfile created under name \"$jobfile\" "
2852       printf "\n     no batch-job has been sent!"
2853
2854    fi
2855
2856 fi  # END OF REMOTE-PART
Note: See TracBrowser for help on using the repository browser.