source: palm/trunk/SCRIPTS/mrun @ 1443

Last change on this file since 1443 was 1443, checked in by raasch, 10 years ago

last commit documented

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