source: BOL/script_install/install_lmdz.sh @ 4192

Last change on this file since 4192 was 4111, checked in by fhourdin, 2 years ago

Detail
Frzedho

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