source: BOL/script_install_amaury/install_lmdz.sh @ 4861

Last change on this file since 4861 was 4861, checked in by abarral, 2 months ago

remove ksh support
correct indentation
fix build typo

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