source: BOL/script_install/install_lmdz.sh @ 4248

Last change on this file since 4248 was 4239, checked in by lguez, 22 months ago

Polish

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