source: palm/trunk/SCRIPTS/mrun @ 1483

Last change on this file since 1483 was 1469, checked in by maronga, 10 years ago

last commit documented

  • Property svn:keywords set to Id Rev
File size: 176.6 KB
Line 
1#!/bin/ksh
2
3# mrun - script for running PALM jobs
4
5#--------------------------------------------------------------------------------#
6# This file is part of PALM.
7#
8# PALM is free software: you can redistribute it and/or modify it under the terms
9# of the GNU General Public License as published by the Free Software Foundation,
10# either version 3 of the License, or (at your option) any later version.
11#
12# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
13# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along with
17# PALM. If not, see <http://www.gnu.org/licenses/>.
18#
19# Copyright 1997-2014  Leibniz Universitaet Hannover
20#--------------------------------------------------------------------------------#
21#
22# Current revisions:
23# ------------------
24#
25#
26# Former revisions:
27# -----------------
28# $Id: mrun 1469 2014-09-24 14:09:56Z raasch $
29#
30# 1468 2014-09-24 14:06:57Z maronga
31# Typo removed (addres->address)
32# Bugfix: returning files to IMUK via ssh did not work for lccrayh and lcycrayb
33# Added support for restart runs (remote) for lcxe6
34#
35# 1442 2014-07-28 07:09:10Z raasch
36# default queues for HLRN-III (lccrayb/lccrayh) defined
37#
38# 1422 2014-07-02 10:01:25Z kanani
39# automatic restarts enabled for lccrayb,
40# adjustment of path to compilervars.sh at IMUK (see automatic restarts)
41#
42# 1420 2014-06-10 06:24:14Z raasch
43# -j1 option added to aprung command for lccrayf (CSC)
44#
45# 1402 2014-05-09 14:25:13Z raasch
46# batch_job added to envpar-NAMELIST
47#
48# 1357 2014-04-11 15:02:03Z witha
49# adjustments for lccrayh (automatic restarts on lccrayh outside of IMUK are now
50# possible)
51#
52# 1320 2014-03-20 08:40:49Z raasch
53# check namelist file set false by default
54#
55# 1304 2014-03-12 10:29:42Z raasch
56# ulimit option changed from -Ss to -s
57#
58# bugfix: missing "fi" in r1289
59#
60# 1289 2014-03-04 07:12:34Z raasch
61# comments translated to English
62# necriam-, fimm-, ibmy-, and sgi-specific code removed
63# export of variables for palm and interpret_config removed
64#
65# 1281 2014-02-01 07:55:49Z raasch
66# rsync-copy restricted to Cray machines, since command is unavailable on some
67# other systems
68#
69# 1279 2014-01-28 12:10:14Z raasch
70# tasks_per_node must not be an integral divisor of numprocs any more. This was done
71# in order to remove annoying restrictions concerning the number of processors which
72# appear on machines with larger nodes (e.g. containing 24 cores). Now without this
73# restriction, one of the nodes will be filled with less than the given number of
74# tasks per node. A respective warning is given.
75#
76# 1274 2014-01-09 13:14:54Z heinze
77# adjustments for lccrayh
78#
79# 1272 2014-01-08 10:19:32Z witha
80# small adjustment for lcflow
81#
82# 1270 2013-12-16 11:05:01Z fricke
83# call of combine_plot_fields adjusted for lccrayb/lccrayh
84#
85# 1255 2013-11-07 14:43:35Z raasch
86# further adjustments for lccrayb remote access
87#
88# 1241 2013-10-30 11:36:58Z heinze
89# Enable use of nudging input and input of large scale forcing from
90# external files
91#
92# 1229 2013-09-20 06:55:19Z raasch
93# further adjustments for lccrayb
94#
95# 1224 2013-09-16 07:27:23Z raasch
96# first adjustments for lccrayb
97#
98# 1210 2013-08-14 10:58:20Z raasch
99# fftw support added
100#
101# 1201 2013-07-10 16:17:59Z witha
102# adjustments for Forwind cluster (lcflow)
103#
104# 1199 2013-07-05 14:52:22Z raasch
105# adjustments for CSC Helsinki (lccrayf),
106# executables for batch jobs can be created in advance, in order to avoid calling
107# the compiler within the batch job (only works if batch jobs are submitted on
108# local host)
109#
110# 1190 2013-06-25 09:39:21Z heinze
111# enable use of automatic restarts for ibmh
112# use of cluster/express queue enabled (ibmh)
113#
114# 1124 2013-04-09 15:46:52Z raasch
115# variable "memory" is exported via typeset option -x, because otherwise an unknown
116# side effect may lead to data loss while getopts is reading the script-option arguments
117#
118# 1122 2013-04-09 08:37:16Z heinze
119# Bugfix: change type of variable last_char
120#
121# 1119 2013-04-05 15:11:19Z raasch
122# Bugfix for setting -T option for subjob
123#
124# 1108 2013-03-05 07:03:32Z raasch
125# bugfix for coupled runs on lckyut/lckyuh
126#
127# 1106 2013-03-04 05:31:38Z raasch
128# --stdin argument for mpiexec on lckyuh
129# -y and -Y settings output to header
130#
131# 1103 2013-02-20 02:15:53Z raasch
132# default script runs again under ksh, because of unsolved problems with read
133# from stdin: when bash script is called from a ksh, message "read error: 0:
134# Resource temporarily unavailable" appears and script does not stop,
135# further bash compatibility adjustments,
136# shebang line replaced by /bin/bash when running jobs on lckyuh; no restarts
137# on lckyuh, but mrun does not terminate and issues a warning instead
138#
139# 1101 2013-02-17 10:20:21Z raasch
140# script now running under bash instead of ksh, which required small adjustments
141# (output formatting with printf instead "typeset -L/-R", print replaced by echo,
142# read from stdin),
143# cross compilername on lckyuh compute nodes replaced by real compiler name
144#
145# 1099 2013-02-10 01:47:43Z raasch
146# adjustments for Kyushu-University computing center (lckyuh - hayaka)
147# and for Forwind cluster (lcflow)
148# small further adjustments for lckyut
149#
150# 1094 2013-02-03 01:52:12Z raasch
151# explicit ssh/scp port can be set in config file with environment variable
152# scp_port.  This port is handled to all ssh/scp/batch_scp calls.
153# decalpha parts (yonsei) removed
154#
155# 2013-02-02 07:06:13Z raasch
156# adjustments for Kyushu-University computing center (lckyut - tatara)
157#
158# 1083 2013-01-04 10:22:09Z maronga
159# bugfix in parameter file check (read %cpp_options was missing)
160#
161# 1069 2012-11-28 16:18:43Z maronga
162# bugfix: coupling mode was always set to mpi2, typos removed
163#
164# 1058 2012-11-21 07:00:35Z raasch
165# Intel inspector (inspxe) is given the number of PEs instead of the number of
166# nodes
167#
168# 1046 2012-11-09 14:38:45Z maronga
169# code put under GPL (PALM 3.9)
170#
171# 21/03/94 - Siggi - first version finished
172# 03/03/94 - Siggi - script development started
173#
174#--------------------------------------------------------------------------------#
175# mrun - script for running PALM jobs
176#--------------------------------------------------------------------------------#
177
178
179 
180    # DECLARATION OF VARIABLES AND THEIR DEFUALT VALUES
181
182 set +o allexport    # SUPPRESS EXPORT OF ALL VARIABLES, SINCE IN THE PAST THIS
183                     # LES TO PROBLEMS IN ROUTINES CALLED BY MRUN
184                     # (TOO MANY ARGUMENTS - PROBLEM)
185 set +o noclobber    # EXISTING FILES ARE ALLOWED TO BE OVERWRITTEN
186
187 AddFilenames=""
188 additional_conditions=""
189 add_source_path=""
190 afname=""
191 archive_save=true
192 archive_system=none
193 check_namelist_files=false
194 combine_plot_fields=true
195 compiler_name=""
196 cond1=""
197 cond2="" 
198 config_file=.mrun.config
199 coupled_dist=""
200 coupled_mode="mpi1"
201 cpp_opts=""
202 cpp_options=""
203 cpumax=0
204 cpurest=0
205 create_executable_for_batch=false
206 delete_temporary_catalog=true
207 do_batch=false
208 do_compile=true
209 do_remote=false
210 do_stagein=true
211 do_stageout=true
212 do_trace=false
213 email_notification="none"
214 exclude=""
215 executable=""
216 execution_error=false
217 fftw_inc=""
218 fftw_lib=""
219 fftw_support=false
220  fname=test
221 fromhost=""
222 global_revision=""
223 group_number=none
224 host=""
225 host_file=""
226 hp=""
227 ignore_archive_error=false
228 input_list=""
229 interpreted_config_file=""
230 job_catalog="~/job_queue"
231 job_on_file=""
232 keep_data_from_previous_run=false
233 link_local_input=false
234 link_local_output=false
235 localhost_realname=$(hostname)
236 local_dvrserver_running=.FALSE.
237 locat=normal
238 mainprog=""
239 makefile=""
240 max_par_io_str=""
241 mc=$0
242 while [[ $(echo $mc | grep -c "/") != 0 ]]
243 do
244    mc=`echo $mc | cut -f2- -d"/"`
245 done
246 module_calls=""
247 mrun_script_name=$mc
248 netcdf_inc=""
249 netcdf_lib=""
250 netcdf_support=false
251 node_usage=default
252 numprocs=""
253 numprocs_atmos=0
254 numprocs_ocean=0
255 OOPT=""
256 openmp=false
257 output_list=""
258 package_list=""
259 queue=none
260 read_from_config=""
261 restart_run=false
262 if [[ `hostname` = rte10 ]]
263 then
264    return_address=133.5.185.60
265    echo "+++ WARNING: fixed return_address = $return_address is used !!!!!"
266 elif [[ `hostname` = climate0 ]]
267 then
268    return_address=165.132.26.68
269    echo "+++ WARNING: fixed return_address = $return_address is used !!!!!"
270 elif [[ `hostname` = urban00 ]]
271 then
272    return_address=147.46.30.151
273    echo "+++ WARNING: fixed return_address = $return_address is used !!!!!"
274 else
275    return_address=$(nslookup `hostname` 2>&1 | grep "Address:" | tail -1 | awk '{print $2}')
276 fi
277 return_password=""
278 return_username=$LOGNAME
279 remotecall=false
280 remote_username=""
281 run_coupled_model=false
282 run_mode=""
283 store_on_archive_system=false
284 dashes="  ----------------------------------------------------------------------------"
285 silent=false
286 source_list=""
287 source_path=SOURCE
288 tasks_per_node=""
289 threads_per_task=1
290 tmpcreate=false
291 tmp_data_catalog=""
292 transfer_problems=false
293 usern=$LOGNAME
294 use_openmp=false
295 version="MRUN  2.1 Rev$Rev: 1469 $"
296 working_directory=`pwd`
297 TOPT=""
298 XOPT=""
299 zeit=$( date | cut -c 12-19 )
300
301 typeset -i  iec=0 iic=0 iin=0 ioc=0 iout=0 stagein_anz=0 stageout_anz=0
302 typeset -x -i  memory=0   # HAS TO BE EXPORTED HERE, OTHERWISE AN UNKNOWN SIDE
303                           # SIDE EFFECT MAY CAUSE DATA LOSS WHEN GETOPTS IS READING THE
304                           # SCRIPT-OPTION ARGUMENTS
305 typeset -i  cputime i ii iia iii iio icycle inode ival jobges jobsek last_char_int maxcycle minuten nodes pes remaining_pes sekunden tp1
306
307
308
309    # ERROR HANDLING IN CASE OF EXIT
310 trap 'rm -rf  $working_directory/tmp_mrun
311       if [[ $locat != normal  &&  $locat != control_c ]]
312       then
313
314              # CARRY OUT ERROR-COMMANDS GIVEN IN THE CONFIGURATION FILE (EC:)
315          (( i = 0 ))
316          while (( i < iec ))
317          do
318             (( i = i + 1 ))
319             printf "\n  *** Execution of ERROR-command:\n"
320             printf "  >>> ${err_command[$i]}\n"
321             eval  ${err_command[$i]}
322          done
323          if [[ -n $interpreted_config_file ]]
324          then
325             rm -rf  $interpreted_config_file
326          fi
327          if [[ -n .mrun_environment ]]
328          then
329             rm -rf  .mrun_environment
330          fi
331          if [[ $tmpcreate = true ]]
332          then
333             printf "\n  *** Contents of \"$TEMPDIR\":\n"
334             ls -al; cd
335             [[ $delete_temporary_catalog = true ]]  &&  rm -rf $TEMPDIR
336          fi
337          if [[ "$dvrserver_id" != "" ]]
338          then
339             echo "+++ killing dvrserver_id=$dvrserver_id"
340             kill $dvrserver_id
341          fi
342          if [[ -f ~/job_queue/JOBINFO.$QSUB_REQID ]]
343          then
344             rm -rf  ~/job_queue/JOBINFO.$QSUB_REQID
345          fi
346          printf "\n\n+++ MRUN killed \n\n"
347       elif [[ $locat != control_c ]]
348       then
349          printf "\n\n --> all actions finished\n\n"
350          printf "     Bye, bye $usern !!\n\n"
351       fi' exit
352
353
354    # ACTIONS IN CASE OF TERMINAL-BREAK (CONTROL-C):
355 trap 'rm -rf  $working_directory/tmp_mrun
356       rm -rf  $working_directory/tmp_check_namelist_files
357       [[ $tmpcreate = true ]]  &&  (cd; rm -rf $TEMPDIR)
358       if [[ -f ~/job_queue/JOBINFO.$QSUB_REQID ]]
359       then
360          rm -rf  ~/job_queue/JOBINFO.$QSUB_REQID
361       fi
362       if [[ "$dvrserver_id" != "" ]]
363       then
364          echo "+++ killing dvrserver_id=$dvrserver_id"
365          kill $dvrserver_id
366       fi
367       printf "\n+++ MRUN killed by \"^C\" \n\n"
368       locat=control_c
369       exit
370      ' 2
371
372
373    # CHECK IF THE PATH FOR THE PALM BINARIES (SCRIPTS+UTILITY-PROGRAMS) HAS
374    # BEEN SET
375 if [[ "$PALM_BIN" = "" ]]
376 then
377    printf "\n  +++ environment variable PALM_BIN has not been set"
378    printf "\n      please set it to the directory where the PALM scripts are located"
379    locat=palm_bin; exit
380 fi
381 export PATH=$PALM_BIN:$PATH
382
383
384
385    # READ SHELLSCRIPT-OPTIONS AND REBUILD THE MRUN-COMMAND STRING (MC),
386    # WHICH WILL BE USED TO START RESTART-JOBS
387 while  getopts  :a:AbBc:Cd:D:Fg:G:h:H:i:IkK:m:M:n:o:O:p:P:q:r:R:s:St:T:u:U:vw:xX:yY:zZ option
388 do
389   case  $option  in
390       (a)   afname=$OPTARG;;
391       (A)   store_on_archive_system=true; mc="$mc -A";;
392       (b)   do_batch=true; mc="$mc -b";;
393       (B)   delete_temporary_catalog=false; mc="$mc -B";;
394       (c)   config_file=$OPTARG; mc="$mc -c$OPTARG";;
395       (C)   restart_run=true; mc="$mc -C";;
396       (d)   fname=$OPTARG; mc="$mc -d$OPTARG";;
397       (D)   cpp_opts="$cpp_opts $OPTARG"; mc="$mc -D'$OPTARG'";;
398       (F)   job_on_file="-D"; mc="$mc -F";;
399       (g)   group_number=$OPTARG; mc="$mc -g$OPTARG";;
400       (G)   global_revision=$OPTARG; mc="$mc -G'$OPTARG'";;
401       (h)   host=$OPTARG; mc="$mc -h$OPTARG";;
402       (H)   fromhost=$OPTARG; mc="$mc -H$OPTARG";;
403       (i)   input_list=$OPTARG; mc="$mc -i'$OPTARG'";;
404       (I)   ignore_archive_error=true; mc="$mc -I";;
405       (k)   keep_data_from_previous_run=true; mc="$mc -k";;
406       (K)   additional_conditions="$OPTARG"; mc="$mc -K'$OPTARG'";;
407       (m)   memory=$OPTARG; mc="$mc -m$OPTARG";;
408       (M)   makefile=$OPTARG; mc="$mc -M$OPTARG";;
409       (n)   node_usage=$OPTARG; mc="$mc -n$OPTARG";;
410       (o)   output_list=$OPTARG; mc="$mc -o'$OPTARG'";;
411       (O)   use_openmp=true; threads_per_task=$OPTARG; mc="$mc -O$OPTARG";;
412       (p)   package_list=$OPTARG; mc="$mc -p'$OPTARG'";;
413       (P)   return_password=$OPTARG; mc="$mc -P$OPTARG";;
414       (q)   queue=$OPTARG; mc="$mc -q$OPTARG";;
415       (r)   run_mode=$OPTARG; mc="$mc -r'$OPTARG'";;
416       (R)   remotecall=true;return_address=$OPTARG; mc="$mc -R$OPTARG";;
417       (s)   source_list=$OPTARG; mc="$mc -s'$OPTARG'";;
418       (S)   read_from_config=false; mc="$mc -S";;
419       (t)   cpumax=$OPTARG; mc="$mc -t$OPTARG";;
420       (T)   mrun_tasks_per_node=$OPTARG; mc="$mc -T$OPTARG";;
421       (u)   remote_username=$OPTARG; mc="$mc -u$OPTARG";;
422       (U)   return_username=$OPTARG; mc="$mc -U$OPTARG";;
423       (v)   silent=true; mc="$mc -v";;
424       (w)   max_par_io_str=$OPTARG; mc="$mc -w$OPTARG";;
425       (x)   do_trace=true;set -x; mc="$mc -x";;
426       (X)   numprocs=$OPTARG; mc="$mc -X$OPTARG";;
427       (y)   ocean_file_appendix=true; mc="$mc -y";;
428       (Y)   run_coupled_model=true; coupled_dist=$OPTARG; mc="$mc -Y'$OPTARG'";;
429       (z)   check_namelist_files=false; mc="$mc -z";;
430       (Z)   combine_plot_fields=false; mc="$mc -Z";;
431       (\?)  printf "\n  +++ unknown option $OPTARG \n"
432             printf "\n  --> type \"$0 ?\" for available options \n"
433             locat=parameter;exit;;
434   esac
435 done
436
437
438    # SKIP GIVEN OPTIONS TO READ POSITIONAL PARAMETER, IF GIVEN
439    # CURRENTLY ONLY PARAMETER ? (TO OUTPUT A SHORT COMMAND INFO) IS ALLOWED
440 (( to_shift = $OPTIND - 1 ))
441 shift $to_shift
442
443    # PRINT SHORT DESCRIPTION OF MRUN OPTIONS
444 if [[ "$1" = "?" ]]
445 then
446   (printf "\n  *** mrun can be called as follows:\n"
447    printf "\n      $mrun_script_name  -b -c.. -d.. -D.. -f.. -F -h.. -i.. -I -K.. -m.. -o.. -p.. -r.. -R -s.. -t.. -T.. -v -x -X.. -y -Y.. -z -Z <modus> \n"
448    printf "\n      Description of available options:\n"
449    printf "\n      Option  Description                              Default-Value"
450    printf "\n        -a    base name of input files                 equiv. -d"
451    printf "\n        -A    archiving when using file-attribute fl"
452    printf "\n        -b    batch-job on local machine               ---"
453    printf "\n        -B    do not delete temporary directory at end ---"
454    printf "\n        -c    configuration file                       .mrun.config"
455    printf "\n        -d    base name of files attached to program   test"
456    printf "\n        -D    preprocessor(cpp)-directives             \"\" "
457    printf "\n        -F    create remote job file only              ---"
458    printf "\n        -h    execution host                           $localhost_realname"
459    printf "\n        -i    INPUT control list                       \"\" "
460    printf "\n        -I    archiving errors of previous batch-jobs"
461    printf "\n              will be ignored"
462    printf "\n        -k    keep data from previous run"
463    printf "\n        -K    additional conditions for controling"
464    printf "\n              usage of conditional code and"
465    printf "\n              env-variables in configuration file      \"\" "
466    printf "\n        -m    memory demand in MB (batch-jobs)         0 MB"
467    printf "\n        -M    Makefile name                            Makefile"
468    printf "\n        -n    node usage (shared/not_shared)           depending on -h"
469    printf "\n        -o    OUTPUT control list                      \"\" "
470    printf "\n        -O    threads per openMP task                  ---"
471    printf "\n        -p    software package list                    \"\" "
472    printf "\n        -q    queue                                    \"$queue\" "
473    printf "\n        -r    run control list (combines -i -o)        \"\" "
474    printf "\n        -s    filenames of routines to be compiled     \"\" "
475    printf "\n              must end with .f, .f90, .F, or .c !"
476    printf "\n              use \"..\" for more than one file and wildcards"
477    printf "\n              -s LM compiles all locally modified files"
478    printf "\n        -S    config file interpreted by shellscript   ---"
479    printf "\n        -t    allowed cpu-time in seconds (batch)      0"
480    printf "\n        -T    tasks per node                           depending on -h"
481    printf "\n        -u    username on remote machine               \"\" "
482    printf "\n        -v    no prompt for confirmation               ---"
483    printf "\n        -w    maximum parallel io streams              as given by -X"
484    printf "\n        -x    tracing of mrun for debug purposes       ---"
485    printf "\n        -X    # of processors (on parallel machines)   1"
486    printf "\n        -y    add appendix \"_O\" to all local output"
487    printf "\n              files (ocean precursor runs followed by"
488    printf "\n              coupled atmosphere-ocean runs)           ---"
489    printf "\n        -Y    run coupled model, \"#1 #2\" with" 
490    printf "\n              #1 atmosphere and #2 ocean processors    \"#/2 #/2\" depending on -X"
491    printf "\n        -z    disable a priori parameter file check    ---"
492    printf "\n        -Z    skip combine_plot_fields at the end of      "
493    printf "\n              the simulation                           ---"
494    printf "\n "
495    printf "\n      Possible values of positional parameter <modus>:"
496    printf "\n        \"?\"       -  this outline \n\n") | more
497    exit
498 elif [[ "$1" != "" ]]
499 then
500    printf "\n  +++ positional parameter $1 unknown \n"
501    locat=parameter; exit
502 fi
503
504
505
506    # SHORT STARTING MESSAGE
507 printf "\n*** $version "
508 printf "\n    will be executed.     Please wait ..."
509
510
511
512    # CHECK, IF CONFIGURATION FILE EXISTS
513 if [[ ! -f $config_file ]]
514 then
515    printf "\n\n  +++ configuration file: "
516    printf "\n           $config_file"
517    printf "\n      does not exist"
518    locat=connect; exit 
519 fi
520
521
522    # DETERMINE THE HOST-IDENTIFIER (localhost) FROM THE CONFIGURATION FILE
523 line=""
524 grep  "%host_identifier"  $config_file  >  tmp_mrun
525 while read line
526 do
527    if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
528    then
529       HOSTNAME=`echo $line | cut -d" " -s -f2`
530       host_identifier=`echo $line | cut -d" " -s -f3`
531       if [[ $localhost_realname = $HOSTNAME ]]
532       then
533          localhost=$host_identifier
534          break
535       fi
536    fi
537 done < tmp_mrun
538
539 if [[ "$localhost" = "" ]]
540 then
541    printf "\n\n  +++ no host identifier found in configuration file \"$config_file\""
542    printf "\n      for local host \"$localhost_realname\"."
543    printf "\n      Please add line"
544    printf "\n      \"\%host_identifier $localhost_realname <identifier>\""
545    printf "\n      to the configuration file."
546    locat=localhost; exit
547 fi
548
549
550    # SET HOST-SPECIFIC VARIABLES
551 case  $localhost_realname  in
552     (r1*|r2*|h01*|b01*)     archive_system=tivoli;;
553     (cs*)                   archive_system=ut;;
554 esac
555
556
557    # ??? THIS SHOULD BE DECRIBED IN THE MRUN DOCUMENTATION ???
558    # SET BASENAME OF THE INPUT-FILES TO THE GENERAL BASENAME (GIVEN BY OPTION -d),
559    # IF IT HAS NOT BEEN SET BY THE USER DIFFERENTLY (USING OPTION -a)
560 [[ "$afname" = "" ]]  &&  afname=$fname
561
562
563    # ADD RUN-FILE ACTIVATION STRINGS (GIVEN BY OPTION -r) TO THE
564    # RESPECTIVE LISTS FOR ACTIVATING THE INPUT/OUTPUT FILE CONNECTION
565    # STATEMENTS IN THE CONFIGURATION FILE
566 if [[ "$run_mode" != "" ]]
567 then
568    input_list="$input_list $run_mode"
569    output_list="$output_list $run_mode"
570 fi
571
572
573    # ??? is this (and the respective option -H) really required ???
574    # STORE HOSTNAME, FROM WHICH THE JOB IS STARTED,
575    # BUT ONLY IF IT HASN'T BEEN ALREADY SET BY OPTION -H
576    # (MRUN IS AUTOMATICALLY SETTING THIS OPTION IN THE MRUN-CALLS WITHIN
577    # THOSE BATCH-JOBS, WHICH ARE CREATED BY MRUN ITSELF)
578 if [[ "$fromhost" = "" ]]
579 then
580    fromhost=$localhost
581 fi
582
583
584    # CHECK, IF EXECUTION SHALL TO BE DONE ON THE REMOTE-MACHINE.
585    # VALUE OF do_remote IS IMPORTANT FOR THE FILE CONNECTIONS.
586    # IN CASE OF EXECUTION ON A REMOTE-MACHINE, A BATCH-JOB HAS
587    # TO BE SUBMITTED (I.E. do_bacth=true)
588 if [[ -n $host  &&  "$host" != $localhost ]]
589 then
590    do_batch=true
591    do_remote=true
592    case  $host  in
593        (ibm|ibmh|ibmkisti|ibmku|ibms|nech|lccrayb|lccrayh|lccrayf|lcflow|lckyoto|unics|lcxe6|lcxt5m|lck|lckiaps|lckordi|lckyuh|lckyut|lcsb)  true;;
594        (*)  printf "\n"
595             printf "\n  +++ sorry: execution of batch jobs on remote host \"$host\""
596             printf "\n      is not available"
597             locat=nqs; (( iec = 0 )); exit;;
598    esac
599 else
600    host=$localhost
601 fi
602
603
604     # EVALUATE ADDITIONAL CONDITIONS GIVEN BY OPTION -K
605 if [[ -n $additional_conditions ]]
606 then
607    cond1=`echo $additional_conditions | cut -d" " -f1`
608    cond2=`echo $additional_conditions | cut -d" " -s -f2`
609    dummy=`echo $additional_conditions | cut -d" " -s -f3`
610    if [[ -n $dummy ]]
611    then
612       printf "\n  +++ more than 2 additional conditions given for Option \"-K\""
613       locat=options; exit
614    fi
615    block=_$cond1
616    [[ -n $cond2 ]]  &&  block=${block}_$cond2
617 fi
618
619
620      # EVALUATE MODEL COUPLING FEATURES (OPTION -Y) AND DETERMINE coupled_mode
621 if [[ $run_coupled_model = true ]] 
622 then
623
624    numprocs_atmos=`echo $coupled_dist | cut -d" " -s -f1`
625    numprocs_ocean=`echo $coupled_dist | cut -d" " -s -f2`
626
627    if (( $numprocs_ocean + $numprocs_atmos != $numprocs ))
628    then
629
630       printf "\n  +++ number of processors does not fit to specification by \"-Y\"."
631       printf "\n      PEs (total)     : $numprocs"
632       printf "\n      PEs (atmosphere): $numprocs_atmos"
633       printf "\n      PEs (ocean)     : $numprocs_ocean"
634       locat=coupling; exit
635
636    fi
637
638
639       # GET coupled_mode FROM THE CONFIG FILE
640    line=""
641    grep  "%cpp_options.*-D__mpi2.*$host" $config_file  >  tmp_mrun
642    while read line
643    do
644       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" &&  $(echo $line | cut -d" " -s -f4) = $cond1 && $(echo $line | cut -d" " -s -f4)  = $cond2 ]]
645       then
646          coupled_mode="mpi2"
647       fi
648    done < tmp_mrun
649
650 fi
651
652
653    # CHECK, IF FILE-ARCHIVING HAS FAILED IN PREVIOUS JOB (OF A JOB-CHAIN)
654 if [[ -f ~/job_queue/ARCHIVE_ERROR_$fname ]]
655 then
656    if [[ $ignore_archive_error = false ]]
657    then
658       printf "\n  +++ data archiving of previous run failed"
659       printf "\n      see directory \~/job_queue on remote machine"
660       locat=archive; exit
661    else
662       printf "\n  +++ warning: data archiving in a previous run failed"
663       printf "\n      MRUN continues, trying to get backup copy"
664    fi
665 fi
666
667
668    # SAVE VALUES OF MRUN-OPTIONS SICHERN IN ORDER TO OVERWRITE
669    # THOSE VALUES GIVEN IN THE CONFIGURATION-FILE
670 mrun_memory=$memory
671 mrun_group_number=$group_number
672 mrun_cpumax=$cpumax
673 mrun_numprocs=$numprocs
674
675
676    # READ AND EVALUATE THE CONFIGURATION-FILE FROM WITHIN THIS SHELLSCRIPT
677    # (OPTION -S). THE DEFAULT IS USING THE ROUTINE <<<<
678 if [[ "$read_from_config" = false ]]
679 then
680
681    [[ $silent = false ]]  &&  printf "\n    Reading the configuration file... "
682
683       # READ THE CONFIGURATION FILE LINE BY LINE
684    while  read zeile
685    do
686        [[ $silent = false ]]  &&  printf "."
687
688
689          # FIRST REPLACE ENVIRONMENT-VARIABLES BY THEIR RESPECTIVE VALUES
690       eval  zeile=\"$zeile\"
691
692
693          # INTERPRET THE LINE
694       if [[ "$(echo $zeile)" = "" ]]
695       then
696             # EMPTY LINE, NO ACTION
697          continue
698
699       elif [[ "$(echo $zeile | cut -c1)"  =  "#" ]]
700       then
701
702             # LINE IS A COMMENT LINE
703          true
704
705       elif [[ "$(echo $zeile | cut -c1)"  =  "%" ]]
706       then
707
708             # LINE DEFINES AN ENVIRONMENT-VARIABLE
709          zeile=$(echo $zeile | cut -c2-)
710          var=`echo $zeile | cut -d" " -f1`
711          value=`echo $zeile | cut -d" " -s -f2`
712          for_host=`echo $zeile | cut -d" " -s -f3`
713          for_cond1=`echo $zeile | cut -d" " -s -f4`
714          for_cond2=`echo $zeile | cut -d" " -s -f5`
715
716          if [[ "$for_host" = ""  ||  ( "$for_host" = $host  &&  "$for_cond1" = "$cond1"  &&  "$for_cond2" = "$cond2" )  ||  $(echo "$input_list$output_list"|grep -c "$for_host") != 0 ]]
717          then
718
719                # REPLACE ":" BY " " IN COMPILER- CPP- OR LINKER-OPTIONS,
720                # "::" IS REPLACED BY ":".
721             value=`echo $value | sed 's/::/%DUM%/g' | sed 's/:/ /g' | sed 's/%DUM%/:/g'`
722
723
724                # VALUE FROM THE CONFIGURATION-FILE IS ASSIGNED TO THE
725                # ENVIRONMENT-VARIABLE, BUT ONLY IF NO VALUE HAS BEEN ALREADY
726                # ASSIGNED WITHIN THIS SCRIPT (E.G. BY SCRIPT-OPTIONS).
727                # NON-ASSIGNED VARIABLES HAVE VALUE "" OR 0 (IN CASE OF INTEGER).
728                # HENCE THE GENERAL RULE IS: SCRIPT-OPTION OVERWRITES THE
729                # CONFIGURATION-FILE.
730             if [[ "$(eval echo \$$var)" = ""  ||  "$(eval echo \$$var)" = "0" ]]
731             then
732                eval  $var=\$value
733
734                   # TERMINAL OUTPUT OF ENVIRONMENT-VARIABLES, IF TRACEBACK IS SWITCHED on
735                if [[ $do_trace = true ]]
736                then
737                   printf "\n*** ENVIRONMENT-VARIABLE $var = $value"
738                fi
739             fi
740
741                # IF AN ENVIRONMENT-VARIABLE DETERMINES THE HOST, THEN EVALUATE IT IMMEDIATELY:
742                # VALUE OF do-remote IS REQUIRED FOR THE FILE CONNECTIONS (COPY OF I/O FILES).
743                # IF EXECUTION IS SCHEDULED FOR A REMOTE-MASCHINE, A BATCH-JOB
744                # MUST HAVE TO BE STARTED
745             if [[ $var = host ]]
746             then
747                if [[ -n $host  &&  "$host" != $localhost ]]
748                then
749                   do_batch=true
750                   do_remote=true
751                   case  $host  in
752                       (ibm|ibmh|ibmkisti|ibmku|ibms|lccrayb|lccrayh|lccrayf|lcflow|lckyoto|nech|unics|lcxe6|lcxt5m|lck|lckiaps|lckordi|lckyuh|lckyut|lcsb)  true;;
753                       (*)  printf "\n  +++ sorry: execution of batch jobs on remote host \"$host\""
754                            printf "\n      is not available"
755                            locat=nqs; exit;;
756                   esac
757                else
758                   host=$localhost
759                fi
760             fi
761
762                # USER-DEFINED ENVIRONMENT VARIABLES MUST BE EXPORTED,
763                # BECAUSE THEY MAY BE REQUIRED IN OTHER SCRIPTS CALLED
764                # BY MRUN (E.G. subjob)
765             export  $var
766          fi
767
768
769
770
771       elif [[ "$(echo $zeile | cut -c1-3)" = "EC:" ]]
772       then
773
774             # LINE DEFINES ERROR-COMMAND
775          (( iec = iec + 1 ))
776          zeile=$(echo $zeile | cut -c4-)
777          err_command[$iec]="$zeile"
778
779       elif [[ "$(echo $zeile | cut -c1-3)" = "IC:" ]]
780       then
781
782             # LINE DEFINES INPUT-COMMAND
783          (( iic = iic + 1 ))
784          zeile=$(echo $zeile | cut -c4-)
785          in_command[$iic]="$zeile"
786
787       elif [[ "$(echo $zeile | cut -c1-3)" = "OC:" ]]
788       then
789
790             # LINE DEFINES OUTPUT-COMMAND
791          (( ioc = ioc + 1 ))
792          zeile=$(echo $zeile | cut -c4-)
793          out_command[$ioc]="$zeile"
794
795       else
796
797             # LINE DEFINES FILE CONNECTION. READ THE FILE ATTRIBUTES.
798             # s2a: in/out - field
799             # s2b: loc    - field (optional)
800             # s2c: tr/ar  - field (optional)
801          s1=`echo $zeile | cut -d" " -f1`
802          s2=`echo $zeile | cut -d" " -s -f2`
803          s2a=$(echo $s2 | cut -d":" -f1)
804          if [[ $(echo $s2 | grep -c ":") = 0 ]]
805          then
806             s2b=""
807             s2c=""
808          else
809             s2b=`echo $s2 | cut -d":" -f2 | sed 's/:/ /g'`
810             s2c=`echo $s2 | cut -d":" -s -f3 | sed 's/:/ /g'`
811          fi
812          s3=`echo $zeile | cut -d" " -f3`
813          s4=`echo $zeile | cut -d" " -s -f4`
814          s5=`echo $zeile | cut -d" " -s -f5`
815          s6=`echo $zeile | cut -d" " -s -f6`
816
817       
818             # STORE FILE CONNECTION, IF ACTIVATED BY ACTIVATION-STRING FROM
819             # INPUT- OR OUTPUT-LIST.
820             # VARIABLE S3 MAY CONTAIN A LIST OF ACTIVATION STRINGS (FIELD-SEPERATOR ":").
821             # IF EXECUTION IS SCHEDULED FOR A REMOTE-MACHINE AND THE FILE IS ONLY
822             # LOCALLY REQUIRED ON THAT MACHINE (I.E. s2b = loc), THE FILE CONNECTION
823             # IS NOT CHECKED AND STORED.
824          IFSALT="$IFS"; IFS="$IFS:"
825          if [[ "$s2a" = in  &&  ! ( $do_remote = true  &&  ( "$s2b" = loc  ||  "$s2b" = locopt ) ) ]]
826          then
827             found=false
828             for  actual  in  $input_list
829             do
830                for  formal  in  $s3
831                do
832                   [[ $actual = $formal  ||  "$formal" = "-" ]]  &&  found=true
833                done
834             done
835             if [[ $found = true ]]
836             then
837                (( iin = iin + 1 ))
838                localin[$iin]=$s1; transin[$iin]=$s2b; actionin[$iin]=$s2c;
839                typein[$iin]=$s3; pathin[$iin]=$s4; endin[$iin]=$s5;
840                extin[$iin]=$s6
841             fi
842          elif [[ "$s2a" = out  &&  ! ( $do_remote = true  &&  "$s2b" = loc ) ]]
843          then
844             found=false
845             for  actual  in  $output_list
846             do
847                for  formal  in  $s3 
848                do
849                   [[ $actual = $formal  ||  "$formal" = "-"  ]]  &&  found=true
850                done
851             done
852             if [[ $found = true ]]
853             then
854                (( iout = iout + 1 ))
855                localout[$iout]=$s1; actionout[$iout]=$s2c; typeout[$iout]=$s3;
856                pathout[$iout]=$s4; endout[$iout]=$s5; extout[$iout]=$s6
857             fi
858          elif [[ "$s2a" != in  &&  "$s2a" != out ]]
859          then
860             printf "\n  +++ I/O-attribute in configuration file $config_file has the invalid"
861             printf "\n      value \"$s2\". Only \"in\" and \"out\" are allowed!"
862             locat=connect; exit
863          fi
864          IFS="$IFSALT"
865       fi
866    done < $config_file
867
868 else
869
870
871       # EVALUATE THE CONFIGURATION-FILE BY FORTRAN-PROGRAM
872    [[ $silent = false ]]  &&  printf "..."
873    interpreted_config_file=.icf.$RANDOM
874
875
876
877       # PROVIDE VALUES OF ENVIRONMENT-VARIABLE FOR interpret_config VIA NAMELIST-FILE
878    cat  >  .mrun_environment  <<  %%END%%
879 &mrun_environment  cond1 = '$cond1', cond2 = '$cond2',
880                    config_file = '$config_file', do_remote = '$do_remote',
881                    do_trace = '$do_trace', host = '$host',
882                    input_list = '$input_list', icf = '$interpreted_config_file',
883                    localhost = '$localhost', output_list = '$output_list' /
884
885%%END%%
886
887    if [[ "$host" != $localhost ]]
888    then
889
890          # REMOTE JOB FROM LOCAL HOST: JUST TAKE THE FIRST EXECUTABLE FOUND
891       interpret_config_executable=`ls -1 ${PALM_BIN}/interpret_config*.x 2>/dev/null`
892       if [[ $? != 0 ]]
893       then
894          printf "\n\n  +++ no interpret_config found"
895          printf "\n      run \"mbuild -u -h ...\" to generate utilities for this host"
896          locat=interpret_config; exit
897       fi
898       interpret_config_executable=`echo $interpret_config_executable | cut -d" " -f1`
899       $interpret_config_executable
900
901    else
902
903          # CHECK, IF THERE IS AN EXECUTABLE FOR THE BLOCK
904       if [[ ! -f ${PALM_BIN}/interpret_config${block}.x ]]
905       then
906          printf "\n\n  +++ no interpret_config found for given block \"$cond1 $cond2\""
907          printf "\n      run \"mbuild -u -h ...\" to generate utilities for this block"
908          locat=interpret_config; exit
909       else
910          interpret_config${block}.x
911       fi
912
913    fi
914    rm .mrun_environment
915
916
917       # EXECUTE SHELL-COMMANDS GENERATED BY interpret_config WITHIN THIS SHELL
918    chmod  u+x  $interpreted_config_file
919    export PATH=$PATH:.
920    . $interpreted_config_file
921    rm  $interpreted_config_file
922
923 fi
924
925
926    # VALUES OF MRUN-OPTIONS OVERWRITE THOSE FROM THE CONFIGURATION-FILE
927 [[ $mrun_memory     != 0   ]]  &&  memory=$mrun_memory
928 [[ "$mrun_group_number" != "none" ]]  &&  group_number=$mrun_group_number
929 [[ $mrun_cpumax     != 0   ]]  &&  cpumax=$mrun_cpumax
930 [[ "$mrun_numprocs" != ""  ]]  &&  numprocs=$mrun_numprocs
931 [[ "$max_par_io_str" != "" ]]  &&  maximum_parallel_io_streams=$max_par_io_str
932 [[ "$mrun_tasks_per_node" != "" ]]  &&  tasks_per_node=$mrun_tasks_per_node
933
934
935    # ON THE LOCAL MACHINE, DETERMINE (FROM THE CONFIGURATION-FILE) THE PATH
936    # FOR SOURCE-FILES TO BE COMPILED.
937    # IN A BATCH-JOB, SOURCES (ROUTINES TO BE COMPILED) ARE COMPLETE ALREADY.
938    # BEFORE MRUN IS CALLED IN THE JOB, SOURCES_COMPLETE = true IS ASSIGNED (SEE FURTHER BELOW).
939 if [[ "$SOURCES_COMPLETE" = "" ]]
940 then
941
942       # FIRST CHECK, IF A GLOBAL SOURCE PATH (TO BE USED FOR ALL HOSTS)
943       # HAS BEEN DEFINED
944    source_path=""
945    line=""
946    grep "%source_path" $config_file  >  tmp_mrun
947    while read line
948    do
949       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
950       then
951          if [[ "$(echo $line | cut -d" " -f3)" = "" ]]
952          then
953             global_source_path=`echo $line | cut -d" " -f2`
954          fi
955       fi
956    done  <  tmp_mrun
957
958    line=""
959    found=false
960    grep  " $localhost" $config_file | grep "%source_path"  >  tmp_mrun
961    while read line
962    do
963       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
964       then
965          if [[ $found = true ]]
966          then
967             printf "\n\n  +++ more than one source path found in configuration file"
968             printf "\n      for local host \"$localhost\" "
969             locat=source_path; exit
970          fi
971          source_path=`echo $line | cut -d" " -f2`
972          found=true
973       fi
974    done  <  tmp_mrun
975    rm  tmp_mrun
976
977    if [[ "$source_path" = "" ]]
978    then
979       if [[ "$global_source_path" != "" ]]
980       then
981          source_path=$global_source_path
982       else
983          printf "\n\n  +++ no source path found in configuration file"
984          printf "\n      for local host \"$localhost\" "
985          locat=source_path; exit
986       fi
987    fi
988    eval source_path=$source_path
989
990    if [[ ! -d $source_path ]]
991    then
992       printf "\n\n  +++ source path \"$source_path\" on local host"
993       printf "\n      \"$localhost\" does not exist"
994       locat=source_path; exit
995    fi
996
997 fi
998
999
1000    # GET THE GLOBAL REVISION-NUMBER OF THE SVN-REPOSITORY
1001    # (HANDED OVER TO RESTART-RUNS USING OPTION -G)
1002 if [[ "$global_revision" = ""  &&  $host != "ibmkisti" ]]
1003 then
1004    global_revision=`svnversion $source_path  2>/dev/null`
1005    global_revision="Rev: $global_revision"
1006 fi
1007
1008
1009    # ??? das darf doch eigentlich garnicht passieren, weil optionen config-datei uebersteuern ???
1010    # CHECK AGAIN, IF EXECUTION SHALL BE DONE ON A REMOTE-HOST (BATCH-JOB).
1011    # (HOST MAY HAVE CHANGED DUE TO SETTINGS IN THE CONFIGURATION-FILE)
1012 if [[ -n $host  &&  "$host" != $localhost ]]
1013 then
1014    do_batch=true
1015    do_remote=true
1016    case  $host  in
1017        (ibm|ibmh|ibmkisti|ibmku|ibms|lccrayb|lccrayh|lccrayf|lcflow|lckyoto|nech|unics|lcxe6|lcxt5m|lck|lckiaps|lckordi|lckyuh|lckyut|lcsb)  true;;
1018        (*)  printf "\n"
1019             printf "\n  +++ sorry: execution of batch jobs on remote host \"$host\""
1020             printf "\n      is not available"
1021             locat=nqs; (( iec = 0 )); exit;;
1022    esac
1023 else
1024    host=$localhost
1025 fi
1026
1027
1028    # IN CASE OF PARALLEL EXECUTION, CHECK SOME SPECIFICATIONS CONCERNING PROCESSOR NUMBERS
1029 if [[ "$cond1" = parallel  ||  "$cond2" = parallel ]]
1030 then
1031
1032       # CHECK, IF NUMBER OF CORES TO BE USED HAS BEEN GIVEN
1033    if [[ ! -n $numprocs ]]
1034    then
1035       printf "\n"
1036       printf "\n  +++ option \"-K parallel\" requires additional specification"
1037       printf "\n      of the number of processors to be used by"
1038       printf "\n      mrun-option \"-X\" or by environment-variable"
1039       printf "\n      \"numprocs\" in the configuration file"
1040       locat=numprocs; (( iec = 0 )); exit
1041    fi
1042
1043       # CHECK, IF THE NUMBER OF CORES PER NODE HAS BEEN GIVEN UND IF IT IS AN
1044       # INTEGRAL DIVISOR OF THE TOTAL NUMBER OF CORES GIVEN BY OPTION -X
1045    if [[ "$tasks_per_node" = ""  &&  $host != lcflow  &&  $host != lcxt5m ]]
1046    then
1047       printf "\n"
1048       printf "\n  +++ option \"-T\" (tasks per node) is missing"
1049       printf "\n      set -T option or define tasks_per_node in the config file"
1050       locat=tasks_per_node; (( iec = 0 )); exit
1051    fi
1052
1053    if (( numprocs < tasks_per_node ))
1054    then
1055       printf "\n"
1056       printf "\n  +++ tasks per node (-T) cannot exceed total number of processors (-X)"
1057       printf "\n      given values: -T $tasks_per_node  -X $numprocs"
1058       locat=tasks_per_node; (( iec = 0 )); exit
1059    fi
1060
1061    if [[ $host != lcflow  &&  $host != lcxt5m ]]
1062    then
1063       (( nodes = numprocs / ( tasks_per_node * threads_per_task ) ))
1064       (( ival = $tasks_per_node ))
1065       (( pes = numprocs ))
1066       (( ii = pes / ival ))
1067       (( remaining_pes =  pes - ii * ival ))
1068       if (( remaining_pes > 0 ))
1069       then
1070          printf "\n"
1071          printf "\n  +++ WARNING: tasks per node (option \"-T\") is not an integral"
1072          printf "\n      divisor of the total number of processors (option \"-X\")"
1073          printf "\n      values of this mrun-call: \"-T $tasks_per_node\" \"-X $numprocs\""
1074          printf "\n      One of the nodes is filled with $remaining_pes instead of $tasks_per_node tasks"
1075          (( nodes = nodes + 1 ))
1076       fi
1077    fi
1078
1079
1080       # SETTINGS FOR SUBJOB-COMMAND
1081    OOPT="-O $threads_per_task"
1082
1083       # SET THE TOTAL NUMBER OF NODES, REQUIRED FOR THE SUBJOB-COMMAND (SEE FURTHER BELOW)
1084    if [[ "$tasks_per_node" != "" ]]
1085    then
1086       TOPT="-T $tasks_per_node"
1087    fi
1088
1089       # CHECK node_usage FOR ALLOWED VALUES AND SET DEFAULT VALUE, IF NECESSARY
1090    if [[ $node_usage = default ]]
1091    then
1092       if [[ $host = ibms ]]
1093       then
1094          node_usage=shared
1095       else
1096          node_usage=not_shared
1097       fi
1098    fi
1099
1100    if [[ $node_usage != shared  &&  $node_usage != not_shared  &&  $node_usage != singlejob  &&  "$(echo $node_usage | cut -c1-3)" != "sla" ]]
1101    then
1102       printf "\n"
1103       printf "\n  +++ node usage (option \"-n\") is only allowed to be set"
1104       printf "\n      \"shared\" or \"not_shared\""
1105       locat=tasks_per_node; (( iec = 0 )); exit
1106    fi
1107
1108 fi
1109
1110    # CHECK IF HOSTFILE EXISTS
1111 if [[ -n $hostfile ]]
1112 then
1113    if [[ ! -f $hostfile ]]
1114    then
1115       printf "\n"
1116       printf "\n  +++ hostfile \"$hostfile\" does not exist"
1117       locat=hostfile; exit
1118    fi
1119 fi
1120
1121
1122    # SET DEFAULT VALUE FOR THE MAXIMUM NUMBER OF PARALLEL IO STREAMS
1123 if [[ "$maximum_parallel_io_streams" = "" ]]
1124 then
1125    maximum_parallel_io_streams=$numprocs
1126 fi
1127
1128
1129    # SET PORT NUMBER OPTION FOR CALLS OF SSH/SCP, subjob AND batch_scp SCRIPTS
1130 if [[ "$scp_port" != "" ]]
1131 then
1132    PORTOPT="-P $scp_port"
1133    SSH_PORTOPT="-p $scp_port"
1134 fi
1135
1136
1137    # SET DEFAULT-QUEUE, IF NOT GIVEN
1138 if [[ $queue = none ]]
1139 then
1140    case  $host  in
1141        (ibmh)       queue=cluster;;
1142        (ibmkisti)   queue=class.32plus;;
1143        (lccrayb)    queue=mpp1q;;
1144        (lccrayh)    queue=mpp1q;;
1145        (lckiaps)    queue=normal;;
1146        (lckyoto)    queue=ph;;
1147        (lckyuh)     queue=fx-single;;
1148        (lckyut)     queue=cx-single;;
1149        (lctit)      queue=S;;
1150        (nech)       queue=none;;
1151        (unics)      queue=unics;;
1152    esac
1153 fi
1154
1155
1156    # GENERATE FULL FILENAMES OF INPUT-FILES, INCLUDING THEIR PATH
1157    # CHECK, IF INPUT-FILES EXIST, AND DETERMINE HIGHEST CYCLE NUMBER (IF CYCLES EXIST)
1158 (( i = 0 ))
1159 while (( i < iin ))
1160 do
1161    (( i = i + 1 ))
1162    (( maxcycle = 0 ))
1163
1164       # GENERATE PATH AND FULL FILE NAME (then-BRANCH: FIXED FULL NAME IS GIVEN, I.E. THE
1165       # FILE IDENTIFIER IS NOT PART OF THE FILENAME))
1166    if [[ "${actionin[$i]}" = di ]]
1167    then
1168       remotepathin[$i]=${pathin[$i]}/${endin[$i]}  # EVALUATE REMOTE-PATH ON THE REMOTE
1169                                                    # HOST ONLY
1170       eval filename=${pathin[$i]}/${endin[$i]}
1171    else
1172       remotepathin[$i]=${pathin[$i]}/${afname}${endin[$i]}  # EVALUATE REMOTE-PATH ON THE REMOTE
1173                                                             # HOST ONLY
1174       eval filename=${pathin[$i]}/${afname}${endin[$i]}
1175    fi
1176    eval pathname=${pathin[$i]}
1177
1178       # SAVE INPUT FILE NAME FOR PARAMETER FILE CHECK
1179    if [[ ("${transin[$i]}" = job) && (-f $filename) ]]
1180    then
1181       filename_input=$filename
1182    fi
1183
1184       # CHECK IF FILE EXISTS
1185    if [[ $(ls $filename* 2>&1 | grep -c "not found") = 1  || \
1186          $(ls $filename* 2>&1 | grep -c "nicht gefunden") = 1  || \
1187          $(ls $filename* 2>&1 | grep -c "No such file") = 1  || \
1188          $(ls $filename* 2>&1 | grep -c "does not exist") = 1 ]]
1189    then
1190
1191          # FILES WITH ATTRIBUTE locopt ARE OPTIONAL. NO ABORT, IF THEY DO NOT EXIST.
1192       if [[ "${transin[$i]}" != "locopt" ]]
1193       then
1194          printf "\n\n  +++ INPUT-file: "
1195          if [[ "${extin[$i]}" = "" ]]
1196          then
1197             printf "\n           $filename"
1198          else
1199             printf "\n           $filename.${extin[$i]}"
1200          fi
1201          printf "\n      does not exist\n"
1202          locat=input; exit
1203       else
1204          transin[$i]="unavailable"
1205       fi
1206    else
1207
1208          # DETERMINE THE FILE'S CYCLE NUMBER
1209       ls -1 -d $filename    >   filelist  2>/dev/null
1210       ls -1 -d $filename.*  >>  filelist  2>/dev/null
1211       while  read zeile
1212       do
1213          cycle=$(echo $zeile | cut -f2 -d".")
1214          if [[ "$cycle" = "$zeile" ]]
1215          then
1216             (( icycle = 0 ))
1217          elif [[ "$cycle" = "${extin[$i]}" ]]
1218          then
1219             (( icycle = 0 ))
1220          else
1221             (( icycle = $cycle ))
1222          fi
1223          if (( icycle > maxcycle ))
1224          then
1225             (( maxcycle = icycle ))
1226             file_to_be_used=$zeile
1227          fi
1228       done <filelist
1229       rm filelist
1230
1231          # APPEND CYCLE NUMBER TO FILENAME
1232       if (( maxcycle > 0 ))
1233       then
1234          if [[ "${extin[$i]}" != " "  &&   "${extin[$i]}" != "" ]]
1235          then
1236             filename=${filename}.$maxcycle.${extin[$i]}
1237          else
1238             filename=${filename}.$maxcycle
1239          fi
1240       else
1241          if [[ "${extin[$i]}" != " "  &&   "${extin[$i]}" != "" ]]
1242          then
1243             filename=${filename}.${extin[$i]}
1244          fi
1245       fi
1246       
1247          # STORE FILENAME WITHOUT PATH BUT WITH CYCLE NUMBER,
1248          # BECAUSE IT MIGHT BE REQUIRED LATER TO RESTORE THE FILE FROM AN ARCHIVE-SYSTEM
1249       absnamein[$i]=$filename
1250       if (( maxcycle > 0 ))
1251       then
1252          if [[ "${actionin[$i]}" = di ]]
1253          then
1254             frelin[$i]=${endin[$i]}.$maxcycle
1255          else
1256             frelin[$i]=${afname}${endin[$i]}.$maxcycle
1257          fi
1258       else
1259          if [[ "${actionin[$i]}" = di ]]
1260          then
1261             frelin[$i]=${endin[$i]}
1262          else
1263             frelin[$i]=${afname}${endin[$i]}
1264          fi
1265       fi
1266
1267    fi
1268 done
1269   
1270    # GENERATE FULL FILENAMES OF OUTPUT-FILES (WITHOUT $ OR ~),
1271    # CHECK, IF OUTPUT-FILES EXIST, AND DETERMINE HIGHEST CYCLE NUMBER (IF CYCLES EXIST),
1272    # OR, IN CASE THAT FILE DOES NOT EXIST, CHECK, IF IT CAN BE CREATED 
1273    # THESE ACTIONS ARE NOT CARRIED OUT, IF FILES SHALL BE TRASFERRED FROM THE REMOTE TO
1274    # THE LOCAL HOST (BECAUSE THEIR IS NO DIRECT ACCESS TO THE LOCAL DIRECTORIES FROM THE
1275    # REMOTE HOST)
1276 (( i = 0 ))
1277 while (( i < iout ))
1278 do
1279    (( i = i + 1 ))
1280    if [[ ! ( $fromhost != $localhost  &&  ( "${actionout[$i]}" = tr || "${actionout[$i]}" = tra || "${actionout[$i]}" = trpe ) ) ]]
1281    then
1282       if [[ "${actionout[$i]}" = tr ]]
1283       then
1284          actionout[$i]=""
1285       elif [[ "${actionout[$i]}" = trpe ]]
1286       then
1287          actionout[$i]=pe
1288       elif [[ "${actionout[$i]}" = tra ]]
1289       then
1290          actionout[$i]=a
1291       fi
1292       (( maxcycle = 0 ))
1293       eval filename=${pathout[$i]}/${fname}${endout[$i]}
1294       eval catalogname=${pathout[$i]}
1295       if [[ $(ls $filename* 2>&1 | grep -c "not found") = 1  || \
1296             $(ls $filename* 2>&1 | grep -c "nicht gefunden") = 1  || \
1297             $(ls $filename* 2>&1 | grep -c "No such file") = 1  || \
1298             $(ls $filename* 2>&1 | grep -c "does not exist") = 1 ]]
1299       then
1300     
1301             # IF OUTPUT-FILE DOES NOT EXIST CHECK, IF IT CAN BE CREATED
1302          if  cat /dev/null > $filename 
1303          then
1304             rm  $filename
1305          else
1306
1307                # CHECK, IF THE DIRECTORY WHERE FILE SHALL BE COPIED TO EXISTS
1308                # IF IT DOES NOT EXIST, TRY TO CREATE IT
1309             if [[ ! -d $catalogname ]]
1310             then
1311                if  mkdir -p  $catalogname
1312                then
1313                   printf "\n\n  *** directory:"
1314                   printf "\n           $catalogname"
1315                   printf "\n      was created\n"
1316                else
1317                   printf "\n\n  +++ OUTPUT-file:"
1318                   printf "\n           $filename"
1319                   printf "\n      cannot be created, because directory does not exist"
1320                   printf "\n      and cannot be created either"
1321                   printf "\n"
1322                   locat=output  ; exit
1323                fi 2>/dev/null
1324             else
1325                printf "\n\n  +++ OUTPUT-file:"
1326                printf "\n           $filename"
1327                printf "\n      cannot be created, although directory exists"
1328                printf "\n"
1329                locat=output  ; exit
1330             fi
1331          fi 2>/dev/null
1332       else
1333
1334             # DETERMINE THE CYCLE NUMBER
1335          ls -1 -d $filename    >   filelist  2>/dev/null
1336          ls -1 -d $filename.*  >>  filelist  2>/dev/null
1337          while  read zeile
1338          do
1339             cycle=$(echo $zeile | cut -f2 -d".")
1340             if [[ "$cycle" = "$zeile"  ||  "$cycle" = ${extout[$i]} ]]
1341             then
1342                (( icycle = 1 ))
1343             else
1344                (( icycle = $cycle + 1 ))
1345             fi
1346             if (( icycle > maxcycle ))
1347             then
1348                (( maxcycle = icycle ))
1349             fi
1350          done <filelist
1351          rm filelist
1352       fi
1353
1354          # APPEND CYCLE NUMBER TO FILENAME AND CHECK, IF FILE CAN BE CREATED
1355          # IN CASE OF FILE-APPEND, FILE MUST BE APPENDED TO THE ONE WITH HIGHEST CYCLE NUMBER
1356       if [[ "${actionout[$i]}" != a ]]
1357       then
1358          if (( maxcycle > 0 ))
1359          then
1360             filename=${filename}.$maxcycle
1361             if  cat /dev/null > $filename 
1362             then
1363                rm  $filename
1364             else
1365                printf "\n  +++ OUTPUT-file:"
1366                printf "\n           $filename"
1367                printf "\n      cannot be created"
1368                locat=output  ; exit
1369             fi
1370          fi
1371       else
1372          (( maxcycle = maxcycle - 1 ))
1373          if (( maxcycle > 0 ))
1374          then
1375             filename=${filename}.$maxcycle
1376          fi
1377       fi
1378       
1379          # STORE FILENAME WITHOUT PATH BUT WITH CYCLE NUMBER,
1380          # BECAUSE IT MIGHT BE REQUIRED LATER TO STORE THE FILE ON AN ARCHIVE-SYSTEM
1381          # OR TO PUT THIS FILENAME ON FILE OUTPUT_FILE_CONNECTIONS
1382       pathout[$i]=$filename
1383       if (( maxcycle > 0 ))
1384       then
1385          frelout[$i]=${fname}${endout[$i]}.$maxcycle
1386       else
1387          frelout[$i]=${fname}${endout[$i]}
1388       fi
1389
1390    fi
1391 done
1392
1393
1394     # THE DVR-PACKAGE REQUIRES ITS OWN LIBRARY
1395 if [[ $(echo $package_list | grep -c dvrp_graphics) != 0 ]]
1396 then
1397    if [[ "$dvr_inc" = "" ]]
1398    then
1399       printf "\n\n  +++ no value for \"dvr_inc\" given in configuration file"
1400       printf "\n      This is required for the dvrp_graphics package.\n"
1401       locat=dvr; exit
1402    fi
1403    if [[ "$dvr_lib" = "" ]]
1404    then
1405       printf "\n\n  +++ no value for \"dvr_lib\" given in configuration file"
1406       printf "\n      This is required for the dvrp_graphics package.\n"
1407       locat=dvr; exit
1408    fi
1409 fi
1410
1411
1412     # CHECK, WETHER A MAIN PROGRAM OR AN EXECUTABLE HAVE BEEN DECLARED.
1413     # EXECUTABLES DO NOT NEED TO BE COMPILED.
1414 if [[ "$mainprog" = ""  &&  "$executable" = "" ]]
1415 then
1416    printf "\n  +++ neither main program nor executable defined"
1417    locat=source; exit
1418 elif [[ "$mainprog" != ""  &&  "$executable" != "" ]]
1419 then
1420    printf "\n  +++ main program as well as executable defined"
1421    locat=source; exit
1422 elif [[ "$mainprog" = ""  &&  "$executable" != "" ]]
1423 then
1424    do_compile=false
1425 fi
1426
1427
1428    # CREATE SOURCE-DIRECTORY TO COLLECT ROUTINES TO BE COMPILED.
1429    # LATER THE MRUN-SCRIPT AND CONFIGURATION-FILE WILL ALSO BE COPIED TO THIS DIRECTORY.
1430 if [[ $restart_run != true  &&  "$SOURCES_COMPLETE" = "" ]]
1431 then
1432    rm -rf  SOURCES_FOR_RUN_$fname
1433    mkdir   SOURCES_FOR_RUN_$fname
1434 fi
1435
1436
1437    # COLLECT ALL ROUTINES TO BE COMPILED
1438    # THIS IS NOT REQUIRED WITHIN BATCH-JOBS, BECAUSE ROUTINES HAVE ALREADY BEEN COLLECTED
1439    # BY THE MRUN-CALL WHICH CREATED THE BATCH-JOB.
1440 if [[ $do_compile = true  &&  "$SOURCES_COMPLETE" = "" ]]
1441 then
1442
1443    [[ "$source_list" = LM ]]  &&  source_list=LOCALLY_MODIFIED
1444
1445    if [[ "$source_list" = LOCALLY_MODIFIED ]]
1446    then
1447
1448          # DETERMINE MODIFIED FILES OF THE SVN WORKING COPY
1449       source_list=""
1450       cd  $source_path
1451
1452
1453          # CHECK, IF DIRECTORY IS UNDER SVN CONTROL
1454       if [[ ! -d .svn ]]
1455       then
1456          printf "\n\n  +++ source directory"
1457          printf "\n         \"$source_path\" "
1458          printf "\n         is not under control of \"subversion\"."
1459          printf "\n         Please do not use mrun-option \"-s LOCALLY_MODIFIED\"\n"
1460       fi
1461
1462
1463          # LIST ALL MODIFIED SOURCE CODE FILES
1464       Filenames=""
1465       svn status  >  tmp_mrun
1466       while  read line
1467       do
1468          firstc=`echo $line | cut -c1`
1469          if [[ $firstc = M  ||  $firstc = "?" ]]
1470          then
1471             Name=`echo "$line" | cut -c8-`
1472             extension=`echo $Name | cut -d. -f2`
1473             if [[ "$extension" = f90 || "$extension" = F90 || "$extension" = f || "$extension" = F || "$extension" = c ]]
1474             then
1475                Filenames="$Filenames "$Name
1476             fi
1477          fi
1478       done < tmp_mrun
1479
1480
1481          # COPY FILES TO SOURCES_FOR_RUN_...
1482       for  dateiname  in  $Filenames
1483       do
1484          cp  $dateiname  $working_directory/SOURCES_FOR_RUN_$fname
1485          source_list=$source_list"$dateiname "
1486       done
1487
1488       cd -  > /dev/null
1489
1490
1491       # COPY FILES GIVEN BY OPTION -s TO DIRECTORY SOURCES_FOR_RUN_...
1492       # AUTOMATIC RESTART RUNS JUST ACCESS THE DIRECTORY CREATED BY THE INITIAL RUN
1493    elif [[ "$source_list" != ""  &&  $restart_run != true ]]
1494    then
1495
1496       cd  $source_path
1497
1498       for  filename  in  $source_list
1499       do
1500
1501             # SOURCE CODE FILE IS NOT ALLOWED TO INCLUDE PATH
1502          if [[ $(echo $filename | grep -c "/") != 0 ]]
1503          then
1504             printf "\n  +++ source code file:  $filename"
1505             printf "\n      must not contain (\"/\") "
1506             locat=source; exit
1507          fi
1508
1509          if [[ ! -f $filename ]]
1510          then
1511             printf "\n  +++ source code file:  $filename"
1512             printf "\n      does not exist"
1513             locat=source; exit
1514          else
1515             cp  $filename  $working_directory/SOURCES_FOR_RUN_$fname
1516          fi
1517
1518       done
1519
1520       cd -  > /dev/null
1521
1522    fi
1523
1524
1525       # CHECK, IF A MAIN PROGRAM EXISTS AND IF IT IS PART OF THE LIST OF FILES
1526       # TO BE COMPILED. IF NOT, ADD IT TO THE LIST.
1527    if [[ $restart_run != true ]]
1528    then
1529
1530       if [[ ! -f "$source_path/$mainprog" ]]
1531       then
1532          printf "\n\n  +++ main program:  $mainprog"
1533          printf "\n      does not exist in source directory"
1534          printf "\n      \"$source_path\"\n"
1535          locat=source; exit
1536       else
1537          if [[ $(echo $source_list | grep -c $mainprog) = 0 ]]
1538          then
1539             cp  $source_path/$mainprog  SOURCES_FOR_RUN_$fname
1540             source_list=${mainprog}" $source_list"
1541          fi
1542       fi
1543    fi
1544
1545
1546       # CHECK, IF MAKEFILE EXISTS AND COPY IT TO THE SOURCES_FOR_RUN... DIRECTORY
1547       # NOT REQUIRED FOR RESTART RUNS, SOURCES_FOR_RUN... HAS BEEN CREATED BY THE INITIAL RUN
1548    if [[ "$restart_run" != true ]]
1549    then
1550       [[ "$makefile" = "" ]]  &&  makefile=$source_path/Makefile
1551       if [[ ! -f $makefile ]]
1552       then
1553          printf "\n  +++ file \"$makefile\" does not exist"
1554          locat=make; exit
1555       else
1556          cp  $makefile  SOURCES_FOR_RUN_$fname/Makefile
1557       fi
1558    fi
1559
1560
1561       # COPY FILES FROM OPTIONAL SOURCE PATH GIVEN IN THE CONFIGURATION FILE
1562    if [[ $restart_run != true  &&  "$add_source_path" != "" ]]
1563    then
1564
1565          # DOES THE DIRECTORY EXIST?
1566       if [[ ! -d $add_source_path ]]
1567       then
1568          printf "\n\n  +++ WARNING: additional source code directory"
1569          printf "\n      \"$add_source_path\" "
1570          printf "\n      does not exist or is not a directory."
1571          printf "\n      No source code will be used from this directory!\n"
1572          add_source_path=""
1573          if [[ $silent == false ]]
1574          then
1575             sleep 3
1576          fi
1577       else
1578
1579          cd $add_source_path
1580          found=false
1581
1582          Names=$(ls -1 *.f90 2>&1)
1583          [[ $(echo $Names | grep -c '*.f90') = 0 ]]  &&  AddFilenames="$Names"
1584          Names=$(ls -1 *.F90 2>&1)
1585          [[ $(echo $Names | grep -c '*.F90') = 0 ]]  &&  AddFilenames="$AddFilenames $Names"
1586          Names=$(ls -1 *.F 2>&1)
1587          [[ $(echo $Names | grep -c '*.F') = 0   ]]  &&  AddFilenames="$AddFilenames $Names"
1588          Names=$(ls -1 *.f 2>&1)
1589          [[ $(echo $Names | grep -c '*.f') = 0   ]]  &&  AddFilenames="$AddFilenames $Names"
1590          Names=$(ls -1 *.c 2>&1)
1591          [[ $(echo $Names | grep -c '*.c') = 0   ]]  &&  AddFilenames="$AddFilenames $Names"
1592
1593          cd -  > /dev/null
1594          cd  SOURCES_FOR_RUN_$fname
1595
1596             # COPY MAKEFILE IF EXISTING
1597          if [[ -f $add_source_path/Makefile ]]
1598          then
1599             printf "\n\n  *** user Makefile from directory"
1600             printf "\n      \"$add_source_path\" is used \n"
1601             if [[ $silent == false ]]
1602             then
1603                sleep 1
1604             fi
1605             cp  $add_source_path/Makefile  .
1606          fi
1607
1608          for  dateiname  in  $AddFilenames
1609          do
1610             if [[ -f $dateiname ]]
1611             then
1612                printf "\n  +++ source code file \"$dateiname\" found in additional"
1613                printf "\n      source code directory \"$add_source_path\" "
1614                printf "\n      but was also given with option \"-s\" which means that it should be taken"
1615                printf "\n      from directory \"$source_path\"."
1616                locat=source; exit
1617             fi
1618
1619             cp  $add_source_path/$dateiname  .
1620             source_list="$source_list $dateiname"
1621
1622                # CHECK IF FILE IS CONTAINED IN MAKEFILE
1623             if [[ $(grep -c $dateiname Makefile) = 0 ]]
1624             then
1625                printf "\n\n  +++ user file \"$dateiname\" "
1626                printf "\n      is not listed in Makefile \n"
1627                locat=source; exit
1628             else
1629
1630                if [[ $found = false ]]
1631                then
1632                   found=true
1633                   printf "\n\n  *** following user file(s) added to the"
1634                   printf " files to be translated:\n      "
1635                fi
1636                printf "$dateiname  "
1637                if [[ $silent == false ]]
1638                then
1639                   sleep 0.5
1640                fi
1641
1642             fi
1643          done
1644          [[ $found = true ]]  &&  printf "\n"
1645          cd -  > /dev/null
1646       fi
1647    fi
1648
1649
1650       # ADD ALL ROUTINES BELONGING TO SOFTWARE PACKAGES (GIVEN BY OPTION -p)
1651       # TO THE LIST OF FILES TO BE COMPILED
1652    if [[ $restart_run != true  &&  -n $package_list ]]
1653    then
1654
1655       cd  $source_path
1656
1657       for  package  in  $package_list
1658       do
1659
1660          [[ $package = "dvrp_graphics+1PE" ]]  &&  package=dvrp_graphics
1661
1662             # DETERMINE FILES BELONGING TO THE PACKAGE
1663             # ERROR MESSAGE ARE REDIRECTED TO /dev/null, BECAUSE WILDCARD (*) ALSO GIVES
1664             # THE NAME OF THE DIRECTORY
1665          package_source_list=`grep "defined( __$package " * 2>/dev/null | cut -f1 -d:`
1666
1667
1668             # ADD THESE FILES TO THE LIST OF FILES TO BE COMPILED,
1669             # IF THEY ARE NOT ALREADY PART OF THE LIST
1670          for  source_list_name  in  $package_source_list
1671          do
1672             if [[ $(echo $source_list | grep -c $source_list_name) = 0 ]]
1673             then
1674
1675                    # ONLY TAKE FILES WITH VALID SUFFIX
1676                ending=`echo $source_list_name | cut -f2 -d.`
1677                if [[ "$ending" = f90  ||  "$ending" = F90  ||  "$ending" = f  ||  "$ending" = F  ||  "$ending" = c ]]
1678                then
1679                   cp  $source_list_name  $working_directory/SOURCES_FOR_RUN_$fname
1680                   source_list="$source_list $source_list_name"
1681                fi
1682             fi
1683          done
1684       done
1685
1686       cd -  > /dev/null
1687    fi
1688
1689 fi  # do_compile=true
1690
1691
1692    # IF SOURCE CODE IS TO BE COMPILED, DO SOME MORE CHECKS
1693    # AND SET PRE-PROCESSOR DIRECTIVES
1694 if [[ $do_compile = true  ||  $create_executable_for_batch = true ]]
1695 then
1696
1697       # SET PREPROCESSOR-DIRECTIVES TO SELECT OPERATING SYSTEM SPECIFIC CODE
1698    if [[ $(echo $localhost | cut -c1-3) = ibm ]]
1699    then
1700       cpp_options="${cpp_options},-D__ibm=__ibm"
1701    elif [[ $(echo $localhost | cut -c1-3) = nec ]]
1702    then
1703       cpp_options="$cpp_options -D__nec"
1704    elif [[ $(echo $localhost | cut -c1-2) = lc ]]
1705    then
1706       cpp_options="$cpp_options -D__lc"
1707    else
1708       cpp_options="$cpp_options -D__$localhost"
1709    fi
1710
1711       # SET DIRECTIVES GIVEN BY OPTION -K (E.G. parallel)
1712    if [[ $(echo $localhost | cut -c1-3) = ibm ]]
1713    then
1714       [[ -n $cond1 ]]  &&  cpp_options="${cpp_options},-D__$cond1=__$cond1"
1715       [[ -n $cond2 ]]  &&  cpp_options="${cpp_options},-D__$cond2=__$cond2"
1716    else
1717       [[ -n $cond1 ]]  &&  cpp_options="$cpp_options -D__$cond1"
1718       [[ -n $cond2 ]]  &&  cpp_options="$cpp_options -D__$cond2"
1719    fi
1720
1721       # SET DIRECTIVES FOR ACTIVATING SOFTWARE-PACKAGES (OPTION -p)
1722    if [[ -n $package_list ]]
1723    then
1724       for  package  in  $package_list
1725       do
1726          if [[ $(echo $localhost | cut -c1-3) = ibm ]]
1727          then
1728             if [[ $package != "dvrp_graphics+1PE" ]]
1729             then
1730                cpp_options="${cpp_options},-D__$package=__$package"
1731             else
1732                cpp_options="${cpp_options},-D__dvrp_graphics=__dvrp_graphics"
1733                export use_seperate_pe_for_dvrp_output=true
1734             fi
1735          else
1736             if [[ $package != "dvrp_graphics+1PE" ]]
1737             then
1738                cpp_options="$cpp_options -D__$package"
1739             else
1740                cpp_options="$cpp_options -D__dvrp_graphics"
1741                export use_seperate_pe_for_dvrp_output=true
1742             fi
1743          fi
1744       done
1745    fi
1746
1747       # SET DIRECTIVES GIVEN BY OPTION -D
1748    if [[ -n $cpp_opts ]]
1749    then
1750       for  popts  in  $cpp_opts
1751       do
1752          if [[ $(echo $localhost | cut -c1-3) = ibm ]]
1753          then
1754             cpp_options="${cpp_options},-D__$popts=__$popts"
1755          else
1756             cpp_options="$cpp_options -D__$popts"
1757          fi
1758       done
1759    fi
1760
1761 else
1762
1763
1764       # FOR LOCAL RUNS CHECK AGAIN, IF EXECUTABLE EXISTS
1765    if [[ $do_remote = false ]]
1766    then
1767       if [[ ! -f $executable ]]
1768       then
1769          printf "\n  +++ executable file:  $executable"
1770          printf "\n      does not exist"
1771          locat=executable; exit
1772       fi
1773    fi
1774 fi
1775
1776
1777    # DETERMINE THE JOB MODE
1778 if [[ "$ENVIRONMENT" = BATCH ]]
1779 then
1780    batch_job=.TRUE.
1781    jobmo=BATCH
1782 else
1783    batch_job=.FALSE.
1784    jobmo=INTERACTIVE
1785 fi
1786
1787
1788    # NO INTERACTIVE RUNS ALLOWED ON LCTIT
1789 if [[ $host = lctit  &&  $jobmo = INTERACTIVE  &&  $do_batch = false ]]
1790 then
1791    printf "\n  +++ no interactive runs allowed on host \"$host\" "
1792    printf "\n      please submit batch job using mrun option \"-b\" \n"
1793    locat=normal; exit
1794 fi
1795
1796
1797    # CHECK, IF USER DEFINED A COMPILER
1798 if [[ "$compiler_name" = "" ]]
1799 then
1800
1801    printf "\n  +++ no compiler specified for \"$host $cond1 $cond2\""
1802    locat=compiler_name; exit
1803
1804 fi
1805
1806
1807    # DETERMINE THE NAME OF MRUN'S TEMPORARY WORKING DIRECTORY
1808 kennung=$RANDOM
1809 if [[ "$tmp_user_catalog" = "" ]]
1810 then
1811    if [[ $localhost = ibmh ]]
1812    then
1813       tmp_user_catalog=$SCRATCH
1814    elif [[ $localhost = nech ]]
1815    then
1816       tmp_user_catalog=$WRKSHR
1817    else
1818       tmp_user_catalog=/tmp
1819    fi
1820 fi
1821 TEMPDIR=$tmp_user_catalog/${usern}.$kennung
1822
1823
1824    # DETERMINE THE NAME OF THE DIRECTORY WHICH IS USED TO TEMPORARILY STORE DATA FOR RESTART RUNS
1825 if [[ "$tmp_data_catalog" = "" ]]
1826 then
1827    if [[ $localhost = nech ]]
1828    then
1829       tmp_data_catalog=$WRKSHR/mrun_restart_data
1830    else
1831       tmp_data_catalog=/tmp/mrun_restart_data
1832    fi
1833 fi
1834
1835
1836    # IN CASE OF LOCAL RUNS REPLACE ENVIRONMENT VARIABLES BY THEIR VALUES
1837 if [[ $do_remote = false  &&  $do_compile = true  ||  $create_executable_for_batch = true ]]
1838 then
1839    eval  fopts=\"$fopts\"
1840    eval  lopts=\"$lopts\"
1841 fi
1842
1843
1844
1845    # DETERMINE COMPILE- AND LINK-OPTIONS
1846 fopts="$fopts $netcdf_inc $fftw_inc $dvr_inc"
1847 lopts="$lopts $netcdf_lib $fftw_lib $dvr_lib"
1848 ROPTS="$ropts"
1849# if [[ ( $(echo $host | cut -c1-3) = nec  ||  $(echo $host | cut -c1-3) = ibm  ||  $host = lckyoto  ||  $host = lctit  ||  $host = lcflow  ||  $host = lcxe6 ||  $host = lcxt5m || $host = lck || $host = lckiaps || $host = lckordi || $host = lcsb || $host )  &&  -n $numprocs ]]
1850# then
1851    XOPT="-X $numprocs"
1852# fi
1853
1854
1855
1856    # CHECK THE CPU-LIMIT. IT MUST BE GIVEN FOR BATCH-JOBS AND IS COMMUNICATED TO THE
1857    # EXECUTABLE VIA NAMELIST-PARAMETER cputime
1858 done=false
1859 while [[ $done = false ]]
1860 do
1861    cputime=$cpumax
1862    if (( $cputime == 0 ))
1863    then
1864       if [[ $do_batch = true ]]
1865       then
1866          printf "\n  +++ cpu-time is undefined"
1867          printf "\n  >>> Please type CPU-time in seconds as INTEGER:"
1868          printf "\n  >>> "
1869          read  cputime  1>/dev/null  2>&1
1870       else
1871          cputime=10000000   # NO CPU LIMIT FOR INTERACTIVE RUNS
1872       fi
1873    else
1874       done=true
1875    fi
1876    cpumax=$cputime
1877 done
1878
1879 (( minuten = cputime / 60 ))
1880 (( sekunden = cputime - minuten * 60 ))
1881
1882
1883    # CHECK THE MEMORY DEMAND
1884 if [[ $do_batch = true ]]
1885 then
1886    done=false
1887    while [[ $done = false ]]
1888    do
1889       if (( memory == 0 ))
1890       then
1891          printf "\n  +++ memory demand is undefined"
1892          printf "\n  >>> Please type memory in  MByte per process  as INTEGER:"
1893          printf "\n  >>> "
1894          read  memory  1>/dev/null  2>&1
1895       else
1896          done=true
1897       fi
1898    done
1899 fi
1900
1901
1902    # IN CASE OF REMOTE-JOBS CHECK, IF A USERNAME FOR THE REMOTE HOST IS GIVEN
1903 if [[ $do_remote = true  &&  -z $remote_username ]]
1904 then
1905    while [[ -z $remote_username ]]
1906    do
1907       printf "\n  +++ username on remote host \"$host\" is undefined"
1908       printf "\n  >>> Please type username:"
1909       printf "\n  >>> "
1910       read  remote_username
1911    done
1912    mc="$mc -u$remote_username"
1913 fi
1914
1915    # CHECK FOR INITIAL COMMANDS AFTER LOGIN
1916 if [[ "$login_init_cmd" != "" ]]
1917 then
1918    export init_cmds="${login_init_cmd};"
1919 fi
1920
1921
1922    # SET THE MODULE-LOAD COMMAD AND EXPORT IT FOR subjob
1923 if [[ "$modules" != "" ]]
1924 then
1925    if [[ $host = lctit ]]
1926    then
1927       export module_calls=". $modules"
1928    else
1929       export module_calls="module load ${modules};"
1930    fi
1931 fi
1932
1933
1934
1935    # OUTPUT OF THE MRUN-HEADER
1936 calltime=$(date)
1937 printf "\n"
1938 printf "#------------------------------------------------------------------------# \n"
1939 printf "| %-35s%35s | \n" "$version" "$calltime"
1940 printf "|                                                                        | \n"
1941 spalte1="called on:"; spalte2=$localhost_realname
1942 printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
1943 if [[ $do_remote = true ]]
1944 then
1945    spalte1="execution on:"; spalte2="$host (username: $remote_username)"
1946 else
1947    spalte1="execution on:"; spalte2="$host ($localhost_realname)"
1948 fi
1949 printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
1950 if [[ -n $numprocs ]]
1951 then
1952    if [[ $run_coupled_model = false ]]
1953    then
1954       spalte1="number of PEs:"; spalte2=$numprocs
1955    else
1956       spalte1="number of PEs:"; spalte2="$numprocs  (atmosphere: $numprocs_atmos, ocean: $numprocs_ocean)"
1957    fi
1958    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
1959 fi
1960 if [[ -n $tasks_per_node ]]
1961 then
1962    spalte1="tasks per node:"; spalte2="$tasks_per_node (number of nodes: $nodes)"
1963    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
1964    if (( remaining_pes > 0 ))
1965    then
1966       spalte1=" "; spalte2="one of the nodes only filled with $remaining_pes tasks"
1967       printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
1968    fi
1969 fi
1970 if [[ $maximum_parallel_io_streams != $numprocs ]]
1971 then
1972    spalte1="max par io streams:"; spalte2="$maximum_parallel_io_streams"
1973    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
1974 fi
1975 if [[ $use_openmp = true ]]
1976 then
1977    spalte1="threads per task:"; spalte2="$threads_per_task"
1978    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
1979 fi
1980 printf "|                                                                        | \n"
1981 if [[ $do_compile = true ]]
1982 then
1983    if [[ "$mopts" != "" ]]
1984    then
1985       spalte1="make options:"; spalte2=$(echo "$mopts" | cut -c-45)
1986       printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
1987       zeile=$(echo "$mopts" | cut -c46-)
1988       while [[ "$zeile" != "" ]]
1989       do
1990          spalte1=""
1991          spalte2=$(echo "$zeile" | cut -c-45)
1992          printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
1993          zeile=$(echo "$zeile" | cut -c46-)
1994       done
1995    fi
1996
1997    spalte1="cpp directives:"; spalte2=$(echo "$cpp_options" | cut -c-45)
1998    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
1999    zeile=$(echo "$cpp_options" | cut -c46-)
2000    while [[ "$zeile" != "" ]]
2001    do
2002       spalte1=""
2003       spalte2=$(echo "$zeile" | cut -c-45)
2004       printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2005       zeile=$(echo "$zeile" | cut -c46-)
2006    done
2007
2008    spalte1="compiler options:"; spalte2=$(echo "$fopts" | cut -c-45)
2009    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2010    zeile=$(echo "$fopts" | cut -c46-)
2011    while [[ "$zeile" != "" ]]
2012    do
2013       spalte1=""
2014       spalte2=$(echo "$zeile" | cut -c-45)
2015       printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2016       zeile=$(echo "$zeile" | cut -c46-)
2017    done
2018
2019    spalte1="linker options:"; spalte2=$(echo "$lopts" | cut -c-45)
2020    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2021    zeile=$(echo "$lopts" | cut -c46-)
2022    while [[ "$zeile" != "" ]]
2023    do
2024       spalte1=""
2025       spalte2=$(echo "$zeile" | cut -c-45)
2026       printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2027       zeile=$(echo "$zeile" | cut -c46-)
2028    done
2029
2030    spalte1="modules to be load:"; spalte2=$(echo "$modules" | cut -c-45)
2031    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2032    zeile=$(echo "$modules" | cut -c46-)
2033    while [[ "$zeile" != "" ]]
2034    do
2035       spalte1=""
2036       spalte2=$(echo "$zeile" | cut -c-45)
2037       printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2038       zeile=$(echo "$zeile" | cut -c46-)
2039    done
2040
2041    spalte1="main program:"; spalte2=$mainprog
2042    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2043 else
2044    spalte1=executable:; spalte2=$executable
2045    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2046 fi
2047 printf "|                                                                        | \n"
2048 spalte1="base name of files:"; spalte2=$fname
2049 printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2050 if [[ $fname != $afname ]]
2051 then
2052    spalte1="base name of input files:"; spalte2=$afname
2053    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2054 fi
2055 spalte1="INPUT control list:"; spalte2=$(echo $input_list)
2056 printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2057 spalte1="OUTPUT control list:"; spalte2=$(echo $output_list)
2058 printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2059
2060 if [[ "$ocean_file_appendix" = true ]]
2061 then
2062    printf "| %-35s%-35s | \n" "suffix \"_O\" is added to local files" " "
2063 fi
2064
2065 if [[ $do_batch = true  ||  "$LOADLBATCH" = yes ]]
2066 then
2067    spalte1="memory demand / PE":; spalte2="$memory MB"
2068    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2069    spalte1=CPU-time:; spalte2="$minuten:$sekunden"
2070    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2071 fi
2072
2073 if [[ $do_compile = true ]]
2074 then
2075    printf "|                                                                        | \n"
2076    printf "| Files to be compiled:                                                  | \n"
2077    zeile=$source_list
2078    while [[ "$zeile" != "" ]]
2079    do
2080       linestart=$(echo $zeile | cut -c-70)
2081       printf "| %-70s | \n" "$linestart"
2082       zeile=$(echo "$zeile" | cut -c71-)
2083    done
2084 fi
2085 printf "#------------------------------------------------------------------------#"
2086
2087
2088
2089    # OUTPUT OF FILE CONNECTIONS IN CASE OF TRACEBACK
2090 if [[ $do_trace = true ]]
2091 then
2092    (( i = 0 ))
2093    while (( i < iin ))
2094    do
2095       (( i = i + 1 ))
2096       if (( i == 1 ))
2097       then
2098          printf "\n\n >>> INPUT-file assignments:\n"
2099       fi
2100       printf "\n     ${localin[$i]} :  ${absnamein[$i]}"
2101    done
2102    (( i = 0 ))
2103    while (( i < iout ))
2104    do
2105       (( i = i + 1 ))
2106       if (( i == 1 ))
2107       then
2108          printf "\n\n >>> OUTPUT-file assignments:\n"
2109       fi
2110       printf "\n     ${localout[$i]} :  ${pathout[$i]}"
2111    done
2112    (( i = 0 ))
2113    while (( i < iic ))
2114    do
2115       (( i = i + 1 ))
2116       if (( i == 1 ))
2117       then
2118          printf "\n\n >>> INPUT-commands:\n"
2119       fi
2120       printf "\n     ${in_command[$i]}" 
2121    done
2122    (( i = 0 ))
2123    while (( i < ioc ))
2124    do
2125       (( i = i + 1 ))
2126       if (( i == 1 ))
2127       then
2128          printf "\n\n >>> OUTPUT-commands:\n"
2129       fi
2130       printf "\n     ${out_command[$i]}" 
2131    done
2132 fi
2133
2134
2135    # QUERY FOR CONTINUE (ON LOCAL MACHINES ONLY)
2136 if [[ $remotecall = false  &&  $silent = false  &&  $jobmo != BATCH ]]
2137 then
2138    antwort=dummy
2139    printf "\n\n"
2140    printf " >>> everything o.k. (y/n) ?  "
2141    while  read antwort
2142    do
2143       if [[ "$antwort" != y  &&  "$antwort" != Y  &&  "$antwort" != n  &&  "$antwort" != N ]]
2144       then
2145          printf " >>> everything o.k. (y/n) ?  "
2146       else
2147          break
2148       fi
2149    done
2150    if [[ $antwort = n  ||  $antwort = N ]]
2151    then
2152       locat=user_abort; (( iec = 0 )); exit
2153    fi
2154    if [[ $do_batch = true ]]
2155    then
2156       printf " >>> batch-job will be created and submitted"
2157    else
2158       printf " >>> MRUN will now continue to execute on this machine"
2159    fi
2160 fi
2161
2162
2163    # PERFORM PARAMETER FILE CHECK (COUPLED RUNS ARE NOT SUPPORTED YET)
2164    # DEFINE VARIABLES FOR FREQUENTLY USED DIRECTORIES
2165 check_depository="${working_directory}/trunk/UTIL"
2166 check_sources="${working_directory}/tmp_check_namelist_files"
2167 skip_check=false
2168
2169    # CHECK IF NAMELIST_FILE_CHECK HAS BEEN COMPILED SUCCESSFULLY
2170 if [[ ! -f $check_depository/check_namelist_files.tar ]]
2171 then
2172    skip_check=true
2173    reason="run on remote host or parameter file check has not been compiled."
2174 fi
2175 if [[ ! -f $PALM_BIN/check_namelist_files.x ]]
2176 then
2177    skip_check=true
2178    reason="parameter file check has not been compiled."
2179 fi
2180
2181    # CHECK FOR PARALLEL RUN; OTHERWISE SKIP CHECK
2182 if [[ "$cond1" != "parallel"  &&  "$cond2" != "parallel" ]]
2183 then
2184    skip_check=true
2185    reason="serial run."
2186 fi
2187
2188    # ONLY PERFORM CHECK IF -z OPTION IS NOT SET, NO RESTART RUN IS CARRIED OUT
2189    # AND IF THE EXECUTION HOST IS THE LOCAL HOST
2190    # ATTENTION: THIS ROUTINE DOES NOT WORK IF THE COMPILER ON THE LOCAL HOST
2191    # DIFFERS FROM THE COMPILER ON THE REMOTE HOST
2192 if [[ $check_namelist_files == false ]]
2193 then
2194    skip_check=true
2195    reason="-z option set."
2196 fi
2197
2198 if [[ $fromhost != $localhost ]]
2199 then
2200    skip_check=true
2201    reason="submitting host is local host." 
2202 fi 
2203
2204 if [[ $run_coupled_model == true ]]
2205 then
2206    skip_check=true
2207    reason="coupled run." 
2208 fi
2209
2210 if [[ $restart_run == true ]]
2211 then
2212    skip_check=true
2213    reason="restart run."     
2214 fi
2215
2216    # SKIP CHECK IN CASE OF RESTART RUN: CHECK WHETHER THE LAST CHAR IS "f" IN PARIN
2217 (( last_char_int = `echo $filename_input | wc -c` - 1 ))
2218 last_char=`echo $filename_input | cut -c $last_char_int`
2219 if [[ "$last_char" == "f" ]]
2220 then
2221    skip_check=true
2222    reason="restart run."
2223 fi
2224
2225 if [[ $skip_check == false ]]
2226 then
2227    tmp_check=${working_directory}/tmp_check
2228
2229       # GET TOPOGRAPHY PARAMETER FILE SUFFIX (USUALLY "_TOPO"). THIS FILE IS
2230       # NOT NECESSARILY REQUIRED
2231    line=""
2232    found=false
2233    grep  "TOPOGRAPHY_DATA" $config_file  >  $tmp_check
2234    while read line1
2235    do
2236       line="$line1"
2237       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
2238       then
2239          topo_suffix=`echo $line | tr -s " " | cut -d" " -s -f5`
2240          found=true
2241       fi
2242    done < $tmp_check
2243
2244    if [[ $found = false ]]
2245    then
2246       printf "\n  +++ no TOPOGRAPHY list entry found in the configuration file."
2247    fi
2248
2249       # GET NUDGING PARAMETER FILE SUFFIX (USUALLY "_NUDGE"). THIS FILE IS
2250       # NOT NECESSARILY REQUIRED
2251    line=""
2252    found=false
2253    grep  "NUDGING_DATA" $config_file  >  $tmp_check
2254    while read line1
2255    do
2256       line="$line1"
2257       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
2258       then
2259          nudge_suffix=`echo $line | tr -s " " | cut -d" " -s -f5`
2260          found=true
2261       fi
2262    done < $tmp_check
2263
2264    if [[ $found = false ]]
2265    then
2266       printf "\n  +++ no NUDGING list entry found in the configuration file."
2267    fi
2268
2269       # GET LARGE SCALE FORCING PARAMETER FILE SUFFIX (USUALLY "_LSF"). THIS FILE IS
2270       # NOT NECESSARILY REQUIRED
2271    line=""
2272    found=false
2273    grep  "LSF_DATA" $config_file  >  $tmp_check
2274    while read line1
2275    do
2276       line="$line1"
2277       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
2278       then
2279          lsf_suffix=`echo $line | tr -s " " | cut -d" " -s -f5`
2280          found=true
2281       fi
2282    done < $tmp_check
2283
2284    if [[ $found = false ]]
2285    then
2286       printf "\n  +++ no LSF list entry found in the configuration file."
2287    fi
2288
2289    rm -rf ${working_directory}/tmp_check
2290
2291       # CHECK IF THE P3DF FILE MUST BE CHECKED
2292    for  item  in  $input_list
2293    do
2294       if [[ "$item" == "restart" ]]
2295       then
2296          check_restart=1
2297       else
2298          check_restart=0
2299       fi
2300    done
2301
2302      # ERROR IF NO PARAMETER FILE WAS FOUND, OTHERWISE PROCEED
2303    if [[ (! -f $filename_input) && ( "$filename_input" != "" ) ]]
2304    then
2305       printf "\n\n  +++ ERROR: parameter file ($filename_input) not found." 
2306       locat=check_namelist; exit
2307    fi
2308   
2309       # CHECK IF THE RESTART PARAMETER FILE EXISTS (IF NECESSARY)
2310    if  [[ $check_restart == 1 ]]
2311    then
2312
2313       filenamef="${filename_input}f"
2314       if [[ ! -f $filenamef ]]
2315       then
2316          printf "\n\n  +++ WARNING: restart parameter file ($filenamef) is missing." 
2317          check_restart=0
2318          answer=dummy
2319          printf "\n\n"
2320
2321          if [[ $silent == false ]]
2322          then
2323             while [[ "$answer" != c  &&  "$answer" != C  && "$answer" != a  &&  "$answer" != A ]]
2324             do
2325                printf " >>> continue anyway (c(ontinue)/a(bort)) ?  "
2326                read  answer
2327             done
2328             if [[ $answer = a  ||  $answer = A ]]
2329             then
2330                printf "\n  +++ Aborting...."
2331                locat=normal; exit
2332             fi
2333          fi
2334       else
2335          check_restart=1
2336       fi
2337    fi
2338
2339       # CREATE TEMPORARY SOURCES_FOR_CHECK PATH
2340    mkdir $check_sources
2341    cd $check_sources
2342
2343
2344       # CHECK FOR USER CODE, OTHERWISE USE THE PRECOMPILED CHECK_NAMELIST_FILES.X
2345    if [[ -d $add_source_path ]]
2346    then
2347       printf "\n\n  *** copying files from $check_depository" 
2348       cp $check_depository/check_namelist_files.tar ./
2349
2350       printf "\n\n  *** untar of makefile and source files in $check_sources"
2351       tar -xf check_namelist_files.tar  >  /dev/null  2>&1
2352
2353       printf "\n\n  *** adding user code." 
2354       cp $add_source_path/* ./
2355       touch check_namelist_files.f90
2356
2357          # GET COMPILER OPTIONS AND PERFORM MAKE
2358       printf "\n\n  *** compiling code if necessary...\n"
2359
2360          # workaround for batch jobs on local machine (lcxe6)
2361       if [[ $do_batch == true && $do_remote == false ]]
2362       then
2363          eval $init_cmds
2364       fi
2365
2366          # GET CHECK OPTIONS
2367       line=""
2368       found=false
2369
2370       grep  "$localhost" ${base_directory}/${config_file} | grep "%cpp_options"  >  $tmp_check
2371
2372       while read line1
2373       do
2374
2375          if [[ $(echo $line1 | cut -d" " -s -f3-) = "$localhost" ]]
2376          then
2377             line="$line1"
2378          fi
2379
2380          if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
2381          then
2382                # REMOVE COLONS FROM OPTION-STRING, REMOVE ALL -D OPTIONS
2383             line="$line "
2384             copts_check=`echo $line | cut -d" " -s -f2 | sed 's/::/%DUM%/g' | sed 's/:/ /g' | sed 's/%DUM%/:/g' | sed 's/-D[^ ]* //g' | sed 's/ -D.*//g'`
2385             found=true
2386          fi
2387
2388       done < $tmp_check
2389       copts_check="$copts_check -D__check -D__parallel"
2390
2391       make -f Makefile_check F90=$compiler_name_ser  COPT="$copts_check"
2392
2393          # GET MAKE OUTPUT
2394       if [[ $? != 0 ]]
2395       then
2396          printf "\n  +++ error during make."       
2397          answer=dummy
2398          printf "\n\n"
2399          if [[ $silent == false ]]
2400          then
2401             while [[ "$answer" != c  &&  "$answer" != C  && "$answer" != a  &&  "$answer" != A ]]
2402             do
2403                printf " >>> continue anyway (c(ontinue)/a(bort)) ?  "
2404                read  answer
2405             done
2406             if [[ $answer = a  ||  $answer = A ]]
2407             then
2408                printf "\n  +++ Aborting..."
2409                rm -rf  $check_sources
2410                locat=normal; exit
2411             else
2412                skip_check=true
2413             fi
2414          else
2415             skip_check=true
2416          fi
2417       fi
2418    else
2419       cp $PALM_BIN/check_namelist_files.x ./
2420    fi
2421
2422    cp $filename_input ./PARIN
2423    if [[ $check_restart == 1 ]] 
2424    then
2425       cp $filenamef ./PARINF   
2426    fi
2427
2428    if [[ -f ${pathname}/${fname}${topo_suffix} && $skip_check == false ]]
2429    then
2430       printf "\n  *** adding topography data"
2431       cp ${pathname}/${fname}${topo_suffix} ./TOPOGRAPHY_DATA
2432
2433          # IN CASE OF TOPOGRAPHY AND HIGH GRID POINT NUMBERS, THE STACK SIZE
2434          # MUST BE INCREASED. THIS IS DUE TO THE ARRAY nzb_local AND topo_height,
2435          # WHICH REQUIRE SUFFICIENT MEMORY
2436       ulimit -s unlimited         
2437    fi
2438
2439    if [[ -f ${pathname}/${fname}${nudge_suffix} && $skip_check == false ]]
2440    then
2441       printf "\n  *** adding nudging data"
2442       cp ${pathname}/${fname}${nudge_suffix} ./NUDGING_DATA       
2443    fi
2444
2445    if [[ -f ${pathname}/${fname}${lsf_suffix} && $skip_check == false ]]
2446    then
2447       printf "\n  *** adding large scale forcing data"
2448       cp ${pathname}/${fname}${lsf_suffix} ./LSF_DATA       
2449    fi
2450
2451       # CREATE ENVPAR FILE, WHICH IS NEEDED BY CHECK_NAMELIST_FILES.X
2452    cat  >  ENVPAR  <<  %%END%%
2453 &envpar  run_identifier = '$fname', host = '$host',
2454            write_binary = '$write_binary', tasks_per_node = $tasks_per_node,
2455            maximum_parallel_io_streams = $maximum_parallel_io_streams,
2456            maximum_cpu_time_allowed = ${cpumax}.,
2457            revision = '$global_revision',
2458            local_dvrserver_running = $local_dvrserver_running /
2459
2460%%END%%
2461
2462       # SAFETY CHECK: ONLY PROCEED IF THE PARAMETER CHECK PROGRAM WAS PROPERLY COMPILED
2463    if [[ ! -f check_namelist_files.x  &&  $skip_check == false ]]
2464    then
2465       printf "\n  +++ WARNING: check_namelist_files.x not found."
2466       answer=dummy
2467       printf "\n\n"
2468
2469       if [[ $silent == false ]]
2470       then
2471          while [[ "$answer" != c  &&  "$answer" != C  && "$answer" != a  &&  "$answer" != A ]]
2472          do
2473             printf " >>> continue anyway (c(ontinue)/a(bort)) ?  "
2474             read  answer
2475          done
2476          if [[ $answer = a  ||  $answer = A ]]
2477          then
2478             printf "\n  +++ Aborting..."
2479             rm -rf  $check_sources
2480             locat=normal; exit
2481          else
2482             printf "\n  *** skipping parameter file check."         
2483          fi
2484      fi
2485       
2486    elif [[ $skip_check == false ]]
2487    then
2488          # STARTING THE PARAMETER FILE CHECK
2489       printf "\n\n  *** starting parameter file check..."
2490
2491          # CHECKING THE P3D FILE
2492       printf "\n\n      (1) checking $filename_input" 
2493       echo "$numprocs 0 0" > VARIN
2494       errors=`./check_namelist_files.x < VARIN 2>&1`
2495
2496       check_error=false
2497       if [[ "$errors" == "" ]]
2498       then
2499          printf " --> o.k."
2500       else
2501          printf " --> failed."
2502          check_error=true
2503          printf "\n\n  $errors"
2504       fi
2505
2506          # CHECKING THE PD3F FILE IF NECESSARY
2507       if [[ $check_restart == 1 && $check_error == false ]]
2508       then
2509          printf "\n\n      (2) checking $filenamef" 
2510
2511             # FIRST CHECK IF INITIALIZING_ACTIONS="READ_RESTART_DATA" IS SET
2512             # IN &INIPAR LIST
2513          found=false
2514          cat PARINF | while read line
2515          do
2516             line=$(echo $line|sed 's/ //g')
2517             if [[ $line == *"&inipar"* ]]
2518             then
2519                start_search=true
2520             fi
2521
2522             if [[ $start_search == true ]]
2523             then
2524                if [[ $line == *"initializing_actions='read_restart_data'"* ]]
2525                then
2526                   found=true
2527                   break
2528                fi
2529             fi
2530
2531             if [[ $line == *"/"* ]]
2532             then
2533                start_search=false
2534             fi
2535
2536          done
2537
2538          if [[ $found = false ]]
2539          then
2540             printf "\n\n  +++ ERROR: initializing_actions = 'read_restart_data' not found"
2541             printf "\n      in &inipar list in $fname$p3df_suffix."
2542             rm -rf  $check_sources
2543             locat=check_namelist; exit
2544          fi
2545
2546             # READ max_user_pr FROM FILES
2547          if [[ -f parin_for_check ]]
2548          then
2549             read max_pr_user < parin_for_check
2550          else
2551             max_user_pr=0
2552          fi
2553
2554          echo "$numprocs 1 $max_pr_user" > VARIN
2555          errors=`./check_namelist_files.x < VARIN 2>&1`
2556
2557          if [[ "$errors" == "" ]]
2558          then
2559             printf " --> o.k."
2560          else
2561             printf " --> failed."
2562             check_error=true
2563             printf "\n\n  $errors"
2564          fi
2565       fi
2566   
2567          # REPORT ERRORS AND CONTINUE/EXIT
2568       if [[ $check_error == true ]]
2569       then
2570          printf "\n  +++ errors found in the parameter file!\n"
2571          answer=dummy
2572          printf "\n\n"
2573
2574          while [[ "$answer" != c  &&  "$answer" != C  && "$answer" != a  &&  "$answer" != A ]]
2575          do
2576             printf " >>> continue anyway (c(ontinue)/a(bort)) ?  "
2577             read  answer
2578          done
2579
2580          if [[ $answer = a  ||  $answer = A ]]
2581          then
2582             printf "\n  +++ Aborting..."
2583             rm -rf  $check_sources
2584             locat=normal; exit
2585          fi
2586        else
2587          printf "\n\n  *** parameter file(s) seem(s) to be o.k.\n"
2588        fi
2589        rm -rf $check_sources
2590    fi
2591 else
2592    printf "\n\n  +++ skipping parameter file check due to following reason: $reason \n" 
2593 fi
2594
2595    # DELETE TEMPORARY DIRECTORY AND FINISH NAMELIST FILE CHECK   
2596 rm -rf  $check_sources
2597 cd $working_directory
2598
2599
2600    # DETERMINE PATH FOR MAKE DEPOSITORY
2601 if [[ $do_batch = false  ||  $create_executable_for_batch = true ]]
2602 then
2603
2604    line=""
2605    grep "%depository_path" $config_file  >  tmp_mrun
2606    while read line
2607    do
2608       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
2609       then
2610          if [[ "$(echo $line | cut -d" " -s -f3)" = "" ]]
2611          then
2612             global_depository_path=`echo $line | cut -d" " -s -f2`
2613          fi
2614       fi
2615    done < tmp_mrun
2616
2617    line=""
2618    grep  " $localhost" $config_file | grep "%depository_path"  >  tmp_mrun
2619    while read line
2620    do
2621       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
2622       then
2623          if [[ "$(echo $line | cut -d" " -s -f4)" = "$cond1"  &&  "$(echo $line | cut -d" " -s -f5)" = "$cond2" ]]
2624          then
2625             local_depository_path=`echo $line | cut -d" " -s -f2`
2626          fi
2627       fi
2628    done < tmp_mrun
2629
2630    if [[ "$local_depository_path" = "" ]]
2631    then
2632       if [[ "$global_depository_path" != "" ]]
2633       then
2634          local_depository_path=$global_depository_path
2635       else
2636          printf "\n\n  +++ no depository path found in configuration file"
2637          printf "\n      for local host \"$localhost\" "
2638          printf "\n      please set \"\%depository_path\" in configuration file\n"
2639          locat=config_file; exit
2640       fi
2641    fi
2642    eval local_depository_path=$local_depository_path
2643    [[ "$cond1" != "" ]]  &&  local_depository_path=${local_depository_path}_$cond1
2644    [[ "$cond2" != "" ]]  &&  local_depository_path=${local_depository_path}_$cond2
2645
2646
2647    basename=`echo $mainprog | cut -f1 -d"."`
2648    eval make_depository=${local_depository_path}/${basename}_current_version.tar
2649    if [[ ! -f $make_depository ]]
2650    then
2651       printf "\n"
2652       printf "\n  *** WARNING: make depository \"$make_depository\" not found"
2653       printf "\n               \"make\" will fail, if the Makefile or other source files are missing\n"
2654    fi
2655
2656 fi
2657
2658
2659    # NOW PERFORM THOSE ACTIONS REQUIRED TO EXECUTE THE PROGRAM (PALM) ON THIS MACHINE
2660    # (COMPILING/LINKING, EXECUTING, COPYING I/O FILES)
2661 if [[ $do_batch = false ]]
2662 then
2663
2664
2665       # CREATE THE TEMPORARY WORKING DIRECTORY
2666    mkdir -p  $TEMPDIR
2667    chmod  go+rx  $TEMPDIR
2668    tmpcreate=true
2669
2670
2671       # COPY EITHER THE COMPLETE SOURCE CODE FILES TO BE COMPILED OR THE EXECUTABLE
2672       # INTO THE TEMPORARY WORKING DIRECTORY
2673    if [[ $do_compile = true ]]
2674    then
2675
2676          # ON NEC, COMPILATION IS DONE ON HOST CROSS VIA CROSS COMPILING
2677          # CREATE A TEMPORARY DIRECTORY ON THAT MACHINE (HOME MOUNTED VIA NFS)
2678       if [[ $localhost = nech ]]
2679       then
2680          TEMPDIR_COMPILE=$HOME/work/${usern}.$kennung
2681          if  mkdir -p  $TEMPDIR_COMPILE
2682          then
2683             printf "\n  *** \"$TEMPDIR_COMPILE\" "
2684             printf "\n      is generated as temporary directory for cross compiling\n"
2685          else
2686             printf "\n  +++ creating directory \"$TEMPDIR_COMPILE\" "
2687             printf "\n      needed for cross compilation failed"
2688             locat=compile
2689             exit
2690          fi
2691       else
2692          TEMPDIR_COMPILE=$TEMPDIR
2693       fi
2694
2695       cp  $make_depository  $TEMPDIR_COMPILE
2696       cd  $TEMPDIR_COMPILE
2697       tar -xf  $make_depository  >  /dev/null  2>&1
2698       cd -  > /dev/null
2699
2700          # DUE TO UNKNOWN REASONS, COPY WITH cp COMMAND CREATES CORRUPT
2701          # FILES ON CRAY XC30 SYSTEMS (HLRN III), rsync IS USED INSTEAD
2702       if [[ $(echo $host | cut -c1-6) = lccray ]]
2703       then
2704          rsync -av -t  SOURCES_FOR_RUN_$fname/*  $TEMPDIR_COMPILE  >  /dev/null
2705       else
2706          cp  SOURCES_FOR_RUN_$fname/*  $TEMPDIR_COMPILE  >  /dev/null
2707       fi
2708
2709    else
2710
2711       cp  $executable   ${TEMPDIR}/a.out
2712
2713    fi
2714
2715
2716       # CHANGE TO THE TEMPORARY WORKING DIRECTORY
2717    cd  $TEMPDIR
2718    printf "\n  *** changed to temporary directory: $TEMPDIR"
2719
2720
2721       # THE FOLLOWING IS REQUIRED FPR AVS-OUTPUT WITH PALM  ??? REMOVE ???
2722       # WRITE INFORMATIONS ABOUT THE OUTPUT-FILE CONNECTIONS TO A TEMPORARY FILE
2723       # THIS FILE CAN LATER BE READ FROM USER-DEFINED CODE TO DETERMINE THE
2724       # RELATION BETWEEN THE LOCAL TEMPORARY AND PERMANENT FILE NAMES
2725    (( i = 0 ))
2726    while (( i < iout ))
2727    do
2728       (( i = i + 1 ))
2729       if [[ "${actionout[$i]}" = tr  ||  "${actionout[$i]}" = tra  ||  "${actionout[$i]}" = trpe ]]
2730       then
2731          printf "${localout[$i]} ${actionout[$i]}\n${pathout[$i]}\n${localhost}_${fname}${endout[$i]}\n" >> OUTPUT_FILE_CONNECTIONS
2732       else
2733          printf "${localout[$i]} ${actionout[$i]}\n${pathout[$i]}\n${frelout[$i]}\n" >> OUTPUT_FILE_CONNECTIONS
2734       fi
2735    done
2736
2737
2738       # IF REQUIRED, START WITH COMPILING
2739    if [[ $do_compile = true ]]
2740    then
2741
2742
2743       if [[ -f a.out ]]
2744       then
2745
2746             # EXECUTABLE WAS CREATED DURING INTERACTIVE CALL OF MRUN
2747          printf "\n\n\n  *** executable a.out found"
2748          printf "\n      no compilation required \n"
2749
2750       else
2751
2752             # COMPILING WITH MAKE (ON NEC COMPILER IS CALLED ON HOST CROSS)
2753          printf "\n\n\n  *** compilation starts \n$dashes\n"
2754          printf "  *** compilation with make using following options:\n"
2755          printf "      make depository:          $make_depository"
2756          if [[ "$mopts" != "" ]]
2757          then
2758             printf "      make options:             $mopts\n"
2759          fi
2760          printf "      compilername:             $compiler_name\n"
2761          printf "      compiler options:         $fopts\n"
2762          printf "      preprocessor directives:  $cpp_options \n"
2763          printf "      linker options:           $lopts \n"
2764          if [[ "$modules" != "" ]]
2765          then
2766             printf "      modules to be load:       $modules \n"
2767          fi
2768          printf "      source code files:        $source_list \n"
2769
2770          if [[ $localhost = nech ]]
2771          then
2772             ssh  $SSH_PORTOPT  136.172.44.192 -l $usern "$init_cmds $module_calls cd \$HOME/work/${usern}.$kennung; sxmake $mopts -f Makefile PROG=a.out  F90=$compiler_name  COPT=\"$cpp_options\"  F90FLAGS=\"$fopts\"  LDFLAGS=\"$lopts\" "
2773             cp  $TEMPDIR_COMPILE/a.out  .
2774             [[ $? != 0 ]]  &&  compile_error=true
2775             rm -rf  $TEMPDIR_COMPILE
2776          elif [[ $localhost = ibmh ]]
2777          then
2778             printf "      compiler is called via ssh on \"plogin1\" \n"
2779             ssh  $SSH_PORTOPT  plogin1  -l $usern  "$init_cmds export PATH=/sw/ibm/xlf/13.1.0.8/usr/bin:$PATH; $module_calls cd $TEMPDIR; make $mopts -f Makefile PROG=a.out  F90=$compiler_name  COPT=\"$cpp_options\"  F90FLAGS=\"$fopts\"  LDFLAGS=\"$lopts\" "
2780             [[ ! -f a.out ]]  &&  compile_error=true
2781             continue   # STATUS=1, IF a.out EXISTS
2782          elif [[ $localhost = lcflow ]]
2783          then
2784             printf "      compiler is called via ssh on \"flow\" \n"
2785             /usr/bin/ssh  $SSH_PORTOPT  flow02.hpc.uni-oldenburg.de -l $usern "$init_cmds $module_calls cd $TEMPDIR; make $mopts -f Makefile PROG=a.out F90=$compiler_name COPT=\"$cpp_options\" F90FLAGS=\"$fopts\" LDFLAGS=\"$lopts\" "
2786             check_for_file=`/usr/bin/ssh $SSH_PORTOPT flow02.hpc.uni-oldenburg.de -l $usern "ls $TEMPDIR/a.out 2> /dev/null"`
2787             [[ "$check_for_file" = "" ]]  &&  compile_error=true
2788             continue   # STATUS=1, IF a.out EXISTS
2789          elif [[ $localhost = lccrayb  ||  $localhost = lccrayf ||  $localhost = lccrayh ]]
2790          then
2791             make $mopts -f Makefile PROG=a.out  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$fopts"  LDFLAGS="$lopts"
2792          else
2793             [[ "$init_cmds" != "" ]]  &&  eval $init_cmds
2794             [[ "$module_calls" != "" ]]  &&  eval $module_calls
2795             make $mopts -f Makefile PROG=a.out  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$fopts"  LDFLAGS="$lopts"
2796          fi
2797
2798          if [[ $? != 0  ||  "$compile_error" = true  ||  "$module_compile_error" = true ]]
2799          then
2800             printf "\n  +++ error occured while compiling or linking"
2801             locat=compile
2802
2803             exit
2804          else
2805             printf "$dashes\n  *** compilation finished \n"
2806          fi
2807
2808       fi
2809
2810    fi
2811
2812
2813       # PROVIDE THE INPUT FILES
2814       # LOOP OVER ALL ACTIVATED FILES (LISTED IN THE CONFIGURATION FILE)
2815    (( i = 0 ))
2816    while (( i < iin ))
2817    do
2818       (( i = i + 1 ))
2819       if (( i == 1 ))
2820       then
2821          printf "\n\n  *** providing INPUT-files:\n$dashes"
2822       fi
2823
2824
2825          # SKIP OPTIONAL FILES, IF THEY DO NOT EXIST
2826       if [[ "${transin[$i]}" = unavailable ]]
2827       then
2828          if [[ "${extin[$i]}" = ""  ||  "${extin[$i]}" = " " ]]
2829          then
2830             printf "\n  +++ WARNING: input file \"${pathin[$i]}/${afname}${endin[$i]}\" "
2831             printf "\n               is not available!"
2832          else
2833             printf "\n  +++ WARNING: input file \"${pathin[$i]}/${afname}${endin[$i]}.${extin[$i]}\" "
2834             printf "\n               is not available!"
2835          fi
2836          continue
2837       fi
2838
2839          # CHECK FOR SINGLE FILE (SERIAL RUN) OR DIRECTORY (ONE FILE PER CORE FOR PARELLEL EXECUTION)
2840       files_for_pes=false; datentyp=file
2841       if [[ "${actionin[$i]}" = pe  &&  -n $numprocs ]]
2842       then
2843          files_for_pes=true; datentyp=directory
2844          actionin[$i]=""
2845       elif [[ "${actionin[$i]}" = pe  &&  ! -n $numprocs ]]
2846       then
2847          actionin[$i]=""
2848       elif [[ "${actionin[$i]}" = arpe  &&  -n $numprocs ]]
2849       then
2850          files_for_pes=true; datentyp=directory
2851          actionin[$i]="ar"
2852       elif [[ "${actionin[$i]}" = arpe  &&  ! -n $numprocs ]]
2853       then
2854          actionin[$i]="ar"
2855       elif [[ "${actionin[$i]}" = flpe  &&  -n $numprocs ]]
2856       then
2857          files_for_pes=true; datentyp=directory
2858          actionin[$i]="fl"
2859       elif [[ "${actionin[$i]}" = flpe  &&  ! -n $numprocs ]]
2860       then
2861          actionin[$i]="fl"
2862       fi
2863
2864       if [[ $files_for_pes = true ]]
2865       then
2866          printf "\n  >>> INPUT: ${absnamein[$i]}/....  to  ${localin[$i]}"
2867       else
2868          printf "\n  >>> INPUT: ${absnamein[$i]}  to  ${localin[$i]}"
2869       fi
2870
2871          # INPUT-FILE FOR A RESTART RUN.
2872          # CHECK, IF THIS FILE STILL EXISTS ON THE TEMPORARY DATA DIRECTORY.
2873          # IF NOT, TRY TO GET IT FROM THE ARCHIVE SYSTEM
2874       if [[ "${actionin[$i]}" = fl ]]
2875       then
2876          printf "\n      $datentyp will be fetched from temporary directory \"${tmp_data_catalog}\" !"
2877          if [[ $files_for_pes = false ]]
2878          then
2879             if [[ -f "$tmp_data_catalog/${frelin[$i]}" ]]
2880             then
2881                ln  $tmp_data_catalog/${frelin[$i]}  ${localin[$i]}
2882                got_tmp[$i]=true
2883             elif [[ -f "$WORK/${frelin[$i]}"  &&  $ignore_archive_error = true ]]
2884             then
2885                printf "\n  +++ $datentyp not found in \"$tmp_data_catalog\" !"
2886                printf "\n  *** trying to use backup copy in \"$WORK\" "
2887                cp  $WORK/${frelin[$i]}  ${localin[$i]}
2888             else
2889                printf "\n  +++ $datentyp not found in \"$tmp_data_catalog\" "
2890                printf "\n      or \"$tmp_data_catalog\" does not exist!"
2891                printf "\n  *** trying to get copy from archive"
2892                actionin[$i]=ar
2893             fi
2894          else
2895             if [[ -d "$tmp_data_catalog/${frelin[$i]}" ]]
2896             then
2897                mkdir  ${localin[$i]}
2898                cd $tmp_data_catalog/${frelin[$i]}
2899                for file in $(ls *)
2900                do
2901                   ln $file $TEMPDIR/${localin[$i]}
2902                done
2903                cd $TEMPDIR
2904                got_tmp[$i]=true
2905             elif [[ -d "$WORK/${frelin[$i]}"  &&  $ignore_archive_error = true ]]
2906             then
2907                printf "\n  +++ $datentyp not found in \"$tmp_data_catalog\" !"
2908                printf "\n  *** trying to use backup copy in \"$WORK\" "
2909                cp -r  $WORK/${frelin[$i]}  ${localin[$i]}
2910             else
2911                printf "\n  +++ $datentyp not found in \"$tmp_data_catalog\" "
2912                printf "\n      or \"$tmp_data_catalog\" does not exist!"
2913                printf "\n  *** trying to get copy from archive"
2914                actionin[$i]=ar
2915             fi
2916          fi
2917       fi
2918
2919
2920          # FILE IS STORED ON THE ARCHIVE SYSTEM
2921       if [[ "${actionin[$i]}" = ar ]]
2922       then
2923
2924          if [[ $files_for_pes = false ]]
2925          then
2926             printf "\n      file will be restored from archive-system ($archive_system)!"
2927          else
2928             printf "\n      directory will be restored from archive-system ($archive_system)!"
2929          fi
2930
2931          file_restored=false
2932
2933          if [[ $archive_system = asterix ]]
2934          then
2935             do_stagein=true
2936             (( stagein_anz = 0 ))
2937             while [[ $do_stagein = true ]]
2938             do
2939                if [[ $files_for_pes = false ]]
2940                then
2941                   stagein  -O  ${frelin[$i]}  >  STAGEIN_OUTPUT
2942                else
2943                   stagein  -t  -O  ${frelin[$i]}  >  STAGEIN_OUTPUT
2944                fi
2945                cat  STAGEIN_OUTPUT
2946                if [[ $(grep -c "st.msg:i24"  STAGEIN_OUTPUT) != 0 ]]
2947                then
2948                   file_restored=true
2949                   do_stagein=false
2950                else
2951                   (( stagein_anz = stagein_anz + 1 ))
2952                   if (( stagein_anz == 10 ))
2953                   then
2954                      printf "\n  +++ stagein stoped after 10 tries"
2955                      locat=stage
2956                      exit
2957                   fi
2958                   printf "\n  +++ restoring from archive failed, trying again:"
2959                   sleep 900
2960                fi
2961             done
2962          elif [[ $archive_system = DMF ]]
2963          then
2964             if [[ $files_for_pes = false ]]
2965             then
2966                printf "\n  +++ restoring of single files impossible with $archive_system !\n"
2967                locat=DMF
2968                exit
2969             else
2970                find  $ARCHIVE/${frelin[$i]}  -type m  -print  |  dmget
2971                cp  -r $ARCHIVE/${frelin[$i]}  $PWD
2972                file_restored=true
2973             fi
2974          elif [[ $archive_system = tivoli ]]
2975          then
2976             if [[ $files_for_pes = false ]]
2977             then
2978                ssh  $SSH_PORTOPT  $usern@bicedata.hlrn.de  "cp  $PERM/${frelin[$i]}  $PWD"
2979             else
2980                (( inode = 0 ))
2981                while (( inode < nodes ))
2982                do
2983                   ssh  $SSH_PORTOPT  $usern@bicedata.hlrn.de  "cd $PWD; tar  xf  $PERM/${frelin[$i]}/${frelin[$i]}.node_$inode.tar"
2984                   (( inode = inode + 1 ))
2985                done
2986             fi
2987             file_restored=true
2988          elif [[ $archive_system = ut ]]
2989          then
2990             if [[ $files_for_pes = false ]]
2991             then
2992                cp  $UT/${frelin[$i]}  .
2993             else
2994                (( inode = 0 ))
2995                while (( inode < nodes ))
2996                do
2997                   tar  xf  $UT/${frelin[$i]}/${frelin[$i]}.node_$inode.tar
2998                   (( inode = inode + 1 ))
2999                done
3000             fi
3001             file_restored=true
3002          else
3003             printf "\n  +++ archive_system=\"$archive_system\"   restore impossible!"
3004             locat=rearchive
3005             exit
3006          fi
3007
3008          if [[ $file_restored = true ]]
3009          then
3010
3011                # PUT FILE ON THE TEMPORARY DATA DIRECTORY TOO.
3012                # THIS WILL MAKE FILE ACCESS EASIER FOR LATER RUNS
3013             [[ ! -d $tmp_data_catalog ]]  &&  mkdir -p  $tmp_data_catalog; chmod  g+rx  $tmp_data_catalog
3014             if [[ $files_for_pes = false ]]
3015             then
3016                ln  -f  ${frelin[$i]}  $tmp_data_catalog/${frelin[$i]}
3017             else
3018                mkdir  $tmp_data_catalog/${frelin[$i]}
3019                ln  -f  ${frelin[$i]}/*  $tmp_data_catalog/${frelin[$i]}
3020             fi
3021             got_tmp[$i]=true
3022
3023                # PROVIDE THE FILE UNDER ITS LOCAL NAME
3024             mv  ${frelin[$i]}  ${localin[$i]}
3025
3026          fi
3027       fi
3028
3029
3030          # FILE IS STORED IN THE RESPECTIVE DIRECTORY GIVEN IN THE CONFIGURATION FILE
3031       if [[ "${actionin[$i]}" = ""  ||  "${actionin[$i]}" = "di"  ||  "${actionin[$i]}" = "npe" ]]
3032       then
3033
3034          if [[ "${actionin[$i]}" = "npe"  &&  -n $numprocs ]]
3035          then
3036
3037                # FILE COPIES ARE PROVIDED FOR ALL CORES
3038                # EACH FILE GETS A UNIQUE FILENAME WITH A FOUR DIGIT NUMBER
3039             printf "\n      file will be provided for $numprocs processors"
3040             mkdir  ${localin[$i]}
3041             ival=$numprocs
3042             (( ii = 0 ))
3043             while (( ii <= ival-1 ))
3044             do
3045                if (( ii < 10 ))
3046                then
3047                   cp  ${absnamein[$i]}  ${localin[$i]}/_000$ii
3048                elif (( ii < 100 ))
3049                then
3050                   cp  ${absnamein[$i]}  ${localin[$i]}/_00$ii
3051                elif (( ii < 1000 ))
3052                then
3053                   cp  ${absnamein[$i]}  ${localin[$i]}/_0$ii
3054                else
3055                   cp  ${absnamein[$i]}  ${localin[$i]}/_$ii
3056                fi
3057                (( ii = ii + 1 ))
3058             done
3059
3060          else
3061
3062             if [[ $files_for_pes = true ]]
3063             then
3064
3065                   # PROVIDE FILES FOR EACH CORE
3066                   # FIRST CREATE THE LOCAL DIRECTORY, THEN COPY FILES
3067                   # FROM THE PERMANENT DIRECTORY BY LINKING THEM TO THE LOCAL ONE
3068                printf "\n      providing $numprocs files for the respective processors"
3069                mkdir  ${localin[$i]}
3070                if [[ $link_local_input = true ]]
3071                    then
3072                    printf "      using ln -f\n"
3073                    cd ${absnamein[$i]}
3074                    for file in $(ls *)
3075                      do
3076                      ln -f $file  ${localin[$i]}
3077                    done
3078                    cd $TEMPDIR
3079                fi
3080
3081                   # IF "ln -f" FAILED OR IF "$link_local_input = false" DO A NORMAL "cp -r"
3082                if [[ ! -f "${localin[$i]}/_0000" ]]
3083                    then
3084                    if [[ $link_local_input = true ]]
3085                        then
3086                        printf "      ln failed for .../_0000, using cp...\n"
3087                    fi
3088                    cp -r  ${absnamein[$i]}/*  ${localin[$i]}
3089                fi
3090
3091             else
3092
3093                   # PROVIDE FILE FOR RUNS ON A SINGLE CORE
3094                if [[ $link_local_input = true ]]
3095                then
3096                    printf "      using ln -f\n"
3097                    ln -f  ${absnamein[$i]}  ${localin[$i]}
3098                fi
3099                # If "ln -f" fails of if "$link_local_input = false" do a normal "cp"
3100                if [[ ! -f "${localin[$i]}" ]]
3101                then
3102                    if [[ $link_local_input = true ]]
3103                    then
3104                        printf "      ln failed, using cp...\n"
3105                    fi
3106                    cp  ${absnamein[$i]}  ${localin[$i]}
3107                fi
3108             fi
3109          fi
3110       fi
3111
3112    done
3113    if (( i != 0 ))
3114    then
3115       printf "\n$dashes\n  *** all INPUT-files provided \n"
3116    fi
3117
3118
3119       # EXECUTE INPUT-COMMANDS GIVEN IN THE CONFIGURATION FILE
3120    (( i = 0 ))
3121    while (( i < iic ))
3122    do
3123       (( i = i + 1 ))
3124       if (( i == 1 ))
3125       then
3126          printf "\n\n  *** execution of INPUT-commands:\n$dashes"
3127       fi
3128       printf "\n  >>> ${in_command[$i]}"
3129       eval  ${in_command[$i]}
3130       if (( i == iic ))
3131       then
3132          printf "\n$dashes\n"
3133       fi
3134    done
3135
3136
3137       # SET THE REMAINING CPU-TIME
3138    cpurest=${cpumax}.
3139
3140
3141       # START DVR STREAMING SERVER
3142    if [[ $(echo $package_list | grep -c dvrp_graphics) != 0 ]]
3143    then
3144       if [[ "$dvr_server" != "" ]]
3145       then
3146
3147          printf "\n\n  *** preparing the dvr streaming server configuration file"
3148
3149             # CHECK, IF A DVR SERVER IS ALREADY RUNNING
3150          running_dvrserver_id=`echo $(ps -edaf | grep .dvrserver.config | grep -v grep) | cut -d" " -f2`
3151          if [[ "$running_dvrserver_id" != "" ]]
3152          then
3153
3154             printf "\n\n  +++ WARNING: A dvr server with id=$running_dvrserver_id is already running!"
3155             printf "\n      This server is used instead starting a new one!"
3156             printf "\n      If required, script \"process_dvr_output\" has to be run manually."
3157
3158          else
3159
3160                # COPY CONFIGURATION FILE FOR STREAMING SERVER FROM REPOSITORY TO HERE
3161             if [[ -f ${PALM_BIN}/.dvrserver.config ]]
3162             then
3163                cp  ${PALM_BIN}/.dvrserver.config  .
3164
3165                   # ENTERING THE BASEDIR, UID AND GID INTO THIS FILE
3166                user_id=`id -u`
3167                group_id=`id -g`
3168
3169                   # "&" IS REQUIRED AS A SEPERATOR, BECAUSE TEMPDIR CONTAINS "/"
3170                sed "s&<replace by dvr data directory>&${TEMPDIR}&g" .dvrserver.config > .dvrserver.1
3171                sed "s/<replace by user id>/$user_id/g"    .dvrserver.1 > .dvrserver.2
3172                sed "s/<replace by group id>/$group_id/g"  .dvrserver.2 > .dvrserver.3
3173                mv  .dvrserver.3  .dvrserver.config
3174                rm  .dvrserver.1  .dvrserver.2
3175
3176                   # START DVR SERVER IN BACKGROUND, GET HIS ID AND PRINT ON TERMINAL
3177                $dvr_server  .dvrserver.config  >>  DVR_LOGFILE  2>&1  &
3178                dvrserver_id=`echo $(ps -edaf | grep .dvrserver.config) | cut -d" " -f2`
3179                printf "\n  *** streaming server with id=$dvrserver_id is started in background"
3180                local_dvrserver_running=.TRUE.
3181             else
3182                printf "\n  +++ missing file \".dvrserver.config\" in directory:"
3183                printf "\n      \"$PALM_BIN\" "
3184                locat=dvr
3185                exit
3186             fi
3187
3188          fi
3189
3190       else
3191          printf "\n\n  --- INFORMATIVE: no dvr streaming server will be started"
3192       fi
3193    fi
3194
3195
3196       # CREATE THE NAMELIST-FILE WITH VALUES OF ENVIRONMENT-VARIABLES REQUIRED BY PALM
3197       # (FILE ENVPAR WILL BE READ BY PALM)
3198    cat  >  ENVPAR  <<  %%END%%
3199 &envpar  run_identifier = '$fname', host = '$localhost',
3200          write_binary = '$write_binary', tasks_per_node = $tasks_per_node,
3201          maximum_parallel_io_streams = $maximum_parallel_io_streams,
3202          maximum_cpu_time_allowed = ${cpumax}.,
3203          revision = '$global_revision',
3204          local_dvrserver_running = $local_dvrserver_running,
3205          batch_job = $batch_job /
3206
3207%%END%%
3208
3209
3210       # STARTING THE EXECUTABLE
3211    printf "\n\n  *** execution starts in directory\n      \"`pwd`\"\n$dashes\n"
3212    PATH=$PATH:$TEMPDIR
3213
3214       # MPI DEBUG OPTION (ARGUMENT CHECKING, SLOWS DOWN EXECUTION DUE TO INCREASED LATENCY)
3215    if [[ "$mpi_debug" = true ]]
3216    then
3217       export MPI_CHECK_ARGS=1
3218       printf "\n  +++ MPI_CHECK_ARGS=$MPI_CHECK_ARGS"
3219    fi
3220
3221    if [[ "$totalview" = true ]]
3222    then
3223       printf "\n *** totalview debugger will be used"
3224       tv_opt="-tv"
3225    else
3226       tv_opt=""
3227    fi
3228
3229    if [[ "$cond1" = debug  ||  "$cond2" = debug ]]
3230    then
3231       if [[ "$ENVIRONMENT" = BATCH ]]
3232       then
3233          continue
3234       fi
3235       if [[ $localhost = ibmh ]]
3236       then
3237
3238             # SETUP THE IBM MPI ENVIRONMENT
3239          export MP_SHARED_MEMORY=yes
3240          export AIXTHREADS_SCOPE=S
3241          export OMP_NUM_THREADS=$threads_per_task
3242          export AUTHSTATE=files
3243          export XLFRTEOPTS="nlwidth=132:err_recovery=no"    # RECORD-LENGTH OF NAMELIST-OUTPUT
3244
3245             # FOLLOWING OPTIONS ARE MANDATORY FOR TOTALVIEW
3246          export MP_ADAPTER_USE=shared
3247          export MP_CPU_USE=multiple
3248          export MP_TIMEOUT=1200
3249
3250          unset  MP_TASK_AFFINITY
3251
3252             # SO FAR, TOTALVIEW NEEDS HOSTFILE MECHANISM FOR EXECUTION
3253          #(( ii = 1 ))
3254          #while (( ii <= $numprocs ))
3255          #do
3256          #   echo  $localhost_realname  >>  hostfile
3257          #   (( ii = ii + 1 ))
3258          #done
3259          #export MP_HOSTFILE=hostfile
3260
3261          if [[ "$LOADLBATCH" = yes ]]
3262          then
3263             totalview   poe  a.out  $ROPTS
3264          else
3265             echo totalview   poe  -a a.out  -procs $numprocs  -rmpool 0  -nodes 1   $ROPTS
3266             export TVDSVRLAUNCHCMD=ssh
3267             totalview   poe  -a a.out  -procs $numprocs  -rmpool 0  -nodes 1   $ROPTS
3268          fi
3269
3270       fi  # END DEBUG MODE
3271
3272    else
3273
3274          # NORMAL EXECUTION
3275       if [[ -n $numprocs ]]
3276       then
3277
3278             # RUNNING THE PROGRAM ON PARALLEL MACHINES
3279          if [[ $(echo $host | cut -c1-3) = ibm ]]
3280          then
3281
3282                # SETUP THE IBM MPI ENVIRONMENT
3283             if [[ $host != ibmh  &&  $host != ibmkisti ]]
3284             then
3285                export MP_SHARED_MEMORY=yes
3286                export AIXTHREAD_SCOPE=S
3287                export OMP_NUM_THREADS=$threads_per_task
3288                export XLSMPOPTS="spins=0:yields=0:stack=20000000"
3289                export AUTHSTATE=files
3290                export XLFRTEOPTS="nlwidth=132:err_recovery=no"    # RECORD-LENGTH OF NAMELIST-OUTPUT
3291                #  export MP_PRINTENV=yes
3292
3293                   # TUNING-VARIABLES TO IMPROVE COMMUNICATION SPEED
3294                   # DO NOT SHOW SIGNIFICANT EFFECTS (SEP 04, FEDERATION-SWITCH)
3295                export MP_WAIT_MODE=poll
3296                [[ $node_usage = not_shared ]]  &&  export MP_SINGLE_THREAD=yes
3297             fi
3298
3299             if [[ $host = ibmkisti ]]
3300             then
3301                export LANG=en_US
3302                export MP_SHARED_MEMORY=yes
3303                if [[ $threads_per_task = 1 ]]
3304                then
3305                   export MP_SINGLE_THREAD=yes
3306                   export MEMORY_AFFINITY=MCM
3307                else
3308                   export OMP_NUM_THREADS=$threads_per_task
3309                fi
3310             fi
3311
3312             if [[ "$LOADLBATCH" = yes ]]
3313             then
3314                printf "\n--- Control: OMP_NUM_THREADS = \"$OMP_NUM_THREADS\" \n"
3315                if [[ "$cond1" = hpmcount  ||  "$cond2" = hpmcount ]]
3316                then
3317                   /opt/optibm/HPM_2_4_1/bin/hpmcount  a.out  $ROPTS
3318                else
3319                   if [[ $run_coupled_model = false ]]
3320                   then
3321                      if [[ "$ocean_file_appendix" = true ]]
3322                      then
3323                         echo "precursor_ocean"  >  runfile_atmos
3324                      else
3325                         echo "precursor_atmos"  >  runfile_atmos
3326                      fi
3327                   else
3328                      (( iia = $numprocs_atmos / $threads_per_task ))
3329                      (( iio = $numprocs_ocean / $threads_per_task ))
3330                      printf "\n      coupled run ($iia atmosphere, $iio ocean)"
3331                      printf "\n      using $coupled_mode coupling"
3332                      printf "\n\n"
3333                      echo "coupled_run $iia $iio"  >  runfile_atmos
3334                   fi
3335                   poe ./a.out  $ROPTS  <  runfile_atmos
3336                fi
3337             else
3338                if [[ $localhost = ibmh  ||  $localhost = ibms ]]
3339                then
3340                   poe  a.out  -procs $numprocs  -nodes 1  -rmpool 0  $ROPTS
3341                elif [[ $localhost = ibmkisti  ||  $localhost = ibmku ]]
3342                then
3343                   if [[ -f $hostfile ]]
3344                   then
3345                      cp  $hostfile  hostfile
3346                   else
3347                      (( ii = 1 ))
3348                      while (( ii <= $numprocs ))
3349                      do
3350                         echo  $localhost_realname  >>  hostfile
3351                         (( ii = ii + 1 ))
3352                      done
3353                   fi
3354                   export MP_HOSTFILE=hostfile
3355                   if [[ $run_coupled_model = false ]]
3356                   then
3357                      if [[ "$ocean_file_appendix" = true ]]
3358                      then
3359                         echo "precursor_ocean"  >  runfile_atmos
3360                      else
3361                         echo "precursor_atmos"  >  runfile_atmos
3362                      fi
3363                   else
3364                      (( iia = $numprocs_atmos / $threads_per_task ))
3365                      (( iio = $numprocs_ocean / $threads_per_task ))
3366                      printf "\n      coupled run ($iia atmosphere, $iio ocean)"
3367                      printf "\n      using $coupled_mode coupling"
3368                      printf "\n\n"
3369                      echo "coupled_run $iia $iio"  >  runfile_atmos
3370                   fi
3371
3372                   poe  ./a.out  -procs $numprocs $ROPTS  <  runfile_atmos
3373
3374                else
3375                   if [[ "$host_file" = "" ]]
3376                   then
3377                      printf "\n  +++ no hostfile given in configuration file"
3378                      locat=config_file
3379                      exit
3380                   else
3381                      eval host_file=$host_file
3382                   fi
3383                   export MP_HOSTFILE=$host_file
3384                   poe  a.out  -procs $numprocs  -tasks_per_node $numprocs  $ROPTS
3385                fi
3386             fi
3387          elif [[ $host = nech ]]
3388          then
3389             (( ii = nodes ))
3390             if [[ $ii = 1 ]]
3391             then
3392                export F_ERRCNT=0        # acceptable number of errors before program is stopped
3393                export MPIPROGINF=YES
3394                #  export F_TRACE=YES|FMT1|FMT2  # output of ftrace informations to job protocol
3395                echo "*** execution on single node with mpirun"
3396                mpirun  -np $numprocs  ./a.out  $ROPTS
3397             else
3398                (( i = 0 ))
3399                while (( i < ii ))
3400                do
3401                   echo "-h $i  -p $tasks_per_node  -e ./mpi_exec_shell"  >>  multinode_config
3402                   (( i = i + 1 ))
3403                done
3404
3405                echo "#!/bin/sh"                         >   mpi_exec_shell
3406                echo " "                                 >>  mpi_exec_shell
3407                echo "set -u"                            >>  mpi_exec_shell
3408                echo "F_ERRCNT=0"                        >>  mpi_exec_shell
3409                echo "MPIPROGINV=YES"                    >>  mpi_exec_shell
3410                echo "OMP_NUM_THREADS=$threads_per_task" >>  mpi_exec_shell
3411                echo "cpurest=$cpurest"                  >>  mpi_exec_shell
3412                echo "fname=$fname"                      >>  mpi_exec_shell
3413                echo "localhost=$localhost"              >>  mpi_exec_shell
3414                echo "return_address=$return_address"    >>  mpi_exec_shell
3415                echo "return_username=$return_username"  >>  mpi_exec_shell
3416                echo "tasks_per_node=$tasks_per_node"    >>  mpi_exec_shell
3417                echo "write_binary=$write_binary"        >>  mpi_exec_shell
3418                echo "use_seperate_pe_for_dvrp_output=$use_seperate_pe_for_dvrp_output"  >>  mpi_exec_shell
3419                echo "  "                                >>  mpi_exec_shell
3420                echo "export F_ERRCNT"                   >>  mpi_exec_shell
3421                echo "export MPIPROGINV"                 >>  mpi_exec_shell
3422                echo "export OMP_NUM_THREADS"            >>  mpi_exec_shell
3423                echo "export cpurest"                    >>  mpi_exec_shell
3424                echo "export fname"                      >>  mpi_exec_shell
3425                echo "export localhost"                  >>  mpi_exec_shell
3426                echo "export return_address"             >>  mpi_exec_shell
3427                echo "export return_username"            >>  mpi_exec_shell
3428                echo "export tasks_per_node"             >>  mpi_exec_shell
3429                echo "export write_binary"               >>  mpi_exec_shell
3430                echo "export use_seperate_pe_for_dvrp_output"  >>  mpi_exec_shell
3431                echo " "                                 >>  mpi_exec_shell
3432                echo "exec  ./a.out"                     >>  mpi_exec_shell
3433
3434                chmod u+x  mpi_exec_shell
3435                export MPIPROGINF=YES
3436                mpirun  -f multinode_config  &
3437                wait
3438
3439             fi
3440          elif [[ $(echo $host | cut -c1-2) = lc  &&  $host != lckyoto &&  $host != lctit ]]
3441          then
3442
3443                # COPY HOSTFILE FROM SOURCE DIRECTORY OR CREATE IT, IF IT
3444                # DOES NOT EXIST
3445             if [[  $host != lccrayb  &&$host != lccrayf  && $host != lccrayh  &&  $host != lckyuh  &&  $host != lckyut ]]
3446             then
3447                if [[ -f $hostfile ]]
3448                then
3449                   cp  $hostfile  hostfile
3450                   (( ii = $numprocs / $threads_per_task ))
3451                else
3452                   (( ii = 1 ))
3453                   while (( ii <= $numprocs / $threads_per_task ))
3454                   do
3455                      echo  $localhost_realname  >>  hostfile
3456                      (( ii = ii + 1 ))
3457                   done
3458                fi
3459                eval zeile=\"`head -n $ii  hostfile`\"
3460                printf "\n  *** running on: $zeile"
3461             fi
3462
3463             (( ii = $numprocs / $threads_per_task ))
3464             export OMP_NUM_THREADS=$threads_per_task
3465
3466             if [[ $threads_per_task != 1 ]]
3467             then
3468                   # INCREASE STACK SIZE TO UNLIMITED, BECAUSE OTHERWISE LARGE RUNS
3469                   # MAY ABORT
3470                ulimit -s unlimited
3471                printf "\n      threads per task: $threads_per_task  stacksize: unlimited"
3472             fi
3473             if [[ $run_coupled_model = false ]]
3474             then
3475                if [[ "$ocean_file_appendix" = true ]]
3476                then
3477                   echo "precursor_ocean"  >  runfile_atmos
3478                else
3479                   echo "precursor_atmos"  >  runfile_atmos
3480                fi
3481                printf "\n\n"
3482
3483                if [[ $host = lccrayb || $host = lccrayh ]]
3484                then
3485                    echo "--- aprun  -n $ii  -N $tasks_per_node  a.out  $ROPTS  < runfile_atmos"
3486                    aprun  -n $ii  -N $tasks_per_node  a.out  $ROPTS  < runfile_atmos
3487#                    aprun  -n $ii  -ss  -r2  -j1  a.out  $ROPTS  < runfile_atmos
3488                elif [[ $host = lccrayf ]]
3489                then
3490                    aprun  -j1  -n $ii  -N $tasks_per_node  -m ${memory}M  a.out  $ROPTS  < runfile_atmos
3491                elif [[ $host = lcxe6  ||  $host = lcxt5m ]]
3492                then
3493                    aprun  -n $ii  -N $tasks_per_node  a.out  $ROPTS  < runfile_atmos
3494                elif [[ $host = lcflow ]]
3495                then
3496                   mpirun -bootstrap sge -np $ii  -env I_MPI_FABRICS shm:ofa a.out  < runfile_atmos  $ROPTS
3497                elif [[ $host = lcsb ]]
3498                then
3499                   mpirun_rsh -hostfile $PBS_NODEFILE -np `cat $PBS_NODEFILE | wc -l` a.out  < runfile_atmos  $ROPTS
3500                elif [[ $host = lckiaps ]]
3501                then
3502                   mpirun -np $ii  -f $PBS_NODEFILE  a.out  <  runfile_atmos  $ROPTS
3503                elif [[ $host = lckyu* ]]
3504                then
3505                   mpiexec -n $ii --stdin runfile_atmos  ./a.out  $ROPTS
3506                else
3507                   mpiexec  -machinefile hostfile  -n $ii  a.out  <  runfile_atmos  $ROPTS
3508                fi
3509             else
3510
3511                    # CURRENTLY THERE IS NO FULL MPI-2 SUPPORT ON ICE AND XT4
3512                (( iia = $numprocs_atmos / $threads_per_task ))
3513                (( iio = $numprocs_ocean / $threads_per_task ))
3514                printf "\n      coupled run ($iia atmosphere, $iio ocean)"
3515                printf "\n      using $coupled_mode coupling"
3516                printf "\n\n"
3517
3518                if [[ $coupled_mode = "mpi2" ]]
3519                then
3520                   echo "atmosphere_to_ocean $iia $iio"  >  runfile_atmos
3521                   echo "ocean_to_atmosphere $iia $iio"  >  runfile_ocean
3522
3523                   if [[ $host = lccrayf  ||  $host = lcxe6  ||  $host = lcxt5m ]]
3524                   then
3525
3526                      aprun  -n $iia  -N $tasks_per_node  a.out < runfile_atmos  $ROPTS  &
3527                      aprun  -n $iio  -N $tasks_per_node  a.out < runfile_ocean  $ROPTS  &
3528
3529                   else
3530                          # WORKAROUND BECAUSE mpiexec WITH -env option IS NOT AVAILABLE ON SOME SYSTEMS
3531                       mpiexec  -machinefile hostfile  -n $iia  a.out  $ROPTS  <  runfile_atmos &
3532                       mpiexec  -machinefile hostfile  -n $iio  a.out  $ROPTS  <  runfile_ocean &
3533#                       mpiexec  -machinefile hostfile  -n $iia  -env coupling_mode atmosphere_to_ocean  a.out  $ROPTS  &
3534#                       mpiexec  -machinefile hostfile  -n $iio  -env coupling_mode ocean_to_atmosphere  a.out  $ROPTS  &
3535                   fi
3536                   wait
3537
3538                else
3539
3540                   echo "coupled_run $iia $iio"  >  runfile_atmos
3541
3542                   if [[ $host = lccrayf  ||  $host = lcxe6  ||  $host = lcxt5m ]]
3543                   then
3544
3545                      aprun  -n $ii  -N $tasks_per_node  a.out < runfile_atmos  $ROPTS
3546
3547                   elif [[ $host = lck || $host = lckordi ]]
3548                   then
3549
3550                      mpiexec -n $ii  ./a.out  $ROPTS < runfile_atmos &
3551
3552                   elif [[ $host = lckyu* ]]
3553                   then
3554
3555                      mpiexec -n $ii --stdin runfile_atmos  ./a.out  $ROPTS
3556
3557                   fi
3558                   wait
3559                fi
3560
3561             fi
3562
3563          elif [[ $host = lckyoto ]]
3564          then
3565             set -xv
3566             export P4_RSHCOMMAND=plesh
3567             echo "     P4_RSHCOMMAND = $P4_RSHCOMMAND"
3568             if [[ "$ENVIRONMENT" = BATCH ]]
3569             then
3570                if [[ "$cond2" = fujitsu ]]
3571                then
3572                   mpiexec  -n $numprocs  ./a.out  $ROPTS  # for fujitsu-compiler
3573                elif [[ "cond2" = pgi ]]
3574                then
3575                   mpirun  -np $numprocs  -machinefile ${QSUB_NODEINF}  ./a.out  $ROPTS
3576                else
3577                   mpirun_rsh -np $numprocs -hostfile ${QSUB_NODEINF} MV2_USE_SRQ=0 ./a.out ${ROPTS} || /bin/true
3578                fi
3579             else
3580                if [[ "$cond2" = "" ]]
3581                then
3582                   mpiruni_rsh -np $numprocs ./a.out  $ROPTS  # for intel
3583                else
3584                   mpirun  -np $numprocs  ./a.out  $ROPTS
3585                fi
3586             fi
3587             set +xv
3588
3589          elif [[ $host = lctit ]]
3590          then
3591             export OMP_NUM_THREADS=$threads_per_task
3592             echo "OMP_NUM_THREADS=$OMP_NUM_THREADS"
3593             if [[ "$threads_per_task" != 1 ]]
3594             then
3595                export MV2_ENABLE_AFFINITY=0
3596             fi
3597             echo "----- PBS_NODEFILE content:"
3598             cat $PBS_NODEFILE
3599             echo "-----"
3600             (( ii = $numprocs / $threads_per_task ))
3601             echo "mpirun  -np $ii  -hostfile $PBS_NODEFILE ./a.out  $ROPTS"
3602             mpirun  -np $ii  -hostfile $PBS_NODEFILE ./a.out  $ROPTS
3603          else
3604             mpprun  -n $numprocs  a.out  $ROPTS
3605          fi
3606       else
3607          a.out  $ROPTS
3608       fi
3609    fi
3610
3611    if [[ $? != 0 ]]
3612    then
3613
3614          # ABORT IN CASE OF RUNTIME ERRORS
3615       printf "\n  +++ runtime error occured"
3616       locat=execution
3617       exit
3618
3619    else
3620
3621       printf "\n$dashes\n  *** execution finished \n"
3622
3623          # STOP THE DVR STREAMING SERVER AND PROCESS THE DVR OUTPUT IN ORDER
3624          # TO CREAT DVRS- AND HTML-FILES CONTAINING ALL STREAMS
3625       if [[ "$dvrserver_id" != "" ]]
3626       then
3627          kill $dvrserver_id
3628          printf "\n  *** dvr server with id=$dvrserver_id has been stopped"
3629
3630             # IF THERE IS A DIRECTORY, DATA HAVE BEEN OUTPUT BY THE
3631             # STREAMING SERVER. OTHERWISE, USER HAS CHOSEN dvrp_output=local
3632          if [[ -d DATA_DVR ]]
3633          then
3634
3635                # ADD THE CURRENT DVR CONFIGURATION FILE TO THE DVR OUTPUT
3636                # DIRECTORY
3637             cp  .dvrserver.config  DATA_DVR
3638
3639                # PROCESS THE DVR OUTPUT (OPTION -s FOR GENERATING
3640                # SEQUENCE MODE DATA TOO)
3641             process_dvr_output  -d DATA_DVR  -f $fname  -s
3642
3643          else
3644
3645                # PROCESS THE LOCAL OUTPUT
3646             process_dvr_output  -l  -d DATA_DVR  -f $fname
3647
3648          fi
3649
3650       elif [[ $(echo $package_list | grep -c dvrp_graphics) != 0 ]]
3651       then
3652
3653             # PROCESS DVR OUTPUT GENERATD IN LOCAL MODE (dvrp_output=local)
3654          process_dvr_output  -l  -d DATA_DVR  -f $fname
3655
3656       fi
3657    fi
3658
3659
3660
3661       # CALL OF combine_plot_fields IN ORDER TO MERGE SINGLE FILES WRITTEN
3662       # BY EACH CORE INTO ONE FILE
3663   if [[ ! -f ${PALM_BIN}/combine_plot_fields${block}.x ]]
3664   then
3665      printf "\n\n\n  +++ WARNING: no combine_plot_fields found for given block \"$cond1 $cond2\""
3666      printf "\n      2d- and/or 3d-data may be incomplete!"
3667      printf "\n      Run \"mbuild -u -h $localhost\" to generate utilities for this block.\n"
3668   elif [[ "$combine_plot_fields" == true ]]
3669   then
3670      if [[ $localhost = lccrayh  ||  $localhost = lccrayb ]]
3671      then
3672         printf "\n\n\n *** post-processing: now executing \"aprun  -n 1  -N 1 combine_plot_fields${block}.x\" ..."
3673         aprun  -n 1  -N 1 combine_plot_fields${block}.x #$ROPTS < runfile_atmos
3674      else
3675         printf "\n\n\n *** post-processing: now executing \"combine_plot_fields${block}.x\" ..."
3676         combine_plot_fields${block}.x
3677      fi
3678   else
3679
3680         # TEMPORARY SOLUTION TO SKIP combine_plot_fields. THIS IS REQUIRED IN CASE OF HUGE AMOUNT OF
3681         # DATA OUTPUT. TO DO: EXTEND THIS BRANCH BY CREATING A BATCH JOB for combine_plot_fields.
3682         # ??? koennen wir das streichen ???
3683      printf "\n\n\n *** post-processing: skipping combine_plot_fields (-Z option set) ..."
3684   fi
3685
3686
3687
3688       # EXECUTE OUTPUT-COMMANDS GIVEN IN THE CONFIGURATION FILE
3689    (( i = 0 ))
3690    while (( i < ioc ))
3691    do
3692       (( i = i + 1 ))
3693       if (( i == 1 ))
3694       then
3695          printf "\n\n  *** execution of OUTPUT-commands:\n$dashes"
3696       fi
3697       printf "\n  >>> ${out_command[$i]}"
3698       eval  ${out_command[$i]}
3699       if (( i == ioc ))
3700       then
3701          printf "\n$dashes\n"
3702       fi
3703    done
3704
3705
3706       # IN TRACE-MODE PRINT CONTENTS OF THE CURRENT (TEMPORARY) WORKING DIRECTORY
3707    if [[ $do_trace = true ]]
3708    then
3709       printf "\n\n"
3710       ls -al
3711    fi
3712
3713
3714
3715       # COPY LOCAL OUTPUT-FILES TO THEIR PERMANENT DESTINATIONS
3716    (( i = 0 ))
3717    while (( i < iout ))
3718    do
3719       (( i = i + 1 ))
3720       if (( i == 1 ))
3721       then
3722          printf "\n\n  *** saving OUTPUT-files:\n$dashes"
3723       fi
3724
3725          # CHECK FOR SINGLE FILE (SERIAL RUN) OR DIRECTORY (ONE FILE PER CORE FOR PARELLEL EXECUTION)
3726       files_for_pes=false; filetyp=file
3727       if [[ "${actionout[$i]}" = pe  &&  -n $numprocs ]]
3728       then
3729          files_for_pes=true; filetyp=directory
3730          actionout[$i]=""
3731       elif [[ "${actionout[$i]}" = pe  &&  ! -n $numprocs ]]
3732       then
3733          actionout[$i]=""
3734       elif [[ "${actionout[$i]}" = arpe  &&  -n $numprocs ]]
3735       then
3736          files_for_pes=true; filetyp=directory
3737          actionout[$i]="ar"
3738       elif [[ "${actionout[$i]}" = arpe  &&  ! -n $numprocs ]]
3739       then
3740          actionout[$i]="ar"
3741       elif [[ "${actionout[$i]}" = flpe  &&  -n $numprocs ]]
3742       then
3743          files_for_pes=true; filetyp=directory
3744          actionout[$i]="fl"
3745       elif [[ "${actionout[$i]}" = flpe  &&  ! -n $numprocs ]]
3746       then
3747          actionout[$i]="fl"
3748       elif [[ "${actionout[$i]}" = trpe  &&  -n $numprocs ]]
3749       then
3750          files_for_pes=true; filetyp=directory
3751          actionout[$i]="tr"
3752       elif [[ "${actionout[$i]}" = trpe  &&  ! -n $numprocs ]]
3753       then
3754          actionout[$i]="tr"
3755       fi
3756
3757       if [[ ! -f ${localout[$i]}  &&  $files_for_pes = false ]]
3758       then
3759          printf "\n  +++ temporary OUTPUT-file  ${localout[$i]}  does not exist\n"
3760       elif [[ ! -d ${localout[$i]}  &&  $files_for_pes = true ]]
3761       then
3762          printf "\n  +++ temporary OUTPUT-file  ${localout[$i]}/....  does not exist\n"
3763       else
3764
3765
3766             # COPY VIA SCP TO LOCAL HOST (ALWAYS IN BINARY MODE USING batch_scp option -m)
3767             # IF TARGET DIRECTORY DOES NOT EXISTS, TRY TO CREATE IT
3768          if [[ "${actionout[$i]}" = tr ]]
3769          then
3770             if [[ $localhost != $fromhost ]]
3771             then
3772                if [[ $files_for_pes = false ]]
3773                then
3774                   cps=""
3775                   cst=""
3776                else
3777                   cps=-c
3778                   cst="/"
3779                fi
3780                if [[ $localhost = nech ]]
3781                then
3782
3783                      # TRANSFER IN SEPERATE JOB
3784                      # FIRST COPY FILE TO TEMPORY DATA DIRECTORY
3785                   [[ ! -d $tmp_data_catalog/TRANSFER ]]  &&  mkdir -p  $tmp_data_catalog/TRANSFER
3786                   file_to_transfer=${fname}_${localout[$i]}_to_transfer_$kennung
3787                   if [[ $files_for_pes = false ]]
3788                   then
3789                      ln -f  ${localout[$i]}  $tmp_data_catalog/TRANSFER/$file_to_transfer
3790                   else
3791                      mkdir  $tmp_data_catalog/TRANSFER/$file_to_transfer
3792                      ln  ${localout[$i]}/*  $tmp_data_catalog/TRANSFER/$file_to_transfer
3793                   fi
3794
3795                   echo "set -x"                                    >    transfer_${localout[$i]}
3796                   echo "cd  $tmp_data_catalog/TRANSFER"            >>   transfer_${localout[$i]}
3797
3798                   printf "\n  >>> OUTPUT: ${localout[$i]}$cst  by SCP in seperate job to"
3799                   printf "\n              ${pathout[$i]}/${localhost}_${fname}${endout[$i]}$cst"
3800                   printf "\n              or higher cycle\n"
3801                   echo "batch_scp $PORTOPT $cps -b -m -u $return_username $return_address  $file_to_transfer \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"  >>  transfer_${localout[$i]}
3802
3803                   echo "[[ \$? = 0 ]]  &&  rm  $file_to_transfer"  >>  transfer_${localout[$i]}
3804
3805                   if [[ $localhost = nech ]]
3806                   then
3807                      subjob  -d  -c /pf/b/$usern/job_queue  -v  -q pp  -X 0  -m 1000  -t 900  $PORTOPT  transfer_${localout[$i]}
3808                   else
3809                      if [[ "$LOGNAME" = b323013 ]]
3810                      then
3811                         subjob  -v  -q c1  -X 0  -m 1000  -t 900  -c $job_catalog  $PORTOPT  transfer_${localout[$i]}
3812                      else
3813                         subjob  -d  -v  -q c1  -X 0  -m 1000  -t 900  -c $job_catalog  $PORTOPT  transfer_${localout[$i]}
3814                      fi
3815                   fi
3816
3817                else
3818
3819                      # TRANSFER WITHIN THIS JOB
3820                   transfer_failed=false
3821                   printf "\n  >>> OUTPUT: ${localout[$i]}$cst  by SCP to"
3822                   printf "\n              ${pathout[$i]}/${localhost}_${fname}${endout[$i]}$cst\n"
3823                   if [[ $localhost = lccrayb ]]
3824                   then
3825                      ssh $usern@blogin1 ". \\$HOME/.profile; cd $TEMPDIR; batch_scp $PORTOPT $cps -b -m -u $return_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"
3826                   elif [[ $localhost = lccrayh ]]
3827                   then
3828                      ssh $usern@hlogin1 ". \\$HOME/.profile; cd $TEMPDIR; batch_scp $PORTOPT $cps -b -m -u $return_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"
3829                   elif [[ $localhost = lcxe6 ]]
3830                   then
3831                      ssh $usern@hexagon ". \\$HOME/.profile; cd $TEMPDIR; batch_scp $PORTOPT $cps -b -m -u $return_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"
3832                   else
3833                      batch_scp $PORTOPT $cps -b -m -u $return_username $return_address  ${localout[$i]} "${pathout[$i]}" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}
3834                   fi
3835                   [[ $? != 0 ]]  &&  transfer_failed=true
3836
3837                      # IF TRANSFER FAILED, CREATE BACKUP COPY ON THIS MACHINE
3838                   if [[ $transfer_failed = true ]]
3839                   then
3840                      printf "  +++ transfer failed. Trying to save a copy on this host under:\n"
3841                      printf "      ${pathout[$i]}/${localhost}_${fname}${endout[$i]}_$kennung\n"
3842
3843                         # FIRST CHECK, IF DIRECTORY EXISTS, AND CREATE IT, IF NECESSARY
3844                      eval  local_catalog=${pathout[$i]}
3845                      if [[ ! -d $local_catalog ]]
3846                      then
3847                         printf "  *** local directory does not exist. Trying to create:\n"
3848                         printf "      $local_catalog \n"
3849                         mkdir -p  $local_catalog
3850                      fi
3851                      eval  cp  ${localout[$i]}  ${pathout[$i]}/${localhost}_${fname}${endout[$i]}_$kennung
3852                      transfer_problems=true
3853                   fi
3854                fi
3855             else
3856
3857                   # UNSET actionout. DUE TO THIS SETTING, FILE WILL LATER JUST BE COPIED ON THIS MACHINE
3858                actionout[$i]=""
3859             fi
3860          fi
3861
3862
3863             # APPEND VIA SCP TO LOCAL HOST (ALWAYS IN BINARY MODE USING batch_scp option -m)
3864             # IF TARGET DIRECTORY DOES NOT EXISTS, TRY TO CREATE IT
3865          if [[ "${actionout[$i]}" = tra ]]
3866          then
3867             if [[ $localhost != $fromhost ]]
3868             then
3869                if [[ $localhost = ibmh  ||  $localhost = nech ]]
3870                then
3871
3872                      # TRANSFER IN SEPERATE JOB
3873                      # FIRST COPY FILE TO TEMPORY DATA DIRECTORY
3874                   [[ ! -d $tmp_data_catalog/TRANSFER ]]  &&  mkdir -p  $tmp_data_catalog/TRANSFER
3875                   file_to_transfer=${fname}_${localout[$i]}_to_transfer_$kennung
3876                   ln -f  ${localout[$i]}  $tmp_data_catalog/TRANSFER/$file_to_transfer
3877
3878                   echo "set -x"                                    >    transfer_${localout[$i]}
3879                   echo "cd  $tmp_data_catalog/TRANSFER"            >>   transfer_${localout[$i]}
3880
3881                   printf "\n  >>> OUTPUT: ${localout[$i]}  append by SCP in seperate job to"
3882                   printf "\n              ${pathout[$i]}/${localhost}_${fname}${endout[$i]}"
3883                   printf "\n              or higher cycle\n"
3884                   echo "batch_scp $PORTOPT -A -b -m -u $return_username $return_address  $file_to_transfer \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"  >>  transfer_${localout[$i]}
3885
3886                   echo "[[ \$? = 0 ]]  &&  rm  $file_to_transfer"  >>  transfer_${localout[$i]}
3887
3888                   if [[ $localhost = nech ]]
3889                   then
3890                      subjob  -d  -c /pf/b/$usern/job_queue  -v  -q pp  -X 0  -m 1000  -t 900  $PORTOPT  transfer_${localout[$i]}
3891                   else
3892                      if [[ $LOGNAME = b323013 ]]
3893                      then
3894                         subjob  -v  -q c1  -X 0  -m 1000  -t 900  -c $job_catalog  $PORTOPT  transfer_${localout[$i]}
3895                      else
3896                         subjob  -d  -v  -q c1  -X 0  -m 1000  -t 900  -c $job_catalog  $PORTOPT  transfer_${localout[$i]}
3897                      fi
3898                   fi
3899
3900                else
3901
3902                      # TRANSFER WITHIN THIS JOB
3903                   transfer_failed=false
3904                   printf "\n  >>> OUTPUT: ${localout[$i]}  append by SCP to"
3905                   printf "\n              ${pathout[$i]}/${localhost}_${fname}${endout[$i]}\n"
3906                   if [[ $localhost = lccrayb ]]
3907                   then
3908                      ssh $usern@blogin1 ". \\$HOME/.profile; cd $TEMPDIR; batch_scp $PORTOPT -A -b -m -u $return_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"
3909                   elif [[ $localhost = lccrayh ]]
3910                   then
3911                      ssh $usern@hlogin1 ". \\$HOME/.profile; cd $TEMPDIR; batch_scp $PORTOPT -A -b -m -u $return_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"
3912                   elif [[ $localhost = lcxe6 ]]
3913                   then
3914                      ssh $usern@hexagon ". \\$HOME/.profile; cd $TEMPDIR; batch_scp $PORTOPT -A -b -m -u $return_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"
3915                   else
3916                      batch_scp $PORTOPT -A -b -m -u $return_username  $return_address ${localout[$i]} "${pathout[$i]}" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}
3917                   fi
3918                   [[ $? != 0 ]]  &&  transfer_failed=true
3919
3920                      # IF TRANSFER FAILED, CREATE BACKUP COPY ON THIS MACHINE
3921                   if [[ $transfer_failed = true ]]
3922                   then
3923                      printf "  +++ transfer failed. Trying to save a copy on this host under:\n"
3924                      printf "      ${pathout[$i]}/${localhost}_${fname}${endout[$i]}_$kennung\n"
3925
3926                         # FIRST CHECK, IF DIRECTORY EXISTS, AND CREATE IT, IF NECESSARY
3927                      eval  local_catalog=${pathout[$i]}
3928                      if [[ ! -d $local_catalog ]]
3929                      then
3930                         printf "  *** local directory does not exist. Trying to create:\n"
3931                         printf "      $local_catalog \n"
3932                         mkdir -p  $local_catalog
3933                      fi
3934
3935                      eval  cp  ${localout[$i]}  ${pathout[$i]}/${localhost}_${fname}${endout[$i]}_$kennung
3936                      transfer_problems=true
3937                   fi
3938                fi
3939             else
3940
3941                   # RESET actionout. DUE TO THIS SETTING, FILE WILL LATER JUST BE APPENDED ON THIS MACHINE
3942                actionout[$i]=a
3943             fi
3944          fi
3945
3946
3947             # OUTPUT-FILE FOR A RESTART-RUN.
3948             # FILE IS MOVED TO THE TEMPORARY DATA DIRECTORY USING link COMMAND.
3949             # OPTION -f IS USED TO OVERWRITE EXISTING FILES.
3950             # AS LAST ACTION, ARCHIVING IS INITIATED.
3951          if [[ "${actionout[$i]}" = fl ]]
3952          then
3953             [[ ! -d $tmp_data_catalog ]]  &&  mkdir -p  $tmp_data_catalog
3954             chmod  g+rx  $tmp_data_catalog
3955             if [[ $files_for_pes = false ]]
3956             then
3957                printf "\n  >>> OUTPUT: ${localout[$i]}  to"
3958                printf "\n              $tmp_data_catalog/${frelout[$i]} (temporary data catalog)\n"
3959                ln -f  ${localout[$i]}  $tmp_data_catalog/${frelout[$i]}
3960             else
3961                printf "\n  >>> OUTPUT: ${localout[$i]}/....  to"
3962                printf "\n              $tmp_data_catalog/${frelout[$i]} (temporary data catalog)\n"
3963                mkdir  $tmp_data_catalog/${frelout[$i]}
3964                cd ${localout[$i]}
3965                for file in $(ls *)
3966                do
3967                   ln -f $file $tmp_data_catalog/${frelout[$i]}
3968                done
3969                cd $TEMPDIR
3970             fi
3971
3972
3973                # CREATE AND SUBMIT ARCHIVING-JOB
3974             if [[ $store_on_archive_system = true ]]
3975             then
3976
3977                if [[ $archive_system = asterix ]]
3978                then
3979                   echo "cd  $tmp_data_catalog"                      >> archive_${frelout[$i]}
3980                   if [[ $files_for_pes = false ]]
3981                   then
3982                      echo "stageout  ${frelout[$i]}  > STAGE_OUTPUT${i}_$kennung" >> archive_${frelout[$i]}
3983                   else
3984                      echo "stageout -t  ${frelout[$i]}  > STAGE_OUTPUT${i}_$kennung" >> archive_${frelout[$i]}
3985                   fi
3986                   echo "cat  STAGE_OUTPUT${i}_$kennung"               >> archive_${frelout[$i]}
3987                   echo "if [[ \$(grep -c \"st.msg:150\"  STAGE_OUTPUT${i}_$kennung) != 0 ]]" >> archive_${frelout[$i]}
3988                   echo "then"                                       >> archive_${frelout[$i]}
3989                   echo "   do_stageout=false"                       >> archive_${frelout[$i]}
3990                   echo "else"                                       >> archive_${frelout[$i]}
3991                   echo "   echo \"  +++ $filetyp ${frelout[$i]}  could not be stored on archive-system\" " >> archive_${frelout[$i]}
3992                   echo "   cat  /dev/null  >  ~/job_queue/ARCHIVE_ERROR_$fname" >> archive_${frelout[$i]}
3993                   echo "   cat  STAGE_OUTPUT${i}_$kennung  >  ~/job_queue/archive_${frelout[$i]}_error" >> archive_${frelout[$i]}
3994                   echo "   echo \"  *** $filetyp ${frelout[$i]} will be copied to \$WORK as backup\" " >> archive_${frelout[$i]}
3995                   if [[ $files_for_pes = false ]]
3996                   then
3997                      echo "   cp   ${frelout[$i]}  \$WORK"                    >> archive_${frelout[$i]}
3998                   else
3999                      echo "   cp -r  ${frelout[$i]}  \$WORK/${frelout[$i]}"   >> archive_${frelout[$i]}
4000                   fi
4001                   echo "   echo \"  *** $filetyp ${frelout[$i]} saved\" " >> archive_${frelout[$i]}
4002                   echo "fi"                                         >> archive_${frelout[$i]}
4003                   echo "rm  STAGE_OUTPUT${i}_$kennung"              >> archive_${frelout[$i]}
4004                elif [[ $archive_system = DMF ]]
4005                then
4006                   echo "cd  $tmp_data_catalog"                      >> archive_${frelout[$i]}
4007                   if [[ $files_for_pes = false ]]
4008                   then
4009                      printf "\n  +++ archiving of single files impossible with $archive_system !\n"
4010                      locat=DMF
4011                      exit
4012                   else
4013                         # ??? nicht benötigte Archiv-Systeme entfernen ???
4014                         # FUER RECHNER IN JUELICH. DORT KOENNTEN AUCH
4015                         # EINZELNE DATEIEN GESICHERT WERDEN (SPAETER KORR.)
4016                      echo "rm -rf  \$ARCHIVE/${frelout[$i]}"     >> archive_${frelout[$i]}
4017                      echo "cp -r  ${frelout[$i]}  \$ARCHIVE"     >> archive_${frelout[$i]}
4018                   fi
4019                elif [[ $archive_system = tivoli ]]
4020                then
4021                   echo "cd  $tmp_data_catalog"                       >> archive_${frelout[$i]}
4022                   if [[ $files_for_pes = false ]]
4023                   then
4024                         # REMOVE EXISTING OLD FILES FROM THE ARCHIVE
4025                      echo "set -x"                                   >> archive_${frelout[$i]}
4026                      echo "rm  -rf  \$PERM/${frelout[$i]}"           >> archive_${frelout[$i]}
4027                      echo "cp  ${frelout[$i]} \$PERM/${frelout[$i]}" >> archive_${frelout[$i]}
4028                   else
4029
4030                      echo "set -x"                                   >> archive_${frelout[$i]}
4031                      echo "rm  -rf  \$PERM/${frelout[$i]}/*"         >> archive_${frelout[$i]}
4032                      echo "[[ ! -d \$PERM/${frelout[$i]} ]] && mkdir $PERM/${frelout[$i]}" >> archive_${frelout[$i]}
4033                      cd  $tmp_data_catalog
4034                      all_files=`ls -1 ${frelout[$i]}/*`
4035                      cd -  > /dev/null
4036                      (( inode = 0 ))
4037                      (( tp1   = tasks_per_node + 1 ))
4038                      while (( inode < nodes ))
4039                      do
4040                         files=`echo $all_files | cut -d" " -f1-$tasks_per_node`
4041                         all_files=`echo $all_files | cut -d" " -f$tp1-`
4042                         echo "tar  cvf \$PERM/${frelout[$i]}/${frelout[$i]}.node_$inode.tar $files"   >> archive_${frelout[$i]}
4043                         (( inode = inode + 1 ))
4044                      done
4045                   fi
4046                elif [[ $archive_system = ut ]]
4047                then
4048                   echo "cd  $tmp_data_catalog"                       >> archive_${frelout[$i]}
4049                   if [[ $files_for_pes = false ]]
4050                   then
4051                         # REMOVE EXISTING OLD FILES FROM THE ARCHIVE
4052                      echo "set -x"                                 >> archive_${frelout[$i]}
4053                      echo "rm  -rf  \$UT/${frelout[$i]}"           >> archive_${frelout[$i]}
4054                      echo "cp  ${frelout[$i]} \$UT/${frelout[$i]}" >> archive_${frelout[$i]}
4055                   else
4056
4057                      echo "set -x"                                 >> archive_${frelout[$i]}
4058                      echo "rm  -rf  \$UT/${frelout[$i]}/*"         >> archive_${frelout[$i]}
4059                      echo "[[ ! -d \$UT/${frelout[$i]} ]] && mkdir $UT/${frelout[$i]}" >> archive_${frelout[$i]}
4060                      cd  $tmp_data_catalog
4061                      all_files=`ls -1 ${frelout[$i]}/*`
4062                      cd -  > /dev/null
4063                      (( inode = 0 ))
4064                      (( tp1   = tasks_per_node + 1 ))
4065                      while (( inode < nodes ))
4066                      do
4067                         files=`echo $all_files | cut -d" " -f1-$tasks_per_node`
4068                         all_files=`echo $all_files | cut -d" " -f$tp1-`
4069                         echo "tar  cvf \$UT/${frelout[$i]}/${frelout[$i]}.node_$inode.tar $files"   >> archive_${frelout[$i]}
4070                         (( inode = inode + 1 ))
4071                      done
4072                   fi
4073                elif [[ $archive_system = none ]]
4074                then
4075                   printf "              +++ archiving on $localhost not available!\n"
4076                fi
4077
4078                if [[ $archive_system != none ]]
4079                then
4080                   if [[ $localhost = nech ]]
4081                   then
4082                      subjob  -d  -c /pf/b/$usern/job_queue  -v  -q pp  -X 0  -m 1000  -t 7200  $PORTOPT  archive_${frelout[$i]}
4083                   fi
4084                   printf "              Archiving of $tmp_data_catalog/${frelout[$i]} initiated (batch job submitted)\n"
4085                fi
4086             else
4087                printf "              +++ caution: option -A is switched off. No archiving on $archive_system!\n"
4088             fi
4089
4090
4091                # CREATE AN EMPTY DIRECTORY IN THE USERS PERMANENT DIRECTORY,
4092                # IN ORDER TO NOTE THE RESPECTIVE CYCLE NUMBER ON THE ARCHIVE SYSTEM
4093                # RESTART-JOBS ARE USING THESE EMPTY-DIRECTORIES TO GET THE CURRENT HIGHEST
4094                # CYCLE NUMBER ON THE ARCHIVE SYSTEM (IN CASE THAT INFORMATIONS ARE DIFFICULT TO
4095                # TO ACCESS FROM THE ARCHIVE-SYSTEM DIRECTLY))
4096             if [[ $files_for_pes = false ]]
4097             then
4098                cat  /dev/null  >  ${pathout[$i]}
4099             else
4100                mkdir -p  ${pathout[$i]}
4101             fi
4102
4103          fi
4104
4105
4106             # COPY FROM THIS HOST TO THE ARCHIVE-SYSTEM
4107             # IF ANY ARCHIVING FAILS, AN ERROR-FLAG-FILE IS SET
4108             # THIS FILE REMAINS TO BE SET, EVEN IF ARCHIVING OF FURTHER FILES IS SUCCESSFULL
4109          if [[ "${actionout[$i]}" = ar ]]
4110          then
4111             if [[ $files_for_pes = false ]]
4112             then
4113                printf "\n  >>> OUTPUT: ${localout[$i]}  to"
4114                printf "\n              ${pathout[$i]}"
4115                printf "\n              File will be copied to archive-system ($archive_system) !\n"
4116             else
4117                printf "\n  >>> OUTPUT: ${localout[$i]}/_....  to"
4118                printf "\n              ${pathout[$i]}"
4119                printf "\n              Directory will be copied to archive-system ($archive_system) !\n"
4120             fi
4121             mv  ${localout[$i]}  ${frelout[$i]}
4122
4123             file_saved=false
4124
4125             if [[ $archive_system = asterix ]]
4126             then
4127                do_stageout=true
4128                (( stageout_anz = 0 ))
4129                while [[ $do_stageout = true ]]
4130                do
4131                   if [[ $files_for_pes = false ]]
4132                   then
4133                      stageout  ${frelout[$i]}  > STAGE_OUTPUT
4134                   else
4135                      stageout  -t  ${frelout[$i]}  > STAGE_OUTPUT
4136                   fi
4137                   cat  STAGE_OUTPUT
4138                   if [[ $(grep -c "st.msg:150"  STAGE_OUTPUT) != 0 ]]
4139                   then
4140                      file_saved=true
4141                      do_stageout=false
4142                   else
4143                      if [[ $files_for_pes = false ]]
4144                      then
4145                         printf "\n  +++ file ${frelout[$i]}  could not be saved on archive-system"
4146                      else
4147                         printf "\n  +++ directory ${frelout[$i]} could not be saved on archive-system"
4148                      fi
4149                      (( stageout_anz = stageout_anz + 1 ))
4150                      if (( stageout_anz == 10 ))
4151                      then
4152                         printf "\n  +++ stoped after 10 unsuccessful tries!"
4153                         archive_save=false
4154                         do_stageout=false
4155                      else
4156                         printf "\n  *** new try to store on archive after 15 min:"
4157                         sleep 900
4158                      fi
4159                   fi
4160                done
4161             elif [[ $archive_system = DMF ]]
4162             then
4163                if [[ $files_for_pes = false ]]
4164                then
4165                   printf "\n  +++ archiving of single files impossible on $archive_system!\n"
4166                   locat=DMF
4167                   exit
4168                else
4169                   rm -rf  $ARCHIVE/${frelout[$i]}
4170                   cp -r  ${frelout[$i]}  $ARCHIVE
4171                fi
4172                file_saved=true
4173             elif [[ $archive_system = tivoli ]]
4174             then
4175                   # ARCHIVING ONLY POSSIBLE VIA BATCH-JOB
4176                   # IN THE MEANTIME, FILE IS STORED IN THE TEMPORARY DATA DIRECTORY,
4177                   # BECAUSE MRUN'S CURRENT TEMPORARY WORKING DIRECTORY MAY ALREADY BE DELETED
4178                   # WHEN THE ARCHIVE-JOB IS EXECUTED
4179                [[ ! -d $tmp_data_catalog ]]  &&  mkdir -p  $tmp_data_catalog
4180                chmod  g+rx  $tmp_data_catalog
4181                if [[ $files_for_pes = false ]]
4182                then
4183                   ln -f  ${frelout[$i]}  $tmp_data_catalog/${frelout[$i]}
4184                else
4185                   mkdir  $tmp_data_catalog/${frelout[$i]}
4186                   ln -f  ${frelout[$i]}/*  $tmp_data_catalog/${frelout[$i]}
4187                fi
4188
4189                   # GENERATE AND SUBMIT BATCH-JOB
4190                   # FILE HAS TO BE DELETED FROM THE TEMPORARY DATA DIRECTORY
4191                   # DELETE OLD EXISTING FILES FROM THE ARCHIVE
4192                echo "cd  $tmp_data_catalog"                       >  archive_${frelout[$i]}
4193                if [[ $files_for_pes = false ]]
4194                then
4195                   echo "rm  -rf  \$PERM/${frelout[$i]}"           >> archive_${frelout[$i]}
4196                   echo "cp  ${frelout[$i]} \$PERM/${frelout[$i]}" >> archive_${frelout[$i]}
4197                   echo "rm  -rf  ${frelout[$i]}"                  >> archive_${frelout[$i]}
4198                else
4199                   echo "rm  -rf  \$PERM/${frelout[$i]}.tar"       >> archive_${frelout[$i]}
4200                   echo "tar  cvf \$PERM/${frelout[$i]}.tar ${frelout[$i]}" >> archive_${frelout[$i]}
4201                   echo "rm  -rf  ${frelout[$i]}"                  >> archive_${frelout[$i]}
4202                fi
4203
4204                subjob  -v  -d  -q cdata  -X 0  -m 1000  -t 43200  -c $job_catalog  $PORTOPT  archive_${frelout[$i]}
4205                printf "              Archiving of $tmp_data_catalog/${frelout[$i]} initiated (batch job submitted)\n"
4206                file_saved=true
4207
4208             elif [[ $archive_system = ut ]]
4209             then
4210                   # ARCHIVING ONLY POSSIBLE VIA BATCH-JOB
4211                   # IN THE MEANTIME, FILE IS STORED IN THE TEMPORARY DATA DIRECTORY,
4212                   # BECAUSE MRUN'S CURRENT TEMPORARY WORKING DIRECTORY MAY ALREADY BE DELETED
4213                   # WHEN THE ARCHIVE-JOB IS EXECUTED
4214                [[ ! -d $tmp_data_catalog ]]  &&  mkdir -p  $tmp_data_catalog
4215                chmod  g+rx  $tmp_data_catalog
4216                if [[ $files_for_pes = false ]]
4217                then
4218                   ln -f  ${frelout[$i]}  $tmp_data_catalog/${frelout[$i]}
4219                else
4220                   mkdir  $tmp_data_catalog/${frelout[$i]}
4221                   ln -f  ${frelout[$i]}/*  $tmp_data_catalog/${frelout[$i]}
4222                fi
4223
4224                   # GENERATE AND SUBMIT BATCH-JOB
4225                   # FILE HAS TO BE DELETED FROM THE TEMPORARY DATA DIRECTORY
4226                   # DELETE OLD EXISTING FILES FROM THE ARCHIVE
4227                echo "cd  $tmp_data_catalog"                       >  archive_${frelout[$i]}
4228                if [[ $files_for_pes = false ]]
4229                then
4230                   echo "rm  -rf  \$UT/${frelout[$i]}"           >> archive_${frelout[$i]}
4231                   echo "cp  ${frelout[$i]} \$UT/${frelout[$i]}" >> archive_${frelout[$i]}
4232                   echo "rm  -rf  ${frelout[$i]}"                >> archive_${frelout[$i]}
4233                else
4234                   echo "rm  -rf  \$UT/${frelout[$i]}.tar"       >> archive_${frelout[$i]}
4235                   echo "tar  cvf \$UT/${frelout[$i]}.tar ${frelout[$i]}" >> archive_${frelout[$i]}
4236                   echo "rm  -rf  ${frelout[$i]}"                >> archive_${frelout[$i]}
4237                fi
4238
4239                subjob  -v  -c /pf/b/$usern/job_queue  -d  -q pp  -X 0  -m 1000  -t 7200  $PORTOPT  archive_${frelout[$i]}
4240                printf "              Archiving of $tmp_data_catalog/${frelout[$i]} initiated (batch job submitted)\n"
4241                file_saved=true
4242
4243             else
4244                printf "\n  +++ archive_system=\"$archive_system\"  archiving impossible!"
4245                archive_save=false
4246             fi
4247
4248                # CREATE EMPTY FLAG-FILE OR -DIRECTORY
4249                # IN ORDER TO NOTE THE RESPECTIVE CYCLE NUMBER ON THE ARCHIVE SYSTEM
4250                # RESTART-JOBS ARE USING THESE EMPTY-DIRECTORIES TO GET THE CURRENT HIGHEST
4251                # CYCLE NUMBER ON THE ARCHIVE SYSTEM (IN CASE THAT INFORMATIONS ARE DIFFICULT TO
4252                # TO ACCESS FROM THE ARCHIVE-SYSTEM DIRECTLY))
4253             if [[ $file_saved = true ]]
4254             then
4255                if [[ $files_for_pes = false ]]
4256                then
4257                   cat  /dev/null  >  ${pathout[$i]}
4258                else
4259                   mkdir -p  ${pathout[$i]}
4260                fi
4261             fi
4262
4263          fi
4264
4265             # APPEND ON THIS MACHINE
4266          if [[ "${actionout[$i]}" = "a" ]]
4267          then
4268             if [[ "${extout[$i]}" != " "  &&  "${extout[$i]}" != "" ]]
4269             then
4270                printf "\n  >>> OUTPUT: ${localout[$i]}  append to  ${pathout[$i]}.${extout[$i]}\n"
4271                cat  ${localout[$i]}  >>  ${pathout[$i]}.${extout[$i]}
4272             else
4273                printf "\n  >>> OUTPUT: ${localout[$i]}  append to  ${pathout[$i]}\n"
4274                cat  ${localout[$i]}  >>  ${pathout[$i]}
4275             fi
4276          fi
4277
4278             # COPY ON THIS MACHINE
4279             # COPY HAS TO BE USED, BECAUSE MOVE DOES NOT WORK IF FILE-ORIGIN AND TARGET ARE
4280             # ON DIFFERENT FILE-SYSTEMS
4281          if [[ "${actionout[$i]}" = ""  &&  $files_for_pes = false ]]
4282          then
4283
4284                # COPY IN CASE OF RUNS ON SINGLE CORES
4285             if [[ "${extout[$i]}" != " "  &&  "${extout[$i]}" != "" ]]
4286             then
4287                printf "\n  >>> OUTPUT: ${localout[$i]}  to  ${pathout[$i]}.${extout[$i]}\n"
4288                if [[ $link_local_output = true ]]
4289                then
4290                    printf "      using ln -f\n"
4291                    ln -f  ${localout[$i]}  ${pathout[$i]}.${extout[$i]}
4292                fi
4293                # If "ln -f" fails of if "$link_local_output = false" do a normal "cp"
4294                if [[ ! -f "${pathout[$i]}.${extout[$i]}" ]]
4295                then
4296                    if [[ $link_local_output = true ]]
4297                    then
4298                        printf "      ln failed, using cp...\n"
4299                    fi
4300                    cp  ${localout[$i]}  ${pathout[$i]}.${extout[$i]}
4301                fi
4302             else
4303                printf "\n  >>> OUTPUT: ${localout[$i]}  to  ${pathout[$i]}\n"
4304                if [[ $link_local_output = true ]]
4305                then
4306                    printf "      using ln -f\n"
4307                    ln -f  ${localout[$i]}  ${pathout[$i]}
4308                fi
4309                # If "ln -f" fails of if "$link_local_output = false" do a normal "cp"
4310                if [[ ! -f "${pathout[$i]}" ]]
4311                then
4312                    if [[ $link_local_output = true ]]
4313                    then
4314                        printf "      ln failed, using cp...\n"
4315                    fi
4316                    cp  ${localout[$i]}  ${pathout[$i]}
4317                fi
4318             fi
4319
4320          elif [[ "${actionout[$i]}" = ""  &&  $files_for_pes = true ]]
4321          then
4322
4323                # FILES FROM THE DIFFERENT CORES ARE MOVED WITH ln-COMMAND TO THE PERMANENT DIRECTORY
4324                # AS A FIRST STEP, THE PERMANENT DIRECTORY IS CREATED
4325             printf "\n  >>> OUTPUT: ${localout[$i]}/_....  to  ${pathout[$i]}\n"
4326             if [[ $link_local_output = true ]]
4327             then
4328                 printf "      using ln -f\n"
4329                 mkdir  ${pathout[$i]}
4330                 cd ${localout[$i]}
4331                 for file in $(ls *)
4332                 do
4333                   ln -f $file  ${pathout[$i]}
4334                 done
4335                 cd $TEMPDIR
4336             fi
4337
4338                # IF "ln -f" HAS FAILED OR IF "$link_local_output = false" DO A NORMAL COPY "cp -r"
4339             if [[ ! -f "${pathout[$i]}/_0000" ]]
4340             then
4341                 if [[ $link_local_output = true ]]
4342                 then
4343                     printf "      ln failed for .../_0000, using cp...\n"
4344                 fi
4345                 cp -r  ${localout[$i]}  ${pathout[$i]}
4346             fi
4347
4348          fi
4349       fi
4350    done
4351    if (( i != 0 ))
4352    then
4353       if [[ $transfer_problems = true ]]
4354       then
4355          printf "\n$dashes\n  *** OUTPUT-files saved"
4356          printf "\n  +++ WARNING: some data transfers failed! \n"
4357       else
4358          printf "\n$dashes\n  *** all OUTPUT-files saved \n"
4359       fi
4360    fi
4361
4362
4363       # IF REQUIRED, START A RESTART-JOB
4364       # FILE CONTINUE_RUN MUST HAVE BEEN CREATED BY THE EXECUTABLE (PALM)
4365    if [[ -f CONTINUE_RUN ]]
4366    then
4367
4368       if [[ $archive_save = true ]]
4369       then
4370
4371             # ADD RESTART-OPTIONS TO THE MRUN-CALL (IF THEY ARE NOT USED ALREADY):
4372             # -C TELLS MRUN THAT IT IS A RESTART-RUN
4373             # -v SILENT MODE WITHOUT INTERACTIVE QUERIES
4374             # -n BATCH-MODE (IMPORTANT ONLY IN CASE OF BATCH JOBS ON THE LOCAL MACHINE)
4375          [[ $(echo $mc | grep -c "\-C") = 0 ]]  &&  mc="$mc -C"
4376          [[ $(echo $mc | grep -c "\-v") = 0 ]]  &&  mc="$mc -v"
4377          [[ $(echo $mc | grep -c "\-b") = 0 ]]  &&  mc="$mc -b"
4378          if [[ $(echo $mc | grep -c "#") != 0 ]]
4379          then
4380             mc=`echo $mc | sed 's/#/f/g'`
4381          fi
4382
4383
4384             # START THE RESTART-JOB
4385          printf "\n\n  *** initiating restart-run on \"$return_address\" using command:\n"
4386          echo "      $mc"
4387          printf "\n$dashes\n"
4388          if [[ $localhost != $fromhost ]]
4389          then
4390
4391             if [[ $localhost = lccrayb  || $localhost = lccrayh  ||  $localhost = nech  ||  $localhost = ibmh  ||  $localhost = ibmkisti  ||  $localhost = ibmku  ||  $localhost = ibms  ||  $localhost = lcflow  ||  $localhost = lckyu* || $localhost = lcxe6 ]]
4392             then
4393                echo "*** ssh will be used to initiate restart-runs!"
4394                echo "    return_address=\"$return_address\" "
4395                echo "    return_username=\"$return_username\" "
4396                if [[ $(echo $return_address | grep -c "130.75.105") = 1 ]]
4397                then
4398                   if [[ $localhost = ibmh ]]
4399                   then
4400                      ssh $SSH_PORTOPT $usern@136.172.40.15 "ssh $SSH_PORTOPT $return_address -l $return_username \". \\\$HOME/.profile; module load intel-compiler hdf5 netcdf; PATH=\\\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4401                   elif [[ $localhost = lccrayb ]]
4402                   then
4403                      ssh $usern@blogin1 "ssh $SSH_PORTOPT $return_address -l $return_username \". \\\$HOME/.profile; module load intel-compiler hdf5 netcdf; PATH=\\\$PATH:$LOCAL_MRUN_PATH; export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4404                   elif [[ $localhost = lccrayh ]]
4405                   then
4406                      ssh $usern@hlogin1 "ssh $SSH_PORTOPT $return_address -l $return_username \". \\\$HOME/.profile; module load intel-compiler hdf5 netcdf; PATH=\\\$PATH:$LOCAL_MRUN_PATH; export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4407                   elif [[ $localhost = lcxe6 ]]
4408                   then
4409                      ssh $usern@hexagon "ssh $SSH_PORTOPT $return_address -l $return_username \". \\\$HOME/.profile; module load intel-compiler hdf5 netcdf; PATH=\\\$PATH:$LOCAL_MRUN_PATH; export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4410                   else
4411                      ssh $SSH_PORTOPT $return_address -l $return_username ". \\\$HOME/.profile; module load intel-compiler hdf5 netcdf; PATH=\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc "
4412                   fi
4413                else
4414                   if [[ $localhost = ibmkisti ]]
4415                   then
4416                      ssh $SSH_PORTOPT $usern@gaiad "ssh $SSH_PORTOPT $return_address -l $return_username \"PATH=\\\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4417                   elif [[ $localhost = lcflow ]]
4418                   then
4419                      /usr/bin/ssh $SSH_PORTOPT $return_address -l $return_username "PATH=\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc "
4420                   elif [[ $localhost = lccrayb ]]
4421                   then
4422                      ssh $usern@blogin1 "ssh $SSH_PORTOPT $return_address -l $return_username \"PATH=\\\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4423                   elif [[ $localhost = lccrayh ]]
4424                   then
4425                      ssh $usern@hlogin1 "ssh $SSH_PORTOPT $return_address -l $return_username \"PATH=\\\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4426                   else
4427                      ssh $SSH_PORTOPT $return_address -l $return_username "PATH=\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc "
4428                   fi
4429                fi
4430             else
4431                printf "\n  +++ no restart mechanism available for host \"$localhost\" "
4432                locat=restart; exit
4433             fi
4434
4435                # WAIT TO ALLOW THE RESTART-JOB TO BE QUEUED, BEFORE THE CURRENT JOB IS FINISHED
4436             if [[ $queue = special1q ]]
4437             then
4438                sleep 120
4439             else
4440                sleep 30
4441             fi
4442
4443          else
4444
4445                # JOBS RUNNING (AND STARTED) ON THE LOCAL MACHINE CAN DIRECTLY CALL MRUN (WITHOUT
4446                # USING SSH)
4447             cd $LOCAL_PWD
4448             if [[ $localhost = lckyuh ]]
4449             then
4450                printf "\n  +++ WARNING: no restart mechanism available for host \"$localhost\" "
4451                printf "\n               please restart job manually using command:\n"
4452                printf "\n               \"$mc\" "
4453             else
4454                eval  $mc                # THE ' MUST BE EVALUATED
4455             fi
4456             cd -  > /dev/null
4457          fi
4458          if [[ $localhost = lckyuh ]]
4459          then
4460             printf "\n$dashes\n  *** restart-run to be initiated manually\n"
4461          else
4462             printf "\n$dashes\n  *** restart-run initiated \n"
4463          fi
4464
4465
4466             # DELETE INPUT-(RESTART)FILES, WHICH HAVE BEEN FETCHED FROM THE TEMPORARY DATA
4467             # DIRECTORY, BACAUSE THEY ARE NOT REQUIRED BY THE RESTART-JOB.
4468             # THIS IS DONE IN ORDER TO AVOID EXCEEDING DISC QUOTAS OR DISC SPACE (RESTART-FILES
4469             # MAY BE VERY HUGE)
4470          (( i = 0 ))
4471          while (( i < iin ))
4472          do
4473             (( i = i + 1 ))
4474             if [[ "${got_tmp[$i]}" = true   &&  $keep_data_from_previous_run = false ]]
4475             then
4476                rm -r  $tmp_data_catalog/${frelin[$i]}
4477             fi
4478          done
4479
4480       else
4481
4482          printf "\n  +++ no restart-run possible, since errors occured"
4483          printf "\n      during the archive process"
4484       fi
4485
4486    fi
4487
4488
4489   
4490       # SEND EMAIL NOTIFICATION ABOUT THE FINISHED RUN
4491    if [[ "$email_notification" != "none" ]]
4492    then
4493
4494       if [[ $localhost != $fromhost ]]
4495       then
4496          if [[ -f CONTINUE_RUN ]]
4497          then
4498             echo "PALM restart run necessary"        >   email_text
4499             echo "description header of actual run:" >>  email_text
4500             cat  CONTINUE_RUN                        >>  email_text
4501             echo "mrun-command to restart:"          >>  email_text
4502             echo "$mc"                               >>  email_text
4503          else
4504             echo "PALM run with base filename \"$fname\" on host \"$localhost\" finished"  >  email_text
4505          fi
4506          mail  $email_notification  <  email_text
4507          printf "\n  *** email notification sent to \"$email_notification\" "
4508       fi
4509    fi
4510
4511
4512
4513       # ALL ACTIONS FINISHED, TEMPORARY WORKING-DIRECTORY CAN BE DELETED
4514    cd  $HOME
4515    [[ $delete_temporary_catalog = true ]]  &&  rm -rf $TEMPDIR
4516
4517 else
4518
4519
4520       # PREPARING ACTIONS,
4521       # IF A BATCH-JOB IS TO BE GENERATED AND STARTED ON A REMOTE-MACHINE GERECHNET
4522
4523       # BUILD THE MRUN-COMMAND TO BE CALLED IN THE BATCH-JOB ON THE REMOTE-MACHINE
4524    mrun_com="$mrun_script_name -a $afname -c $config_file -d $fname -h $host -H $fromhost -m $memory -t $cpumax -q $queue -R $return_address -U $return_username -u $remote_username"
4525    [[ "$cpp_opts" != "" ]]       &&  mrun_com=${mrun_com}" -D \"$cpp_opts\""
4526    [[ "$global_revision" != "" ]]  &&  mrun_com=${mrun_com}" -G \"$global_revision\""
4527    [[ $group_number != none ]]   &&  mrun_com=${mrun_com}" -g $group_number"
4528    [[ $do_compile = true ]]      &&  mrun_com=${mrun_com}" -s \"$source_list\""
4529    [[ "$input_list" != "" ]]     &&  mrun_com=${mrun_com}" -i \"$input_list\""
4530    [[ $ignore_archive_error = true ]]  &&  mrun_com=${mrun_com}" -I"
4531    [[ $keep_data_from_previous_run = true ]]  &&  mrun_com=${mrun_com}" -k"
4532    [[ "$additional_conditions" != "" ]]  &&  mrun_com=${mrun_com}" -K \"$additional_conditions\""
4533    [[ "$output_list" != "" ]]    &&  mrun_com=${mrun_com}" -o \"$output_list\""
4534    [[ "$read_from_config" = false ]]  &&  mrun_com=${mrun_com}" -S"
4535    [[ $do_trace = true ]]        &&  mrun_com=${mrun_com}" -x"
4536    [[ "$numprocs" != "" ]]       &&  mrun_com=${mrun_com}" -X $numprocs"
4537    if [[ $use_openmp = true ]]
4538    then
4539       mrun_com=${mrun_com}" -O $threads_per_task"
4540    fi
4541    [[ "$tasks_per_node" != "" ]]  &&  mrun_com=${mrun_com}" -T $tasks_per_node"
4542    [[ $store_on_archive_system = true ]]  &&  mrun_com=${mrun_com}" -A"
4543    [[ $package_list != "" ]]     &&  mrun_com=${mrun_com}" -p \"$package_list\""
4544    [[ $return_password != "" ]]  &&  mrun_com=${mrun_com}" -P $return_password"
4545    [[ $delete_temporary_catalog = false ]]  &&  mrun_com=${mrun_com}" -B"
4546    [[ $node_usage != default  &&  "$(echo $node_usage | cut -c1-3)" != "sla"  &&  $node_usage != novice ]]  &&  mrun_com=${mrun_com}" -n $node_usage"
4547    [[ "$ocean_file_appendix" = true ]]  &&  mrun_com=${mrun_com}" -y"
4548    [[ $run_coupled_model = true ]]  &&  mrun_com=${mrun_com}" -Y \"$coupled_dist\""
4549    [[ "$check_namelist_files" = false ]]  &&  mrun_com=${mrun_com}" -z"
4550    [[ "$combine_plot_fields" = false ]]  &&  mrun_com=${mrun_com}" -Z"
4551    [[ "$max_par_io_str" != "" ]]  &&  mrun_com=${mrun_com}" -w $max_par_io_str"
4552    if [[ $do_remote = true ]]
4553    then
4554       printf "\n>>>> MRUN-command on execution host:\n>>>> $mrun_com \n"
4555    fi
4556
4557
4558       # CREATE EXECUTABLE FOR BATCH JOB
4559    if [[ $create_executable_for_batch = true  &&  $restart_run != true ]]
4560    then
4561
4562       printf "\n  *** creating the executable for batch job\n"
4563
4564          # METHOD ONLY WORKS FOR BATCH JOBS ON LOCAL HOSTS
4565       if [[ $host != $localhost ]]
4566       then
4567          printf "\n  +++ creation of executables is only allowed for batch jobs on local hosts."
4568          printf "\n      Please set create_executable_for_batch = false in the config-file.\n"
4569          locat=create_executable; exit
4570       fi
4571
4572       mkdir  $working_directory/SOURCES_FOR_RUN_${fname}/TMPDIR_FOR_CREATING_EXECUTABLE
4573       cd  $working_directory/SOURCES_FOR_RUN_${fname}/TMPDIR_FOR_CREATING_EXECUTABLE
4574
4575       cp  $make_depository  .
4576       tar -xf  $make_depository  >  /dev/null  2>&1
4577       cp  ../*  .   >  /dev/null  2>&1
4578
4579       make $mopts -f Makefile PROG=a.out  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$fopts"  LDFLAGS="$lopts"
4580
4581       if [[ $? != 0  ||  "$compile_error" = true  ||  "$module_compile_error" = true ]]
4582       then
4583          printf "\n  +++ error occured while compiling or linking"
4584          locat=compile
4585          exit
4586       fi
4587
4588       mv  a.out  ..
4589       cd -  >  /dev/null  2>&1
4590       rm -rf  $working_directory/SOURCES_FOR_RUN_${fname}/TMPDIR_FOR_CREATING_EXECUTABLE
4591
4592       printf "  *** executable created in \"$working_directory/SOURCES_FOR_RUN_${fname}\"\n "
4593
4594    fi
4595
4596
4597       # BUILD THE JOB-SCRIPTS ON FILE jobfile
4598    jobfile=jobfile.$RANDOM
4599
4600
4601       # CREATE TEMPORARY DIRECTORY AND SWITCH TO IT
4602    echo  "mkdir  $TEMPDIR"      >>  $jobfile
4603    echo  "cd  $TEMPDIR"         >>  $jobfile
4604
4605
4606       # ACTIVATE ERROR-TRACEBACK
4607    if [[ $do_trace = true ]]
4608    then
4609       echo  "set -x"                                    >>  $jobfile
4610    else
4611       echo  "set +vx"                                   >>  $jobfile
4612    fi
4613
4614
4615       # INITIALIZE THE ENVIRONMENT AND LOAD MODULES
4616    if [[ "$init_cmds" != "" ]]
4617    then
4618       echo  "$init_cmds"        >>  $jobfile
4619    fi
4620    if [[ "$module_calls" != "" ]]
4621    then
4622       echo  "$module_calls"     >>  $jobfile
4623    fi
4624
4625
4626       # PROVIDE SOURCE-CODE FILES, MRUN-SCRIPT AND CONFIGURATION-FILE FOR THE JOB
4627       # then-CLAUSE: FILES ARE COLLECTED IN THE SOURCES_FOR_RUN_... DIRECTORY ON THE LOCAL HOST,
4628       #              WHICH IS THEN FETCHED FROM THE BATCH-JOB BY USING cp/scp
4629       #              THE SOURCE-CODE FILES ALREADY EXIST IN THIS DIRECTORY
4630       # else-CLAUSE: FILE-CONTENTS ARE PUT INTO THE JOB-FILE AS HERE-DOCUMENTS
4631       #              THIS MAY CREATE A QUITE LARGE JOB-FILE, WHICH CAN CAUSE PROBLEMS WITH SOME
4632       #              QUEUEING-SYSTEMS
4633    if [[ $host = ibmkisti  ||  $host = lccrayb  ||  $host = lccrayf  ||  $host = lccrayh ]]
4634    then
4635
4636          # COPY CONFIGURATION-FILE AND MRUN-SCRIPT INTO THE SOURCES_FOR_RUN... DIRECTORY
4637       if [[ $restart_run != true ]]
4638       then
4639          cp  $config_file  $working_directory/SOURCES_FOR_RUN_$fname
4640          cp  ${PALM_BIN}/$mrun_script_name  $working_directory/SOURCES_FOR_RUN_$fname
4641       fi
4642
4643          # COPY THE SOURCES_FOR_RUN... DIRECTORY FROM THE LOCAL HOST TO THE JOB VIA scp
4644          # (then-CLAUSE: JOBS ON THE LOCAL HOST CAN JUST USE cp)
4645       echo  "set -x"  >>  $jobfile
4646       if [[ $host = $localhost ]]
4647       then
4648
4649             # DUE TO UNKNOWN REASONS, COPY WITH cp COMMAND CREATES CORRUPT
4650             # FILES ON CRAY XC30 SYSTEMS (CSC HELSINKI), rsync IS USED INSTEAD
4651          if [[ $(echo $host | cut -c1-6) = lccray ]]
4652          then
4653             echo  "rsync -av -t  $working_directory/SOURCES_FOR_RUN_$fname  ."  >>  $jobfile
4654          else
4655             echo  "cp -r  $working_directory/SOURCES_FOR_RUN_$fname  ."  >>  $jobfile
4656          fi
4657
4658       else
4659          if [[ $host = ibmkisti ]]
4660          then
4661                # ON KISTI'S IBM FIREWALL IS ONLY OPENED ON INTERACTIVE NODE
4662             echo  "localdir=\`pwd\`"                            >>  $jobfile
4663             echo  "ssh $SSH_PORTOPT $remote_username@gaiad \"cd \$localdir; scp $PORTOPT -r  $return_username@$return_address:$working_directory/SOURCES_FOR_RUN_$fname .\" "  >>  $jobfile
4664          elif [[ $host = lccrayb ]]
4665          then
4666             echo  "localdir=\`pwd\`"                            >>  $jobfile
4667             echo  "ssh $SSH_PORTOPT $remote_username@blogin1 \"cd \$localdir; scp $PORTOPT -r  $return_username@$return_address:$working_directory/SOURCES_FOR_RUN_$fname .\" "  >>  $jobfile
4668          elif [[ $host = lccrayh ]]
4669          then
4670             echo  "localdir=\`pwd\`"                            >>  $jobfile
4671             echo  "ssh $SSH_PORTOPT $remote_username@hlogin1 \"cd \$localdir; scp $PORTOPT -r  $return_username@$return_address:$working_directory/SOURCES_FOR_RUN_$fname .\" "  >>  $jobfile
4672
4673          else
4674             echo  "scp $PORTOPT -r $return_username@$return_address:$working_directory/SOURCES_FOR_RUN_$fname ."  >>  $jobfile
4675          fi
4676       fi
4677       echo  "export SOURCES_COMPLETE=true"                      >>  $jobfile
4678
4679          # MOVE MRUN-SCRIPT AND CONFIGURATION-FILE FROM THE SOURCES_FOR_RUN... DIRECTORY TO THE
4680          # WORKING DIRECTORY OF THE JOB
4681       echo  "mv  SOURCES_FOR_RUN_$fname/$config_file  . "       >>  $jobfile
4682       echo  "mv  SOURCES_FOR_RUN_$fname/$mrun_script_name  . "  >>  $jobfile
4683       echo  "chmod u+rwx  $mrun_script_name"                    >>  $jobfile
4684       echo  "execute_mrun=true"                                 >>  $jobfile
4685       echo  " "                                                 >>  $jobfile
4686
4687    else
4688
4689          # PROVIDE SOURCE-CODE FILES AND MAKEFILE AS HERE DOCUMENT
4690       if [[ $do_compile = true ]]
4691       then
4692
4693          source_catalog=SOURCES_FOR_RUN_$fname
4694
4695              # CREATE SOURCES_FOR_RUN... DIRECTORY TO STORE THE SOURCE CODE FILES AND THE MAKEFILE
4696          echo  "mkdir  SOURCES_FOR_RUN_$fname"                >>  $jobfile
4697          echo  "export SOURCES_COMPLETE=true"                 >>  $jobfile
4698          echo  "cd     SOURCES_FOR_RUN_$fname"                >>  $jobfile
4699
4700          for  filename  in  $source_list
4701          do
4702                # BACKSLASH IS USED FOR MASKING
4703             echo  "cat > $filename << \"%END%\""              >>  $jobfile
4704             cat   $source_catalog/$filename                   >>  $jobfile
4705             echo  " "                                         >>  $jobfile
4706             echo  "%END%"                                     >>  $jobfile
4707             echo  " "                                         >>  $jobfile
4708          done
4709
4710             # BACKSLASH IS USED FOR MASKING
4711          echo  "cat > Makefile << \"%END%\""               >>  $jobfile
4712          cat   $source_catalog/Makefile                    >>  $jobfile
4713          echo  " "                                         >>  $jobfile
4714          echo  "%END%"                                     >>  $jobfile
4715          echo  " "                                         >>  $jobfile
4716
4717          echo  "cd -  > /dev/null"                         >>  $jobfile
4718
4719       fi
4720
4721
4722          # PROVIDE THE CONFIGURATION-FILE AS HERE-DOCUMENT
4723          # BACKSLASH IS USED FOR MASKING
4724          # LINES WITH #$ IN THE CONFIGURATION-FILE, COMING FROM THE SVN KEYWORD SUBSTITUTION,
4725          # ARE REMOVED FROM THE FILE IN ORDER TO AVOID PROBLEMS WITH THE SGE BATCH SYSTEM
4726       echo  "cat > $config_file << \"%END%\""      >>  $jobfile
4727       if [[ $host = lckyuh ]]
4728       then
4729             # NO CROSS-COMPILER ON COMPUTE NODE
4730          sed  's/frtpx/frt/g'  $config_file        >>  $jobfile
4731       else
4732          sed 's/#$.*//g'   $config_file            >>  $jobfile
4733       fi
4734       echo  "%END%"                                >>  $jobfile
4735       echo  " "                                    >>  $jobfile
4736
4737
4738          # PROVIDE THE MRUN-SCRIPTS AS HERE-DOCUMENT
4739          # BACKSLASH IS USED FOR MASKING
4740       echo  "cat > $mrun_script_name <<\"%END%\""  >>  $jobfile
4741       if [[ $host = lckyuh ]]
4742       then
4743          sed 's/\/bin\/ksh/\/bin\/bash/g' ${PALM_BIN}/$mrun_script_name  >>  $jobfile
4744       else
4745          cat  ${PALM_BIN}/$mrun_script_name        >>  $jobfile
4746       fi
4747       echo  "%END%"                                >>  $jobfile
4748       echo  "chmod u+x $mrun_script_name"          >>  $jobfile
4749       echo  "execute_mrun=true"                    >>  $jobfile
4750       echo  " "                                    >>  $jobfile
4751
4752    fi
4753
4754
4755       # GET REQUIRED INPUT-FILES BY SCP OR BY SENDING THEM WITH THE JOB AS HERE-DOCUMENT
4756       # PUT THESE FILES INTO THE USER'S RESPECTIVE PERMANENT DIRECTORIES ON THE REMOTE-HOST
4757       # IF THE DIRECTORIES DO NOT EXIST, TRY TO CREATE THEM
4758    if [[ $do_remote = true ]]
4759    then
4760       (( i = 0 ))
4761       while (( i < iin ))
4762       do
4763          (( i = i + 1 ))
4764          echo  "[[ ! -d ${pathin[$i]} ]]  &&  mkdir -p  ${pathin[$i]}"  >>  $jobfile
4765          if [[ "${transin[$i]}" = job ]]
4766          then
4767             echo  "cat > ${remotepathin[$i]} <<\"%END%\""    >>  $jobfile
4768             eval cat   ${pathin[$i]}/${frelin[$i]}           >>  $jobfile
4769             echo  " "                                        >>  $jobfile
4770             echo  "%END%"                                    >>  $jobfile
4771          else
4772             echo  "batch_scp $PORTOPT -b -o -g -s -u $return_username $return_address ${remotepathin[$i]} \"${pathin[$i]}\" ${frelin[$i]}" >>  $jobfile
4773          fi
4774
4775             # CHECK, IF FILE COULD BE CREATED
4776          echo  "if [[ \$? = 1 ]]"                    >>  $jobfile
4777          echo  "then"                                >>  $jobfile
4778          echo  "   echo \" \" "                      >>  $jobfile
4779          echo  "   echo \"+++ file ${remotepathin[$i]} could not be created\" "   >>  $jobfile
4780          echo  "   echo \"    please check, if directory exists on $host!\" "  >>  $jobfile
4781          echo  "   echo \"+++ MRUN will not be continued\" "  >>  $jobfile
4782          echo  "   execute_mrun=false"               >>  $jobfile
4783          echo  "fi"                                  >>  $jobfile
4784       done
4785    fi
4786
4787       # PROVIDE NAME OF THE CURRENT WORKING-DIRECTORY ON THE LOCAL MACHINE (FROM WHERE THE JOB IS
4788       # STARTED) BY SETTING AN ENVIRONMENT-VARIABLE. THIS INFORMATION IS USED IN THE JOB BY MRUN
4789       # IN CASE THAT RESTART-RUNS HAVE TO BE GENERATED
4790    echo  "LOCAL_PWD=$working_directory"                >>  $jobfile
4791    echo  "export LOCAL_PWD"                            >>  $jobfile
4792
4793       # PROVIDE THE PATH OF THE LOCAL MRUN-SCRIPT FOR THE SAME REASON
4794    echo  "LOCAL_MRUN_PATH=$PALM_BIN"                   >>  $jobfile
4795    echo  "export LOCAL_MRUN_PATH"                      >>  $jobfile
4796
4797       # lcflow ALSO REQUIRES TO PROVIDE PATH FOR THE PALM-SCRIPTS
4798    if [[ $host = lcflow  ||  $localhost = lcflow ]]
4799    then
4800       echo  "export PALM_BIN=$PALM_BIN" | sed -e 's:'$HOME':$HOME:'   >>  $jobfile
4801       echo  "export PATH=\$PATH:\$PALM_BIN"              >>  $jobfile
4802    fi
4803
4804       # CALL MRUN WITHIN THE JOB (SETTING QUEUE IS A WORKAROUND FOR ibmkisti)
4805       # AS FINAL ACTION, REMOVE THE TEMPORARY DIRECTORY CREATED AT THE BEGINNING OF THE JOB
4806    echo  "set -x"                                        >>  $jobfile
4807    echo  "queue=$queue"                                  >>  $jobfile
4808    echo  "[[ \$execute_mrun = true ]]  &&  ./$mrun_com"  >>  $jobfile
4809    echo  'ls -al; echo `pwd`'                            >>  $jobfile
4810    echo  "cd \$HOME"                                     >>  $jobfile
4811    echo  "rm -rf  $TEMPDIR"                              >>  $jobfile
4812
4813
4814
4815
4816       # START THE JOB USING SUBJOB-COMMAND
4817    if [[ $silent = false ]]
4818    then
4819       printf "\n     "
4820    else
4821       printf "\n\n"
4822    fi
4823
4824    subjob  $job_on_file  -h $host  -u $remote_username -g $group_number -q $queue  -m $memory  -N $node_usage -t $cpumax  $XOPT  $TOPT  $OOPT  -n $fname  -v  -c $job_catalog  -e $email_notification  $PORTOPT  $jobfile
4825    rm -rf  $jobfile
4826
4827
4828 fi  # END OF REMOTE-PART
Note: See TracBrowser for help on using the repository browser.