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