source: CPL/oasis3/trunk/util/compile/frames/Create_COMP_models.frm @ 1991

Last change on this file since 1991 was 1991, checked in by aclsce, 11 years ago

Added ada compilation options for Oasis3.
Added -xHost on Curie (without that crashes...I have to investigate)

File size: 12.8 KB
Line 
1#! /bin/ksh
2################################################################################
3#
4#     Script to generate a component model compile script
5#                                                                       
6#     File       : ~/util/compile/frames/Create_COMP_models.frm
7#
8#     Stephanie Legutke, MPI-HH, M&D          Dec 14, 2004
9#
10#     This script is used to generate a compile script for a PRISM component model.
11#     The script is specifically created for the target platform.
12#     Depending on the node name it selects site and OS specifics.
13#     The node name is either detected with `uname -n` or, if the script is not
14#     created on the target machine, it must be specifieid by the user.
15#     The generated compile script is moved to ~/src/mod/'modelname'
16#     after successful generation.
17#     The script uses m4 for preprocessing. It has been tested with
18#     GNU m4 version 1.4. Other, older or non-GNU versions of m4 may fail!
19#
20#     This script is called interactively only.
21#
22#     7 positional parameters :
23#
24#     Usage : Create_COMP_models.frm \
25#             'model_name'           \
26#             [message_passing [std out [std err [node[version[partner models]]]]]]
27#
28#        $1='model_name'         (required)
29#        $2=""/"MPI1"/"NONE"     message passing
30#        $3=""/"-"               directing std output to a file / the screen
31#        $4=""/"-"/"+"           directing err output to a file / the screen / stdout
32#        $5=""/"'node'"          node name for header files with OS/site specs
33#        $6=""/"'version'"       version acronym for differentiation of executables
34#        $7=""/"partner models"  models of the coupled model constellation
35#
36#     If not called with all parameters, the defaults are:
37#        $2 MPI2
38#        $3 gmake directs stdout to a file
39#        $4 gmake directs stderr to a file
40#        $5 node name `uname -n` of the machine where the script is run
41#        $6 D10
42#        $7 " " (standalone)
43#               
44#
45#     Note: if the model has not yet been ported to a machine (specified by
46#           node name) a message like: infile.m4:53: m4: Cannot open include/...
47#           for some model or machine dependent header file will be given.
48#           These files have to be provided then.
49#           
50################################################################################
51set +x
52
53if [ "$1" = "" ] || [ "$1" = "--" ] || [ "$1" = "help" ] || [ "$1" = "--help" ] ; then
54  echo
55  echo '--------------------------------------------------------------------------'
56  echo ' '
57  echo ' This script may fail if you do not use the right version of m4!'
58  if [ "$5" = "rhodes" ] ; then
59    echo ' The version you use is :' `/usr/freeware/bin/m4 --version`
60  elif [ "$5" = "zahir" ] ; then
61    echo ' The version you use is :' `/usr/local/bin/m4 --version`
62  elif [ "$5" = "vargas" ] ; then
63    echo ' The version you use is :' '`/usr/local/pub/M4/m4-1.4.11/bin/m4 --version`'
64  else
65    echo ' The version you use is :' `m4 --version`
66  fi
67  echo ' Make sure this is GNU m4 younger than version 1.4!'
68  echo ' '
69  echo '--------------------------------------------------------------------------'
70  echo '----------- Usage --------------------------------------------------------'
71  echo ' $1=model name                                                      (none)'
72  echo ' $2=""/"MPI1"/"NONE": message passing                               (MPI2)'
73  echo ' $3=""/"-": std output of compile script -> file / screen           (file)'
74  echo ' $4=""/"-"/"+": err output -> file / the screen / stdout            (file)'
75  echo ' $5=""/"node name": node name of compile server               (`uname -n`)'
76  echo ' $6="version acronym"                                               (none)'
77  echo ' $7="list of participating models"                                  (none)'
78  echo ''
79  echo ' Specification of defaults is not allowed: write e.g.'
80  echo '            Create_COMP_models.frm oasis3 "" - "" ""'
81  echo ' instead of'
82  echo '            Create_COMP_models.frm oasis3 "MPI2" - "" ""'
83  echo '--------------------------------------------------------------------------'
84  exit
85fi
86
87#
88#  Model names for header file selection
89#
90list_of_PRISM_models="arpege_climat4 echam5 hamocc ham lim lmdz mozart mpi-om oasis3 opa orchidee pisces psmodel toy4opa toyatm toyche toyoce toy4arpege"
91
92valid_model=no
93for spec_model in ${list_of_PRISM_models}; do
94  if [ "$1" = "$spec_model"  ]; then
95    valid_model=yes
96    model=$1
97  fi
98done
99if [ "${valid_model}" = "no" ]; then
100  echo ' The model name is not a valid PRISM model: '$1
101  echo ' The script is stopped!'
102  exit 1
103fi
104
105#
106#  Model version
107#
108if [ "$6" = ""  ]; then
109  version=D10
110else
111  version=$6
112  echo "* "
113  echo "* Compile script for model $model, version=$version is created"
114fi
115
116#
117#  If no partner models are specified with cpl_to the standalone version is taken as default.
118#  This may not be possible for al models.
119#
120if [ "$7" = "" ] || [ "$7" = " " ]; then
121  cpl_to=" "
122else
123  for model1 in $7; do
124    valid_model=no
125    for model2 in ${list_of_PRISM_models}; do
126      if [ "$model1" = "$model2"  ]; then
127        valid_model=yes
128      fi
129    done
130    if [ "${valid_model}" = "no" ]; then
131      echo ' One of the models names is not a valid PRISM model: ' $model1
132      echo ' The script is stopped!'
133      exit 1
134    fi
135  done
136  if [ "${valid_model}" = "yes" ]; then
137      cpl_to=$7
138      echo "* "
139      echo "* Partner component models are: ${cpl_to}"
140  fi
141fi
142#
143#  HOST, OS, node name for header selection
144#
145echo ' '
146node=`uname -n`
147node1_7=`echo ${node} | cut -c1-7`
148if [ ${node1_7} = platine ]; then node=${node1_7}; fi
149if [ ${node1_7} = mercure ]; then node=${node1_7}; fi
150node1_5=`echo ${node} | cut -c1-5`
151if [ ${node1_5} = zahir ]; then node=${node1_5}; fi
152if [ ${node1_5} = curie ]; then node=${node1_5}; fi
153node1_6=`echo ${node} | cut -c1-6`
154if [ ${node1_6} = vargas ] || [ ${node1_6} = titane ]; then node=${node1_6}; fi
155node1_3=`echo ${node} | cut -c1-3`
156if [ ${node1_3} = ada ]; then node=${node1_3}; fi
157
158build=`uname -s`
159if [ "$5" != "" ] && [ "$5" != $node ]; then
160    echo ' '
161    echo Warning: the node specified is not the node of this machine.
162    echo Ensure that the site/OS specific header files exist.
163    node=$5
164    build=""
165    echo '* Creating compile script'
166    echo '           for ' $model'.'
167else
168  echo '* Creating compile script'
169  echo '           on/for a '$build ' platform with node name ' $node','
170  echo '           for ' $model'.'
171fi
172
173node1_4=`echo ${node} | cut -c1-4`
174if [ ${node1_4} = xbar ]; then node=${node1_4}; fi
175if [ ${node1_4} = hpca ]; then node=${node1_4}; fi
176
177node1_2=`echo ${node} | cut -c1-2`
178if [ ${node1_2} = ds ]; then node=${node1_2}; fi
179
180node1_6=`echo ${node} | cut -c1-6`
181if [ ${node1_6} = total1 ]; then node=${node1_6}; fi
182
183echo '* Abbreviated node name is ' $node'.'
184
185#
186# Checking consistency of message passing parameter and model
187#
188mespas=irgendwas
189messpass=MPI2
190if [ "$2" != "" ];  then
191
192if [ "$2" = "MPI1" ] || [ "$2" = "NONE" ]; then
193  if [ "$2" = "MPI1" ] ; then
194    if [ "$model"  = "echam5" ] ||
195       [ "$model"  = "mpi-om" ] ||
196       [ "$model"  = "hamocc" ] ||
197       [ "$model"  = "pisces" ] ||
198       [ "$model"  = "psoce"  ]    ; then
199       echo 'MPI1 for '$model' is not possible.'
200       exit 1
201     else
202       messpass=$2
203       mespas=MPI2   
204     fi
205  fi
206  if [ "$2" = "NONE" ] ; then
207    if [ "$model"  = ""       ]    ; then
208       echo 'NONE for '$model' is not possible.'
209       exit 1
210     else
211       messpass=$2
212       mespas=MPI2   
213     fi
214  fi
215else
216  echo 'ERROR:This message passing may not be specified:'$2
217  exit 1
218fi
219
220fi
221echo '* The message passing will be '$messpass'.'
222
223#
224# Redirecting standard output and err output
225#
226outout='stdout=$SCRIPTDIR/COMP_${MODEL_DIR}.log'
227if [ "$3" != "" ]; then
228  if [ "$3" = "-" ]; then
229    outout='stdout=`tty`'
230    echo '* (g)make standard output will directed to screen.'
231  else
232    echo 'This values is not allowed for parameter 3 (std out)'
233    exit
234  fi
235else
236  echo '* (g)make standard output will be directed to a file.'
237fi
238errout='stderr=$SCRIPTDIR/COMP_${MODEL_DIR}.err'
239if [ "$4" != "" ]; then
240  if [ "$4" = "-" ]; then
241    echo '* (g)make standard error will directed to screen.'
242    errout='stderr=`tty`'
243  elif [ "$4" = "+" ]; then
244    echo '* (g)make standard error will directed to stdout.'
245    errout='stderr="$stdout"'
246  else
247    echo 'This values is not allowed for parameter 4 (std err)'
248    exit
249  fi
250else
251  echo '* (g)make standard error will be directed to a file.'
252fi
253
254#
255#  Change to directory of script
256#
257
258scriptdir=`dirname $0`
259cd $scriptdir
260
261# /u/fj/mfuj/mfuj004/bin/m4  ; xbar
262
263cat > infile.m4 <<EOF
264#! /bin/ksh
265changequote([{,}])dnl
266changecom
267dnl
268dnl  Embedding as batch  (not needed on all nodes)
269dnl
270define(comp_Model,comp_${model})dnl
271sinclude(include_${node}/Qsub_start_${node}.h)dnl
272undefine([{comp_Model}])dnl
273
274dnl
275dnl  Comments, usage, history
276dnl
277define(comp_Model,${model})dnl
278define(COMP_comp_Model,COMP_${model})dnl
279include(include/Comments_models.h)dnl
280include(include/Comments_models_frm.h)dnl
281undefine([{comp_Model}])dnl
282undefine([{COMP_comp_Model}])dnl
283
284scriptdir=\`dirname \$0\`
285cd \$scriptdir
286export SCRIPTDIR=\`pwd\`
287node=\`uname -n\`
288node1_7=\`echo \${node} | cut -c1-7\`
289if [ \${node1_7} = platine ]; then node=\${node1_7}; fi
290if [ \${node1_7} = mercure ]; then node=\${node1_7}; fi
291node1_5=\`echo \${node} | cut -c1-5\`
292if [ \${node1_5} = zahir ]; then node=\${node1_5}; fi
293if [ \${node1_5} = curie ]; then node=\${node1_5}; fi
294node1_6=\`echo \${node} | cut -c1-6\`
295if [ \${node1_6} = vargas ] || [ \${node1_6} = titane ]; then node=\${node1_6}; fi
296node1_3=\`echo \${node} | cut -c1-3\`
297if [ \${node1_3} = ada ]; then node=\${node1_3}; fi
298
299dnl
300dnl  HOST, OS, node name ( <libprolog_oasis3.h>)
301dnl
302include(include/Prolog_all.h)dnl
303include(include/Prolog_models.h)dnl
304export TARFILE=\${MODEL_DIR}_\`date +%y%m%d\`.tar
305
306dnl
307dnl  GUI input for all compile scripts
308dnl
309changecom(#)
310define(${mespas},${messpass})dnl
311include(include/Guispecif_all.h)dnl
312undefine([{${mespas}}])dnl
313changecom
314
315dnl
316dnl  GUI input for all model compile scripts
317dnl
318changecom(#)
319define(Invalid_model,"${cpl_to}")dnl
320include(include/Guispecif_models.h)dnl
321undefine([{Invalid_model}])dnl
322changecom
323
324dnl
325dnl  GUI input depending on model
326dnl
327changecom(#)
328define(_ModVers,_${version})dnl
329include(include/Guispecif_${model}.h)dnl
330undefine([{_ModVers}])dnl
331sinclude(include/Guispecif_${model}_frm.h)dnl
332changecom
333
334dnl
335dnl  Command parameter input (scripting only)
336dnl
337include(include/Command_par_models_frm.h)dnl
338include(include/Input_check_all_frm.h)dnl
339
340dnl
341dnl  Parameter renaming and printing
342dnl
343include(include/Print_par_all.h)dnl
344include(include/Print_par_models.h)dnl
345include(include/Print_par_${model}.h)dnl
346
347dnl
348dnl  Site and OS specifics
349dnl
350include(include_${node}/Sitespecific_${node}.h)dnl
351include(include_${node}/Compile_mode_${model}_${node}.h)dnl
352include(include_${node}/OSspecific_${node}.h)dnl
353
354dnl
355dnl  Non Site and OS dependent cpp flags
356dnl
357include(include/Cppflags_${model}.h)dnl
358include(include/Cppflags_edit.h)dnl
359
360dnl
361dnl  Name of executabele
362dnl
363include(include/Execname.h)dnl
364
365dnl
366dnl  Libraries and directories
367dnl
368include(include/Libraries_${model}.h)dnl
369include(include/Libraries_models.h)dnl
370include(include/Build_dirs_models.h)dnl
371
372dnl
373dnl  Check library update status : scripting only
374dnl
375include(include/Check_libs.h)dnl
376
377dnl
378dnl  Additional update conditions
379dnl
380sinclude(include/Add_cond_${model}.h)dnl
381
382dnl
383dnl  Create top level Makefile
384dnl
385include(include/Top_makefile_all.h)dnl
386define(NodeName,$node)dnl
387include(include/Top_makefile_models.h)dnl
388undefine(NodeName)dnl
389
390define(outdev,${outout})dnl
391outdev
392undefine([{outdev}])dnl
393define(errdev,${errout})dnl
394errdev
395undefine([{errdev}])dnl
396
397if [ -f \$BLDROOT/${model}.status ]; then rm \$BLDROOT/${model}.status; fi
398
399dnl
400dnl  Make model
401dnl
402include(include/Make_model.h)dnl
403
404dnl
405dnl  Print update status : scripting only
406dnl
407include(include/Status_mods_frm.h)dnl
408
409dnl
410dnl  Save/rename the executable
411dnl
412include(include/Save_exec.h)dnl
413
414dnl
415dnl  Embedding as batch  (not needed on all nodes)
416dnl
417sinclude(include_${node}/Qsub_end_${node}.h)dnl
418exit
419m4exit
420
421EOF
422
423#
424# Run m4.
425#
426
427if [ "$5" = "rhodes" ] ; then
428  /usr/freeware/bin/m4 infile.m4 > COMP_${model}
429elif [ "$5" = "zahir" ] ; then
430  /usr/local/bin/m4 infile.m4 > COMP_${model}
431elif [ "$5" = "vargas" ] ; then
432  /usr/local/pub/M4/m4-1.4.11/bin/m4 infile.m4 > COMP_${model}
433else
434  m4 infile.m4 > COMP_${model}
435fi 
436
437status=$?
438if [ $status -eq 0 ]; then
439  if [ ! ${model} = "oasis3" ]; then
440    Compile_script=COMP_${model}_$6.${node}
441  else
442    Compile_script=COMP_${model}_${messpass}.${node}
443  fi
444  mv COMP_${model} ../../../src/mod/${model}/${Compile_script}
445  chmod 755 ../../../src/mod/${model}/${Compile_script}
446  olddir=`pwd`
447  cd ../../../src/mod/${model}
448  moddir=`pwd`
449  echo "* The model directory is " $moddir
450  echo "* The compile script name is "$moddir/${Compile_script}
451  echo ' '
452else
453  echo "An error occurred! Status="$status
454  echo ' '
455fi
456cd $olddir
457rm infile.m4
458
459exit
Note: See TracBrowser for help on using the repository browser.