source: palm/trunk/SCRIPTS/palmrun @ 2883

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

fname renamed jobname

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