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 : 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 | |
---|
40 | function myget { |
---|
41 | # Get a file from LMDZ repository, make it executable if .(ba)sh |
---|
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 do_compile_sh { |
---|
52 | local component=$1 |
---|
53 | local command=$2 |
---|
54 | local log |
---|
55 | |
---|
56 | log="$(pwd)/$component.log" |
---|
57 | echo "$command" > compile.sh |
---|
58 | echo "Compiling $component using $(\cat compile.sh) (log: $log) $(date)" |
---|
59 | chmod +x ./compile.sh |
---|
60 | if ! ./compile.sh &> "$log"; then |
---|
61 | echo "STOP: $component compilation failed, exiting"; exit 1 |
---|
62 | fi |
---|
63 | echo "Finished $component compilation $(date)" |
---|
64 | } |
---|
65 | |
---|
66 | function get_svn_branch { |
---|
67 | local url=$1 |
---|
68 | local rev=$2 |
---|
69 | local res |
---|
70 | |
---|
71 | res=$(svn log -v -q "$url" -r "$rev" -l 1 | cut -d "/" -f -4) |
---|
72 | if echo "$res" | grep -q "/trunk/"; then |
---|
73 | res=$(echo "$res" | grep "/trunk/" | head -1 | cut -d "/" -f 2-3) |
---|
74 | elif echo "$res" | grep -q "/branches/"; then |
---|
75 | res=$(echo "$res" | grep "/branches/" | head -1 | cut -d "/" -f 2-4) |
---|
76 | else |
---|
77 | echo "Could not determine svn branch for $url, r=$rev" |
---|
78 | fi |
---|
79 | echo "$res" |
---|
80 | } |
---|
81 | |
---|
82 | function set_default_params { |
---|
83 | # Valeur par défaut des parametres |
---|
84 | svn_lmdz="" |
---|
85 | version="20241018.trunk" |
---|
86 | |
---|
87 | netcdf=1 |
---|
88 | bench=1 |
---|
89 | SCM=0 |
---|
90 | veget="none" |
---|
91 | grid_resolution="32x32x39" |
---|
92 | benchphysiq="" |
---|
93 | compphysiq="lmd" |
---|
94 | is_1D="n" |
---|
95 | fortran_file="gcm" |
---|
96 | |
---|
97 | parallel="none" |
---|
98 | trusting="testing" |
---|
99 | MODEL="" |
---|
100 | |
---|
101 | with_xios=0 |
---|
102 | opt_makelmdz_xios="" |
---|
103 | |
---|
104 | icolmdz=0 |
---|
105 | dynamico_commit="11001689" |
---|
106 | |
---|
107 | rad="rrtm" |
---|
108 | |
---|
109 | compile_with_fcm=1 |
---|
110 | |
---|
111 | cosp="none" |
---|
112 | aerosols=0 |
---|
113 | strataer=0 |
---|
114 | inlandsis=0 |
---|
115 | |
---|
116 | make_j=8 |
---|
117 | clean_install=1 |
---|
118 | local="$(pwd)" |
---|
119 | |
---|
120 | # Check if on a Mac /!\ Probably doesn't work anymore, to fix one day... |
---|
121 | if [[ $(uname) = "Darwin" ]]; then |
---|
122 | export MAKE="make" |
---|
123 | fi |
---|
124 | |
---|
125 | optim_flag="-prod" |
---|
126 | arch="local" |
---|
127 | |
---|
128 | arch="local-gfortran" |
---|
129 | arch_dir="" |
---|
130 | |
---|
131 | jobcmd="" |
---|
132 | } |
---|
133 | |
---|
134 | function read_cmdline_args { |
---|
135 | while (($# > 0)); do |
---|
136 | case $1 in |
---|
137 | "-h") cat <<........fin |
---|
138 | $0 [ -v version ] [ -r svn_release ] |
---|
139 | [ -parallel PARA ] [ -d GRID_RESOLUTION ] [ -bench 0/1 ] |
---|
140 | [-name LOCAL_MODEL_NAME] [-rad RADIATIF] |
---|
141 | |
---|
142 | -v "version" like 20150828.trunk, see http://www.lmd.jussieu.fr/~lmdz/Distrib/LISMOI.trunk (default <$version>) |
---|
143 | |
---|
144 | -r "svn_release" : either the svn release number or "last" (default <$svn_lmdz>) |
---|
145 | |
---|
146 | -parallel parallel support: mpi, omp, mpi_omp (mpi with openMP) or none (default: <$parallel>) |
---|
147 | |
---|
148 | -d "grid resolution": should be among the available benchs if -bench 1 (valid values: 48x36x19, 48x36x39) (default : <$grid_resolution>) |
---|
149 | |
---|
150 | -bench activating the bench or not (0/1) (default: <$bench>) |
---|
151 | |
---|
152 | -unstable use unstable tar instead of testing |
---|
153 | |
---|
154 | -name name of the folder to install to (default <$MODEL>) |
---|
155 | |
---|
156 | -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>) |
---|
157 | |
---|
158 | -xios use (download and compile) the XIOS library (will compile the parallel NetCDF4-HDF5 library) (requires to also have -parallel mpi_omp) |
---|
159 | |
---|
160 | -cosp to run with cospv1 or cospv2 [none/v1/v2] (default <$cosp>) |
---|
161 | |
---|
162 | -rad radiative code: oldrad, rrtm or ecrad (default <$rad>) |
---|
163 | |
---|
164 | -nofcm to compile without fcm |
---|
165 | |
---|
166 | -SCM install 1D version automatically |
---|
167 | |
---|
168 | -debug compile everything in debug mode |
---|
169 | |
---|
170 | -benchphysiq to choose which physics.def package to use in the bench (default <$benchphysiq>) |
---|
171 | |
---|
172 | -compilephysiq physics to compile the model with (default <$compphysiq>) |
---|
173 | |
---|
174 | -veget surface/vegetation scheme treatment controlled by the single variable veget which can have the following values: none: bucket scheme (default); CMIP6 | veget2.0: orchidee version used in CMIP exercise, rev 5661; veget2.2: orchidee branch 2.2, rev 8529 (bundled); number: orchidee version number [only orch>2.0] (default $veget) |
---|
175 | |
---|
176 | -spla activate interactive aerosols |
---|
177 | |
---|
178 | -inlandsis activate new snow scheme |
---|
179 | |
---|
180 | -arch name of the arch to use (default <$arch>) |
---|
181 | |
---|
182 | -arch_dir where to find the arch files (default <$arch_dir>) |
---|
183 | |
---|
184 | -make_j number of processes to parallelize installations (default <$make_j>) |
---|
185 | |
---|
186 | -jobcmd command prepended to fcm compile jobs, e.g. "srun" (default <$jobcmd>) |
---|
187 | |
---|
188 | -noclean will only download necessary files (but no thorough check is made on the integrity of existing files), and will recompile everything (very quick if it's already been compiled before) |
---|
189 | |
---|
190 | -icolmdz to compile the icolmdz executable as well as the lonlat one |
---|
191 | |
---|
192 | ........fin |
---|
193 | exit 1;; |
---|
194 | "-v") version=$2; shift; shift;; |
---|
195 | "-r") svn_lmdz=$2; shift; shift;; |
---|
196 | "-d") grid_resolution=$2; shift; shift;; |
---|
197 | "-unstable") trusting="unstable"; shift;; |
---|
198 | "-cosp") cosp=$2 |
---|
199 | case $cosp in |
---|
200 | "none"|"v1"|"v2") cosp=$2; shift; shift;; |
---|
201 | *) echo "Only none v1 v2 for cosp option"; exit 1 |
---|
202 | esac;; |
---|
203 | "-nofcm") compile_with_fcm=0; echo "This option will be reactivated soon (promesse du 8dec2022)"; exit 1; shift;; |
---|
204 | "-SCM") SCM=1; shift;; |
---|
205 | "-rad") rad=$2 |
---|
206 | case $rad in |
---|
207 | "oldrad"|"rrtm"|"ecrad") rad=$2; shift; shift;; |
---|
208 | *) echo "Only oldrad rrtm ecrad for rad option"; exit 1 |
---|
209 | esac;; |
---|
210 | "-parallel") parallel=$2 |
---|
211 | case $parallel in |
---|
212 | "none"|"mpi"|"omp"|"mpi_omp") parallel=$2; shift; shift;; |
---|
213 | *) echo "Only none mpi omp mpi_omp for the parallel option"; exit 1 |
---|
214 | esac;; |
---|
215 | "-bench") bench=$2; shift; shift;; |
---|
216 | "-debug") optim_flag="-debug"; shift;; |
---|
217 | "-name") MODEL=$2; shift; shift;; |
---|
218 | "-netcdf") netcdf=$2; shift; shift;; |
---|
219 | "-benchphysiq") benchphysiq=$2; shift; shift;; |
---|
220 | "-compilephysiq") compphysiq=$2; shift; shift;; |
---|
221 | "-xios") with_xios=1; shift;; |
---|
222 | "-arch") arch=$2; shift; shift;; |
---|
223 | "-arch_dir") arch_dir=$2; shift; shift;; |
---|
224 | "-veget") veget=$2; shift; shift;; |
---|
225 | "-spla") aerosols=1; shift;; |
---|
226 | "-strataer") strataer=1; shift;; |
---|
227 | "-inlandsis") inlandsis=1; shift;; |
---|
228 | "-make_j") make_j=$2; shift; shift;; |
---|
229 | "-jobcmd") jobcmd=$2; shift; shift;; |
---|
230 | "-noclean") clean_install=0; shift;; |
---|
231 | "-icolmdz") icolmdz=1; shift;; |
---|
232 | *) bash install_lmdz.sh -h; exit 1 |
---|
233 | esac |
---|
234 | done |
---|
235 | |
---|
236 | # Isotopes : Compile and run with isotopes if lmdz_phys="lmdiso" in main.sh |
---|
237 | if [[ $compphysiq = "lmdiso" ]]; then isotopes=1; else isotopes=0; fi |
---|
238 | |
---|
239 | # Option de compilation pour Cosp |
---|
240 | case $cosp in |
---|
241 | v1) opt_cosp="-cosp true";; |
---|
242 | v2) opt_cosp="-cospv2 true";; |
---|
243 | *) opt_cosp="" |
---|
244 | esac |
---|
245 | |
---|
246 | #Define veget-related suffix for gcm name |
---|
247 | if [[ $veget = 'none' ]]; then |
---|
248 | suff_orc='' |
---|
249 | else |
---|
250 | suff_orc='_orch' |
---|
251 | fi |
---|
252 | |
---|
253 | |
---|
254 | if [[ $parallel = "none" ]]; then |
---|
255 | suff_para='_seq' |
---|
256 | else |
---|
257 | suff_para='_para_mem' |
---|
258 | fi |
---|
259 | |
---|
260 | if [[ $with_xios = 1 ]]; then opt_makelmdz_xios="-io xios"; fi |
---|
261 | |
---|
262 | if [[ $aerosols = 1 ]]; then |
---|
263 | opt_aer="-dust true"; suff_aer="_spla" |
---|
264 | else |
---|
265 | opt_aer=""; suff_aer="" |
---|
266 | fi |
---|
267 | |
---|
268 | if [[ $strataer = 1 ]]; then |
---|
269 | opt_strataer="-strataer true" |
---|
270 | else |
---|
271 | opt_strataer="" |
---|
272 | fi |
---|
273 | |
---|
274 | if [[ $inlandsis = 1 ]]; then |
---|
275 | opt_inlandsis="-inlandsis true" |
---|
276 | else |
---|
277 | opt_inlandsis="" |
---|
278 | fi |
---|
279 | |
---|
280 | if [[ $isotopes = 1 ]]; then |
---|
281 | opt_isotopes="-isotopes true"; suff_iso="_iso" |
---|
282 | else |
---|
283 | opt_isotopes="" ; suff_iso="" |
---|
284 | fi |
---|
285 | |
---|
286 | # set default arch if parallel |
---|
287 | if [[ $arch = "local-gfortran" && $parallel != "none" ]]; then |
---|
288 | arch="local-gfortran-parallel" |
---|
289 | echo "Switching default arch to $arch" |
---|
290 | fi |
---|
291 | |
---|
292 | # Name of the model's folder. The convention taken here is that models that requires different compilation sources should have a different names. |
---|
293 | local xios_name="" |
---|
294 | if [[ $with_xios = 1 ]]; then xios_name="XIOS"; fi |
---|
295 | if [[ $MODEL = "" ]]; then MODEL="./LMDZ$version${svn_lmdz}OR$veget$xios_name"; fi |
---|
296 | |
---|
297 | if [[ $arch_dir = "" ]]; then |
---|
298 | arch_dir="$MODEL/modipsl/config/IPSLCM7/ARCH/"; |
---|
299 | elif ! readlink -fe "$arch_dir" >/dev/null; then |
---|
300 | echo "STOP: no arch dir <$arch_dir>"; exit 1 |
---|
301 | fi |
---|
302 | |
---|
303 | if ! (echo "$grid_resolution" | grep -q "x"); then |
---|
304 | is_1D="y" |
---|
305 | fortran_file="lmdz1d" |
---|
306 | fi |
---|
307 | } |
---|
308 | |
---|
309 | function ensure_correct_option_combinations { |
---|
310 | # Check on veget version |
---|
311 | if [[ $veget != 'none' && $veget != "CMIP6" && $veget != "orch2.0" && $veget != "orch2.2" ]]; then |
---|
312 | re='^[0-9]+$' |
---|
313 | if ! [[ $veget =~ $re ]]; then |
---|
314 | echo 'Valeur de l option veget non valable'; exit 1 |
---|
315 | fi |
---|
316 | fi |
---|
317 | |
---|
318 | ## if compiling icolmdz, XIOS must be set |
---|
319 | if [[ $icolmdz = 1 && $with_xios = 0 ]]; then |
---|
320 | echo "Error, you must set -xios to compile the icolmdz executable"; exit 1 |
---|
321 | fi |
---|
322 | ## if also compiling XIOS, parallel must be mpi_omp |
---|
323 | if [[ $with_xios = 1 && $parallel != "mpi_omp" ]]; then |
---|
324 | echo "Error, you must set -parallel mpi_omp if you want XIOS"; exit 1 |
---|
325 | fi |
---|
326 | |
---|
327 | if [[ $cosp = "v2" && $with_xios = 0 ]]; then |
---|
328 | echo "Error, Cospv2 cannot run without Xios"; exit 1 |
---|
329 | fi |
---|
330 | |
---|
331 | # STOP if trying to use both ORCHIDEE and Isotopes : |
---|
332 | if [[ $isotopes = 1 && $veget != "none" ]]; then |
---|
333 | echo "STOP: You cannot run LMDZ with ORCHIDEE and ISOtopes at the same time"; exit 1 |
---|
334 | fi |
---|
335 | |
---|
336 | # STOP if trying to use both SPLA and Isotopes : |
---|
337 | if [[ $isotopes = 1 && $aerosols = 1 ]]; then |
---|
338 | echo "STOP: You cannot run LMDZ with Isotopes and aerosols=spla at the same time"; exit 1 |
---|
339 | fi |
---|
340 | |
---|
341 | # (Temporary) STOP if trying to use Isotopes with XIOS : |
---|
342 | if [[ $isotopes = 1 && $with_xios = 1 ]]; then |
---|
343 | echo "STOP: Isotopes cannont yet be run with XIOS"; exit 1 |
---|
344 | fi |
---|
345 | |
---|
346 | if [[ $aerosols = 1 && $rad != "rrtm" ]]; then |
---|
347 | echo "STOP: For the time being, <aerosols=spla> requires <rad=rrtm>"; exit 1 |
---|
348 | fi |
---|
349 | } |
---|
350 | |
---|
351 | function check_available_software { |
---|
352 | local required_soft=("wget" "tar" "gzip" "make" "gcc" "cmake" "m4" "c++") |
---|
353 | echo "Checking if required software is available (${required_soft[*]})" |
---|
354 | for logiciel in "${required_soft[@]}"; do |
---|
355 | if [[ $(which "$logiciel") = "" ]]; then |
---|
356 | echo "You must first install $logiciel on your system"; exit 1 |
---|
357 | fi |
---|
358 | done |
---|
359 | } |
---|
360 | |
---|
361 | function download_modipsl_tar { |
---|
362 | if [[ $clean_install = 1 ]]; then rm -rf "$MODEL"; fi |
---|
363 | |
---|
364 | mkdir -p "$MODEL" |
---|
365 | MODEL=$(readlink -e -f "$MODEL"); echo "MODEL: $MODEL" # absolute path |
---|
366 | if [[ ! -d "$MODEL/modipsl" ]]; then |
---|
367 | echo "Downloading a slightly modified version of modipsl+LMDZ" |
---|
368 | cd "$MODEL" |
---|
369 | getlog="$(pwd)/get.log" |
---|
370 | echo "logfile : $getlog" |
---|
371 | set +e; myget "src_archives/$trusting/modipsl.$version.tar.gz" &>> "$getlog"; set -e |
---|
372 | if [[ ! -f "modipsl.$version.tar.gz" ]]; then |
---|
373 | echo "STOP: failed to download modipsl. $getlog: <$(tail "$getlog")>"; exit 1 |
---|
374 | fi |
---|
375 | echo "install_lmdz.sh wget_OK $(date)" |
---|
376 | |
---|
377 | gunzip "modipsl.$version.tar.gz" &>> get.log |
---|
378 | tar xf "modipsl.$version.tar" &>> get.log |
---|
379 | rm "modipsl.$version.tar" |
---|
380 | fi |
---|
381 | } |
---|
382 | |
---|
383 | function init_arch { |
---|
384 | cd "$local" |
---|
385 | set +e; arch_dir=$(readlink -f "$arch_dir"); set -e # full path. readlink must be called *after* the path is created |
---|
386 | |
---|
387 | # Check where default fcm, path, env are located - by default in $arch_path, instead in $MODEL/modipsl/modeles/LMDZ/arch/ |
---|
388 | local i fcm_path path_path env_path |
---|
389 | for i in "path" "fcm" "env"; do |
---|
390 | local varname=${i}_path |
---|
391 | if [[ -f $arch_dir/arch-$arch.$i ]]; then |
---|
392 | declare $varname="$arch_dir/arch-$arch.$i" |
---|
393 | else |
---|
394 | declare $varname="$MODEL/modipsl/modeles/LMDZ/arch/arch-$arch.$i" |
---|
395 | if [[ ! -f ${!varname} ]]; then |
---|
396 | echo "STOP: no ${!varname}"; exit 1 |
---|
397 | fi |
---|
398 | fi |
---|
399 | done |
---|
400 | default_fcm_path=$fcm_path |
---|
401 | default_path_path=$path_path |
---|
402 | default_env_path=$env_path |
---|
403 | |
---|
404 | # check compiler |
---|
405 | compiler=$(< "$default_fcm_path" grep "%COMPILER" | sed -e "s/%COMPILER\s*//") |
---|
406 | |
---|
407 | # load env |
---|
408 | # shellcheck disable=SC1090 |
---|
409 | if [[ -f $default_env_path ]]; then source "$default_env_path"; fi |
---|
410 | |
---|
411 | local mpi_file # can't be done before as it depends on sourcing the env |
---|
412 | mpi_file=$(readlink -e -f "$(which mpif90)") |
---|
413 | path_mpi=$(dirname "$mpi_file") |
---|
414 | root_mpi=$(dirname "$path_mpi") |
---|
415 | } |
---|
416 | |
---|
417 | function check_compiler { |
---|
418 | # Must be called after init_arch to know which compiler to use |
---|
419 | cat <<eod > tt.f90 |
---|
420 | print*,'coucou' |
---|
421 | end |
---|
422 | eod |
---|
423 | $compiler tt.f90 || a.out |
---|
424 | ./a.out >| tt |
---|
425 | if [[ $(< tt sed -e 's/ //g' ) != "coucou" ]]; then |
---|
426 | echo "problem installing with compiler $compiler"; exit 1 |
---|
427 | fi |
---|
428 | rm tt a.out tt.f90 |
---|
429 | } |
---|
430 | |
---|
431 | function install_arch { |
---|
432 | local component=$1 |
---|
433 | |
---|
434 | # Use same .env for all components (for module compatibility) |
---|
435 | cp -f "$default_env_path" "$MODEL/modipsl/modeles/$component/arch" &> /dev/null || true # allow failure if we're copying the file to itself |
---|
436 | |
---|
437 | # Use local .path and .fcm if available, otherwise default |
---|
438 | if [[ ! -f "$MODEL/modipsl/modeles/$component/arch/arch-$arch.path" ]]; then |
---|
439 | cp -f "$default_path_path" "$MODEL/modipsl/modeles/$component/arch" |
---|
440 | |
---|
441 | if [[ $component = "ORCHIDEE" ]]; then |
---|
442 | if [[ $orcbranch = "/tags/ORCHIDEE_2_0/ORCHIDEE" ]]; then # 2.0 and before have a different fcm convention |
---|
443 | sed -i'' -e "s/-I//" -e "s/-L//" "$MODEL/modipsl/modeles/ORCHIDEE/arch/arch-$arch.path" # /!\ we only replace first occurence on purpose |
---|
444 | fi |
---|
445 | fi |
---|
446 | fi |
---|
447 | if [[ ! -f "$MODEL/modipsl/modeles/$component/arch/arch-$arch.fcm" ]]; then |
---|
448 | cp -f "$default_fcm_path" "$MODEL/modipsl/modeles/$component/arch" |
---|
449 | |
---|
450 | if [[ $component = "XIOS" ]]; then |
---|
451 | # Adapt for XIOS, which uses different naming conventions |
---|
452 | sed -i'' -e "s/%COMPILER/%FCOMPILER/" -e "s/%LINK/%LINKER/" -e "s/-fdefault-real-8//" "$MODEL/modipsl/modeles/XIOS/arch/arch-$arch.fcm" |
---|
453 | fi |
---|
454 | fi |
---|
455 | } |
---|
456 | |
---|
457 | function install_netcdf { |
---|
458 | echo "Installing Netcdf" |
---|
459 | local ncdf_compiler="$compiler" |
---|
460 | |
---|
461 | if [[ $netcdf = 0 ]]; then |
---|
462 | ncdfdir=$(nf-config --prefix) |
---|
463 | else |
---|
464 | cd "$MODEL" |
---|
465 | |
---|
466 | # Convert non-basic compiler |
---|
467 | case $compiler in |
---|
468 | mpif90) ncdf_compiler=$($compiler --version | head -n 1 | cut -d " " -f -1) |
---|
469 | esac |
---|
470 | |
---|
471 | case $ncdf_compiler in |
---|
472 | gfortran | GNU) ncdf_compiler="gfortran"; opt1="-compiler gnu"; opt2="-CC gcc -FC gfortran -CXX g++";; |
---|
473 | *) echo "unexpected compiler $ncdf_compiler for netcdf"; exit 1 |
---|
474 | esac |
---|
475 | |
---|
476 | case $with_xios in |
---|
477 | 0) script_install_netcdf="install_netcdf4_hdf5_seq.bash" |
---|
478 | ncdfdir="netcdf4_hdf5_seq" |
---|
479 | opt_="$opt1";; |
---|
480 | 1) script_install_netcdf="install_netcdf4_hdf5.bash" |
---|
481 | ncdfdir="netcdf4_hdf5" |
---|
482 | opt_="$opt2 -MPI $root_mpi";; |
---|
483 | *) echo "with_xios=$with_xios, should be 0 or 1"; exit 1 |
---|
484 | esac |
---|
485 | if [[ $netcdf = 1 ]]; then |
---|
486 | ncdfdir="$MODEL/$ncdfdir" |
---|
487 | else |
---|
488 | mkdir -p "$netcdf"; ncdfdir="$netcdf/$ncdfdir" |
---|
489 | fi |
---|
490 | |
---|
491 | echo "Repertoire netcdf $ncdfdir" |
---|
492 | if [[ ! -d $ncdfdir ]]; then |
---|
493 | netcdflog=$(pwd)/netcdf.log |
---|
494 | echo "----------------------------------------------------------" |
---|
495 | echo "Compiling the Netcdf library" |
---|
496 | echo "----------------------------------------------------------" |
---|
497 | echo "log file : $netcdflog" |
---|
498 | myget script_install/$script_install_netcdf &>> "$netcdflog" |
---|
499 | chmod u=rwx $script_install_netcdf |
---|
500 | # shellcheck disable=SC2086 |
---|
501 | ./$script_install_netcdf -prefix "$ncdfdir" $opt_ &>> "$netcdflog" |
---|
502 | fi |
---|
503 | |
---|
504 | # Add to path |
---|
505 | export PATH="$ncdfdir/bin:$PATH" |
---|
506 | echo "Bin PATH" $PATH |
---|
507 | |
---|
508 | #---------------------------------------------------------------------------- |
---|
509 | # LF rajout d'une verrue, pour une raison non encore expliquee, |
---|
510 | # la librairie est parfois rangée dans lib64 et non dans lib |
---|
511 | # par certains compilateurs |
---|
512 | if [[ ! -e lib && -d lib64 ]]; then ln -s lib64 lib; fi |
---|
513 | #---------------------------------------------------------------------------- |
---|
514 | |
---|
515 | echo "install_lmdz.sh netcdf_OK $(date)" |
---|
516 | fi |
---|
517 | |
---|
518 | cat >test_netcdf90.f90 <<EOF |
---|
519 | use netcdf |
---|
520 | print *, "NetCDF library version: ", nf90_inq_libvers() |
---|
521 | end |
---|
522 | EOF |
---|
523 | |
---|
524 | if $ncdf_compiler -I"$ncdfdir"/include test_netcdf90.f90 -L"$ncdfdir"/lib -lnetcdff -lnetcdf -Wl,-rpath="$ncdfdir"/lib && ./a.out; then |
---|
525 | rm test_netcdf90.f90 a.out |
---|
526 | else |
---|
527 | cat <<EOF |
---|
528 | Failed test program using NetCDF-Fortran. You can: |
---|
529 | - check that you have NetCDF-Fortran installed in your system |
---|
530 | - or specify an installation directory with option -netcdf of install_lmdz.sh |
---|
531 | - or download and compile NetCDF-Fortran with option -netcdf 1 of install_lmdz.sh |
---|
532 | EOF |
---|
533 | exit 1 |
---|
534 | fi |
---|
535 | |
---|
536 | # Compile NetCDF95 |
---|
537 | cd "$MODEL/modipsl/modeles/LMD"* |
---|
538 | echo "Installing NetCDF95" |
---|
539 | cd "$MODEL" |
---|
540 | if [[ ! -d "NetCDF95-0.3" ]]; then |
---|
541 | myget src_archives/netcdf/NetCDF95-0.3.tar.gz |
---|
542 | tar -xf NetCDF95-0.3.tar.gz |
---|
543 | rm NetCDF95-0.3.tar.gz |
---|
544 | cd NetCDF95-0.3 |
---|
545 | mkdir -p build && cd build |
---|
546 | 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" |
---|
547 | make install |
---|
548 | fi |
---|
549 | } |
---|
550 | |
---|
551 | function install_IOIPSL { |
---|
552 | install_arch "IOIPSL" |
---|
553 | |
---|
554 | cd "$MODEL/modipsl/modeles/IOIPSL" |
---|
555 | ioipsllog="$(pwd)/ioipsl.log" |
---|
556 | echo "Compiling IOIPSL, the interface library with Netcdf $(date) (log: $ioipsllog)" |
---|
557 | # in case ksh is not installed on the pc |
---|
558 | if [[ ! -x /bin/ksh ]]; then |
---|
559 | sed -i'' -e 's/ksh/bash/' ins_m_prec |
---|
560 | fi |
---|
561 | echo "$jobcmd ./makeioipsl_fcm -j $make_j -arch $arch $optim_flag" > compile.sh |
---|
562 | chmod +x compile.sh |
---|
563 | echo "Compiling IOIPSL using $(\cat compile.sh)" |
---|
564 | if ! ./compile.sh &> "$ioipsllog"; then |
---|
565 | echo "STOP: IOIPSL compile failed, exiting"; exit 1 |
---|
566 | fi |
---|
567 | |
---|
568 | # Link to modipsl/bin |
---|
569 | cp -f bin/* ../../bin |
---|
570 | |
---|
571 | echo "IOIPSL compiled $(date)" |
---|
572 | } |
---|
573 | |
---|
574 | function install_XIOS { |
---|
575 | if [[ $with_xios = 1 ]]; then |
---|
576 | cd "$MODEL/modipsl/modeles" |
---|
577 | xioslog="$(pwd)/XIOS/xios.log" |
---|
578 | echo "##########################################################" |
---|
579 | echo "Compiling XIOS (log $xioslog) $(date)" |
---|
580 | echo "##########################################################" |
---|
581 | |
---|
582 | # Download XIOS |
---|
583 | local xios_http="http://forge.ipsl.fr/ioserver/svn/XIOS2/branches/xios-2.6" |
---|
584 | local xios_rev="2568" |
---|
585 | |
---|
586 | cd "$MODEL/modipsl/modeles" |
---|
587 | set +e; svn co -r $xios_rev $xios_http XIOS; set -e |
---|
588 | |
---|
589 | cd XIOS |
---|
590 | |
---|
591 | install_arch "XIOS" |
---|
592 | do_compile_sh "XIOS" "$jobcmd ./make_xios --job $make_j --arch $arch" |
---|
593 | fi |
---|
594 | } |
---|
595 | |
---|
596 | function get_orchidee_version { # Set / Check ORCHIDEE version |
---|
597 | echo "Checking Orchidee source version" |
---|
598 | local fetch_rev="" |
---|
599 | orcbranch="" |
---|
600 | case $veget in |
---|
601 | "none") fcm_veget_version="false";; |
---|
602 | "orch2.0" | "CMIP6") fcm_veget_version=orchidee2.0; fetch_rev=7906;; # in previous tar we used 6592 but with some modifications to xios_orchidee.f90, which got integrated in 7906 |
---|
603 | "orch2.2") fcm_veget_version=orchidee2.1; orcbranch="/branches/ORCHIDEE_2_2/ORCHIDEE" ;; # the bundled version |
---|
604 | *) fetch_rev=$veget; fcm_veget_version=orchidee2.1;; # /!\ arbitary rev only works for orch>=2.1 |
---|
605 | # /!\ Note: for orch>=4, we should be using fcm_vegt_version="orchideetrunk". Below copied comment by Adriana in LMDZ_Setup docs: |
---|
606 | # Avec orchidee2.1, on va compiler LMDZ avec le cle cpp ORCHIDEE_NOLIC. On ne va donc pas prendre en compte les avancements fait dans le trunk qui permet que les fractions lic soitent traité par ORCHIDEE. Ca marche très bien sans cela puisque dans tout façon c'est en cours de développement et ce n'est pas activé par default. En fait on devrait compiler le trunk avec -v orchideetrunk mais avec landice_opt>2, ce qui ne change rien par rapport à orchidee2.1 |
---|
607 | #Si on voudrait activer landice_opt=2 , il faut compiler avec -v orchideetrunk. |
---|
608 | |
---|
609 | esac |
---|
610 | |
---|
611 | if [[ -n $fetch_rev ]]; then |
---|
612 | echo "IF YOU INSTALL ORCHIDEE THE VERY FIRST TIME, ASK for PASSWORD at orchidee-help@listes.ipsl.fr" |
---|
613 | local curr_rev |
---|
614 | curr_rev=$(svn info "$MODEL/modipsl/modeles/ORCHIDEE" | grep Revision: | cut -d ":" -f 2 | cut -c 2-) |
---|
615 | orcbranch=$(svn log -v -q svn://forge.ipsl.fr/orchidee/ -r "$fetch_rev" | grep ORCHIDEE | head -1 | sed -e 's:ORCHIDEE/.*$:ORCHIDEE:' | awk '{print $2}') |
---|
616 | if [[ $fetch_rev != "$curr_rev" ]]; then |
---|
617 | echo "Fetching orch $fetch_rev from the repository (curr: $curr_rev)" |
---|
618 | echo "branch is $orcbranch" |
---|
619 | if [[ $fetch_rev -lt 4465 ]]; then echo 'ORCHIDEE version must be >=4465, exiting'; exit 1; fi |
---|
620 | cd "$MODEL/modipsl/modeles" |
---|
621 | rm -rf ORCHIDEE |
---|
622 | svn co -r "$fetch_rev" "svn://forge.ipsl.fr/orchidee/$orcbranch" |
---|
623 | cd - > /dev/null |
---|
624 | fi |
---|
625 | fi |
---|
626 | |
---|
627 | # Check parallel LMDZ+ORCH |
---|
628 | if [[ (! $veget = "none") && $parallel = "none" && ($used_lmdz_rev -lt 4894) ]]; then |
---|
629 | echo "LMDZ revision must be >=4894 for orchidee without parallel support. Upgrade lmdz or use -parallel mpi_omp."; exit 1 |
---|
630 | fi |
---|
631 | } |
---|
632 | |
---|
633 | function compile_orchidee { |
---|
634 | install_arch "ORCHIDEE" |
---|
635 | |
---|
636 | if [[ $veget != "none" ]]; then |
---|
637 | cd "$MODEL/modipsl/modeles/ORCHIDEE" |
---|
638 | |
---|
639 | local xios_orchid |
---|
640 | if [[ $with_xios = 1 ]]; then |
---|
641 | xios_orchid="-xios"; |
---|
642 | else |
---|
643 | xios_orchid="-noxios" |
---|
644 | fi |
---|
645 | |
---|
646 | if [[ $parallel != "none" && ! -d src_parallel ]]; then |
---|
647 | echo "STOP: Orchidee version too old for parallel support"; exit 1 |
---|
648 | fi |
---|
649 | do_compile_sh "ORCHIDEE" "$jobcmd ./makeorchidee_fcm -j $make_j $xios_orchid $optim_flag -parallel $parallel -arch $arch" |
---|
650 | fi |
---|
651 | } |
---|
652 | |
---|
653 | function get_lmdz_version { |
---|
654 | echo "Checking LMDZ source version" |
---|
655 | LMDZPATH=$(readlink -e -f "$MODEL/modipsl/modeles/LMD"*) |
---|
656 | cd "$LMDZPATH" |
---|
657 | |
---|
658 | if [[ -n $svn_lmdz ]]; then |
---|
659 | local curr_rev |
---|
660 | curr_rev=$(svn info "$MODEL/modipsl/modeles/LMD"* | grep Revision: | cut -d ":" -f 2 | cut -c 2-) |
---|
661 | if [[ $svn_lmdz != "$curr_rev" ]]; then |
---|
662 | local lmdzbranch |
---|
663 | echo "Fetching LMDZ $svn_lmdz from the repository" |
---|
664 | lmdzbranch=$(get_svn_branch "https://svn.lmd.jussieu.fr/LMDZ" "$svn_lmdz") |
---|
665 | echo "branch is $lmdzbranch" |
---|
666 | cd "$MODEL/modipsl/modeles" |
---|
667 | rm -rf LMD* |
---|
668 | svn co -r "$svn_lmdz" "https://svn.lmd.jussieu.fr/LMDZ/$lmdzbranch" LMDZ |
---|
669 | cd - > /dev/null |
---|
670 | fi |
---|
671 | used_lmdz_rev=$svn_lmdz |
---|
672 | else # get svn from info |
---|
673 | set +e; used_lmdz_rev=$(svn info | grep "Last Changed Rev" | cut -c 19-); set -e |
---|
674 | if [[ -z $used_lmdz_rev ]]; then # svn info failed |
---|
675 | used_lmdz_rev=$(grep 'Revision: [0-9]' "$MODEL"/Read*.md | awk ' { print $2 } ' 2>/dev/null) |
---|
676 | if [[ -z $used_lmdz_rev ]]; then echo "Could not determine lmdz version. This is likely an issue with the .tar itself, please report to LMDZ team."; exit 1; fi |
---|
677 | fi |
---|
678 | fi |
---|
679 | } |
---|
680 | |
---|
681 | function compile_lmdz { |
---|
682 | install_arch "LMDZ" |
---|
683 | cd "$LMDZPATH" |
---|
684 | |
---|
685 | if [[ $used_lmdz_rev -le 4185 ]]; then |
---|
686 | exe_name="bin/${fortran_file}_${grid_resolution}_phy${compphysiq}_${suff_para}${suff_orc}${suff_aer}${suff_iso}.e" |
---|
687 | else |
---|
688 | exe_name="bin/${fortran_file}_${grid_resolution}_phy${compphysiq}_${rad}${suff_para}${suff_orc}${suff_aer}${suff_iso}.e" |
---|
689 | fi |
---|
690 | |
---|
691 | local opt_rad |
---|
692 | case $rad in |
---|
693 | oldrad) iflag_rrtm=0; NSW=2; opt_rad="";; |
---|
694 | rrtm) iflag_rrtm=1; NSW=6 |
---|
695 | if [[ $used_lmdz_rev -le 4185 ]]; then |
---|
696 | opt_rad="-rrtm true" |
---|
697 | else |
---|
698 | opt_rad="-rad rrtm" |
---|
699 | fi;; |
---|
700 | ecrad) iflag_rrtm=2; NSW=6; opt_rad="-rad ecrad";; |
---|
701 | *) echo "Only oldrad rrtm ecrad for rad option"; exit 1 |
---|
702 | esac |
---|
703 | if [[ $used_lmdz_rev -le 4185 && $rad = "ecrad" ]]; then |
---|
704 | echo "ecrad only available for LMDZ rev starting with 4186 "; exit 1 |
---|
705 | fi |
---|
706 | |
---|
707 | # Compile |
---|
708 | local makelmdz="makelmdz_fcm $optim_flag -arch $arch -j $make_j" |
---|
709 | local para_compile_opt="-mem -parallel $parallel"; if [[ $parallel = "none" ]]; then para_compile_opt=""; fi |
---|
710 | do_compile_sh "LMDZ" "$jobcmd ./$makelmdz $opt_rad $opt_cosp $opt_makelmdz_xios $opt_aer $opt_inlandsis $opt_strataer $opt_isotopes -p $compphysiq -d ${grid_resolution} -v $fcm_veget_version $para_compile_opt $fortran_file" |
---|
711 | |
---|
712 | # Check executable |
---|
713 | if [[ ! -f $exe_name ]]; then |
---|
714 | echo "STOP: Compilation failed, can't find the executable"; exit 1 |
---|
715 | else |
---|
716 | echo "Compilation successful, the executable is $exe_name $(date)" |
---|
717 | fi |
---|
718 | } |
---|
719 | |
---|
720 | function get_dynamico_icosa_version { |
---|
721 | if [[ $icolmdz = 1 ]]; then |
---|
722 | echo "Checking DYNAMICO source version" |
---|
723 | cd "$MODEL/modipsl/modeles" |
---|
724 | if [[ ! -d DYNAMICO ]]; then |
---|
725 | git clone https://gitlab.in2p3.fr/ipsl/projets/dynamico/dynamico.git DYNAMICO |
---|
726 | fi |
---|
727 | cd DYNAMICO |
---|
728 | git checkout master && git checkout $dynamico_commit |
---|
729 | cd - > /dev/null |
---|
730 | |
---|
731 | echo "Checking ICOSA_LMDZ source version" |
---|
732 | if [[ ! -d ICOSA_LMDZ ]]; then |
---|
733 | svn checkout http://svn.lmd.jussieu.fr/LMDZ/ICOSA_LMDZ |
---|
734 | fi |
---|
735 | cd ICOSA_LMDZ |
---|
736 | svn up -r 5320 |
---|
737 | fi |
---|
738 | } |
---|
739 | |
---|
740 | function compile_icolmdzor { |
---|
741 | if [[ $icolmdz = 1 ]]; then |
---|
742 | install_arch "ICOSA_LMDZ" |
---|
743 | local para_compile_opt="-parallel $parallel"; if [[ $parallel = "none" ]]; then para_compile_opt=""; fi |
---|
744 | |
---|
745 | # LMDZ physics package library already available in LMDZ/config/lib directory |
---|
746 | |
---|
747 | # Compile DYNAMICO |
---|
748 | cd "$MODEL/modipsl/modeles/DYNAMICO" |
---|
749 | |
---|
750 | # Need to get rather than install the archs as DYNAMICO uses FCMv2 that does not understand the makefile syntax ($shell) |
---|
751 | cd arch |
---|
752 | wget "http://lmdz.lmd.jussieu.fr/pub/src_archives/misc/arch/DYNAMICO/arch-$arch.env" |
---|
753 | wget "http://lmdz.lmd.jussieu.fr/pub/src_archives/misc/arch/DYNAMICO/arch-$arch.fcm" |
---|
754 | wget "http://lmdz.lmd.jussieu.fr/pub/src_archives/misc/arch/DYNAMICO/arch-$arch.path" |
---|
755 | cd .. |
---|
756 | |
---|
757 | do_compile_sh "DYNAMICO" "$jobcmd ./make_icosa $optim_flag -arch $arch -job $make_j $para_compile_opt -external_ioipsl -with_xios" |
---|
758 | |
---|
759 | # Compile icosa_lmdz |
---|
760 | echo "Bin PATH before icosalmdz" "$PATH" |
---|
761 | cd "$MODEL/modipsl/modeles/ICOSA_LMDZ" |
---|
762 | do_compile_sh "ICOSA_LMDZ" "$jobcmd ./make_icosa_lmdz -arch $arch -j $make_j -nodeps -p lmd $optim_flag $para_compile_opt -with_orchidee" |
---|
763 | echo "# Running environment for icosa_lmdz" > icosalmdz.env |
---|
764 | echo "# " >> icosalmdz.env |
---|
765 | if [[ -v LD_LIBRARY_PATH ]]; then |
---|
766 | echo "export LD_LIBRARY_PATH=$ncdfdir/lib:$LD_LIBRARY_PATH" >> icosalmdz.env |
---|
767 | else |
---|
768 | echo "export LD_LIBRARY_PATH=$ncdfdir/lib" >> icosalmdz.env |
---|
769 | fi |
---|
770 | fi |
---|
771 | } |
---|
772 | |
---|
773 | function run_bench { |
---|
774 | local bench_cmd="./bench.sh" |
---|
775 | |
---|
776 | cd "$MODEL/modipsl/modeles/LMDZ"* |
---|
777 | |
---|
778 | if [[ $bench = "tuto" ]]; then |
---|
779 | myget "Training/tutorial.tar"; tar xf tutorial.tar; cd TUTORIAL |
---|
780 | ./init.sh |
---|
781 | elif [[ $bench = 1 ]]; then |
---|
782 | rm -rf "BENCH${grid_resolution}" |
---|
783 | local bench=bench_lmdz_${grid_resolution} |
---|
784 | if [[ $compphysiq = "lmdiso" ]]; then bench=bench_lmdz_iso_${grid_resolution}; fi |
---|
785 | |
---|
786 | if [[ $is_1D = "y" ]] ; then # 1D |
---|
787 | myget "1D/1D.tar.gz" |
---|
788 | mkdir -p "BENCH${grid_resolution}" |
---|
789 | tar xf "1D.tar.gz" -C "BENCH${grid_resolution}" --strip-components=1 |
---|
790 | cd "BENCH${grid_resolution}" |
---|
791 | # Below: ugly, but until we rewrite the 1D case... |
---|
792 | sed -i'' -e "s:^listecas=.*$:listecas=ARMCU/REF:" -e "s:cd \$local/bin ; ./compile -L \$L:#cd \$local/bin ; ./compile -L \$L:" \ |
---|
793 | -e "s:./compile -L \$llm:#./compile -L \$llm:" -e "s:ln -sf \$bin/\\\\\${main}\${suffixe}.e .:ln -sf ../../../../../$exe_name \\\\\${main}\${suffixe}.e:" -e "s:gzip listing:cp listing restartphy.nc ../../../../; exit 0:" \ |
---|
794 | run.sh |
---|
795 | cp "../$exe_name" bin/ |
---|
796 | bench_cmd="./run.sh -rad $rad" # suppress ferret commands that launch after bench is "over" |
---|
797 | else |
---|
798 | myget "3DBenchs/$bench.tar.gz" |
---|
799 | mkdir "BENCH${grid_resolution}" |
---|
800 | tar xf "$bench.tar.gz" -C "BENCH${grid_resolution}" --strip-components=1 |
---|
801 | |
---|
802 | if [[ $cosp = "v1" || $cosp = "v2" ]]; then |
---|
803 | cd "BENCH${grid_resolution}" |
---|
804 | # copier les fichiers namelist input et output our COSP |
---|
805 | cp ../DefLists/cosp*_input_nl.txt . |
---|
806 | cp ../DefLists/cosp*_output_nl.txt . |
---|
807 | # Activer la cles ok_cosp pour tourner avec COSP |
---|
808 | sed -e 's@ok_cosp=n@ok_cosp=y@' config.def > tmp |
---|
809 | \mv -f tmp config.def |
---|
810 | cd .. |
---|
811 | fi |
---|
812 | |
---|
813 | if [[ -n "$benchphysiq" ]]; then |
---|
814 | cd "BENCH${grid_resolution}" |
---|
815 | if [[ -f "physiq.def_${benchphysiq}" ]]; then |
---|
816 | cp "physiq.def_${benchphysiq}" benchphysiq.def |
---|
817 | echo "using physiq.def_${benchphysiq}" |
---|
818 | else |
---|
819 | echo "using standard physiq.def" |
---|
820 | fi |
---|
821 | cd .. |
---|
822 | else |
---|
823 | echo "using standard physiq.def" |
---|
824 | fi |
---|
825 | |
---|
826 | if [[ $with_xios = 1 ]]; then |
---|
827 | cd "BENCH${grid_resolution}" |
---|
828 | cp ../DefLists/iodef.xml . |
---|
829 | cp ../DefLists/context_lmdz.xml . |
---|
830 | cp ../DefLists/field_def_lmdz.xml . |
---|
831 | # A raffiner par la suite |
---|
832 | echo "A FAIRE : Copier les *xml en fonction de l option cosp" |
---|
833 | cp ../DefLists/field_def_cosp*.xml . |
---|
834 | cp ../DefLists/file_def_hist*xml . |
---|
835 | # adapt iodef.xml to use attached mode |
---|
836 | sed -e 's@"using_server" type="bool">true@"using_server" type="bool">false@' \ |
---|
837 | iodef.xml > tmp |
---|
838 | \mv -f tmp iodef.xml |
---|
839 | |
---|
840 | # and convert all the enabled="_AUTO_" (for libIGCM) to enabled=.FALSE. |
---|
841 | # except for histday |
---|
842 | for histfile in file_def_hist*xml; do |
---|
843 | if [[ "$histfile" = "file_def_histday_lmdz.xml" ]]; then |
---|
844 | sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".TRUE."@' \ |
---|
845 | "$histfile" > tmp |
---|
846 | \mv -f tmp "$histfile" |
---|
847 | sed -e 's@output_level="_AUTO_"@output_level="5"@' "$histfile" \ |
---|
848 | > tmp |
---|
849 | \mv -f tmp "$histfile" |
---|
850 | sed -e 's@compression_level="2"@compression_level="0"@' \ |
---|
851 | "$histfile" > tmp |
---|
852 | \mv -f tmp "$histfile" |
---|
853 | else |
---|
854 | sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \ |
---|
855 | "$histfile" > tmp |
---|
856 | \mv -f tmp "$histfile" |
---|
857 | fi |
---|
858 | done |
---|
859 | # and add option "ok_all_xml=y" in config.def |
---|
860 | echo "### XIOS outputs" >> config.def |
---|
861 | echo 'ok_all_xml=.true.' >> config.def |
---|
862 | |
---|
863 | #activer les sorties pour Cosp |
---|
864 | if [[ "$cosp" = "v1" ]]; then |
---|
865 | sed -i'' -e 's@enabled=".FALSE."@enabled=".TRUE."@' \ |
---|
866 | -e 's@output_level="_AUTO_"@output_level="5"@' \ |
---|
867 | -e 's@compression_level="2"@compression_level="0"@' \ |
---|
868 | file_def_histdayCOSP_lmdz.xml |
---|
869 | fi |
---|
870 | if [[ "$cosp" = "v2" ]]; then |
---|
871 | sed -i'' -e 's@compression_level="2"@compression_level="0"@' file_def_histdayCOSPv2_lmdz.xml |
---|
872 | for type_ in hf day mth; do |
---|
873 | file=file_def_hist${type_}COSP |
---|
874 | sed -i'' -e 's@src="./'${file}'_lmdz.xml"@src="./'${file}'v2_lmdz.xml"@' context_lmdz.xml |
---|
875 | done |
---|
876 | sed -i'' -e 's@field_def_cosp1.xml@field_def_cospv2.xml@' field_def_lmdz.xml |
---|
877 | fi |
---|
878 | |
---|
879 | cd .. |
---|
880 | fi |
---|
881 | |
---|
882 | # Cas Bench avec ecrad |
---|
883 | if [[ $rad = "ecrad" ]]; then |
---|
884 | cd "BENCH${grid_resolution}" |
---|
885 | cp ../DefLists/namelist_ecrad . |
---|
886 | cp -r ../libf/phylmd/ecrad/data . |
---|
887 | cd .. |
---|
888 | fi |
---|
889 | |
---|
890 | # Adjusting bench physiq.def to radiative code chosen |
---|
891 | cd "BENCH${grid_resolution}" |
---|
892 | sed -e 's/iflag_rrtm=.*.$/iflag_rrtm='$iflag_rrtm'/' \ |
---|
893 | -e 's/NSW=.*.$/NSW='$NSW'/' physiq.def > tmpdef |
---|
894 | \mv tmpdef physiq.def |
---|
895 | cd .. |
---|
896 | |
---|
897 | cp "$exe_name" "BENCH${grid_resolution}/gcm.e" |
---|
898 | cd "BENCH${grid_resolution}" |
---|
899 | |
---|
900 | if [[ ${parallel:0:3} = "mpi" ]]; then |
---|
901 | # Lancement avec deux procs mpi et 2 openMP |
---|
902 | echo "export OMP_STACKSIZE=800M" > bench.sh |
---|
903 | if [[ "${parallel:4:3}" = "omp" ]]; then |
---|
904 | echo "export OMP_NUM_THREADS=2" >> bench.sh |
---|
905 | fi |
---|
906 | if [[ $cosp = "v1" || $cosp = "v2" ]]; then |
---|
907 | echo "ulimit -s 200000" >> bench.sh |
---|
908 | else |
---|
909 | echo "ulimit -s unlimited" >> bench.sh |
---|
910 | fi |
---|
911 | if which mpirun &> /dev/null; then |
---|
912 | echo "mpirun -np 2 gcm.e &> listing" >> bench.sh |
---|
913 | elif grep -q "Adastra" /etc/motd; then |
---|
914 | local account |
---|
915 | account=$(/usr/sbin/my_project.py -l 2>&1 | head -1 | cut -d " " -f 3- | cut -c 5-) |
---|
916 | bench_cmd="srun --nodes=1 --ntasks=1 --cpus-per-task=2 --threads-per-core=2 --time=0:10:00 --constraint=GENOA --account=$account bash bench.sh" |
---|
917 | echo "./gcm.e &> listing" >> bench.sh |
---|
918 | else |
---|
919 | echo "Error: No command found to run parallel bench"; exit 1 |
---|
920 | fi |
---|
921 | if [[ $(hostname | cut -c -6) = "spirit" ]]; then # ulimit unlimited segfaults on Spirit |
---|
922 | sed -i'' "s/ulimit -s unlimited/ulimit -Ss 8000/" bench.sh |
---|
923 | fi |
---|
924 | # Add rebuild, using reb.sh if it is there |
---|
925 | cat <<EOF >> bench.sh |
---|
926 | if [[ -f reb.sh ]]; then |
---|
927 | ./reb.sh histday; ./reb.sh histmth; ./reb.sh histhf; |
---|
928 | ./reb.sh histins; ./reb.sh stomate_history; |
---|
929 | ./reb.sh sechiba_history; ./reb.sh sechiba_out_2 |
---|
930 | fi |
---|
931 | EOF |
---|
932 | else |
---|
933 | echo "./gcm.e &> listing" > bench.sh |
---|
934 | fi |
---|
935 | chmod +x bench.sh |
---|
936 | # Getting orchidee stuff |
---|
937 | if [[ $veget = 'CMIP6' || $veget = "orch2.0" ]]; then # TODO once we have a 2.2 bench, add it here (or in planned separate bench script) |
---|
938 | echo 'myget 3DBenchs/BENCHCMIP6.tar.gz' |
---|
939 | myget 3DBenchs/BENCHCMIP6.tar.gz |
---|
940 | tar xvzf BENCHCMIP6.tar.gz |
---|
941 | sed -e "s:VEGET=n:VEGET=y:" config.def > tmp |
---|
942 | mv -f tmp config.def |
---|
943 | if [[ $with_xios = 1 ]]; then |
---|
944 | cp ../../ORCHIDEE/src_xml/context_orchidee.xml . |
---|
945 | echo '<context id="orchidee" src="./context_orchidee.xml"/>' > add.tmp |
---|
946 | cp ../../ORCHIDEE/src_xml/field_def_orchidee.xml . |
---|
947 | cp ../../ORCHIDEE/src_xml/file_def_orchidee.xml . |
---|
948 | cp ../../ORCHIDEE/src_xml/file_def_input_orchidee.xml . |
---|
949 | if [[ -f ../../ORCHIDEE/src_xml/context_input_orchidee.xml ]]; then |
---|
950 | cp ../../ORCHIDEE/src_xml/context_input_orchidee.xml . |
---|
951 | echo '<context id="orchidee" src="./context_input_orchidee.xml"/>' >> add.tmp |
---|
952 | fi |
---|
953 | sed -e '/id="LMDZ"/r add.tmp' iodef.xml > tmp |
---|
954 | mv tmp iodef.xml |
---|
955 | sed -e'{/sechiba1/ s/enabled="_AUTO_"/type="one_file" enabled=".TRUE."/}' \ |
---|
956 | file_def_orchidee.xml > tmp |
---|
957 | \mv -f tmp file_def_orchidee.xml |
---|
958 | sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \ |
---|
959 | file_def_orchidee.xml > tmp |
---|
960 | \mv -f tmp file_def_orchidee.xml |
---|
961 | sed -e 's@output_level="_AUTO_"@output_level="1"@' \ |
---|
962 | file_def_orchidee.xml > tmp |
---|
963 | \mv -f tmp file_def_orchidee.xml |
---|
964 | sed -e 's@output_freq="_AUTO_"@output_freq="1d"@' \ |
---|
965 | file_def_orchidee.xml > tmp |
---|
966 | \mv -f tmp file_def_orchidee.xml |
---|
967 | sed -e 's@compression_level="4"@compression_level="0"@' \ |
---|
968 | file_def_orchidee.xml > tmp |
---|
969 | \mv -f tmp file_def_orchidee.xml |
---|
970 | sed -e 's@XIOS_ORCHIDEE_OK = n@XIOS_ORCHIDEE_OK = y@' \ |
---|
971 | orchidee.def > tmp |
---|
972 | \mv -f tmp orchidee.def |
---|
973 | fi |
---|
974 | fi |
---|
975 | |
---|
976 | fi |
---|
977 | |
---|
978 | if [[ -f ../arch.env ]]; then source ../arch.env; fi |
---|
979 | |
---|
980 | echo "STARTING BENCH" |
---|
981 | date |
---|
982 | if (! $bench_cmd &> out.bench) || ! (tail -n 1 listing | grep "Everything is cool"); then |
---|
983 | tail listing |
---|
984 | echo "Bench FAILED, exiting"; exit 1 |
---|
985 | fi |
---|
986 | date |
---|
987 | tail listing |
---|
988 | fi |
---|
989 | |
---|
990 | # 1D case |
---|
991 | if [[ $SCM = 1 ]]; then |
---|
992 | cd "$MODEL" |
---|
993 | myget 1D/1D.tar.gz |
---|
994 | tar xf 1D.tar.gz |
---|
995 | cd 1D |
---|
996 | for e in "fcm" "env" "path"; do |
---|
997 | cp "$MODEL/modipsl/modeles/LMDZ/arch/arch-$arch.$e" "$MODEL/modipsl/modeles/LMDZ/arch/arch-local.$e" |
---|
998 | done |
---|
999 | if [[ $rad = "oldrad" ]]; then |
---|
1000 | sed -i'' -e 's/^rad=.*$/rad=oldrad/' run.sh |
---|
1001 | sed -i'' -e 's/^rad=.*$/rad=oldrad/' bin/compile |
---|
1002 | elif [[ $rad = ecrad ]] ; then |
---|
1003 | sed -i'' -e 's/^rad=.*$/rad=ecrad/' run.sh |
---|
1004 | sed -i'' -e 's/^rad=.*$/rad=ecrad/' bin/compile |
---|
1005 | fi |
---|
1006 | echo "Running 1D/run.sh, log in $(pwd)/run1d.log" |
---|
1007 | ./run.sh &> "$(pwd)/run1d.log" |
---|
1008 | fi |
---|
1009 | } |
---|
1010 | |
---|
1011 | function run_bench_icosa { |
---|
1012 | local bench_cmd="./bench.sh" |
---|
1013 | |
---|
1014 | if [[ $icolmdz = 1 ]]; then |
---|
1015 | cd "$MODEL/modipsl/modeles/ICOSA_LMDZ" |
---|
1016 | if [[ $bench = 1 ]]; then |
---|
1017 | namebench="bench_icolmdz_nbp10_79" |
---|
1018 | rm -rf $namebench |
---|
1019 | myget "3DBenchs/$namebench.tar.gz" |
---|
1020 | mkdir -p $namebench |
---|
1021 | tar xf "$namebench.tar.gz" -C "$namebench" --strip-components=1 |
---|
1022 | cd $namebench |
---|
1023 | # copy executables |
---|
1024 | if [[ ! -x ../bin/icosa_lmdz.exe ]]; then |
---|
1025 | echo "STOP in icosa_lmdz bench, icosa_lmdz.exe executable not present"; exit 1 |
---|
1026 | fi |
---|
1027 | cp ../bin/icosa_lmdz.exe . |
---|
1028 | if [[ ! -x ../../XIOS/bin/xios_server.exe ]]; then |
---|
1029 | echo "STOP in icosa_lmdz bench, XIOS executable not present"; exit 1 |
---|
1030 | fi |
---|
1031 | cp ../../XIOS/bin/xios_server.exe . |
---|
1032 | echo "STARTING ICOSA_LMDZ BENCH" |
---|
1033 | date |
---|
1034 | if (! $bench_cmd &> out.bench) || ! ( grep "Time elapsed" listing); then |
---|
1035 | tail listing |
---|
1036 | echo "ICOSA_LMDZ bench FAILED, exiting"; exit 1 |
---|
1037 | fi |
---|
1038 | date |
---|
1039 | echo "ICOSA_LMDZ bench finished" |
---|
1040 | fi |
---|
1041 | fi |
---|
1042 | |
---|
1043 | } |
---|
1044 | # If sourced: returns, else run setup |
---|
1045 | if [[ ! "${BASH_SOURCE[0]}" = "$0" ]]; then return 0; fi |
---|
1046 | |
---|
1047 | echo "install_lmdz.sh DEBUT $(date)" |
---|
1048 | |
---|
1049 | set_default_params |
---|
1050 | read_cmdline_args "$@" |
---|
1051 | ensure_correct_option_combinations |
---|
1052 | download_modipsl_tar |
---|
1053 | get_lmdz_version |
---|
1054 | get_dynamico_icosa_version |
---|
1055 | get_orchidee_version |
---|
1056 | init_arch |
---|
1057 | check_available_software |
---|
1058 | check_compiler |
---|
1059 | install_netcdf |
---|
1060 | install_IOIPSL |
---|
1061 | install_XIOS |
---|
1062 | compile_orchidee |
---|
1063 | compile_lmdz |
---|
1064 | compile_icolmdzor |
---|
1065 | run_bench |
---|
1066 | run_bench_icosa |
---|