source: BOL/script_install_amaury/install_lmdz.sh @ 4934

Last change on this file since 4934 was 4934, checked in by abarral, 5 months ago

fix run for users w/o svn
make sourceable as a lib

  • Property svn:executable set to *
File size: 31.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    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         set +e; used_lmdz_rev=$(svn info | grep "Last Changed Rev" | cut -c 19-); set -e
578         if [[ -z $used_lmdz_rev ]]; then  # svn info failed
579            used_lmdz_rev=$(grep 'Revision: [0-9]' "$MODEL"/Read*.md | awk ' { print $2 } ' 2>/dev/null)
580            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
581         fi
582    fi
583}
584
585function compile_lmdz {
586    install_arch "LMDZ"
587    cd "$LMDZPATH"
588
589    exe_name="bin/gcm_${grid_resolution}_phylmd_${rad}${suff_exe}${suff_orc}.e"
590
591    local opt_rad
592    case $rad in
593        oldrad) iflag_rrtm=0; NSW=2; opt_rad="";;
594        rrtm)   iflag_rrtm=1; NSW=6
595            if [[ $used_lmdz_rev -le 4185 ]]; then
596                opt_rad="-rrtm true"
597            else
598                opt_rad="-rad rrtm"
599            fi;;
600        ecrad)  iflag_rrtm=2; NSW=6; opt_rad="-rad ecrad";;
601        *) echo "Only oldrad rrtm ecrad for rad option"; exit 1
602    esac
603    if [[ $used_lmdz_rev -le 4185 && $rad = "ecrad" ]]; then
604        echo "ecrad only available for LMDZ rev starting with 4186 "; exit 1
605    fi
606
607    # Compile
608    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_\""
609    makelmdz="makelmdz_fcm $optim_debug -arch $arch -j $make_j"
610    if [[ $parallel = "none" ]]; then
611        echo "$varenv ./$makelmdz $opt_rad $opt_cosp -d ${grid_resolution} -v $fcm_veget_version gcm " > compile.sh
612    else
613        echo "$varenv ./$makelmdz $opt_rad $opt_cosp $opt_makelmdz_xios -d ${grid_resolution} -v $fcm_veget_version -mem -parallel $parallel gcm" > compile.sh
614    fi
615    echo "Compiling lmdz using $(\cat compile.sh) (log: $lmdzlog) $(date)"
616    chmod +x ./compile.sh
617    if ! ./compile.sh > "$lmdzlog" 2>&1; then
618        echo "LMDZ compilation failed, exiting"; exit 1
619    fi
620    echo "Finished LMDZ compilation $(date)"
621
622    # Check executable
623    # TODO $mysev -ge 4186 => other name convention ! check original install
624    if [[ ! -f $exe_name ]]; then
625        echo "Compilation failed, can't find the executable"; exit 1
626    else
627        echo "Compilation successfull, the executable is $exe_name $(date)"
628    fi
629}
630
631function run_bench {
632    cd "$MODEL/modipsl/modeles/LMDZ"*
633
634    if [[ $bench = "tuto" ]]; then
635        myget "Training/tutorial.tar"; tar xf tutorial.tar; cd TUTORIAL
636        ./init.sh
637    elif [[ $bench = 1 ]]; then
638        \rm -rf "BENCH${grid_resolution}"
639        local bench=bench_lmdz_${grid_resolution}
640        myget "3DBenchs/$bench.tar.gz"
641        tar xf "$bench.tar.gz"
642
643        if [[ $cosp = "v1" || $cosp = "v2" ]]; then
644            cd "BENCH${grid_resolution}"
645            # copier les fichiers namelist input et output our COSP
646            cp ../DefLists/cosp*_input_nl.txt .
647            cp ../DefLists/cosp*_output_nl.txt .
648            # Activer la cles ok_cosp pour tourner avec COSP
649            sed -e 's@ok_cosp=n@ok_cosp=y@' config.def > tmp
650            \mv -f tmp config.def
651            cd ..
652        fi
653
654        if [[ -n "$physiq" ]]; then
655            cd "BENCH${grid_resolution}"
656            if [[ -f "physiq.def_${physiq}" ]]; then
657                cp "physiq.def_${physiq}" physiq.def
658                echo "using physiq.def_${physiq}"
659            else
660                echo "using standard physiq.def"
661            fi
662            cd ..
663        else
664            echo "using standard physiq.def"
665        fi
666
667        if [[ $with_xios = 1 ]]; then
668            cd "BENCH${grid_resolution}"
669            cp ../DefLists/iodef.xml .
670            cp ../DefLists/context_lmdz.xml .
671            cp ../DefLists/field_def_lmdz.xml .
672            # A raffiner par la suite
673            echo "A FAIRE : Copier les *xml en fonction de l option cosp"
674            cp ../DefLists/field_def_cosp*.xml .
675            cp ../DefLists/file_def_hist*xml .
676            # adapt iodef.xml to use attached mode
677            sed -e 's@"using_server" type="bool">true@"using_server" type="bool">false@' \
678                iodef.xml > tmp
679            \mv -f tmp iodef.xml
680
681            # and convert all the enabled="_AUTO_" (for libIGCM) to enabled=.FALSE.
682            # except for histday
683            for histfile in file_def_hist*xml; do
684                if [[ "$histfile" = "file_def_histday_lmdz.xml" ]]; then
685                    sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".TRUE."@' \
686                        "$histfile" > tmp
687                    \mv -f tmp "$histfile"
688                    sed -e 's@output_level="_AUTO_"@output_level="5"@' "$histfile" \
689                        > tmp
690                    \mv -f tmp "$histfile"
691                    sed -e 's@compression_level="2"@compression_level="0"@' \
692                        "$histfile" > tmp
693                    \mv -f tmp "$histfile"
694                else
695                    sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \
696                        "$histfile" > tmp
697                    \mv -f tmp "$histfile"
698                fi
699            done
700            # and add option "ok_all_xml=y" in config.def
701            echo "### XIOS outputs" >> config.def
702            echo 'ok_all_xml=.true.' >> config.def
703
704            #activer les sorties pour Cosp
705            if [[ "$cosp" = "v1" ]]; then
706                sed -i'' -e 's@enabled=".FALSE."@enabled=".TRUE."@' \
707                         -e 's@output_level="_AUTO_"@output_level="5"@' \
708                         -e 's@compression_level="2"@compression_level="0"@' \
709                         file_def_histdayCOSP_lmdz.xml
710            fi
711            if [[ "$cosp" = "v2" ]]; then
712                sed -i'' -e 's@compression_level="2"@compression_level="0"@' file_def_histdayCOSPv2_lmdz.xml
713                for type_ in hf day mth; do
714                    file=file_def_hist${type_}COSP
715                    sed -i'' -e 's@src="./'${file}'_lmdz.xml"@src="./'${file}'v2_lmdz.xml"@' context_lmdz.xml
716                done
717                sed -i'' -e 's@field_def_cosp1.xml@field_def_cospv2.xml@' field_def_lmdz.xml
718            fi
719
720            cd ..
721        fi
722
723        # Cas Bench avec ecrad
724        if [[ $rad = "ecrad" ]]; then
725            cd "BENCH${grid_resolution}"
726            cp  ../DefLists/namelist_ecrad .
727            cp -r ../libf/phylmd/ecrad/data .
728            cd ..
729        fi
730
731        # Adjusting bench physiq.def to radiative code chosen
732        cd "BENCH${grid_resolution}"
733        sed -e 's/iflag_rrtm=.*.$/iflag_rrtm='$iflag_rrtm'/' \
734            -e 's/NSW=.*.$/NSW='$NSW'/' physiq.def > tmpdef
735        \mv tmpdef physiq.def
736        cd ..
737
738        cp "$exe_name" "BENCH${grid_resolution}/gcm.e"
739        cd "BENCH${grid_resolution}"
740
741        local bench_cmd="./bench.sh"
742        if [[ ${parallel:0:3} = "mpi" ]]; then
743            # Lancement avec deux procs mpi et 2 openMP
744            echo "export OMP_STACKSIZE=800M" > bench.sh
745            if [[ "${parallel:4:3}" = "omp" ]]; then
746                echo "export OMP_NUM_THREADS=2" >> bench.sh
747            fi
748            if [[ $cosp = "v1" || $cosp = "v2" ]]; then
749                echo "ulimit -s 200000" >> bench.sh
750            else
751                echo "ulimit -s unlimited" >> bench.sh
752            fi
753            if which mpirun > /dev/null 2>&1; then
754                echo "mpirun -np 2 gcm.e > listing 2>&1" >> bench.sh
755            elif grep -q "Adastra" /etc/motd; then
756                local account
757                account=$(/usr/sbin/my_project.py -l 2>&1 | head -1 | cut -d " " -f 3- | cut -c 5-)
758                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"
759                echo "./gcm.e > listing 2>&1" >> bench.sh
760            else
761                echo "Error: No command found to run parallel bench"; exit 1
762            fi
763            # Add rebuild, using reb.sh if it is there
764            cat <<EOF >> bench.sh
765if [[ -f reb.sh ]]; then
766  ./reb.sh histday; ./reb.sh histmth; ./reb.sh histhf;
767  ./reb.sh histins; ./reb.sh stomate_history;
768  ./reb.sh sechiba_history; ./reb.sh sechiba_out_2
769fi
770EOF
771        else
772            echo "./gcm.e > listing 2>&1" > bench.sh
773        fi
774        # Getting orchidee stuff
775        if [[ $veget = 'CMIP6' || $veget = "orch2.0" ]]; then  # TODO once we have a 2.2 bench, add it here (or in planned separate bench script)
776            echo 'myget 3DBenchs/BENCHCMIP6.tar.gz'
777            myget 3DBenchs/BENCHCMIP6.tar.gz
778            tar xvzf BENCHCMIP6.tar.gz
779            sed -e "s:VEGET=n:VEGET=y:" config.def > tmp
780            mv -f tmp config.def
781            if [[ $with_xios = 1 ]]; then
782                cp ../../ORCHIDEE/src_xml/context_orchidee.xml .
783                echo '<context id="orchidee" src="./context_orchidee.xml"/>' > add.tmp
784                cp ../../ORCHIDEE/src_xml/field_def_orchidee.xml .
785                cp ../../ORCHIDEE/src_xml/file_def_orchidee.xml .
786                cp ../../ORCHIDEE/src_xml/file_def_input_orchidee.xml .
787                if [[ -f ../../ORCHIDEE/src_xml/context_input_orchidee.xml ]]; then
788                       cp ../../ORCHIDEE/src_xml/context_input_orchidee.xml .
789                       echo '<context id="orchidee" src="./context_input_orchidee.xml"/>' >> add.tmp
790                fi
791                sed -e '/id="LMDZ"/r add.tmp' iodef.xml > tmp
792                mv tmp iodef.xml
793                sed -e'{/sechiba1/ s/enabled="_AUTO_"/type="one_file" enabled=".TRUE."/}' \
794                    file_def_orchidee.xml > tmp
795                \mv -f tmp file_def_orchidee.xml
796                sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \
797                    file_def_orchidee.xml > tmp
798                \mv -f tmp file_def_orchidee.xml
799                sed -e 's@output_level="_AUTO_"@output_level="1"@' \
800                    file_def_orchidee.xml > tmp
801                \mv -f tmp file_def_orchidee.xml
802                sed -e 's@output_freq="_AUTO_"@output_freq="1d"@' \
803                    file_def_orchidee.xml > tmp
804                \mv -f tmp file_def_orchidee.xml
805                sed -e 's@compression_level="4"@compression_level="0"@' \
806                    file_def_orchidee.xml > tmp
807                \mv -f tmp file_def_orchidee.xml
808                sed -e 's@XIOS_ORCHIDEE_OK = n@XIOS_ORCHIDEE_OK = y@' \
809                    orchidee.def > tmp
810                \mv -f tmp orchidee.def
811            fi
812        fi
813
814        if [[ -f ../arch.env ]]; then source ../arch.env; fi
815
816        echo "EXECUTION DU BENCH"
817        date
818        if (! $bench_cmd > out.bench 2>&1) || ! (tail -n 1 listing | grep "Everything is cool"); then
819            tail listing
820            echo "Bench FAILED, exiting"; exit 1
821        fi
822        date
823        tail listing
824    fi
825
826    # 1D case
827    if [[ $SCM = 1 ]]; then
828        cd "$MODEL"
829        myget 1D/1D.tar.gz
830        tar xf 1D.tar.gz
831        cd 1D
832        if [[ $rad = "oldrad" ]]; then
833            sed -i'' -e 's/^rad=.*$/rad=oldrad/' run.sh
834            sed -i'' -e 's/^rad=.*$/rad=oldrad/' bin/compile
835        elif [[ $rad = ecrad ]] ; then
836                        sed -i'' -e 's/^rad=.*$/rad=ecrad/' run.sh
837                        sed -i'' -e 's/^rad=.*$/rad=ecrad/' bin/compile
838                    fi
839        echo "Running 1D/run.sh, log in $(pwd)/run1d.log"
840        ./run.sh > "$(pwd)/run1d.log" 2>&1
841    fi
842}
843
844# If sourced: returns, else run setup
845if [[ ! "${BASH_SOURCE[0]}" = "$0" ]]; then return 0; fi
846
847echo "install_lmdz.sh DEBUT $(date)"
848
849set_default_params
850read_cmdline_args "$@"
851#download_model
852create_model_tar
853init_arch
854check_available_software
855get_lmdz_version
856get_orchidee_version
857install_netcdf
858install_IOIPSL
859install_XIOS
860compile_orchidee
861compile_lmdz
862run_bench
Note: See TracBrowser for help on using the repository browser.