source: palm/trunk/SCRIPTS/palmrun @ 2993

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

bugfix of r2990

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