source: BOL/script_install/install_lmdz.sh @ 5538

Last change on this file since 5538 was 5538, checked in by fhourdin, 6 days ago

Checking failures in wget

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