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