source: BOL/script_install/install_lmdz_new.sh @ 4219

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

Polish

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