source: BOL/script_install/install_lmdz_new.sh @ 4217

Last change on this file since 4217 was 4217, checked in by lguez, 2 years ago

Bug fix: correct the name of NetCDF directory

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