source: BOL/script_install/install_lmdz.sh @ 5771

Last change on this file since 5771 was 5762, checked in by Laurent Fairhead, 5 months ago

Modifications brought about by new options in makelmdz_fcm
LF

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