source: BOL/script_install/install_lmdz.sh @ 5737

Last change on this file since 5737 was 5567, checked in by asima, 11 months ago

For Jean-Jay, do not install NetCDF95 next to modipsl.
netcdf95 is loaded as a module in the arch*.env
(also, minor : since a getlog variable is defined, let's use it :) )

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