source: palm/trunk/SCRIPTS/mrun @ 1310

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

update of GPL copyright

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