1 | #!/bin/bash |
---|
2 | set -eu # error on command failure, and on unset variables |
---|
3 | export LC_ALL=C # standardize awk format |
---|
4 | |
---|
5 | ########################################################################### |
---|
6 | # Author : Laurent Fairhead et Frédéric Hourdin |
---|
7 | # Usage : install_lmdz.sh -help |
---|
8 | # |
---|
9 | # bash installation script of the LMDZ model on different computer types : |
---|
10 | # Linux PC, "mesocentre" (IPSL-UPMC, IPSL-X), super-computer (IDRIS) |
---|
11 | # |
---|
12 | # The model is downloaded in the following directory tree |
---|
13 | # $MODEL/modipsl/modeles/... |
---|
14 | # using the "modipsl" infrastructure created by the "IPSL" |
---|
15 | # for coupled (atmosphere/ocean/vegetation/chemistry) climate modeling |
---|
16 | # activities. |
---|
17 | # Here we only download atmospheric (LMDZ) and vegetation (ORCHIDEE) |
---|
18 | # components. |
---|
19 | # |
---|
20 | # The sources of the models can be found in the "modeles" directory. |
---|
21 | # In the present case, LMDZ, ORCHIDEE, and IOIPSL or XIOS (handling of |
---|
22 | # input-outputs using the NetCDF library). |
---|
23 | # |
---|
24 | # The script downloads various source files (including a version of NetCDF) |
---|
25 | # and utilities, compiles the model, and runs a test simulation in a |
---|
26 | # minimal configuration. |
---|
27 | # |
---|
28 | # Prerequisites : pgf90/gfortran, bash or ksh, wget , gunzip, tar, ... |
---|
29 | # |
---|
30 | # Modif 18/11/2011 |
---|
31 | # changes for option real 8. |
---|
32 | # We compile with -r8 (or equivalent) and -DNC_DOUBLE for the GCM |
---|
33 | # but with -r4 for netcdf. Variable real must be set to |
---|
34 | # r4 or r8 at the beginning of the script below. |
---|
35 | # |
---|
36 | ########################################################################### |
---|
37 | |
---|
38 | ### Functions |
---|
39 | # TODO add make_j parallel argument -> check what is used for libigcm |
---|
40 | |
---|
41 | function myget { # Get a file from LMDZ repository |
---|
42 | local url=$1 |
---|
43 | |
---|
44 | local filename |
---|
45 | filename=$(basename "$url") |
---|
46 | |
---|
47 | wget --no-check-certificate -nv "http://lmdz.lmd.jussieu.fr/pub/$url" |
---|
48 | if [[ $filename =~ .*\.(ba)?sh ]]; then chmod +x "$filename"; fi |
---|
49 | } |
---|
50 | |
---|
51 | function set_default_params { |
---|
52 | # Valeur par défaut des parametres |
---|
53 | svn="" |
---|
54 | version="20231022.trunk" |
---|
55 | |
---|
56 | netcdf=1 |
---|
57 | bench=1 |
---|
58 | pcmac=0 # default: not on a Mac |
---|
59 | SCM=0 |
---|
60 | veget="none" |
---|
61 | grid_resolution="32x32x39" |
---|
62 | physiq="" |
---|
63 | |
---|
64 | xios_branch="2.6" |
---|
65 | xios_rev="2568" |
---|
66 | |
---|
67 | parallel="none" |
---|
68 | trusting="testing" |
---|
69 | MODEL="" |
---|
70 | |
---|
71 | with_xios=0 |
---|
72 | opt_makelmdz_xios="" |
---|
73 | |
---|
74 | rad="rrtm" |
---|
75 | |
---|
76 | compile_with_fcm=1 |
---|
77 | |
---|
78 | cosp="none" |
---|
79 | opt_cosp="" |
---|
80 | |
---|
81 | make_j=8 |
---|
82 | |
---|
83 | # Check if on a Mac |
---|
84 | if [[ $(uname) = "Darwin" ]]; then |
---|
85 | pcmac=1 |
---|
86 | export MAKE="make" |
---|
87 | fi |
---|
88 | |
---|
89 | optim_debug="" |
---|
90 | arch="local" |
---|
91 | |
---|
92 | local mpi_file |
---|
93 | mpi_file=$(readlink -f "$(which mpif90)") |
---|
94 | path_mpi=$(dirname "$mpi_file") |
---|
95 | root_mpi=$(dirname "$path_mpi") |
---|
96 | |
---|
97 | arch="local-gfortran" |
---|
98 | arch_dir="" |
---|
99 | } |
---|
100 | |
---|
101 | function read_cmdline_args { |
---|
102 | while (($# > 0)); do |
---|
103 | case $1 in |
---|
104 | "-h") cat <<........fin |
---|
105 | $0 [ -v version ] [ -r svn_release ] |
---|
106 | [ -parallel PARA ] [ -d GRID_RESOLUTION ] [ -bench 0/1 ] |
---|
107 | [-name LOCAL_MODEL_NAME] [-gprof] [-opt_makelmdz] [-rad RADIATIF] |
---|
108 | |
---|
109 | -v "version" like 20150828.trunk, see http://www.lmd.jussieu.fr/~lmdz/Distrib/LISMOI.trunk (default <$version>) |
---|
110 | |
---|
111 | -r "svn_release" : either the svn release number or "last" (default <$svn>) |
---|
112 | |
---|
113 | -parallel parallel support: mpi, omp, mpi_omp (mpi with openMP) or none (default: <$parallel>) |
---|
114 | |
---|
115 | -d "grid resolution": should be among the available benchs if -bench 1 (valid values: 48x36x19, 48x36x39) (default : <$grid_resolution>) |
---|
116 | |
---|
117 | -bench activating the bench or not (0/1) (default: <$bench>) |
---|
118 | |
---|
119 | -testing/unstable |
---|
120 | |
---|
121 | -name name of the folder to install to (default <$MODEL>) |
---|
122 | |
---|
123 | -netcdf 0, 1 or PATH. 0: do not download NetCDF, look for it in standard locations (/usr); 1: download and compile NetCDF; PATH: full path to an existing installed NetCDF library (default: <$netcdf>) |
---|
124 | |
---|
125 | -xios use (download and compile) the XIOS library (will compile the parallel NetCDF4-HDF5 library) (requires to also have -parallel mpi_omp) |
---|
126 | |
---|
127 | -cosp to run with cospv1 or cospv2 [none/v1/v2] (default <$cosp>) |
---|
128 | |
---|
129 | -rad radiative code: oldrad, rrtm or ecrad (default <$rad>) |
---|
130 | |
---|
131 | -nofcm to compile without fcm |
---|
132 | |
---|
133 | -SCM install 1D version automatically |
---|
134 | |
---|
135 | -debug compile everything in debug mode |
---|
136 | |
---|
137 | -physiq to choose which physics package to use (default <$physiq>) |
---|
138 | |
---|
139 | -veget surface/vegetation scheme treatment controlled by the single variable veget which can have the following values: none: bucket scheme (default); CMIP6: orchidee version used in CMIP exercise, rev 5661; number: orchidee version number (default $veget) |
---|
140 | |
---|
141 | -arch name of the arch to use (default <$arch>) |
---|
142 | |
---|
143 | -arch_dir where to find the arch files (default <$arch_dir>) |
---|
144 | |
---|
145 | -make_j number of processes to parallelize installations (default <$make_j>) |
---|
146 | |
---|
147 | ........fin |
---|
148 | exit 1;; |
---|
149 | "-v") version=$2; shift; shift;; |
---|
150 | "-r") svn=$2; shift; shift;; |
---|
151 | "-d") grid_resolution=$2; shift; shift;; |
---|
152 | "-unstable"|"-testing") trusting=$(echo "$1" | cut -c2-); shift;; |
---|
153 | "-cosp") cosp=$2 |
---|
154 | case $cosp in |
---|
155 | "none"|"v1"|"v2") cosp=$2; shift; shift;; |
---|
156 | *) echo "Only none v1 v2 for cosp option"; exit 1 |
---|
157 | esac;; |
---|
158 | "-nofcm") compile_with_fcm=0; echo "This option will be reactivated soon (promesse du 8dec2022)"; exit 1; shift;; |
---|
159 | "-SCM") SCM=1; shift;; |
---|
160 | "-rad") rad=$2 |
---|
161 | case $rad in |
---|
162 | "oldrad"|"rrtm"|"ecrad") rad=$2; shift; shift;; |
---|
163 | *) echo "Only oldrad rrtm ecrad for rad option"; exit 1 |
---|
164 | esac;; |
---|
165 | "-parallel") parallel=$2 |
---|
166 | case $parallel in |
---|
167 | "none"|"mpi"|"omp"|"mpi_omp") parallel=$2; shift; shift;; |
---|
168 | *) echo "Only none mpi omp mpi_omp for the parallel option"; exit 1 |
---|
169 | esac;; |
---|
170 | "-bench") bench=$2; shift; shift;; |
---|
171 | "-debug") optim_debug=-debug; shift;; |
---|
172 | "-name") MODEL=$2; shift; shift;; |
---|
173 | "-netcdf") netcdf=$2; shift; shift;; |
---|
174 | "-physiq") physiq=$2; shift; shift;; |
---|
175 | "-xios") with_xios=1; shift;; |
---|
176 | "-arch") arch=$2; shift; shift;; |
---|
177 | "-arch_dir") arch_dir=$2; shift; shift;; |
---|
178 | "-veget") veget=$2; shift; shift;; |
---|
179 | "-make_j") make_j=$2; shift; shift;; |
---|
180 | *) bash install_lmdz.sh -h; exit 1 |
---|
181 | esac |
---|
182 | done |
---|
183 | |
---|
184 | # Option de compilation pour Cosp |
---|
185 | case $cosp in |
---|
186 | v1) opt_cosp="-cosp true";; |
---|
187 | v2) opt_cosp="-cospv2 true";; |
---|
188 | *) opt_cosp="" |
---|
189 | esac |
---|
190 | |
---|
191 | # Check on veget version |
---|
192 | if [[ $veget != 'none' && $veget != "CMIP6" ]]; then |
---|
193 | re='^[0-9]+$' |
---|
194 | if ! [[ $veget =~ $re ]]; then |
---|
195 | echo 'Valeur de l option veget non valable'; exit 1 |
---|
196 | fi |
---|
197 | fi |
---|
198 | |
---|
199 | #Define veget-related suffix for gcm name |
---|
200 | if [[ $veget = 'none' ]]; then |
---|
201 | suff_orc='' |
---|
202 | #For use with tutorial, orchidee_rev is also defined (will be |
---|
203 | #written in surface_env at the end of the script) |
---|
204 | orchidee_rev='' |
---|
205 | else |
---|
206 | suff_orc='_orch' |
---|
207 | fi |
---|
208 | |
---|
209 | |
---|
210 | if [[ $parallel = "none" ]]; then |
---|
211 | suff_exe='_seq' |
---|
212 | else |
---|
213 | suff_exe='_para_mem' |
---|
214 | fi |
---|
215 | |
---|
216 | #Chemin pour placer le modele |
---|
217 | if [[ $MODEL = "" ]]; then MODEL="./LMDZ$version$svn$optim_debug"; fi |
---|
218 | |
---|
219 | ## if also compiling XIOS, parallel must be mpi_omp |
---|
220 | if [[ $with_xios = 1 && $parallel != "mpi_omp" ]]; then |
---|
221 | echo "Error, you must set -parallel mpi_omp if you want XIOS"; exit 1 |
---|
222 | fi |
---|
223 | |
---|
224 | if [[ $with_xios = 1 ]]; then |
---|
225 | opt_makelmdz_xios="-io xios" |
---|
226 | fi |
---|
227 | |
---|
228 | if [[ $cosp = "v2" && $with_xios = 0 ]]; then |
---|
229 | echo "Error, Cospv2 cannot run without Xios"; exit 1 |
---|
230 | fi |
---|
231 | |
---|
232 | if [[ $arch_dir = "" ]]; then |
---|
233 | arch_dir="$MODEL/modipsl/config/IPSLCM7/ARCH/" |
---|
234 | fi |
---|
235 | arch_dir=$(readlink -f "$arch_dir") # full path |
---|
236 | } |
---|
237 | |
---|
238 | function check_available_software { |
---|
239 | echo "################################################################" |
---|
240 | echo "Check if required software is available" |
---|
241 | echo "################################################################" |
---|
242 | for logiciel in wget tar gzip make gcc cmake m4 c++; do |
---|
243 | if [[ $(which "$logiciel") = "" ]]; then |
---|
244 | echo "You must first install $logiciel on your system"; exit 1 |
---|
245 | fi |
---|
246 | done |
---|
247 | |
---|
248 | cat <<eod > tt.f90 |
---|
249 | print*,'coucou' |
---|
250 | end |
---|
251 | eod |
---|
252 | $compiler tt.f90 || a.out |
---|
253 | ./a.out >| tt |
---|
254 | if [[ $(< tt sed -e 's/ //g' ) != "coucou" ]]; then |
---|
255 | echo "problem installing with compiler $compiler"; exit 1 |
---|
256 | fi |
---|
257 | \rm tt a.out tt.f90 |
---|
258 | } |
---|
259 | |
---|
260 | function download_model { |
---|
261 | mkdir -p "$MODEL" |
---|
262 | MODEL=$(readlink -f "$MODEL"); echo "$MODEL" # absolute path |
---|
263 | |
---|
264 | rm -rf "$MODEL/modipsl" |
---|
265 | |
---|
266 | echo "##########################################################" |
---|
267 | echo "Download a slightly modified version of LMDZ" |
---|
268 | echo "##########################################################" |
---|
269 | cd "$MODEL" |
---|
270 | getlog="$(pwd)/get.log" |
---|
271 | echo "logfile : $getlog" |
---|
272 | myget "src_archives/$trusting/modipsl.$version.tar.gz" >> get.log 2>&1 |
---|
273 | echo "install_lmdz.sh wget_OK $(date)" |
---|
274 | gunzip "modipsl.$version.tar.gz" >> get.log 2>&1 |
---|
275 | tar xf "modipsl.$version.tar" >> get.log 2>&1 |
---|
276 | \rm "modipsl.$version.tar" |
---|
277 | |
---|
278 | if [[ $svn != "" ]]; then |
---|
279 | mysvn=$svn |
---|
280 | else |
---|
281 | mysvn="$(grep 'Revision: [0-9]' "$MODEL"/Read*.md | awk ' { print $2 } ' 2>/dev/null)" |
---|
282 | fi |
---|
283 | echo "SVN revision used: $mysvn" |
---|
284 | } |
---|
285 | |
---|
286 | function download_model_AMAURY { # TODO |
---|
287 | MODEL=$(readlink -f "$MODEL"); echo "$MODEL" # absolute path |
---|
288 | |
---|
289 | if [[ $svn != "" ]]; then |
---|
290 | mysvn=$svn |
---|
291 | else |
---|
292 | mysvn="$(grep 'Revision: [0-9]' "$MODEL"/Read*.md | awk ' { print $2 } ' 2>/dev/null)" |
---|
293 | fi |
---|
294 | echo "SVN revision used: $mysvn" |
---|
295 | } |
---|
296 | |
---|
297 | function install_arch { |
---|
298 | if [[ ! -d $arch_dir ]]; then |
---|
299 | echo "Error: no arch dir $arch_dir"; exit 1 |
---|
300 | elif [[ ! -f $arch_dir/arch-$arch.path ]]; then |
---|
301 | echo "Error: no arch-$arch.path in $arch_dir"; exit 1 |
---|
302 | fi |
---|
303 | |
---|
304 | local fcm_path |
---|
305 | if [[ -f $arch_dir/arch-$arch.fcm ]]; then |
---|
306 | fcm_path="$arch_dir/arch-$arch.fcm" |
---|
307 | else |
---|
308 | fcm_path="$MODEL/modipsl/modeles/LMDZ/arch/arch-$arch.fcm" |
---|
309 | if [[ ! -f $fcm_path ]]; then |
---|
310 | echo "Error: no $fcm_path"; exit 1 |
---|
311 | fi |
---|
312 | fi |
---|
313 | |
---|
314 | # check compiler |
---|
315 | compiler=$(< "$fcm_path" grep "%COMPILER" | sed -e "s/%COMPILER\s*//") |
---|
316 | |
---|
317 | # Copy arch to different components |
---|
318 | # TODO check that this doesn't error if the source and destination are the same |
---|
319 | for dir in "IOIPSL" "ORCHIDEE" "LMDZ" "XIOS"; do |
---|
320 | \cp -f "$arch_dir/arch-$arch.fcm" "$MODEL/modipsl/modeles/$dir/arch" |
---|
321 | \cp -f "$arch_dir/arch-$arch.path" "$MODEL/modipsl/modeles/$dir/arch" |
---|
322 | done |
---|
323 | |
---|
324 | # TODO TEMP compat w/ old orch version - make a proper case later |
---|
325 | sed -i'' -e "s/-I//" -e "s/-L//" "$MODEL/modipsl/modeles/ORCHIDEE/arch/arch-$arch.path" # /!\ we only replace first occurence on purpose |
---|
326 | |
---|
327 | # Adapt for XIOS, which uses different naming conventions |
---|
328 | # TODO >:c ugly fdefault-real-8 fix |
---|
329 | sed -i'' -e "s/%COMPILER/%FCOMPILER/" -e "s/%LINK/%LINKER/" -e "s/-fdefault-real-8//" "$MODEL/modipsl/modeles/XIOS/arch/arch-$arch.fcm" |
---|
330 | } |
---|
331 | |
---|
332 | function install_netcdf { |
---|
333 | echo "Installing Netcdf" |
---|
334 | |
---|
335 | if [[ $netcdf = 0 ]]; then |
---|
336 | ncdfdir=$(nc-config --prefix) |
---|
337 | else |
---|
338 | cd "$MODEL" |
---|
339 | |
---|
340 | case $compiler in |
---|
341 | gfortran) opt1="-compiler gnu"; opt2="-CC gcc -FC gfortran -CXX g++";; |
---|
342 | ifort) opt1="-compiler intel"; opt2="-CC icc -FC ifort -CXX icpc";; |
---|
343 | pgf90) opt1="-compiler pgf90"; opt2="-CC pgcc -FC pgf90 -CXX pgCC";; |
---|
344 | *) echo "unexpected compiler $compiler for netcdf"; exit 1 |
---|
345 | esac |
---|
346 | |
---|
347 | case $with_xios in |
---|
348 | 0) script_install_netcdf="install_netcdf4_hdf5_seq.bash" |
---|
349 | ncdfdir="netcdf4_hdf5_seq" |
---|
350 | opt_="$opt1";; |
---|
351 | 1) script_install_netcdf="install_netcdf4_hdf5.bash" |
---|
352 | ncdfdir="netcdf4_hdf5" |
---|
353 | opt_="$opt2 -MPI $root_mpi";; |
---|
354 | *) echo "with_xios=$with_xios, should be 0 or 1"; exit 1 |
---|
355 | esac |
---|
356 | if [[ $netcdf = 1 ]]; then |
---|
357 | ncdfdir="$MODEL/$ncdfdir" |
---|
358 | else |
---|
359 | mkdir -p "$netcdf"; ncdfdir="$netcdf/$ncdfdir" |
---|
360 | fi |
---|
361 | |
---|
362 | echo "Repertoire netcdf $ncdfdir" |
---|
363 | if [[ ! -d $ncdfdir ]]; then |
---|
364 | netcdflog=$(pwd)/netcdf.log |
---|
365 | echo "----------------------------------------------------------" |
---|
366 | echo "Compiling the Netcdf library" |
---|
367 | echo "----------------------------------------------------------" |
---|
368 | echo "log file : $netcdflog" |
---|
369 | myget script_install/$script_install_netcdf >> "$netcdflog" 2>&1 |
---|
370 | chmod u=rwx $script_install_netcdf |
---|
371 | # shellcheck disable=SC2086 |
---|
372 | ./$script_install_netcdf -prefix "$ncdfdir" $opt_ >> "$netcdflog" 2>&1 |
---|
373 | fi |
---|
374 | |
---|
375 | #---------------------------------------------------------------------------- |
---|
376 | # LF rajout d'une verrue, pour une raison non encore expliquee, |
---|
377 | # la librairie est parfois rangée dans lib64 et non dans lib |
---|
378 | # par certains compilateurs |
---|
379 | if [[ ! -e lib && -d lib64 ]]; then ln -s lib64 lib; fi |
---|
380 | #---------------------------------------------------------------------------- |
---|
381 | |
---|
382 | echo "install_lmdz.sh netcdf_OK $(date)" |
---|
383 | fi |
---|
384 | |
---|
385 | cat >test_netcdf90.f90 <<EOF |
---|
386 | use netcdf |
---|
387 | print *, "NetCDF library version: ", nf90_inq_libvers() |
---|
388 | end |
---|
389 | EOF |
---|
390 | |
---|
391 | if $compiler -I"$ncdfdir"/include test_netcdf90.f90 -L"$ncdfdir"/lib -lnetcdff \ |
---|
392 | -lnetcdf -Wl,-rpath="$ncdfdir"/lib && ./a.out |
---|
393 | then |
---|
394 | \rm test_netcdf90.f90 a.out |
---|
395 | else |
---|
396 | cat <<EOF |
---|
397 | Failed test program using NetCDF-Fortran. You can: |
---|
398 | - check that you have NetCDF-Fortran installed in your system |
---|
399 | - or specify an installation directory with option -netcdf of install_lmdz.sh |
---|
400 | - or download and compile NetCDF-Fortran with option -netcdf 1 of nstall_lmdz.sh |
---|
401 | EOF |
---|
402 | exit 1 |
---|
403 | fi |
---|
404 | |
---|
405 | # Compile NetCDF95 |
---|
406 | cd "$MODEL/modipsl/modeles/LMD"* |
---|
407 | echo "Installing NetCDF95" |
---|
408 | cd "$MODEL" |
---|
409 | myget src_archives/netcdf/NetCDF95-0.3.tar.gz |
---|
410 | tar -xf NetCDF95-0.3.tar.gz |
---|
411 | \rm NetCDF95-0.3.tar.gz |
---|
412 | cd NetCDF95-0.3 |
---|
413 | mkdir -p build && cd build |
---|
414 | netCDF_INCLUDE_DIR=$(nc-config --includedir) netCDF_LIBRARY=$(nc-config --libdir) cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$ncdfdir" -DCMAKE_INSTALL_PREFIX="$MODEL/modipsl" |
---|
415 | make install |
---|
416 | } |
---|
417 | |
---|
418 | function install_IOIPSL { # via fcm |
---|
419 | cd "$MODEL/modipsl/modeles/IOIPSL" |
---|
420 | ioipsllog="$(pwd)/ioipsl.log" |
---|
421 | echo "Compiling IOIPSL, the interface library with Netcdf $(date) (log: $ioipsllog)" |
---|
422 | |
---|
423 | if ! ./makeioipsl_fcm -arch "$arch" -job 8 > "$ioipsllog" 2>&1; then |
---|
424 | echo "IOIPSL compile failed, exiting"; exit 1 |
---|
425 | fi |
---|
426 | cp lib/* ../../lib |
---|
427 | echo "IOIPSL compiled $(date)" |
---|
428 | |
---|
429 | IOIPSL_LIBDIR_="$MODEL/modipsl/modeles/IOIPSL/lib" |
---|
430 | IOIPSL_INCDIR_="$MODEL/modipsl/modeles/IOIPSL/inc" |
---|
431 | } |
---|
432 | |
---|
433 | function install_XIOS { |
---|
434 | if [[ $with_xios = 1 ]]; then |
---|
435 | cd "$MODEL/modipsl/modeles" |
---|
436 | xioslog="$(pwd)/XIOS/xios.log" |
---|
437 | echo "##########################################################" |
---|
438 | echo "Compiling XIOS (log $xioslog) $(date)" |
---|
439 | echo "##########################################################" |
---|
440 | |
---|
441 | # Download XIOS |
---|
442 | case $xios_branch in |
---|
443 | "trunk") |
---|
444 | xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/trunk";; |
---|
445 | "2.5") |
---|
446 | xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/branchs/xios-2.5";; |
---|
447 | "2.6") |
---|
448 | xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS2/branches/xios-2.6";; |
---|
449 | *) echo "XIOS: Error, bad argument for -branch ! Did not expect $xios_branch"; exit;; |
---|
450 | esac |
---|
451 | |
---|
452 | cd "$MODEL/modipsl/modeles" |
---|
453 | set +e; svn co --revision $xios_rev $xios_http XIOS; set -e |
---|
454 | |
---|
455 | cd XIOS |
---|
456 | if ! ./make_xios --arch "$arch" --job 8 > "$xioslog" 2>&1; then |
---|
457 | echo "XIOS compilation failed, exiting"; exit 1 |
---|
458 | fi |
---|
459 | |
---|
460 | echo "Compiled XIOS $(date)" |
---|
461 | fi |
---|
462 | |
---|
463 | XIOS_LIBDIR_="$MODEL/modipsl/modeles/XIOS/lib" |
---|
464 | XIOS_INCDIR_="$MODEL/modipsl/modeles/XIOS/inc" |
---|
465 | } |
---|
466 | |
---|
467 | function get_orchidee_version { # Set / Check ORCHIDEE version |
---|
468 | if [[ $veget = "none" ]]; then |
---|
469 | veget_version="false" |
---|
470 | elif [[ $veget = "CMIP6" ]]; then |
---|
471 | veget_version=orchidee2.0 |
---|
472 | else # specific orchidee revision newer than CMIP6, on 2_1 or 2_2 branches |
---|
473 | veget_version=orchidee2.1 |
---|
474 | if [[ $veget -lt 4465 ]]; then |
---|
475 | echo 'ORCHIDEE version must be >=4465, exiting' |
---|
476 | exit 1 |
---|
477 | fi |
---|
478 | |
---|
479 | set +e |
---|
480 | svn upgrade |
---|
481 | local orcbranch |
---|
482 | orcbranch=$(svn log -v -q svn://forge.ipsl.jussieu.fr/orchidee/ -r "$veget" |grep ORCHIDEE |head -1| sed -e 's:ORCHIDEE/.*$:ORCHIDEE:' | awk '{print $2}') |
---|
483 | echo "IF YOU INSTALL ORCHIDEE THE VERY FIRST TIME, ASK for PASSWORD at orchidee-help@listes.ipsl.fr" |
---|
484 | svn switch -r "$veget" --accept theirs-full "svn://forge.ipsl.jussieu.fr/orchidee/$orcbranch" |
---|
485 | svn log -r "$veget" | grep "$veget" |
---|
486 | if ! svn log -r "$veget" | grep "$veget"; then |
---|
487 | echo 'Cannot update ORCHIDEE as not on the right branch for ORCHIDEE' |
---|
488 | exit 1 |
---|
489 | fi |
---|
490 | svn update -r "$veget" |
---|
491 | set -e |
---|
492 | fi |
---|
493 | } |
---|
494 | |
---|
495 | function compile_orchidee { |
---|
496 | get_orchidee_version |
---|
497 | ORCHPATH="" |
---|
498 | |
---|
499 | |
---|
500 | if [[ $veget != "none" ]]; then |
---|
501 | cd "$MODEL/modipsl/modeles/ORCHIDEE" |
---|
502 | ORCHPATH=$(pwd) |
---|
503 | |
---|
504 | orchideelog="$(pwd)/orchidee.log" |
---|
505 | echo "Compiling ORCHIDEE, the continental surface model (log $orchideelog) $(date)" |
---|
506 | |
---|
507 | local xios_orchid opt_orc |
---|
508 | if [[ $with_xios = 1 ]]; then |
---|
509 | xios_orchid="-xios"; |
---|
510 | else |
---|
511 | xios_orchid="-noxios" |
---|
512 | fi |
---|
513 | if [[ $optim_debug = "-debug" ]]; then |
---|
514 | opt_orc="-debug"; |
---|
515 | else |
---|
516 | opt_orc="-prod" |
---|
517 | fi |
---|
518 | |
---|
519 | # TODO check that this works with old orchidee versions (cf. -d tools) |
---|
520 | local varenv="IOIPSL_LIBDIR_=$IOIPSL_LIBDIR_ IOIPSL_INCDIR_=$IOIPSL_INCDIR_ ORCHPATH=$ORCHPATH" |
---|
521 | if [[ $parallel = "none" ]]; then |
---|
522 | echo "$varenv ./makeorchidee_fcm $xios_orchid $opt_orc -parallel none -arch $arch -j $make_j" > compile.sh |
---|
523 | else |
---|
524 | if [[ ! -d src_parallel ]]; then |
---|
525 | echo "Orchidee version too old for parallel support"; exit 1 |
---|
526 | fi |
---|
527 | { |
---|
528 | echo "$varenv ./makeorchidee_fcm -j $make_j -clean $xios_orchid $opt_orc -parallel $parallel -arch $arch" |
---|
529 | echo "$varenv ./makeorchidee_fcm -j $make_j $xios_orchid $opt_orc -parallel $parallel -arch $arch" |
---|
530 | } > compile.sh |
---|
531 | fi |
---|
532 | chmod +x compile.sh |
---|
533 | echo "Compiling ORCHIDEE using $(\cat compile.sh)" |
---|
534 | if ! ./compile.sh > "$orchideelog" 2>&1; then |
---|
535 | echo "ORCHIDEE compilation failed, exiting"; exit 1 |
---|
536 | fi |
---|
537 | echo "Compiled ORCHIDEE $(date)" |
---|
538 | fi |
---|
539 | |
---|
540 | ORCH_LIBDIR_="$MODEL/modipsl/modeles/ORCHIDEE/lib" |
---|
541 | } |
---|
542 | |
---|
543 | function get_lmdz_version { |
---|
544 | LMDZPATH=$(readlink -f "$MODEL/modipsl/modeles/LMD"*) |
---|
545 | cd "$LMDZPATH" |
---|
546 | lmdzlog="$(pwd)/lmdz.log" |
---|
547 | |
---|
548 | set +e |
---|
549 | svn upgrade |
---|
550 | if [[ $svn = "last" ]]; then |
---|
551 | svnopt="" |
---|
552 | else |
---|
553 | svnopt="-r $svn" |
---|
554 | fi |
---|
555 | if [[ $svn != "" ]]; then |
---|
556 | if svn info | grep -q 'https:'; then svn switch --relocate https://svn.lmd.jussieu.fr/LMDZ http://svn.lmd.jussieu.fr/LMDZ; fi |
---|
557 | svn update "$svnopt" |
---|
558 | fi |
---|
559 | mysvn=$(svnversion . | grep -E -o "[0-9]+" 2>/dev/null) |
---|
560 | set -e |
---|
561 | |
---|
562 | if [[ $mysvn = "" ]]; then mysvn=$(grep 'Revision: [0-9]' "$MODEL"/Read*.md | awk ' { print $2 } ' 2>/dev/null); fi |
---|
563 | if [[ $mysvn = "" ]]; then mysvn=4190; fi |
---|
564 | } |
---|
565 | |
---|
566 | function compile_lmdz { |
---|
567 | get_lmdz_version |
---|
568 | |
---|
569 | exe_name="bin/gcm_${grid_resolution}_phylmd_${rad}${suff_exe}${suff_orc}.e" |
---|
570 | |
---|
571 | local opt_rad |
---|
572 | case $rad in |
---|
573 | oldrad) iflag_rrtm=0; NSW=2; opt_rad="";; |
---|
574 | rrtm) iflag_rrtm=1; NSW=6 |
---|
575 | if [[ $mysvn -le 4185 ]]; then |
---|
576 | opt_rad="-rrtm true" |
---|
577 | else |
---|
578 | opt_rad="-rad rrtm" |
---|
579 | fi;; |
---|
580 | ecrad) iflag_rrtm=2; NSW=6; opt_rad="-rad ecrad";; |
---|
581 | *) echo "Only oldrad rrtm ecrad for rad option"; exit 1 |
---|
582 | esac |
---|
583 | if [[ $mysvn -le 4185 && $rad = "ecrad" ]]; then |
---|
584 | echo "ecrad only available for LMDZ rev starting with 4186 "; exit 1 |
---|
585 | fi |
---|
586 | |
---|
587 | # Compile |
---|
588 | local varenv="IOIPSL_LIBDIR_=$IOIPSL_LIBDIR_ IOIPSL_INCDIR_=$IOIPSL_INCDIR_ ORCH_LIBDIR_=$ORCH_LIBDIR_ ORCHPATH=$ORCHPATH XIOS_INCDIR_=$XIOS_INCDIR_ XIOS_LIBDIR_=$XIOS_LIBDIR_" |
---|
589 | makelmdz="makelmdz_fcm $optim_debug -arch $arch -j $make_j" |
---|
590 | if [[ $parallel = "none" ]]; then |
---|
591 | echo "$varenv ./$makelmdz $opt_rad $opt_cosp -d ${grid_resolution} -v $veget_version gcm " > compile.sh |
---|
592 | else |
---|
593 | echo "$varenv ./$makelmdz $opt_rad $opt_cosp $opt_makelmdz_xios -d ${grid_resolution} -v $veget_version -mem -parallel $parallel gcm" > compile.sh |
---|
594 | fi |
---|
595 | echo "Compiling lmdz using $(\cat compile.sh) (log: $lmdzlog) $(date)" |
---|
596 | chmod +x ./compile.sh |
---|
597 | if ! ./compile.sh > "$lmdzlog" 2>&1; then |
---|
598 | echo "LMDZ compilation failed, exiting"; exit 1 |
---|
599 | fi |
---|
600 | echo "Finished LMDZ compilation $(date)" |
---|
601 | |
---|
602 | # Check executable |
---|
603 | # TODO $mysev -ge 4186 => other name convention ! check original install |
---|
604 | if [[ ! -f $exe_name ]]; then |
---|
605 | echo "Compilation failed, can't find the executable"; exit 1 |
---|
606 | else |
---|
607 | echo "Compilation successfull, the executable is $exe_name $(date)" |
---|
608 | fi |
---|
609 | } |
---|
610 | |
---|
611 | function run_bench { |
---|
612 | cd "$MODEL/modipsl/modeles/LMDZ"* |
---|
613 | |
---|
614 | if [[ $bench = "tuto" ]]; then |
---|
615 | myget "Training/tutorial.tar"; tar xf tutorial.tar; cd TUTORIAL |
---|
616 | ./init.sh |
---|
617 | elif [[ $bench = 1 ]]; then |
---|
618 | \rm -rf "BENCH${grid_resolution}" |
---|
619 | local bench=bench_lmdz_${grid_resolution} |
---|
620 | myget "3DBenchs/$bench.tar.gz" |
---|
621 | tar xf "$bench.tar.gz" |
---|
622 | |
---|
623 | if [[ $cosp = "v1" || $cosp = "v2" ]]; then |
---|
624 | cd "BENCH${grid_resolution}" |
---|
625 | # copier les fichiers namelist input et output our COSP |
---|
626 | cp ../DefLists/cosp*_input_nl.txt . |
---|
627 | cp ../DefLists/cosp*_output_nl.txt . |
---|
628 | # Activer la cles ok_cosp pour tourner avec COSP |
---|
629 | sed -e 's@ok_cosp=n@ok_cosp=y@' config.def > tmp |
---|
630 | \mv -f tmp config.def |
---|
631 | cd .. |
---|
632 | fi |
---|
633 | |
---|
634 | if [[ -n "$physiq" ]]; then |
---|
635 | cd "BENCH${grid_resolution}" |
---|
636 | if [[ -f "physiq.def_${physiq}" ]]; then |
---|
637 | cp "physiq.def_${physiq}" physiq.def |
---|
638 | echo "using physiq.def_${physiq}" |
---|
639 | else |
---|
640 | echo "using standard physiq.def" |
---|
641 | fi |
---|
642 | cd .. |
---|
643 | else |
---|
644 | echo "using standard physiq.def" |
---|
645 | fi |
---|
646 | |
---|
647 | if [[ $with_xios = 1 ]]; then |
---|
648 | cd "BENCH${grid_resolution}" |
---|
649 | cp ../DefLists/iodef.xml . |
---|
650 | cp ../DefLists/context_lmdz.xml . |
---|
651 | cp ../DefLists/field_def_lmdz.xml . |
---|
652 | # A raffiner par la suite |
---|
653 | echo "A FAIRE : Copier les *xml en fonction de l option cosp" |
---|
654 | cp ../DefLists/field_def_cosp*.xml . |
---|
655 | cp ../DefLists/file_def_hist*xml . |
---|
656 | # adapt iodef.xml to use attached mode |
---|
657 | sed -e 's@"using_server" type="bool">true@"using_server" type="bool">false@' \ |
---|
658 | iodef.xml > tmp |
---|
659 | \mv -f tmp iodef.xml |
---|
660 | |
---|
661 | # and convert all the enabled="_AUTO_" (for libIGCM) to enabled=.FALSE. |
---|
662 | # except for histday |
---|
663 | for histfile in file_def_hist*xml |
---|
664 | do |
---|
665 | if [[ "$histfile" = "file_def_histday_lmdz.xml" ]]; then |
---|
666 | sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".TRUE."@' \ |
---|
667 | "$histfile" > tmp |
---|
668 | \mv -f tmp "$histfile" |
---|
669 | sed -e 's@output_level="_AUTO_"@output_level="5"@' "$histfile" \ |
---|
670 | > tmp |
---|
671 | \mv -f tmp "$histfile" |
---|
672 | sed -e 's@compression_level="2"@compression_level="0"@' \ |
---|
673 | "$histfile" > tmp |
---|
674 | \mv -f tmp "$histfile" |
---|
675 | else |
---|
676 | sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \ |
---|
677 | "$histfile" > tmp |
---|
678 | \mv -f tmp "$histfile" |
---|
679 | fi |
---|
680 | done |
---|
681 | # and add option "ok_all_xml=y" in config.def |
---|
682 | echo "### XIOS outputs" >> config.def |
---|
683 | echo 'ok_all_xml=.true.' >> config.def |
---|
684 | |
---|
685 | #activer les sorties pour Cosp |
---|
686 | if [[ "$cosp" = "v1" ]]; then |
---|
687 | sed -i'' -e 's@enabled=".FALSE."@enabled=".TRUE."@' \ |
---|
688 | -e 's@output_level="_AUTO_"@output_level="5"@' \ |
---|
689 | -e 's@compression_level="2"@compression_level="0"@' \ |
---|
690 | file_def_histdayCOSP_lmdz.xml |
---|
691 | fi |
---|
692 | if [[ "$cosp" = "v2" ]]; then |
---|
693 | sed -e 's@compression_level="2"@compression_level="0"@' file_def_histdayCOSPv2_lmdz.xml |
---|
694 | for type_ in hf day mth; do |
---|
695 | file=file_def_hist${type_}COSP |
---|
696 | sed -i'' -e 's@src="./'${file}'_lmdz.xml"@src="./'${file}'v2_lmdz.xml"@' context_lmdz.xml |
---|
697 | done |
---|
698 | sed -i '' -e 's@field_def_cosp1.xml@field_def_cospv2.xml@' field_def_lmdz.xml |
---|
699 | fi |
---|
700 | |
---|
701 | cd .. |
---|
702 | fi |
---|
703 | |
---|
704 | # Cas Bench avec ecrad |
---|
705 | if [[ $rad = "ecrad" ]]; then |
---|
706 | cd "BENCH${grid_resolution}" |
---|
707 | cp ../DefLists/namelist_ecrad . |
---|
708 | cp -r ../libf/phylmd/ecrad/data . |
---|
709 | cd .. |
---|
710 | fi |
---|
711 | |
---|
712 | # Adjusting bench physiq.def to radiative code chosen |
---|
713 | cd "BENCH${grid_resolution}" |
---|
714 | sed -e 's/iflag_rrtm=.*.$/iflag_rrtm='$iflag_rrtm'/' \ |
---|
715 | -e 's/NSW=.*.$/NSW='$NSW'/' physiq.def > tmpdef |
---|
716 | \mv tmpdef physiq.def |
---|
717 | cd .. |
---|
718 | |
---|
719 | cp "$exe_name" "BENCH${grid_resolution}/gcm.e" |
---|
720 | cd "BENCH${grid_resolution}" |
---|
721 | |
---|
722 | if [[ ${parallel:0:3} = "mpi" ]]; then |
---|
723 | # Lancement avec deux procs mpi et 2 openMP |
---|
724 | echo "export OMP_STACKSIZE=800M" > bench.sh |
---|
725 | if [[ "${parallel:4:3}" = "omp" ]]; then |
---|
726 | echo "export OMP_NUM_THREADS=2" >> bench.sh |
---|
727 | fi |
---|
728 | if [[ "$cosp" = "v1" || "$cosp" = "v2" ]]; then |
---|
729 | echo "ulimit -s 200000" >> bench.sh |
---|
730 | else |
---|
731 | echo "ulimit -s unlimited" >> bench.sh |
---|
732 | fi |
---|
733 | echo "mpirun -np 2 gcm.e > listing 2>&1" >> bench.sh |
---|
734 | # Add rebuild, using reb.sh if it is there |
---|
735 | cat <<EOF >> bench.sh |
---|
736 | if [[ -f reb.sh ]]; then |
---|
737 | ./reb.sh histday; ./reb.sh histmth; ./reb.sh histhf; |
---|
738 | ./reb.sh histins; ./reb.sh stomate_history; |
---|
739 | ./reb.sh sechiba_history; ./reb.sh sechiba_out_2 |
---|
740 | fi |
---|
741 | EOF |
---|
742 | else |
---|
743 | echo "./gcm.e > listing 2>&1" > bench.sh |
---|
744 | fi |
---|
745 | # Getting orchidee stuff |
---|
746 | if [[ $veget = 'CMIP6' ]]; then |
---|
747 | echo 'myget 3DBenchs/BENCHCMIP6.tar.gz' |
---|
748 | myget 3DBenchs/BENCHCMIP6.tar.gz |
---|
749 | tar xvzf BENCHCMIP6.tar.gz |
---|
750 | sed -e "s:VEGET=n:VEGET=y:" config.def > tmp |
---|
751 | mv -f tmp config.def |
---|
752 | if [[ $with_xios = 1 ]]; then |
---|
753 | cp ../../ORCHIDEE/src_xml/context_orchidee.xml . |
---|
754 | echo '<context id="orchidee" src="./context_orchidee.xml"/>' > add.tmp |
---|
755 | cp ../../ORCHIDEE/src_xml/field_def_orchidee.xml . |
---|
756 | cp ../../ORCHIDEE/src_xml/file_def_orchidee.xml . |
---|
757 | cp ../../ORCHIDEE/src_xml/file_def_input_orchidee.xml . |
---|
758 | if [[ -f ../../ORCHIDEE/src_xml/context_input_orchidee.xml ]]; then |
---|
759 | cp ../../ORCHIDEE/src_xml/context_input_orchidee.xml . |
---|
760 | echo '<context id="orchidee" src="./context_input_orchidee.xml"/>' >> add.tmp |
---|
761 | fi |
---|
762 | sed -e '/id="LMDZ"/r add.tmp' iodef.xml > tmp |
---|
763 | mv tmp iodef.xml |
---|
764 | sed -e'{/sechiba1/ s/enabled="_AUTO_"/type="one_file" enabled=".TRUE."/}' \ |
---|
765 | file_def_orchidee.xml > tmp |
---|
766 | \mv -f tmp file_def_orchidee.xml |
---|
767 | sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \ |
---|
768 | file_def_orchidee.xml > tmp |
---|
769 | \mv -f tmp file_def_orchidee.xml |
---|
770 | sed -e 's@output_level="_AUTO_"@output_level="1"@' \ |
---|
771 | file_def_orchidee.xml > tmp |
---|
772 | \mv -f tmp file_def_orchidee.xml |
---|
773 | sed -e 's@output_freq="_AUTO_"@output_freq="1d"@' \ |
---|
774 | file_def_orchidee.xml > tmp |
---|
775 | \mv -f tmp file_def_orchidee.xml |
---|
776 | sed -e 's@compression_level="4"@compression_level="0"@' \ |
---|
777 | file_def_orchidee.xml > tmp |
---|
778 | \mv -f tmp file_def_orchidee.xml |
---|
779 | sed -e 's@XIOS_ORCHIDEE_OK = n@XIOS_ORCHIDEE_OK = y@' \ |
---|
780 | orchidee.def > tmp |
---|
781 | \mv -f tmp orchidee.def |
---|
782 | fi |
---|
783 | fi |
---|
784 | |
---|
785 | if [[ -f ../arch.env ]]; then source ../arch.env; fi |
---|
786 | |
---|
787 | echo "EXECUTION DU BENCH" |
---|
788 | date |
---|
789 | if (! ./bench.sh > out.bench 2>&1) || ! (tail -n 1 listing | grep "Everything is cool"); then |
---|
790 | tail listing |
---|
791 | echo "Bench FAILED, exiting"; exit 1 |
---|
792 | fi |
---|
793 | date |
---|
794 | tail listing |
---|
795 | fi |
---|
796 | |
---|
797 | # 1D case |
---|
798 | if [[ $SCM = 1 ]]; then |
---|
799 | cd "$MODEL" |
---|
800 | myget 1D/1D.tar.gz |
---|
801 | tar xf 1D.tar.gz |
---|
802 | cd 1D |
---|
803 | if [[ $rad = "oldrad" ]]; then |
---|
804 | sed -i'' -e 's/^rad=.*$/rad=oldrad/' run.sh |
---|
805 | sed -i'' -e 's/^rad=.*$/rad=oldrad/' bin/compile |
---|
806 | fi |
---|
807 | echo "Running 1D/run.sh, log in $(pwd)/run1d.log" |
---|
808 | ./run.sh > "$(pwd)/run1d.log" 2>&1 |
---|
809 | fi |
---|
810 | } |
---|
811 | |
---|
812 | echo "install_lmdz.sh DEBUT $(date)" |
---|
813 | |
---|
814 | set_default_params |
---|
815 | read_cmdline_args "$@" |
---|
816 | #download_model |
---|
817 | download_model_AMAURY |
---|
818 | install_arch |
---|
819 | check_available_software |
---|
820 | install_netcdf |
---|
821 | install_IOIPSL |
---|
822 | install_XIOS |
---|
823 | compile_orchidee |
---|
824 | compile_lmdz |
---|
825 | run_bench |
---|