source: BOL/script_install/install_lmdz.sh @ 4043

Last change on this file since 4043 was 4043, checked in by Ehouarn Millour, 3 years ago

Update install_lmdz.sh to also work on LMD local machines.
EM

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