source: palm/trunk/SCRIPTS/palmrun @ 2639

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

bugfix for r2638: switchback to palmrun r2636

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