1 | #!/bin/bash |
---|
2 | # |
---|
3 | # $Id$ |
---|
4 | # |
---|
5 | # |
---|
6 | ######################################################################## |
---|
7 | # for debug, uncomment line below |
---|
8 | #set -xv |
---|
9 | ######################################################################## |
---|
10 | # options par defaut pour la commande make |
---|
11 | ######################################################################## |
---|
12 | dim="96x72x19" |
---|
13 | physique=lmd |
---|
14 | code=gcm |
---|
15 | filtre=filtrez |
---|
16 | grille=reg |
---|
17 | couple=false |
---|
18 | veget=false |
---|
19 | chimie=false |
---|
20 | parallel=none |
---|
21 | paramem="mem" |
---|
22 | compil_mod=prod |
---|
23 | io=ioipsl |
---|
24 | LIBPREFIX="" |
---|
25 | fcm_path=none |
---|
26 | cosp=false |
---|
27 | cosp2=false |
---|
28 | cospv2=false |
---|
29 | inlandsis=false |
---|
30 | rrtm=false |
---|
31 | rad="" |
---|
32 | dust=false |
---|
33 | strataer=false |
---|
34 | full="" |
---|
35 | |
---|
36 | arch_defined="FALSE" |
---|
37 | arch_path="arch" |
---|
38 | arch_default_path="arch" |
---|
39 | |
---|
40 | # guess a default 'arch' |
---|
41 | arch="local" # start with assuming we're on a local machine with local arch file |
---|
42 | arch_defined="TRUE" # and thus also set arch_defined to true |
---|
43 | ## try to recognise machine and infer arch from it |
---|
44 | machine=`hostname` |
---|
45 | if [[ "${machine:0:4}" == "jean" ]] |
---|
46 | then |
---|
47 | arch="X64_JEANZAY" |
---|
48 | fi |
---|
49 | if [[ "${machine:0:7}" == "platine" ]] |
---|
50 | then |
---|
51 | arch="IA64_PLATINE" |
---|
52 | fi |
---|
53 | if [[ "${machine:0:6}" == "titane" ]] |
---|
54 | then |
---|
55 | arch="X64_TITANE" |
---|
56 | fi |
---|
57 | if [[ "${machine:0:8}" == "mercure1" ]] |
---|
58 | then |
---|
59 | arch="SX8_MERCURE" |
---|
60 | fi |
---|
61 | if [[ "${machine:0:8}" == "mercure2" ]] |
---|
62 | then |
---|
63 | arch="SX9_MERCURE" |
---|
64 | fi |
---|
65 | |
---|
66 | LMDGCM=`pwd -P` |
---|
67 | LIBFGCM=$LMDGCM/libf |
---|
68 | LIBOGCM=$LMDGCM/libo |
---|
69 | if [[ ! -d $LIBOGCM ]] |
---|
70 | then |
---|
71 | # create the directory |
---|
72 | mkdir $LIBOGCM |
---|
73 | if [[ ! $? ]] |
---|
74 | then |
---|
75 | echo "Failed to create directory $LIBOGCM" |
---|
76 | exit |
---|
77 | fi |
---|
78 | fi |
---|
79 | #COSP_PATH=$LMDGCM/.void_dir |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | localdir=`pwd -P` |
---|
84 | ######################################################################## |
---|
85 | # Quelques initialisations de variables du shell. |
---|
86 | ######################################################################## |
---|
87 | |
---|
88 | CPP_KEY="IN_LMDZ" |
---|
89 | INCLUDE='-I$(LIBF)/grid -I$(LIBF)/misc -I$(LIBF)/filtrez -I. ' |
---|
90 | LIB="" |
---|
91 | adjnt="" |
---|
92 | ##COMPIL_FFLAGS="%PROD_FFLAGS" |
---|
93 | PARA_FFLAGS="" |
---|
94 | PARA_LD="" |
---|
95 | EXT_SRC="" |
---|
96 | #src_dirs: directories containing source files |
---|
97 | src_dirs="grid misc" |
---|
98 | ######################################################################## |
---|
99 | # lecture des options |
---|
100 | ######################################################################## |
---|
101 | |
---|
102 | while (($# > 0)) |
---|
103 | do |
---|
104 | case $1 in |
---|
105 | "-h") cat <<fin |
---|
106 | Usage : |
---|
107 | makelmdz [options] -arch nom_arch exec |
---|
108 | [-h] : brief help |
---|
109 | [-d [[IMx]JMx]LM] : IM, JM, LM are the dimensions in x, y, z (default: $dim) |
---|
110 | [-p PHYS] : set of physical parametrizations (in libf/phyPHYS), (default: lmd) |
---|
111 | [-prod / -dev / -debug] : compilation mode production (default) / developement / debug |
---|
112 | [-c false/MPI1/MPI2] : coupling with ocean model : MPI1/MPI2/false (default: false) |
---|
113 | [-v false/orchideetrunk/orchidee2.1/orchidee2.0/orchidee1.9] : version of the vegetation model to include (default: false) |
---|
114 | false : no vegetation model |
---|
115 | orchideetrunk : compile using ORCHIDEE trunk from revision 7757 or higher |
---|
116 | orchidee2.1 : compile using ORCHIDEE 2.1 until 4.1 included or until revision 7757 on the trunk |
---|
117 | orchidee2.0 : compile using ORCHIDEE 2.0 (or more recent version) |
---|
118 | orchidee1.9 : compile using ORCHIDEE up to the version including OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6 |
---|
119 | true : (obsolete; for backward compatibility) use ORCHIDEE tag 1.9-1.9.6 |
---|
120 | [-chimie INCA/false] : with INCA chemistry model or without (default: false) |
---|
121 | [-cosp true/false] : compile with/without cosp package (default: false) |
---|
122 | [-cosp2 true/false] : compile with/without cosp2 package (default: false) |
---|
123 | [-cospv2 true/false] : compile with/without cospv2 package (default: false) |
---|
124 | [-inlandsis true/false] : compile with/without inlandsis package (default: false) |
---|
125 | [-rrtm true/false] : compile with/without rrtm package (default: false) |
---|
126 | [-rad oldrad/rrtm/ecrad] : compile with oldrad/rrtm/ecrad radiatif code (default: oldrad) |
---|
127 | [-dust true/false] : compile with/without the dust package from Boucher et al. (default: false) |
---|
128 | [-strataer true/false] : compile with/without the strat aer package from Boucher et al. (default: false) |
---|
129 | [-parallel none/mpi/omp/mpi_omp] : parallelism (default: none) : mpi, openmp or mixted mpi_openmp |
---|
130 | [-g GRI] : grid configuration in dyn3d/GRI_xy.h (default: reg, inclues a zoom) |
---|
131 | [-io ioipsl/mix/xios] : Input/Output library (default: ioipsl) |
---|
132 | [-include INCLUDES] : extra include path to add |
---|
133 | [-cpp CPP_KEY] : additional preprocessing definitions |
---|
134 | [-adjnt] : adjoint model, not operational ... |
---|
135 | [-mem] : reduced memory dynamics (obsolete flag; always on in parallel mode) |
---|
136 | [-filtre NOMFILTRE] : use filtre from libf/NOMFILTRE (default: filtrez) |
---|
137 | [-full] : Full (re)compilation (from scratch) |
---|
138 | [-link LINKS] : additional links with other libraries |
---|
139 | [-fcm_path path] : path to the fcm tool (default: tools/fcm/bin) |
---|
140 | [-ext_src path] : path to an additional set of routines to compile with the model |
---|
141 | [-arch_path path] : path to architecture files (default: $arch_default_path) |
---|
142 | -arch nom_arch : target architecture |
---|
143 | exec : executable to build |
---|
144 | fin |
---|
145 | exit;; |
---|
146 | "-d") |
---|
147 | dim=$2 ; shift ; shift ;; |
---|
148 | |
---|
149 | "-p") |
---|
150 | physique="$2" ; shift ; shift ;; |
---|
151 | |
---|
152 | "-g") |
---|
153 | grille="$2" ; shift ; shift ;; |
---|
154 | |
---|
155 | "-c") |
---|
156 | couple="$2" ; shift ; shift ;; |
---|
157 | |
---|
158 | "-prod") |
---|
159 | compil_mod="prod" ; shift ;; |
---|
160 | |
---|
161 | "-dev") |
---|
162 | compil_mod="dev" ; shift ;; |
---|
163 | |
---|
164 | "-debug") |
---|
165 | compil_mod="debug" ; shift ;; |
---|
166 | |
---|
167 | "-io") |
---|
168 | io="$2" ; shift ; shift ;; |
---|
169 | |
---|
170 | "-v") |
---|
171 | veget="$2" ; shift ; shift ;; |
---|
172 | |
---|
173 | "-chimie") |
---|
174 | chimie="$2" ; shift ; shift ;; |
---|
175 | |
---|
176 | "-parallel") |
---|
177 | parallel="$2" ; shift ; shift ;; |
---|
178 | |
---|
179 | "-include") |
---|
180 | INCLUDE="$INCLUDE -I$2" ; shift ; shift ;; |
---|
181 | |
---|
182 | "-cpp") |
---|
183 | CPP_KEY="$CPP_KEY $2" ; shift ; shift ;; |
---|
184 | |
---|
185 | "-cosp") |
---|
186 | cosp="$2" ; shift ; shift ;; |
---|
187 | |
---|
188 | "-cosp2") |
---|
189 | cosp2="$2" ; shift ; shift ;; |
---|
190 | |
---|
191 | "-cosp2") |
---|
192 | cospv2="$2" ; shift ; shift ;; |
---|
193 | |
---|
194 | "-inlandsis") |
---|
195 | inlandsis="$2" ; shift ; shift ;; |
---|
196 | |
---|
197 | "-rrtm") |
---|
198 | rrtm="$2" ; if [ "$2" = "false" ] ; then rad="oldrad" ; else rad="rrtm" ; fi ; shift ; shift ;; |
---|
199 | |
---|
200 | "-rad") |
---|
201 | rad="$2" ; shift ; shift ;; |
---|
202 | |
---|
203 | "-dust") |
---|
204 | dust="$2" ; shift ; shift ;; |
---|
205 | |
---|
206 | "-strataer") |
---|
207 | strataer="$2" ; shift ; shift ;; |
---|
208 | |
---|
209 | "-mem") |
---|
210 | echo "option -mem is obsolete (now always on in parallel)" |
---|
211 | paramem="mem" ; shift ;; |
---|
212 | |
---|
213 | "-filtre") |
---|
214 | filtre=$2 ; shift ; shift ;; |
---|
215 | |
---|
216 | "-full") |
---|
217 | full="full" ; shift ;; |
---|
218 | |
---|
219 | "-link") |
---|
220 | LIB="$LIB $2" ; shift ; shift ;; |
---|
221 | |
---|
222 | "-fcm_path") |
---|
223 | fcm_path=$2 ; shift ; shift ;; |
---|
224 | |
---|
225 | "-ext_src") |
---|
226 | EXT_SRC=$2 ; src_dirs="$src_dirs $EXT_SRC" ; shift ; shift ;; |
---|
227 | |
---|
228 | "-arch") |
---|
229 | arch=$2 ; arch_defined="TRUE" ; shift ; shift ;; |
---|
230 | |
---|
231 | "-arch_path") |
---|
232 | arch_path=$2 ; arch_path_defined="TRUE"; shift ; shift ;; |
---|
233 | |
---|
234 | *) |
---|
235 | code="$1" ; shift ;; |
---|
236 | esac |
---|
237 | done |
---|
238 | |
---|
239 | ############################################################### |
---|
240 | # lecture des chemins propres \`a l'architecture de la machine # |
---|
241 | ############################################################### |
---|
242 | rm -f .void_file |
---|
243 | echo > .void_file |
---|
244 | rm -rf .void_dir |
---|
245 | mkdir .void_dir |
---|
246 | |
---|
247 | if [[ "$arch_defined" == "TRUE" ]] |
---|
248 | then |
---|
249 | rm -f arch.path |
---|
250 | rm -f arch.fcm |
---|
251 | rm -f arch.env |
---|
252 | |
---|
253 | if test -f $arch_path/arch-${arch}.path |
---|
254 | then |
---|
255 | ln -s $arch_path/arch-${arch}.path arch.path |
---|
256 | elif test -f $arch_default_path/arch-${arch}.path |
---|
257 | then |
---|
258 | ln -s $arch_default_path/arch-${arch}.path arch.path |
---|
259 | fi |
---|
260 | |
---|
261 | if test -f $arch_path/arch-${arch}.fcm |
---|
262 | then |
---|
263 | ln -s $arch_path/arch-${arch}.fcm arch.fcm |
---|
264 | elif test -f $arch_default_path/arch-${arch}.fcm |
---|
265 | then |
---|
266 | ln -s $arch_default_path/arch-${arch}.fcm arch.fcm |
---|
267 | fi |
---|
268 | |
---|
269 | if test -f $arch_path/arch-${arch}.env |
---|
270 | then |
---|
271 | ln -s $arch_path/arch-${arch}.env arch.env |
---|
272 | elif test -f $arch_default_path/arch-${arch}.env |
---|
273 | then |
---|
274 | ln -s $arch_default_path/arch-${arch}.env arch.env |
---|
275 | else |
---|
276 | ln -s .void_file arch.env |
---|
277 | fi |
---|
278 | # source architecture PATH and ENV files |
---|
279 | source arch.env |
---|
280 | source arch.path |
---|
281 | else |
---|
282 | echo "You must define a target architecture" |
---|
283 | exit 1 |
---|
284 | fi |
---|
285 | |
---|
286 | ######################################################################## |
---|
287 | # Definition des clefs CPP, des chemins des includes et modules |
---|
288 | # et des libraries |
---|
289 | ######################################################################## |
---|
290 | |
---|
291 | # basic compile flags from arch.fcm file |
---|
292 | archfileline=$( grep -i '^%BASE_FFLAGS' arch.fcm ) |
---|
293 | COMPIL_FFLAGS=$( echo ${archfileline##%BASE_FFLAGS} ) |
---|
294 | |
---|
295 | # other compile flags, depending on compilation mode |
---|
296 | if [[ "$compil_mod" == "prod" ]] |
---|
297 | then |
---|
298 | ## read COMPIL_FFLAGS from arch.fcm file |
---|
299 | archfileline=$( grep -i '^%PROD_FFLAGS' arch.fcm ) |
---|
300 | archfileopt=$( echo ${archfileline##%PROD_FFLAGS} ) |
---|
301 | COMPIL_FFLAGS="${COMPIL_FFLAGS} ${archfileopt}" |
---|
302 | elif [[ "$compil_mod" == "dev" ]] |
---|
303 | then |
---|
304 | ## read %DEV_FFLAGS from arch.fcm file |
---|
305 | archfileline=$( grep -i '^%DEV_FFLAGS' arch.fcm ) |
---|
306 | archfileopt=$( echo ${archfileline##%DEV_FFLAGS} ) |
---|
307 | COMPIL_FFLAGS="${COMPIL_FFLAGS} ${archfileopt}" |
---|
308 | elif [[ "$compil_mod" == "debug" ]] |
---|
309 | then |
---|
310 | ## read %DEBUG_FFLAGS from arch.fcm file |
---|
311 | archfileline=$( grep -i '^%DEBUG_FFLAGS' arch.fcm ) |
---|
312 | archfileopt=$( echo ${archfileline##%DEBUG_FFLAGS} ) |
---|
313 | COMPIL_FFLAGS="${COMPIL_FFLAGS} ${archfileopt}" |
---|
314 | fi |
---|
315 | |
---|
316 | # add CPP_KEY defined in arch.fcm file |
---|
317 | archfileline=$( grep -i '^%FPP_DEF' arch.fcm ) |
---|
318 | archfileopt=$( echo ${archfileline##%FPP_DEF} ) |
---|
319 | CPP_KEY="$CPP_KEY ${archfileopt}" |
---|
320 | |
---|
321 | # get compiler name from arch.fcm file |
---|
322 | archfileline=$( grep -i '^%COMPILER' arch.fcm ) |
---|
323 | fcompiler=$( echo ${archfileline##%COMPILER} ) |
---|
324 | |
---|
325 | # get linker name from arch.fcm file |
---|
326 | archfileline=$( grep -i '^%LINK' arch.fcm ) |
---|
327 | linker=$( echo ${archfileline##%LINK} ) |
---|
328 | |
---|
329 | # get ar command from arch.fcm file |
---|
330 | archfileline=$( grep -i '^%AR ' arch.fcm ) |
---|
331 | arcommand=$( echo ${archfileline##%AR} ) |
---|
332 | |
---|
333 | # get ar command options from arch.fcm file |
---|
334 | archfileline=$( grep -i '^%ARFLAGS' arch.fcm ) |
---|
335 | arflags=$( echo ${archfileline##%ARFLAGS} ) |
---|
336 | |
---|
337 | # get make utility from arch.fcm file |
---|
338 | archfileline=$( grep -i '^%MAKE' arch.fcm ) |
---|
339 | makecommand=$( echo ${archfileline##%MAKE} ) |
---|
340 | |
---|
341 | # get basic libraries to link with arch.fcm file |
---|
342 | archfileline=$( grep -i '^%BASE_LD' arch.fcm ) |
---|
343 | archfileopt=$( echo ${archfileline##%BASE_LD} ) |
---|
344 | LIB="$LIB ${archfileopt}" |
---|
345 | |
---|
346 | # add Include files defined in arch.fcm file for pre-processing |
---|
347 | archfileline=$( grep -i '^%FPP_FLAGS' arch.fcm ) |
---|
348 | for inc in $archfileline ; do INCLUDE="$INCLUDE `echo $inc | grep '\-I'`" ; done |
---|
349 | |
---|
350 | phys_root=$physique |
---|
351 | if [[ "${physique:0:3}" == "lmd" ]] ; then phys_root=lmd ; fi |
---|
352 | if [[ "${physique:0:4}" == "mars" ]] ; then phys_root=mars ; fi |
---|
353 | if [[ "${physique:0:3}" == "std" ]] ; then phys_root=std ; fi |
---|
354 | if [[ "${physique:0:5}" == "venus" ]] ; then phys_root=venus ; fi |
---|
355 | if [[ "${physique:0:5}" == "titan" ]] ; then phys_root=titan ; fi |
---|
356 | if [[ "${physique:0:3}" == "dev" ]] ; then phys_root=dev ; fi |
---|
357 | |
---|
358 | if [[ "$physique" != "nophys" ]] |
---|
359 | then |
---|
360 | #We'll use some physics |
---|
361 | src_dirs="$src_dirs phy_common phy$physique" |
---|
362 | LIBPHY='$(LIBO)/libphy'"$physique"'.a' |
---|
363 | LIBPHY_COMMON='$(LIBO)/libphy_common.a' |
---|
364 | lib_phy='-lphy'"$physique"' -lphy_common' |
---|
365 | CPP_KEY="$CPP_KEY CPP_PHYS" |
---|
366 | if [[ $phys_root == "lmd" ]] |
---|
367 | then |
---|
368 | #For lmd physics, default planet type is Earth |
---|
369 | CPP_KEY="$CPP_KEY CPP_EARTH" |
---|
370 | fi |
---|
371 | fi |
---|
372 | |
---|
373 | if [[ "$chimie" == "INCA" ]] |
---|
374 | then |
---|
375 | CPP_KEY="$CPP_KEY INCA" |
---|
376 | INCLUDE="$INCLUDE -I${INCA_INCDIR}" |
---|
377 | LIB="$LIB -L${INCA_LIBDIR} -lchimie" |
---|
378 | libchimie=" -L${INCA_LIBDIR} -lchimie" |
---|
379 | fi |
---|
380 | |
---|
381 | if [[ "$couple" != "false" ]] |
---|
382 | then |
---|
383 | CPP_KEY="$CPP_KEY CPP_COUPLE" |
---|
384 | INCLUDE="$INCLUDE -I${OASIS_INCDIR}" |
---|
385 | LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.${couple} -lmpp_io" |
---|
386 | fi |
---|
387 | |
---|
388 | if [[ "$parallel" == "none" ]] |
---|
389 | then |
---|
390 | FLAG_PARA='' |
---|
391 | else |
---|
392 | FLAG_PARA="$paramem" |
---|
393 | if [[ $paramem == par ]] |
---|
394 | then |
---|
395 | echo "The version of the dynamics in dyn3dpar is no longer updated." |
---|
396 | echo "You should use option \"-mem\"." |
---|
397 | exit 1 |
---|
398 | fi |
---|
399 | fi |
---|
400 | |
---|
401 | if [[ "$parallel" == "mpi" ]] |
---|
402 | then |
---|
403 | CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI" |
---|
404 | # MPI additional compilation options |
---|
405 | archfileline=$( grep -i '^%MPI_FFLAGS' arch.fcm ) |
---|
406 | PARA_FFLAGS=$( echo ${archfileline##%MPI_FFLAGS} ) |
---|
407 | # MPI additional links |
---|
408 | archfileline=$( grep -i '^%MPI_LD' arch.fcm ) |
---|
409 | PARA_LD=$( echo ${archfileline##%MPI_LD} ) |
---|
410 | elif [[ "$parallel" == "omp" ]] |
---|
411 | then |
---|
412 | CPP_KEY="$CPP_KEY CPP_PARA CPP_OMP" |
---|
413 | # OMP additional compilation options |
---|
414 | archfileline=$( grep -i '^%OMP_FFLAGS' arch.fcm ) |
---|
415 | PARA_FFLAGS=$( echo ${archfileline##%OMP_FFLAGS} ) |
---|
416 | # OMP additional links |
---|
417 | archfileline=$( grep -i '^%OMP_LD' arch.fcm ) |
---|
418 | PARA_LD=$( echo ${archfileline##%OMP_LD} ) |
---|
419 | elif [[ "$parallel" == "mpi_omp" ]] |
---|
420 | then |
---|
421 | CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI CPP_OMP" |
---|
422 | # MPI additional compilation options |
---|
423 | archfileline=$( grep -i '^%MPI_FFLAGS' arch.fcm ) |
---|
424 | PARA_FFLAGS=$( echo ${archfileline##%MPI_FFLAGS} ) |
---|
425 | # OMP additional compilation options |
---|
426 | archfileline=$( grep -i '^%OMP_FFLAGS' arch.fcm ) |
---|
427 | PARA_FFLAGS="${PARA_FFLAGS} "$( echo $archfileopt ${archfileline##%OMP_FFLAGS} ) |
---|
428 | # MPI additional links |
---|
429 | archfileline=$( grep -i '^%MPI_LD' arch.fcm ) |
---|
430 | PARA_LD=$( echo ${archfileline##%MPI_LD} ) |
---|
431 | # OMP additional links |
---|
432 | archfileline=$( grep -i '^%OMP_LD' arch.fcm ) |
---|
433 | PARA_LD="${PARA_LD} "$( echo $archfileopt ${archfileline##%OMP_LD} ) |
---|
434 | fi |
---|
435 | |
---|
436 | if [[ ( "$parallel" == "omp" || "$parallel" == "mpi_omp" ) \ |
---|
437 | && "$compil_mod" == "debug" ]] |
---|
438 | then |
---|
439 | echo "Usually, parallelization with OpenMP requires some optimization." |
---|
440 | echo "We suggest switching to \"-dev\"." |
---|
441 | fi |
---|
442 | |
---|
443 | |
---|
444 | #============================================================================== |
---|
445 | if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" -o "$veget" = "orchidee2.1" -o "$veget" = "orchideetrunk" ] |
---|
446 | then |
---|
447 | |
---|
448 | INCLUDE="${INCLUDE} -I${ORCH_INCDIR}" |
---|
449 | CPP_KEY="$CPP_KEY CPP_VEGET" |
---|
450 | # temporary, for Orchidee versions 1.9.* (before openmp activation) |
---|
451 | if [[ "$veget" == "orchidee1.9" ]] ; then |
---|
452 | CPP_KEY="$CPP_KEY ORCHIDEE_NOOPENMP" |
---|
453 | fi |
---|
454 | if [[ "$veget" == "orchidee2.0" ]] ; then |
---|
455 | orch_libs="sechiba parameters stomate parallel orglob orchidee" |
---|
456 | CPP_KEY="$CPP_KEY ORCHIDEE_NOUNSTRUCT" |
---|
457 | elif [[ "$veget" == "orchidee2.1" ]] ; then |
---|
458 | CPP_KEY="$CPP_KEY ORCHIDEE_NOLIC" |
---|
459 | orch_libs="sechiba parameters stomate parallel orglob orchidee" |
---|
460 | elif [[ "$veget" == "orchideetrunk" ]] ; then |
---|
461 | orch_libs="orchidee" |
---|
462 | else |
---|
463 | orch_libs="sechiba parameters stomate parallel orglob" |
---|
464 | fi |
---|
465 | LIB="${LIB} -L${ORCH_LIBDIR}" |
---|
466 | for lib in ${orch_libs} ; do |
---|
467 | if [ -f ${ORCH_LIBDIR}/lib${LIBPREFIX}$lib.a ] ; then |
---|
468 | LIB="${LIB} -l${LIBPREFIX}$lib " |
---|
469 | fi |
---|
470 | done |
---|
471 | elif [[ "$veget" != "false" ]] ; then |
---|
472 | echo "Option -v $veget does not exist" |
---|
473 | echo "Use ./makelmdz -h for more information" |
---|
474 | exit |
---|
475 | fi |
---|
476 | |
---|
477 | #=============================================================================== |
---|
478 | if [[ $io == ioipsl ]] |
---|
479 | then |
---|
480 | CPP_KEY="$CPP_KEY CPP_IOIPSL" |
---|
481 | INCLUDE="$INCLUDE -I${IOIPSL_INCDIR}" |
---|
482 | LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl" |
---|
483 | elif [[ $io == mix ]] |
---|
484 | then |
---|
485 | # For now, xios implies also using ioipsl |
---|
486 | CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS" |
---|
487 | INCLUDE="$INCLUDE -I${IOIPSL_INCDIR} -I${XIOS_INCDIR}" |
---|
488 | LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl -L${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios -l${LIBPREFIX}stdc++" |
---|
489 | elif [[ $io == xios ]] |
---|
490 | then |
---|
491 | # For now, xios implies also using ioipsl |
---|
492 | CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS CPP_IOIPSL_NO_OUTPUT" |
---|
493 | INCLUDE="$INCLUDE -I${IOIPSL_INCDIR} -I${XIOS_INCDIR}" |
---|
494 | LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl -L${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios -l${LIBPREFIX}stdc++" |
---|
495 | fi |
---|
496 | |
---|
497 | if [[ "$cosp" == "true" ]] |
---|
498 | then |
---|
499 | CPP_KEY="$CPP_KEY CPP_COSP" |
---|
500 | # COSP_PATH="$LIBFGCM/phylmd/cosp" |
---|
501 | src_dirs="$src_dirs phy${physique}/cosp" |
---|
502 | # LIB="${LIB} -l${LIBPREFIX}cosp" |
---|
503 | # opt_dep="$opt_dep cosp" |
---|
504 | # lcosp="-l${LIBPREFIX}cosp" |
---|
505 | INCLUDE="$INCLUDE"' -I$(LIBF)/'phy${physique}'/cosp' |
---|
506 | fi |
---|
507 | |
---|
508 | if [[ "$cosp2" == "true" ]] |
---|
509 | then |
---|
510 | CPP_KEY="$CPP_KEY CPP_COSP2" |
---|
511 | src_dirs="$src_dirs phy${physique}/cosp2" |
---|
512 | INCLUDE="$INCLUDE"' -I$(LIBF)/'phy${physique}'/cosp2' |
---|
513 | fi |
---|
514 | |
---|
515 | if [[ "$cospv2" == "true" ]] |
---|
516 | then |
---|
517 | CPP_KEY="$CPP_KEY CPP_COSPV2" |
---|
518 | src_dirs="$src_dirs phy${physique}/cospv2" |
---|
519 | INCLUDE="$INCLUDE"' -I$(LIBF)/'phy${physique}'/cospv2' |
---|
520 | fi |
---|
521 | |
---|
522 | |
---|
523 | if [[ "$inlandsis" == "true" ]] |
---|
524 | then |
---|
525 | CPP_KEY="$CPP_KEY CPP_INLANDSIS" |
---|
526 | src_dirs="$src_dirs phy${physique}/inlandsis" |
---|
527 | fi |
---|
528 | |
---|
529 | |
---|
530 | if [[ "$rad" == "rrtm" ]] |
---|
531 | then |
---|
532 | CPP_KEY="$CPP_KEY CPP_RRTM" |
---|
533 | src_dirs="$src_dirs phy${physique}/rrtm" |
---|
534 | fi |
---|
535 | if [[ "$rad" == "ecrad" ]] |
---|
536 | then |
---|
537 | CPP_KEY="$CPP_KEY CPP_ECRAD" |
---|
538 | src_dirs="$src_dirs phy${physique}/ecrad" |
---|
539 | fi |
---|
540 | |
---|
541 | if [[ "$dust" == "true" ]] |
---|
542 | then |
---|
543 | CPP_KEY="$CPP_KEY CPP_Dust" |
---|
544 | src_dirs="$src_dirs phy${physique}/Dust" |
---|
545 | fi |
---|
546 | |
---|
547 | if [[ "$strataer" == "true" ]] |
---|
548 | then |
---|
549 | CPP_KEY="$CPP_KEY CPP_StratAer" |
---|
550 | src_dirs="$src_dirs phy${physique}/StratAer" |
---|
551 | fi |
---|
552 | |
---|
553 | #add new ocean skin modelisation to source dir by default |
---|
554 | |
---|
555 | src_dirs="$src_dirs phy${physique}/Ocean_skin" |
---|
556 | |
---|
557 | |
---|
558 | INCLUDE="$INCLUDE ${NETCDF_INCDIR}" |
---|
559 | LIB="$LIB ${NETCDF_LIBDIR}" |
---|
560 | |
---|
561 | ######################################################################## |
---|
562 | # calcul du nombre de dimensions |
---|
563 | ######################################################################## |
---|
564 | |
---|
565 | |
---|
566 | dim_full=$dim |
---|
567 | dim=`echo $dim | sed -e 's/[^0-9]/ /g'` |
---|
568 | set $dim |
---|
569 | dimc=$# |
---|
570 | echo calcul de la dimension |
---|
571 | echo dim $dim |
---|
572 | echo dimc $dimc |
---|
573 | |
---|
574 | ######################################################################## |
---|
575 | # Gestion des dimensions du modele. |
---|
576 | # on cree ou remplace le fichier des dimensions |
---|
577 | ######################################################################## |
---|
578 | |
---|
579 | cd $LIBFGCM/grid |
---|
580 | if [[ -f dimensions.h ]] |
---|
581 | then |
---|
582 | echo 'ATTENTION: vous etes sans doute en train de compiler le modele par ailleurs' |
---|
583 | echo "Attendez que la premiere compilation soit terminee pour relancer la suivante." |
---|
584 | echo "Si vous etes sur que vous ne compilez pas le modele par ailleurs," |
---|
585 | echo vous pouvez continuer en repondant oui. |
---|
586 | echo "Voulez-vous vraiment continuer?" |
---|
587 | echo "" |
---|
588 | echo "WARNING: you are probably already compiling the model somewhere else." |
---|
589 | echo "Wait until the first compilation is finished before launching this one." |
---|
590 | echo "If you are sure that you are not compiling elsewhere, just answer " |
---|
591 | echo "yes (or 'oui') to the question below to proceed." |
---|
592 | echo "Do you wish to continue?" |
---|
593 | read reponse |
---|
594 | if [[ $reponse == "oui" || $reponse == "yes" ]] |
---|
595 | then |
---|
596 | \rm -f $LIBFGCM/grid/dimensions.h |
---|
597 | else |
---|
598 | exit |
---|
599 | fi |
---|
600 | fi |
---|
601 | |
---|
602 | cd $LIBFGCM/grid/dimension |
---|
603 | ./makdim $dim |
---|
604 | if (($? != 0)) |
---|
605 | then |
---|
606 | exit 1 |
---|
607 | fi |
---|
608 | |
---|
609 | cat $LIBFGCM/grid/dimensions.h |
---|
610 | cd $LMDGCM |
---|
611 | |
---|
612 | ######################################################################## |
---|
613 | # Differentes dynamiques (3d, 2d, 1d) |
---|
614 | ######################################################################## |
---|
615 | |
---|
616 | if (( $dimc == 3 )) ; then |
---|
617 | src_dirs="$src_dirs $filtre dyn3d_common dyn3d${FLAG_PARA}" |
---|
618 | if [[ $physique != "nophys" ]] ; then |
---|
619 | src_dirs="$src_dirs dynphy_lonlat dynphy_lonlat/phy${phys_root}" |
---|
620 | libdyn_phy="-ldynphy_lonlat" |
---|
621 | LIBDYN_PHYS='$(LIBO)/libdynphy_lonlat.a' |
---|
622 | INCLUDE="$INCLUDE "'-I$(LIBF)/dynphy_lonlat' |
---|
623 | INCLUDE="$INCLUDE "'-I$(LIBF)/dynphy_lonlat/'"phy${phys_root}" |
---|
624 | fi |
---|
625 | cd $LIBFGCM/grid |
---|
626 | \rm fxyprim.h |
---|
627 | cp -p fxy_${grille}.h fxyprim.h |
---|
628 | filtre="FILTRE=$filtre" |
---|
629 | INCLUDE="$INCLUDE "'-I$(LIBF)/dyn3d${FLAG_PARA} -I$(LIBF)/dyn3d_common ' |
---|
630 | elif (( $dimc == 2 )) ; then |
---|
631 | src_dirs="$src_dirs dyn2d" |
---|
632 | filtre="FILTRE= L_FILTRE= " |
---|
633 | INCLUDE="$INCLUDE "'-I$(LIBF)/dyn2d' |
---|
634 | elif (( $dimc == 1 )) ; then |
---|
635 | #src_dirs="$src_dirs dyn3d dyn3d_common filtrez" |
---|
636 | src_dirs="$src_dirs phy${physique}/dyn1d" |
---|
637 | CPP_KEY="$CPP_KEY CPP_1D" |
---|
638 | filtre="L_DYN= DYN= FILTRE= L_FILTRE= " |
---|
639 | #INCLUDE="$INCLUDE "'-I$(LIBF)/dyn3d -I$(LIBF)/dyn3d_common ' # Pas tres propre |
---|
640 | INCLUDE="$INCLUDE "' -I$(LIBF)/phy'"$physique"'/dyn1d' |
---|
641 | else |
---|
642 | echo Dimension dimc=$dimc pas prevu ; exit |
---|
643 | fi |
---|
644 | |
---|
645 | cd $LMDGCM |
---|
646 | |
---|
647 | ######################################################################## |
---|
648 | # library directory name: |
---|
649 | ######################################################################## |
---|
650 | |
---|
651 | nomlib=`echo ${arch}_${physique}_${rad}_${dim_full}_${grille}_${compil_mod}_parall${parallel}_${CPP_KEY}_${FLAG_PARA} | sed -e 's/ //g' -e 's/-//g ' | sed -e 's/CPP_//g'` |
---|
652 | echo "Path to library: "$nomlib |
---|
653 | |
---|
654 | ######################################################################## |
---|
655 | # Cleanup for a full recompilation, if requested |
---|
656 | ######################################################################## |
---|
657 | |
---|
658 | if [[ $full == "full" ]] |
---|
659 | then |
---|
660 | # remove makefile and librairies |
---|
661 | echo "-full option: recompiling from scratch" |
---|
662 | \rm -f makefile |
---|
663 | \rm -rf "${LIBOGCM}/${nomlib}" |
---|
664 | fi |
---|
665 | |
---|
666 | ######################################################################## |
---|
667 | # Avant de lancer le make, on recree le makefile si necessaire |
---|
668 | ######################################################################## |
---|
669 | ######################################################################## |
---|
670 | # c'est a dire dans 3 cas: |
---|
671 | # 1. si la liste des fichiers .F et .h a ete modifiee depuis la |
---|
672 | # derniere creation du makefile |
---|
673 | # 2. si le fichier contenant cette liste "liste_des_sources" |
---|
674 | # n'existe pas. |
---|
675 | # 3. Si le makefile n'existe pas. |
---|
676 | ######################################################################## |
---|
677 | cd $LMDGCM |
---|
678 | |
---|
679 | |
---|
680 | if [[ -r .makelmdz ]] |
---|
681 | then |
---|
682 | old_lmdz_configuration=$(cat .makelmdz ) |
---|
683 | else |
---|
684 | old_lmdz_configuration="" |
---|
685 | fi |
---|
686 | lmdz_configuration="$src_dirs" |
---|
687 | if [[ "$lmdz_configuration" != "$old_lmdz_configuration" ]] |
---|
688 | then |
---|
689 | configuration_change="true" |
---|
690 | else |
---|
691 | configuration_change="false" |
---|
692 | fi |
---|
693 | |
---|
694 | mkdir -p make_dir |
---|
695 | suf_make=`echo $src_dirs | sed -e 's/\//_/g' -e 's/ /_/g'` |
---|
696 | echo suf_make $suf_make |
---|
697 | |
---|
698 | ######################################################################## |
---|
699 | # (re)Creation du makefile |
---|
700 | ######################################################################## |
---|
701 | |
---|
702 | echo "Controle de la necessite de recreer le makefile" |
---|
703 | \rm tmp77 tmp90 |
---|
704 | for dir in $src_dirs ; do |
---|
705 | # On recupere la liste de tous les subroutine, use et include pour |
---|
706 | # vérifier que les dépendense n'ont pas changé et reconstuire le |
---|
707 | # makefile le cas échéant |
---|
708 | # On enleve tout apres ONLy et on met un "uniq" pour que ca ne recrée pas |
---|
709 | # le makefile si on se contente d'ajouter des lignes dans le ONLY |
---|
710 | exclude="replay automatic include" |
---|
711 | for str in subroutine "use " "include " ; do |
---|
712 | grep -i "$str" libf/$dir/*.[Fh] | sed -e "/$exclude/d" | cut -d\( -f1 | sed -e 's/[Oo][Nn][Ll][Yy].*.$//' | uniq >> tmp77 |
---|
713 | grep -i "$str" libf/$dir/*.F90 | sed -e "/$exclude/d" | cut -d\( -f1 | sed -e 's/[Oo][Nn][Ll][Yy].*.$//' | uniq >> tmp90 |
---|
714 | done |
---|
715 | done |
---|
716 | |
---|
717 | liste77=make_dir/liste_des_sources_f77_$suf_make |
---|
718 | liste90=make_dir/liste_des_sources_f90_$suf_make |
---|
719 | makefile=make_dir/makefile_$suf_make |
---|
720 | |
---|
721 | if [[ $configuration_change == "true" || ! ( -r $makefile ) || ! ( -r $liste90 ) || ! ( -r $liste77 ) || ` diff tmp77 $liste77 | wc -w ` -ne 0 || ` diff tmp90 $liste90 | wc -w ` -ne 0 ]] |
---|
722 | then |
---|
723 | echo "les fichiers suivants ont ete crees ou detruits" |
---|
724 | echo "ou les fichiers suivants sont passes ou ne sont plus en Fortran 90" |
---|
725 | diff $liste77 tmp77 |
---|
726 | diff $liste90 tmp90 |
---|
727 | \cp -f tmp77 $liste77 |
---|
728 | \cp -f tmp90 $liste90 |
---|
729 | echo "Recreating the makefile" |
---|
730 | echo "src_dirs: $src_dirs" |
---|
731 | ./create_make_gcm $src_dirs > tmp |
---|
732 | \mv -f tmp $makefile |
---|
733 | echo "New makefile created" |
---|
734 | else |
---|
735 | echo Pas besoin de recreer le makefile |
---|
736 | fi |
---|
737 | |
---|
738 | |
---|
739 | ln -sf $makefile makefile |
---|
740 | echo "$lmdz_configuration" > .makelmdz |
---|
741 | |
---|
742 | ################################################################# |
---|
743 | # Preparation de l'execution de la comande make |
---|
744 | ################################################################# |
---|
745 | |
---|
746 | source_code=${code}.F |
---|
747 | dirmain=dyn${dimc}d${FLAG_PARA} |
---|
748 | if [[ -r $LMDGCM/libf/dyn${dimc}d${FLAG_PARA}/${code}.F90 ]] |
---|
749 | then |
---|
750 | source_code=${code}.F90 |
---|
751 | elif [[ -r $LMDGCM/libf/phy$physique/${code}.F90 ]] ; then |
---|
752 | dirmain=phy$physique |
---|
753 | source_code=${code}.F90 |
---|
754 | elif [[ -r $LMDGCM/libf/dynphy_lonlat/phy$phys_root/${code}.F90 ]] ; then |
---|
755 | dirmain="dynphy_lonlat/phy${phys_root}" |
---|
756 | source_code=${code}.F90 |
---|
757 | elif [[ -r $LMDGCM/libf/phy$physique/dyn1d/${code}.F90 ]] ; then |
---|
758 | dirmain=phy$physique/dyn1d |
---|
759 | source_code=${code}.F90 |
---|
760 | fi |
---|
761 | |
---|
762 | if [[ ! -d "${LIBOGCM}/${nomlib}" ]] |
---|
763 | then |
---|
764 | mkdir ${LIBOGCM}/${nomlib} |
---|
765 | # check we indeed managed to create the directory |
---|
766 | if [[ ! $? ]] |
---|
767 | then |
---|
768 | echo "Error: could not create directory ${LIBOGCM}/${nomlib}" |
---|
769 | exit |
---|
770 | fi |
---|
771 | fi |
---|
772 | |
---|
773 | # where module files are created |
---|
774 | mod_loc_dir=$localdir |
---|
775 | |
---|
776 | if [[ "$physique" != "nophys" ]] |
---|
777 | then |
---|
778 | INCLUDE="$INCLUDE"' -I$(LIBF)/phy'"$physique" |
---|
779 | fi |
---|
780 | INCLUDE="$INCLUDE"' -I'${LIBOGCM}/${nomlib} |
---|
781 | |
---|
782 | # ranlib utility (check it exists or else default to ls) |
---|
783 | if [[ `which ranlib > /dev/null 2>&1 ; echo $?` -eq 0 ]] |
---|
784 | then |
---|
785 | ranlib="ranlib" |
---|
786 | else |
---|
787 | ranlib="ls" |
---|
788 | fi |
---|
789 | |
---|
790 | # add CPP keys to COMPIL_FLAGS |
---|
791 | # (but first add -D before all CPP_KEY items) |
---|
792 | cpp_definitions=`echo $CPP_KEY | sed -e 's/[A-Za-z_=0-9]*/-D&/g'` |
---|
793 | # (but add a -WF,-D before all CPP_KEY items) => for xlf on Vargas |
---|
794 | if [[ "${fcompiler:0:3}" == "xlf" ]] |
---|
795 | then |
---|
796 | cpp_definitions=`echo $CPP_KEY | sed -e 's/[A-Za-z_=0-9]*/-WF,-D&/g'` |
---|
797 | fi |
---|
798 | COMPIL_FFLAGS="${COMPIL_FFLAGS} ${cpp_definitions}" |
---|
799 | |
---|
800 | ################################################################# |
---|
801 | # Execution du make |
---|
802 | ################################################################# |
---|
803 | echo $makecommand RANLIB=$ranlib -f $LMDGCM/makefile \ |
---|
804 | OPTION_DEP="$opt_dep" OPTION_LINK="$LIB ${PARA_LD}" \ |
---|
805 | OPTIM90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \ |
---|
806 | OPTIMTRU90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \ |
---|
807 | OPTIM="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \ |
---|
808 | INCLUDE="$INCLUDE" \ |
---|
809 | $filtre \ |
---|
810 | LIBO=${LIBOGCM}/${nomlib} \ |
---|
811 | "PHYS=$physique" \ |
---|
812 | LIBPHY=${LIBPHY} \ |
---|
813 | LIBPHY_COMMON=${LIBPHY_COMMON} \ |
---|
814 | LIBDYN_PHYS=${LIBDYN_PHYS} \ |
---|
815 | DIM=$dimc \ |
---|
816 | FLAG_PARA=$FLAG_PARA \ |
---|
817 | L_PHY="$lib_phy" \ |
---|
818 | L_DYN_PHY="$libdyn_phy" \ |
---|
819 | L_ADJNT=$adjnt \ |
---|
820 | L_COSP="$lcosp" \ |
---|
821 | L_COSP2="$lcosp2" \ |
---|
822 | L_COSPV2="$lcospv2" \ |
---|
823 | L_CHIMIE="$libchimie" \ |
---|
824 | LOCAL_DIR="$localdir" \ |
---|
825 | F77="$fcompiler" \ |
---|
826 | F90="$fcompiler" \ |
---|
827 | OPLINK="$LIB" \ |
---|
828 | LINK="$linker" \ |
---|
829 | GCM="$LMDGCM" \ |
---|
830 | MOD_LOC_DIR=$mod_loc_dir \ |
---|
831 | MOD_SUFFIX="mod" \ |
---|
832 | AR=$arcommand \ |
---|
833 | ARFLAGS="$arflags" \ |
---|
834 | DIRMAIN=$dirmain \ |
---|
835 | SOURCE=$source_code \ |
---|
836 | PROG=$code |
---|
837 | |
---|
838 | $makecommand RANLIB=$ranlib -f $LMDGCM/makefile \ |
---|
839 | OPTION_DEP="$opt_dep" OPTION_LINK="$LIB ${PARA_LD}" \ |
---|
840 | OPTIM90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \ |
---|
841 | OPTIMTRU90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \ |
---|
842 | OPTIM="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \ |
---|
843 | INCLUDE="$INCLUDE" \ |
---|
844 | $filtre \ |
---|
845 | LIBO=${LIBOGCM}/${nomlib} \ |
---|
846 | "PHYS=$physique" \ |
---|
847 | LIBPHY=${LIBPHY} \ |
---|
848 | LIBPHY_COMMON=${LIBPHY_COMMON} \ |
---|
849 | LIBDYN_PHYS=${LIBDYN_PHYS} \ |
---|
850 | DIM=$dimc \ |
---|
851 | FLAG_PARA=$FLAG_PARA \ |
---|
852 | L_PHY="$lib_phy" \ |
---|
853 | L_DYN_PHY="$libdyn_phy" \ |
---|
854 | L_ADJNT=$adjnt \ |
---|
855 | L_COSP="$lcosp" \ |
---|
856 | L_COSP2="$lcosp2" \ |
---|
857 | L_COSPV2="$lcospv2" \ |
---|
858 | L_CHIMIE="$libchimie" \ |
---|
859 | LOCAL_DIR="$localdir" \ |
---|
860 | F77="$fcompiler" \ |
---|
861 | F90="$fcompiler" \ |
---|
862 | OPLINK="$LIB" \ |
---|
863 | LINK="$linker" \ |
---|
864 | GCM="$LMDGCM" \ |
---|
865 | MOD_LOC_DIR=$mod_loc_dir \ |
---|
866 | MOD_SUFFIX="mod" \ |
---|
867 | AR=$arcommand \ |
---|
868 | ARFLAGS="$arflags" \ |
---|
869 | DIRMAIN=$dirmain \ |
---|
870 | SOURCE=$source_code \ |
---|
871 | PROG=$code |
---|
872 | |
---|
873 | |
---|
874 | if [[ -r $LIBFGCM/grid/dimensions.h ]] |
---|
875 | then |
---|
876 | # Cleanup: remove dimension.h file |
---|
877 | \rm -f $LIBFGCM/grid/dimensions.h |
---|
878 | fi |
---|