source: palm/trunk/SCRIPTS/mrun @ 1402

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

output of location messages complemented, output of location bar added
(Makefile, check_parameters, cpulog, init_pegrid, init_3d_model, message, palm, parin, time_integration, new: progress_bar)
preprocessor switch intel_compiler added, -r8 compiler options removed
(.mrun.config.default, .mrun.config.imuk, .mrun.config.kiaps)

batch_job added to envpar-NAMELIST
(mrun, parin)

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