source: palm/trunk/SCRIPTS/palmrun @ 2990

Last change on this file since 2990 was 2990, checked in by raasch, 4 years ago

bugfix: temporary SOURCES_FOR_RUN_CATALOG now created in base_directory and not in the working directory from where palmrun is called

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