source: palm/trunk/SCRIPTS/mrun @ 1468

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

New flag files allow to force unscheduled termination/restarts of batch jobs, progress output is made for batch runs, small adjustments for lxce6 and lccrayh/lccrayb

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