source: BOL/script_install/install_lmdz.sh @ 4405

Last change on this file since 4405 was 4405, checked in by fhourdin, 16 months ago

Mise à jour de l'installation sur ~lmdz/pub

Nettoyage du répertoire ~/lmdz/pub
on met tous les scripts dans le répertoir script_install
géré sous svn sous "BOL".
pub/script_install devient donc le résultat d'un svn checkout.
On peut y faire directement des svn update.
Les scripts d'installationdes ordinateurs et de netcdf sont
maintenant gérés au même endroit.
Le script install_lmdz et modifié en conséquence et la gestion
de l'installation de netcdf dans ce script grandement allégée.

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