source: palm/trunk/SCRIPTS/mrun @ 1289

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

script comments translated to English
version update to 3.10

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