source: palm/trunk/SCRIPTS/palmrun @ 2968

Last change on this file since 2968 was 2957, checked in by Giersch, 7 years ago

Sky view factors will always be read from file now in case of automatic restarts, corrected error message in case of writing sky view factors

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