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 | ################################################################################ |
---|
51 | set +x |
---|
52 | |
---|
53 | if [ "$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 |
---|
85 | fi |
---|
86 | |
---|
87 | # |
---|
88 | # Model names for header file selection |
---|
89 | # |
---|
90 | list_of_PRISM_models="arpege_climat4 echam5 hamocc ham lim lmdz mozart mpi-om oasis3 opa orchidee pisces psmodel toy4opa toyatm toyche toyoce toy4arpege" |
---|
91 | |
---|
92 | valid_model=no |
---|
93 | for spec_model in ${list_of_PRISM_models}; do |
---|
94 | if [ "$1" = "$spec_model" ]; then |
---|
95 | valid_model=yes |
---|
96 | model=$1 |
---|
97 | fi |
---|
98 | done |
---|
99 | if [ "${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 |
---|
103 | fi |
---|
104 | |
---|
105 | # |
---|
106 | # Model version |
---|
107 | # |
---|
108 | if [ "$6" = "" ]; then |
---|
109 | version=D10 |
---|
110 | else |
---|
111 | version=$6 |
---|
112 | echo "* " |
---|
113 | echo "* Compile script for model $model, version=$version is created" |
---|
114 | fi |
---|
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 | # |
---|
120 | if [ "$7" = "" ] || [ "$7" = " " ]; then |
---|
121 | cpl_to=" " |
---|
122 | else |
---|
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 |
---|
141 | fi |
---|
142 | # |
---|
143 | # HOST, OS, node name for header selection |
---|
144 | # |
---|
145 | echo ' ' |
---|
146 | node=`uname -n` |
---|
147 | node1_7=`echo ${node} | cut -c1-7` |
---|
148 | if [ ${node1_7} = platine ]; then node=${node1_7}; fi |
---|
149 | if [ ${node1_7} = mercure ]; then node=${node1_7}; fi |
---|
150 | node1_5=`echo ${node} | cut -c1-5` |
---|
151 | if [ ${node1_5} = zahir ]; then node=${node1_5}; fi |
---|
152 | if [ ${node1_5} = curie ]; then node=${node1_5}; fi |
---|
153 | node1_6=`echo ${node} | cut -c1-6` |
---|
154 | if [ ${node1_6} = vargas ] || [ ${node1_6} = titane ]; then node=${node1_6}; fi |
---|
155 | node1_3=`echo ${node} | cut -c1-3` |
---|
156 | if [ ${node1_3} = ada ]; then node=${node1_3}; fi |
---|
157 | |
---|
158 | build=`uname -s` |
---|
159 | if [ "$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'.' |
---|
167 | else |
---|
168 | echo '* Creating compile script' |
---|
169 | echo ' on/for a '$build ' platform with node name ' $node',' |
---|
170 | echo ' for ' $model'.' |
---|
171 | fi |
---|
172 | |
---|
173 | node1_4=`echo ${node} | cut -c1-4` |
---|
174 | if [ ${node1_4} = xbar ]; then node=${node1_4}; fi |
---|
175 | if [ ${node1_4} = hpca ]; then node=${node1_4}; fi |
---|
176 | |
---|
177 | node1_2=`echo ${node} | cut -c1-2` |
---|
178 | if [ ${node1_2} = ds ]; then node=${node1_2}; fi |
---|
179 | |
---|
180 | node1_6=`echo ${node} | cut -c1-6` |
---|
181 | if [ ${node1_6} = total1 ]; then node=${node1_6}; fi |
---|
182 | |
---|
183 | echo '* Abbreviated node name is ' $node'.' |
---|
184 | |
---|
185 | # |
---|
186 | # Checking consistency of message passing parameter and model |
---|
187 | # |
---|
188 | mespas=irgendwas |
---|
189 | messpass=MPI2 |
---|
190 | if [ "$2" != "" ]; then |
---|
191 | |
---|
192 | if [ "$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 |
---|
215 | else |
---|
216 | echo 'ERROR:This message passing may not be specified:'$2 |
---|
217 | exit 1 |
---|
218 | fi |
---|
219 | |
---|
220 | fi |
---|
221 | echo '* The message passing will be '$messpass'.' |
---|
222 | |
---|
223 | # |
---|
224 | # Redirecting standard output and err output |
---|
225 | # |
---|
226 | outout='stdout=$SCRIPTDIR/COMP_${MODEL_DIR}.log' |
---|
227 | if [ "$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 |
---|
235 | else |
---|
236 | echo '* (g)make standard output will be directed to a file.' |
---|
237 | fi |
---|
238 | errout='stderr=$SCRIPTDIR/COMP_${MODEL_DIR}.err' |
---|
239 | if [ "$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 |
---|
250 | else |
---|
251 | echo '* (g)make standard error will be directed to a file.' |
---|
252 | fi |
---|
253 | |
---|
254 | # |
---|
255 | # Change to directory of script |
---|
256 | # |
---|
257 | |
---|
258 | scriptdir=`dirname $0` |
---|
259 | cd $scriptdir |
---|
260 | |
---|
261 | # /u/fj/mfuj/mfuj004/bin/m4 ; xbar |
---|
262 | |
---|
263 | cat > infile.m4 <<EOF |
---|
264 | #! /bin/ksh |
---|
265 | changequote([{,}])dnl |
---|
266 | changecom |
---|
267 | dnl |
---|
268 | dnl Embedding as batch (not needed on all nodes) |
---|
269 | dnl |
---|
270 | define(comp_Model,comp_${model})dnl |
---|
271 | sinclude(include_${node}/Qsub_start_${node}.h)dnl |
---|
272 | undefine([{comp_Model}])dnl |
---|
273 | |
---|
274 | dnl |
---|
275 | dnl Comments, usage, history |
---|
276 | dnl |
---|
277 | define(comp_Model,${model})dnl |
---|
278 | define(COMP_comp_Model,COMP_${model})dnl |
---|
279 | include(include/Comments_models.h)dnl |
---|
280 | include(include/Comments_models_frm.h)dnl |
---|
281 | undefine([{comp_Model}])dnl |
---|
282 | undefine([{COMP_comp_Model}])dnl |
---|
283 | |
---|
284 | scriptdir=\`dirname \$0\` |
---|
285 | cd \$scriptdir |
---|
286 | export SCRIPTDIR=\`pwd\` |
---|
287 | node=\`uname -n\` |
---|
288 | node1_7=\`echo \${node} | cut -c1-7\` |
---|
289 | if [ \${node1_7} = platine ]; then node=\${node1_7}; fi |
---|
290 | if [ \${node1_7} = mercure ]; then node=\${node1_7}; fi |
---|
291 | node1_5=\`echo \${node} | cut -c1-5\` |
---|
292 | if [ \${node1_5} = zahir ]; then node=\${node1_5}; fi |
---|
293 | if [ \${node1_5} = curie ]; then node=\${node1_5}; fi |
---|
294 | node1_6=\`echo \${node} | cut -c1-6\` |
---|
295 | if [ \${node1_6} = vargas ] || [ \${node1_6} = titane ]; then node=\${node1_6}; fi |
---|
296 | node1_3=\`echo \${node} | cut -c1-3\` |
---|
297 | if [ \${node1_3} = ada ]; then node=\${node1_3}; fi |
---|
298 | |
---|
299 | dnl |
---|
300 | dnl HOST, OS, node name ( <libprolog_oasis3.h>) |
---|
301 | dnl |
---|
302 | include(include/Prolog_all.h)dnl |
---|
303 | include(include/Prolog_models.h)dnl |
---|
304 | export TARFILE=\${MODEL_DIR}_\`date +%y%m%d\`.tar |
---|
305 | |
---|
306 | dnl |
---|
307 | dnl GUI input for all compile scripts |
---|
308 | dnl |
---|
309 | changecom(#) |
---|
310 | define(${mespas},${messpass})dnl |
---|
311 | include(include/Guispecif_all.h)dnl |
---|
312 | undefine([{${mespas}}])dnl |
---|
313 | changecom |
---|
314 | |
---|
315 | dnl |
---|
316 | dnl GUI input for all model compile scripts |
---|
317 | dnl |
---|
318 | changecom(#) |
---|
319 | define(Invalid_model,"${cpl_to}")dnl |
---|
320 | include(include/Guispecif_models.h)dnl |
---|
321 | undefine([{Invalid_model}])dnl |
---|
322 | changecom |
---|
323 | |
---|
324 | dnl |
---|
325 | dnl GUI input depending on model |
---|
326 | dnl |
---|
327 | changecom(#) |
---|
328 | define(_ModVers,_${version})dnl |
---|
329 | include(include/Guispecif_${model}.h)dnl |
---|
330 | undefine([{_ModVers}])dnl |
---|
331 | sinclude(include/Guispecif_${model}_frm.h)dnl |
---|
332 | changecom |
---|
333 | |
---|
334 | dnl |
---|
335 | dnl Command parameter input (scripting only) |
---|
336 | dnl |
---|
337 | include(include/Command_par_models_frm.h)dnl |
---|
338 | include(include/Input_check_all_frm.h)dnl |
---|
339 | |
---|
340 | dnl |
---|
341 | dnl Parameter renaming and printing |
---|
342 | dnl |
---|
343 | include(include/Print_par_all.h)dnl |
---|
344 | include(include/Print_par_models.h)dnl |
---|
345 | include(include/Print_par_${model}.h)dnl |
---|
346 | |
---|
347 | dnl |
---|
348 | dnl Site and OS specifics |
---|
349 | dnl |
---|
350 | include(include_${node}/Sitespecific_${node}.h)dnl |
---|
351 | include(include_${node}/Compile_mode_${model}_${node}.h)dnl |
---|
352 | include(include_${node}/OSspecific_${node}.h)dnl |
---|
353 | |
---|
354 | dnl |
---|
355 | dnl Non Site and OS dependent cpp flags |
---|
356 | dnl |
---|
357 | include(include/Cppflags_${model}.h)dnl |
---|
358 | include(include/Cppflags_edit.h)dnl |
---|
359 | |
---|
360 | dnl |
---|
361 | dnl Name of executabele |
---|
362 | dnl |
---|
363 | include(include/Execname.h)dnl |
---|
364 | |
---|
365 | dnl |
---|
366 | dnl Libraries and directories |
---|
367 | dnl |
---|
368 | include(include/Libraries_${model}.h)dnl |
---|
369 | include(include/Libraries_models.h)dnl |
---|
370 | include(include/Build_dirs_models.h)dnl |
---|
371 | |
---|
372 | dnl |
---|
373 | dnl Check library update status : scripting only |
---|
374 | dnl |
---|
375 | include(include/Check_libs.h)dnl |
---|
376 | |
---|
377 | dnl |
---|
378 | dnl Additional update conditions |
---|
379 | dnl |
---|
380 | sinclude(include/Add_cond_${model}.h)dnl |
---|
381 | |
---|
382 | dnl |
---|
383 | dnl Create top level Makefile |
---|
384 | dnl |
---|
385 | include(include/Top_makefile_all.h)dnl |
---|
386 | define(NodeName,$node)dnl |
---|
387 | include(include/Top_makefile_models.h)dnl |
---|
388 | undefine(NodeName)dnl |
---|
389 | |
---|
390 | define(outdev,${outout})dnl |
---|
391 | outdev |
---|
392 | undefine([{outdev}])dnl |
---|
393 | define(errdev,${errout})dnl |
---|
394 | errdev |
---|
395 | undefine([{errdev}])dnl |
---|
396 | |
---|
397 | if [ -f \$BLDROOT/${model}.status ]; then rm \$BLDROOT/${model}.status; fi |
---|
398 | |
---|
399 | dnl |
---|
400 | dnl Make model |
---|
401 | dnl |
---|
402 | include(include/Make_model.h)dnl |
---|
403 | |
---|
404 | dnl |
---|
405 | dnl Print update status : scripting only |
---|
406 | dnl |
---|
407 | include(include/Status_mods_frm.h)dnl |
---|
408 | |
---|
409 | dnl |
---|
410 | dnl Save/rename the executable |
---|
411 | dnl |
---|
412 | include(include/Save_exec.h)dnl |
---|
413 | |
---|
414 | dnl |
---|
415 | dnl Embedding as batch (not needed on all nodes) |
---|
416 | dnl |
---|
417 | sinclude(include_${node}/Qsub_end_${node}.h)dnl |
---|
418 | exit |
---|
419 | m4exit |
---|
420 | |
---|
421 | EOF |
---|
422 | |
---|
423 | # |
---|
424 | # Run m4. |
---|
425 | # |
---|
426 | |
---|
427 | if [ "$5" = "rhodes" ] ; then |
---|
428 | /usr/freeware/bin/m4 infile.m4 > COMP_${model} |
---|
429 | elif [ "$5" = "zahir" ] ; then |
---|
430 | /usr/local/bin/m4 infile.m4 > COMP_${model} |
---|
431 | elif [ "$5" = "vargas" ] ; then |
---|
432 | /usr/local/pub/M4/m4-1.4.11/bin/m4 infile.m4 > COMP_${model} |
---|
433 | else |
---|
434 | m4 infile.m4 > COMP_${model} |
---|
435 | fi |
---|
436 | |
---|
437 | status=$? |
---|
438 | if [ $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 ' ' |
---|
452 | else |
---|
453 | echo "An error occurred! Status="$status |
---|
454 | echo ' ' |
---|
455 | fi |
---|
456 | cd $olddir |
---|
457 | rm infile.m4 |
---|
458 | |
---|
459 | exit |
---|