source: palm/trunk/SCRIPTS/palmrun @ 2693

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

replacement of variables in configuration file is done in a more general way, variable names are written in small letters

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