source: BOL/script_install/install_lmdz.sh @ 5399

Last change on this file since 5399 was 5399, checked in by Laurent Fairhead, 2 days ago

forgot a test on the installation directory

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