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