source: BOL/script_install_amaury/install_lmdz.sh @ 4914

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

Move fetching orch and lmdz earlier in the code
Allow lmdz version switch
Add check for lmdz version if orch in parallel
Remove explicit pgf90/ifort support
Add lmdz version to tests

  • Property svn:executable set to *
File size: 30.7 KB
Line 
1#!/bin/bash
2set -eu  # error on command failure, and on unset variables
3export LC_ALL=# standardize awk format
4
5###########################################################################
6# Author : Laurent Fairhead et Frédéric Hourdin
7# Usage  : install_lmdz.sh -help
8#
9# bash installation script of the LMDZ model on different computer types :
10# Linux PC, "mesocentre" (IPSL-UPMC, IPSL-X), super-computer (IDRIS)
11#
12# The model is downloaded in the following directory tree
13# $MODEL/modipsl/modeles/...
14# using the "modipsl" infrastructure created by the "IPSL"
15# for coupled (atmosphere/ocean/vegetation/chemistry) climate modeling
16# activities.
17# Here we only download atmospheric (LMDZ) and vegetation (ORCHIDEE)
18# components.
19#
20# The sources of the models can be found in the "modeles" directory.
21# In the present case, LMDZ, ORCHIDEE, and IOIPSL or XIOS (handling of
22# input-outputs using the NetCDF library).
23#
24# The script downloads various source files (including a version of NetCDF)
25# and utilities, compiles the model, and runs a test simulation in a
26# minimal configuration.
27#
28# Prerequisites : gfortran, bash or ksh, wget, gunzip, tar, ...
29#
30# Modif 18/11/2011
31#    changes for option real 8.
32#      We compile with -r8 (or equivalent) and -DNC_DOUBLE for the GCM
33#      but with -r4 for netcdf. Variable real must be set to
34#      r4 or r8 at the beginning of the script below.
35#
36###########################################################################
37
38### Functions
39
40function myget { # Get a file from LMDZ repository
41  local url=$1
42
43  local filename
44  filename=$(basename "$url")
45
46  wget --no-check-certificate -nv "http://lmdz.lmd.jussieu.fr/pub/$url"
47  if [[ $filename =~ .*\.(ba)?sh ]]; then chmod +x "$filename"; fi
48}
49
50function set_default_params {
51    # Valeur par défaut des parametres
52    svn_lmdz=""
53    version="20231022.trunk"
54
55    netcdf=1
56    bench=1
57    pcmac=0 # default: not on a Mac
58    SCM=0
59    veget="none"
60    grid_resolution="32x32x39"
61    physiq=""
62
63    xios_branch="2.6"
64    xios_rev="2568"
65
66    parallel="none"
67    trusting="testing"
68    MODEL=""
69
70    with_xios=0
71    opt_makelmdz_xios=""
72
73    rad="rrtm"
74
75    compile_with_fcm=1
76
77    cosp="none"
78    opt_cosp=""
79
80    make_j=8
81
82    # Check if on a Mac
83    if [[ $(uname) = "Darwin" ]]; then
84        pcmac=1
85        export MAKE="make"
86    fi
87
88    optim_debug=""
89    arch="local"
90
91    local mpi_file
92    mpi_file=$(readlink -f "$(which mpif90)")
93    path_mpi=$(dirname "$mpi_file")
94    root_mpi=$(dirname "$path_mpi")
95
96    arch="local-gfortran"
97    arch_dir=""
98}
99
100function read_cmdline_args {
101    while (($# > 0)); do
102        case $1 in
103            "-h") cat <<........fin
104        $0 [ -v version ] [ -r svn_release ]
105               [ -parallel PARA ] [ -d GRID_RESOLUTION ] [ -bench 0/1 ]
106               [-name LOCAL_MODEL_NAME] [-gprof] [-opt_makelmdz] [-rad RADIATIF]
107
108        -v       "version" like 20150828.trunk, see http://www.lmd.jussieu.fr/~lmdz/Distrib/LISMOI.trunk (default <$version>)
109
110        -r       "svn_release" : either the svn release number or "last" (default <$svn_lmdz>)
111
112        -parallel parallel support: mpi, omp, mpi_omp (mpi with openMP) or none (default: <$parallel>)
113
114        -d        "grid resolution": should be among the available benchs if -bench 1 (valid values: 48x36x19, 48x36x39) (default : <$grid_resolution>)
115
116        -bench     activating the bench or not (0/1) (default: <$bench>)
117
118        -testing/unstable
119
120        -name      name of the folder to install to (default <$MODEL>)
121
122        -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>)
123
124        -xios      use (download and compile) the XIOS library (will compile the parallel NetCDF4-HDF5 library) (requires to also have -parallel mpi_omp)
125
126        -cosp       to run with cospv1 or cospv2 [none/v1/v2] (default <$cosp>)
127
128        -rad        radiative code: oldrad, rrtm or ecrad (default <$rad>)
129
130        -nofcm      to compile without fcm
131
132        -SCM        install 1D version automatically
133
134        -debug      compile everything in debug mode
135
136        -physiq     to choose which physics package to use (default <$physiq>)
137
138        -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 (default $veget)
139
140        -arch       name of the arch to use (default <$arch>)
141
142        -arch_dir   where to find the arch files (default <$arch_dir>)
143
144        -make_j     number of processes to parallelize installations (default <$make_j>)
145
146........fin
147                  exit 1;;
148            "-v") version=$2; shift; shift;;
149            "-r") svn_lmdz=$2; shift; shift;;
150            "-d") grid_resolution=$2; shift; shift;;
151            "-unstable"|"-testing") trusting=$(echo "$1" | cut -c2-); shift;;
152            "-cosp") cosp=$2
153                     case $cosp in
154                         "none"|"v1"|"v2") cosp=$2; shift; shift;;
155                         *) echo "Only none v1 v2 for cosp option"; exit 1
156                     esac;;
157            "-nofcm") compile_with_fcm=0; echo "This option will be reactivated soon (promesse du 8dec2022)"; exit 1;  shift;;
158            "-SCM") SCM=1; shift;;
159            "-rad") rad=$2
160                    case $rad in
161                        "oldrad"|"rrtm"|"ecrad") rad=$2; shift; shift;;
162                        *) echo "Only oldrad rrtm ecrad for rad option"; exit 1
163                    esac;;
164            "-parallel") parallel=$2
165                         case $parallel in
166                             "none"|"mpi"|"omp"|"mpi_omp") parallel=$2; shift; shift;;
167                             *) echo "Only none mpi omp mpi_omp for the parallel option"; exit 1
168                         esac;;
169            "-bench") bench=$2; shift; shift;;
170            "-debug") optim_debug=-debug; shift;;
171            "-name") MODEL=$2; shift; shift;;
172            "-netcdf") netcdf=$2; shift; shift;;
173            "-physiq") physiq=$2; shift; shift;;
174            "-xios") with_xios=1; shift;;
175            "-arch") arch=$2; shift; shift;;
176            "-arch_dir") arch_dir=$2; shift; shift;;
177            "-veget") veget=$2; shift; shift;;
178            "-make_j") make_j=$2; shift; shift;;
179            *)  bash install_lmdz.sh -h; exit 1
180        esac
181    done
182
183    # Option de compilation pour Cosp
184    case $cosp in
185        v1) opt_cosp="-cosp true";;
186        v2) opt_cosp="-cospv2 true";;
187        *) opt_cosp=""
188    esac
189
190    # Check on veget version
191    if [[ $veget != 'none' && $veget != "CMIP6" && $veget != "orch2.0" && $veget != "orch2.2" ]]; then
192        re='^[0-9]+$'
193        if ! [[ $veget =~ $re ]]; then
194            echo 'Valeur de l option veget non valable'; exit 1
195        fi
196    fi
197
198    #Define veget-related suffix for gcm name
199    if [[ $veget = 'none' ]]; then
200        suff_orc=''
201    else
202        suff_orc='_orch'
203    fi
204
205
206    if [[ $parallel = "none" ]]; then
207        suff_exe='_seq'
208    else
209        suff_exe='_para_mem'
210    fi
211
212    #Chemin pour placer le modele
213    if [[ $MODEL = "" ]]; then MODEL="./LMDZ$version$svn_lmdz$optim_debug"; fi
214
215    ## if also compiling XIOS, parallel must be mpi_omp
216    if [[ $with_xios = 1 && $parallel != "mpi_omp" ]]; then
217        echo "Error, you must set -parallel mpi_omp if you want XIOS"; exit 1
218    fi
219
220    if [[ $with_xios = 1 ]]; then
221        opt_makelmdz_xios="-io xios"
222    fi
223
224    if [[ $cosp = "v2" && $with_xios = 0 ]]; then
225        echo "Error, Cospv2 cannot run without Xios"; exit 1
226    fi
227
228    if [[ $arch_dir = "" ]]; then
229        arch_dir="$MODEL/modipsl/config/IPSLCM7/ARCH/"
230    fi
231    arch_dir=$(readlink -f "$arch_dir")  # full path
232}
233
234function check_available_software {
235    echo "################################################################"
236    echo "Check if required software is available"
237    echo "################################################################"
238    for logiciel in wget tar gzip make gcc cmake m4 c++; do
239        if [[ $(which "$logiciel") = "" ]]; then
240            echo "You must first install $logiciel on your system"; exit 1
241        fi
242    done
243
244    cat <<eod > tt.f90
245print*,'coucou'
246end
247eod
248    $compiler tt.f90 || a.out
249    ./a.out >| tt
250    if [[ $(< tt sed -e 's/ //g' ) != "coucou" ]]; then
251        echo "problem installing with compiler $compiler"; exit 1
252    fi
253    \rm tt a.out tt.f90
254}
255
256function download_model {
257    mkdir -p "$MODEL"
258    MODEL=$(readlink -f "$MODEL"); echo "$MODEL"  # absolute path
259
260    rm -rf "$MODEL/modipsl"
261
262    echo "##########################################################"
263    echo "Download a slightly modified version of  LMDZ"
264    echo "##########################################################"
265    cd "$MODEL"
266    getlog="$(pwd)/get.log"
267    echo "logfile : $getlog"
268    myget "src_archives/$trusting/modipsl.$version.tar.gz" >> get.log 2>&1
269    echo "install_lmdz.sh wget_OK $(date)"
270    gunzip "modipsl.$version.tar.gz" >> get.log 2>&1
271    tar xf "modipsl.$version.tar" >> get.log 2>&1
272    \rm "modipsl.$version.tar"
273}
274
275function create_model_tar {  # TODO TEMP while waiting for tar: we copy the base from a local path = IPSLCM7 + ORCH2.2 8504
276    if [[ ! -d ../MODEL_REF ]]; then
277        cd ..
278        mkdir MODEL_REF
279        cd MODEL_REF
280        # Base is IPSLCM7
281        svn co --username icmc_users https://forge.ipsl.fr/igcmg/svn/modipsl/trunk modipsl
282        cd modipsl/util
283        ./model IPSLCM7_work
284        # Remove unused components
285        rm -rf ../oasis3-mct
286        cd ../modeles
287        rm -rf ICOSA_LMDZ ORCHIDEE_4 ORCHIDEE_2_2 NEMO DYNAMICO XIOS INCA
288        # Retrieve orch version
289        svn co svn://forge.ipsl.fr/orchidee/branches/ORCHIDEE_2_2/ORCHIDEE -r 8504
290        # Correct orchidee bug in 8504
291        sed -i"" -e "s/ts.second=dt_routing/ts%second=dt_routing/" -e "380,390 s/USE grid/USE grid, temp_disabled => contfrac/" ORCHIDEE/src_sechiba/routing_native_flow.f90
292
293        cd ../../../script_install
294    fi
295
296    if [[ ! -d "$MODEL" ]]; then
297        \cp -r ../MODEL_REF .
298        mv MODEL_REF "$MODEL"
299    fi
300    MODEL=$(readlink -f "$MODEL"); echo "$MODEL"  # absolute path
301}
302
303function init_arch {
304    if [[ ! -d $arch_dir ]]; then
305        echo "Error: no arch dir $arch_dir"; exit 1
306    elif [[ ! -f $arch_dir/arch-$arch.path ]]; then
307        echo "Error: no arch-$arch.path in $arch_dir"; exit 1
308    fi
309
310    local fcm_path
311    if [[ -f $arch_dir/arch-$arch.fcm ]]; then
312        fcm_path="$arch_dir/arch-$arch.fcm"
313    else
314        fcm_path="$MODEL/modipsl/modeles/LMDZ/arch/arch-$arch.fcm"
315        if [[ ! -f $fcm_path ]]; then
316            echo "Error: no $fcm_path"; exit 1
317        fi
318    fi
319
320    # check compiler
321    compiler=$(< "$fcm_path" grep "%COMPILER" | sed -e "s/%COMPILER\s*//")
322}
323
324function install_arch {
325    local component=$1
326
327    if [[ ! -f "$MODEL/modipsl/modeles/$component/arch/arch-$arch.fcm" ]]; then
328        \cp -f "$arch_dir/arch-$arch.fcm" "$MODEL/modipsl/modeles/$component/arch"
329        \cp -f "$arch_dir/arch-$arch.path" "$MODEL/modipsl/modeles/$component/arch"
330
331        if [[ $component = "XIOS" ]]; then
332            # Adapt for XIOS, which uses different naming conventions
333            sed -i'' -e "s/%COMPILER/%FCOMPILER/" -e "s/%LINK/%LINKER/" -e "s/-fdefault-real-8//" "$MODEL/modipsl/modeles/XIOS/arch/arch-$arch.fcm"
334        elif [[ $component = "ORCHIDEE" ]]; then
335            if [[ $orcbranch = "/tags/ORCHIDEE_2_0/ORCHIDEE" ]]; then  # 2.0 and before have a different fcm convention
336                sed -i'' -e "s/-I//" -e "s/-L//" "$MODEL/modipsl/modeles/ORCHIDEE/arch/arch-$arch.path"  # /!\ we only replace first occurence on purpose
337            fi
338        fi
339    fi
340}
341
342function install_netcdf {
343    echo "Installing Netcdf"
344    local ncdf_compiler="$compiler"
345
346    if [[ $netcdf = 0 ]]; then
347        ncdfdir=$(nc-config --prefix)
348    else
349        cd "$MODEL"
350
351        # Convert non-basic compiler
352        case $compiler in
353            mpif90) ncdf_compiler=$($compiler 2>&1 >/dev/null | head -n 1 | cut -f 1 -d ":")
354        esac
355
356        case $ncdf_compiler in
357            gfortran) opt1="-compiler gnu"; opt2="-CC gcc -FC gfortran -CXX g++";;
358            *)      echo "unexpected compiler $ncdf_compiler for netcdf"; exit 1
359        esac
360
361        case $with_xios in
362            0) script_install_netcdf="install_netcdf4_hdf5_seq.bash"
363               ncdfdir="netcdf4_hdf5_seq"
364               opt_="$opt1";;
365            1) script_install_netcdf="install_netcdf4_hdf5.bash"
366               ncdfdir="netcdf4_hdf5"
367               opt_="$opt2 -MPI $root_mpi";;
368            *) echo "with_xios=$with_xios, should be 0 or 1"; exit 1
369        esac
370        if [[ $netcdf = 1 ]]; then
371           ncdfdir="$MODEL/$ncdfdir"
372        else
373           mkdir -p "$netcdf"; ncdfdir="$netcdf/$ncdfdir"
374        fi
375
376        echo "Repertoire netcdf $ncdfdir"
377        if [[ ! -d $ncdfdir ]]; then
378            netcdflog=$(pwd)/netcdf.log
379            echo "----------------------------------------------------------"
380            echo "Compiling the Netcdf library"
381            echo "----------------------------------------------------------"
382            echo "log file : $netcdflog"
383            myget script_install/$script_install_netcdf >> "$netcdflog" 2>&1
384            chmod u=rwx $script_install_netcdf
385            # shellcheck disable=SC2086
386            ./$script_install_netcdf -prefix "$ncdfdir" $opt_ >> "$netcdflog" 2>&1
387        fi
388
389        # Add to path
390        export PATH="$ncdfdir/bin:$PATH"
391
392        #----------------------------------------------------------------------------
393        # LF rajout d'une verrue, pour une raison non encore expliquee,
394        # la librairie est parfois rangée dans lib64 et non dans lib
395        # par certains compilateurs
396        if [[ ! -e lib && -d lib64 ]]; then ln -s lib64 lib; fi
397        #----------------------------------------------------------------------------
398
399        echo "install_lmdz.sh netcdf_OK $(date)"
400    fi
401
402    cat >test_netcdf90.f90 <<EOF
403    use netcdf
404    print *, "NetCDF library version: ", nf90_inq_libvers()
405    end
406EOF
407
408    if $ncdf_compiler -I"$ncdfdir"/include test_netcdf90.f90 -L"$ncdfdir"/lib -lnetcdff \
409              -lnetcdf -Wl,-rpath="$ncdfdir"/lib && ./a.out
410    then
411        \rm test_netcdf90.f90 a.out
412    else
413        cat <<EOF
414Failed test program using NetCDF-Fortran. You can:
415- check that you have NetCDF-Fortran installed in your system
416- or specify an installation directory with option -netcdf of install_lmdz.sh
417- or download and compile NetCDF-Fortran with option -netcdf 1 of nstall_lmdz.sh
418EOF
419        exit 1
420    fi
421
422    # Compile NetCDF95
423    cd "$MODEL/modipsl/modeles/LMD"*
424    echo "Installing NetCDF95"
425    cd "$MODEL"
426    myget src_archives/netcdf/NetCDF95-0.3.tar.gz
427    tar -xf NetCDF95-0.3.tar.gz
428    \rm NetCDF95-0.3.tar.gz
429    cd NetCDF95-0.3
430    mkdir -p build && cd build
431    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"
432    make install
433}
434
435function install_IOIPSL {
436    install_arch "IOIPSL"
437
438    cd "$MODEL/modipsl/modeles/IOIPSL"
439    ioipsllog="$(pwd)/ioipsl.log"
440    echo "Compiling IOIPSL, the interface library with Netcdf $(date) (log: $ioipsllog)"
441
442    if ! ./makeioipsl_fcm -arch "$arch" -job 8 > "$ioipsllog" 2>&1; then
443        echo "IOIPSL compile failed, exiting"; exit 1
444    fi
445
446    # Link to modipsl/bin
447    cp -f bin/* ../../bin
448
449    echo "IOIPSL compiled $(date)"
450
451    IOIPSL_LIBDIR_="$MODEL/modipsl/modeles/IOIPSL/lib"
452    IOIPSL_INCDIR_="$MODEL/modipsl/modeles/IOIPSL/inc"
453}
454
455function install_XIOS {
456    if [[ $with_xios = 1 ]]; then
457        cd "$MODEL/modipsl/modeles"
458        xioslog="$(pwd)/XIOS/xios.log"
459        echo "##########################################################"
460        echo "Compiling XIOS (log $xioslog) $(date)"
461        echo "##########################################################"
462
463        # Download XIOS
464        case $xios_branch in
465            "trunk")
466            xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/trunk";;
467            "2.5")
468            xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/branchs/xios-2.5";;
469            "2.6")
470            xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS2/branches/xios-2.6";;
471            *) echo "XIOS: Error, bad argument for -branch ! Did not expect $xios_branch"; exit;;
472        esac
473       
474        cd "$MODEL/modipsl/modeles"
475        set +e; svn co --revision $xios_rev $xios_http XIOS; set -e
476
477        cd XIOS
478
479        install_arch "XIOS"
480
481        echo "Starting XIOS compilation"
482        if ! ./make_xios --arch "$arch" --job 8 > "$xioslog" 2>&1; then
483            echo "XIOS compilation failed, exiting"; exit 1
484        fi
485
486        echo "Compiled XIOS $(date)"
487    fi
488
489    XIOS_LIBDIR_="$MODEL/modipsl/modeles/XIOS/lib"
490    XIOS_INCDIR_="$MODEL/modipsl/modeles/XIOS/inc"
491}
492
493function get_orchidee_version {  # Set / Check ORCHIDEE version
494    local fetch_rev=""
495    orcbranch=""
496    case $veget in
497        "none") fcm_veget_version="false";;
498        "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
499        "orch2.2") fcm_veget_version=orchidee2.1; orcbranch="ORCHIDEE_2_2" ;; # the bundled version
500        *) fetch_rev=$veget
501    esac
502
503    if [[ -n $fetch_rev ]]; then
504        echo "Fetching orch $fetch_rev from the repository"
505        orcbranch=$(svn log -v -q svn://forge.ipsl.jussieu.fr/orchidee/ -r "$fetch_rev" | grep ORCHIDEE | head -1 | sed -e 's:ORCHIDEE/.*$:ORCHIDEE:' | awk '{print $2}')
506        echo "branch is $orcbranch"
507        if [[ $fetch_rev -lt 4465 ]]; then echo 'ORCHIDEE version must be >=4465, exiting'; exit 1; fi
508        \rm -rf "$MODEL/modipsl/modeles/ORCHIDEE"
509        echo "IF YOU INSTALL ORCHIDEE THE VERY FIRST TIME, ASK for PASSWORD at orchidee-help@listes.ipsl.fr"
510        cd "$MODEL/modipsl/modeles"
511        set +e
512        svn co -r "$fetch_rev" "svn://forge.ipsl.jussieu.fr/orchidee/$orcbranch"
513        set -e
514        cd -
515    fi
516
517
518    # Check parallel LMDZ+ORCH
519    if [[ (! $veget = "none") && (! $parallel = "none") && ($used_lmdz_rev -lt 4894) ]]; then
520        echo "LMDZ revision must be >=4894 for orchidee with parallel support"; exit 1
521    fi
522}
523
524function compile_orchidee {
525    install_arch "ORCHIDEE"
526
527    if [[ $veget != "none" ]]; then
528        cd "$MODEL/modipsl/modeles/ORCHIDEE"
529
530        orchideelog="$(pwd)/orchidee.log"
531        echo "Compiling ORCHIDEE, the continental surface model (log $orchideelog) $(date)"
532
533        local xios_orchid opt_orc
534        if [[ $with_xios = 1 ]]; then
535            xios_orchid="-xios";
536        else
537            xios_orchid="-noxios"
538        fi
539        if [[ $optim_debug = "-debug" ]]; then
540            opt_orc="-debug";
541        else
542            opt_orc="-prod"
543        fi
544
545        local varenv="IOIPSL_LIBDIR_=$IOIPSL_LIBDIR_ IOIPSL_INCDIR_=$IOIPSL_INCDIR_ XIOS_INCDIR_=$XIOS_INCDIR_ XIOS_LIBDIR_=$XIOS_LIBDIR_"
546        if [[ $parallel = "none" ]]; then
547            echo "$varenv ./makeorchidee_fcm $xios_orchid $opt_orc -parallel none -arch $arch -j $make_j" > compile.sh
548        else
549            if [[ ! -d src_parallel ]]; then
550               echo "Orchidee version too old for parallel support"; exit 1
551            fi
552            {
553                echo "$varenv ./makeorchidee_fcm -j $make_j $xios_orchid $opt_orc -parallel $parallel -arch $arch"
554            } > compile.sh
555        fi
556        chmod +x compile.sh
557        echo "Compiling ORCHIDEE using $(\cat compile.sh)"
558        if ! ./compile.sh > "$orchideelog" 2>&1; then
559            echo "ORCHIDEE compilation failed, exiting"; exit 1
560        fi
561        echo "Compiled ORCHIDEE $(date)"
562    fi
563
564    ORCH_INCDIR_="$MODEL/modipsl/modeles/ORCHIDEE/inc"
565    ORCH_LIBDIR_="$MODEL/modipsl/modeles/ORCHIDEE/lib"
566}
567
568function get_lmdz_version {
569    LMDZPATH=$(readlink -f "$MODEL/modipsl/modeles/LMD"*)
570    cd "$LMDZPATH"
571    lmdzlog="$(pwd)/lmdz.log"
572
573    used_lmdz_rev=$svn_lmdz
574    if [[ -n $svn_lmdz ]]; then
575        local lmdzbranch
576        echo "Fetching LMDZ $svn_lmdz from the repository"
577        lmdzbranch=$(svn log -v -q https://svn.lmd.jussieu.fr/LMDZ -r "$svn_lmdz" | grep LMDZ | head -1 | sed -e 's:trunk/.*$:trunk:' | awk '{print $2}')
578        \rm -rf "$MODEL/modipsl/modeles/LMDZ"
579        cd "$MODEL/modipsl/modeles"
580        set +e
581        svn co -r "$svn_lmdz" "https://svn.lmd.jussieu.fr/LMDZ$lmdzbranch" LMDZ
582        set -e
583        cd -
584    else  # get svn from info
585         used_lmdz_rev=$(svn info | grep "Last Changed Rev" | cut -c 19-)
586    fi
587}
588
589function compile_lmdz {
590    install_arch "LMDZ"
591    cd "$LMDZPATH"
592
593    exe_name="bin/gcm_${grid_resolution}_phylmd_${rad}${suff_exe}${suff_orc}.e"
594
595    local opt_rad
596    case $rad in
597        oldrad) iflag_rrtm=0; NSW=2; opt_rad="";;
598        rrtm)   iflag_rrtm=1; NSW=6
599            if [[ $used_lmdz_rev -le 4185 ]]; then
600                opt_rad="-rrtm true"
601            else
602                opt_rad="-rad rrtm"
603            fi;;
604        ecrad)  iflag_rrtm=2; NSW=6; opt_rad="-rad ecrad";;
605        *) echo "Only oldrad rrtm ecrad for rad option"; exit 1
606    esac
607    if [[ $used_lmdz_rev -le 4185 && $rad = "ecrad" ]]; then
608        echo "ecrad only available for LMDZ rev starting with 4186 "; exit 1
609    fi
610
611    # Compile
612    local varenv="IOIPSL_LIBDIR_=\"$IOIPSL_LIBDIR_\" IOIPSL_INCDIR_=\"$IOIPSL_INCDIR_\" ORCH_INCDIR_=\"$ORCH_INCDIR_\" ORCH_LIBDIR_=\"$ORCH_LIBDIR_\" XIOS_INCDIR_=\"$XIOS_INCDIR_\" XIOS_LIBDIR_=\"$XIOS_LIBDIR_\""
613    makelmdz="makelmdz_fcm $optim_debug -arch $arch -j $make_j"
614    if [[ $parallel = "none" ]]; then
615        echo "$varenv ./$makelmdz $opt_rad $opt_cosp -d ${grid_resolution} -v $fcm_veget_version gcm " > compile.sh
616    else
617        echo "$varenv ./$makelmdz $opt_rad $opt_cosp $opt_makelmdz_xios -d ${grid_resolution} -v $fcm_veget_version -mem -parallel $parallel gcm" > compile.sh
618    fi
619    echo "Compiling lmdz using $(\cat compile.sh) (log: $lmdzlog) $(date)"
620    chmod +x ./compile.sh
621    if ! ./compile.sh > "$lmdzlog" 2>&1; then
622        echo "LMDZ compilation failed, exiting"; exit 1
623    fi
624    echo "Finished LMDZ compilation $(date)"
625
626    # Check executable
627    # TODO $mysev -ge 4186 => other name convention ! check original install
628    if [[ ! -f $exe_name ]]; then
629        echo "Compilation failed, can't find the executable"; exit 1
630    else
631        echo "Compilation successfull, the executable is $exe_name $(date)"
632    fi
633}
634
635function run_bench {
636    cd "$MODEL/modipsl/modeles/LMDZ"*
637
638    if [[ $bench = "tuto" ]]; then
639        myget "Training/tutorial.tar"; tar xf tutorial.tar; cd TUTORIAL
640        ./init.sh
641    elif [[ $bench = 1 ]]; then
642        \rm -rf "BENCH${grid_resolution}"
643        local bench=bench_lmdz_${grid_resolution}
644        myget "3DBenchs/$bench.tar.gz"
645        tar xf "$bench.tar.gz"
646
647        if [[ $cosp = "v1" || $cosp = "v2" ]]; then
648            cd "BENCH${grid_resolution}"
649            # copier les fichiers namelist input et output our COSP
650            cp ../DefLists/cosp*_input_nl.txt .
651            cp ../DefLists/cosp*_output_nl.txt .
652            # Activer la cles ok_cosp pour tourner avec COSP
653            sed -e 's@ok_cosp=n@ok_cosp=y@' config.def > tmp
654            \mv -f tmp config.def
655            cd ..
656        fi
657
658        if [[ -n "$physiq" ]]; then
659            cd "BENCH${grid_resolution}"
660            if [[ -f "physiq.def_${physiq}" ]]; then
661                cp "physiq.def_${physiq}" physiq.def
662                echo "using physiq.def_${physiq}"
663            else
664                echo "using standard physiq.def"
665            fi
666            cd ..
667        else
668            echo "using standard physiq.def"
669        fi
670
671        if [[ $with_xios = 1 ]]; then
672            cd "BENCH${grid_resolution}"
673            cp ../DefLists/iodef.xml .
674            cp ../DefLists/context_lmdz.xml .
675            cp ../DefLists/field_def_lmdz.xml .
676            # A raffiner par la suite
677            echo "A FAIRE : Copier les *xml en fonction de l option cosp"
678            cp ../DefLists/field_def_cosp*.xml .
679            cp ../DefLists/file_def_hist*xml .
680            # adapt iodef.xml to use attached mode
681            sed -e 's@"using_server" type="bool">true@"using_server" type="bool">false@' \
682                iodef.xml > tmp
683            \mv -f tmp iodef.xml
684
685            # and convert all the enabled="_AUTO_" (for libIGCM) to enabled=.FALSE.
686            # except for histday
687            for histfile in file_def_hist*xml
688            do
689                if [[ "$histfile" = "file_def_histday_lmdz.xml" ]]; then
690                    sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".TRUE."@' \
691                        "$histfile" > tmp
692                    \mv -f tmp "$histfile"
693                    sed -e 's@output_level="_AUTO_"@output_level="5"@' "$histfile" \
694                        > tmp
695                    \mv -f tmp "$histfile"
696                    sed -e 's@compression_level="2"@compression_level="0"@' \
697                        "$histfile" > tmp
698                    \mv -f tmp "$histfile"
699                else
700                    sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \
701                        "$histfile" > tmp
702                    \mv -f tmp "$histfile"
703                fi
704            done
705            # and add option "ok_all_xml=y" in config.def
706            echo "### XIOS outputs" >> config.def
707            echo 'ok_all_xml=.true.' >> config.def
708
709            #activer les sorties pour Cosp
710            if [[ "$cosp" = "v1" ]]; then
711                sed -i'' -e 's@enabled=".FALSE."@enabled=".TRUE."@' \
712                         -e 's@output_level="_AUTO_"@output_level="5"@' \
713                         -e 's@compression_level="2"@compression_level="0"@' \
714                         file_def_histdayCOSP_lmdz.xml
715            fi
716            if [[ "$cosp" = "v2" ]]; then
717                sed -e 's@compression_level="2"@compression_level="0"@' file_def_histdayCOSPv2_lmdz.xml
718                for type_ in hf day mth; do
719                    file=file_def_hist${type_}COSP
720                    sed -i'' -e 's@src="./'${file}'_lmdz.xml"@src="./'${file}'v2_lmdz.xml"@' context_lmdz.xml
721                done
722                sed -i '' -e 's@field_def_cosp1.xml@field_def_cospv2.xml@' field_def_lmdz.xml
723            fi
724
725            cd ..
726        fi
727
728        # Cas Bench avec ecrad
729        if [[ $rad = "ecrad" ]]; then
730            cd "BENCH${grid_resolution}"
731            cp  ../DefLists/namelist_ecrad .
732            cp -r ../libf/phylmd/ecrad/data .
733            cd ..
734        fi
735
736        # Adjusting bench physiq.def to radiative code chosen
737        cd "BENCH${grid_resolution}"
738        sed -e 's/iflag_rrtm=.*.$/iflag_rrtm='$iflag_rrtm'/' \
739            -e 's/NSW=.*.$/NSW='$NSW'/' physiq.def > tmpdef
740        \mv tmpdef physiq.def
741        cd ..
742
743        cp "$exe_name" "BENCH${grid_resolution}/gcm.e"
744        cd "BENCH${grid_resolution}"
745
746        if [[ ${parallel:0:3} = "mpi" ]]; then
747            # Lancement avec deux procs mpi et 2 openMP
748            echo "export OMP_STACKSIZE=800M" > bench.sh
749            if [[ "${parallel:4:3}" = "omp" ]]; then
750                echo "export OMP_NUM_THREADS=2" >> bench.sh
751            fi
752            if [[ "$cosp" = "v1" || "$cosp" = "v2" ]]; then
753                echo "ulimit -s 200000" >> bench.sh
754            else
755                echo "ulimit -s unlimited" >> bench.sh
756            fi
757            echo "mpirun -np 2 gcm.e > listing  2>&1" >> bench.sh
758            # Add rebuild, using reb.sh if it is there
759            cat <<EOF >> bench.sh
760    if [[ -f reb.sh ]]; then
761      ./reb.sh histday; ./reb.sh histmth; ./reb.sh histhf;
762      ./reb.sh histins; ./reb.sh stomate_history;
763      ./reb.sh sechiba_history; ./reb.sh sechiba_out_2
764    fi
765EOF
766        else
767            echo "./gcm.e > listing  2>&1" > bench.sh
768        fi
769        # Getting orchidee stuff
770        if [[ $veget = 'CMIP6' || $veget = "orch2.0" ]]; then  # TODO once we have a 2.2 bench, add it here (or in planned separate bench script)
771            echo 'myget 3DBenchs/BENCHCMIP6.tar.gz'
772            myget 3DBenchs/BENCHCMIP6.tar.gz
773            tar xvzf BENCHCMIP6.tar.gz
774            sed -e "s:VEGET=n:VEGET=y:" config.def > tmp
775            mv -f tmp config.def
776            if [[ $with_xios = 1 ]]; then
777                cp ../../ORCHIDEE/src_xml/context_orchidee.xml .
778                echo '<context id="orchidee" src="./context_orchidee.xml"/>' > add.tmp
779                cp ../../ORCHIDEE/src_xml/field_def_orchidee.xml .
780                cp ../../ORCHIDEE/src_xml/file_def_orchidee.xml .
781                cp ../../ORCHIDEE/src_xml/file_def_input_orchidee.xml .
782                if [[ -f ../../ORCHIDEE/src_xml/context_input_orchidee.xml ]]; then
783                       cp ../../ORCHIDEE/src_xml/context_input_orchidee.xml .
784                       echo '<context id="orchidee" src="./context_input_orchidee.xml"/>' >> add.tmp
785                fi
786                sed -e '/id="LMDZ"/r add.tmp' iodef.xml > tmp
787                mv tmp iodef.xml
788                sed -e'{/sechiba1/ s/enabled="_AUTO_"/type="one_file" enabled=".TRUE."/}' \
789                    file_def_orchidee.xml > tmp
790                \mv -f tmp file_def_orchidee.xml
791                sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \
792                    file_def_orchidee.xml > tmp
793                \mv -f tmp file_def_orchidee.xml
794                sed -e 's@output_level="_AUTO_"@output_level="1"@' \
795                    file_def_orchidee.xml > tmp
796                \mv -f tmp file_def_orchidee.xml
797                sed -e 's@output_freq="_AUTO_"@output_freq="1d"@' \
798                    file_def_orchidee.xml > tmp
799                \mv -f tmp file_def_orchidee.xml
800                sed -e 's@compression_level="4"@compression_level="0"@' \
801                    file_def_orchidee.xml > tmp
802                \mv -f tmp file_def_orchidee.xml
803                sed -e 's@XIOS_ORCHIDEE_OK = n@XIOS_ORCHIDEE_OK = y@' \
804                    orchidee.def > tmp
805                \mv -f tmp orchidee.def
806            fi
807        fi
808
809        if [[ -f ../arch.env ]]; then source ../arch.env; fi
810
811        echo "EXECUTION DU BENCH"
812        date
813        if (! ./bench.sh > out.bench 2>&1) || ! (tail -n 1 listing | grep "Everything is cool"); then
814            tail listing
815            echo "Bench FAILED, exiting"; exit 1
816        fi
817        date
818        tail listing
819    fi
820
821    # 1D case
822    if [[ $SCM = 1 ]]; then
823        cd "$MODEL"
824        myget 1D/1D.tar.gz
825        tar xf 1D.tar.gz
826        cd 1D
827        if [[ $rad = "oldrad" ]]; then
828            sed -i'' -e 's/^rad=.*$/rad=oldrad/' run.sh
829            sed -i'' -e 's/^rad=.*$/rad=oldrad/' bin/compile
830        fi
831        echo "Running 1D/run.sh, log in $(pwd)/run1d.log"
832        ./run.sh > "$(pwd)/run1d.log" 2>&1
833    fi
834}
835
836echo "install_lmdz.sh DEBUT $(date)"
837
838set_default_params
839read_cmdline_args "$@"
840#download_model
841create_model_tar
842init_arch
843check_available_software
844get_lmdz_version
845get_orchidee_version
846install_netcdf
847install_IOIPSL
848install_XIOS
849compile_orchidee
850compile_lmdz
851run_bench
Note: See TracBrowser for help on using the repository browser.