source: palm/trunk/SCRIPTS/palmrun @ 3132

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

create consistent error messages in case of failed restarts, check existence of remote job catalog

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