source: BOL/script_install_amaury/install_lmdz.sh @ 4871

Last change on this file since 4871 was 4871, checked in by abarral, 8 weeks ago

(WIP)
fix IOIPSL fcm arch
refactor install_xios

  • Property svn:executable set to *
File size: 46.9 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
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
53    # 04_2021 : tester si r4 marche encore !
54    real="r8"  # ou "r4"
55
56    svn=""
57    version="20231022.trunk"
58
59    getlmdzor=1
60    netcdf=1   #  1: for automatic installation;
61    #          or 0: do not install NetCDF and look for it in standard locations;
62    #          or absolute path: look for NetCDF there
63    check_software_linux=1
64    ioipsl=1
65    bench=1
66    pclinux=1
67    pcmac=0 # default: not on a Mac
68    compiler="gfortran"
69    if [[ $(gfortran -dumpversion | cut -d. -f1) -ge 10 ]]; then allow_arg_mismatch="-fallow-argument-mismatch"; fi
70    SCM=0
71    # surface/vegetation scheme treatment
72    # controlled by the single variable veget which can have the following values
73    # - NONE: bucket scheme (default)
74    # - CMIP6: orchidee version used in CMIP exercise, rev 5661
75    # - number: orchidee version number
76    veget="NONE"
77    # choose the resolution for the bench runs
78    # grid_resolution= 32x24x11 or 48x36x19 for tests (test without ORCHIDEE)
79    #                  96x71x19  standard configuration
80    grid_resolution="32x32x39"  # "48x36x19", "96x95x39", "144x142x79"
81    # choose the physiq version you want to test
82    #physiq=NPv6.0.14splith
83    physiq=""
84
85    ## parallel can take the values none/mpi/omp/mpi_omp
86    parallel="none"  # "mpi_omp"
87    idris_acct="lmd"
88    trusting="testing"
89    OPT_GPROF=""
90    OPT_MAKELMDZ=""
91    MODEL=""
92
93    ## also compile XIOS? (and more recent NetCDF/HDF5 libraries) Default=no
94    with_xios="n"
95    opt_makelmdz_xios=""
96
97    ## compile with oldrad/rrtm/ecrad radiatif code (Default=rrtm)
98    rad="rrtm"
99
100    ## compile_with_fcm=1 : use makelmdz_fcm (1) or makelmdz (0)
101    compile_with_fcm=1
102
103    #Compilation with Cosp (cosp=NONE/v1/v2; default=NONE)
104    cosp="NONE"
105    opt_cosp=""
106
107    # Check if on a Mac
108    if [[ $(uname) = "Darwin" ]]; then
109        pcmac=1
110        export MAKE="make"
111    fi
112
113    env_file=""
114    optim=""
115    arch="local"
116
117    local mpi_file
118    mpi_file=$(readlink -f "$(which mpif90)")
119    path_mpi=$(dirname "$mpi_file")
120    root_mpi=$(dirname "$path_mpi")
121}
122
123function read_cmdline_args {
124    while (($# > 0)); do
125        case $1 in
126            "-h") cat <<........fin
127        $0 [ -v version ] [ -r svn_release ]
128               [ -parallel PARA ] [ -d GRID_RESOLUTION ] [ -bench 0/1 ]
129               [-name LOCAL_MODEL_NAME] [-gprof] [-opt_makelmdz] [-rad RADIATIF]
130
131        -v       "version" like 20150828.trunk
132                 see http://www.lmd.jussieu.fr/~lmdz/Distrib/LISMOI.trunk
133
134        -r       "svn_release" : either the svn release number or "last"
135
136        -compiler gfortran|ifort|pgf90 (default: gfortran)
137
138        -parallel PARA : can be mpi_omp (mpi with openMP) or none (for sequential)
139
140        -d        GRID_RESOLUTION should be among the available benchs if -bench 1
141                  among which : 48x36x19, 48x36x39
142                  if wanting to run a bench simulation in addition to compilation
143                  default : 48x36x19
144
145        -bench     activating the bench or not (0/1). Default 1
146
147        -testing/unstable
148
149        -name      LOCAL_MODEL_NAME : default = LMDZversion.release
150
151        -netcdf    0, 1 or PATH
152                       0: do not download NetCDF, look for it in standard locations
153                   1: download and compile NetCDF
154                       PATH: full path to an existing installed NetCDF library
155
156        -xios      also download and compile the XIOS library
157                   (requires the NetCDF4-HDF5 library, also installed by default)
158                   (requires to also have -parallel mpi_omp)
159
160        -gprof     to compile with -pg to enable profiling with gprof
161
162        -cosp      to run without our with cospv1 or cospv2 [none/v1/v2]
163
164        -rad RADIATIF can be oldrad, rrtm or ecrad radiatif code
165
166        -nofcm     to compile without fcm
167
168        -SCM        install 1D version automatically
169
170        -debug      compile everything in debug mode
171
172        -opt_makelmdz     to call makelmdz or makelmdz_fcm with additional options
173
174        -physiq    to choose which physics package to use
175
176        -env_file  specify an arch.env file to overwrite the existing one
177
178        -veget surface model to run [NONE/CMIP6/xxxx]
179
180........fin
181                  exit 1;;
182            "-v") version=$2; shift; shift;;
183            "-r") svn=$2; shift; shift;;
184            "-compiler") compiler=$2
185                         case $compiler in
186                             "gfortran"|"ifort"|"pgf90") compiler=$2; shift
187                                                         shift;;
188                             *) echo "Only gfortran , ifort or pgf90 for the " \
189                                     "compiler option"
190                                exit 1
191                         esac;;
192            "-d") grid_resolution=$2; shift; shift;;
193            "-gprof") OPT_GPROF="-pg"; shift;;
194            "-unstable"|"-testing") trusting=$(echo "$1" | cut -c2-) ; shift;;
195            "-cosp") cosp=$2
196                     case $cosp in
197                         "none"|"v1"|"v2") cosp=$2; shift; shift;;
198                         *) echo "Only none v1 v2 for cosp option"; exit 1
199                     esac;;
200            "-nofcm") compile_with_fcm=0; echo "This option will be reactivated soon (promesse du 8dec2022)"; exit 1;  shift;;
201            "-SCM") SCM=1; shift;;
202            "-opt_makelmdz") OPT_MAKELMDZ="$2"; shift; shift;;
203            "-rrtm") if [[ $2 = "false" ]]; then
204                         rad="oldrad"
205                     else
206                         rad="rrtm"
207                     fi
208                     shift; shift;;
209            "-rad") rad=$2
210                    case $rad in
211                        "oldrad"|"rrtm"|"ecrad") rad=$2; shift; shift;;
212                        *) echo "Only oldrad rrtm ecrad for rad option"; exit 1
213                    esac;;
214            "-parallel") parallel=$2
215                         case $parallel in
216                             "none"|"mpi"|"omp"|"mpi_omp") parallel=$2; shift; shift;;
217                             *) echo "Only none mpi omp mpi_omp for the parallel option"; exit 1
218                         esac;;
219            "-bench") bench=$2; shift; shift;;
220            "-debug") optim=-debug; shift;;
221            "-name") MODEL=$2; shift; shift;;
222            "-netcdf") netcdf=$2; shift; shift;;
223            "-physiq") physiq=$2; shift; shift;;
224            "-xios") with_xios="y"; shift;;
225            "-env_file") env_file=$2; shift; shift;;
226            "-veget") veget=$2; shift; shift;;
227            *)  bash install_lmdz.sh -h; exit 1
228        esac
229    done
230
231    # Option de compilation pour Cosp
232    case $cosp in
233        v1) opt_cosp="-cosp true";;
234        v2) opt_cosp="-cospv2 true";;
235        *) opt_cosp=""
236    esac
237
238    # Check on veget version
239    if [[ $veget != 'NONE' && $veget != "CMIP6" ]]; then
240        re='^[0-9]+$'
241        if ! [[ $veget =~ $re ]]; then
242            echo 'Valeur de l option veget non valable'; exit 1
243        fi
244    fi
245
246    #Define veget-related suffix for gcm name
247    if [[ $veget = 'NONE' ]]; then
248        suff_orc=''
249        #For use with tutorial, orchidee_rev is also defined (will be
250        #written in surface_env at the end of the script)
251        orchidee_rev=''
252    else
253        suff_orc='_orch'
254    fi
255
256
257    if [[ $parallel = "none" ]]; then
258        sequential=1; suff_exe='_seq'
259    else
260        sequential=0; suff_exe='_para_mem'
261    fi
262
263    #Chemin pour placer le modele
264    if [[ $MODEL = "" ]]; then MODEL="./LMDZ$version$svn$optim"; fi
265
266    ## if also compiling XIOS, parallel must be mpi_omp
267    if [[ $with_xios = "y" && $parallel != "mpi_omp" ]]; then
268        echo "Error, you must set -parallel mpi_omp if you want XIOS"; exit 1
269    fi
270
271    if [[ $with_xios = "y" ]]; then
272        opt_makelmdz_xios="-io xios"
273    fi
274
275    if [[ $cosp = "v2" && $with_xios = "n" ]]; then
276        echo "Error, Cospv2 cannot run without Xios"; exit 1
277    fi
278}
279
280function check_available_software {
281    if [[ $check_software_linux = 1 ]]; then
282        echo "################################################################"
283        echo "Check if required software is available"
284        echo "################################################################"
285
286        for logiciel in wget tar gzip make $compiler gcc cmake m4 c++; do
287            if [[ $(which "$logiciel") = "" ]]; then
288                echo "You must first install $logiciel on your system"; exit 1
289            fi
290        done
291
292        cat <<eod > tt.f90
293    print*,'coucou'
294    end
295eod
296        $compiler tt.f90 || a.out
297        ./a.out >| tt
298        if [[ $(< tt sed -e 's/ //g' ) != "coucou" ]]; then
299            echo "problem installing with compiler $compiler"; exit 1; fi
300        \rm tt a.out tt.f90
301    fi
302}
303
304function download_model {
305    mkdir -p "$MODEL"
306    MODEL=$(readlink -f "$MODEL"); echo "$MODEL"  # absolute path
307
308    if [[ $getlmdzor = 1 && ! -d $MODEL/modipsl ]]; then
309        echo "##########################################################"
310        echo "Download a slightly modified version of  LMDZ"
311        echo "##########################################################"
312        cd "$MODEL"
313        getlog="$(pwd)/get.log"
314        echo "logfile : $getlog"
315        myget "src_archives/$trusting/modipsl.$version.tar.gz" >> get.log 2>&1
316        echo "install_lmdz.sh wget_OK $(date)"
317        gunzip "modipsl.$version.tar.gz" >> get.log 2>&1
318        tar xf "modipsl.$version.tar" >> get.log 2>&1
319        \rm "modipsl.$version.tar"
320    fi
321
322    if [[ $svn != "" ]]; then
323        mysvn=$svn
324    else
325        mysvn="$(grep 'Revision: [0-9]' "$MODEL"/Read*.md | awk ' { print $2 } ' 2>/dev/null)"
326    fi
327    echo "SVN revision used: $mysvn"
328}
329
330function setup_local_arch {
331    # Setup local arch, and correspondance between arch names accross different programs
332
333    case $arch in
334        local)
335            arch_ioipsl="gfortran"
336            arch_xios="local"
337
338            cat <<EOF >"$MODEL/modipsl/modeles/IOIPSL/arch/arch-${arch_ioipsl}.path"  # fix bad IOIPSL arch files...
339NETCDF_INCDIR="\$(nf-config --fflags)"
340NETCDF_LIBDIR="\$(nf-config --flibs)"
341EOF
342        ;;
343      *) arch_ioipsl=$arch
344         arch_xios=$arch
345  esac
346}
347
348function install_netcdf {
349    echo "Installing Netcdf"
350
351    if [[ $netcdf = 0 ]]; then
352        ncdfdir=$(nc-config --prefix)
353    else
354        cd "$MODEL"
355
356        case $compiler in
357          gfortran) opt1="-compiler gnu"; opt2="-CC gcc -FC gfortran -CXX g++";;
358          ifort)  opt1="-compiler intel"; opt2="-CC icc -FC ifort -CXX icpc";;
359          pgf90)  opt1="-compiler pgf90"; opt2="-CC pgcc -FC pgf90 -CXX pgCC";;
360          *)      echo "unexpected compiler $compiler" for netcdf; exit 1
361        esac
362
363        case $with_xios in
364            n) script_install_netcdf="install_netcdf4_hdf5_seq.bash"
365               ncdfdir="netcdf4_hdf5_seq"
366               opt_="$opt1";;
367            y) script_install_netcdf="install_netcdf4_hdf5.bash"
368               ncdfdir="netcdf4_hdf5"
369               opt_="$opt2 -MPI $root_mpi";;
370            *) echo "with_xios=$with_xios, should be n or y"; exit 1
371        esac
372        if [[ $netcdf = 1 ]]; then
373           ncdfdir="$MODEL/$ncdfdir"
374        else
375           mkdir -p "$netcdf"; ncdfdir="$netcdf/$ncdfdir"
376        fi
377
378        echo "Repertoire netcdf $ncdfdir"
379        if [[ ! -d $ncdfdir ]]; then
380            netcdflog=$(pwd)/netcdf.log
381            echo "----------------------------------------------------------"
382            echo "Compiling the Netcdf library"
383            echo "----------------------------------------------------------"
384            echo "log file : $netcdflog"
385            myget script_install/$script_install_netcdf >> "$netcdflog" 2>&1
386            chmod u=rwx $script_install_netcdf
387            # shellcheck disable=SC2086
388            ./$script_install_netcdf -prefix "$ncdfdir" $opt_ >> "$netcdflog" 2>&1
389        fi
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 $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
422function install_IOIPSL {  # via fcm
423  if [[ ! -f $MODEL/modipsl/lib/libioipsl.a ]]; then
424    cd "$MODEL/modipsl/modeles/IOIPSL"
425    ioipsllog="$(pwd)/ioipsl.log"
426    echo "Compiling IOIPSL, the interface library with Netcdf $(date) (log: $ioipsllog)"
427
428    if ! ./makeioipsl_fcm -arch "$arch_ioipsl" -job 8 > "$ioipsllog" 2>&1; then
429      echo "IOIPSL compile failed, exiting"; exit 1
430    fi
431    cp lib/* ../../lib
432    echo "IOIPSL compiled $(date)"
433  fi
434}
435
436function install_XIOS {
437    if [[ $with_xios = "y"  && ! -f "$MODEL/modipsl/modeles/XIOS/lib/libxios.a" ]]; then
438        cd "$MODEL/modipsl/modeles"
439        xioslog="$(pwd)/xios.log"
440        echo "##########################################################"
441        echo "Compiling XIOS (log $xioslog) $(date)"
442        echo "##########################################################"
443        myget script_install/install_xios.bash
444
445        if ! ./install_xios.bash -prefix "$MODEL/modipsl/modeles" -arch "$arch_xios" > "$xioslog" 2>&1; then
446            echo "XIOS compilation failed, exiting"; exit 1
447        fi
448
449        echo "Compiled XIOS $(date)"
450    fi
451}
452
453echo "install_lmdz.sh DEBUT $(date)"
454
455set_default_params
456read_cmdline_args "$@"
457check_available_software
458download_model
459setup_local_arch
460install_netcdf
461install_IOIPSL
462install_XIOS
463
464exit 0
465
466
467
468
469################################################################
470# Specificite des machines
471################################################################
472
473hostname=$(hostname)
474#case ${hostname:0:5} in
475#    *)       if [[ $parallel = none || -f /usr/bin/mpif90 ]]; then
476#                 path_mpi=$(which mpif90 | sed -e s:/mpif90::);
477#                 if [[ -d /usr/lib64/openmpi ]]; then
478#                     root_mpi="/usr/lib64/openmpi"
479#                 else
480#                     root_mpi="/usr"
481#                 fi
482#             else
483#                 echo "Cannot find mpif90";
484#                 if [[ $parallel = none ]]; then exit 1; fi;
485#             fi;
486#             if [[ $parallel != none ]]; then
487#                 root_mpi=$(which mpif90 | sed -e s:/bin/mpif90::)
488#                 path_mpi=$(which mpif90 | sed -e s:/mpif90::)
489#                 export LD_LIBRARY_PATH=${root_mpi}/lib:$LD_LIBRARY_PATH
490#             fi
491#             par_comp=${path_mpi}/mpif90;
492#             mpirun=${path_mpi}/mpirun;
493#             arch="local" ;
494#             make="make";
495#             o_ins_make="-t g95"
496#esac
497
498## Flags for parallelism:
499#if [[ $parallel != none ]]; then
500#    # MPI_LD are the flags needed for linking with MPI
501#    MPI_LD="-L${root_mpi}/lib -lmpi"
502#    if [[ $compiler = "gfortran" ]]; then
503#        # MPI_FLAGS are the flags needed for compilation with MPI
504#        MPI_FLAGS="-fcray-pointer"
505#        # OMP_FLAGS are the flags needed for compilation with OpenMP
506#        OMP_FLAGS="-fopenmp -fcray-pointer"
507#        # OMP_LD are the flags needed for linking with OpenMP
508#        OMP_LD="-fopenmp"
509#    elif [[ $compiler = "ifort" ]]; then
510#        MPI_FLAGS=""
511#        OMP_FLAGS="-openmp"
512#        OMP_LD="-openmp"
513#    else # pgf90
514#        MPI_FLAGS=""
515#        OMP_FLAGS="-mp"
516#        OMP_LD="-mp"
517#    fi
518#fi
519#
520#
521#echo "################################################################"
522#echo  "Choix des options de compilation"
523#echo "################################################################"
524#
525#export FC=$compiler
526#export F90=$compiler
527#export F77=$compiler
528#export CPPFLAGS=
529#OPTIMNC=""
530#BASE_LD="$OPT_GPROF"
531#OPTPREC="$OPT_GPROF"
532#ARFLAGS="rs"
533#if [[ $(lsb_release -i -s) = "Ubuntu" ]]; then
534#    if [[ $(lsb_release -r -s | cut -d. -f1) -ge 16 ]]; then
535#        ARFLAGS="rU"
536#    fi
537#fi
538#
539#if [[ $compiler = "gfortran" ]]; then
540#   OPTIM="-O3 $allow_arg_mismatch"
541#   OPTDEB="-g3 -Wall -fbounds-check -ffpe-trap=invalid,zero,overflow -O0 -fstack-protector-all -fbacktrace -finit-real=snan  $allow_arg_mismatch"
542#   OPTDEV="-Wall -fbounds-check  $allow_arg_mismatch"
543#   fmod="I "
544#   OPTPREC="$OPTPREC -cpp -ffree-line-length-0"
545#   if [[ $real = r8 ]]; then OPTPREC="$OPTPREC -fdefault-real-8 -DNC_DOUBLE"; fi
546#   export F90FLAGS=" -ffree-form $OPTIMNC"
547#   export FFLAGS=" $OPTIMNC"
548#   export CC=gcc
549#   export CXX=g++
550#   export fpp_flags="-P -C -traditional -ffreestanding"
551#
552#elif [[ $compiler = mpif90 ]]; then
553#    OPTIM="-O3"
554#    OPTDEB="-g3 -Wall -fbounds-check -ffpe-trap=invalid,zero,overflow -O0 -fstack-protector-all"
555#    OPTDEV="-Wall -fbounds-check"
556#    BASE_LD="$BASE_LD -lblas"
557#    fmod="I "
558#    if [[ $real = r8 ]]; then
559#        OPTPREC="$OPTPREC -fdefault-real-8 -DNC_DOUBLE -fcray-pointer"
560#    fi
561#    export F90FLAGS=" -ffree-form $OPTIMNC"
562#    export FFLAGS=" $OPTIMNC"
563#    export CC=gcc
564#    export CXX=g++
565#
566#elif [[ $compiler = pgf90 ]]; then
567#    OPTIM="-O2 -Mipa -Munroll -Mnoframe -Mautoinline -Mcache_align"
568#    OPTDEB="-g -Mdclchk -Mbounds -Mchkfpstk -Mchkptr -Minform=inform -Mstandard -Ktrap=fp -traceback"
569#    OPTDEV="-g -Mbounds -Ktrap=fp -traceback"
570#    fmod="module "
571#    if [[ $real = r8 ]]; then OPTPREC="$OPTPREC -r8 -DNC_DOUBLE"; fi
572#    export CPPFLAGS="-DpgiFortran"
573#    export CC=pgcc
574#    export CFLAGS="-O2 -Msignextend"
575#    export CXX=pgCC
576#    export CXXFLAGS="-O2 -Msignextend"
577#    export FFLAGS="-O2 $OPTIMNC"
578#    export F90FLAGS="-O2 $OPTIMNC"
579#    compile_with_fcm=1
580#
581#elif [[ $compiler = ifort || $compiler = mpiifort ]]; then
582#    OPTIM="-O2 -fp-model strict -ip -align all "
583#    OPTDEV="-p -g -O2 -traceback -fp-stack-check -ftrapuv -check"
584#    OPTDEB="-g -no-ftz -traceback -ftrapuv -fp-stack-check -check"
585#    fmod='module '
586#    if [[ $real = r8 ]]; then OPTPREC="$OPTPREC -real-size 64 -DNC_DOUBLE"; fi
587#    export CPP="icc -E"
588#    export FFLAGS="-O2 -ip -fpic -mcmodel=large"
589#    export FCFLAGS="-O2 -ip -fpic -mcmodel=large"
590#    export CC=icc
591#    export CFLAGS="-O2 -ip -fpic -mcmodel=large"
592#    export CXX=icpc
593#    export CXXFLAGS="-O2 -ip -fpic -mcmodel=large"
594#    export fpp_flags="-P -traditional"
595#    # Pourquoi forcer la compilation fcm. Marche mieux sans
596#    #compile_with_fcm=1
597#else
598#    echo "unexpected compiler $compiler"; exit 1
599#fi
600#
601#OPTIMGCM="$OPTIM $OPTPREC"
602
603
604
605
606#============================================================================
607veget_version=false
608if [[ $veget != 'NONE' ]]; then
609    cd "$MODEL/modipsl/modeles/ORCHIDEE"
610    set +e; svn upgrade; set -e
611    if [[ $veget = "CMIP6" ]]; then
612        veget_version=orchidee2.0
613        orchidee_rev=6592
614    else # specific orchidee revision newer than CMIP6, on 2_1 or 2_2 branches
615        veget_version=orchidee2.1
616        orchidee_rev=$veget
617        if [[ $veget -lt 4465 ]]; then
618            echo 'Stopping, ORCHIDEE version too old, script needs work on ' \
619                 'the CPP flags to pass to makelmdz'
620            exit 1
621        fi
622        set +e
623        # which branch is my version on?
624        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}')
625        # switch to that branch
626        echo IF YOU INSTALL ORCHIDEE THE VERY FIRST TIME, ASK for PASSWORD at \
627             orchidee-help@listes.ipsl.fr
628        svn switch -r "$veget" --accept theirs-full "svn://forge.ipsl.jussieu.fr/orchidee/$orcbranch"
629        if ! (svn log -r "$veget" | grep "$veget"); then
630            echo 'Cannot update ORCHIDEE as not on the right branch for ORCHIDEE'
631            exit 1
632        fi
633        set -e
634        set +e; svn update -r "$veget"; set -e
635    fi
636    # Correctif suite debug Jean-Zay
637    sed -i -e 's/9010  FORMAT(A52,F17.14)/9010  FORMAT(A52,F20.14)/' \
638        src_stomate/stomate.f90
639    opt_orc="-prod"; if [[ "$optim" = "-debug" ]]; then opt_orc="-debug"; fi
640
641    orchideelog=$(pwd)/orchidee.log
642    echo '########################################################'
643    echo 'Compiling ORCHIDEE, the continental surface model '
644    echo '########################################################'
645    echo "Start of the first compilation of orchidee, in sequential mode: $(date)"
646    echo "log file : $orchideelog"
647
648    ORCHPATH=$(pwd)
649    export ORCHPATH=$ORCHPATH
650    xios_orchid="-noxios"
651    if [[ "$with_xios" = "y" ]]; then
652        xios_orchid="-xios"
653    fi
654    if [[ -d tools ]]; then
655        ###################################################################
656        # Pour les experts qui voudraient changer de version d'orchidee.
657        # Attention : necessite d'avoir le password pour orchidee
658        ###################################################################
659        if [[ "$veget_version" == "false" ]]; then
660            veget_version=orchidee2.0
661        fi
662        cd arch
663        sed -e s:"%COMPILER        .*.$:%COMPILER            $compiler":1 \
664            -e s:"%LINK            .*.$:%LINK                $compiler":1 \
665            -e s:"%FPP_FLAGS       .*.$:%FPP_FLAGS           $fpp_flags":1 \
666            -e s:"%PROD_FFLAGS     .*.$:%PROD_FFLAGS         $OPTIM":1 \
667            -e s:"%DEV_FFLAGS      .*.$:%DEV_FFLAGS          $OPTDEV":1 \
668            -e s:"%DEBUG_FFLAGS    .*.$:%DEBUG_FFLAGS        $OPTDEB":1 \
669            -e s:"%BASE_FFLAGS     .*.$:%BASE_FFLAGS         $OPTPREC":1 \
670            -e s:"%BASE_LD         .*.$:%BASE_LD             $BASE_LD":1 \
671            -e s:"%ARFLAGS         .*.$:%ARFLAGS             $ARFLAGS":1 \
672            arch-gfortran.fcm > arch-local.fcm
673        cat <<EOF > arch-local.path
674NETCDF_LIBDIR="-L$ncdfdir/lib -lnetcdff -lnetcdf"
675NETCDF_INCDIR="$ncdfdir/include"
676IOIPSL_INCDIR="$ORCHPATH/../../lib"
677IOIPSL_LIBDIR="$ORCHPATH/../../lib"
678XIOS_INCDIR="\$ORCHDIR/../XIOS/inc"
679XIOS_LIBDIR="\$ORCHDIR/../XIOS/lib -lxios"
680EOF
681        cd ../
682
683        echo ./makeorchidee_fcm -j $xios_orchid $opt_orc -parallel none \
684             -arch $arch
685        ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc -parallel none \
686                           -arch $arch > "$orchideelog" 2>&1
687        pwd
688    else # of "if [[ -d tools ]]"
689        if [[ -d src_parallel ]]; then
690            liste_src="parallel parameters global stomate sechiba driver"
691            if [[ "$veget_version" == "false" ]]; then
692                veget_version=orchidee2.0
693            fi
694        fi
695        for d in $liste_src; do
696            src_d=src_$d
697            echo src_d "$src_d"
698            echo ls; ls
699            if [[ ! -d $src_d ]]; then
700                echo "Problem orchidee : no $src_d"; exit 1
701            fi
702            cd "$src_d"; \rm -f -- *.mod make; $make clean
703            $make > "$orchideelog" 2>&1
704            if [[ "$compiler" = "gfortran" || "$compiler" = "mpif90" ]]; then
705                cp -f -- *.mod ../../../lib
706            fi
707            cd ..
708        done
709    fi # of "if [[ -d tools ]]"
710    echo "install_lmdz.sh orchidee_compil_seq_OK $(date)"
711fi # of if [[ "$veget" != 'NONE' ]]
712
713
714#============================================================================
715# Ehouarn: the directory name LMDZ* depends on version/tar file...
716if find . -name "$MODEL/modipsl/modeles/LMD*"; then
717    echo '###############################################################'
718    echo 'Preparing LMDZ compilation : arch file, svn switch if needed...'
719    echo '###############################################################'
720    cd "$MODEL/modipsl/modeles/"LMD*
721    LMDZPATH=$(pwd)
722else
723    echo "ERROR: No LMD* directory !!!"
724    exit 1
725fi
726
727
728###########################################################
729# For those who want to use fcm to compile via :
730#  makelmdz_fcm -arch local .....
731############################################################
732
733
734
735cd "$MODEL/modipsl/modeles"/LMDZ*
736lmdzlog=$(pwd)/lmdz.log
737
738##################################################################
739# Possibly update LMDZ if a specific svn release is requested
740##################################################################
741
742set +e; svn upgrade; set -e
743
744if [[ $svn = "last" ]]; then svnopt=""; else svnopt="-r $svn"; fi
745if [[ $svn != "" ]]; then
746    if set +e; svn info | grep -q 'https:'; then
747        svn switch --relocate https://svn.lmd.jussieu.fr/LMDZ \
748            http://svn.lmd.jussieu.fr/LMDZ
749    fi
750    svn update "$svnopt"
751    set -e
752fi
753
754#---------------------------------------------------------------------
755# Retrieve the final svn release number, and adjust compilation
756# options accordingly
757# If svn not available, will use the svn writen in $MODEL/Readm*md
758# For old version it assumes that it is before 4185 (the version
759# for which the test was introduced
760#---------------------------------------------------------------------
761
762set +e; mysvn=$(svnversion . | grep -E || "[0-9]+" 2>/dev/null); set -e
763if [[ "$mysvn" = "" ]]; then mysvn=$(grep 'Revision: [0-9]' "$MODEL"/Read*.md | awk ' { print $2 } ' 2>/dev/null); fi
764if [[ "$mysvn" = "" ]]; then mysvn=4190; fi
765
766if [[ "$pclinux" = "1" && ! -f arch/arch-local.path ]]; then
767
768    # create local 'arch' files (if on Linux PC):
769    cd arch
770    # arch-local.path file
771    # test for version as arch.pth file changed format with rev 4426
772    if [[ "$mysvn" -gt 4425 ]]; then
773      cat <<EOF > arch-local.path
774NETCDF_LIBDIR="-L$ncdfdir/lib"
775NETCDF_LIB="-lnetcdff -lnetcdf"
776NETCDF_INCDIR=-I$ncdfdir/include
777NETCDF95_INCDIR=-I\$LMDGCM/../../include
778NETCDF95_LIBDIR=-L\$LMDGCM/../../lib
779NETCDF95_LIB=-lnetcdf95
780IOIPSL_INCDIR=-I\$LMDGCM/../../lib
781IOIPSL_LIBDIR=-L\$LMDGCM/../../lib
782IOIPSL_LIB=-lioipsl
783XIOS_INCDIR=-I\$LMDGCM/../XIOS/inc
784XIOS_LIBDIR=-L\$LMDGCM/../XIOS/lib
785XIOS_LIB="-lxios -lstdc++"
786ORCH_INCDIR=-I\$LMDGCM/../../lib
787ORCH_LIBDIR=-L\$LMDGCM/../../lib
788EOF
789    else
790      cat <<EOF > arch-local.path
791NETCDF_LIBDIR="-L$ncdfdir/lib -lnetcdff -lnetcdf"
792NETCDF_INCDIR=-I$ncdfdir/include
793NETCDF95_INCDIR=\$LMDGCM/../../include
794NETCDF95_LIBDIR=\$LMDGCM/../../lib
795IOIPSL_INCDIR=\$LMDGCM/../../lib
796IOIPSL_LIBDIR=\$LMDGCM/../../lib
797XIOS_INCDIR=\$LMDGCM/../XIOS/inc
798XIOS_LIBDIR=\$LMDGCM/../XIOS/lib
799ORCH_INCDIR=\$LMDGCM/../../lib
800ORCH_LIBDIR=\$LMDGCM/../../lib
801EOF
802    fi 
803
804    if [[ $pcmac == 1 ]]; then
805        BASE_LD="$BASE_LD -Wl,-rpath,${ncdfdir}/lib"
806    else
807        BASE_LD="$BASE_LD -Wl,-rpath=${ncdfdir}/lib"
808    fi
809    # Arch-local.fcm file (adapted from arch-linux-32bit.fcm)
810
811    if [[ $real = r8 ]]; then FPP_DEF=NC_DOUBLE; else FPP_DEF=""; fi
812    sed -e s:"%COMPILER        .*.$:%COMPILER            $compiler":1 \
813        -e s:"%LINK            .*.$:%LINK                $compiler":1 \
814        -e s:"%PROD_FFLAGS     .*.$:%PROD_FFLAGS         $OPTIM":1 \
815        -e s:"%DEV_FFLAGS      .*.$:%DEV_FFLAGS          $OPTDEV":1 \
816        -e s:"%DEBUG_FFLAGS    .*.$:%DEBUG_FFLAGS        $OPTDEB":1 \
817        -e s:"%BASE_FFLAGS     .*.$:%BASE_FFLAGS         $OPTPREC":1 \
818        -e s:"%FPP_DEF         .*.$:%FPP_DEF             $FPP_DEF":1 \
819        -e s:"%BASE_LD         .*.$:%BASE_LD             $BASE_LD":1 \
820        -e s:"%ARFLAGS         .*.$:%ARFLAGS             $ARFLAGS":1 \
821        arch-linux-32bit.fcm > arch-local.fcm
822
823    cd ..
824    ### Adapt "bld.cfg" (add the shell):
825    #whereisthatshell=$(which ${use_shell})
826    #echo "bld::tool::SHELL   $whereisthatshell" >> bld.cfg
827
828fi # of if [[ "$pclinux" = 1 ]]
829#---------------------------------------------------------------------
830# Option de compilation du rayonnement : depend de $mysvn ><= r4185
831#---------------------------------------------------------------------
832opt_rad=""
833
834case $rad in
835    oldrad) iflag_rrtm=0; NSW=2; opt_rad="";;
836    rrtm)   iflag_rrtm=1; NSW=6
837            if [[ $mysvn -le 4185 ]]; then
838                opt_rad="-rrtm true"
839            else
840                opt_rad="-rad rrtm"
841            fi;;
842    ecrad)  iflag_rrtm=2; NSW=6; opt_rad="-rad ecrad";;
843    *) echo "Only oldrad rrtm ecrad for rad option"; exit 1
844esac
845
846if [[ $mysvn -le 4185 && $rad = "ecrad" ]]; then
847    echo "ecrad only available for LMDZ rev starting with 4186 "; exit 1
848fi
849
850##################################################################
851
852
853if [[ ! -f libf/misc/netcdf95.F90 &&  ! -d $MODEL/NetCDF95-0.3 ]]; then
854    cd "$MODEL"
855    myget src_archives/netcdf/NetCDF95-0.3.tar.gz
856    tar -xf NetCDF95-0.3.tar.gz
857    rm NetCDF95-0.3.tar.gz
858    cd NetCDF95-0.3
859    mkdir build
860    cd build
861    cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$ncdfdir" \
862          -DCMAKE_INSTALL_PREFIX="$MODEL/modipsl"
863    make install
864    cd "$MODEL/modipsl/modeles/"LMDZ*
865fi
866
867echo '##################################################################'
868echo "Preparing script compile.sh for LMDZ compilation"
869echo "It will only be run automatically if bench=1/tuto"
870echo "Here bench=$bench"
871echo '##################################################################'
872
873if [[ $env_file != "" ]]; then
874    mv arch/arch-${arch}.env arch/arch-${arch}.orig
875    \cp -f "$env_file" arch/arch-${arch}.env
876fi
877
878if [[ $compile_with_fcm = 1 ]]; then
879    makelmdz="makelmdz_fcm $optim -arch $arch -j 8 "
880else
881    makelmdz="makelmdz $optim -arch $arch"
882fi
883
884# sequential compilation
885if [[ "$sequential" = 1 ]]; then
886    echo Sequential compilation command, saved in compile.sh:
887    echo "./$makelmdz $optim $OPT_MAKELMDZ $optim $opt_rad $opt_cosp " \
888         "-d ${grid_resolution} -v $veget_version gcm "
889    echo "./$makelmdz $optim $OPT_MAKELMDZ $optim $opt_rad $opt_cosp " \
890         "-d ${grid_resolution} -v $veget_version gcm " > compile.sh
891    chmod +x ./compile.sh
892    if [[ $bench = 1 ]]; then
893        echo "install_lmdz.sh start_lmdz_seq_compilation $(date)"
894        echo "log file: $lmdzlog"
895        ./compile.sh > "$lmdzlog" 2>&1
896        echo "install_lmdz.sh end_lmdz_seq_compilation $(date)"
897    fi
898fi # fin sequential
899
900# compiling in parallel mode
901if [[ $parallel != "none" ]]; then
902    echo '##########################################################'
903    echo ' Parallel compile '
904    echo '##########################################################'
905    echo "(after saving the sequential libs and binaries)"
906    cd "$MODEL/modipsl"
907    tar cf sequential.tar bin/ lib/
908    #
909    # Orchidee
910    #
911    cd "$ORCHPATH"
912    if [[ -d src_parallel && $veget != 'NONE' ]]; then
913        cd arch
914        sed  \
915            -e s:"%COMPILER.*.$:%COMPILER            $par_comp":1 \
916            -e s:"%LINK.*.$:%LINK                $par_comp":1 \
917            -e s:"%MPI_FFLAG.*.$:%MPI_FFLAGS          $MPI_FLAGS":1 \
918            -e s:"%OMP_FFLAG.*.$:%OMP_FFLAGS          $OMP_FLAGS":1 \
919            -e s:"%MPI_LD.*.$:%MPI_LD              $MPI_LD":1 \
920            -e s:"%OMP_LD.*.$:%OMP_LD              $OMP_LD":1 \
921            arch-local.fcm > tmp.fcm
922
923        mv tmp.fcm arch-local.fcm
924        cd ../
925        echo "Compiling ORCHIDEE in parallel mode $(date)"
926        echo "logfile $orchideelog"
927        echo "NOTE : to recompile it when necessary, use ./compile_orc.sh " \
928             "in modipsl/modeles/ORCHIDEE"
929        echo ./makeorchidee_fcm -j 8 -clean $xios_orchid $opt_orc \
930             -parallel "$parallel" -arch $arch > compile_orc.sh
931        echo ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc \
932             -parallel "$parallel" -arch $arch >> compile_orc.sh
933        echo echo Now you must also recompile LMDZ, by running ./compile.sh \
934             in modeles/LMDZ >> compile_orc.sh
935        chmod u+x compile_orc.sh
936        ./makeorchidee_fcm -j 8 -clean $xios_orchid $opt_orc \
937                           -parallel "$parallel" -arch $arch > "$orchideelog" 2>&1
938        ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc -parallel "$parallel" \
939                           -arch $arch >> "$orchideelog" 2>&1
940        echo "End of ORCHIDEE compilation in parallel mode $(date)"
941    elif [[ $veget != 'NONE' ]]; then
942        echo '##########################################################'
943        echo ' Orchidee version too old                                 '
944        echo ' Please update to new version                             '
945        echo '##########################################################'
946        exit 1
947    fi #�of [ -d src_parallel && $veget != 'NONE' ]
948
949    # LMDZ
950    cd "$LMDZPATH"
951    if [[ $arch = local ]]; then
952        cd arch
953        sed -e s:"%COMPILER.*.$:%COMPILER            $par_comp":1 \
954            -e s:"%LINK.*.$:%LINK                $par_comp":1 \
955            -e s:"%MPI_FFLAG.*.$:%MPI_FFLAGS          $MPI_FLAGS":1 \
956            -e s:"%OMP_FFLAG.*.$:%OMP_FFLAGS          $OMP_FLAGS":1 \
957            -e s:"%ARFLAGS.*.$:%ARFLAGS          $ARFLAGS":1 \
958            -e "s§%BASE_LD.*.$§%BASE_LD             -Wl,-rpath=${root_mpi}/lib:${ncdfdir}/lib§1" \
959            -e s:"%MPI_LD.*.$:%MPI_LD              $MPI_LD":1 \
960            -e s:"%OMP_LD.*.$:%OMP_LD              $OMP_LD":1 \
961            arch-local.fcm > tmp.fcm
962        mv tmp.fcm arch-local.fcm
963        cd ../
964    fi
965    rm -f compile.sh
966    echo resol="$grid_resolution" >> compile.sh
967    if [[ ${hostname:0:5} = jean- && "$cosp" = "v2" ]]; then
968
969        echo "LMDZ compilation command in parallel mode, saved in compile.sh, is :"
970        echo "(ATTENTION le probleme de cospv2 sur jean-zay en mode prod " \
971             "n est pas corrige ! )"
972        # ATTENTION le probleme de cospv2 sur jean-zay en mode prod n
973        # est pas corrige
974        echo ./"$makelmdz" -dev $optim "$OPT_MAKELMDZ" "$opt_rad" "$opt_cosp" \
975             "$opt_makelmdz_xios" -d \$resol -v $veget_version -mem \
976             -parallel "$parallel" gcm >> compile.sh
977        echo ./"$makelmdz" -dev $optim "$OPT_MAKELMDZ" "$opt_rad" "$opt_cosp" \
978             "$opt_makelmdz_xios" -d \$resol -v $veget_version -mem \
979             -parallel "$parallel" gcm
980    else
981        echo ./"$makelmdz" $optim "$OPT_MAKELMDZ" "$opt_rad" "$opt_cosp" \
982             "$opt_makelmdz_xios" -d \$resol -v $veget_version -mem \
983             -parallel "$parallel" gcm >> compile.sh
984        echo ./"$makelmdz" $optim "$OPT_MAKELMDZ" "$opt_rad" "$opt_cosp" \
985             "$opt_makelmdz_xios" -d \$resol -v $veget_version -mem \
986             -parallel "$parallel" gcm
987    fi
988    chmod +x ./compile.sh
989
990    if [[ $bench = 1 ]]; then
991        echo "Compiling LMDZ in parallel mode $(date),  LMDZ log file: $lmdzlog"
992        ./compile.sh > "$lmdzlog" 2>&1
993    fi
994
995fi # of if [[ $parallel != "none" ]]
996
997
998##################################################################
999# Verification du succes de la compilation
1000##################################################################
1001
1002# Recherche de l'executable dont le nom a change au fil du temps ...
1003# suffix contains radiative option starting with revision 4186
1004if [[ $mysvn -ge 4186 ]]; then suff_exe=_${rad}${suff_exe}; fi
1005gcm=""
1006
1007for exe in gcm.e bin/gcm_${grid_resolution}_phylmd${suff_exe}${suff_orc}.e
1008do
1009    if [[ -f $exe ]]; then gcm=$exe; fi
1010done
1011
1012if [[ "$gcm" = "" ]]; then
1013    if [[ $bench = 1 ]]; then
1014        echo 'Compilation failed !! Cannot run the benchmark;'
1015        exit 1
1016    else
1017        echo 'Compilation not done (only done when bench=1)'
1018    fi
1019else
1020    echo '##########################################################'
1021    echo "Compilation successfull !!  $(date)"
1022    echo '##########################################################'
1023    echo "The executable is $gcm"
1024fi
1025
1026##################################################################
1027# Below, we run a benchmark if bench=1 or tuto
1028##################################################################
1029
1030if [[ $bench = tuto ]]; then
1031    myget Training/tutorial.tar; tar xf tutorial.tar; cd TUTORIAL
1032    ./init.sh
1033
1034elif [[ $bench = 1 && ! -d BENCH${grid_resolution} ]]; then
1035    # TOUTE CETTE SECTION DEVRAIT DISPARAITRE POUR UNE COMMANDE
1036    # OU DES BENCHS PAR MOTS CLES COMME tuto
1037
1038    echo '##########################################################'
1039    echo ' Running a test run '
1040    echo '##########################################################'
1041
1042    \rm -rf "BENCH${grid_resolution}"
1043    bench=bench_lmdz_${grid_resolution}
1044    echo "install_lmdz.sh before bench download  $(date)"
1045    #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/$bench.tar.gz
1046    myget "3DBenchs/$bench.tar.gz"
1047    echo "install_lmdz.sh after bench download  $(date)"
1048    tar xf "$bench.tar.gz"
1049
1050    if [[ "$cosp" = "v1" || "$cosp" = "v2" ]]; then
1051        cd "BENCH${grid_resolution}"
1052        # copier les fichiers namelist input et output our COSP
1053        cp ../DefLists/cosp*_input_nl.txt .
1054        cp ../DefLists/cosp*_output_nl.txt .
1055        # Activer la cles ok_cosp pour tourner avec COSP
1056        sed -e 's@ok_cosp=n@ok_cosp=y@' config.def > tmp
1057        \mv -f tmp config.def
1058        cd ..
1059    fi
1060
1061    if [[ -n "$physiq" ]]; then
1062        cd "BENCH${grid_resolution}"
1063        if [[ -f "physiq.def_${physiq}" ]]; then
1064            cp "physiq.def_${physiq}" physiq.def
1065            echo using "physiq.def_${physiq}"
1066        else
1067            echo using standard physiq.def
1068        fi
1069        cd ..
1070    else
1071        echo using standard physiq.def
1072    fi
1073
1074    if [[ "$with_xios" = "y" ]]; then
1075        cd "BENCH${grid_resolution}"
1076        cp ../DefLists/iodef.xml .
1077        cp ../DefLists/context_lmdz.xml .
1078        cp ../DefLists/field_def_lmdz.xml .
1079        # A raffiner par la suite
1080        echo "A FAIRE : Copier les *xml en fonction de l option cosp"
1081        cp ../DefLists/field_def_cosp*.xml .
1082        cp ../DefLists/file_def_hist*xml .
1083        # adapt iodef.xml to use attached mode
1084        sed -e 's@"using_server" type="bool">true@"using_server" type="bool">false@' \
1085            iodef.xml > tmp
1086        \mv -f tmp iodef.xml
1087
1088        # and convert all the enabled="_AUTO_" (for libIGCM) to enabled=.FALSE.
1089        # except for histday
1090        for histfile in file_def_hist*xml
1091        do
1092            if [[ "$histfile" = "file_def_histday_lmdz.xml" ]]; then
1093                sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".TRUE."@' \
1094                    "$histfile" > tmp
1095                \mv -f tmp "$histfile"
1096                sed -e 's@output_level="_AUTO_"@output_level="5"@' "$histfile" \
1097                    > tmp
1098                \mv -f tmp "$histfile"
1099                sed -e 's@compression_level="2"@compression_level="0"@' \
1100                    "$histfile" > tmp
1101                \mv -f tmp "$histfile"
1102            else
1103                sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \
1104                    "$histfile" > tmp
1105                \mv -f tmp "$histfile"
1106            fi
1107        done
1108        # and add option "ok_all_xml=y" in config.def
1109        echo "### XIOS outputs" >> config.def
1110        echo 'ok_all_xml=.true.' >> config.def
1111
1112        #activer les sorties pour Cosp
1113        if [[ "$cosp" = "v1" ]]; then
1114            sed -i'' -e 's@enabled=".FALSE."@enabled=".TRUE."@' \
1115                     -e 's@output_level="_AUTO_"@output_level="5"@' \
1116                     -e 's@compression_level="2"@compression_level="0"@' \
1117                     file_def_histdayCOSP_lmdz.xml
1118        fi
1119        if [[ "$cosp" = "v2" ]]; then
1120            sed -e 's@compression_level="2"@compression_level="0"@' file_def_histdayCOSPv2_lmdz.xml
1121            for type_ in hf day mth; do
1122                file=file_def_hist${type_}COSP
1123                sed -i'' -e 's@src="./'${file}'_lmdz.xml"@src="./'${file}'v2_lmdz.xml"@' context_lmdz.xml
1124            done
1125            sed -i '' -e 's@field_def_cosp1.xml@field_def_cospv2.xml@' field_def_lmdz.xml
1126        fi
1127
1128        cd ..
1129    fi
1130
1131    # Cas Bensh avec ecrad
1132    if [[ "$rad" = "ecrad" ]]; then
1133        cd "BENCH${grid_resolution}"
1134        cp  ../DefLists/namelist_ecrad .
1135        cp -r ../libf/phylmd/ecrad/data .
1136        cd ..
1137    fi
1138
1139    # Adjusting bench physiq.def to radiative code chosen
1140    cd "BENCH${grid_resolution}"
1141    sed -e 's/iflag_rrtm=.*.$/iflag_rrtm='$iflag_rrtm'/' \
1142        -e 's/NSW=.*.$/NSW='$NSW'/' physiq.def > tmpdef
1143    \mv tmpdef physiq.def
1144    cd ..
1145
1146    cp "$gcm" "BENCH${grid_resolution}/gcm.e"
1147
1148    cd "BENCH${grid_resolution}"
1149    # On cree le fichier bench.sh au besoin
1150    # Dans le cas 48x36x39 le bench.sh existe deja en parallele
1151
1152    if [[ "$grid_resolution" = "48x36x39" ]]; then
1153        echo On ne touche pas au bench.sh
1154        # But we have to adapt "run_local.sh" for $mpirun
1155        sed -e "s@mpirun@$mpirun@g" run_local.sh > tmp
1156        mv -f tmp run_local.sh
1157        chmod u=rwx run_local.sh
1158    elif [[ "${parallel:0:3}" = "mpi" ]]; then
1159        # Lancement avec deux procs mpi et 2 openMP
1160        echo "export OMP_STACKSIZE=800M" > bench.sh
1161        if [[ "${parallel:4:3}" = "omp" ]]; then
1162            echo "export OMP_NUM_THREADS=2" >> bench.sh
1163        fi
1164        if [[ "$cosp" = "v1" || "$cosp" = "v2" ]]; then
1165            if [[ ${hostname:0:5} = jean- ]]; then
1166                   chmod +x ../arch.env
1167                ../arch.env       
1168                echo "ulimit -s 2000000" >> bench.sh
1169            else
1170                echo "ulimit -s 200000" >> bench.sh
1171            fi       
1172        else
1173            echo "ulimit -s unlimited" >> bench.sh
1174        fi
1175        if [[ ${hostname:0:5} = jean- ]]; then
1176            . ../arch/arch-${arch}.env
1177            echo "srun -n 2 && $idris_acct@cpu gcm.e > listing  2>&1" \
1178                 >> bench.sh
1179        else
1180            echo "$mpirun -np 2 gcm.e > listing  2>&1" >> bench.sh
1181        fi
1182        # Add rebuild, using reb.sh if it is there
1183        cat <<EOF >> bench.sh
1184if [[ -f reb.sh ]]; then
1185  ./reb.sh histday; ./reb.sh histmth; ./reb.sh histhf;
1186  ./reb.sh histins; ./reb.sh stomate_history;
1187  ./reb.sh sechiba_history; ./reb.sh sechiba_out_2
1188fi
1189EOF
1190    else
1191        echo "./gcm.e > listing  2>&1" > bench.sh
1192    fi
1193    # Getting orchidee stuff
1194    if [[ $veget == 'CMIP6' ]]; then
1195        #echo 'myget 3DBenchs/BENCHorch11.tar.gz'
1196        #myget 3DBenchs/BENCHorch11.tar.gz
1197        #tar xvzf BENCHorch11.tar.gz
1198        echo 'myget 3DBenchs/BENCHCMIP6.tar.gz'
1199        myget 3DBenchs/BENCHCMIP6.tar.gz
1200        tar xvzf BENCHCMIP6.tar.gz
1201        sed -e "s:VEGET=n:VEGET=y:" config.def > tmp
1202        mv -f tmp config.def
1203        if [[ "$with_xios" = "y" ]]; then
1204            cp ../../ORCHIDEE/src_xml/context_orchidee.xml .
1205            echo '<context id="orchidee" src="./context_orchidee.xml"/>' \
1206                 > add.tmp
1207            cp ../../ORCHIDEE/src_xml/field_def_orchidee.xml .
1208            cp ../../ORCHIDEE/src_xml/file_def_orchidee.xml .
1209            cp ../../ORCHIDEE/src_xml/file_def_input_orchidee.xml .
1210            if [[ -f ../../ORCHIDEE/src_xml/context_input_orchidee.xml ]]; then
1211                   cp ../../ORCHIDEE/src_xml/context_input_orchidee.xml .
1212                   echo '<context id="orchidee" ' \
1213                     'src="./context_input_orchidee.xml"/>' >> add.tmp
1214            fi
1215            sed -e '/id="LMDZ"/r add.tmp' iodef.xml > tmp
1216            mv tmp iodef.xml
1217            sed -e'{/sechiba1/ s/enabled="_AUTO_"/type="one_file" enabled=".TRUE."/}' \
1218                file_def_orchidee.xml > tmp
1219            \mv -f tmp file_def_orchidee.xml
1220            sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \
1221                file_def_orchidee.xml > tmp
1222            \mv -f tmp file_def_orchidee.xml
1223            sed -e 's@output_level="_AUTO_"@output_level="1"@' \
1224                file_def_orchidee.xml > tmp
1225            \mv -f tmp file_def_orchidee.xml
1226            sed -e 's@output_freq="_AUTO_"@output_freq="1d"@' \
1227                file_def_orchidee.xml > tmp
1228            \mv -f tmp file_def_orchidee.xml
1229            sed -e 's@compression_level="4"@compression_level="0"@' \
1230                file_def_orchidee.xml > tmp
1231            \mv -f tmp file_def_orchidee.xml
1232            sed -e 's@XIOS_ORCHIDEE_OK = n@XIOS_ORCHIDEE_OK = y@' \
1233                orchidee.def > tmp
1234            \mv -f tmp orchidee.def
1235        fi
1236    fi
1237
1238    if [[ -f ../arch.env ]]
1239    then
1240        source ../arch.env
1241    fi
1242
1243    echo EXECUTION DU BENCH
1244    set +e
1245    date; ./bench.sh > out.bench 2>&1; date
1246    set -e
1247    tail listing
1248
1249
1250    echo "##########################################################"
1251    echo "Simulation finished in $(pwd)"
1252    echo "You have compiled with:"
1253    cat ../compile.sh
1254    if [[ $parallel = "none" ]]; then
1255        echo "You may re-run it with : cd  $(pwd) ; gcm.e"
1256        echo "or ./bench.sh"
1257    else
1258        echo "You may re-run it with : "
1259        echo "cd  $(pwd) ; ./bench.sh"
1260        #  echo 'ulimit -s unlimited'
1261        #  echo 'export OMP_NUM_THREADS=2'
1262        #  echo 'export OMP_STACKSIZE=800M'
1263        #  echo "$mpirun -np 2 gcm.e "
1264    fi
1265    echo '##########################################################'
1266
1267fi # bench
1268
1269
1270#################################################################
1271# Installation eventuelle du 1D
1272#################################################################
1273
1274if [[ $SCM = 1 ]]; then
1275    cd "$MODEL"
1276    myget 1D/1D.tar.gz
1277    tar xf 1D.tar.gz
1278    cd 1D
1279    if [[ $rad = oldrad ]]; then
1280        sed -i'' -e 's/^rad=.*$/rad=oldrad/' run.sh
1281        sed -i'' -e 's/^rad=.*$/rad=oldrad/' bin/compile
1282    fi
1283    echo "Running 1D/run.sh, log in $(pwd)/run1d.log"
1284    ./run.sh > "$(pwd)/run1d.log" 2>&1
1285fi
1286
1287
1288#################################################################
1289# sauvegarde des options veget pour utilisation eventuelle tutorial_prod
1290#################################################################
1291cd "$MODEL/modipsl/modeles"
1292#echo surface_env file created in $MODEL
1293cat <<EOF >surface_env
1294veget=$veget
1295opt_veget="-v $veget_version"
1296orchidee_rev=$orchidee_rev
1297suforch=$suff_orc
1298EOF
Note: See TracBrowser for help on using the repository browser.