source: palm/trunk/SCRIPTS/palmrun @ 2789

Last change on this file since 2789 was 2789, checked in by raasch, 4 years ago

bugfix: exit if no queue has been given neither with option -q nor in the configuration file

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