source: palm/trunk/SCRIPTS/mrun @ 1421

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

last commit documented

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