source: BOL/script_install_amaury/install_lmdz.sh @ 5444

Last change on this file since 5444 was 5342, checked in by abarral, 4 weeks ago

Add message if modipsl tar retrieval fails

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