source: BOL/script_install/install_lmdz.sh @ 3973

Last change on this file since 3973 was 3973, checked in by Laurent Fairhead, 3 years ago

Modifications pour pouvoir tourner LMDZOR avec XIOS. Si on lance le script avec l'option -xios
LMDZ et ORCHIDEE seront compilés avec XIOS et le bench utilise XIOS pour les sorties.
Attention pour l'instant ne marche que sur jean-zay

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