source: BOL/script_install_amaury/install_lmdz.sh @ 4932

Last change on this file since 4932 was 4930, checked in by abarral, 2 years ago

fix cosp bench

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