source: BOL/script_install/install_lmdz_new.sh @ 4221

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

Define compiler variables for mpiifort

With mpiifort, we only need to add the definition of CC to compile
NetCDF95, but it is simpler to just merge the cases ifort and
mpiifort.

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