source: BOL/script_install_new

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