source: palm/trunk/SCRIPTS/palmrun @ 3294

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

modularization of the ocean code

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