source: BOL/script_install_amaury/install_lmdz.sh @ 4896

Last change on this file since 4896 was 4896, checked in by abarral, 5 weeks ago

Fix XIOS compile
Fix mpif90 netcdf compile
Fix local netcdf compile
Fix missing rebuild

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