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

Last change on this file since 1677 was 1677, checked in by aclsce, 10 years ago

Imported oasis3 (tag ipslcm5a) from cvs server to svn server (igcmg project).

File size: 12.7 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
155
156build=`uname -s`
157if [ "$5" != "" ] && [ "$5" != $node ]; then
158    echo ' '
159    echo Warning: the node specified is not the node of this machine.
160    echo Ensure that the site/OS specific header files exist.
161    node=$5
162    build=""
163    echo '* Creating compile script'
164    echo '           for ' $model'.'
165else
166  echo '* Creating compile script'
167  echo '           on/for a '$build ' platform with node name ' $node','
168  echo '           for ' $model'.'
169fi
170
171node1_4=`echo ${node} | cut -c1-4`
172if [ ${node1_4} = xbar ]; then node=${node1_4}; fi
173if [ ${node1_4} = hpca ]; then node=${node1_4}; fi
174
175node1_2=`echo ${node} | cut -c1-2`
176if [ ${node1_2} = ds ]; then node=${node1_2}; fi
177
178node1_6=`echo ${node} | cut -c1-6`
179if [ ${node1_6} = total1 ]; then node=${node1_6}; fi
180
181echo '* Abbreviated node name is ' $node'.'
182
183#
184# Checking consistency of message passing parameter and model
185#
186mespas=irgendwas
187messpass=MPI2
188if [ "$2" != "" ];  then
189
190if [ "$2" = "MPI1" ] || [ "$2" = "NONE" ]; then
191  if [ "$2" = "MPI1" ] ; then
192    if [ "$model"  = "echam5" ] ||
193       [ "$model"  = "mpi-om" ] ||
194       [ "$model"  = "hamocc" ] ||
195       [ "$model"  = "pisces" ] ||
196       [ "$model"  = "psoce"  ]    ; then
197       echo 'MPI1 for '$model' is not possible.'
198       exit 1
199     else
200       messpass=$2
201       mespas=MPI2   
202     fi
203  fi
204  if [ "$2" = "NONE" ] ; then
205    if [ "$model"  = ""       ]    ; then
206       echo 'NONE for '$model' is not possible.'
207       exit 1
208     else
209       messpass=$2
210       mespas=MPI2   
211     fi
212  fi
213else
214  echo 'ERROR:This message passing may not be specified:'$2
215  exit 1
216fi
217
218fi
219echo '* The message passing will be '$messpass'.'
220
221#
222# Redirecting standard output and err output
223#
224outout='stdout=$SCRIPTDIR/COMP_${MODEL_DIR}.log'
225if [ "$3" != "" ]; then
226  if [ "$3" = "-" ]; then
227    outout='stdout=`tty`'
228    echo '* (g)make standard output will directed to screen.'
229  else
230    echo 'This values is not allowed for parameter 3 (std out)'
231    exit
232  fi
233else
234  echo '* (g)make standard output will be directed to a file.'
235fi
236errout='stderr=$SCRIPTDIR/COMP_${MODEL_DIR}.err'
237if [ "$4" != "" ]; then
238  if [ "$4" = "-" ]; then
239    echo '* (g)make standard error will directed to screen.'
240    errout='stderr=`tty`'
241  elif [ "$4" = "+" ]; then
242    echo '* (g)make standard error will directed to stdout.'
243    errout='stderr="$stdout"'
244  else
245    echo 'This values is not allowed for parameter 4 (std err)'
246    exit
247  fi
248else
249  echo '* (g)make standard error will be directed to a file.'
250fi
251
252#
253#  Change to directory of script
254#
255
256scriptdir=`dirname $0`
257cd $scriptdir
258
259# /u/fj/mfuj/mfuj004/bin/m4  ; xbar
260
261cat > infile.m4 <<EOF
262#! /bin/ksh
263changequote([{,}])dnl
264changecom
265dnl
266dnl  Embedding as batch  (not needed on all nodes)
267dnl
268define(comp_Model,comp_${model})dnl
269sinclude(include_${node}/Qsub_start_${node}.h)dnl
270undefine([{comp_Model}])dnl
271
272dnl
273dnl  Comments, usage, history
274dnl
275define(comp_Model,${model})dnl
276define(COMP_comp_Model,COMP_${model})dnl
277include(include/Comments_models.h)dnl
278include(include/Comments_models_frm.h)dnl
279undefine([{comp_Model}])dnl
280undefine([{COMP_comp_Model}])dnl
281
282scriptdir=\`dirname \$0\`
283cd \$scriptdir
284export SCRIPTDIR=\`pwd\`
285node=\`uname -n\`
286node1_7=\`echo \${node} | cut -c1-7\`
287if [ \${node1_7} = platine ]; then node=\${node1_7}; fi
288if [ \${node1_7} = mercure ]; then node=\${node1_7}; fi
289node1_5=\`echo \${node} | cut -c1-5\`
290if [ \${node1_5} = zahir ]; then node=\${node1_5}; fi
291if [ \${node1_5} = curie ]; then node=\${node1_5}; fi
292node1_6=\`echo \${node} | cut -c1-6\`
293if [ \${node1_6} = vargas ] || [ \${node1_6} = titane ]; then node=\${node1_6}; fi
294
295dnl
296dnl  HOST, OS, node name ( <libprolog_oasis3.h>)
297dnl
298include(include/Prolog_all.h)dnl
299include(include/Prolog_models.h)dnl
300export TARFILE=\${MODEL_DIR}_\`date +%y%m%d\`.tar
301
302dnl
303dnl  GUI input for all compile scripts
304dnl
305changecom(#)
306define(${mespas},${messpass})dnl
307include(include/Guispecif_all.h)dnl
308undefine([{${mespas}}])dnl
309changecom
310
311dnl
312dnl  GUI input for all model compile scripts
313dnl
314changecom(#)
315define(Invalid_model,"${cpl_to}")dnl
316include(include/Guispecif_models.h)dnl
317undefine([{Invalid_model}])dnl
318changecom
319
320dnl
321dnl  GUI input depending on model
322dnl
323changecom(#)
324define(_ModVers,_${version})dnl
325include(include/Guispecif_${model}.h)dnl
326undefine([{_ModVers}])dnl
327sinclude(include/Guispecif_${model}_frm.h)dnl
328changecom
329
330dnl
331dnl  Command parameter input (scripting only)
332dnl
333include(include/Command_par_models_frm.h)dnl
334include(include/Input_check_all_frm.h)dnl
335
336dnl
337dnl  Parameter renaming and printing
338dnl
339include(include/Print_par_all.h)dnl
340include(include/Print_par_models.h)dnl
341include(include/Print_par_${model}.h)dnl
342
343dnl
344dnl  Site and OS specifics
345dnl
346include(include_${node}/Sitespecific_${node}.h)dnl
347include(include_${node}/Compile_mode_${model}_${node}.h)dnl
348include(include_${node}/OSspecific_${node}.h)dnl
349
350dnl
351dnl  Non Site and OS dependent cpp flags
352dnl
353include(include/Cppflags_${model}.h)dnl
354include(include/Cppflags_edit.h)dnl
355
356dnl
357dnl  Name of executabele
358dnl
359include(include/Execname.h)dnl
360
361dnl
362dnl  Libraries and directories
363dnl
364include(include/Libraries_${model}.h)dnl
365include(include/Libraries_models.h)dnl
366include(include/Build_dirs_models.h)dnl
367
368dnl
369dnl  Check library update status : scripting only
370dnl
371include(include/Check_libs.h)dnl
372
373dnl
374dnl  Additional update conditions
375dnl
376sinclude(include/Add_cond_${model}.h)dnl
377
378dnl
379dnl  Create top level Makefile
380dnl
381include(include/Top_makefile_all.h)dnl
382define(NodeName,$node)dnl
383include(include/Top_makefile_models.h)dnl
384undefine(NodeName)dnl
385
386define(outdev,${outout})dnl
387outdev
388undefine([{outdev}])dnl
389define(errdev,${errout})dnl
390errdev
391undefine([{errdev}])dnl
392
393if [ -f \$BLDROOT/${model}.status ]; then rm \$BLDROOT/${model}.status; fi
394
395dnl
396dnl  Make model
397dnl
398include(include/Make_model.h)dnl
399
400dnl
401dnl  Print update status : scripting only
402dnl
403include(include/Status_mods_frm.h)dnl
404
405dnl
406dnl  Save/rename the executable
407dnl
408include(include/Save_exec.h)dnl
409
410dnl
411dnl  Embedding as batch  (not needed on all nodes)
412dnl
413sinclude(include_${node}/Qsub_end_${node}.h)dnl
414exit
415m4exit
416
417EOF
418
419#
420# Run m4.
421#
422
423if [ "$5" = "rhodes" ] ; then
424  /usr/freeware/bin/m4 infile.m4 > COMP_${model}
425elif [ "$5" = "zahir" ] ; then
426  /usr/local/bin/m4 infile.m4 > COMP_${model}
427elif [ "$5" = "vargas" ] ; then
428  /usr/local/pub/M4/m4-1.4.11/bin/m4 infile.m4 > COMP_${model}
429else
430  m4 infile.m4 > COMP_${model}
431fi 
432
433status=$?
434if [ $status -eq 0 ]; then
435  if [ ! ${model} = "oasis3" ]; then
436    Compile_script=COMP_${model}_$6.${node}
437  else
438    Compile_script=COMP_${model}_${messpass}.${node}
439  fi
440  mv COMP_${model} ../../../src/mod/${model}/${Compile_script}
441  chmod 755 ../../../src/mod/${model}/${Compile_script}
442  olddir=`pwd`
443  cd ../../../src/mod/${model}
444  moddir=`pwd`
445  echo "* The model directory is " $moddir
446  echo "* The compile script name is "$moddir/${Compile_script}
447  echo ' '
448else
449  echo "An error occurred! Status="$status
450  echo ' '
451fi
452cd $olddir
453rm infile.m4
454
455exit
Note: See TracBrowser for help on using the repository browser.