source: BOL/script_install/install_lmdz.sh @ 4372

Last change on this file since 4372 was 4372, checked in by fhourdin, 18 months ago

Ajout d'un Readme dans le tar contenant la svn

La nouvelle version de install_lmdz.sh fonctionne sans svn.
Quelques dépendances supplémentaires aussi dans install_lmdz.sh

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