source: palm/trunk/SCRIPTS/palmrun @ 3573

Last change on this file since 3573 was 3573, checked in by raasch, 6 years ago

bugfixes: don't check the .palm.iofiles in restart runs + wrong cd-command, r3570 reverted

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