source: BOL/script_install/install_lmdz.sh @ 4784

Last change on this file since 4784 was 4784, checked in by idelkadi, 5 months ago

Fixed error in install_lmdz.sh script to enable Cosp simulator in LMDZ

  • Property svn:executable set to *
File size: 57.8 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=20231022.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 10 ] ; 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
109trusting=testing
110OPT_GPROF=""
111OPT_MAKELMDZ=""
112MODEL=""
113
114## also compile XIOS? (and more recent NetCDF/HDF5 libraries) Default=no
115with_xios="n"
116opt_makelmdz_xios=""
117
118## compile with oldrad/rrtm/ecrad radiatif code (Default=rrtm)
119rad=rrtm
120
121## compile_with_fcm=1 : use makelmdz_fcm (1) or makelmdz (0)
122compile_with_fcm=1
123
124#Compilation with Cosp (cosp=NONE/v1/v2 ; default=NONE)
125cosp=NONE
126opt_cosp=""
127
128# Check if on a Mac
129if [ `uname` = "Darwin" ]
130then
131    pcmac=1
132    export MAKE=make
133fi
134#echo "pcmac="$pcmac
135
136env_file=""
137
138#########################################################################
139#  Options interactives
140#########################################################################
141while (($# > 0))
142do
143    case $1 in
144        "-h") cat <<........fin
145    $0 [ -v version ] [ -r svn_release ]
146           [ -parallel PARA ] [ -d GRID_RESOLUTION ] [ -bench 0/1 ]
147           [-name LOCAL_MODEL_NAME] [-gprof] [-opt_makelmdz] [-rad RADIATIF]
148
149    -v       "version" like 20150828.trunk
150             see http://www.lmd.jussieu.fr/~lmdz/Distrib/LISMOI.trunk
151
152    -r       "svn_release" : either the svn release number or "last"
153
154    -compiler gfortran|ifort|pgf90 (default: gfortran)
155
156    -parallel PARA : can be mpi_omp (mpi with openMP) or none (for sequential)
157
158    -d        GRID_RESOLUTION should be among the available benchs if -bench 1
159              among which : 48x36x19, 48x36x39
160              if wanting to run a bench simulation in addition to compilation
161              default : 48x36x19
162
163    -bench     activating the bench or not (0/1). Default 1
164
165    -testing/unstable
166
167    -name      LOCAL_MODEL_NAME : default = LMDZversion.release
168
169    -netcdf    0, 1 or PATH
170                   0: do not download NetCDF, look for it in standard locations
171               1: download and compile NetCDF
172                   PATH: full path to an existing installed NetCDF library
173
174    -xios      also download and compile the XIOS library
175               (requires the NetCDF4-HDF5 library, also installed by default)
176               (requires to also have -parallel mpi_omp)
177
178    -gprof     to compile with -pg to enable profiling with gprof
179
180    -cosp      to run without our with cospv1 or cospv2 [none/v1/v2]
181
182    -rad RADIATIF can be oldrad, rrtm or ecrad radiatif code
183
184    -nofcm     to compile without fcm
185
186    -SCM        install 1D version automatically
187
188    -debug      compile everything in debug mode
189
190    -opt_makelmdz     to call makelmdz or makelmdz_fcm with additional options
191
192    -physiq    to choose which physics package to use
193
194    -env_file  specify an arch.env file to overwrite the existing one
195
196    -veget surface model to run [NONE/CMIP6/xxxx]
197
198........fin
199              exit ;;
200        "-v") version=$2 ; shift ; shift ;;
201        "-r") svn=$2 ; shift ; shift ;;
202        "-compiler") compiler=$2
203                     case $compiler in
204                         "gfortran"|"ifort"|"pgf90") compiler=$2 ; shift
205                                                     shift ;;
206                         *) echo "Only gfortran , ifort or pgf90 for the " \
207                                 "compiler option"
208                            exit
209                     esac ;;
210        "-d") grid_resolution=$2 ; shift ; shift ;;
211        "-gprof") OPT_GPROF="-pg" ; shift ;;
212        "-unstable"|"-testing") trusting=`echo $1 | cut -c2-`  ; shift ;;
213        "-cosp") cosp=$2
214                 case $cosp in
215                     "none"|"v1"|"v2") cosp=$2 ; shift ; shift ;;
216                     *) echo Only none v1 v2 for cosp option ; exit
217                 esac ;;
218        "-nofcm") compile_with_fcm=0 ; echo This option will be reactivated soon '(promesse du 8dec2022)' ; exit 1 ;  shift ;;
219        "-SCM") SCM=1 ; shift ;;
220        "-opt_makelmdz") OPT_MAKELMDZ="$2" ; shift ; shift ;;
221        "-rrtm") rrtm="$2"
222                 if [ "$2" = "false" ] ; then
223                     rad="oldrad"
224                 else
225                     rad="rrtm"
226                 fi
227                 shift ; shift ;;
228        "-rad") rad=$2
229                case $rad in
230                    "oldrad"|"rrtm"|"ecrad") rad=$2 ; shift ; shift ;;
231                    *) echo Only oldrad rrtm ecrad for rad option ; exit
232                esac ;;
233        "-parallel") parallel=$2
234                     case $parallel in
235                         "none"|"mpi"|"omp"|"mpi_omp") parallel=$2 ; shift
236                                                       shift ;;
237                         *) echo Only none mpi omp mpi_omp for the parallel \
238                                 option
239                            exit
240                     esac ;;
241        "-bench") bench=$2 ; shift ; shift ;;
242        "-debug") optim=-debug ; shift ;;
243        "-name") MODEL=$2 ; shift ; shift ;;
244        "-netcdf") netcdf=$2 ; 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        *)  bash 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# Option de compilation pour Cosp
263opt_cosp=""
264case $cosp in
265    v1) opt_cosp="-cosp true" ;;
266    v2) opt_cosp="-cospv2 true" ;;
267esac
268
269# Check on veget version
270#if [ "$veget" != 'NONE'  -a "$veget" != "CMIP6" -a "$veget" != +([0-9]) ] ; then
271if [ $veget != 'NONE'   -a $veget != "CMIP6" ] ; then
272    re='^[0-9]+$'
273    if ! [[ $veget =~ $re ]] ; then
274        echo 'Valeur de l option veget non valable'
275        exit
276    fi
277fi
278
279#Define veget-related suffix for gcm name
280if [ "$veget" = 'NONE' ] ; then
281    suff_orc=''
282    #For use with tutorial, orchidee_rev is also defined (will be
283    #written in surface_env at the end of the script)
284    orchidee_rev=''
285else
286    suff_orc='_orch'
287fi
288
289
290if [ $parallel = none ] ; then
291    sequential=1; suff_exe='_seq'
292else
293    sequential=0; suff_exe='_para_mem'
294fi
295
296#Chemin pour placer le modele
297if [ "$MODEL" = "" ] ; then MODEL=./LMDZ$version$svn$optim ; fi
298
299
300arch=local
301
302
303if [ $compiler = g95 ] ; then echo g95 is not supported anymore ; exit ; fi
304
305################################################################
306# Specificite des machines
307################################################################
308
309hostname=`hostname`
310if [ "$pclinux" = 1 ] ; then o_ins_make="-t g95" ; else o_ins_make="" ; fi
311
312case ${hostname:0:5} in
313
314    jean-)   compiler="mpiifort" ;
315             par_comp="mpiifort" ;
316             o_ins_make="-t jeanzay" ;
317             make=gmake ;
318             module purge
319             module load intel-compilers/19.0.4 ;
320             #module load intel-mpi/19.0.4 ;
321             #module load intel-mkl/19.0.4 ;
322             module load hdf5/1.10.5-mpi ;
323             module load netcdf/4.7.2-mpi ;
324             module load netcdf-fortran/4.5.2-mpi ;
325             module load subversion/1.9.7 ;
326             module load cmake
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`" = "Ubuntu" ] ; 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_archives/$trusting/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###########################################################################
601echo Installing Netcdf
602###########################################################################
603
604if [ $netcdf = 0 ] ; then
605    ncdfdir=/usr
606
607else
608    cd $MODEL
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=netcdf4_hdf5_seq
620           opt_=$opt1 ;;
621        y) script_install_netcdf=install_netcdf4_hdf5.bash
622           ncdfdir=netcdf4_hdf5
623           opt_="$opt2 -MPI $root_mpi" ;;
624        *) echo with_xios=$with_xios, should be n or y ; exit 1
625    esac
626    if [ $netcdf = 1 ] ; then
627       ncdfdir=$MODEL/$ncdfdir
628    else
629       mkdir -p $netcdf ; ncdfdir=$netcdf/$ncdfdir
630    fi
631         
632    echo Repertoire netcdf $ncdfdir
633    if [ ! -d $ncdfdir ] ; then
634        netcdflog=`pwd`/netcdf.log
635        echo '----------------------------------------------------------'
636        echo Compiling the Netcdf library
637        echo '----------------------------------------------------------'
638        echo log file : $netcdflog
639        myget script_install/$script_install_netcdf >> $netcdflog 2>&1
640        chmod u=rwx $script_install_netcdf
641        ./$script_install_netcdf -prefix $ncdfdir $opt_ >> $netcdflog 2>&1
642    fi
643
644    #----------------------------------------------------------------------------
645    # LF rajout d'une verrue, pour une raison non encore expliquee,
646    # la librairie est parfois rangée dans lib64 et non dans lib
647    # par certains compilateurs
648    if [ ! -e lib -a -d lib64 ] ; then ln -s lib64 lib; fi
649    #----------------------------------------------------------------------------
650
651    echo install_lmdz.sh netcdf_OK `date`
652
653fi
654
655cat >test_netcdf90.f90 <<EOF
656use netcdf
657print *, "NetCDF library version: ", nf90_inq_libvers()
658end
659EOF
660
661$compiler -I$ncdfdir/include test_netcdf90.f90 -L$ncdfdir/lib -lnetcdff \
662          -lnetcdf -Wl,-rpath=$ncdfdir/lib && ./a.out
663   
664if (($? == 0))
665then
666    rm test_netcdf90.f90 a.out
667else
668    echo "Failed test program using NetCDF-Fortran."
669    echo "You can:"
670    echo "- check that you have NetCDF-Fortran installed in your system"
671    echo "- or specify an installation directory with option -netcdf of" \
672         "install_lmdz.sh"
673    echo "- or download and compile NetCDF-Fortran with option -netcdf 1 of" \
674         "install_lmdz.sh"
675    exit 1
676fi
677
678#=========================================================================
679if [[ ! -f $MODEL/modipsl/lib/libioipsl.a ]]
680then
681    if [ $ioipsl = 1 ] ; then
682        #=====================================================================
683        echo OK ioipsl=$ioipsl
684        echo '##########################################################'
685        echo 'Installing MODIPSL, the installation package manager for the '
686        echo 'IPSL models and tools'
687        echo '##########################################################'
688        echo `date`
689
690        cd $MODEL/modipsl
691        \rm -rf lib/*
692        cd util
693        cp AA_make.gdef AA_make.orig
694        F_C="$compiler -c "
695        if [ "$compiler" = "$gfortran" -o "$compiler" = "mpif90" ]
696        then
697            F_C="$compiler -c -cpp "
698        fi
699        if [ "$compiler" = "pgf90" ] ; then F_C="$compiler -c -Mpreprocess" ; fi
700        sed -e 's/^\#.*.g95.*.\#.*.$/\#/' AA_make.gdef > tmp
701        sed -e "s:F_L = g95:F_L = $compiler:" \
702            -e "s:F_C = g95 -c -cpp:F_C = $F_C": \
703            -e 's/g95.*.w_w.*.(F_D)/g95      w_w = '"$OPTIMGCM"'/' \
704            -e 's:g95.*.NCDF_INC.*.$:g95      NCDF_INC= '"$ncdfdir"'/include:' \
705            -e 's:g95.*.NCDF_LIB.*.$:g95      NCDF_LIB= -L'"$ncdfdir"'/lib -lnetcdff -lnetcdf:' \
706            -e 's:g95      L_O =:g95      L_O = -Wl,-rpath='"$ncdfdir"'/lib:' \
707            -e "s:-fmod=:-$fmod:" -e 's/-fno-second-underscore//' \
708            -e 's:#-Q- g95      M_K = gmake:#-Q- g95      M_K = make:' \
709            tmp >| AA_make.gdef
710
711        if [ $pcmac == 1 ]
712        then
713            cp AA_make.gdef tmp
714            sed -e 's/rpath=/rpath,/g' tmp > AA_make.gdef
715        fi
716
717
718        # We use lines for g95 even for the other compilers to run ins_make
719        if [ "$use_shell" = "ksh" ] ; then
720            ./ins_make $o_ins_make
721        else # bash
722            sed -e s:/bin/ksh:/bin/bash:g ins_make > ins_make.bash
723            if [ "`grep jeanzay AA_make.gdef`" = "" ] ; then
724                # Bidouille pour compiler sur ada des vieux modipsl.tar
725                echo 'Warning jean-zay not in AA_make.gdef'
726                echo 'Think about updating'
727                exit 1
728            fi
729
730            chmod u=rwx ins_make.bash
731            ./ins_make.bash $o_ins_make
732        fi # of if [ "$use_shell" = "ksh" ]
733
734        echo install_lmdz.sh MODIPSL_OK `date`
735
736        cd $MODEL/modipsl/modeles/IOIPSL/src
737        ioipsllog=`pwd`/ioipsl.log
738        echo '##########################################################'
739        echo 'Compiling IOIPSL, the interface library with Netcdf'
740        echo '##########################################################'
741        echo `date`
742        echo log file : $ioipsllog
743
744        if [ "$use_shell" = "bash" ] ; then
745            cp Makefile Makefile.ksh
746            sed -e s:/bin/ksh:/bin/bash:g Makefile.ksh > Makefile
747        fi
748        ### if [ "$pclinux" = 1 ] ; then
749        # Build IOIPSL modules and library
750        $make clean
751        $make > $ioipsllog 2>&1
752        if [ "$compiler" = "$gfortran" -o "$compiler" = "mpif90" ] ; then
753            # copy module files to lib
754            cp -f *.mod ../../../lib
755        fi
756        # Build IOIPSL tools (ie: "rebuild", if present)
757          # For IOIPSLv_2_2_2, "rebuild" files are in IOIPSL/tools
758        rebuild_dir=""
759        if [ -f $MODEL/modipsl/modeles/IOIPSL/tools/rebuild ] ; then 
760            rebuild_dir=$MODEL/modipsl/modeles/IOIPSL/tools
761        elif [ -d $MODEL/modipsl/modeles/IOIPSL/rebuild ] ; then
762              rebuild_dir=$MODEL/modipsl/modeles/IOIPSL/rebuild
763        fi
764        if [ $rebuild_dir != "" ] ; then
765            cd $rebuild_dir     
766            # adapt Makefile & rebuild script if in bash
767            if [ "$use_shell" = "bash" ] ; then
768                cp Makefile Makefile.ksh
769                sed -e s:/bin/ksh:/bin/bash:g Makefile.ksh > Makefile
770                cp rebuild rebuild.ksh
771                sed -e 's:/bin/ksh:/bin/bash:g' \
772                    -e 's:print -u2:echo:g' \
773                    -e 's:print:echo:g' rebuild.ksh > rebuild
774            fi
775            $make clean
776            $make > $ioipsllog 2>&1
777        fi
778        ### fi # of if [ "$pclinux" = 1 ] which is commented out
779
780    else # of if [ $ioipsl = 1 ]
781        if [ ${hostname:0:5} = jean- ] ; then
782            cd $MODEL/modipsl
783            cd util
784            if [ "`grep jeanzay AA_make.gdef`" = "" ] ; then
785                echo 'Warning jean-zay not in AA_make.gdef'
786                echo 'Think about updating'
787                exit 1
788            fi
789            ./ins_make $o_ins_make
790            # Compile IOIPSL on jean-zay
791            cd $MODEL/modipsl/modeles/IOIPSL/src
792            gmake > ioipsl.log
793            # For IOIPSLv_2_2_2, "rebuild" files are in IOIPSL/tools, so "gmake" in IOIPSL/tools is enough
794            # For IOIPSLv_2_2_5, "rebuild" files are in a separate IOIPSL/rebuild folder , while "tools" only contains "FCM"
795            if [ -f $MODEL/modipsl/modeles/IOIPSL/tools/Makefile ] ; then
796              cd $MODEL/modipsl/modeles/IOIPSL/tools
797              gmake > ioipsl.log
798            fi
799            if [ -d $MODEL/modipsl/modeles/IOIPSL/rebuild ] ; then
800              cd $MODEL/modipsl/modeles/IOIPSL/rebuild
801              gmake > ioipsl.log
802            fi
803
804        fi
805        echo install_lmdz.sh ioipsl_OK `date`
806    fi # of if [ $ioipsl = 1 ]
807fi # of if [[ ! -f $MODEL/modipsl/lib/libioipsl.a ]]
808
809#=========================================================================
810if [ "$with_xios" = "y" ] ; then
811    echo '##########################################################'
812    echo 'Compiling XIOS'
813    echo '##########################################################'
814    cd $MODEL/modipsl/modeles
815    xioslog=`pwd`/xios.log
816    #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/install_xios.bash
817    myget script_install/install_xios.bash
818    chmod u=rwx install_xios.bash
819# following will be recalculated later on once LMDZ is updated
820#    mysvn=`svnversion LMDZ | egrep -o "[0-9]+" 2>/dev/null`
821    mysvn=`grep 'Revision: [0-9]' $MODEL/Read*.md | awk ' { print $2 } ' 2>/dev/null`
822    if [ "$svn" != "" ] ; then mysvn=$svn ; fi 
823    echo mysvn $mysvn
824
825    if [ ${hostname:0:5} = jean- ] ; then
826        if [ $mysvn -ge 4619 ] ; then 
827          svn co http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS2/branches/xios-2.6 \
828            XIOS
829        else
830          svn co http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS2/branches/xios-2.5 \
831            XIOS
832        fi
833        cd XIOS/arch
834        svn update
835        cd ..
836        echo "Compiling XIOS, start" `date` \
837             "(it takes about 20 min on Jean-Zay)"
838        echo "log file: $xioslog"
839        ./make_xios --prod --arch $arch --job 4 > xios.log 2>&1
840    else
841        ./install_xios.bash -prefix $MODEL/modipsl/modeles \
842                            -netcdf ${ncdfdir} -hdf5 ${ncdfdir} \
843                            -MPI $root_mpi -arch $arch > xios.log 2>&1
844    fi # of case Jean-Zay
845    if [ -f XIOS/lib/libxios.a ] ; then
846        echo "XIOS library successfully generated"
847        echo install_lmdz.sh XIOS_OK `date`
848    fi
849fi
850
851#============================================================================
852veget_version=false
853if [ "$veget" != 'NONE' ] ; then
854    cd $MODEL/modipsl/modeles/ORCHIDEE
855    set +e ; svn upgrade ; set -e
856    if [ "$veget" = "CMIP6" ] ; then
857        veget_version=orchidee2.0
858        orchidee_rev=6592
859    else # specific orchidee revision newer than CMIP6, on 2_1 or 2_2 branches
860        veget_version=orchidee2.1
861        orchidee_rev=$veget
862        if [ $veget -lt 4465 ] ; then
863            echo 'Stopping, ORCHIDEE version too old, script needs work on ' \
864                 'the CPP flags to pass to makelmdz'
865            exit 1
866        fi
867        set +e
868        # which branch is my version on?
869        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}'`
870        # switch to that branch
871        echo IF YOU INSTALL ORCHIDEE THE VERY FIRST TIME, ASK for PASSWORD at \
872             orchidee-help@listes.ipsl.fr
873        svn switch -r $veget --accept theirs-full \
874            svn://forge.ipsl.jussieu.fr/orchidee/$orcbranch
875        svn log -r $veget | grep  $veget
876        if [  $? -gt 0 ] ; then
877            echo 'Cannot update ORCHIDEE as not on the right branch for ' \
878                 'ORCHIDEE'
879            exit
880        fi
881        set -e
882        set +e ; svn update -r $veget ; set -e
883    fi
884    # Correctif suite debug Jean-Zay
885    sed -i -e 's/9010  FORMAT(A52,F17.14)/9010  FORMAT(A52,F20.14)/' \
886        src_stomate/stomate.f90
887    opt_orc="-prod" ; if [ "$optim" = "-debug" ] ; then opt_orc="-debug" ; fi
888
889    orchideelog=`pwd`/orchidee.log
890    echo '########################################################'
891    echo 'Compiling ORCHIDEE, the continental surface model '
892    echo '########################################################'
893    echo Start of the first compilation of orchidee, in sequential mode: `date`
894    echo log file : $orchideelog
895
896    export ORCHPATH=`pwd`
897    xios_orchid="-noxios"
898    if [ "$with_xios" = "y" ] ; then
899        xios_orchid="-xios"
900    fi
901    if [ -d tools ] ; then
902        ###################################################################
903        # Pour les experts qui voudraient changer de version d'orchidee.
904        # Attention : necessite d'avoir le password pour orchidee
905
906        # Correctif suite debug Jean-Zay
907        if [ -f src_global/time.f90 ] ; then
908            sed -i -e 's/CALL tlen2itau/\!CALL tlen2itau/' src_global/time.f90
909        fi
910        ###################################################################
911        if [ "$veget_version" == "false" ] ; then
912            veget_version=orchidee2.0
913        fi
914        cd arch
915        sed -e s:"%COMPILER        .*.$":"%COMPILER            $compiler":1 \
916            -e s:"%LINK            .*.$":"%LINK                $compiler":1 \
917            -e s:"%FPP_FLAGS       .*.$":"%FPP_FLAGS           $fpp_flags":1 \
918            -e s:"%PROD_FFLAGS     .*.$":"%PROD_FFLAGS         $OPTIM":1 \
919            -e s:"%DEV_FFLAGS      .*.$":"%DEV_FFLAGS          $OPTDEV":1 \
920            -e s:"%DEBUG_FFLAGS    .*.$":"%DEBUG_FFLAGS        $OPTDEB":1 \
921            -e s:"%BASE_FFLAGS     .*.$":"%BASE_FFLAGS         $OPTPREC":1 \
922            -e s:"%BASE_LD         .*.$":"%BASE_LD             $BASE_LD":1 \
923            -e s:"%ARFLAGS         .*.$":"%ARFLAGS             $ARFLAGS":1 \
924            arch-gfortran.fcm > arch-local.fcm
925        echo "NETCDF_LIBDIR=\"-L${ncdfdir}/lib -lnetcdff -lnetcdf\"" \
926             > arch-local.path
927        echo "NETCDF_INCDIR=${ncdfdir}/include" >> arch-local.path
928        echo "IOIPSL_INCDIR=$ORCHPATH/../../lib" >> arch-local.path
929        echo "IOIPSL_LIBDIR=$ORCHPATH/../../lib" >> arch-local.path
930        echo 'XIOS_INCDIR=${ORCHDIR}/../XIOS/inc' >> arch-local.path
931        echo 'XIOS_LIBDIR="${ORCHDIR}/../XIOS/lib -lxios"' >> arch-local.path
932        cd ../
933
934        echo ./makeorchidee_fcm -j $xios_orchid $opt_orc -parallel none \
935             -arch $arch
936        ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc -parallel none \
937                           -arch $arch > $orchideelog 2>&1
938        pwd
939    else # of "if [ -d tools ]"
940        if [ -d src_parallel ] ; then
941            liste_src="parallel parameters global stomate sechiba driver"
942            if [ "$veget_version" == "false" ] ; then
943                veget_version=orchidee2.0
944            fi
945        fi
946        for d in $liste_src ; do
947            src_d=src_$d
948            echo src_d $src_d
949            echo ls ; ls
950            if [ ! -d $src_d ] ; then
951                echo Problem orchidee : no $src_d ; exit
952            fi
953            cd $src_d ; \rm -f *.mod make ; $make clean
954            $make > $orchideelog 2>&1
955            if [ "$compiler" = "$gfortran" -o "$compiler" = "mpif90" ] ; then
956                cp -f *.mod ../../../lib
957            fi
958            cd ..
959        done
960    fi # of "if [ -d tools ]"
961    echo install_lmdz.sh orchidee_compil_seq_OK `date`
962fi # of if [ "$veget" != 'NONE' ]
963
964
965#============================================================================
966# Ehouarn: the directory name LMDZ* depends on version/tar file...
967if [ -d $MODEL/modipsl/modeles/LMD* ] ; then
968    echo '###############################################################'
969    echo 'Preparing LMDZ compilation : arch file, svn switch if needed...'
970    echo '###############################################################'
971    cd $MODEL/modipsl/modeles/LMD*
972    LMDZPATH=`pwd`
973else
974    echo "ERROR: No LMD* directory !!!"
975    exit
976fi
977
978###########################################################
979# For those who want to use fcm to compile via :
980#  makelmdz_fcm -arch local .....
981############################################################
982
983
984
985cd $MODEL/modipsl/modeles/LMDZ*
986lmdzlog=`pwd`/lmdz.log
987
988##################################################################
989# Possibly update LMDZ if a specific svn release is requested
990##################################################################
991
992set +e ; svn upgrade ; set -e
993
994if [ "$svn" = "last" ] ; then svnopt="" ; else svnopt="-r $svn" ; fi
995if [ "$svn" != "" ] ; then
996    set +e ; svn info | grep -q 'https:'
997    if [ $? = 0 ] ; then
998        svn switch --relocate https://svn.lmd.jussieu.fr/LMDZ \
999            http://svn.lmd.jussieu.fr/LMDZ
1000    fi
1001    svn update $svnopt
1002    set -e
1003fi
1004
1005#---------------------------------------------------------------------
1006# Retrieve the final svn release number, and adjust compilation
1007# options accordingly
1008# If svn not available, will use the svn writen in $MODEL/Readm*md
1009# For old version it assumes that it is before 4185 (the version
1010# for which the test was introduced
1011#---------------------------------------------------------------------
1012
1013set +e ; mysvn=`svnversion . | egrep -o "[0-9]+" 2>/dev/null` ; set -e
1014if [ "$mysvn" = "" ] ; then mysvn=`grep 'Revision: [0-9]' $MODEL/Read*.md | awk ' { print $2 } ' 2>/dev/null` ; fi
1015if [ "$mysvn" = "" ] ; then mysvn=4190 ; fi
1016
1017if [[ "$pclinux" = "1" && ! -f arch/arch-local.path ]] ; then
1018
1019    # create local 'arch' files (if on Linux PC):
1020    cd arch
1021    # arch-local.path file
1022    # test for version as arch.pth file changed format with rev 4426
1023    if [ "$mysvn" -gt 4425 ] ; then
1024      echo "NETCDF_LIBDIR=\"-L${ncdfdir}/lib \"" > arch-local.path
1025      echo "NETCDF_LIB=\"-lnetcdff -lnetcdf\"" >> arch-local.path
1026      echo "NETCDF_INCDIR=-I${ncdfdir}/include" >> arch-local.path
1027      echo 'NETCDF95_INCDIR=-I$LMDGCM/../../include' >> arch-local.path
1028      echo 'NETCDF95_LIBDIR=-L$LMDGCM/../../lib' >> arch-local.path
1029      echo 'NETCDF95_LIB=-lnetcdf95' >> arch-local.path
1030      echo 'IOIPSL_INCDIR=-I$LMDGCM/../../lib' >> arch-local.path
1031      echo 'IOIPSL_LIBDIR=-L$LMDGCM/../../lib' >> arch-local.path
1032      echo 'IOIPSL_LIB=-lioipsl' >> arch-local.path
1033      echo 'XIOS_INCDIR=-I$LMDGCM/../XIOS/inc' >> arch-local.path
1034      echo 'XIOS_LIBDIR=-L$LMDGCM/../XIOS/lib' >> arch-local.path
1035      echo "XIOS_LIB=\"-lxios -lstdc++\"" >> arch-local.path
1036      echo 'ORCH_INCDIR=-I$LMDGCM/../../lib' >> arch-local.path
1037      echo 'ORCH_LIBDIR=-L$LMDGCM/../../lib' >> arch-local.path
1038    else
1039      echo "NETCDF_LIBDIR=\"-L${ncdfdir}/lib -lnetcdff -lnetcdf\"" \
1040         > arch-local.path
1041      echo "NETCDF_INCDIR=-I${ncdfdir}/include" >> arch-local.path
1042      echo 'NETCDF95_INCDIR=$LMDGCM/../../include' >> arch-local.path
1043      echo 'NETCDF95_LIBDIR=$LMDGCM/../../lib' >> arch-local.path
1044      echo 'IOIPSL_INCDIR=$LMDGCM/../../lib' >> arch-local.path
1045      echo 'IOIPSL_LIBDIR=$LMDGCM/../../lib' >> arch-local.path
1046      echo 'XIOS_INCDIR=$LMDGCM/../XIOS/inc' >> arch-local.path
1047      echo 'XIOS_LIBDIR=$LMDGCM/../XIOS/lib' >> arch-local.path
1048      echo 'ORCH_INCDIR=$LMDGCM/../../lib' >> arch-local.path
1049      echo 'ORCH_LIBDIR=$LMDGCM/../../lib' >> arch-local.path
1050    fi 
1051
1052    if [ $pcmac == 1 ] ; then
1053        BASE_LD="$BASE_LD -Wl,-rpath,${ncdfdir}/lib"
1054    else
1055        BASE_LD="$BASE_LD -Wl,-rpath=${ncdfdir}/lib"
1056    fi
1057    # Arch-local.fcm file (adapted from arch-linux-32bit.fcm)
1058
1059    if [ $real = r8 ] ; then FPP_DEF=NC_DOUBLE ; else FPP_DEF="" ; fi
1060    sed -e s:"%COMPILER        .*.$":"%COMPILER            $compiler":1 \
1061        -e s:"%LINK            .*.$":"%LINK                $compiler":1 \
1062        -e s:"%PROD_FFLAGS     .*.$":"%PROD_FFLAGS         $OPTIM":1 \
1063        -e s:"%DEV_FFLAGS      .*.$":"%DEV_FFLAGS          $OPTDEV":1 \
1064        -e s:"%DEBUG_FFLAGS    .*.$":"%DEBUG_FFLAGS        $OPTDEB":1 \
1065        -e s:"%BASE_FFLAGS     .*.$":"%BASE_FFLAGS         $OPTPREC":1 \
1066        -e s:"%FPP_DEF         .*.$":"%FPP_DEF             $FPP_DEF":1 \
1067        -e s:"%BASE_LD         .*.$":"%BASE_LD             $BASE_LD":1 \
1068        -e s:"%ARFLAGS         .*.$":"%ARFLAGS             $ARFLAGS":1 \
1069        arch-linux-32bit.fcm > arch-local.fcm
1070
1071    cd ..
1072    ### Adapt "bld.cfg" (add the shell):
1073    #whereisthatshell=$(which ${use_shell})
1074    #echo "bld::tool::SHELL   $whereisthatshell" >> bld.cfg
1075
1076fi # of if [ "$pclinux" = 1 ]
1077#---------------------------------------------------------------------
1078# Option de compilation du rayonnement : depend de $mysvn ><= r4185
1079#---------------------------------------------------------------------
1080opt_rad=""
1081
1082case $rad in
1083    oldrad) iflag_rrtm=0 ; NSW=2 ; opt_rad="" ;;
1084    rrtm)   iflag_rrtm=1 ; NSW=6
1085            if [ $mysvn -le 4185 ] ; then
1086                opt_rad="-rrtm true"
1087            else
1088                opt_rad="-rad rrtm"
1089            fi ;;
1090    ecrad)  iflag_rrtm=2 ; NSW=6 ; opt_rad="-rad ecrad" ;;
1091    *) echo Only oldrad rrtm ecrad for rad option ; exit
1092esac
1093
1094if [ $mysvn -le 4185 -a $rad = "ecrad" ] ; then
1095    echo "ecrad only available for LMDZ rev starting with 4186 " ; exit
1096fi
1097
1098##################################################################
1099
1100
1101if [[ ! -f libf/misc/netcdf95.F90 &&  ! -d $MODEL/NetCDF95-0.3 ]]
1102then
1103    cd $MODEL
1104    myget src_archives/netcdf/NetCDF95-0.3.tar.gz
1105    tar -xf NetCDF95-0.3.tar.gz
1106    rm NetCDF95-0.3.tar.gz
1107    cd NetCDF95-0.3
1108    mkdir build
1109    cd build
1110    cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$ncdfdir \
1111          -DCMAKE_INSTALL_PREFIX=$MODEL/modipsl
1112    make install
1113    cd $MODEL/modipsl/modeles/LMDZ*
1114fi
1115
1116echo '##################################################################'
1117echo "Preparing script compile.sh for LMDZ compilation"
1118echo "It will only be run automatically if bench=1/tuto"
1119echo Here bench=$bench
1120echo '##################################################################'
1121
1122if [ "$env_file" != "" ] ; then
1123    mv arch/arch-${arch}.env arch/arch-${arch}.orig
1124    \cp -f $env_file arch/arch-${arch}.env
1125fi
1126
1127if [ $compile_with_fcm = 1 ] ; then
1128    makelmdz="makelmdz_fcm $optim -arch $arch -j 8 "
1129else
1130    makelmdz="makelmdz $optim -arch $arch"
1131fi
1132
1133# sequential compilation
1134if [ "$sequential" = 1 ] ; then
1135    echo Sequential compilation command, saved in compile.sh:
1136    echo "./$makelmdz $optim $OPT_MAKELMDZ $optim $opt_rad $opt_cosp " \
1137         "-d ${grid_resolution} -v $veget_version gcm "
1138    echo "./$makelmdz $optim $OPT_MAKELMDZ $optim $opt_rad $opt_cosp " \
1139         "-d ${grid_resolution} -v $veget_version gcm " > compile.sh
1140    chmod +x ./compile.sh
1141    if [ $bench = 1 ] ; then
1142        echo install_lmdz.sh start_lmdz_seq_compilation `date`
1143        echo log file: $lmdzlog
1144        ./compile.sh > $lmdzlog 2>&1
1145        echo install_lmdz.sh end_lmdz_seq_compilation `date`
1146    fi
1147fi # fin sequential
1148
1149# compiling in parallel mode
1150if [ $parallel != "none" ] ; then
1151    echo '##########################################################'
1152    echo ' Parallel compile '
1153    echo '##########################################################'
1154    echo "(after saving the sequential libs and binaries)"
1155    cd $MODEL/modipsl
1156    tar cf sequential.tar bin/ lib/
1157    #
1158    # Orchidee
1159    #
1160    cd $ORCHPATH
1161    if [ -d src_parallel -a $veget != 'NONE' ] ; then
1162        cd arch
1163        sed  \
1164            -e s:"%COMPILER.*.$":"%COMPILER            $par_comp":1 \
1165            -e s:"%LINK.*.$":"%LINK                $par_comp":1 \
1166            -e s:"%MPI_FFLAG.*.$":"%MPI_FFLAGS          $MPI_FLAGS":1 \
1167            -e s:"%OMP_FFLAG.*.$":"%OMP_FFLAGS          $OMP_FLAGS":1 \
1168            -e s:"%MPI_LD.*.$":"%MPI_LD              $MPI_LD":1 \
1169            -e s:"%OMP_LD.*.$":"%OMP_LD              $OMP_LD":1 \
1170            arch-local.fcm > tmp.fcm
1171
1172        mv tmp.fcm arch-local.fcm
1173        cd ../
1174        echo Compiling ORCHIDEE in parallel mode `date`
1175        echo logfile $orchideelog
1176        echo "NOTE : to recompile it when necessary, use ./compile_orc.sh " \
1177             "in modipsl/modeles/ORCHIDEE"
1178        echo ./makeorchidee_fcm -j 8 -clean $xios_orchid $opt_orc \
1179             -parallel $parallel -arch $arch > compile_orc.sh
1180        echo ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc \
1181             -parallel $parallel -arch $arch >> compile_orc.sh
1182        echo echo Now you must also recompile LMDZ, by running ./compile.sh \
1183             in modeles/LMDZ >> compile_orc.sh
1184        chmod u+x compile_orc.sh
1185        ./makeorchidee_fcm -j 8 -clean $xios_orchid $opt_orc \
1186                           -parallel $parallel -arch $arch > $orchideelog 2>&1
1187        ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc -parallel $parallel \
1188                           -arch $arch >> $orchideelog 2>&1
1189        echo End of ORCHIDEE compilation in parallel mode `date`
1190    elif [ $veget != 'NONE' ] ; then
1191        echo '##########################################################'
1192        echo ' Orchidee version too old                                 '
1193        echo ' Please update to new version                             '
1194        echo '##########################################################'
1195        exit
1196    fi # of [ -d src_parallel -a $veget != 'NONE' ]
1197
1198    # LMDZ
1199    cd $LMDZPATH
1200    if [ $arch = local ] ; then
1201        cd arch
1202        sed -e s:"%COMPILER.*.$":"%COMPILER            $par_comp":1 \
1203            -e s:"%LINK.*.$":"%LINK                $par_comp":1 \
1204            -e s:"%MPI_FFLAG.*.$":"%MPI_FFLAGS          $MPI_FLAGS":1 \
1205            -e s:"%OMP_FFLAG.*.$":"%OMP_FFLAGS          $OMP_FLAGS":1 \
1206            -e s:"%ARFLAGS.*.$":"%ARFLAGS          $ARFLAGS":1 \
1207            -e s@"%BASE_LD.*.$"@"%BASE_LD             -Wl,-rpath=${root_mpi}/lib:${ncdfdir}/lib"@1 \
1208            -e s:"%MPI_LD.*.$":"%MPI_LD              $MPI_LD":1 \
1209            -e s:"%OMP_LD.*.$":"%OMP_LD              $OMP_LD":1 \
1210            arch-local.fcm > tmp.fcm
1211        mv tmp.fcm arch-local.fcm
1212        cd ../
1213    fi
1214    rm -f compile.sh
1215    echo resol=${grid_resolution} >> compile.sh
1216    if [ ${hostname:0:5} = jean- -a "$cosp" = "v2" ] ; then
1217
1218        echo LMDZ compilation command in parallel mode, saved in compile.sh, \
1219             is :
1220        echo "(ATTENTION le probleme de cospv2 sur jean-zay en mode prod " \
1221             "n est pas corrige ! )"
1222        # ATTENTION le probleme de cospv2 sur jean-zay en mode prod n
1223        # est pas corrige
1224        echo ./$makelmdz -dev $optim $OPT_MAKELMDZ $opt_rad $opt_cosp \
1225             $opt_makelmdz_xios -d \$resol -v $veget_version -mem \
1226             -parallel $parallel gcm >> compile.sh
1227        echo ./$makelmdz -dev $optim $OPT_MAKELMDZ $opt_rad $opt_cosp \
1228             $opt_makelmdz_xios -d \$resol -v $veget_version -mem \
1229             -parallel $parallel gcm
1230    else
1231        echo ./$makelmdz $optim $OPT_MAKELMDZ $opt_rad $opt_cosp \
1232             $opt_makelmdz_xios -d \$resol -v $veget_version -mem \
1233             -parallel $parallel gcm >> compile.sh
1234        echo ./$makelmdz $optim $OPT_MAKELMDZ $opt_rad $opt_cosp \
1235             $opt_makelmdz_xios -d \$resol -v $veget_version -mem \
1236             -parallel $parallel gcm
1237    fi
1238    chmod +x ./compile.sh
1239
1240    if [ $bench = 1 ] ; then
1241        echo Compiling LMDZ in parallel mode `date`,  LMDZ log file: $lmdzlog
1242        ./compile.sh > $lmdzlog 2>&1
1243    fi
1244
1245fi # of if [ $parallel != "none" ]
1246
1247
1248##################################################################
1249# Verification du succes de la compilation
1250##################################################################
1251
1252# Recherche de l'executable dont le nom a change au fil du temps ...
1253# suffix contains radiative option starting with revision 4186
1254if [ $mysvn -ge 4186 ] ; then suff_exe=_${rad}${suff_exe} ; fi
1255gcm=""
1256
1257for exe in gcm.e bin/gcm_${grid_resolution}_phylmd${suff_exe}${suff_orc}.e
1258do
1259    if [ -f $exe ] ; then gcm=$exe ; fi
1260done
1261
1262if [ "$gcm" = "" ] ; then
1263    if [ $bench = 1 ] ; then
1264        echo 'Compilation failed !! Cannot run the benchmark;'
1265        exit
1266    else
1267        echo 'Compilation not done (only done when bench=1)'
1268    fi
1269else
1270    echo '##########################################################'
1271    echo 'Compilation successfull !! ' `date`
1272    echo '##########################################################'
1273    echo The executable is $gcm
1274fi
1275
1276##################################################################
1277# Below, we run a benchmark if bench=1 or tuto
1278##################################################################
1279
1280if [ $bench = tuto ] ; then
1281    myget Training/tutorial.tar ; tar xf tutorial.tar ; cd TUTORIAL
1282    ./init.sh
1283
1284elif [[ $bench = 1 && ! -d BENCH${grid_resolution} ]] ; then
1285    # TOUTE CETTE SECTION DEVRAIT DISPARAITRE POUR UNE COMMANDE
1286    # OU DES BENCHS PAR MOTS CLES COMME tuto
1287
1288    echo '##########################################################'
1289    echo ' Running a test run '
1290    echo '##########################################################'
1291
1292    \rm -rf BENCH${grid_resolution}
1293    bench=bench_lmdz_${grid_resolution}
1294    echo install_lmdz.sh before bench download  `date`
1295    #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/$bench.tar.gz
1296    myget 3DBenchs/$bench.tar.gz
1297    echo install_lmdz.sh after bench download  `date`
1298    tar xf $bench.tar.gz
1299
1300    if [ "$cosp" = "v1" -o "$cosp" = "v2" ] ; then
1301        cd BENCH${grid_resolution}
1302        # copier les fichiers namelist input et output our COSP
1303        cp ../DefLists/cosp*_input_nl.txt .
1304        cp ../DefLists/cosp*_output_nl.txt .
1305        # Activer la cles ok_cosp pour tourner avec COSP
1306        sed -e 's@ok_cosp=n@ok_cosp=y@' config.def > tmp
1307        \mv -f tmp config.def
1308        cd ..
1309    fi
1310
1311    if [ -n "$physiq" ]; then
1312        cd BENCH${grid_resolution}
1313        if [ -f physiq.def_${physiq} ]; then
1314            cp physiq.def_${physiq} physiq.def
1315            echo using physiq.def_${physiq}
1316        else
1317            echo using standard physiq.def
1318        fi
1319        cd ..
1320    else
1321        echo using standard physiq.def
1322    fi
1323
1324    if [ "$with_xios" = "y" ] ; then
1325        cd BENCH${grid_resolution}
1326        cp ../DefLists/iodef.xml .
1327        cp ../DefLists/context_lmdz.xml .
1328        cp ../DefLists/field_def_lmdz.xml .
1329        # A raffiner par la suite
1330        echo A FAIRE : Copier les *xml en fonction de l option cosp
1331        cp ../DefLists/field_def_cosp*.xml .
1332        cp ../DefLists/file_def_hist*xml .
1333        # adapt iodef.xml to use attached mode
1334        sed -e 's@"using_server" type="bool">true@"using_server" type="bool">false@' \
1335            iodef.xml > tmp
1336        \mv -f tmp iodef.xml
1337
1338        # and convert all the enabled="_AUTO_" (for libIGCM) to enabled=.FALSE.
1339        # except for histday
1340        for histfile in file_def_hist*xml
1341        do
1342            if [ "$histfile" = "file_def_histday_lmdz.xml" ] ; then
1343                sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".TRUE."@' \
1344                    $histfile > tmp
1345                \mv -f tmp $histfile
1346                sed -e 's@output_level="_AUTO_"@output_level="5"@' $histfile \
1347                    > tmp
1348                \mv -f tmp $histfile
1349                sed -e 's@compression_level="2"@compression_level="0"@' \
1350                    $histfile > tmp
1351                \mv -f tmp $histfile
1352            else
1353                sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \
1354                    $histfile > tmp
1355                \mv -f tmp $histfile
1356            fi
1357        done
1358        # and add option "ok_all_xml=y" in config.def
1359        echo "### XIOS outputs" >> config.def
1360        echo 'ok_all_xml=.true.' >> config.def
1361
1362        #activer les sorties pour Cosp
1363        if [ "$cosp" = "v1" ] ; then
1364            histfile=file_def_histdayCOSP_lmdz.xml
1365            sed -e 's@enabled=".FALSE."@enabled=".TRUE."@' $histfile > tmp
1366            \mv -f tmp $histfile
1367            sed -e 's@output_level="_AUTO_"@output_level="5"@' $histfile > tmp
1368            \mv -f tmp $histfile
1369            sed -e 's@compression_level="2"@compression_level="0"@' \
1370                $histfile > tmp
1371            \mv -f tmp $histfile
1372        fi
1373        if [ "$cosp" = "v2" ] ; then
1374            histfile=file_def_histdayCOSPv2_lmdz.xml
1375            sed -e 's@compression_level="2"@compression_level="0"@' \
1376                $histfile > tmp
1377            \mv -f tmp $histfile
1378            contextfile=context_lmdz.xml
1379            sed -e 's@src="./file_def_histdayCOSP_lmdz.xml"@src="./file_def_histdayCOSPv2_lmdz.xml"@' \
1380                $contextfile > tmp
1381            \mv -f tmp $contextfile
1382            sed -e 's@src="./file_def_histmthCOSP_lmdz.xml"@src="./file_def_histmthCOSPv2_lmdz.xml"@' \
1383                $contextfile > tmp
1384            \mv -f tmp $contextfile
1385            sed -e 's@src="./file_def_histhfCOSP_lmdz.xml"@src="./file_def_histhfCOSPv2_lmdz.xml"@' \
1386                $contextfile > tmp
1387            \mv -f tmp $contextfile
1388            fieldfile=field_def_lmdz.xml
1389            sed -e 's@field_def_cosp1.xml@field_def_cospv2.xml@' $fieldfile \
1390                > tmp
1391            \mv -f tmp $fieldfile
1392        fi
1393
1394        cd ..
1395    fi
1396
1397    # Cas Bensh avec ecrad
1398    if [ "$rad" = "ecrad" ] ; then
1399        cd BENCH${grid_resolution}
1400        cp  ../DefLists/namelist_ecrad .
1401        cp -r ../libf/phylmd/ecrad/data .
1402        cd ..
1403    fi
1404
1405    # Adjusting bench physiq.def to radiative code chosen
1406    cd BENCH${grid_resolution}
1407    sed -e 's/iflag_rrtm=.*.$/iflag_rrtm='$iflag_rrtm'/' \
1408        -e 's/NSW=.*.$/NSW='$NSW'/' physiq.def > tmpdef
1409    \mv tmpdef physiq.def
1410    cd ..
1411
1412    cp $gcm BENCH${grid_resolution}/gcm.e
1413
1414    cd BENCH${grid_resolution}
1415    # On cree le fichier bench.sh au besoin
1416    # Dans le cas 48x36x39 le bench.sh existe deja en parallele
1417
1418    if [ "$grid_resolution" = "48x36x39" ] ; then
1419        echo On ne touche pas au bench.sh
1420        # But we have to adapt "run_local.sh" for $mpirun
1421        sed -e "s@mpirun@$mpirun@g" run_local.sh > tmp
1422        mv -f tmp run_local.sh
1423        chmod u=rwx run_local.sh
1424    elif [ "${parallel:0:3}" = "mpi" ] ; then
1425        # Lancement avec deux procs mpi et 2 openMP
1426        echo "export OMP_STACKSIZE=800M" > bench.sh
1427        if [ "${parallel:4:3}" = "omp" ] ; then
1428            echo "export OMP_NUM_THREADS=2" >> bench.sh
1429        fi
1430        if [ "$cosp" = "v1" -o "$cosp" = "v2" ] ; then
1431            if [ ${hostname:0:5} = jean- ] ; then
1432                   chmod +x ../arch.env
1433                ../arch.env       
1434                echo "ulimit -s 2000000" >> bench.sh
1435            else
1436                echo "ulimit -s 200000" >> bench.sh
1437            fi       
1438        else
1439            echo "ulimit -s unlimited" >> bench.sh
1440        fi
1441        if [ ${hostname:0:5} = jean- ] ; then
1442            . ../arch/arch-${arch}.env
1443            echo "srun -n 2 -A $idris_acct@cpu gcm.e > listing  2>&1" \
1444                 >> bench.sh
1445        else
1446            echo "$mpirun -np 2 gcm.e > listing  2>&1" >> bench.sh
1447        fi
1448        # Add rebuild, using reb.sh if it is there
1449        echo 'if [ -f reb.sh ] ; then' >> bench.sh
1450        echo '  ./reb.sh histday ; ./reb.sh histmth ; ./reb.sh histhf ; ' \
1451             './reb.sh histins ; ./reb.sh stomate_history ; ' \
1452             './reb.sh sechiba_history ; ./reb.sh sechiba_out_2 ' >> bench.sh
1453        echo 'fi' >> bench.sh
1454    else
1455        echo "./gcm.e > listing  2>&1" > bench.sh
1456    fi
1457    # Getting orchidee stuff
1458    if [ $veget == 'CMIP6' ] ; then
1459        #echo 'myget 3DBenchs/BENCHorch11.tar.gz'
1460        #myget 3DBenchs/BENCHorch11.tar.gz
1461        #tar xvzf BENCHorch11.tar.gz
1462        echo 'myget 3DBenchs/BENCHCMIP6.tar.gz'
1463        myget 3DBenchs/BENCHCMIP6.tar.gz
1464        tar xvzf BENCHCMIP6.tar.gz
1465        sed -e "s:VEGET=n:VEGET=y:" config.def > tmp
1466        mv -f tmp config.def
1467        if [ "$with_xios" = "y" ] ; then
1468            cp ../../ORCHIDEE/src_xml/context_orchidee.xml .
1469            echo '<context id="orchidee" src="./context_orchidee.xml"/>' \
1470                 > add.tmp
1471            cp ../../ORCHIDEE/src_xml/field_def_orchidee.xml .
1472            cp ../../ORCHIDEE/src_xml/file_def_orchidee.xml .
1473            cp ../../ORCHIDEE/src_xml/file_def_input_orchidee.xml .
1474            if [ -f ../../ORCHIDEE/src_xml/context_input_orchidee.xml ] ; then
1475                   cp ../../ORCHIDEE/src_xml/context_input_orchidee.xml .
1476                   echo '<context id="orchidee" ' \
1477                     'src="./context_input_orchidee.xml"/>' >> add.tmp
1478            fi
1479            sed -e '/id="LMDZ"/r add.tmp' iodef.xml > tmp
1480            mv tmp iodef.xml
1481            sed -e'{/sechiba1/ s/enabled="_AUTO_"/type="one_file" enabled=".TRUE."/}' \
1482                file_def_orchidee.xml > tmp
1483            \mv -f tmp file_def_orchidee.xml
1484            sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \
1485                file_def_orchidee.xml > tmp
1486            \mv -f tmp file_def_orchidee.xml
1487            sed -e 's@output_level="_AUTO_"@output_level="1"@' \
1488                file_def_orchidee.xml > tmp
1489            \mv -f tmp file_def_orchidee.xml
1490            sed -e 's@output_freq="_AUTO_"@output_freq="1d"@' \
1491                file_def_orchidee.xml > tmp
1492            \mv -f tmp file_def_orchidee.xml
1493            sed -e 's@compression_level="4"@compression_level="0"@' \
1494                file_def_orchidee.xml > tmp
1495            \mv -f tmp file_def_orchidee.xml
1496            sed -e 's@XIOS_ORCHIDEE_OK = n@XIOS_ORCHIDEE_OK = y@' \
1497                orchidee.def > tmp
1498            \mv -f tmp orchidee.def
1499        fi
1500    fi
1501
1502    if [[ -f ../arch.env ]]
1503    then
1504        source ../arch.env
1505    fi
1506
1507    echo EXECUTION DU BENCH
1508    set +e
1509    date ; ./bench.sh > out.bench 2>&1 ; date
1510    set -e
1511    tail listing
1512
1513
1514    echo '##########################################################'
1515    echo 'Simulation finished in' `pwd`
1516    echo 'You have compiled with:'
1517    cat ../compile.sh
1518    if [ $parallel = "none" ] ; then
1519        echo 'You may re-run it with : cd ' `pwd` ' ; gcm.e'
1520        echo 'or ./bench.sh'
1521    else
1522        echo 'You may re-run it with : '
1523        echo 'cd ' `pwd` '; ./bench.sh'
1524        #  echo 'ulimit -s unlimited'
1525        #  echo 'export OMP_NUM_THREADS=2'
1526        #  echo 'export OMP_STACKSIZE=800M'
1527        #  echo "$mpirun -np 2 gcm.e "
1528    fi
1529    echo '##########################################################'
1530
1531fi # bench
1532
1533
1534#################################################################
1535# Installation eventuelle du 1D
1536#################################################################
1537
1538if [ $SCM = 1 ] ; then
1539    cd $MODEL
1540    myget 1D/1D.tar.gz
1541    tar xf 1D.tar.gz
1542    cd 1D
1543    if [ $rad = oldrad ] ; then
1544        sed -i'' -e 's/^rad=.*$/rad=oldrad/' run.sh
1545        sed -i'' -e 's/^rad=.*$/rad=oldrad/' bin/compile
1546    fi
1547    echo Running 1D/run.sh, log in `pwd`/run1d.log
1548    ./run.sh > `pwd`/run1d.log 2>&1
1549fi
1550
1551
1552#################################################################
1553# sauvegarde des options veget pour utilisation eventuelle tutorial_prod
1554#################################################################
1555cd $MODEL/modipsl/modeles
1556#echo surface_env file created in $MODEL
1557echo 'veget='$veget > surface_env
1558#opt_veget="-v $veget_version"
1559#echo 'opt_veget="'$opt_veget\" >> surface_env
1560echo 'opt_veget="'-v $veget_version\" >> surface_env
1561echo 'orchidee_rev='$orchidee_rev >> surface_env
1562echo 'suforch='$suff_orc >> surface_env
Note: See TracBrowser for help on using the repository browser.