source: palm/trunk/SCRIPTS/palmrun @ 3126

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

check for setting of fast_io_catalog, update of default .palm.config.default

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