source: palm/trunk/SCRIPTS/palmrun @ 3032

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

keyword correction

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